Shop.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\controller\store;
  3. use app\extra\basic\Base;
  4. use app\middleware\AuthMiddleware;
  5. use app\model\saas\SaasStore;
  6. use DI\Attribute\Inject;
  7. use LinFly\Annotation\Route\Controller;
  8. use LinFly\Annotation\Route\Route;
  9. use support\Request;
  10. use support\Response;
  11. use Webman\Annotation\Middleware;
  12. #[Controller(prefix: "/api/store/shop"),Middleware(AuthMiddleware::class)]
  13. class Shop extends Base
  14. {
  15. #[Inject]
  16. protected SaasStore $mode;
  17. #[Route(path: "detail",methods: "get")]
  18. public function getShopDetail(Request $request): Response
  19. {
  20. try {
  21. $map = ["store_id" => $request->user['store_id'],'agent_id' => $request->user['agent_id']];
  22. $detail = $this->mode->where($map)->findOrEmpty();
  23. if ($detail->isEmpty()) return error("店铺信息错误");
  24. return success("ok",$detail->toArray());
  25. } catch (\Throwable $throwable) {
  26. return error($throwable->getMessage());
  27. }
  28. }
  29. /**
  30. * 保存
  31. * @param Request $request
  32. * @return Response
  33. */
  34. #[Route(path: "save",methods: "post")]
  35. public function setUserData(Request $request): Response
  36. {
  37. try {
  38. $param = $request->post();
  39. $store = $this->mode->where("store_id",$request->user['store_id'])->findOrEmpty();
  40. if ($store->isEmpty()) return errorTrans(40015);
  41. $state = $this->mode->setAutoData($param,"store_id");
  42. if (!$state) return errorTrans("error.data");
  43. return successTrans("success.data");
  44. } catch (\Throwable $throwable) {
  45. return error($throwable->getMessage());
  46. }
  47. }
  48. }