Store.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\controller\admin;
  3. use app\extra\basic\Base;
  4. use app\middleware\AuthMiddleware;
  5. use app\model\saas\SaasStore;
  6. use app\service\saas\GoodsService;
  7. use app\service\saas\StoreService;
  8. use DI\Attribute\Inject;
  9. use LinFly\Annotation\Attributes\Route\Controller;
  10. use LinFly\Annotation\Attributes\Route\GetMapping;
  11. use LinFly\Annotation\Attributes\Route\Middleware;
  12. use LinFly\Annotation\Attributes\Route\PostMapping;
  13. use support\Container;
  14. use support\Request;
  15. use support\Response;
  16. use Webman\RedisQueue\Redis;
  17. /**
  18. * POI门店
  19. */
  20. #[Controller("/api/store"),Middleware(AuthMiddleware::class)]
  21. class Store extends Base
  22. {
  23. #[Inject]
  24. protected StoreService $service;
  25. #[Inject]
  26. protected GoodsService $goodsService;
  27. #[Inject]
  28. protected SaasStore $model;
  29. /**
  30. * 数据列表
  31. * @param Request $request
  32. * @return Response
  33. */
  34. #[GetMapping('list')]
  35. public function getStoreData(Request $request): Response
  36. {
  37. try {
  38. $param = $request->all();
  39. $data = $this->service->setModel()->getList($param,null,true,['type'],['type' => function($query,$resp){
  40. if (empty($resp['product_type'])) return [];
  41. $productType = json_decode($resp['product_type'],true);
  42. $typeData = [];
  43. foreach ($this->goodsService->productType() as $key => $value) {
  44. if (in_array($value['key'],$productType)) {
  45. $typeData[] = $value['name'];
  46. }
  47. }
  48. return $typeData;
  49. }]);
  50. return successTrans(100010,pageFormat($data),200);
  51. } catch (\Throwable $th) {
  52. return error($th->getMessage());
  53. }
  54. }
  55. /**
  56. * 同步POI门店
  57. * @param Request $request
  58. * @return Response
  59. */
  60. #[GetMapping('sync')]
  61. public function syncStore(Request $request): Response
  62. {
  63. try {
  64. Redis::send("sync-store",[
  65. "appid" => sConf("wechat.appid"),
  66. "secret" => sConf("wechat.secret"),
  67. "account" => sConf("wechat.shop_id"),
  68. ]);
  69. return success("发起成功");
  70. } catch (\Throwable $throwable) {
  71. return error($throwable->getMessage());
  72. }
  73. }
  74. /**
  75. * 编辑代理信息
  76. * @param Request $request
  77. * @return Response
  78. */
  79. #[PostMapping("edit")]
  80. public function setListData(Request $request): Response
  81. {
  82. try {
  83. $param = $request->post();
  84. $factory = $this->model->where("id",$param['id'])->findOrEmpty();
  85. if ($factory->isEmpty()) return errorTrans("error.data");
  86. $state = $this->model->setAutoData($param);
  87. if (!$state) return errorTrans("error.data");
  88. return successTrans("success.data");
  89. } catch (\Throwable $throwable) {
  90. return error($throwable->getMessage());
  91. }
  92. }
  93. /**
  94. * 批量操作
  95. * @param Request $request
  96. * @return Response
  97. */
  98. #[PostMapping("batch")]
  99. public function setGoodsBatch(Request $request): Response
  100. {
  101. try {
  102. $param = $this->_valid([
  103. "id.require" => "参数错误",
  104. "value.require" => "参数错误",
  105. "field.require" => "参数错误",
  106. "type.require" => "参数错误"
  107. ],"post");
  108. if (!is_array($param)) return error($param);
  109. if ($param['type'] == "batch") {
  110. $state = $this->model->where("id","in",$param['id'])->save([$param['field'] => $param['value']]);
  111. } else {
  112. $state = $this->model->where("id",$param['id'])->save([$param['field'] => $param['value']]);
  113. }
  114. if (!$state) return errorTrans("error.data");
  115. return successTrans("success.data");
  116. } catch (\Throwable $throwable) {
  117. return error($throwable->getMessage());
  118. }
  119. }
  120. #[GetMapping("cate")]
  121. public function getCategory(): Response
  122. {
  123. try {
  124. $data = $this->goodsService->productType();
  125. return successTrans("success",compact('data'));
  126. } catch (\Throwable $throwable) {
  127. return error($throwable->getMessage());
  128. }
  129. }
  130. }