diff --git a/backend/application/admin/controller/Orders.php b/backend/application/admin/controller/Orders.php index dcb47d6..0dd61f5 100644 --- a/backend/application/admin/controller/Orders.php +++ b/backend/application/admin/controller/Orders.php @@ -48,7 +48,7 @@ class Orders extends Backend if ($this->request->isAjax()) { try { OrderService::orderShip($ids); - $this->success("发货成功", null, ['id' => $ids]); + $this->success("发货成功,请到订单发货管理中编辑并确认发货以通知用户", null, ['id' => $ids]); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; diff --git a/backend/application/admin/controller/order/Ships.php b/backend/application/admin/controller/order/Ships.php index 6e6981c..d58dec3 100644 --- a/backend/application/admin/controller/order/Ships.php +++ b/backend/application/admin/controller/order/Ships.php @@ -3,6 +3,11 @@ namespace app\admin\controller\order; use app\common\controller\Backend; +use app\common\service\OrderService; +use Exception; +use think\Db; +use think\exception\PDOException; +use think\exception\ValidateException; /** * 订单发货管理 @@ -25,13 +30,62 @@ class Ships extends Backend } - - /** - * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 - * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 - * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + * 编辑(选择「确认发货」后保存时发送发货通知) + * @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(); + } } diff --git a/backend/application/admin/lang/zh-cn/order/ships.php b/backend/application/admin/lang/zh-cn/order/ships.php index 4ac2c4f..7095026 100644 --- a/backend/application/admin/lang/zh-cn/order/ships.php +++ b/backend/application/admin/lang/zh-cn/order/ships.php @@ -9,5 +9,7 @@ return [ 'Files' => '多文件', 'Remark' => '备注', 'Createtime' => '添加时间', - 'Updatetime' => '更新时间' + 'Updatetime' => '更新时间', + 'Confirm_ship' => '确认发货', + 'Confirm_ship_tips' => '选择「是」保存后会给用户发送订单发货通知(用户下单时只授权一次,请在发货内容填写完整后再确认)' ]; diff --git a/backend/application/admin/view/order/ships/edit.html b/backend/application/admin/view/order/ships/edit.html index 7f8fb5d..696904e 100644 --- a/backend/application/admin/view/order/ships/edit.html +++ b/backend/application/admin/view/order/ships/edit.html @@ -52,6 +52,18 @@ + {if $canConfirmShip} +