Product.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\cashier;
  12. use app\Request;
  13. use app\services\product\branch\StoreBranchProductServices;
  14. use app\services\product\category\StoreProductCategoryServices;
  15. use app\services\activity\seckill\StoreSeckillServices;
  16. use app\services\product\sku\StoreProductAttrServices;
  17. /**
  18. * 收银台商品控制器
  19. */
  20. class Product extends AuthController
  21. {
  22. /**
  23. * 获取商品一级分类
  24. * @param StoreProductCategoryServices $services
  25. * @return mixed
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public function getOneCategory(StoreProductCategoryServices $services)
  31. {
  32. return $this->success($services->getOneCategory());
  33. }
  34. /**
  35. * 收银台商品列表
  36. * @param Request $request
  37. * @param StoreBranchProductServices $services
  38. * @return mixed
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function getProductList(Request $request, StoreBranchProductServices $services)
  44. {
  45. $where = $request->getMore([
  46. ['store_name', ''],
  47. ['cate_id', 0, '', 'cid'],
  48. ['field_key', ''],
  49. ['staff_id', ''],
  50. ['uid', 0],
  51. ['tourist_uid', ''],//虚拟用户uid
  52. ['show_type', ''],
  53. ]);
  54. $store_id = (int)$this->storeId;
  55. $where['field_key'] = $where['field_key'] == 'all' ? '' : $where['field_key'];
  56. $where['field_key'] = $where['field_key'] == 'id' ? 'product_id' : $where['field_key'];
  57. $where['show_type'] = [0, 2];
  58. $staff_id = (int)$where['staff_id'];
  59. $tourist_uid = (int)$where['tourist_uid'];
  60. $uid = (int)$where['uid'];
  61. unset($where['staff_id'], $where['uid'], $where['tourist_uid']);
  62. return $this->success($services->getCashierProductListV2($where, $store_id, $uid, $staff_id, $tourist_uid));
  63. }
  64. /**
  65. * 获取收银台商品详情
  66. * @param Request $request
  67. * @param StoreBranchProductServices $services
  68. * @param int $id
  69. * @param int $uid
  70. * @return mixed
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public function getProductInfo(Request $request, StoreBranchProductServices $services, $id = 0, $uid = 0)
  76. {
  77. if (!$id) {
  78. return $this->fail('缺少商品id');
  79. }
  80. $touristUid = $request->get('tourist_uid');
  81. return $this->success($services->getProductDetail($this->storeId, (int)$id, (int)$uid, (int)$touristUid));
  82. }
  83. /**
  84. * 获取商品属性
  85. * @param Request $request
  86. * @return mixed
  87. */
  88. public function getProductAttr(Request $request)
  89. {
  90. [$id, $cartNum, $uid] = $request->getMore([
  91. ['id', 0],
  92. ['type', 0],
  93. ['uid', 0]
  94. ], true);
  95. if (!$id) return app('json')->fail('参数错误');
  96. /** @var StoreSeckillServices $seckillServices */
  97. $seckillServices = app()->make(StoreSeckillServices::class);
  98. /** @var StoreProductAttrServices $storeProductAttrServices */
  99. $storeProductAttrServices = app()->make(StoreProductAttrServices::class);
  100. $storeInfo = $seckillServices->getOne(['id' => $id]);
  101. $data['storeInfo'] = $storeInfo ? $storeInfo->toArray() : [];
  102. $data['storeInfo']['store_name'] = $data['storeInfo']['title'] ?? '';
  103. [$data['productAttr'], $data['productValue']] = $storeProductAttrServices->getProductAttrDetail((int)$id, (int)$uid, (int)$cartNum, 1, (int)$storeInfo['product_id']);
  104. return app('json')->successful($data);
  105. }
  106. }