get(); $list = $this->service->getList($param); return successTrans(100010,pageFormat($list),200); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 新增/编辑 * @param Request $request * @return Response */ #[Route(path: "save",methods: "post")] public function save(Request $request): Response { try { $param = $request->post(); if (!empty($param['price'])) $param['price'] = $param['price'] * 100; if (!$this->validate->check($param)) return error($this->validate->getError()); $state = $this->model->setAutoData($param); if (!$state) return errorTrans("error.data"); return successTrans("success.data"); } catch (\Throwable $throwable) { echo $throwable->getLine()."\n"; echo $throwable->getFile()."\n"; echo $throwable->getMessage()."\n"; return error($throwable->getMessage()); } } /** * @param Request $request * @return Response */ #[Route(path: "batch",methods: "post")] public function setBatchData(Request $request): Response { try { $param = $this->_valid([ "id.require" => trans("empty.require"), "value.require" => trans("empty.require"), "field.require" => trans("empty.require"), "type.require" => trans("empty.require"), ],"post"); if (!is_array($param)) return error($param); if ($param['type'] == "batch") { $state = $this->model->where("id","in",$param['id'])->save([$param['field'] => $param['value']]); } else { $state = $this->model->where("id",$param['id'])->save([$param['field'] => $param['value']]); } if (!$state) return errorTrans("error.data"); return successTrans("success.data"); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 删除 * @param Request $request * @return Response */ #[Route(path: "del",methods: "post")] public function delUser(Request $request): Response { try { $param = $this->_valid([ "id.require" => trans("empty.require"), "type.default" => "one", ],"post"); if (!is_array($param)) return error($param); if ($param['type'] == "batch") { $state = $this->model->where("id","in",$param['id'])->delete(); } else { $data = $this->model->where("id",$param['id'])->findOrEmpty(); if ($data->isEmpty()) return errorTrans("empty.data"); // 删除其他相关数据 $state = $data->delete(); } if (!$state) return errorTrans("error.data"); return successTrans("success.data"); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } }