You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Exception\ErrorCodeException;
  5. use App\Controller\BaseController;
  6. use App\Model\v3\Employees;
  7. use App\Model\v3\ServicePersonnel;
  8. use App\Request\v3\StoreIndexRequest;
  9. use App\Service\v3\Interfaces\CategoryServiceInterface;
  10. use App\Service\v3\Interfaces\CollectStoreServiceInterface;
  11. use App\Service\v3\Interfaces\GoodsServiceInterface;
  12. use App\Service\v3\Interfaces\StoreServiceInterface;
  13. use Hyperf\Di\Annotation\Inject;
  14. use Psr\Http\Message\ResponseInterface;
  15. use \App\Service\v3\Interfaces\BusinessHoursServiceInterface;
  16. class StoreController extends BaseController
  17. {
  18. /**
  19. * @Inject
  20. * @var StoreServiceInterface
  21. */
  22. protected $storeService;
  23. /**
  24. * @Inject
  25. * @var CategoryServiceInterface
  26. */
  27. protected $categoryService;
  28. /**
  29. * @Inject
  30. * @var CollectStoreServiceInterface
  31. */
  32. protected $collectService;
  33. /**
  34. * @Inject
  35. * @var BusinessHoursServiceInterface
  36. */
  37. protected $businessHoursService;
  38. /**
  39. * @Inject
  40. * @var GoodsServiceInterface
  41. */
  42. protected $goodsService;
  43. /**
  44. * 商户详情页
  45. * 1、商户id用来查询的,还要有user_id
  46. * 2、返回数据,id、logo、name、收藏状态、简介、地址、营业状态、营业时间、联系电话
  47. * 3、返回数据,商品推荐的分类,需要经过商户商品反查
  48. * 4、分类下的商品,则复用商品搜索接口
  49. * @param StoreIndexRequest $request
  50. * @return ResponseInterface
  51. */
  52. public function index(StoreIndexRequest $request)
  53. {
  54. $params = $this->request->all();
  55. $data = $this->storeService->detail($params['store_id']);
  56. if(empty($data)){
  57. $msg = ['plat'=>'/v3/store/index/',"data"=>$params];
  58. throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,'',$msg);
  59. }
  60. $data['is_collected'] = (bool)$this->collectService->check($params['user_id'],$params['store_id']);
  61. $data['goods_types'] = $this->categoryService->allForStore($params['store_id']);
  62. $data['in_business'] = $this->storeService->check($params['store_id']);
  63. if($data['in_business'] === true)
  64. {
  65. $data['in_business_text'] = '营业中';
  66. }else{
  67. $data['in_business_text'] = '休息中';
  68. }
  69. return $this->success(['store' => $data]);
  70. }
  71. public function getBusinessHours()
  72. {
  73. $storeId = $this->request->input('store_id');
  74. $res = $this->businessHoursService->check($storeId);
  75. return $this->success($res);
  76. }
  77. public function updateBusinessHours()
  78. {
  79. $storeId = $this->request->input('store_id');
  80. $isRest = $this->request->input('is_rest','');
  81. $time1 = $this->request->input('time1','');
  82. $time2 = $this->request->input('time2','');
  83. $time3 = $this->request->input('time3','');
  84. $time4 = $this->request->input('time4','');
  85. $res = $this->businessHoursService->do($storeId,$isRest,$time1,$time2,$time3,$time4);
  86. return $this->success($res);
  87. }
  88. public function getGoodsByType()
  89. {
  90. $storeId = $this->request->input('store_id');
  91. $typeId = $this->request->input('type_id','');
  92. $goods = $this->goodsService->getByType($storeId,$typeId);
  93. return $this->success($goods);
  94. }
  95. public function getList()
  96. {
  97. $userId = $this->request->input('user_id');
  98. $page = $this->request->input('page',1);
  99. $pagesize = $this->request->input('pagesize',10);
  100. $employees = Employees::query()
  101. ->where('user_id',$userId)
  102. ->whereJsonContains('position', '30')
  103. ->first();
  104. if(empty($employees)){
  105. return $this->success(['personnel' => false]);
  106. }
  107. $res = $this->storeService->getList($employees->market_id,$page,$pagesize);
  108. return $this->success($res);
  109. }
  110. public function getCategory()
  111. {
  112. $storeId = $this->request->input('store_id');
  113. $res = $data['goods_types'] = $this->categoryService->allForStoreIncludeOff($storeId);
  114. return $this->success(['goods_types' => $res]);
  115. }
  116. public function getListByMarketId()
  117. {
  118. $marketId = $this->request->input('market_id');
  119. $page = $this->request->input('page',1);
  120. $pagesize = $this->request->input('pagesize',10);
  121. $res = $this->storeService->getListByMarketId($marketId,$page,$pagesize);
  122. return $this->success($res);
  123. }
  124. public function updateIsRest()
  125. {
  126. $storeId = $this->request->input('store_id');
  127. $res = $this->storeService->updateIsRest($storeId);
  128. return $this->success($res);
  129. }
  130. }