StoreProductController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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', 0], 0],
  55. ['ids', ''],
  56. [['selectId', 'd'], 0],
  57. [['productId', 'd'], 0],
  58. [['coupon_category_id', 'd'], 0],
  59. ]);
  60. if ($where['selectId'] && (!$where['sid'] || !$where['cid'])) {
  61. if ($services->value(['id' => $where['selectId']], 'pid')) {
  62. $where['sid'] = $where['selectId'];
  63. } else {
  64. $where['cid'] = $where['selectId'];
  65. }
  66. }
  67. if ($where['ids'] && is_string($where['ids'])) {
  68. $where['ids'] = explode(',', $where['ids']);
  69. foreach ($where['ids'] as $key => &$item) {
  70. $where['ids'][$key] = (int)$item;
  71. if ($where['ids'][$key] == 0) unset($where['ids'][$key]);
  72. }
  73. }
  74. if (!$where['ids']) {
  75. unset($where['ids']);
  76. }
  77. $type = 'big';
  78. $field = ['image', 'recommend_image'];
  79. $list = $this->services->getGoodsList($where, (int)$request->uid());
  80. return app('json')->success(get_thumb_water($list, $type, $field));
  81. }
  82. /**
  83. * 商品分享二维码 推广员
  84. * @param Request $request
  85. * @param $id
  86. * @return mixed
  87. */
  88. public function code(Request $request, $id)
  89. {
  90. if ($request->uid()) {
  91. $user = $request->user();
  92. } else {
  93. $user = ['uid' => 0, 'is_promoter' => 0];
  94. }
  95. $code = $this->services->getCode((int)$id, $request->get('user_type', 'wechat'), $user);
  96. return app('json')->success(['code' => $code]);
  97. }
  98. /**
  99. * 商品详情
  100. * @param Request $request
  101. * @param $id
  102. * @param int $type
  103. * @return mixed
  104. * @throws DataNotFoundException
  105. * @throws DbException
  106. * @throws ModelNotFoundException
  107. */
  108. public function detail(Request $request, $id, $type = 0)
  109. {
  110. $data = $this->services->productDetail($request, (int)$id, (int)$type);
  111. return app('json')->success($data);
  112. }
  113. /**
  114. * 为你推荐
  115. * @param Request $request
  116. * @return mixed
  117. * @throws DataNotFoundException
  118. * @throws DbException
  119. * @throws ModelNotFoundException
  120. */
  121. public function product_hot(Request $request)
  122. {
  123. $vip_user = $request->uid() ? app()->make(UserServices::class)->value(['uid' => $request->uid()], 'is_money_level') : 0;
  124. $list = $this->services->getProducts(['is_hot' => 1, 'is_show' => 1, 'is_del' => 0, 'vip_user' => $vip_user]);
  125. return app('json')->success(get_thumb_water($list, 'mid'));
  126. }
  127. /**
  128. * 获取首页推荐不同类型商品的轮播图和商品
  129. * @param Request $request
  130. * @param $type
  131. * @return mixed
  132. * @throws DataNotFoundException
  133. * @throws DbException
  134. * @throws ModelNotFoundException
  135. */
  136. public function groom_list(Request $request, $type)
  137. {
  138. $info['banner'] = [];
  139. $info['list'] = [];
  140. if ($type == 1) {//TODO 精品推荐
  141. $info['banner'] = sys_data('routine_home_bast_banner') ?: [];//TODO 首页精品推荐图片
  142. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_best');//TODO 精品推荐个数
  143. } else if ($type == 2) {//TODO 热门榜单
  144. $info['banner'] = sys_data('routine_home_hot_banner') ?: [];//TODO 热门榜单 猜你喜欢推荐图片
  145. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_hot');//TODO 热门榜单 猜你喜欢
  146. } else if ($type == 3) {//TODO 首发新品
  147. $info['banner'] = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品推荐图片
  148. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_new');//TODO 首发新品
  149. } else if ($type == 4) {//TODO 促销单品
  150. $info['banner'] = sys_data('routine_home_benefit_banner') ?: [];//TODO 促销单品推荐图片
  151. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_benefit');//TODO 促销单品
  152. } else if ($type == 5) {//TODO 会员商品
  153. $info['list'] = $this->services->getRecommendProduct($request->uid(), 'is_vip');//TODO 会员商品
  154. }
  155. return app('json')->success($info);
  156. }
  157. /**
  158. * 商品评价数量和好评度
  159. * @param $id
  160. * @return mixed
  161. */
  162. public function reply_config($id)
  163. {
  164. /** @var StoreProductReplyServices $replyService */
  165. $replyService = app()->make(StoreProductReplyServices::class);
  166. $count = $replyService->productReplyCount($id);
  167. return app('json')->success($count);
  168. }
  169. /**
  170. * 获取商品评论
  171. * @param Request $request
  172. * @param $id
  173. * @return mixed
  174. * @throws DataNotFoundException
  175. * @throws DbException
  176. * @throws ModelNotFoundException
  177. */
  178. public function reply_list(Request $request, $id)
  179. {
  180. [$type] = $request->getMore([
  181. [['type', 'd'], 0]
  182. ], true);
  183. /** @var StoreProductReplyServices $replyService */
  184. $replyService = app()->make(StoreProductReplyServices::class);
  185. $list = $replyService->getProductReplyList($id, $type);
  186. return app('json')->success(get_thumb_water($list, 'big', ['pics']));
  187. }
  188. /**
  189. * 获取预售列表
  190. * @param Request $request
  191. * @return mixed
  192. */
  193. public function advanceList(Request $request)
  194. {
  195. $where = $request->getMore([
  196. [['time_type', 'd'], 0]
  197. ]);
  198. return app('json')->success($this->services->getAdvanceList($where));
  199. }
  200. }