| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace app\controller\merchant;
- use app\extra\basic\Base;
- use app\middleware\AuthMiddleware;
- use app\model\saas\SaasService;
- use app\model\saas\SaasServiceQuick;
- use LinFly\Annotation\Attributes\Route\Controller;
- use LinFly\Annotation\Attributes\Route\GetMapping;
- use LinFly\Annotation\Attributes\Route\Middleware;
- use LinFly\Annotation\Attributes\Route\PostMapping;
- use support\Request;
- use support\Response;
- #[Controller("/api/merchant/setting"),Middleware(AuthMiddleware::class)]
- class Setting extends Base
- {
- #[GetMapping('data')]
- public function getSetData(Request $request): Response
- {
- try {
- $data = (new SaasService)->where("poi_id",$request->user['store_id'])->with(['quick'])->findOrEmpty();
- return success("ok",$data->toArray());
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- #[PostMapping('save')]
- public function setSetData(Request $request): Response
- {
- try {
- $param = $request->post();
- if (empty($param['type'])) return errorTrans("empty.require");
- $data = (new SaasService)->where("poi_id",$request->user['store_id'])->findOrEmpty();
- if ($data->isEmpty()) {
- $state = $data->strict(false)->insertGetId([
- "poi_id" => $request->user['store_id'],
- $param['type'] => ($param['type']=='quick'?json_encode($param['content']):$param['content'])
- ]);
- } else {
- $state = $data->strict(false)->save([
- $param['type'] => ($param['type']=='quick'?json_encode($param['content']):$param['content'])
- ]);
- }
- if (!$state) return errorTrans("error.data");
- return successTrans("success.data");
- } catch (\Throwable $th) {
- return error($th->getMessage());
- }
- }
- #[PostMapping('quick')]
- public function setQuickData(Request $request): Response
- {
- try {
- $param = $request->post();
- $param['poi_id'] = $request->user['store_id'];
- $state = (new SaasServiceQuick)->setAutoData($param);
- if (!$state) return errorTrans("error.data");
- return successTrans("success.data");
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- #[PostMapping('del')]
- public function delQuickData(Request $request): Response
- {
- try {
- $param = $this->_valid([
- "id.require" => trans("empty.require"),
- ],$request->method());
- if (!is_array($param)) return error($param);
- $quick = (new SaasServiceQuick)->where("id",$param["id"])->findOrEmpty();
- if ($quick->isEmpty()) return errorTrans("error.data");
- if ($quick['poi_id'] <> $request->user['store_id']) return errorTrans("error.data");
- $state = $quick->delete();
- if (!$state) return errorTrans("error.data");
- return successTrans("success.data");
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- }
|