success('ok',['list'=>$list]); } /** * @title 获取商品二级分类 * @desc 获取商品二级分类 * @author qc * @url /api/Mall/getSecondCate * @method GET * @header name:Authorization require:1 desc:Token * @param name:id type:int default:-- desc:一级分类id * @return name:title type:srting default:-- desc:标题 * @return name:lev type:srting default:-- desc:分类等级(1,2,3,4) */ public function getSecondCate() { $list = GoodsCate::field('id,title,pid,lev')->where(['status'=>1,'is_deleted'=>0,'pid'=>input('get.id')])->order('sort desc ,id desc')->select()->toArray(); $this->success('ok',['list'=>$list]); } /** * @title 商城商品推荐 * @desc 商城商品推荐 * @author qc * @method GET * @url /api/Mall/getRecommendList * @header name:Authorization require:1 desc:Token * @param name:page type:int default:0 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @return name:id type:int default:-- desc:id * @return name:name type:string default:-- desc:商品名称 * @return name:cover type:string default:-- desc:封面 * @return name:low_price type:float default:-- desc:价格 */ public function getRecommendList() { $search_log = UserSearch::getSearchTitle($this->user_id,7); $search_arr = []; $where_str = 'b.id > 0'; foreach ($search_log as $t){ $search_arr[] = " b.name like '".'%'.$t."%'" .' '; } if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr); $field = 'a.id,name,cover,low_price,IFNULL(is_recommend,0) is_recommend '; $table = 'dd_store_goods'; $order_by_two = 'id'; $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.status =1 AND a.is_deleted = 0 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}"; $list = Db::query($sql); $this->success('ok',['list'=>$list]); } /** * @title 获取商品列表 * @desc 获取商品列表 * @author qc * @url /api/Mall/getGoodsList * @method GET * @header name:Authorization require:1 desc:Token * @param name:page type:int default:1 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @param name:goods_name type:string require:0 default:-- desc:商品名称 * @param name:first_classify type:int require:0 default:-- desc:一级分类id * @param name:second_classify type:int require:0 default:-- desc:二级分类id * @param name:sort_type type:int default:1 desc:排序--1默认2时间升序3时间降序 * @return name:name type:string default:-- desc:商品名称 * @return name:cover type:string default:-- desc:商品封面图 * @return name:desc type:string default:-- desc:商品简述(副标题) * @return name:image type:string default:-- desc:商品展示图[多张|隔开] * @return name:content type:string default:-- desc:商品详情图[多张|隔开] * @return name:low_price type:float default:-- desc:最低售价 * @return name:max_price type:float default:-- desc:最高售价 * @return name:low_original type:float default:-- desc:最低原价格 * @return name:total_num type:int default:-- desc:商品总数量 * @return name:detail type:int default:-- desc:商品详情 * @return name:first_classify type:int require:0 default:-- desc:一级分类id * @return name:second_classify type:int require:0 default:-- desc:二级分类id * @return name:freight_type type:int default:-- desc:运费类型0固定金额,1运费模板 * @return name:freight_id type:int default:-- desc:模板id(freight_type=1) * @return name:postage type:float default:-- desc:运费(freight_type=0) * @return name:item_list type:array default:-- desc:商品多规格列表 * @return name:item_list.spec_info type:array default:-- desc:规格型号设置['规格组id'=>'规格id','规格组id'=>'规格id']; * @return name:item_list.goods_no type:string default:-- desc:规格货号 * @return name:item_list.goods_title:string default:-- desc:规格标题 * @return name:item_list.cover type:string default:-- desc:规格封面 * @return name:item_list.stock type:int default:-- desc:剩余库存 * @return name:item_list.original_price type:float default:-- desc:原价 * @return name:item_list.sell_price type:float default:-- desc:售价 * @return name:item_list.virtual type:int default:-- desc:虚拟销量 * @return name:item_list.weight type:float default:-- desc:重量【kg】 * @return name:total_num type:int default:-- desc:总数 */ public function getGoodsList(){ $all_cate = GoodsCate::field('id,title')->select()->toArray(); $all_cate = array_column($all_cate,null,'id'); $input = input('get.'); $sel_where = []; $sel_where[] = ['status','=',1]; $sel_where[] = ['is_deleted','=',0]; $sort_type = input('get.sort_type',1); if(isset_full($input,'goods_name')) { $sel_where[] = ['name','like',"%".$input['goods_name']."%"]; if($this->user_id) UserSearch::saveSearchTitle($this->user_id,$input['goods_name'],7); } if(isset_full($input,'first_classify'))$sel_where[] = ['first_classify','=',$input['first_classify']]; if(isset_full($input,'second_classify'))$sel_where[] = ['second_classify','=',$input['second_classify']]; switch ($sort_type) { case 1: $order = ['sort'=>'desc','id'=>'desc']; break; case 2: $order = ['id'=>'asc','sort'=>'desc']; break; case 3: $order = ['id'=>'desc','sort'=>'desc']; break; } $list = StoreGoods::with(['itemList']) ->field('specs,lists',true) ->where($sel_where)->limit($this->off_set,$this->page_num) ->order($order) ->select()->toArray(); foreach ($list as &$v){ $v['first_classify_name'] = isset($all_cate[$v['first_classify']]['title']) ? $all_cate[$v['first_classify']]['title']:''; $v['second_classify_name'] = isset($all_cate[$v['second_classify']]['title']) ? $all_cate[$v['second_classify']]['title']:''; $v['low_original'] = empty($v['item_list']) ? 0 : min(array_column($v['item_list'],'original_price')); $v['low_price'] = empty($v['item_list']) ? 0 : min(array_column($v['item_list'],'sell_price')); $v['max_price'] = empty($v['item_list']) ? 0 : max(array_column($v['item_list'],'sell_price')); $v['total_num'] = empty($v['item_list']) ? 0 :array_sum(array_column($v['item_list'],'base_stock')); } $total_num = StoreGoods::where($sel_where)->count(); $this->success('ok',['list'=>$list,'total_num'=>$total_num]); } /** * @title 获取商品详情 * @desc 获取商品详情 * @author qc * @url /api/Mall/getGoodsDetail * @method GET * @header name:Authorization require:1 desc:Token * @param name:goods_id type:int require:1 default:0 desc:商品id * @return name:name type:string default:-- desc:商品名称 * @return name:cover type:string default:-- desc:商品封面图 * @return name:desc type:string default:-- desc:商品简述(副标题) * @return name:low_price type:float default:-- desc:最低价格 * @return name:max_price type:float default:-- desc:最高价格(下划线公用) * @return name:low_seckill type:float default:-- desc:最低秒杀价格(有秒杀活动) * @return name:low_group type:float default:-- desc:最低拼团价格(有拼团活动) * @return name:low_discount type:float default:-- desc:最低折扣价格(有折扣活动) * @return name:discount type:float default:-- desc:商品折扣(没有折扣为10,有折扣活动,例如75折,值为7.5) * @return name:freight_type type:int default:-- desc:运费类型0固定金额,1运费模板 * @return name:freight_id type:int default:-- desc:模板id(freight_type=1) * @return name:postage type:float default:-- desc:运费(freight_type=0) * @return name:is_collect type:int default:-- desc:是否收藏(1是0否) * @return name:item_list type:array default:-- desc:商品多规格列表 * @return name:item_list.spec_info type:array default:-- desc:规格型号设置; * @return name:item_list.goods_no type:string default:-- desc:规格货号 * @return name:item_list.stock type:int default:-- desc:剩余库存 * @return name:item_list.original_price type:float default:-- desc:原价 * @return name:item_list.sell_price type:float default:-- desc:售价 */ public function getGoodsDetail() { $goods_id = input('goods_id'); $detail = StoreGoods::with(['itemList'])->field('specs,lists',true)->where('id',$goods_id)->find()->toArray(); $detail['max_price'] = max(array_column($detail['item_list'],'original_price')); $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,6,$detail['id']); UserTrack::crateTrack($this->user_id,6,$goods_id,0); $this->success('oK',['goods_info'=>$detail]); } /** * @title 收藏||取消收藏 * @desc 用户收藏 * @author qc * @method POST * @url /api/Mall/goodsCollect * @header name:Authorization require:1 desc:Token * @param name:id type:int require:1 default:-- desc:商品id * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏) */ public function goodsCollect(){ $coll_status = UserCollect::plateCollect($this->user_id,6,input('post.id',0)); $coll_status ? $this->success('收藏成功',['status'=>1]) : $this->success('取消收藏成功',['status'=>0]); } /** * @title 商品浏览记录 * @desc 商品浏览记录 * @author qc * @url /api/Mall/getGoodsHistory * @method GET * @header name:Authorization require:1 desc:Token * @param name:page type:int default:1 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @param name:name type:string require:0 default:-- desc:商品名称 * @return name:name type:string default:-- desc:商品名称 * @return name:cover type:string default:-- desc:商品封面图 * @return name:desc type:string default:-- desc:商品简述(副标题) * @return name:low_price type:float default:-- desc:最低售价 */ public function getGoodsHistory() { $sel_where = []; $sel_where[] = ['t.user_id','=',$this->user_id]; $sel_where[] = ['t.type','=',6]; $title = input('get.name'); if($title) $sel_where[] = ['i.name','like','%'.$title.'%']; $list = UserTrack::where($sel_where) ->alias('t') ->field('t.id,t.update_int,t.date,t.first_id goods_id,i.name,i.cover,i.low_price') ->leftJoin('StoreGoods i','t.first_id = i.id') ->order('update_int desc') ->limit($this->off_set,$this->page_num) ->select()->toArray(); foreach ($list as &$v) { $v['time'] = date("Y-m-d H:i:s",$v['update_int']); } $this->success('ok',['list'=>$list]); } /** * @title 商品收藏列表 * @desc 商品收藏列表 * @author qc * @url /api/Mall/getGoodsCollectList * @method GET * @header name:Authorization require:1 desc:Token * @param name:page type:int default:1 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @param name:name type:string require:0 default:-- desc:商品名称 * @return name:name type:string default:-- desc:商品名称 * @return name:cover type:string default:-- desc:商品封面图 * @return name:desc type:string default:-- desc:商品简述(副标题) * @return name:low_price type:float default:-- desc:最低售价 */ public function getGoodsCollectList() { $sel_where = []; $title = input('get.name'); if($title) $sel_where[] = ['i.name','like','%'.$title.'%']; $sel_where[] = ['t.user_id','=',$this->user_id]; $sel_where[] = ['t.coll_type','=',6]; $list = UserCollect::where($sel_where) ->alias('t') ->field('t.id,t.create_at,t.coll_id goods_id,i.name,i.cover,i.low_price') ->leftJoin('StoreGoods i','t.coll_id = i.id') ->order('id desc') ->limit($this->off_set,$this->page_num) ->select()->toArray(); $this->success('ok',['list'=>$list]); } /** * @title 获取我发布的商品列表 * @desc 获取我发布的商品列表 * @author qc * @url /api/Mall/getOwnGoodsList * @method GET * @header name:Authorization require:1 desc:Token * @param name:page type:int default:1 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @param name:name type:string require:0 default:-- desc:商品名称 * @return name:name type:string default:-- desc:商品名称 * @return name:cover type:string default:-- desc:商品封面图 * @return name:desc type:string default:-- desc:商品简述(副标题) * @return name:low_price type:float default:-- desc:最低售价 */ public function getOwnGoodsList() { $list = StoreGoods::field('id,name,desc,create_at,low_price') ->where(['user_id'=>$this->user_id]) ->order(['sort'=>'desc','id'=>'desc']) ->limit($this->off_set,$this->page_num) ->select()->toArray(); $this->success('ok',['list'=>$list]); } }