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