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.

141 lines
4.6 KiB

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