model = new \app\common\model\order\Ships; } /** * 编辑(选择「确认发货」后保存时发送发货通知) * @param $ids * @return string * @throws \think\Exception */ public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } //需求交付发货单由需求流程自行通知,这里只对软件订单发货单提供确认发货 $canConfirmShip = empty($row['demand_id']); if (false === $this->request->isPost()) { $this->view->assign('row', $row); $this->view->assign('canConfirmShip', $canConfirmShip); 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); $confirmShip = $canConfirmShip && $this->request->post('confirm_ship/d', 0) === 1; $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')); } if ($confirmShip) { try { $sent = OrderService::sendShipNotice($row['order_no']); } catch (Exception $e) { $this->error('保存成功,但' . $e->getMessage()); } $this->success($sent ? '保存成功,已发送发货通知' : '保存成功,发货通知发送失败,请查看日志'); } $this->success(); } }