StoreProductController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\v2\product;
  12. use app\Request;
  13. use app\services\product\branch\StoreBranchProductServices;
  14. use app\services\product\product\StoreProductReplyServices;
  15. use app\services\product\product\StoreProductServices;
  16. use app\services\product\sku\StoreProductAttrServices;
  17. use app\services\user\level\SystemUserLevelServices;
  18. use app\services\user\UserServices;
  19. use think\db\exception\DataNotFoundException;
  20. use think\db\exception\DbException;
  21. use think\db\exception\ModelNotFoundException;
  22. class StoreProductController
  23. {
  24. protected $services;
  25. public function __construct(StoreProductServices $services)
  26. {
  27. $this->services = $services;
  28. }
  29. /**
  30. * 获取商品属性
  31. * @param Request $request
  32. * @return \think\Response
  33. * @throws DataNotFoundException
  34. * @throws DbException
  35. * @throws ModelNotFoundException
  36. */
  37. public function getProductAttr(Request $request)
  38. {
  39. [$id, $cartNum] = $request->getMore([
  40. ['id', 0],
  41. ['type', 0]
  42. ], true);
  43. if (!$id) return app('json')->fail('参数错误');
  44. /** @var StoreProductAttrServices $storeProductAttrServices */
  45. $storeProductAttrServices = app()->make(StoreProductAttrServices::class);
  46. $storeInfo = $this->services->getOne(['id' => $id]);
  47. $data['storeInfo'] = $storeInfo ? $storeInfo->toArray() : [];
  48. $discount = 100;
  49. $uid = $request->uid();
  50. if ($uid) {
  51. /** @var UserServices $user */
  52. $user = app()->make(UserServices::class);
  53. $userInfo = $user->getUserCacheInfo($uid);
  54. //用户等级是否开启
  55. /** @var SystemUserLevelServices $systemLevel */
  56. $systemLevel = app()->make(SystemUserLevelServices::class);
  57. $levelInfo = $systemLevel->getLevel((int)($userInfo['level'] ?? 0));
  58. if (sys_config('member_func_status', 1) && $levelInfo) {
  59. $discount = $levelInfo['discount'] ?? 100;
  60. }
  61. }
  62. $minData = $this->services->getMinPrice($uid, $data['storeInfo'], $discount);
  63. $data['storeInfo']['price_type'] = $minData['price_type'] ?? '';
  64. if (!$this->services->vipIsOpen(!!$data['storeInfo']['is_vip'])) $data['storeInfo']['is_vip'] = 0;
  65. [$data['productAttr'], $data['productValue']] = $storeProductAttrServices->getProductAttrDetail($id, $request->uid(), $cartNum, 0, 0, $data['storeInfo']);
  66. return app('json')->successful($data);
  67. }
  68. /**
  69. * 获取商品评论
  70. * @param Request $request
  71. * @param StoreProductReplyServices $services
  72. * @param $id
  73. * @return \think\Response
  74. * @throws DataNotFoundException
  75. * @throws DbException
  76. * @throws ModelNotFoundException
  77. */
  78. public function reply_list(Request $request, StoreProductReplyServices $services, $id)
  79. {
  80. [$type] = $request->getMore([
  81. [['type', 'd'], 0]
  82. ], true);
  83. $list = $services->getNewProductReplyList($id, $type, $request->uid());
  84. return app('json')->successful(get_thumb_water($list, 'small', ['pics']));
  85. }
  86. /**
  87. * 平台商品ID:获取在门店该商品详情
  88. * @param Request $request
  89. * @param StoreBranchProductServices $branchProductServices
  90. * @param $id
  91. * @return \think\Response
  92. */
  93. public function getStoreProductInfo(Request $request, StoreBranchProductServices $branchProductServices, $id)
  94. {
  95. [$store_id] = $request->getMore([
  96. [['store_id', 'd'], 0]
  97. ], true);
  98. if (!$id) {
  99. return app('json')->fail('参数错误');
  100. }
  101. $uid = 0;
  102. if ($request->hasMacro('uid')) $uid = (int)$request->uid();
  103. return app('json')->successful($branchProductServices->getStoreProductInfo($uid, (int)$id, (int)$store_id));
  104. }
  105. }