Mall.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\GoodsCate;
  4. use app\common\model\GoodsSeason;
  5. use app\common\model\GoodsServe;
  6. use app\common\model\StoreGoods;
  7. use app\common\model\User;
  8. use app\common\model\UserCollect;
  9. use app\common\model\UserSearch;
  10. use app\common\model\UserTrack;
  11. use app\common\model\WashCate;
  12. use app\common\service\Activity;
  13. use library\tools\Data;
  14. use think\Db;
  15. /**
  16. * @title 商城商品
  17. * @controller Mall
  18. * @group base
  19. */
  20. class Mall extends Base
  21. {
  22. // 需要登录的
  23. public function initialize(){
  24. parent::initialize();
  25. parent::setUid();
  26. }
  27. /**
  28. * @title 获取商品分类【商城商品】
  29. * @desc 获取商品分类
  30. * @author qc
  31. * @url /api/Mall/getGoodsCate
  32. * @method GET
  33. * @header name:Authorization require:1 desc:Token
  34. * @return name:id type:int default:-- desc:分类id
  35. * @return name:title type:string default:-- desc:标题
  36. */
  37. public function getGoodsCate()
  38. {
  39. $list = GoodsCate::getCateTree();
  40. $this->success('ok',['list'=>$list]);
  41. }
  42. /**
  43. * @title 获取洗鞋分类
  44. * @desc 获取洗鞋分类
  45. * @author qc
  46. * @url /api/Mall/getWashCate
  47. * @method GET
  48. * @header name:Authorization require:1 desc:Token
  49. * @return name:id type:int default:-- desc:分类id
  50. * @return name:title type:string default:-- desc:分类名称
  51. * @return name:logo type:string default:-- desc:分类log
  52. * @return name:ladder_set type:array default:-- desc:价格设置
  53. * @return name:ladder_set.title type:string default:-- desc:标题
  54. * @return name:ladder_set.price type:float default:-- desc:价格
  55. * @return name:ladder_set.ladder_key type:int default:-- desc:ladder_set数组的键【下单用的到】
  56. */
  57. public function getWashCate()
  58. {
  59. $list = WashCate::where('is_deleted',0)->field('id,logo,title,ladder_set')->select()->toArray();
  60. array_walk($list,function (&$v,$k){
  61. $v['ladder_set'] = $v['ladder_set'] ? json_decode($v['ladder_set'],true):null;
  62. });
  63. $this->success('ok',['list'=>$list]);
  64. }
  65. /**
  66. * @title 获取商品列表
  67. * @desc 获取商品列表
  68. * @author qc
  69. * @url /api/Mall/getGoodsList
  70. * @method GET
  71. * @header name:Authorization require:1 desc:Token
  72. * @param name:page type:int default:1 desc:页数
  73. * @param name:page_num type:int default:20 desc:每页数
  74. * @param name:goods_name type:string require:0 default:-- desc:商品名称
  75. * @param name:first_classify type:int require:0 default:-- desc:分类id
  76. * @param name:sort_type type:int default:1 desc:排序--1默认2时间升序3时间降序
  77. * @return name:name type:string default:-- desc:商品名称
  78. * @return name:cover type:string default:-- desc:商品封面图
  79. * @return name:desc type:string default:-- desc:商品简述(副标题)
  80. * @return name:low_price type:float default:-- desc:最低售价
  81. * @return name:max_price type:float default:-- desc:最高售价
  82. * @return name:low_original type:float default:-- desc:最低原价格
  83. * @return name:total_num type:int default:-- desc:商品总数量
  84. * @return name:first_classify type:int require:0 default:-- desc:一级分类id
  85. * @return name:item_list type:array default:-- desc:商品多规格列表
  86. * @return name:item_list.goods_spec type:string default:-- desc:规格
  87. * @return name:item_list.goods_no type:string default:-- desc:规格货号
  88. * @return name:item_list.goods_title:string default:-- desc:规格标题
  89. * @return name:item_list.stock type:int default:-- desc:剩余库存
  90. * @return name:item_list.original_price type:float default:-- desc:原价
  91. * @return name:item_list.sell_price type:float default:-- desc:售价
  92. * @return name:item_list.virtual type:int default:-- desc:虚拟销量
  93. * @return name:item_list.weight type:float default:-- desc:重量【kg】
  94. * @return name:total_num type:int default:-- desc:总数
  95. */
  96. public function getGoodsList(){
  97. $all_cate = GoodsCate::getCateTree();
  98. $all_cate = array_column($all_cate,null,'id');
  99. $input = input('get.');
  100. $sel_where = [];
  101. $sel_where[] = ['status','=',1];
  102. $sel_where[] = ['is_deleted','=',0];
  103. $sort_type = input('get.sort_type',1);
  104. if(isset_full($input,'first_classify'))$sel_where[] = ['first_classify','=',$input['first_classify']];
  105. switch ($sort_type) {
  106. case 1:
  107. $order = ['sort'=>'desc','id'=>'desc'];
  108. break;
  109. case 2:
  110. $order = ['id'=>'asc','sort'=>'desc'];
  111. break;
  112. case 3:
  113. $order = ['id'=>'desc','sort'=>'desc'];
  114. break;
  115. }
  116. $list = StoreGoods::with(['itemList'])
  117. ->field('id,name,cover,desc,low_price,first_classify')
  118. ->where($sel_where)->limit($this->off_set,$this->page_num)
  119. ->order($order)
  120. ->select()->toArray();
  121. foreach ($list as &$v){
  122. $v['first_classify_name'] = isset($all_cate[$v['first_classify']]['title']) ? $all_cate[$v['first_classify']]['title']:'';
  123. $v['low_original'] = empty($v['item_list']) ? 0 : min(array_column($v['item_list'],'original_price'));
  124. $v['low_price'] = empty($v['item_list']) ? 0 : min(array_column($v['item_list'],'sell_price'));
  125. $v['max_price'] = empty($v['item_list']) ? 0 : max(array_column($v['item_list'],'sell_price'));
  126. $v['total_num'] = empty($v['item_list']) ? 0 :array_sum(array_column($v['item_list'],'base_stock'));
  127. }
  128. $total_num = StoreGoods::where($sel_where)->count();
  129. $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
  130. }
  131. /**
  132. * @title 获取商品详情
  133. * @desc 获取商品详情
  134. * @author qc
  135. * @url /api/Mall/getGoodsDetail
  136. * @method GET
  137. * @header name:Authorization require:1 desc:Token
  138. * @param name:goods_id type:int require:1 default:0 desc:商品id
  139. * @return name:name type:string default:-- desc:商品名称
  140. * @return name:cover type:string default:-- desc:商品封面图
  141. * @return name:desc type:string default:-- desc:商品简述(副标题)
  142. * @return name:image type:string default:-- desc:商品展示图[多张|隔开]
  143. * @return name:content type:string default:-- desc:商品详情图[多张|隔开]
  144. * @return name:content_arr type:array default:-- desc:商品详情图
  145. * @return name:low_price type:float default:-- desc:最低售价
  146. * @return name:max_price type:float default:-- desc:最高售价
  147. * @return name:low_original type:float default:-- desc:最低原价格
  148. * @return name:total_num type:int default:-- desc:商品总数量
  149. * @return name:detail type:int default:-- desc:商品详情[富文本]
  150. * @return name:first_classify type:int require:0 default:-- desc:一级分类id
  151. * @return name:item_list type:array default:-- desc:商品多规格列表
  152. * @return name:item_list.id type:int default:-- desc:规格id【提交订单时spec_id】
  153. * @return name:item_list.goods_spec type:string default:-- desc:规格
  154. * @return name:item_list.goods_no type:string default:-- desc:规格货号
  155. * @return name:item_list.goods_title:string default:-- desc:规格标题
  156. * @return name:item_list.stock type:int default:-- desc:剩余库存
  157. * @return name:item_list.original_price type:float default:-- desc:原价
  158. * @return name:item_list.sell_price type:float default:-- desc:售价
  159. * @return name:item_list.virtual type:int default:-- desc:虚拟销量
  160. * @return name:item_list.weight type:float default:-- desc:重量【kg】
  161. */
  162. public function getGoodsDetail()
  163. {
  164. $goods_id = input('goods_id');
  165. $all_cate = GoodsCate::getCateTree();
  166. $all_cate = array_column($all_cate,null,'id');
  167. $detail = StoreGoods::with(['itemList'])->field('specs,lists',true)->where('id',$goods_id)->find()->toArray();
  168. $detail['max_price'] = max(array_column($detail['item_list'],'original_price'));
  169. $detail['first_classify_name'] = isset($all_cate[$detail['first_classify']]['title']) ? $all_cate[$detail['first_classify']]['title']:'';
  170. $detail['low_original'] = empty($detail['item_list']) ? 0 : min(array_column($detail['item_list'],'original_price'));
  171. $detail['low_price'] = empty($detail['item_list']) ? 0 : min(array_column($detail['item_list'],'sell_price'));
  172. $detail['max_price'] = empty($detail['item_list']) ? 0 : max(array_column($detail['item_list'],'sell_price'));
  173. $detail['content_arr'] = $detail['content'] ? explode('|',$detail['content']) : null;
  174. $this->success('oK',['goods_info'=>$detail]);
  175. }
  176. }