diff --git a/application/admin/controller/orders/Income.php b/application/admin/controller/orders/Income.php index b2485ef..6c0bdf3 100644 --- a/application/admin/controller/orders/Income.php +++ b/application/admin/controller/orders/Income.php @@ -2,7 +2,11 @@ namespace app\admin\controller\orders; +use app\admin\model\Order; use app\common\controller\Backend; +use think\Db; +use think\exception\PDOException; +use think\exception\ValidateException; /** * 订单收款 @@ -38,4 +42,54 @@ class Income extends Backend */ + + /** + * 添加 + * + * @return string + * @throws \think\Exception + */ + public function add() + { + if (false === $this->request->isPost()) { + + $order_id = $this->request->get('order_id'); + + $order = Order::where('id',$order_id)->find(); + + $this->assign('order',$order); + 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); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $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 . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException()->validate($validate); + } + $params['admin_id'] = $this->auth->id; + $params['admin_user'] = $this->auth->username; + $result = $this->model->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); + } + $this->success(); + } + } diff --git a/application/admin/view/orders/income/add.html b/application/admin/view/orders/income/add.html index c5c6dc0..26cc573 100644 --- a/application/admin/view/orders/income/add.html +++ b/application/admin/view/orders/income/add.html @@ -1,23 +1,23 @@