get(); $list = $this->service->getList($param); return successTrans("success.data",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 (!isset($param['id'])) { $param['agent_id'] = CodeExtend::random(16,1,date("md")); if (!empty($param['username'])) { $userName = (new SystemUser)->where("username",$param['username'])->findOrEmpty(); if (!$userName->isEmpty()) return errorTrans("error.user-exist"); } } if (!$this->validate->check($param)) return error($this->validate->getError()); $state = $this->model->setAutoData($param); if (!$state) return errorTrans("error.data"); $param['truename'] = $param['shop_name']; $this->sceneUser($param,2,"id"); return successTrans("success.data"); } catch (\Throwable $throwable) { echo $throwable->getMessage()."\n"; echo $throwable->getFile()."\n"; echo $throwable->getLine()."\n"; return error($throwable->getMessage()); } } /** * 充值套餐 * @param Request $request * @return Response */ #[Route(path: "combo",methods: "post")] public function comboData(Request $request): Response { try { $param = $request->post(); if (empty($param['combo'])) return errorTrans("empty.require"); if (empty($param['shop_id'])) return errorTrans("empty.require"); $combo = (new SaasCombo)->where("id",$param['combo'])->findOrEmpty(); if ($combo->isEmpty()) return errorTrans("empty.data"); $shop = (new SaasAgent)->where("agent_id",$param['shop_id'])->findOrEmpty(); if ($shop->isEmpty()) return errorTrans("empty.data"); if ($combo['unit'] == 1) { // 天 $shop->vip_end = date('Y-m-d H:i:s',strtotime("+{$combo['time']} day")); } else { $shop->vip_end = date('Y-m-d H:i:s',strtotime("+{$combo['time']} year")); } $state = $shop->save(); if (!$state) return errorTrans("error.data"); return successTrans("success.data"); } catch (\Throwable $throwable) { echo $throwable->getMessage()."\n"; echo $throwable->getFile()."\n"; echo $throwable->getLine()."\n"; return error($throwable->getMessage()); } } /** * 新增/编辑代理 * @param Request $request * @return Response */ #[Route(path: "edit",methods: "post")] public function edit(Request $request): Response { try { $param = $request->post(); if (!$this->validate->check($request->post())) 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->getMessage()."\n"; echo $throwable->getFile()."\n"; echo $throwable->getLine()."\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()); } } }