Expedite.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\Client\AlibabaCloud;
  4. use AlibabaCloud\Client\Exception\ClientException;
  5. use AlibabaCloud\Client\Exception\ServerException;
  6. use app\common\model\CouponConfig;
  7. use app\common\model\ExchangeGoods;
  8. use app\common\model\GoodsCate;
  9. use app\common\model\GoodsSeason;
  10. use app\common\model\GoodsSellInfo;
  11. use app\common\model\GoodsServe;
  12. use app\common\model\GoodsTerritory;
  13. use app\common\model\MallMenu;
  14. use app\common\model\OrderComment;
  15. use app\common\model\ReductionActivity;
  16. use app\common\model\RemarkLabel;
  17. use app\common\model\StoreGoods;
  18. use app\common\model\StoreGoodsItem;
  19. use app\common\model\TopSearch;
  20. use app\common\model\UserCollect;
  21. use app\common\model\UserTrack;
  22. use app\common\service\Activity;
  23. use think\Db;
  24. /**
  25. * @title 不需要验证token接口(商品列表等)
  26. * @controller Expedite
  27. * @package app\api\controller
  28. */
  29. class Expedite extends Base
  30. {
  31. public function initialize(){
  32. parent::initialize();
  33. parent::setUid();
  34. }
  35. /**
  36. * @title 获取首页轮播图(广告位)
  37. * @desc 获取首页轮播图(广告位)
  38. * @author qc
  39. * @url /api/Expedite/getBanner
  40. * @method GET
  41. * @header name:Authorization require:1 desc:Token
  42. * @param name:place type:int default:1 desc:展示位置1商城首页2营养百科3视频专栏4商城商品5商城活动6商城分类7商城广告8预售
  43. * @param name:num type:int default:5 desc:查询数量
  44. * @return name:cover type:srting default:-- desc:图片路径
  45. * @return name:link type:srting default:-- desc:链接
  46. */
  47. public function getBanner()
  48. {
  49. $num = input('get.num',5);
  50. $place = input('get.place',1);
  51. $list = Db::name('store_banner')
  52. ->field('id,cover,link')
  53. ->where(['is_deleted'=>0,'place'=>$place])
  54. ->limit(0,$num)
  55. ->order('sort desc ,id desc')
  56. ->select();
  57. $this->success('ok',['list'=>$list]);
  58. }
  59. /**
  60. * @title 获取首页小菜单
  61. * @desc 获取首页小菜单
  62. * @author qc
  63. * @url /api/Expedite/getIndexMenu
  64. * @method GET
  65. * @header name:Authorization require:1 desc:Token
  66. * @param name:num type:int default:5 desc:查询数量
  67. * @return name:logo type:srting default:-- desc:图片路径
  68. * @return name:link type:srting default:-- desc:跳转链接
  69. */
  70. public function getIndexMenu()
  71. {
  72. $list = MallMenu::where('is_deleted',0)->where('pid',0)->select()->toArray();
  73. $this->success('ok',$list);
  74. }
  75. /**
  76. * @title 获取商品分类(四级)
  77. * @desc 获取商品分类(四级)
  78. * @author qc
  79. * @url /api/Expedite/getGoodsCate
  80. * @method GET
  81. * @header name:Authorization require:1 desc:Token
  82. * @return name:id type:int default:-- desc:分类id
  83. * @return name:title type:srting default:-- desc:标题
  84. * @return name:logo type:srting default:-- desc:图片路径
  85. * @return name:lev type:srting default:-- desc:分类等级(1,2,3,4)
  86. * @return name:children type:array default:-- desc:下级分类(数据同上)
  87. */
  88. public function getGoodsCate()
  89. {
  90. $list = GoodsCate::getCateTree();
  91. $this->success('ok',['list'=>$list]);
  92. }
  93. /**
  94. * @title 获取商品第一级分类
  95. * @desc 获取商品第一级分类
  96. * @author qc
  97. * @url /api/Expedite/getFirstClassify
  98. * @method GET
  99. * @header name:Authorization require:1 desc:Token
  100. * @return name:id type:int default:-- desc:分类id
  101. * @return name:title type:srting default:-- desc:标题
  102. * @return name:logo type:srting default:-- desc:图片路径
  103. * @return name:lev type:srting default:-- desc:分类等级
  104. */
  105. public function getFirstClassify()
  106. {
  107. $list = GoodsCate::field('id,title,logo,lev')->where('lev',1)->select()->toArray();
  108. $this->success('ok',['list'=>$list]);
  109. }
  110. /**
  111. * @title 获取商品时令设置(二级)
  112. * @desc 获取商品时令设置(二级)
  113. * @author qc
  114. * @url /api/Expedite/getGoodsSeason
  115. * @method GET
  116. * @header name:Authorization require:1 desc:Token
  117. * @return name:id type:int default:-- desc:分类id
  118. * @return name:title type:srting default:-- desc:标题
  119. * @return name:lev type:srting default:-- desc:分类等级(1,2)
  120. * @return name:children type:array default:-- desc:下级分类(数据同上)
  121. */
  122. public function getGoodsSeason()
  123. {
  124. $list = GoodsSeason::getSeasonTree();
  125. $this->success('ok',['list'=>$list]);
  126. }
  127. /**
  128. * @title 获取商品地域设置(二级)
  129. * @desc 获取商品地域设置(二级)
  130. * @author qc
  131. * @url /api/Expedite/getGoodsTerritory
  132. * @method GET
  133. * @header name:Authorization require:1 desc:Token
  134. * @return name:id type:int default:-- desc:分类id
  135. * @return name:title type:srting default:-- desc:标题
  136. * @return name:lev type:srting default:-- desc:分类等级(1,2)
  137. * @return name:children type:array default:-- desc:下级分类(数据同上)
  138. */
  139. public function getGoodsTerritory()
  140. {
  141. $list = GoodsTerritory::getTerritoryTree();
  142. $this->success('ok',['list'=>$list]);
  143. }
  144. /**
  145. * @title 获取商品列表
  146. * @desc 获取商品列表
  147. * @author qc
  148. * @url /api/Expedite/getGoodsList
  149. * @method GET
  150. * @header name:Authorization require:1 desc:Token
  151. * @param name:page type:int default:1 desc:页数
  152. * @param name:page_num type:int default:20 desc:每页数
  153. * @param name:goods_name type:string require:0 default:-- desc:商品名称
  154. * @param name:first_classify type:int require:0 default:-- desc:一级分类id
  155. * @param name:second_classify type:int require:0 default:-- desc:二级分类id
  156. * @param name:third_classify type:int require:0 default:-- desc:三级分类id
  157. * @param name:fourth_classify type:int require:0 default:-- desc:四级分类id
  158. * @param name:is_presell type:int require:0 default:0 desc:是否是预售(0否1是)
  159. * @param name:first_season type:int require:0 default:-- desc:第一级时令id
  160. * @param name:second_season type:int require:0 default:-- desc:第二级时令id
  161. * @param name:first_territory type:int require:0 default:-- desc:第一级地域id
  162. * @param name:second_territory type:int require:0 default:-- desc:第二级地域id
  163. * @param name:column_id type:int require:0 default:-- desc:推荐专栏id
  164. * @param name:is_zx type:int require:0 default:-1 desc:是否是产地直销(-1全部,0否,1是)
  165. * @return name:name type:string default:-- desc:商品名称
  166. * @return name:cover type:string default:-- desc:商品封面图
  167. * @return name:desc type:string default:-- desc:商品简述(副标题)
  168. * @return name:low_price type:float default:-- desc:最低售价
  169. * @return name:low_original type:float default:-- desc:最低原价格
  170. * @return name:total_num type:int default:-- desc:商品总数量
  171. * @return name:detail type:int default:-- desc:商品详情
  172. * @return name:first_classify type:int require:0 default:-- desc:一级分类id
  173. * @return name:second_classify type:int require:0 default:-- desc:二级分类id
  174. * @return name:third_classify type:int require:0 default:-- desc:三级分类id
  175. * @return name:fourth_classify type:int require:0 default:-- desc:四级分类id
  176. * @return name:freight_type type:int default:-- desc:运费类型0固定金额,1运费模板
  177. * @return name:freight_id type:int default:-- desc:模板id(freight_type=1)
  178. * @return name:postage type:float default:-- desc:运费(freight_type=0)
  179. * @return name:share_money type:float default:-- desc:分享返利金额
  180. * @return name:source_pic type:string default:-- desc:商品溯源图(多张)
  181. * @return name:goods_match type:string default:-- desc:商品搭配推荐(多个用|隔开)
  182. * @return name:item_list type:array default:-- desc:商品多规格列表
  183. * @return name:item_list.spec_info type:array default:-- desc:规格型号设置['规格组id'=>'规格id','规格组id'=>'规格id'];
  184. * @return name:item_list.goods_no type:string default:-- desc:规格货号
  185. * @return name:item_list.goods_title:string default:-- desc:规格标题
  186. * @return name:item_list.cover type:string default:-- desc:规格封面
  187. * @return name:item_list.stock type:int default:-- desc:剩余库存
  188. * @return name:item_list.original_price type:float default:-- desc:原价
  189. * @return name:item_list.sell_price type:float default:-- desc:售价
  190. * @return name:item_list.sell_price type:float default:-- desc:售价
  191. * @return name:first_classify_name type:int require:0 default:-- desc:一级分类名
  192. * @return name:second_classify_name type:int require:0 default:-- desc:二级分类名
  193. * @return name:third_classify_name type:int require:0 default:-- desc:三级分类名
  194. * @return name:fourth_classify_name type:int require:0 default:-- desc:四级分类名
  195. * @return name:is_presell type:int require:0 default:-- desc:是否是预售商品(0否1是)
  196. * @return name:sell_time type:string require:0 default:-- desc:预售时间
  197. * @return name:first_season type:int require:0 default:0 desc:第一级时令id
  198. * @return name:second_season type:int require:0 default:0 desc:第二级时令id
  199. * @return name:first_territory type:int require:0 default:0 desc:第一级地域id
  200. * @return name:second_territory type:int require:0 default:0 desc:第二级地域id
  201. * @return name:first_season_name type:string require:0 default:0 desc:第一级时令名称
  202. * @return name:second_season_name type:string require:0 default:0 desc:第二级时令名称
  203. * @return name:first_territory_name type:string require:0 default:0 desc:第一级地域名称
  204. * @return name:second_territory_name type:string require:0 default:0 desc:第二级地域名称
  205. */
  206. public function getGoodsList(){
  207. $all_cate = GoodsCate::field('id,title')->select()->toArray();
  208. $all_cate = array_column($all_cate,null,'id');
  209. $all_season = GoodsSeason::field('id,title')->select()->toArray();
  210. $all_season = array_column($all_season,null,'id');
  211. $all_territory= GoodsTerritory::field('id,title')->select()->toArray();
  212. $all_territory = array_column($all_territory,null,'id');
  213. $input = input('get.');
  214. $sel_where = [];
  215. $sel_where[] = ['status','=',1];
  216. $sel_where[] = ['is_deleted','=',0];
  217. if(isset_full($input,'goods_name'))$sel_where[] = ['name','like',"%".$input['goods_name']."%"];
  218. if(isset_full($input,'first_classify'))$sel_where[] = ['first_classify','=',$input['first_classify']];
  219. if(isset_full($input,'second_classify'))$sel_where[] = ['second_classify','=',$input['second_classify']];
  220. if(isset_full($input,'third_classify'))$sel_where[] = ['third_classify','=',$input['third_classify']];
  221. if(isset_full($input,'fourth_classify'))$sel_where[] = ['fourth_classify','=',$input['fourth_classify']];
  222. if(isset_full($input,'first_season'))$sel_where[] = ['first_season','=',$input['first_season']];
  223. if(isset_full($input,'second_season'))$sel_where[] = ['second_season','=',$input['second_season']];
  224. if(isset_full($input,'first_territory'))$sel_where[] = ['first_territory','=',$input['first_territory']];
  225. if(isset_full($input,'second_territory'))$sel_where[] = ['second_territory','=',$input['second_territory']];
  226. if(isset_full($input,'column_id'))$sel_where[] = ['column_id','=',$input['column_id']];
  227. if(isset($input['is_zx']) && $input['is_zx'] >=0 ) $sel_where[] = ['is_zx','=',$input['is_zx']];
  228. if(isset_full($input,'is_presell')){
  229. $sel_where[] = ['is_presell','=',$input['is_presell']];
  230. }else{
  231. $sel_where[] = ['is_presell','=',0];
  232. }
  233. $list = StoreGoods::with(['itemList'])->where($sel_where)->limit($this->off_set,$this->page_num)->select()->toArray();
  234. foreach ($list as &$v){
  235. $v['first_classify_name'] = isset($all_cate[$v['first_classify']]['title']) ? $all_cate[$v['first_classify']]['title']:'';
  236. $v['second_classify_name'] = isset($all_cate[$v['second_classify']]['title']) ? $all_cate[$v['second_classify']]['title']:'';
  237. $v['third_classify_name'] = isset($all_cate[$v['third_classify']]['title']) ? $all_cate[$v['third_classify']]['title']:'';
  238. $v['fourth_classify_name'] = isset($all_cate[$v['fourth_classify']]['title']) ?$all_cate[$v['fourth_classify']]['title']:'';
  239. $v['low_original'] = min(array_column($v['item_list'],'original_price'));
  240. $v['low_price'] = min(array_column($v['item_list'],'sell_price'));
  241. $v['first_season_name'] = isset($all_season[$v['first_season']]['title']) ? $all_season[$v['first_season']]['title']:'';
  242. $v['second_season_name'] = isset($all_season[$v['second_season']]['title']) ? $all_season[$v['second_season']]['title']:'';
  243. $v['first_territory_name'] = isset($all_territory[$v['first_territory']]['title']) ? $all_territory[$v['first_territory']]['title']:'';
  244. $v['second_territory_name'] = isset($all_territory[$v['second_territory']]['title']) ? $all_territory[$v['second_territory']]['title']:'';
  245. $v['total_num'] = array_sum(array_column($v['item_list'],'base_stock'));
  246. }
  247. $this->success('ok',['list'=>$list]);
  248. }
  249. /**
  250. * @title 获取商品详情
  251. * @desc 获取商品详情
  252. * @author qc
  253. * @url /api/Expedite/getGoodsDetail
  254. * @method GET
  255. * @header name:Authorization require:1 desc:Token
  256. * @param name:goods_id type:int require:1 default:0 desc:商品id
  257. * @return name:name type:string default:-- desc:商品名称
  258. * @return name:cover type:string default:-- desc:商品封面图
  259. * @return name:desc type:string default:-- desc:商品简述(副标题)
  260. * @return name:low_price type:float default:-- desc:最低价格
  261. * @return name:max_price type:float default:-- desc:最高价格(下划线公用)
  262. * @return name:low_seckill type:float default:-- desc:最低秒杀价格(有秒杀活动)
  263. * @return name:low_group type:float default:-- desc:最低拼团价格(有拼团活动)
  264. * @return name:low_discount type:float default:-- desc:最低折扣价格(有折扣活动)
  265. * @return name:discount type:float default:-- desc:商品折扣(没有折扣为10,有折扣活动,例如75折,值为7.5)
  266. * @return name:freight_type type:int default:-- desc:运费类型0固定金额,1运费模板
  267. * @return name:freight_id type:int default:-- desc:模板id(freight_type=1)
  268. * @return name:postage type:float default:-- desc:运费(freight_type=0)
  269. * @return name:is_collect type:int default:-- desc:是否收藏(1是0否)
  270. * @return name:effect type:string default:-- desc:商品功效(多个用|隔开)
  271. * @return name:explain type:string default:-- desc:商品说明(使用说明)
  272. * @return name:share_money type:float default:-- desc:分享返利金额
  273. * @return name:source_pic type:string default:-- desc:商品溯源图(多张)
  274. * @return name:goods_match type:string default:-- desc:商品搭配推荐(多个用|隔开)
  275. * @return name:remark_title type:array default:-- desc:评论标签(数组)
  276. * @return name:serve_title type:array default:-- desc:服务标签(数组)
  277. * @return name:is_presell type:int require:0 default:-- desc:是否是预售商品(0否1是,预售商品不加购物)
  278. * @return name:sell_time type:string require:0 default:-- desc:预售时间
  279. * @return name:first_season type:int require:0 default:0 desc:第一级时令id
  280. * @return name:second_season type:int require:0 default:0 desc:第二级时令id
  281. * @return name:first_territory type:int require:0 default:0 desc:第一级地域id
  282. * @return name:second_territory type:int require:0 default:0 desc:第二级地域id
  283. * @return name:first_season_name type:string require:0 default:0 desc:第一级时令名称
  284. * @return name:second_season_name type:string require:0 default:0 desc:第二级时令名称
  285. * @return name:first_territory_name type:string require:0 default:0 desc:第一级地域名称
  286. * @return name:second_territory_name type:string require:0 default:0 desc:第二级地域名称
  287. * @return name:item_list type:array default:-- desc:商品多规格列表
  288. * @return name:item_list.spec_info type:array default:-- desc:规格型号设置;
  289. * @return name:item_list.goods_no type:string default:-- desc:规格货号
  290. * @return name:item_list.goods_title:string default:-- desc:规格标题
  291. * @return name:item_list.cover type:string default:-- desc:规格封面
  292. * @return name:item_list.stock type:int default:-- desc:剩余库存
  293. * @return name:item_list.original_price type:float default:-- desc:原价
  294. * @return name:item_list.sell_price type:float default:-- desc:售价
  295. * @return name:item_list.seckill_price type:float default:-- desc:秒杀价(没有秒杀活动则=售价)
  296. * @return name:goods_param type:array default:-- desc:商品相关参数
  297. * @return name:goods_param.title type:string default:-- desc:参数名
  298. * @return name:goods_param.value type:string default:-- desc:参数值
  299. * @return name:seckill type:array default:-- desc:秒杀活动详情(为空:商品没有正在进行的秒杀活动)
  300. * @return name:seckill.start_time type:string default:-- desc:开始时间
  301. * @return name:seckill.end_time type:string default:-- desc:结束时间
  302. * @return name:group type:array default:-- desc:拼团活动
  303. * @return name:group.start_time type:string default:-- desc:开始时间
  304. * @return name:group.end_time type:string default:-- desc:结束时间
  305. * @return name:group.full_num type:int default:-- desc:成团人数
  306. * @return name:discount_act type:array default:-- desc:折扣活动
  307. * @return name:discount_act.id type:int default:-- desc:折扣活动id
  308. * @return name:reduction type:array default:-- desc:满减活动
  309. * @return name:reduction.id type:int default:-- desc:满减活动id
  310. * @return name:reduction.title type:string default:-- desc:满减标题
  311. * @return name:reduction.start_time type:string default:-- desc:满减开始时间
  312. * @return name:reduction.end_time type:string default:-- desc:满减结束时间
  313. * @return name:reduction.act_set type:array default:-- desc:满减设置
  314. * @return name:reduction.act_set.full type:float default:-- desc:满多少
  315. * @return name:reduction.act_set.reduction type:float default:-- desc:减多少
  316. *
  317. */
  318. public function getGoodsDetail()
  319. {
  320. $goods_id = input('goods_id');
  321. if($this->user_id)UserTrack::createTrack($this->user_id,1,$goods_id);
  322. $detail = StoreGoods::with(['itemList'])->field('g.*,p.goods_param')->alias('g')->leftJoin('GoodsParam p','g.base_id = p.goods_id')->where('g.id',$goods_id)->find()->toArray();
  323. if(isset($detail['goods_param']) && !empty($detail['goods_param'])) $detail['goods_param'] = json_decode($detail['goods_param'],true);
  324. $detail['max_price'] = max(array_column($detail['item_list'],'original_price'));
  325. $detail['remark_title'] = RemarkLabel::getRemarkLabelTitle($detail['remark_label']);
  326. $detail['serve_title'] = GoodsServe::getServeLabelTitle($detail['serve_label']);
  327. $detail['first_season_name'] ='';
  328. $detail['first_season_name'] ='';
  329. $detail['first_territory_name'] ='';
  330. $detail['first_season_name'] ='';
  331. if($detail['first_season']) $detail['first_season_name'] = GoodsSeason::where('id',$detail['first_season'])->value('title');
  332. if($detail['second_season']) $detail['second_season_name'] = GoodsSeason::where('id',$detail['second_season'])->value('title');
  333. if($detail['first_territory']) $detail['first_territory_name'] = GoodsTerritory::where('id',$detail['first_territory'])->value('title');
  334. if($detail['second_territory']) $detail['second_territory_name'] = GoodsTerritory::where('id',$detail['second_territory'])->value('title');
  335. $goods_act = Activity::goodsActivityList($goods_id);
  336. $detail['discount'] = 10;
  337. foreach ($detail['item_list'] as $ik=>&$iv)
  338. {
  339. // $iv['stock'] = $iv['depot_item_info']['stock'];// 仓库库存
  340. $iv['seckill_price'] = $iv['sell_price'];
  341. $iv['group_price'] = $iv['sell_price'];
  342. $iv['discount_price'] = $iv['sell_price'];
  343. // 秒杀
  344. if(!empty($goods_act['seckill']['goods'])){
  345. foreach ($goods_act['seckill']['goods']['item'] as $sv){
  346. if($sv['spec_id'] == $iv['id']){
  347. $iv['seckill_price'] = $sv['seckill_price'];
  348. break;
  349. }
  350. }
  351. }
  352. // 拼团
  353. if(!empty($goods_act['group']['goods'])){
  354. foreach ($goods_act['group']['goods']['item'] as $gv){
  355. if($gv['spec_id'] == $iv['id']){
  356. $iv['group_price'] = $gv['group_price'];
  357. break;
  358. }
  359. }
  360. }
  361. // 折扣活动
  362. if(!empty($goods_act['discount']['act'])){
  363. $detail['discount'] = bcdiv($goods_act['discount']['act']['discount'],10,1);
  364. $iv['discount_price'] = bcmul($iv['sell_price'],$goods_act['discount']['act']['discount']/100,2);
  365. }
  366. }
  367. $detail['low_seckill'] = min(array_column($detail['item_list'],'seckill_price'));
  368. $detail['low_group'] = min(array_column($detail['item_list'],'group_price'));
  369. $detail['low_discount'] = min(array_column($detail['item_list'],'discount_price'));
  370. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,1,$goods_id);
  371. $this->success('oK',[
  372. 'goods_info'=>$detail,
  373. 'seckill'=>$goods_act['seckill']['act'],
  374. 'group'=>$goods_act['group']['act'],
  375. 'discount_act'=>$goods_act['discount']['act'],
  376. 'reduction'=>ReductionActivity::getAct(),
  377. ]);
  378. }
  379. /**
  380. * @title 获取商品评论
  381. * @desc 获取商品评论
  382. * @author qc
  383. * @url /api/Expedite/getGoodsComment
  384. * @method GET
  385. * @header name:Authorization require:1 desc:Token
  386. * @param name:page type:int default:1 desc:页数
  387. * @param name:page_num type:int : default:20 desc:每页数
  388. * @param name:goods_id type:string require:0 default:-- desc:商品名称
  389. * @param name:create_at type:string require:0 default:-- desc:时间
  390. * @param name:spec_id type:string require:0 default:-- desc:规格id
  391. * @param name:sort_type type:int require:0 default:-- desc:排序(1,时间,2商品评分,3物流评分,4服务评分)
  392. * @param name:order_by type:int require:0 default:2 desc:排序规则(1升序,2降序)
  393. * @param name:type type:int require:0 default:0 desc:查询类型(0全部,1有图片)
  394. * @return name:spec_id type:string require:0 default:-- desc:规格id
  395. * @return name:content type:string default:-- desc:内容
  396. * @return name:images type:string default:-- desc:图片
  397. * @return name:video type:string default:-- desc:视频
  398. * @return name:goods_core type:int default:-- desc:商品评分
  399. * @return name:wl_core type:int default:-- desc:物流评分
  400. * @return name:serve_core type:int default:-- desc:服务评分
  401. * @return name:user type:array default:-- desc:会员信息
  402. * @return name:user.name type:string default:-- desc:会员名
  403. * @return name:user.headimg type:string default:-- desc:会员头像
  404. * @return name:total type:int default:-- desc:总评论数量
  405. */
  406. public function getGoodsComment()
  407. {
  408. $goods_id = input('get.goods_id');
  409. $spec_id = input('get.spec_id');
  410. $sort_type = input('get.sort_type',0);
  411. $order_by = input('get.order_by',2);
  412. $type = input('get.type',0);
  413. $oby = $order_by == 1 ?'asc' : 'desc';
  414. $where = [];
  415. $where[] = ['goods_id','=',$goods_id];
  416. if($spec_id) $where[] = ['spec_id','=',$spec_id];
  417. if($type) $where[] = ['images','<>',''];
  418. $sort_arr = ['id','id','goods_core','wl_core','serve_core'];
  419. $total = OrderComment::where($where)->count();
  420. $list = OrderComment::with('user')->where($where)
  421. ->order($sort_arr[$sort_type].' '.$oby)
  422. ->limit($this->off_set,$this->page_num)
  423. ->select();
  424. $this->success('ok',['list'=>$list ? $list->toArray():[],'total'=>$total]);
  425. }
  426. /**
  427. * @title 获取平台文案设置
  428. * @desc 获取平台文案设置
  429. * @author qc
  430. * @url /api/Expedite/getSysConfig
  431. * @method GET
  432. * @param name:search_name type:string default:-- desc:根据下面名称查(不传查全部的)
  433. * @return name:agreement type:string default:-- desc:用户协议
  434. * @return name:about_us type:string default:-- desc:关于我们
  435. * @return name:privacy type:string default:-- desc:隐私政策
  436. * @return name:agent_notice type:string default:-- desc:代理商须知
  437. * @return name:partner_item type:string default:-- desc:分销条款
  438. * @return name:refund_desc type:string default:-- desc:退款退货说明
  439. * @return name:user_equity type:string default:-- desc:会员权益
  440. * @return name:integral_channel type:string default:-- desc:积分渠道
  441. * @return name:sign_rule type:string default:-- desc:签到规则
  442. * @return name:write_off type:string default:-- desc:注销须知
  443. * @return name:customer_service type:string default:-- desc:客服设置
  444. */
  445. public function getSysConfig(){
  446. $search_name = input('get.search_name');
  447. $con_name = $search_name? [$search_name] : ['agreement','about_us','privacy','agent_notice','partner_item','refund_desc','user_equity','integral_channel','sign_rule','write_off','customer_service'];
  448. $set = Db::name('system_config')->where('name','in',$con_name)->select();
  449. $ret = [];
  450. foreach ($set as $value) {
  451. $ret[$value['name']]=$value['value'];
  452. }
  453. $this->success('获取成功',$ret);
  454. }
  455. /**
  456. * @title 获取所有的优惠券设置
  457. * @desc 获取所有的优惠券设置
  458. * @author qc
  459. * @method GET
  460. * @url /api/Expedite/getCouponConfig
  461. * @param name:goods_id type:int require:0 default:限制商品id
  462. * @return name:id type:int default:-- desc:会员优惠券记录id
  463. * @return name:coupon_type type:int default:-- desc:优惠券类型0全场券1商品券
  464. * @return name:goods_id type:int default:-- desc:商品id
  465. * @return name:title type:int default:-- desc:标题
  466. * @return name:low_amount type:float default:-- desc:最低消费限制
  467. * @return name:amount type:float default:-- desc:券额
  468. * @return name:time_type type:int default:-- desc:使用时间限制0数限制(low_day)1时间限制(start_tm--end_tm)
  469. * @return name:low_day type:int default:-- desc:限制天数
  470. * @return name:start_tm type:string default:-- desc:开始使用时间
  471. * @return name:end_tm type:string default:-- desc:结束使用时间
  472. * @return name:status type:int default:-- desc:状态 (状态 0:失效 1:正常)
  473. * @return name:create_at type:string default:-- desc:时间
  474. * @return name:num type:int default:-- desc:优惠券总数量
  475. * @return name:user_num type:int default:-- desc:每人限制领取张数0不限制
  476. */
  477. public function getCouponConfig()
  478. {
  479. $goods_id = input('get.goods_id',0);
  480. $where = [];
  481. $where[] = ['is_deleted','=',0];
  482. $where[] = ['status','=',1];
  483. if($goods_id)$where[] = ['goods_id','in',[0,$goods_id]];
  484. $list = CouponConfig::where($where)->order('id desc')->select();
  485. $this->success('ok',['list'=>$list]);
  486. }
  487. /**
  488. * @title 发送短信验证码
  489. * @desc 发送短信验证码
  490. * @author qc
  491. * @url /api/Expedite/sendSms
  492. * @method POST
  493. * @param name:phone type:int require:1 default:-- desc:要获取验证码的手机号
  494. * @return name:code type:string default:-- desc:验证码
  495. */
  496. public function sendSms(){
  497. $phone = input('post.phone');
  498. if(empty($phone)) $this ->error('参数错误');
  499. $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
  500. AlibabaCloud::accessKeyClient('LTAI5tEEfowhMkLu8auo6n6G', 'ch94CL3TEwNAxXNREweZl3gfk8jQ84')
  501. ->regionId('cn-hangzhou')->asDefaultClient();
  502. try {
  503. $result = AlibabaCloud::rpc()
  504. ->product('Dysmsapi')
  505. ->version('2017-05-25')
  506. ->action('SendSms')
  507. ->method('POST')
  508. ->host('dysmsapi.aliyuncs.com')
  509. ->options([
  510. 'query' => [
  511. 'RegionId' => "cn-hangzhou",
  512. 'PhoneNumbers' => $phone,
  513. 'SignName' => "康养食品",
  514. 'TemplateCode' => "SMS_241155218",
  515. 'TemplateParam' => json_encode(array("code"=>$code)),
  516. ],
  517. ])->request();
  518. $result = $result->toArray();
  519. if($result['Code'] == "OK") {
  520. $sms_data = array(
  521. 'phone'=>$phone,
  522. 'code'=>$code,
  523. 'result'=>$result['Message']
  524. );
  525. Db::name('store_member_sms')->insert($sms_data);
  526. $this->success('发送成功',$code);
  527. }else{
  528. $this->error('发送失败');
  529. }
  530. } catch (ClientException $e) {
  531. $this->error($e->getErrorMessage() . PHP_EOL);
  532. } catch (ServerException $e) {
  533. $this->error($e->getErrorMessage() . PHP_EOL);
  534. }
  535. }
  536. /**
  537. * @title 获取商品热搜设置
  538. * @desc 获取商品热搜设置
  539. * @author qc
  540. * @url /api/Expedite/goodsTopSearch
  541. * @method GET
  542. * @return name:title type:string default:-- desc:标题
  543. */
  544. public function goodsTopSearch()
  545. {
  546. $list = TopSearch::field('id,title')->where(['status'=>1,'is_deleted'=>0])->order('sort desc,id desc')->select()->toArray();
  547. $this->success('ok',['list'=>$list]);
  548. }
  549. /**
  550. * @title 获取热销商品
  551. * @desc 获取热销商品
  552. * @author qc
  553. * @url /api/Expedite/getHotSell
  554. * @method GET
  555. * @return name:goods_id type:int default:-- desc:商品id
  556. * @return name:name type:string default:-- desc:商品名
  557. * @return name:cover type:string default:-- desc:商品图片
  558. * @return name:low_price type:float default:-- desc:最低价
  559. * @return name:line_money type:float default:-- desc:下划线价格
  560. */
  561. public function getHotSell()
  562. {
  563. $sel_time = date('Y-m-d H:i:s',strtotime('-70 days'));
  564. $list = GoodsSellInfo::field('i.goods_id,sum(i.num) total_num,g.name,g.cover,g.low_price')->where('i.create_at','> time',$sel_time)
  565. ->alias('i')
  566. ->leftJoin('StoreGoods g','g.id = i.goods_id')
  567. ->group('i.goods_id')
  568. ->order('total_num desc')
  569. ->limit(0,20)
  570. ->select()->toArray();
  571. array_walk($list,function (&$v){
  572. $v['line_money'] = StoreGoodsItem::where(['goods_id'=>$v['goods_id']])->max('original_price');
  573. });
  574. $this->success('ok',['list'=>$list]);
  575. }
  576. }