StoreProductController.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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', 'd'], 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. // is_lb 条件处理
  97. if (isset($where['is_lb']) && $where['is_lb'] == 1) {
  98. $where['is_lb'] = 1;
  99. } else {
  100. unset($where['is_lb']);
  101. }
  102. $type = 'big';
  103. $field = ['image', 'recommend_image'];
  104. $list = $this->services->getGoodsList($where, (int)$request->uid());
  105. return app('json')->success(get_thumb_water($list, $type, $field));
  106. }
  107. /**
  108. * 商品分享二维码 推广员
  109. * @param Request $request
  110. * @param $id
  111. * @return mixed
  112. */
  113. public function code(Request $request, $id)
  114. {
  115. if ($request->uid()) {
  116. $user = $request->user();
  117. } else {
  118. $user = ['uid' => 0, 'is_promoter' => 0];
  119. }
  120. $code = $this->services->getCode((int)$id, $request->get('user_type', 'wechat'), $user);
  121. return app('json')->success(['code' => $code]);
  122. }
  123. /**
  124. * 商品详情
  125. * @param Request $request
  126. * @param $id
  127. * @param int $type
  128. * @return mixed
  129. * @throws DataNotFoundException
  130. * @throws DbException
  131. * @throws ModelNotFoundException
  132. */
  133. public function detail(Request $request, $id, $type = 0)
  134. {
  135. $data = $this->services->productDetail($request, (int)$id, (int)$type);
  136. return app('json')->success($data);
  137. }
  138. /**
  139. * 为你推荐
  140. * @param Request $request
  141. * @return mixed
  142. * @throws DataNotFoundException
  143. * @throws DbException
  144. * @throws ModelNotFoundException
  145. */
  146. public function product_hot(Request $request)
  147. {
  148. $vip_user = $request->uid() ? app()->make(UserServices::class)->value(['uid' => $request->uid()], 'is_money_level') : 0;
  149. $list = $this->services->getProducts(['is_hot' => 1, 'is_show' => 1, 'is_del' => 0, 'vip_user' => $vip_user]);
  150. return app('json')->success(get_thumb_water($list, 'mid'));
  151. }
  152. /**
  153. * 获取首页推荐不同类型商品的轮播图和商品
  154. * @param Request $request
  155. * @param $type
  156. * @return mixed
  157. * @throws DataNotFoundException
  158. * @throws DbException
  159. * @throws ModelNotFoundException
  160. */
  161. public function groom_list(Request $request, $type)
  162. {
  163. $info['banner'] = [];
  164. $info['list'] = [];
  165. if ($type == 1) {//TODO 精品推荐
  166. $info['banner'] = sys_data('routine_home_bast_banner') ?: [];//TODO 首页精品推荐图片
  167. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_best');//TODO 精品推荐个数
  168. } else if ($type == 2) {//TODO 热门榜单
  169. $info['banner'] = sys_data('routine_home_hot_banner') ?: [];//TODO 热门榜单 猜你喜欢推荐图片
  170. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_hot');//TODO 热门榜单 猜你喜欢
  171. } else if ($type == 3) {//TODO 首发新品
  172. $info['banner'] = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品推荐图片
  173. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_new');//TODO 首发新品
  174. } else if ($type == 4) {//TODO 促销单品
  175. $info['banner'] = sys_data('routine_home_benefit_banner') ?: [];//TODO 促销单品推荐图片
  176. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_benefit');//TODO 促销单品
  177. } else if ($type == 5) {//TODO 会员商品
  178. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_vip');//TODO 会员商品
  179. }
  180. return app('json')->success($info);
  181. }
  182. /**
  183. * 商品评价数量和好评度
  184. * @param $id
  185. * @return mixed
  186. */
  187. public function reply_config($id)
  188. {
  189. /** @var StoreProductReplyServices $replyService */
  190. $replyService = app()->make(StoreProductReplyServices::class);
  191. $count = $replyService->productReplyCount($id);
  192. return app('json')->success($count);
  193. }
  194. /**
  195. * 获取商品评论
  196. * @param Request $request
  197. * @param $id
  198. * @return mixed
  199. * @throws DataNotFoundException
  200. * @throws DbException
  201. * @throws ModelNotFoundException
  202. */
  203. public function reply_list(Request $request, $id)
  204. {
  205. [$type] = $request->getMore([
  206. [['type', 'd'], 0]
  207. ], true);
  208. /** @var StoreProductReplyServices $replyService */
  209. $replyService = app()->make(StoreProductReplyServices::class);
  210. $list = $replyService->getProductReplyList($id, $type);
  211. return app('json')->success(get_thumb_water($list, 'big', ['pics']));
  212. }
  213. /**
  214. * 获取预售列表
  215. * @param Request $request
  216. * @return mixed
  217. */
  218. public function advanceList(Request $request)
  219. {
  220. $where = $request->getMore([
  221. [['time_type', 'd'], 0]
  222. ]);
  223. return app('json')->success($this->services->getAdvanceList($where));
  224. }
  225. /**
  226. * 获取商品实时价格
  227. * @param Request $request
  228. * @param $id
  229. * @param $unique
  230. * @return \think\Response
  231. * @author wuhaotian
  232. * @email 442384644@qq.com
  233. * @date 2025/2/5
  234. */
  235. public function realPrice(Request $request, $id, $unique)
  236. {
  237. $uid = $request->uid() ?? 0;
  238. if (!$id || !$unique) return app('json')->fail('缺少参数');
  239. return app('json')->success($this->services->realPrice($uid, $id, $unique));
  240. }
  241. }