StoreSpu.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\store\product;
  12. use app\common\repositories\store\product\ProductRepository;
  13. use app\common\repositories\store\StoreCategoryRepository;
  14. use app\common\repositories\system\merchant\MerchantRepository;
  15. use app\common\repositories\user\UserHistoryRepository;
  16. use app\common\repositories\user\UserVisitRepository;
  17. use crmeb\services\CopyCommand;
  18. use think\App;
  19. use crmeb\basic\BaseController;
  20. use app\common\repositories\store\product\SpuRepository;
  21. class StoreSpu extends BaseController
  22. {
  23. protected $userInfo;
  24. protected $repository;
  25. public function __construct(App $app, SpuRepository $repository)
  26. {
  27. parent::__construct($app);
  28. $this->repository = $repository;
  29. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  30. }
  31. /**
  32. * 商品搜索列表
  33. * @return mixed
  34. * @author Qinii
  35. * @day 12/24/20
  36. */
  37. public function lst()
  38. {
  39. [$page, $limit] = $this->getPage();
  40. $where = $this->request->params([
  41. 'keyword',
  42. 'cate_id',
  43. 'cate_pid',
  44. 'order',
  45. 'price_on',
  46. 'price_off',
  47. 'brand_id',
  48. 'pid',
  49. 'mer_cate_id',
  50. 'product_type',
  51. 'action',
  52. 'common',
  53. ['is_trader',''],
  54. 'product_ids',
  55. 'mer_id',
  56. 'filter_params',
  57. 'mer_type_id'
  58. ]);
  59. $where['is_gift_bag'] = 0;
  60. // $where['product_type'] = 0;
  61. $where['order'] = $where['order'] ?: 'star';
  62. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  63. return app('json')->success($data);
  64. }
  65. /**
  66. * 商户的商品搜索列表
  67. * @param $id
  68. * @return mixed
  69. * @author Qinii
  70. * @day 12/24/20
  71. */
  72. public function merProductLst($id)
  73. {
  74. [$page, $limit] = $this->getPage();
  75. $where = $this->request->params([
  76. 'keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid', 'mer_cate_id', ['product_type', 0], 'action', 'common'
  77. ]);
  78. if ($where['action']) unset($where['product_type']);
  79. $where['mer_id'] = $id;
  80. $where['is_gift_bag'] = 0;
  81. $where['order'] = $where['order'] ? $where['order'] : 'sort';
  82. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  83. return app('json')->success($data);
  84. }
  85. /**
  86. * 推荐列表
  87. * @return mixed
  88. * @author Qinii
  89. * @day 12/24/20
  90. */
  91. public function recommend()
  92. {
  93. [$page, $limit] = $this->getPage();
  94. $where = $this->request->params(['common', 'mer_id','latitude','longitude']);
  95. $where['is_gift_bag'] = 0;
  96. //1:星级
  97. //2:用户收藏
  98. //3:创建时间
  99. switch (systemConfig('recommend_type')) {
  100. case '1':
  101. $where['order'] = 'star';
  102. break;
  103. case '2':
  104. $where['order'] = 'sales';
  105. if (!is_null($this->userInfo)) {
  106. $cateId = app()->make(UserHistoryRepository::class)->getRecommend($this->userInfo->uid);
  107. if ($cateId && count($cateId) > 5)
  108. $where['cate_id'] = $cateId;
  109. }
  110. break;
  111. case '3':
  112. $where['order'] = 'create_time';
  113. break;
  114. default:
  115. $where['order'] = 'star';
  116. break;
  117. }
  118. $where['product_type'] = 0;
  119. $where['is_stock'] = 1;
  120. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  121. return app('json')->success($data);
  122. }
  123. /**
  124. * 热门列表
  125. * @return mixed
  126. * @author Qinii
  127. * @day 12/24/20
  128. */
  129. public function hot($type)
  130. {
  131. [$page, $limit] = $this->getPage();
  132. $where = $this->request->params(['common', 'mer_id']);
  133. $where['hot_type'] = $type;
  134. $where['is_gift_bag'] = 0;
  135. $where['order'] = 'star';
  136. $where['product_type'] = 0;
  137. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  138. return app('json')->success($data);
  139. }
  140. /**
  141. * 礼包列表
  142. * @return mixed
  143. * @author Qinii
  144. * @day 12/24/20
  145. */
  146. public function bag()
  147. {
  148. [$page, $limit] = $this->getPage();
  149. $promoter_type = systemConfig('promoter_type');
  150. if ($promoter_type == 0) {
  151. $where['is_gift_bag'] = 1;
  152. $title = '分销礼包';
  153. $msg = '购买任意礼包商品,成为分销员';
  154. } else if($promoter_type == 3) {
  155. $where['is_gift_bag'] = 0;
  156. $title = '满额分销';
  157. $promoter_low_money = systemConfig('promoter_low_money');
  158. if ($promoter_low_money){
  159. $msg = '商城消费满' . $promoter_low_money . '元,即可成为分销员';
  160. } else {
  161. $msg = '商城消费,即可成为分销员';
  162. }
  163. } else {
  164. return app('json')->success([]);
  165. }
  166. $where['order'] = 'rank';
  167. $where['product_type'] = 0;
  168. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  169. $data['promoter_type'] = $promoter_type;
  170. $data['msg'] = $msg;
  171. $data['title'] = $title;
  172. return app('json')->success($data);
  173. }
  174. /**
  175. * 礼包推荐列表
  176. * @return mixed
  177. * @author Qinii
  178. * @day 12/24/20
  179. */
  180. public function bagRecommend()
  181. {
  182. [$page, $limit] = $this->getPage();
  183. $where['is_gift_bag'] = 1;
  184. $where['hot_type'] = 'best';
  185. $where['product_type'] = 0;
  186. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  187. return app('json')->success($data);
  188. }
  189. /**
  190. * 活动分类
  191. * @param $type
  192. * @return \think\response\Json
  193. * @author Qinii
  194. * @day 1/12/21
  195. */
  196. public function activeCategory($type)
  197. {
  198. $data = $this->repository->getActiveCategory($type);
  199. return app('json')->success($data);
  200. }
  201. /**
  202. * 根据标签获取数据
  203. * @return \think\response\Json
  204. * @author Qinii
  205. * @day 8/25/21
  206. */
  207. public function labelsLst()
  208. {
  209. [$page, $limit] = $this->getPage();
  210. $where['is_gift_bag'] = 0;
  211. $merId = $this->request->param('mer_id', 0);
  212. if ($merId) {
  213. $where = ['mer_id' => $merId, 'mer_labels' => $this->request->param('labels')];
  214. } else {
  215. $where = ['sys_labels' => $this->request->param('labels')];
  216. }
  217. $where['product_type'] = 0;
  218. $where['order'] = 'star';
  219. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  220. return app('json')->success($data);
  221. }
  222. public function local($id)
  223. {
  224. [$page, $limit] = $this->getPage();
  225. $merchant = app()->make(MerchantRepository::class)->get($id);
  226. if (!in_array(1, $merchant['delivery_way'])) return app('json')->success(['count' => 0, 'list' => []]);
  227. $where = [
  228. 'is_del' => 0,
  229. 'mer_id' => $id,
  230. 'delivery_way' => 1,
  231. 'is_gift_bag' => 0,
  232. ];
  233. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  234. return app('json')->success($data);
  235. }
  236. /**
  237. * 获取复制口令
  238. * @return \think\response\Json
  239. * @author Qinii
  240. * @day 9/2/21
  241. */
  242. public function copy()
  243. {
  244. $id = $this->request->param('id');
  245. $type = $this->request->param('product_type');
  246. $str = app()->make(CopyCommand::class)->create($id, $type, $this->userInfo);
  247. return app('json')->success(['str' => $str]);
  248. }
  249. public function get($id)
  250. {
  251. return app('json')->success($this->repository->get($id));
  252. }
  253. public function getProductByCoupon()
  254. {
  255. [$page, $limit] = $this->getPage();
  256. $where = $this->request->params([
  257. 'keyword',
  258. 'cate_id',
  259. 'cate_pid',
  260. 'order',
  261. 'price_on',
  262. 'price_off',
  263. 'brand_id',
  264. 'pid',
  265. 'mer_cate_id',
  266. 'coupon_id'
  267. ]);
  268. $where['is_gift_bag'] = 0;
  269. $where['order'] = $where['order'] ? $where['order'] : 'star';
  270. $data = $this->repository->getApiSearchByCoupon($where, $page, $limit, $this->userInfo);
  271. return app('json')->success($data);
  272. }
  273. public function getHotRanking()
  274. {
  275. $cateId = $this->request->param('cate_pid', 0);
  276. $cateId = is_array($cateId) ?: explode(',', $cateId);
  277. $limit = $this->request->param('limit', 15);
  278. $data = [];
  279. foreach ($cateId as $cate_id) {
  280. $cate = app()->make(StoreCategoryRepository::class)->get($cate_id);
  281. $list = $this->repository->getHotRanking($cate_id ?: 0, $limit);
  282. if ($list) {
  283. $data[] = [
  284. 'cate_id' => $cate['store_category_id'] ?? 0,
  285. 'cate_name' => $cate['cate_name'] ?? '总榜',
  286. 'list' => $list,
  287. ];
  288. }
  289. }
  290. return app('json')->success($data);
  291. }
  292. }