AlbumController.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\AlbumAgentModel;
  4. use App\Models\AlbumBannerModel;
  5. use App\Models\AlbumCatModel;
  6. use App\Models\AlbumCommentsModel;
  7. use App\Models\AlbumFavoriteModel;
  8. use App\Models\AlbumInformationModel;
  9. use App\Models\AlbumManufacturerModel;
  10. use App\Models\AlbumNavModel;
  11. use App\Models\AlbumNewsModel;
  12. use App\Models\AlbumProductModel;
  13. use App\Models\AlbumProductPriceModel;
  14. use App\Models\AlbumProductStyleModel;
  15. use App\Models\AlbumUserModel;
  16. use App\Models\AlbumXyxUserModel;
  17. use Illuminate\Http\Request;
  18. use Illuminate\Support\Facades\DB;
  19. use Validator, Response,Auth;
  20. use App\Services\Base\ErrorCode;
  21. use WXBizDataCrypt;
  22. use EasyWeChat\Factory;
  23. class AlbumController extends Controller
  24. {
  25. private $wechat_app;
  26. public function albumSetting(Request $request)
  27. {
  28. $validator = Validator::make($request->all(), [
  29. 'store_id' => 'required',
  30. ], [
  31. 'store_id.required' => '店铺信息未知',
  32. ]);
  33. if ($validator->fails()) {
  34. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  35. }
  36. $store_id = $request->store_id;
  37. //小程序設置
  38. $setting = AlbumManufacturerModel::where('store_id',$store_id)->first();
  39. //轮播图
  40. $banner = AlbumBannerModel::where('store_id',$store_id)->orderByDesc('sort')->get();
  41. //底部导航栏
  42. $navbar = AlbumNavModel::where([['store_id',$store_id],['state',0]])->orderByDesc('sort')->get();
  43. //顶部菜单栏
  44. $menus = AlbumNavModel::where([['store_id',$store_id],['state',1]])->orderByDesc('sort')->get();
  45. $news = AlbumNewsModel::where([['store_id',$store_id]])->orderByDesc('sort')->paginate(5);
  46. return $this->api(compact('setting','banner','news','navbar','menus'));
  47. }
  48. /**
  49. * @api {post} /api/album/login 登陆(login)
  50. * @apiDescription 登陆(login)
  51. * @apiGroup Album
  52. * @apiPermission none
  53. * @apiVersion 0.1.0
  54. * @apiParam {string} code 小程序登录生成的code
  55. * @apiParam {string} nickName 微信昵称
  56. * @apiParam {string} avatar 微信头像
  57. * @apiSuccessExample {json} Success-Response:
  58. * HTTP/1.1 200 OK
  59. * {
  60. * "status": true,
  61. * "status_code": 0,
  62. * "message": "",
  63. * "data": {
  64. *
  65. * }
  66. * }
  67. * @apiErrorExample {json} Error-Response:
  68. * HTTP/1.1 400 Bad Request
  69. * {
  70. * "state": false,
  71. * "code": 1000,
  72. * "message": "传入参数不正确",
  73. * "data": null or []
  74. * }
  75. * 可能出现的错误代码:
  76. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  77. */
  78. public function albumXcxLogin(Request $request)
  79. {
  80. $validator = Validator::make($request->all(),
  81. [
  82. 'code' => 'required',
  83. 'store_id' => 'required'
  84. /* 'nickName' => 'required',
  85. 'avatar' => 'required',*/
  86. ],
  87. [
  88. 'code.required' => 'code不能为空!',
  89. 'store_id.required' => 'store_id不能为空!'
  90. /*'nickName.required' => 'nickName不能为空!',
  91. 'avatar.required' => 'avatar不能为空!',*/
  92. ]
  93. );
  94. if ($validator->fails()) {
  95. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  96. }
  97. $storeid = $request->get('store_id');
  98. $this->wechat_app = AlbumManufacturerModel::where('store_id',$storeid)->first();
  99. $config = [
  100. 'app_id' => $this->wechat_app->app_id,
  101. 'secret' => $this->wechat_app->app_secret,
  102. // 下面为可选项
  103. // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  104. 'response_type' => 'array',
  105. ];
  106. $app = Factory::miniProgram($config);
  107. $code = $request->get('code');
  108. $session = $app->auth->session($code);
  109. \Log::info(json_encode($session));
  110. $openid = $session['openid'];
  111. $userinfo = AlbumUserModel::where('wechat_open_id', $openid)->where('store_id',$storeid)->first(['id', 'username','wechat_open_id','avatar']);
  112. if (!$userinfo) {
  113. $data['wechat_open_id'] = $openid;
  114. $data['username'] = $request->get('nickName');
  115. $data['avatar'] = $request->get('avatar');
  116. $data['is_dealer'] = 0;
  117. $userinfo = AlbumUserModel::create($data);
  118. }
  119. if (Auth::loginUsingId($userinfo->id)) {
  120. $user = Auth::user();
  121. $token = $user->createToken($user->id . '-' . $user->openid)->accessToken;
  122. return $this->api(compact('token', 'user', 'session_key'));
  123. } else {
  124. return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
  125. }
  126. }
  127. /**
  128. * @api {post} /api/album/xyx_login 登陆(xyx_login)
  129. * @apiDescription 登陆(xyx_login)
  130. * @apiGroup Album
  131. * @apiPermission none
  132. * @apiVersion 0.1.0
  133. * @apiParam {int} [code]
  134. * @apiParam {int} [agent_id] 经销商id
  135. * @apiParam {int} [store_id] 商户id
  136. * @apiSuccessExample {json} Success-Response:
  137. * HTTP/1.1 200 OK
  138. * {
  139. * "status": true,
  140. * "status_code": 0,
  141. * "message": "",
  142. * "data": {
  143. * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImIyNGI3MzY3MDNmZDg3MGFjNTg2MWIxNDUzMDcyYjljYzFmNmJhMzE2NTAxZWVlNGYzM2M5MTIzNzFmNGYzZjg2MTY1M2YxMjE2YzE4OTFiIn0.eyJhdWQiOiI5IiwianRpIjoiYjI0YjczNjcwM2ZkODcwYWM1ODYxYjE0NTMwNzJiOWNjMWY2YmEzMTY1MDFlZWU0ZjMzYzkxMjM3MWY0ZjNmODYxNjUzZjEyMTZjMTg5MWIiLCJpYXQiOjE1NDA3OTYyMTYsIm5iZiI6MTU0MDc5NjIxNiwiZXhwIjoxNTcyMzMyMjE1LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.Ruihvl_HMCAHx9XDfeckz48Q_72kfG7vWDsqDrZWbrjq-yuNpM3LrUF-nlsKjedo97BwU_Apz-jnGVqr0ONKZlH-aBKDmIgM2aUZfFADsHhHNJH_oU2fMe1bOrjfUp-PJxfVWQS8c8h5RYmeqtzAYCKaD4P7OZbLmOX0YosKghpaGtiyE65s6jtrOXRhAzXAhYsZToQNBMokFVRqGih9EWuVp6EVwRtI3cb4IV6iQf08cX9DGlLLBJJzLWR5ZWgxJLAGrj5iMCWBl4JKVR8Fsy-xnx3EtrB7ODpJH6hB_u3XnUSAFuaG-KzMPLsj45iqg2hy53er2xtcfAowQFsPoAbZZu0n8c9hWt4GLemR6N1iZ3LBViv3tL5BK52pinQzAnmvltAhJP1YhfTOOjzkxcYVh2JeJagufEoxeeUarMMn21gQSFEzKFCimI7zZQxhT9leLpUn51DLD8Mu87NpYb3JN-JFbOlIDA7bDN3bNto7uuSuC4eBwPo3Ge0StuW4kjHsDTcrVF2He_8FdrPcPpGcvQsXQgv4vwlEhbL8dTlrOodum7H_tY_qUxUG1pEg6bfpn_82ej-AOSc9xi0nrhdcS9y_Z68rcwOJu8esI1pXm9TeQdZIDG85y_t74At8XN6oFcIM__6_dTne_3DHwijW-uOLupNky-5J4ILmZck",
  144. * "user": {
  145. * "user_id": 1,
  146. * "is_agent": 1,
  147. * "agent_id": 4
  148. * }
  149. * }
  150. * }
  151. * @apiErrorExample {json} Error-Response:
  152. * HTTP/1.1 400 Bad Request
  153. * {
  154. * "state": false,
  155. * "code": 1000,
  156. * "message": "传入参数不正确",
  157. * "data": null or []
  158. * }
  159. * 可能出现的错误代码:
  160. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  161. */
  162. public function albumXyxLogin(Request $request)
  163. {
  164. $datas = $request->input();
  165. $validator = Validator::make($request->all(),
  166. [
  167. 'code' => 'required',
  168. 'agent_id' => 'required',
  169. 'store_id' => 'required'
  170. ],[
  171. 'code.required' => 'code不能为空!',
  172. 'agent_id.required' => 'agent_id不能为空!',
  173. 'store_id.required' => '站点ID不能为空!'
  174. ]
  175. );
  176. if ($validator->fails()) {
  177. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  178. }
  179. $this->wechat_app = AlbumManufacturerModel::where('store_id',$datas['store_id'])->first();
  180. if(!$this->wechat_app) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  181. $config = [
  182. 'app_id' => $this->wechat_app->xyx_id,
  183. 'secret' => $this->wechat_app->xyx_secret,
  184. // 下面为可选项
  185. // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  186. 'response_type' => 'array',
  187. ];
  188. $app = Factory::miniProgram($config);
  189. $res = $app->auth->session($datas['code']);
  190. // dd($res);
  191. if (!$res || empty($res['openid'])) {
  192. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '获取用户OpenId失败!', $validator->messages());
  193. }
  194. $session_key = $res['session_key'];
  195. $check = AlbumXyxUserModel::where('wechat_open_id',$res['openid'])->first();
  196. if(!$check){
  197. // $add['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
  198. $add['wechat_open_id'] = $res['openid'];
  199. $add['wechat_union_id'] = '';
  200. //$add['avatar'] = $datas['avatar'];
  201. $add['is_agent'] = 0;
  202. $add['store_id'] = $datas['store_id'];
  203. $res = AlbumXyxUserModel::create($add);
  204. if($res){
  205. $check = AlbumXyxUserModel::where('wechat_open_id',$res['openid'])->first();
  206. $user = [
  207. 'user_id'=>$check['id'],
  208. //'avatar'=>$check['avatar'],
  209. // 'username'=>$check['username'],
  210. 'is_agent'=>0,
  211. 'agent_id'=>'',
  212. ];
  213. }else{
  214. $user=[
  215. 'error'=>1
  216. ];
  217. }
  218. } else {
  219. //print_r($check);die;
  220. // $save['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
  221. // $save['avatar'] = $datas['avatar'];
  222. //$res = AlbumXyxUserModel::where('wechat_open_id',$res['openid'])->update($save);
  223. //echo 111;
  224. //print_r($check);die;
  225. if($check->is_agent == 1){
  226. $user_agent = AlbumAgentModel::where('user_id',$check->id)->first();
  227. $agent_id = $user_agent['id'];
  228. } else {
  229. $agent_id = '';
  230. }
  231. $user = [
  232. 'user_id'=>$check->id,
  233. //'avatar'=>$datas['avatar'],
  234. //'username'=>$datas['nickName'],
  235. 'is_agent'=>$check->is_agent,
  236. 'agent_id'=>$agent_id,
  237. ];
  238. }
  239. if (Auth::loginUsingId($check->id)) {
  240. $userAuth = Auth::user();
  241. if($check->is_agent ==1){
  242. $save['up_agent_id'] = $request->input('agent_id');
  243. }else{
  244. $save['up_agent_id'] = 0;
  245. }
  246. $userAuth->save();
  247. $token = $userAuth->createToken($userAuth->id . '-' . $userAuth->openid)->accessToken;
  248. return $this->api(compact('token', 'user'));
  249. } else {
  250. return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
  251. }
  252. }
  253. /*
  254. * curl get请求
  255. */
  256. public function curl_get($url)
  257. {
  258. //初始化
  259. $ch = curl_init();
  260. //设置选项,包括URL
  261. curl_setopt($ch, CURLOPT_URL, $url);
  262. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  263. curl_setopt($ch, CURLOPT_HEADER, 0);
  264. $output = curl_exec($ch);
  265. curl_close($ch);
  266. return $output;
  267. }
  268. private function getOpenid($code)
  269. {
  270. $api = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->wechat_app->app_id}&secret={$this->wechat_app->app_secret}&js_code={$code}&grant_type=authorization_code";
  271. $res = $this->curl_get($api);
  272. $res = json_decode($res, true);
  273. return $res;
  274. }
  275. private function getOpenidxyx($code)
  276. {
  277. //$api = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->wechat_app->xyx_id}&secret={$this->wechat_app->xyx_secret}&js_code={$code}&grant_type=authorization_code";
  278. $api = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->wechat_app->xyx_id}&secret={$this->wechat_app->xyx_secret}&js_code={$code}&grant_type=authorization_code";
  279. $res = $this->curl_get($api);
  280. $res = json_decode($res, true);
  281. return $res;
  282. }
  283. /**
  284. * @api {get} /api/album/goods 商品列表(goods)
  285. * @apiDescription 商品列表(goods)
  286. * @apiGroup Album
  287. * @apiPermission none
  288. * @apiVersion 0.1.0
  289. * @apiParam {int} [cat_id] 分类id
  290. * @apiParam {string} [keywords] 关键词.
  291. * @apiParam {int} [status] 状态 1 只选择热销 2 只选择最新上市 3只选择一个风格 4 同时选择热销和最新上市 5同时选择热销和风格 6同时选择最新上市和风格 7全选 0全不选
  292. * @apiParam {int} [style] 风格
  293. * @apiSuccessExample {json} Success-Response:
  294. * HTTP/1.1 200 OK
  295. * {
  296. * "status": true,
  297. * "status_code": 0,
  298. * "message": "",
  299. * "data": {
  300. * "goods": [
  301. * {
  302. * "id": 3,
  303. * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  304. * "name": "简约",
  305. * "style": "纯白",
  306. * "hot_cake": 1,
  307. * "news": 1,
  308. * "price": ""
  309. * }
  310. * ],
  311. * "name": 品牌名
  312. * }
  313. * }
  314. * @apiErrorExample {json} Error-Response:
  315. * HTTP/1.1 400 Bad Request
  316. * {
  317. * "state": false,
  318. * "code": 1000,
  319. * "message": "传入参数不正确",
  320. * "data": null or []
  321. * }
  322. * 可能出现的错误代码:
  323. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  324. */
  325. public function albumGoods(Request $request)
  326. {
  327. $userAuth = Auth('api')->user();
  328. $validator = Validator::make($request->all(), [
  329. 'cat_id' => 'required',
  330. 'store_id' => 'required',
  331. 'status' => 'required',
  332. ],[
  333. 'cat_id.required'=>'缺少分类参数',
  334. 'store_id.required'=>'缺少商户参数',
  335. 'status.required'=>'缺少状态参数',
  336. ]);
  337. if ($validator->fails()) {
  338. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  339. }
  340. $data = $request->input();
  341. //dd($data);
  342. $cat_id = request('cat_id');
  343. $store_id = request('store_id');
  344. $status = request('status');
  345. $style = request('style');
  346. if(isset($data['keywords'])&&!empty($data['keywords'])) {
  347. $keywords = '%'.$data['keywords'].'%';
  348. $goods = AlbumProductModel::where([['name','like',$keywords],['store_id',$data['store_id']]]);
  349. } else {
  350. $goods = AlbumProductModel::where([['cat_id',$cat_id],['store_id',$store_id]]);
  351. }
  352. if($status == 1) {
  353. $goods->where([['hot_cake', 1]]);
  354. }
  355. if($status == 2){
  356. $goods->where('news',1);
  357. }
  358. if($status == 3){
  359. $goods->where('style',$style);
  360. }
  361. $goods = $goods->select('id','cover_pic','name','style','hot_cake','news')->orderByDesc('sort')->get();
  362. foreach($goods as $key =>$val){
  363. if(isset($data['agent_id'])){
  364. // dd(111);
  365. $check = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
  366. if($check){
  367. $goods[$key]['price'] = $check->price;
  368. }else{
  369. $goods[$key]['price'] = '';
  370. }
  371. }else{
  372. $goods[$key]['price'] = '';
  373. }
  374. }
  375. $data =AlbumManufacturerModel::where('store_id',$store_id)->first();
  376. $name = $data['name'];
  377. return $this->api(compact('goods','name'));
  378. }
  379. /**
  380. * @api {get} /api/album/goods-detail 商品详细(goods-detail)
  381. * @apiDescription 商品列表(goods-detail)
  382. * @apiGroup Album
  383. * @apiPermission none
  384. * @apiVersion 0.1.0
  385. * @apiParam {int} [goods_id] 商品id
  386. * @apiParam {int} [store_id] 商户id 模拟值为0
  387. * @apiSuccessExample {json} Success-Response:
  388. * HTTP/1.1 200 OK
  389. * {
  390. * "status": true,
  391. * "status_code": 0,
  392. * "message": "",
  393. * "data": {
  394. * "id": 3,
  395. * "store_id": 0,
  396. * "cat_id": 9,
  397. * "specifications_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  398. * "style": "纯白",
  399. * "sort": 11,
  400. * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  401. * "hot_cake": 1,
  402. * "news": 1,
  403. * "detail": "<p>达达娃达娃达娃大青蛙大全大是大非如果v率v恶策但是许多女性的项目部的不行么法可没副本副本副本么方便</p>",
  404. * "created_at": "2018-05-19 15:09:04",
  405. * "updated_at": "2018-05-19 15:09:04",
  406. * "deleted_at": null,
  407. * "install_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  408. * "name": "简约",
  409. * "detail_pic": ""
  410. * "price": "",
  411. * "mobile": "",
  412. * "address": "",
  413. * "is_favorite": 1,
  414. * "favorite_id": 4
  415. * }
  416. * }
  417. * @apiErrorExample {json} Error-Response:
  418. * HTTP/1.1 400 Bad Request
  419. * {
  420. * "state": false,
  421. * "code": 1000,
  422. * "message": "传入参数不正确",
  423. * "data": null or []
  424. * }
  425. * 可能出现的错误代码:
  426. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  427. */
  428. public function albumGoodsDetail(Request $request)
  429. {
  430. // $userAuth = AlbumXyxUserModel::find(1);
  431. $userAuth = Auth('api')->user();
  432. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  433. $validator = Validator::make($request->all(), [
  434. 'goods_id' => 'required',
  435. ],[
  436. 'goods_id.required'=>'缺少商品参数',
  437. ]);
  438. if ($validator->fails()) {
  439. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  440. }
  441. $goods_id = request('goods_id');
  442. $store_id = request('store_id');
  443. $goods = AlbumProductModel::where([['id',$goods_id],['store_id',$store_id]])->first();
  444. if(!empty($goods) && $userAuth->up_agent_id != 0){
  445. $price = DB::table('album_product_price')->where([['agent_id',$userAuth->up_agent_id],['store_id',$store_id],['product_id',$goods['id']]])->first();
  446. if(!empty($price)){
  447. $goods->price = $price->price;
  448. $goods->mobile = $price->mobile;
  449. $address = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
  450. $goods->address = $address;
  451. }else{
  452. $goods->price = '';
  453. $goods->mobile = '';
  454. $goods->address = '';
  455. }
  456. $check_favorite = AlbumFavoriteModel::where([['user_id',$userAuth->id],['store_id',$store_id],['product_id',$goods['id']]])->first();
  457. // dd($check_favorite);
  458. if($check_favorite){
  459. $goods->is_favorite = 1;
  460. $goods->favorite_id = $check_favorite->id;
  461. }else{
  462. $goods->is_favorite = 0;
  463. $goods->favorite_id = '';
  464. }
  465. }
  466. return $this->api($goods);
  467. }
  468. /**
  469. * @api {get} /api/album/favorite_list 收藏列表(favorite_list)
  470. * @apiDescription 收藏列表(favorite_list)
  471. * @apiGroup Album
  472. * @apiPermission none
  473. * @apiVersion 0.1.0
  474. * @apiParam {int} [store_id] 商户id 模拟值为0
  475. * @apiSuccessExample {json} Success-Response:
  476. * HTTP/1.1 200 OK
  477. * {
  478. * "status": true,
  479. * "status_code": 0,
  480. * "message": "",
  481. * "data": [
  482. * {
  483. * "id": 4,
  484. * "user_id": 1,
  485. * "deleted_at": null,
  486. * "created_at": "2018-10-29 15:51:47",
  487. * "updated_at": "2018-10-29 15:53:15",
  488. * "product_id": 3,
  489. * "store_id": 0,
  490. * "goods": {
  491. * "id": 3,
  492. * "store_id": 0,
  493. * "cat_id": 9,
  494. * "specifications_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  495. * "style": "纯白",
  496. * "sort": 11,
  497. * "cover_pic": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  498. * "hot_cake": 1,
  499. * "news": 1,
  500. * "detail": "<p>达达娃达娃达娃大青蛙大全大是大非如果v率v恶策但是许多女性的项目部的不行么法可没副本副本副本么方便</p>",
  501. * "created_at": "2018-05-19 15:09:04",
  502. * "updated_at": "2018-05-19 15:09:04",
  503. * "deleted_at": null,
  504. * "install_img": "http://admin.xcx.com/upload/images/20180519/02f2dbe0e1046d7cea8b3b52d5642fb8.jpg",
  505. * "name": "简约",
  506. * "detail_pic": ""
  507. * }
  508. * }
  509. * ]
  510. * }
  511. * @apiErrorExample {json} Error-Response:
  512. * HTTP/1.1 400 Bad Request
  513. * {
  514. * "state": false,
  515. * "code": 1000,
  516. * "message": "传入参数不正确",
  517. * "data": null or []
  518. * }
  519. * 可能出现的错误代码:
  520. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  521. */
  522. public function albumFavoriteList(Request $request)
  523. {
  524. $userAuth = Auth('api')->user();
  525. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  526. $validator = Validator::make($request->all(), [
  527. 'store_id' => 'required',
  528. ],[
  529. 'store_id.required'=>'缺少商户参数',
  530. ]);
  531. if ($validator->fails()) {
  532. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  533. }
  534. $data = $request->input();
  535. $favorite = AlbumFavoriteModel::where([['user_id',$userAuth->id],['store_id',$data['store_id']]])->get();
  536. foreach ($favorite as $key=>$val) {
  537. $favorite[$key]['goods'] = AlbumProductModel::where([['id',$val['product_id']],['store_id',$data['store_id']]])->first();
  538. }
  539. return $this->api($favorite);
  540. }
  541. /**
  542. * @api {get} /api/album/checklogin 登陆应用(checklogin)
  543. * @apiDescription 登陆应用(checklogin)
  544. * @apiGroup Album
  545. * @apiPermission none
  546. * @apiVersion 0.1.0
  547. * @apiParam {int} [store_id] 商户id 模拟值为0
  548. * @apiSuccessExample {json} Success-Response:
  549. * HTTP/1.1 200 OK
  550. * {
  551. * "status": true,
  552. * "status_code": 0,
  553. * "message": "",
  554. * "data": {
  555. *
  556. * }
  557. * }
  558. * @apiErrorExample {json} Error-Response:
  559. * HTTP/1.1 400 Bad Request
  560. * {
  561. * "state": false,
  562. * "code": 1000,
  563. * "message": "传入参数不正确",
  564. * "data": null or []
  565. * }
  566. * 可能出现的错误代码:
  567. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  568. */
  569. public function albumchecklogin(Request $request)
  570. {
  571. $validator = Validator::make($request->all(), [
  572. 'store_id' => 'required',
  573. ],[
  574. 'store_id.required'=>'缺少商户参数',
  575. ]);
  576. if ($validator->fails()) {
  577. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  578. }
  579. $data = $request->input();
  580. $favorite = AlbumManufacturerModel::where([['store_id',$data['store_id']]])->first();
  581. $conf = $favorite->redirectapp;
  582. return $this->api($conf);
  583. }
  584. /**
  585. * @api {get} /api/album/favorite_del 收藏删除(favorite_del)
  586. * @apiDescription 收藏删除(favorite_del)
  587. * @apiGroup Album
  588. * @apiPermission none
  589. * @apiVersion 0.1.0
  590. * @apiParam {int} [store_id] 商户id 模拟值为0
  591. * @apiParam {int} [favorite_id] 收藏id
  592. * @apiSuccessExample {json} Success-Response:
  593. * HTTP/1.1 200 OK
  594. * {
  595. * "status": true,
  596. * "status_code": 0,
  597. * "message": "",
  598. * "data":[]//返回状态
  599. * }
  600. * @apiErrorExample {json} Error-Response:
  601. * HTTP/1.1 400 Bad Request
  602. * {
  603. * "state": false,
  604. * "code": 1000,
  605. * "message": "传入参数不正确",
  606. * "data": null or []
  607. * }
  608. * 可能出现的错误代码:
  609. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  610. */
  611. public function albumFavoriteDel(Request $request)
  612. {
  613. //$userAuth = AlbumXyxUserModel::find(1);
  614. $userAuth = Auth('api')->user();
  615. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  616. $validator = Validator::make($request->all(), [
  617. 'store_id' => 'required',
  618. 'favorite_id' => 'required',
  619. ],[
  620. 'store_id.required'=>'缺少商户参数',
  621. 'favorite_id.required'=>'缺少收藏参数',
  622. ]);
  623. if ($validator->fails()) {
  624. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  625. }
  626. $data = $request->input();
  627. $favorite = AlbumFavoriteModel::find($data['favorite_id']);
  628. if(!$favorite){
  629. $d = [
  630. 'code' =>1,
  631. 'msg' =>'删除失败,或者该收藏已移除',
  632. ];
  633. } else {
  634. $res = $favorite->delete();
  635. if($res){
  636. $d = [
  637. 'code' =>1,
  638. 'msg' =>'删除成功',
  639. ];
  640. } else {
  641. $d = [
  642. 'code' =>1,
  643. 'msg' =>'删除失败,或者该收藏已移除',
  644. ];
  645. }
  646. }
  647. return $this->api($d);
  648. }
  649. /**
  650. * @api {get} /api/album/add_favorite 添加收藏(add_favorite)
  651. * @apiDescription 添加收藏(favorite_list)
  652. * @apiGroup Album
  653. * @apiPermission none
  654. * @apiVersion 0.1.0
  655. * @apiParam {int} [store_id] 商户id
  656. * @apiParam {int} [product_id] 商品id
  657. * @apiSuccessExample {json} Success-Response:
  658. * HTTP/1.1 200 OK
  659. * {
  660. * "status": true,
  661. * "status_code": 0,
  662. * "message": "",
  663. * "data": []//返回信息
  664. * }
  665. * @apiErrorExample {json} Error-Response:
  666. * HTTP/1.1 400 Bad Request
  667. * {
  668. * "state": false,
  669. * "code": 1000,
  670. * "message": "传入参数不正确",
  671. * "data": null or []
  672. * }
  673. * 可能出现的错误代码:
  674. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  675. */
  676. public function albumAddFavorite(Request $request)
  677. {
  678. $userAuth = Auth('api')->user();
  679. if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
  680. $validator = Validator::make($request->all(), [
  681. 'store_id' => 'required',
  682. 'product_id' => 'required',
  683. ],[
  684. 'store_id.required'=>'缺少商户参数',
  685. 'product_id.required'=>'缺少商品参数',
  686. ]);
  687. if ($validator->fails()) {
  688. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  689. }
  690. $data = $request->input();
  691. $check_user = AlbumXyxUserModel::find($userAuth->id);
  692. $check_f = AlbumFavoriteModel::where([['user_id',$userAuth->id],['product_id',$data['product_id']]])->first();
  693. if(!$check_user||$check_f){
  694. $d = [
  695. 'code' =>1,
  696. 'msg' =>'该用户不存在或者已添加',
  697. ];
  698. return $this->api($d);
  699. }
  700. $data['user_id'] = $userAuth->id;
  701. $res = AlbumFavoriteModel::create($data);
  702. if($res){
  703. $d = [
  704. 'code' =>0,
  705. 'msg' =>'success',
  706. ];
  707. }else{
  708. $d = [
  709. 'code' =>1,
  710. 'msg' =>'error',
  711. ];
  712. }
  713. return $this->api($d);
  714. }
  715. /**
  716. * @api {get} /api/album/cat 分类列表(cat)
  717. * @apiDescription 画册分类(cat)
  718. * @apiGroup Album
  719. * @apiPermission none
  720. * @apiVersion 0.1.0
  721. * @apiParam {int} [parent_id] 一级菜单传0 二级菜单的id从一级菜单里面获取
  722. * @apiParam {int} [store_id] 商户id 模拟值为0
  723. * @apiSuccessExample {json} Success-Response:
  724. * HTTP/1.1 200 OK
  725. * {
  726. * "status": true,
  727. * "status_code": 0,
  728. * "message": "",
  729. * "data": [
  730. * {
  731. * "id": 9,
  732. * "name": "圣地亚哥",
  733. * "parent_id": 0,
  734. * "level": "00",
  735. * "pic_url": "http://admin.xcx.com/upload/images/20180518/af6cc8fd71241744ccd638afc6ac25f2.png",
  736. * "created_at": "2018-05-19 14:55:48",
  737. * "updated_at": "2018-05-19 14:55:48",
  738. * "store_id": 0,
  739. * "deleted_at": null,
  740. * "sort": 0
  741. * }
  742. * ]
  743. * }
  744. * @apiErrorExample {json} Error-Response:
  745. * HTTP/1.1 400 Bad Request
  746. * {
  747. * "state": false,
  748. * "code": 1000,
  749. * "message": "传入参数不正确",
  750. * "data": null or []
  751. * }
  752. * 可能出现的错误代码:
  753. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  754. */
  755. public function albumCat(Request $request)
  756. {
  757. $validator = Validator::make($request->all(), [
  758. 'store_id' => 'required',
  759. ],[
  760. 'store_id.required'=>'缺少商户参数',
  761. ]);
  762. if ($validator->fails()) {
  763. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  764. }
  765. $cat_id = 0;
  766. $store_id = request('store_id');
  767. $cats = AlbumCatModel::where([['parent_id',$cat_id],['store_id',$store_id]])->orderByDesc('sort')->get();
  768. return $this->api($cats);
  769. }
  770. /**
  771. * @api {get} /api/album/style 属性列表(style)
  772. * @apiDescription 分类样式(style)
  773. * @apiGroup Album
  774. * @apiPermission none
  775. * @apiVersion 0.1.0
  776. * @apiParam {int} [store_id] 商户id 模拟值为0
  777. * @apiSuccessExample {json} Success-Response:
  778. * HTTP/1.1 200 OK
  779. * {
  780. * "status": true,
  781. * "status_code": 0,
  782. * "message": "",
  783. * "data": [
  784. * {
  785. * "id": 2,
  786. * "name": "1111",
  787. * "deleted_at": null,
  788. * "created_at": "2018-06-05 17:35:08",
  789. * "updated_at": "2018-06-05 17:35:08",
  790. * "store_id": 0
  791. * }
  792. * ]
  793. * }
  794. * @apiErrorExample {json} Error-Response:
  795. * HTTP/1.1 400 Bad Request
  796. * {
  797. * "state": false,
  798. * "code": 1000,
  799. * "message": "传入参数不正确",
  800. * "data": null or []
  801. * }
  802. * 可能出现的错误代码:
  803. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  804. */
  805. public function albumStyle(Request $request)
  806. {
  807. $validator = Validator::make($request->all(), [
  808. 'store_id' => 'required',
  809. ],[
  810. 'store_id.required'=>'缺少商户参数',
  811. ]);
  812. if ($validator->fails()) {
  813. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  814. }
  815. $store_id = request('store_id');
  816. $style = AlbumProductStyleModel::where([['store_id',$store_id]])->orderByDesc('id')->get();
  817. return $this->api($style);
  818. }
  819. /**
  820. * @api {get} /api/album/set-price 经销商修改价格(set-price)
  821. * @apiDescription 画册(set-price)
  822. * @apiGroup Album
  823. * @apiPermission none
  824. * @apiVersion 0.1.0
  825. * @apiParam {int} [goods_id] 商品id
  826. * @apiParam {int} [agent_id] 经销商id 模拟值为10
  827. * @apiParam {int} [store_id] 商户id 模拟值为0
  828. * @apiParam {int} [type] 修改类型 0 电话 1 价格
  829. * @apiParam {string} [mobile] 电话号码
  830. * @apiParam {string} [address] 地址
  831. * @apiParam {double} [price] 价格
  832. * @apiSuccessExample {json} Success-Response:
  833. * HTTP/1.1 200 OK
  834. * {
  835. * "status": true,
  836. * "status_code": 0,
  837. * "message": "",
  838. * "data":[
  839. * "msg":返回信息,
  840. * "data":修改后价格
  841. * ]
  842. * }
  843. * @apiErrorExample {json} Error-Response:
  844. * HTTP/1.1 400 Bad Request
  845. * {
  846. * "state": false,
  847. * "code": 1000,
  848. * "message": "传入参数不正确",
  849. * "data": null or []
  850. * }
  851. * 可能出现的错误代码:
  852. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  853. */
  854. public function albumSetPrice(Request $request)
  855. {
  856. $userAuth = Auth('api')->user();
  857. $data = $request->all();
  858. //print_r($data);
  859. $save = array();
  860. $return_data = array();
  861. if($data['type'] == 0) {
  862. $save['mobile'] = $data['mobile'];
  863. $product = AlbumProductModel::where('store_id',$data['store_id'])->get();
  864. foreach($product as $key=>$val){
  865. $check = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
  866. if(empty($check)){
  867. $save['agent_id'] = $data['agent_id'];
  868. $save['store_id'] = $data['store_id'];
  869. $save['product_id'] = $val['id'];
  870. $res = AlbumProductPriceModel::create($save);
  871. }else{
  872. $res = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$val['id']]])->update($save);
  873. }
  874. if(!$res){
  875. $return['msg'] = 'error';
  876. return $this->api($return);
  877. }
  878. }
  879. $update_agent['phone'] = $data['mobile'];
  880. $update_agent['address'] = $data['address'];
  881. $update_res = AlbumAgentModel::where('id',$data['agent_id'])->update($update_agent);
  882. if(!$update_res){
  883. $return['msg'] = 'error';
  884. return $this->api($return);
  885. }
  886. $return_data['mobile'] = $data['mobile'];
  887. $return_data['address'] = $data['address'];
  888. $return['msg'] = 'success';
  889. } elseif ($data['type'] == 1){
  890. $save['price'] = $data['price'];
  891. $check = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->first();
  892. if(empty($check)){
  893. $save['agent_id'] = $data['agent_id'];
  894. $save['store_id'] = $data['store_id'];
  895. $save['product_id'] = $data['goods_id'];
  896. $res = AlbumProductPriceModel::create($save);
  897. }else{
  898. $res = AlbumProductPriceModel::where([['agent_id',$data['agent_id']],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->update($save);
  899. }
  900. if($res){
  901. $return['msg'] = 'success';
  902. $return_data['price'] = $data['price'];
  903. } else {
  904. $return['msg'] = 'error';
  905. }
  906. }
  907. $return['data'] = $return_data;
  908. return $this->api($return);
  909. }
  910. }