StoreSpu.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. 'type'
  59. ]);
  60. $where['is_gift_bag'] = 0;
  61. // $where['product_type'] = 0;
  62. $where['order'] = $where['order'] ?: 'star';
  63. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  64. return app('json')->success($data);
  65. }
  66. /**
  67. * 商户的商品搜索列表
  68. * @param $id
  69. * @return mixed
  70. * @author Qinii
  71. * @day 12/24/20
  72. */
  73. public function merProductLst($id)
  74. {
  75. [$page, $limit] = $this->getPage();
  76. $where = $this->request->params([
  77. 'keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid', 'mer_cate_id', ['product_type', 0], 'action', 'common'
  78. ]);
  79. if ($where['action']) unset($where['product_type']);
  80. $where['mer_id'] = $id;
  81. $where['is_gift_bag'] = 0;
  82. $where['order'] = $where['order'] ? $where['order'] : 'sort';
  83. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  84. return app('json')->success($data);
  85. }
  86. /**
  87. * 推荐列表
  88. * @return mixed
  89. * @author Qinii
  90. * @day 12/24/20
  91. */
  92. public function recommend()
  93. {
  94. [$page, $limit] = $this->getPage();
  95. $where = $this->request->params(['common', 'mer_id','latitude','longitude']);
  96. $where['is_gift_bag'] = 0;
  97. //1:星级
  98. //2:用户收藏
  99. //3:创建时间
  100. switch (systemConfig('recommend_type')) {
  101. case '1':
  102. $where['order'] = 'star';
  103. break;
  104. case '2':
  105. $where['order'] = 'sales';
  106. if (!is_null($this->userInfo)) {
  107. $cateId = app()->make(UserHistoryRepository::class)->getRecommend($this->userInfo->uid);
  108. if ($cateId && count($cateId) > 5)
  109. $where['cate_id'] = $cateId;
  110. }
  111. break;
  112. case '3':
  113. $where['order'] = 'create_time';
  114. break;
  115. default:
  116. $where['order'] = 'star';
  117. break;
  118. }
  119. $where['product_type'] = 0;
  120. $where['is_stock'] = 1;
  121. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  122. return app('json')->success($data);
  123. }
  124. /**
  125. * 热门列表
  126. * @return mixed
  127. * @author Qinii
  128. * @day 12/24/20
  129. */
  130. public function hot($type)
  131. {
  132. [$page, $limit] = $this->getPage();
  133. $where = $this->request->params(['common', 'mer_id']);
  134. $where['hot_type'] = $type;
  135. $where['is_gift_bag'] = 0;
  136. $where['order'] = 'star';
  137. $where['product_type'] = 0;
  138. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  139. return app('json')->success($data);
  140. }
  141. /**
  142. * 礼包列表
  143. * @return mixed
  144. * @author Qinii
  145. * @day 12/24/20
  146. */
  147. public function bag()
  148. {
  149. [$page, $limit] = $this->getPage();
  150. $promoter_type = systemConfig('promoter_type');
  151. if ($promoter_type == 0) {
  152. $where['is_gift_bag'] = 1;
  153. $title = '分销礼包';
  154. $msg = '购买任意礼包商品,成为分销员';
  155. } else if($promoter_type == 3) {
  156. $where['is_gift_bag'] = 0;
  157. $title = '满额分销';
  158. $promoter_low_money = systemConfig('promoter_low_money');
  159. if ($promoter_low_money){
  160. $msg = '商城消费满' . $promoter_low_money . '元,即可成为分销员';
  161. } else {
  162. $msg = '商城消费,即可成为分销员';
  163. }
  164. } else {
  165. return app('json')->success([]);
  166. }
  167. $where['order'] = 'rank';
  168. $where['product_type'] = 0;
  169. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  170. $data['promoter_type'] = $promoter_type;
  171. $data['msg'] = $msg;
  172. $data['title'] = $title;
  173. return app('json')->success($data);
  174. }
  175. /**
  176. * 礼包推荐列表
  177. * @return mixed
  178. * @author Qinii
  179. * @day 12/24/20
  180. */
  181. public function bagRecommend()
  182. {
  183. [$page, $limit] = $this->getPage();
  184. $where['is_gift_bag'] = 1;
  185. $where['hot_type'] = 'best';
  186. $where['product_type'] = 0;
  187. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  188. return app('json')->success($data);
  189. }
  190. /**
  191. * 活动分类
  192. * @param $type
  193. * @return \think\response\Json
  194. * @author Qinii
  195. * @day 1/12/21
  196. */
  197. public function activeCategory($type)
  198. {
  199. $data = $this->repository->getActiveCategory($type);
  200. return app('json')->success($data);
  201. }
  202. /**
  203. * 根据标签获取数据
  204. * @return \think\response\Json
  205. * @author Qinii
  206. * @day 8/25/21
  207. */
  208. public function labelsLst()
  209. {
  210. [$page, $limit] = $this->getPage();
  211. $where['is_gift_bag'] = 0;
  212. $merId = $this->request->param('mer_id', 0);
  213. if ($merId) {
  214. $where = ['mer_id' => $merId, 'mer_labels' => $this->request->param('labels')];
  215. } else {
  216. $where = ['sys_labels' => $this->request->param('labels')];
  217. }
  218. $where['product_type'] = 0;
  219. $where['order'] = 'star';
  220. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  221. return app('json')->success($data);
  222. }
  223. public function local($id)
  224. {
  225. [$page, $limit] = $this->getPage();
  226. $merchant = app()->make(MerchantRepository::class)->get($id);
  227. if (!in_array(1, $merchant['delivery_way'])) return app('json')->success(['count' => 0, 'list' => []]);
  228. $where = [
  229. 'is_del' => 0,
  230. 'mer_id' => $id,
  231. 'delivery_way' => 1,
  232. 'is_gift_bag' => 0,
  233. ];
  234. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  235. return app('json')->success($data);
  236. }
  237. /**
  238. * 获取复制口令
  239. * @return \think\response\Json
  240. * @author Qinii
  241. * @day 9/2/21
  242. */
  243. public function copy()
  244. {
  245. $id = $this->request->param('id');
  246. $type = $this->request->param('product_type');
  247. $str = app()->make(CopyCommand::class)->create($id, $type, $this->userInfo);
  248. return app('json')->success(['str' => $str]);
  249. }
  250. public function get($id)
  251. {
  252. return app('json')->success($this->repository->get($id));
  253. }
  254. public function getProductByCoupon()
  255. {
  256. [$page, $limit] = $this->getPage();
  257. $where = $this->request->params([
  258. 'keyword',
  259. 'cate_id',
  260. 'cate_pid',
  261. 'order',
  262. 'price_on',
  263. 'price_off',
  264. 'brand_id',
  265. 'pid',
  266. 'mer_cate_id',
  267. 'coupon_id'
  268. ]);
  269. $where['is_gift_bag'] = 0;
  270. $where['order'] = $where['order'] ? $where['order'] : 'star';
  271. $data = $this->repository->getApiSearchByCoupon($where, $page, $limit, $this->userInfo);
  272. return app('json')->success($data);
  273. }
  274. public function getHotRanking()
  275. {
  276. $cateId = $this->request->param('cate_pid', 0);
  277. $cateId = is_array($cateId) ?: explode(',', $cateId);
  278. $limit = $this->request->param('limit', 15);
  279. $data = [];
  280. foreach ($cateId as $cate_id) {
  281. $cate = app()->make(StoreCategoryRepository::class)->get($cate_id);
  282. $list = $this->repository->getHotRanking($cate_id ?: 0, $limit);
  283. if ($list) {
  284. $data[] = [
  285. 'cate_id' => $cate['store_category_id'] ?? 0,
  286. 'cate_name' => $cate['cate_name'] ?? '总榜',
  287. 'list' => $list,
  288. ];
  289. }
  290. }
  291. return app('json')->success($data);
  292. }
  293. }