订单发货优化

This commit is contained in:
Dev
2026-10-14 17:21:51 +08:00
parent cc0c6729a7
commit a070927b15
5 changed files with 101 additions and 14 deletions
@@ -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();
}
}