Store.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. $data = $this->service->setModel()->getList($request->all(),null,true,['type'],['type' => function($query,$resp){
  39. if (empty($resp['product_type'])) return [];
  40. $productType = json_decode($resp['product_type'],true);
  41. $typeData = [];
  42. foreach ($this->goodsService->productType() as $key => $value) {
  43. if (in_array($value['key'],$productType)) {
  44. $typeData[] = $value['name'];
  45. }
  46. }
  47. return $typeData;
  48. }]);
  49. return successTrans(100010,pageFormat($data),200);
  50. } catch (\Throwable $th) {
  51. return error($th->getMessage());
  52. }
  53. }
  54. /**
  55. * 同步POI门店
  56. * @param Request $request
  57. * @return Response
  58. */
  59. #[GetMapping('sync')]
  60. public function syncStore(Request $request): Response
  61. {
  62. try {
  63. Redis::send("sync-store",[
  64. "appid" => sConf("wechat.appid"),
  65. "secret" => sConf("wechat.secret"),
  66. "account" => sConf("wechat.shop_id"),
  67. ]);
  68. return success("发起成功");
  69. } catch (\Throwable $throwable) {
  70. return error($throwable->getMessage());
  71. }
  72. }
  73. /**
  74. * 编辑代理信息
  75. * @param Request $request
  76. * @return Response
  77. */
  78. #[PostMapping("edit")]
  79. public function setListData(Request $request): Response
  80. {
  81. try {
  82. $param = $request->post();
  83. $factory = $this->model->where("id",$param['id'])->findOrEmpty();
  84. if ($factory->isEmpty()) return errorTrans("error.data");
  85. $state = $this->model->setAutoData($param);
  86. if (!$state) return errorTrans("error.data");
  87. return successTrans("success.data");
  88. } catch (\Throwable $throwable) {
  89. return error($throwable->getMessage());
  90. }
  91. }
  92. /**
  93. * 批量操作
  94. * @param Request $request
  95. * @return Response
  96. */
  97. #[PostMapping("batch")]
  98. public function setGoodsBatch(Request $request): Response
  99. {
  100. try {
  101. $param = $this->_valid([
  102. "id.require" => "参数错误",
  103. "value.require" => "参数错误",
  104. "field.require" => "参数错误",
  105. "type.require" => "参数错误"
  106. ],"post");
  107. if (!is_array($param)) return error($param);
  108. if ($param['type'] == "batch") {
  109. $state = $this->model->where("id","in",$param['id'])->save([$param['field'] => $param['value']]);
  110. } else {
  111. $state = $this->model->where("id",$param['id'])->save([$param['field'] => $param['value']]);
  112. }
  113. if (!$state) return errorTrans("error.data");
  114. return successTrans("success.data");
  115. } catch (\Throwable $throwable) {
  116. return error($throwable->getMessage());
  117. }
  118. }
  119. #[GetMapping("cate")]
  120. public function getCategory(): Response
  121. {
  122. try {
  123. $data = $this->goodsService->productType();
  124. return successTrans("success",compact('data'));
  125. } catch (\Throwable $throwable) {
  126. return error($throwable->getMessage());
  127. }
  128. }
  129. }