| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace app\api\controller\v1;
- use app\common\model\ShopGoodsModel;
- use app\common\service\ShopGoodsMenuService;
- use app\common\service\ShopGoodsService;
- use app\Request;
- use think\Exception;
- use think\facade\Db;
- /**
- * 商城 by wes
- * Class Shop
- * @package app\api\controller\v1
- */
- class Shop
- {
- /**
- * 商品列表
- */
- public function goodsList(Request $request)
- {
- try {
- $pageSize = $request->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]);
- }
- }
|