123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- namespace app\api\controller;
- use app\common\model\GoodsCate;
- use app\common\model\GoodsSeason;
- use app\common\model\GoodsServe;
- use app\common\model\StoreGoods;
- use app\common\model\User;
- use app\common\model\UserCollect;
- use app\common\model\UserSearch;
- use app\common\model\UserTrack;
- use app\common\model\WashCate;
- use app\common\service\Activity;
- use library\tools\Data;
- use think\Db;
- /**
- * @title 商城商品
- * @controller Mall
- * @group base
- */
- class Mall extends Base
- {
- // 需要登录的
- public function initialize(){
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 获取商品分类【商城商品】
- * @desc 获取商品分类
- * @author qc
- * @url /api/Mall/getGoodsCate
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:id type:int default:-- desc:分类id
- * @return name:title type:string default:-- desc:标题
- */
- public function getGoodsCate()
- {
- $list = GoodsCate::getCateTree();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取洗鞋分类
- * @desc 获取洗鞋分类
- * @author qc
- * @url /api/Mall/getWashCate
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:id type:int default:-- desc:分类id
- * @return name:title type:string default:-- desc:分类名称
- * @return name:logo type:string default:-- desc:分类log
- * @return name:ladder_set type:array default:-- desc:价格设置
- * @return name:ladder_set.title type:string default:-- desc:标题
- * @return name:ladder_set.price type:float default:-- desc:价格
- * @return name:ladder_set.ladder_key type:int default:-- desc:ladder_set数组的键【下单用的到】
- */
- public function getWashCate()
- {
- $list = WashCate::where('is_deleted',0)->field('id,logo,title,ladder_set')->select()->toArray();
- array_walk($list,function (&$v,$k){
- $v['ladder_set'] = $v['ladder_set'] ? json_decode($v['ladder_set'],true):null;
- });
- $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: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: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:first_classify type:int require:0 default:-- desc:一级分类id
- * @return name:item_list type:array default:-- desc:商品多规格列表
- * @return name:item_list.goods_spec type:string default:-- desc:规格
- * @return name:item_list.goods_no type:string default:-- desc:规格货号
- * @return name:item_list.goods_title: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::getCateTree();
- $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,'first_classify'))$sel_where[] = ['first_classify','=',$input['first_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('id,name,cover,desc,low_price,first_classify')
- ->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['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:image type:string default:-- desc:商品展示图[多张|隔开]
- * @return name:content type:string default:-- desc:商品详情图[多张|隔开]
- * @return name:content_arr type:array 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:item_list type:array default:-- desc:商品多规格列表
- * @return name:item_list.id type:int default:-- desc:规格id【提交订单时spec_id】
- * @return name:item_list.goods_spec type:string default:-- desc:规格
- * @return name:item_list.goods_no type:string default:-- desc:规格货号
- * @return name:item_list.goods_title: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】
- */
- public function getGoodsDetail()
- {
- $goods_id = input('goods_id');
- $all_cate = GoodsCate::getCateTree();
- $all_cate = array_column($all_cate,null,'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['first_classify_name'] = isset($all_cate[$detail['first_classify']]['title']) ? $all_cate[$detail['first_classify']]['title']:'';
- $detail['low_original'] = empty($detail['item_list']) ? 0 : min(array_column($detail['item_list'],'original_price'));
- $detail['low_price'] = empty($detail['item_list']) ? 0 : min(array_column($detail['item_list'],'sell_price'));
- $detail['max_price'] = empty($detail['item_list']) ? 0 : max(array_column($detail['item_list'],'sell_price'));
- $detail['content_arr'] = $detail['content'] ? explode('|',$detail['content']) : null;
- $this->success('oK',['goods_info'=>$detail]);
- }
- }
|