post('limit', 10); $list = ShopGoodsService::make()->getList($request->all, $pageSize); return api_succ_return(['msg'=>'成功', 'data'=> isset($list['data'])? $list['data'] : []]); }catch(Exception $e){ return api_error_return('获取失败:'.$e->getMessage()); } } /** * 专区商品菜单 * @param Request $request * @return \think\Response * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function goodsMenu(Request $request) { try { $list = ShopGoodsMenuService::make()->getList('',999); return api_succ_return(['msg'=>'成功', 'data'=> isset($list['data'])? $list['data']:[]]); } catch (\Exception $e){ return api_error_return('获取失败:'.$e->getMessage()); } } /** * 商品详情 * @param Request $request * @return \think\Response */ public function goodsDetail (Request $request) { try { $goodsSn = $request->only(['goods_sn']); if(empty($goodsSn)){ return api_error_return('参数错误'); } $data = ShopGoodsService::make()->getDetail($request->all()); if (empty($data)){ return api_error_return('请求失败'); } // 更新浏览量 ShopGoodsService::make()->updateScanCount($data['goods_id']); return api_succ_return(['msg'=>'获取成功', 'data'=> $data]); } catch (\Exception $e) { return api_error_return($e->getMessage()); } } /** * 收藏商品 * @param Request $request * @return \think\Response * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function goodsAttension (Request $request) { $post = $request->post(); $goodsId = isset($post['goods_id'])? intval($post['goods_id']) : 0; try { if (ShopGoodsService::make()->goodsAttension($request->uid, $goodsId)){ return api_succ_return('收藏成功'); } } catch (\Exception $e){ return api_succ_return('失败:'.$e->getMessage()); } } /** * 是否收藏过商品 * @param Request $request * @return \think\Response * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function isAttensionGoods(Request $request){ $post = $request->post(); $goodsId = isset($post['goods_id'])? intval($post['goods_id']) : 0; $isAttension = ShopGoodsService::make()->checkAttension($request->uid, $goodsId); return api_succ_return(['msg'=>'成功', 'data'=>['attension'=> $isAttension?1:2]]); } /** * 购物车推荐商品 * @param Request $request * @return \think\Response * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function storeRecommonGoods(Request $request){ $field = 'sort,category,goods_sn,goods_name,goods_img,min_original_price as original_price,min_price as price,rebate_score,sales_volume,inventory,attension_count,scan_count'; $list = ShopGoodsService::make()->getList(['sort'=> 'scan_count desc'], 99, $field); return api_succ_return(['msg'=>'成功', 'data'=>$list]); } }