model = new \app\admin\model\service\info\Projectconfig; } /** * 编辑 * * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function edit($ids = 1) { $row = $this->model->get($ids); if (!$row) { \app\admin\model\service\info\Projectconfig::create(['service_mobile'=>'18200000000','cooperate_mobile'=>'18200000000','user_notice'=>'切换到北京、上海、广州、成都、郑州体验效果更好','skill_notice'=>'这是一个服务端小广播','shop_notice'=>'这是一个商户端小广播','refund_notice'=>'1、这是一个退款注意事项.','state'=>1,'cancel_minute'=>10,'comment_day'=>7]); $row = $this->model->get($ids); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } public function new() { $row = $this->model->get(1); if (!$row) { \app\admin\model\service\info\Projectconfig::create(['service_mobile'=>'18200000000','cooperate_mobile'=>'18200000000','user_notice'=>'切换到北京、上海、广州、成都、郑州体验效果更好','skill_notice'=>'这是一个服务端小广播','shop_notice'=>'这是一个商户端小广播','refund_notice'=>'1、这是一个退款注意事项.','state'=>1,'cancel_minute'=>10,'comment_day'=>7]); $row = $this->model->get(1); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } }