MallIndex.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\DiscountGoods;
  4. use app\common\model\GiftGoods;
  5. use app\common\model\GoodsColumn;
  6. use app\common\model\GoodsOrder;
  7. use app\common\model\GoodsOrderItem;
  8. use app\common\model\InformationArticle;
  9. use app\common\model\InformationGoods;
  10. use app\common\model\MallMenu;
  11. use app\common\model\MenuGoods;
  12. use app\common\model\RegionMenu;
  13. use app\common\model\RegionGoods;
  14. use app\common\model\SeckillActivity;
  15. use app\common\model\SeckillGoods;
  16. use app\common\model\StoreGoods;
  17. use app\common\model\StoreGoodsItem;
  18. use app\common\model\SystemConfig;
  19. /**
  20. * @title 商城首页
  21. * @controller MallIndex
  22. * @package app\api\controller
  23. */
  24. class MallIndex extends Base
  25. {
  26. public function initialize()
  27. {
  28. parent::initialize();
  29. parent::setUid();
  30. }
  31. /**
  32. * @title 获取首页公告
  33. * @desc 获取首页公告
  34. * @author qc
  35. * @url /api/Mall_index/getIndexNotice
  36. * @method GET
  37. * @header name:Authorization require:1 desc:Token
  38. * @return name:detail type:srting default:-- desc:公告内容
  39. */
  40. public function getIndexNotice()
  41. {
  42. $detail = SystemConfig::where(['name'=>'index_notice'])->value('value');
  43. $this->success('ok',['detail'=>$detail]);
  44. }
  45. /**
  46. * @title 获取首页菜单(一级)
  47. * @desc 获取首页菜单(一级)
  48. * @author qc
  49. * @url /api/Mall_index/getIndexMenu
  50. * @method GET
  51. * @header name:Authorization require:1 desc:Token
  52. * @param name:num type:int default:10 desc:查询数量
  53. * @return name:title type:srting default:-- desc:标题
  54. * @return name:logo type:srting default:-- desc:图片路径
  55. */
  56. public function getIndexMenu()
  57. {
  58. $num = input('get.num', 10);
  59. $list = MallMenu::field('id,title,logo')->where('is_deleted', 0)
  60. ->where('pid', 0)
  61. ->order('sort desc ,id desc')
  62. ->limit(0, $num)->select()->toArray();
  63. $this->success('ok', $list);
  64. }
  65. /**
  66. * @title 获取首页菜单(二级)
  67. * @desc 获取首页菜单(二级)
  68. * @author qc
  69. * @url /api/Mall_index/getSecondIndexMenu
  70. * @method GET
  71. * @header name:Authorization require:1 desc:Token
  72. * @param name:id type:int default:-- desc:菜单id
  73. * @return name:title type:srting default:-- desc:标题
  74. * @return name:logo type:srting default:-- desc:图片路径
  75. */
  76. public function getSecondIndexMenu()
  77. {
  78. $pid = input('get.id');
  79. $list = MallMenu::field('id,title,logo')->where('is_deleted', 0)
  80. ->where('pid', $pid)
  81. ->order('sort desc ,id asc')
  82. ->select()->toArray();
  83. $this->success('ok', $list);
  84. }
  85. /**
  86. *
  87. * @title 获取首页菜单关联商品
  88. * @desc 获取首页菜单关联商品
  89. * @author qc
  90. * @url /api/Mall_index/getMallMenuGoods
  91. * @method GET
  92. * @header name:Authorization require:1 desc:Token
  93. * @param name:page type:int default:1 desc:页数
  94. * @param name:page_num type:int default:20 desc:每页数
  95. * @param name:second_id type:int default:-- desc:菜单id(二级菜单id)
  96. * @return name:goods_id type:int default:-- desc:商品id
  97. * @return name:name type:srting default:-- desc:商品名称
  98. * @return name:cover type:srting default:-- desc:图片路径
  99. * @return name:low_price type:float default:-- desc:最低价
  100. * @return name:max_price type:float default:-- desc:下划线价格
  101. */
  102. public function getMallMenuGoods()
  103. {
  104. $second_id = input('get.second_id');
  105. $where = [];
  106. $where[] = ['m.second_menu', '=', $second_id];
  107. $where[] = ['g.is_deleted', '=', 0];
  108. $where[] = ['g.status', '=', 1];
  109. $list = MenuGoods::field('m.id as mid,m.goods_id,g.id,g.name,g.cover,g.desc,g.low_price')->alias('m')
  110. ->where($where)
  111. ->leftJoin('StoreGoods g', 'g.id = m.goods_id')
  112. ->order('m.sort desc ,m.id desc')
  113. ->limit($this->off_set, $this->page_num)
  114. ->select()->toArray();
  115. array_walk($list, function (&$v, $k) {
  116. $v['max_price'] = GoodsOrderItem::where('goods_id', $v['id'])->max('original_price');
  117. });
  118. $this->success('ok', ['list' => $list]);
  119. }
  120. /**
  121. *
  122. * @title 获取首页菜单搭配商品
  123. * @desc 获取首页菜单搭配商品
  124. * @author qc
  125. * @url /api/Mall_index/getRecommendGoods
  126. * @method GET
  127. * @header name:Authorization require:1 desc:Token
  128. * @param name:page type:int default:1 desc:页数
  129. * @param name:page_num type:int default:20 desc:每页数
  130. * @param name:first_id type:int default:-- desc:菜单id(1级菜单id)
  131. * @return name:goods_id type:int default:-- desc:商品id
  132. * @return name:name type:srting default:-- desc:商品名称
  133. * @return name:cover type:srting default:-- desc:图片路径
  134. * @return name:content type:srting default:-- desc:图片(多张用|隔开)
  135. * @return name:low_price type:float default:-- desc:最低价
  136. * @return name:max_price type:float default:-- desc:下划线价格
  137. */
  138. public function getRecommendGoods()
  139. {
  140. $first_id = input('get.first_id');
  141. $where = [];
  142. $where[] = ['m.first_menu', '<>', $first_id];
  143. $where[] = ['g.is_deleted', '=', 0];
  144. $where[] = ['g.status', '=', 1];
  145. $list = MenuGoods::field('m.id as mid,m.goods_id,g.id,g.name,g.cover,g.desc,g.low_price,content')->alias('m')
  146. ->where($where)
  147. ->leftJoin('StoreGoods g', 'g.id = m.goods_id')
  148. ->order('m.sort desc ,m.id desc')
  149. ->limit($this->off_set, $this->page_num)
  150. ->select()->toArray();
  151. array_walk($list, function (&$v, $k) {
  152. $v['max_price'] = GoodsOrderItem::where('goods_id', $v['id'])->max('original_price');
  153. });
  154. $this->success('ok', ['list' => $list]);
  155. }
  156. /**
  157. * @title 获取首页推荐商品区(一级)
  158. * @desc 获取首页推荐商品区(一级)
  159. * @author qc
  160. * @url /api/Mall_index/getIndexRegion
  161. * @method GET
  162. * @header name:Authorization require:1 desc:Token
  163. * @param name:num type:int default:10 desc:查询数量
  164. * @return name:title type:srting default:-- desc:标题
  165. * @return name:desc type:srting default:-- desc:简介
  166. * @return name:logo type:srting default:-- desc:图片路径
  167. */
  168. public function getIndexRegion()
  169. {
  170. $num = input('get.num', 10);
  171. $list = RegionMenu::field('id,title,desc,logo')->where('is_deleted', 0)
  172. ->where('pid', 0)
  173. ->order('sort desc ,id desc')
  174. ->limit(0, $num)->select()->toArray();
  175. $this->success('ok', $list);
  176. }
  177. /**
  178. * @title 获取首页专区详情(最多三级)
  179. * @desc 获取首页专区详情
  180. * @author qc
  181. * @url /api/Mall_index/getRegionMenu
  182. * @method GET
  183. * @header name:Authorization require:1 desc:Token
  184. * @param name:id type:int default:-- desc:专区id
  185. * @return name:title type:srting default:-- desc:标题
  186. * @return name:logo type:srting default:-- desc:图片路径
  187. */
  188. public function getRegionMenu()
  189. {
  190. $id = input('get.id');
  191. $region = RegionMenu::field('id,title,logo,pid')->where('id', $id)->find()->toArray();
  192. $region['children'] = RegionMenu::field('id,title,logo,pid')->where('pid', $region['id'])->where('is_deleted', 0)->select()->toArray();
  193. if (!empty($region['children'])) {
  194. foreach ($region['children'] as $k => $v) {
  195. $region['children'][$k]['children'] = RegionMenu::field('id,title,logo,pid')->where('pid', $v['id'])->where('is_deleted', 0)->select()->toArray();
  196. }
  197. }
  198. $this->success('ok', ['detail' => $region]);
  199. }
  200. /**
  201. * @title 获取首页专区关联商品
  202. * @desc 获取首页专区关联商品
  203. * @author qc
  204. * @url /api/Mall_index/getRegionMenuGoods
  205. * @method GET
  206. * @header name:Authorization require:1 desc:Token
  207. * @param name:page type:int default:1 desc:页数
  208. * @param name:page_num type:int default:20 desc:每页数
  209. * @param name:first_region type:int default:-- desc:第一等级id
  210. * @param name:second_region type:int default:-- desc:第二等级id
  211. * @param name:third_region type:int default:-- desc:第三等级id
  212. * @return name:goods_id type:int default:-- desc:商品id
  213. * @return name:name type:srting default:-- desc:商品名称
  214. * @return name:cover type:srting default:-- desc:图片路径
  215. * @return name:low_price type:float default:-- desc:最低价
  216. * @return name:max_price type:float default:-- desc:下划线价格
  217. */
  218. public function getRegionMenuGoods()
  219. {
  220. $first_region = input('get.first_region');
  221. $second_region = input('get.second_region');
  222. $third_region = input('get.third_region');
  223. $where = [];
  224. if ($first_region) $where[] = ['m.first_region', '=', $first_region];
  225. if ($second_region) $where[] = ['m.second_region', '=', $second_region];
  226. if ($third_region) $where[] = ['m.third_region', '=', $third_region];
  227. $where[] = ['g.is_deleted', '=', 0];
  228. $where[] = ['g.status', '=', 1];
  229. $list = RegionGoods::field('m.id as mid,m.goods_id,g.id,g.name,g.cover,g.desc,g.low_price')->alias('m')
  230. ->where($where)
  231. ->leftJoin('StoreGoods g', 'g.id = m.goods_id')
  232. ->order('m.sort desc ,m.id desc')
  233. ->limit($this->off_set, $this->page_num)
  234. ->select()->toArray();
  235. array_walk($list, function (&$v, $k) {
  236. $v['max_price'] = GoodsOrderItem::where('goods_id', $v['id'])->max('original_price');
  237. });
  238. $this->success('ok', ['list' => $list]);
  239. }
  240. /**
  241. * @title 获取首页商品推荐专栏
  242. * @desc 获取首页商品推荐专栏
  243. * @author qc
  244. * @url /api/Mall_index/getGoodsColumn
  245. * @method GET
  246. * @header name:Authorization require:1 desc:Token
  247. * @return name:title type:srting default:-- desc:标题
  248. * @return name:desc type:srting default:-- desc:描述
  249. */
  250. public function getGoodsColumn()
  251. {
  252. $list = GoodsColumn::field('id,desc,title')->where(['status' => 1, 'is_deleted' => 0])->order('sort desc ,id asc')->select()->toArray();
  253. $this->success('ok', ['list' => $list]);
  254. }
  255. /**
  256. * @title 获取专区模块推荐商品
  257. * @desc 第一个亚健康,第二个礼品心选,第三个秒杀(促销)第四个预售
  258. * @author qc
  259. * @url /api/Mall_index/getRegionRecommend
  260. * @method GET
  261. * @header name:Authorization require:1 desc:Token
  262. * @param name:num type:int default:2 desc:查询数量
  263. * @return name:goods_id type:int default:-- desc:商品id
  264. * @return name:name type:string default:-- desc:商品名
  265. * @return name:low_price type:string default:-- desc:价格
  266. * @return name:cover type:string default:-- desc:封面
  267. */
  268. public function getRegionRecommend()
  269. {
  270. $num = input('get.num',2);
  271. $list = [];
  272. $list[0] = InformationGoods::field('i.id,i.goods_id,g.name,g.low_price,g.cover')
  273. ->alias('i')
  274. ->leftJoin('StoreGoods g','i.goods_id = g.id')
  275. ->order('i.id desc')
  276. ->limit(0,$num)
  277. ->select()->toArray();
  278. $list[1] = GiftGoods::field('i.id,i.goods_id,g.name,g.low_price,g.cover')
  279. ->alias('i')
  280. ->leftJoin('StoreGoods g','i.goods_id = g.id')
  281. ->order('i.is_hot desc,id desc')
  282. ->limit(0,$num)
  283. ->select()->toArray();
  284. $seckill_act = SeckillActivity::where([['status','=',1],['end_time','> time',date('Y-m-d H:i:s')],['is_deleted','=',0]])
  285. ->order('sort desc,id asc')->limit(0,1)->select()->toArray();
  286. if(empty($seckill_act)){
  287. $list[2] = [];
  288. }else{
  289. $list[2] = SeckillGoods::field('i.id,i.goods_id,g.name,g.low_price,g.cover')
  290. ->alias('i')
  291. ->leftJoin('StoreGoods g','i.goods_id = g.id')
  292. ->where('i.act_id',$seckill_act[0]['id'])
  293. ->order('id desc')
  294. ->limit(0,$num)
  295. ->select()->toArray();
  296. }
  297. $list[3] = StoreGoods::field('id goods_id,name,low_price,cover')->where(['is_deleted'=>0,'status'=>1,'is_presell'=>1])->order('sort desc ,id desc')
  298. ->limit(0,$num)->select()->toArray();
  299. $this->success('ok',['list'=>$list]);
  300. }
  301. /**
  302. * @title 获取首页我的康养食品(pc)
  303. * @desc 获取首页我的康养食品(pc)
  304. * @author qc
  305. * @url /api/Mall_index/getBuyInformationGoods
  306. * @method GET
  307. * @param name:page type:int default:1 desc:页数
  308. * @param name:page_num type:int default:20 desc:每页数
  309. * @return name:id type:int default:-- desc:记录id
  310. * @return name:goods_id type:int default:-- desc:商品id
  311. * @return name:spec_id type:int default:-- desc:规格id
  312. * @return name:goods_name type:srting default:-- desc:商品名称
  313. * @return name:cover type:srting default:-- desc:商品图片
  314. * @return name:original_price type:float default:-- desc:交易时原价(下划线)
  315. * @return name:sell_price type:float default:-- desc:交易价格
  316. */
  317. public function getBuyInformationGoods()
  318. {
  319. parent::checkLogin();
  320. $order_ids = GoodsOrder::where(['user_id'=>$this->user_id,'pay_state'=>1])->column('id');
  321. $list = GoodsOrderItem::field('id,goods_id,goods_name,cover,original_price,sell_price')
  322. ->where([['user_id','=',$this->user_id],['belong','=',1],['order_id','in',$order_ids]])
  323. ->order('id desc')
  324. ->limit($this->off_set,$this->page_num)
  325. ->select()->toArray();
  326. $this->success('ok',['list'=>$list]);
  327. }
  328. /**
  329. * @title 获取首页资讯
  330. * @desc 获取首页资讯
  331. * @author qc
  332. * @url /api/Mall_index/getIndexInformation
  333. * @method GET
  334. * @param name:page type:int default:1 desc:页数
  335. * @param name:page_num type:int default:20 desc:每页数
  336. * @return name:new_article type:array default:-- desc:最新资讯
  337. * @return name:new_article.id type:int default:-- desc:资讯id
  338. * @return name:new_article.title type:string default:-- desc:标题
  339. * @return name:new_article.type type:int default:-- desc:1文章2视频
  340. * @return name:top_article type:array default:-- desc:推荐资讯(数据同new_article)
  341. * @return name:hot_article type:array default:-- desc:热门资讯(数据同new_article)
  342. */
  343. public function getIndexInformation()
  344. {
  345. $list = [];
  346. $article_field = 'id,title,cover,type';
  347. // 最新
  348. $new_article = InformationArticle::field($article_field)->where(['status'=>1,'is_deleted'=>0])->order('id desc')->find();
  349. $list['new_article'] = $new_article ? $new_article->toArray():'';
  350. // 推荐
  351. $top_article = InformationArticle::field($article_field)->where(['status'=>1,'is_deleted'=>0,'is_top'=>1])->order('id desc')->find();
  352. $list['top_article'] = $top_article ? $top_article->toArray():'';
  353. // 热门
  354. $hot_article = InformationArticle::field($article_field)->where(['status'=>1,'is_deleted'=>0])->order('read_num desc')->find();
  355. $list['hot_article'] = $hot_article ? $hot_article->toArray():'';
  356. $this->success('ok',['list'=>$list]);
  357. }
  358. }