StoreProductController.php 8.9 KB

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