Setting.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\controller\merchant;
  3. use app\extra\basic\Base;
  4. use app\middleware\AuthMiddleware;
  5. use app\model\saas\SaasService;
  6. use app\model\saas\SaasServiceQuick;
  7. use LinFly\Annotation\Attributes\Route\Controller;
  8. use LinFly\Annotation\Attributes\Route\GetMapping;
  9. use LinFly\Annotation\Attributes\Route\Middleware;
  10. use LinFly\Annotation\Attributes\Route\PostMapping;
  11. use support\Request;
  12. use support\Response;
  13. #[Controller("/api/merchant/setting"),Middleware(AuthMiddleware::class)]
  14. class Setting extends Base
  15. {
  16. #[GetMapping('data')]
  17. public function getSetData(Request $request): Response
  18. {
  19. try {
  20. $data = (new SaasService)->where("poi_id",$request->user['store_id'])->with(['quick'])->findOrEmpty();
  21. return success("ok",$data->toArray());
  22. } catch (\Throwable $th) {
  23. return error($th->getMessage());
  24. }
  25. }
  26. #[PostMapping('save')]
  27. public function setSetData(Request $request): Response
  28. {
  29. try {
  30. $param = $request->post();
  31. if (empty($param['type'])) return errorTrans("empty.require");
  32. $data = (new SaasService)->where("poi_id",$request->user['store_id'])->findOrEmpty();
  33. if ($data->isEmpty()) {
  34. $state = $data->strict(false)->insertGetId([
  35. "poi_id" => $request->user['store_id'],
  36. $param['type'] => ($param['type']=='quick'?json_encode($param['content']):$param['content'])
  37. ]);
  38. } else {
  39. $state = $data->strict(false)->save([
  40. $param['type'] => ($param['type']=='quick'?json_encode($param['content']):$param['content'])
  41. ]);
  42. }
  43. if (!$state) return errorTrans("error.data");
  44. return successTrans("success.data");
  45. } catch (\Throwable $th) {
  46. return error($th->getMessage());
  47. }
  48. }
  49. #[PostMapping('quick')]
  50. public function setQuickData(Request $request): Response
  51. {
  52. try {
  53. $param = $request->post();
  54. $param['poi_id'] = $request->user['store_id'];
  55. $state = (new SaasServiceQuick)->setAutoData($param);
  56. if (!$state) return errorTrans("error.data");
  57. return successTrans("success.data");
  58. } catch (\Throwable $throwable) {
  59. return error($throwable->getMessage());
  60. }
  61. }
  62. #[PostMapping('del')]
  63. public function delQuickData(Request $request): Response
  64. {
  65. try {
  66. $param = $this->_valid([
  67. "id.require" => trans("empty.require"),
  68. ],$request->method());
  69. if (!is_array($param)) return error($param);
  70. $quick = (new SaasServiceQuick)->where("id",$param["id"])->findOrEmpty();
  71. if ($quick->isEmpty()) return errorTrans("error.data");
  72. if ($quick['poi_id'] <> $request->user['store_id']) return errorTrans("error.data");
  73. $state = $quick->delete();
  74. if (!$state) return errorTrans("error.data");
  75. return successTrans("success.data");
  76. } catch (\Throwable $throwable) {
  77. return error($throwable->getMessage());
  78. }
  79. }
  80. }