正在显示
1 个修改的文件
包含
54 行增加
和
0 行删除
@@ -4,6 +4,9 @@ namespace app\admin\controller; | @@ -4,6 +4,9 @@ namespace app\admin\controller; | ||
4 | 4 | ||
5 | use app\admin\model\User; | 5 | use app\admin\model\User; |
6 | use app\common\controller\Backend; | 6 | use app\common\controller\Backend; |
7 | +use think\Db; | ||
8 | +use think\exception\PDOException; | ||
9 | +use think\exception\ValidateException; | ||
7 | 10 | ||
8 | /** | 11 | /** |
9 | * 订单管理 | 12 | * 订单管理 |
@@ -121,5 +124,56 @@ class Cm0order extends Backend | @@ -121,5 +124,56 @@ class Cm0order extends Backend | ||
121 | ]); | 124 | ]); |
122 | } | 125 | } |
123 | 126 | ||
127 | + /** | ||
128 | + * 编辑 | ||
129 | + */ | ||
130 | + public function edit($ids = null) | ||
131 | + { | ||
132 | + $row = $this->model->get($ids); | ||
133 | + if (!$row) { | ||
134 | + $this->error(__('No Results were found')); | ||
135 | + } | ||
136 | + $adminIds = $this->getDataLimitAdminIds(); | ||
137 | + if (is_array($adminIds)) { | ||
138 | + if (!in_array($row[$this->dataLimitField], $adminIds)) { | ||
139 | + $this->error(__('You have no permission')); | ||
140 | + } | ||
141 | + } | ||
142 | + if ($this->request->isPost()) { | ||
143 | + $params = $this->request->post("row/a"); | ||
144 | + if ($params) { | ||
145 | + $params = $this->preExcludeFields($params); | ||
146 | + $result = false; | ||
147 | + Db::startTrans(); | ||
148 | + try { | ||
149 | + //是否采用模型验证 | ||
150 | + if ($this->modelValidate) { | ||
151 | + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | ||
152 | + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | ||
153 | + $row->validateFailException(true)->validate($validate); | ||
154 | + } | ||
155 | + $result = $row->allowField(true)->save($params); | ||
156 | + Db::commit(); | ||
157 | + } catch (ValidateException $e) { | ||
158 | + Db::rollback(); | ||
159 | + $this->error($e->getMessage()); | ||
160 | + } catch (PDOException $e) { | ||
161 | + Db::rollback(); | ||
162 | + $this->error($e->getMessage()); | ||
163 | + } catch (Exception $e) { | ||
164 | + Db::rollback(); | ||
165 | + $this->error($e->getMessage()); | ||
166 | + } | ||
167 | + if ($result !== false) { | ||
168 | + $this->success(); | ||
169 | + } else { | ||
170 | + $this->error(__('No rows were updated')); | ||
171 | + } | ||
172 | + } | ||
173 | + $this->error(__('Parameter %s can not be empty', '')); | ||
174 | + } | ||
175 | + $this->view->assign("row", $row); | ||
176 | + return $this->view->fetch(); | ||
177 | + } | ||
124 | 178 | ||
125 | } | 179 | } |
-
请 注册 或 登录 后发表评论