StoreProductController.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1\store;
  12. use app\Request;
  13. use app\services\product\product\StoreCategoryServices;
  14. use app\services\product\product\StoreProductReplyServices;
  15. use app\services\product\product\StoreProductServices;
  16. use app\services\user\UserServices;
  17. use think\db\exception\DataNotFoundException;
  18. use think\db\exception\DbException;
  19. use think\db\exception\ModelNotFoundException;
  20. /**
  21. * 商品类
  22. * Class StoreProductController
  23. * @package app\api\controller\store
  24. */
  25. class StoreProductController
  26. {
  27. /**
  28. * 商品services
  29. * @var StoreProductServices
  30. */
  31. protected $services;
  32. public function __construct(StoreProductServices $services)
  33. {
  34. $this->services = $services;
  35. }
  36. /**
  37. * 商品列表
  38. * @param Request $request
  39. * @param StoreCategoryServices $services
  40. * @return mixed
  41. * @throws DataNotFoundException
  42. * @throws DbException
  43. * @throws ModelNotFoundException
  44. */
  45. public function lst(Request $request, StoreCategoryServices $services)
  46. {
  47. $where = $request->getMore([
  48. [['sid', 'd'], 0],
  49. [['cid', 'd'], 0],
  50. ['keyword', '', '', 'store_name'],
  51. ['priceOrder', ''],
  52. ['salesOrder', ''],
  53. [['news', 'd'], 0, '', 'is_new'],
  54. [['type', 'd'], 0],
  55. ['ids', ''],
  56. [['selectId', 'd'], 0],
  57. [['productId', 'd'], 0],
  58. [['coupon_category_id', 'd'], 0],
  59. ['cate_id', ''],
  60. ['store_label_id', ''],
  61. ['is_lb', 0],
  62. ]);
  63. if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
  64. if ($services->value(['id' => $where['selectId']], 'pid')) {
  65. $where['sid'] = $where['selectId'];
  66. } else {
  67. $where['cid'] = $where['selectId'];
  68. }
  69. }
  70. if ($where['ids'] && is_string($where['ids'])) {
  71. $where['ids'] = explode(',', $where['ids']);
  72. foreach ($where['ids'] as $key => &$item) {
  73. $where['ids'][$key] = (int)$item;
  74. if ($where['ids'][$key] == 0) unset($where['ids'][$key]);
  75. }
  76. }
  77. if (!$where['ids']) {
  78. unset($where['ids']);
  79. }
  80. if ($where['cate_id'] !== '') {
  81. $where['cate_id'] = explode(',', $where['cate_id']);
  82. foreach ($where['cate_id'] as $keys => &$items) {
  83. $where['cate_id'][$keys] = (int)$items;
  84. }
  85. } else {
  86. $where['cate_id'] = [];
  87. }
  88. if ($where['store_label_id'] !== '') {
  89. $where['store_label_id'] = explode(',', $where['store_label_id']);
  90. foreach ($where['store_label_id'] as $keys => &$items) {
  91. $where['store_label_id'][$keys] = (int)$items;
  92. }
  93. } else {
  94. $where['store_label_id'] = [];
  95. }
  96. if (!empty($where['is_lb'])){
  97. // is_lb 条件处理
  98. if (isset($where['is_lb']) && $where['is_lb'] == 1) {
  99. $where['is_lb'] = 1;
  100. }
  101. // else {
  102. // unset($where['is_lb']);
  103. // }
  104. } else {
  105. unset($where['is_lb']);
  106. }
  107. $type = 'big';
  108. $field = ['image', 'recommend_image'];
  109. $list = $this->services->getGoodsList($where, (int)$request->uid());
  110. return app('json')->success(get_thumb_water($list, $type, $field));
  111. }
  112. /**
  113. * 商品分享二维码 推广员
  114. * @param Request $request
  115. * @param $id
  116. * @return mixed
  117. */
  118. public function code(Request $request, $id)
  119. {
  120. if ($request->uid()) {
  121. $user = $request->user();
  122. } else {
  123. $user = ['uid' => 0, 'is_promoter' => 0];
  124. }
  125. $code = $this->services->getCode((int)$id, $request->get('user_type', 'wechat'), $user);
  126. return app('json')->success(['code' => $code]);
  127. }
  128. /**
  129. * 商品详情
  130. * @param Request $request
  131. * @param $id
  132. * @param int $type
  133. * @return mixed
  134. * @throws DataNotFoundException
  135. * @throws DbException
  136. * @throws ModelNotFoundException
  137. */
  138. public function detail(Request $request, $id, $type = 0)
  139. {
  140. $data = $this->services->productDetail($request, (int)$id, (int)$type);
  141. return app('json')->success($data);
  142. }
  143. /**
  144. * 为你推荐
  145. * @param Request $request
  146. * @return mixed
  147. * @throws DataNotFoundException
  148. * @throws DbException
  149. * @throws ModelNotFoundException
  150. */
  151. public function product_hot(Request $request)
  152. {
  153. $vip_user = $request->uid() ? app()->make(UserServices::class)->value(['uid' => $request->uid()], 'is_money_level') : 0;
  154. $list = $this->services->getProducts(['is_hot' => 1, 'is_show' => 1, 'is_del' => 0, 'vip_user' => $vip_user]);
  155. return app('json')->success(get_thumb_water($list, 'mid'));
  156. }
  157. /**
  158. * 获取首页推荐不同类型商品的轮播图和商品
  159. * @param Request $request
  160. * @param $type
  161. * @return mixed
  162. * @throws DataNotFoundException
  163. * @throws DbException
  164. * @throws ModelNotFoundException
  165. */
  166. public function groom_list(Request $request, $type)
  167. {
  168. $info['banner'] = [];
  169. $info['list'] = [];
  170. if ($type == 1) {//TODO 精品推荐
  171. $info['banner'] = sys_data('routine_home_bast_banner') ?: [];//TODO 首页精品推荐图片
  172. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_best');//TODO 精品推荐个数
  173. } else if ($type == 2) {//TODO 热门榜单
  174. $info['banner'] = sys_data('routine_home_hot_banner') ?: [];//TODO 热门榜单 猜你喜欢推荐图片
  175. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_hot');//TODO 热门榜单 猜你喜欢
  176. } else if ($type == 3) {//TODO 首发新品
  177. $info['banner'] = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品推荐图片
  178. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_new');//TODO 首发新品
  179. } else if ($type == 4) {//TODO 促销单品
  180. $info['banner'] = sys_data('routine_home_benefit_banner') ?: [];//TODO 促销单品推荐图片
  181. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_benefit');//TODO 促销单品
  182. } else if ($type == 5) {//TODO 会员商品
  183. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_vip');//TODO 会员商品
  184. }
  185. return app('json')->success($info);
  186. }
  187. /**
  188. * 商品评价数量和好评度
  189. * @param $id
  190. * @return mixed
  191. */
  192. public function reply_config($id)
  193. {
  194. /** @var StoreProductReplyServices $replyService */
  195. $replyService = app()->make(StoreProductReplyServices::class);
  196. $count = $replyService->productReplyCount($id);
  197. return app('json')->success($count);
  198. }
  199. /**
  200. * 获取商品评论
  201. * @param Request $request
  202. * @param $id
  203. * @return mixed
  204. * @throws DataNotFoundException
  205. * @throws DbException
  206. * @throws ModelNotFoundException
  207. */
  208. public function reply_list(Request $request, $id)
  209. {
  210. [$type] = $request->getMore([
  211. [['type', 'd'], 0]
  212. ], true);
  213. /** @var StoreProductReplyServices $replyService */
  214. $replyService = app()->make(StoreProductReplyServices::class);
  215. $list = $replyService->getProductReplyList($id, $type);
  216. return app('json')->success(get_thumb_water($list, 'big', ['pics']));
  217. }
  218. /**
  219. * 获取预售列表
  220. * @param Request $request
  221. * @return mixed
  222. */
  223. public function advanceList(Request $request)
  224. {
  225. $where = $request->getMore([
  226. [['time_type', 'd'], 0]
  227. ]);
  228. return app('json')->success($this->services->getAdvanceList($where));
  229. }
  230. /**
  231. * 获取商品实时价格
  232. * @param Request $request
  233. * @param $id
  234. * @param $unique
  235. * @return \think\Response
  236. * @author wuhaotian
  237. * @email 442384644@qq.com
  238. * @date 2025/2/5
  239. */
  240. public function realPrice(Request $request, $id, $unique)
  241. {
  242. $uid = $request->uid() ?? 0;
  243. if (!$id || !$unique) return app('json')->fail('缺少参数');
  244. return app('json')->success($this->services->realPrice($uid, $id, $unique));
  245. }
  246. }