cancel任务

This commit is contained in:
xman 2025-03-27 14:33:49 +08:00
parent 4c26d857e8
commit 80a65b325f
4 changed files with 58 additions and 64 deletions

View File

@ -228,66 +228,56 @@ class Dispatch2 extends Backend
* @throws DataNotFoundException * @throws DataNotFoundException
* @throws ModelNotFoundException * @throws ModelNotFoundException
*/ */
public function del($ids = null) // public function del($ids = null)
{ // {
if (false === $this->request->isPost()) { // if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters")); // $this->error(__("Invalid parameters"));
} // }
$ids = $ids ?: $this->request->post("ids"); // $ids = $ids ?: $this->request->post("ids");
if (empty($ids)) { // if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids')); // $this->error(__('Parameter %s can not be empty', 'ids'));
} // }
$pk = $this->model->getPk(); // $pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds(); // $adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) { // if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds); // $this->model->where($this->dataLimitField, 'in', $adminIds);
} // }
$list = $this->model->where($pk, 'in', $ids)->whereIn('status', $this->model->deleteStatusList())->select(); // $list = $this->model->where($pk, 'in', $ids)->whereIn('status', $this->model->deleteStatusList())->select();
//
$remark = $this->request->param('remark', ''); // $remark = $this->request->param('remark', '');
//
$count = 0; // $count = 0;
Db::startTrans(); // Db::startTrans();
try { // try {
foreach ($list as $item) { // foreach ($list as $item) {
//$count += $item->delete(); // //$count += $item->delete();
$order = Order::where('id', $item->order_id)->where('status', Order::STATUS_DISPATCHED)->find(); // $order = Order::where('id', $item->order_id)->where('status', Order::STATUS_DISPATCHED)->find();
if (!$order) { // if (!$order) {
$this->error('订单状态已变更,请刷新后操作'); // $this->error('订单状态已变更,请刷新后操作');
} // }
//取消 // //取消
$item->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]); // $item->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]);
//回退订单状态 // //回退订单状态
$order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]); // $order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]);
//
$params['order'] = $order->ref; // $params['order'] = $order->ref;
$params['role'] = 1; // $params['role'] = 1;
$params['auth'] = $this->auth; // $params['auth'] = $this->auth;
$params['remark'] = '派单被取消[ID' . $item->id . '],订单状态回退'; // $params['remark'] = '派单被取消[ID' . $item->id . '],订单状态回退';
if (!empty($remark)) { // if (!empty($remark)) {
$params['remark'] .= ',操作备注:' . $remark; // $params['remark'] .= ',操作备注:' . $remark;
} // }
Hook::listen('order_change', $params); // Hook::listen('order_change', $params);
} // }
Db::commit(); // Db::commit();
} catch (PDOException | Exception $e) { // } catch (PDOException | Exception $e) {
Db::rollback(); // Db::rollback();
throw $e; // throw $e;
$this->error($e->getMessage()); // $this->error($e->getMessage());
} // }
/* if ($count) { //
$this->success(); // $this->error(__('取消成功'));
}*/ // }
$this->error(__('取消成功'));
}
private function getWorkers($workers)
{
foreach ($workers as $worker){
$worker->dist = '100m';
}
return $workers;
}
/** /**
@ -299,7 +289,7 @@ class Dispatch2 extends Backend
* @throws DataNotFoundException * @throws DataNotFoundException
* @throws ModelNotFoundException * @throws ModelNotFoundException
*/ */
public function cancel() public function del()
{ {
if (false === $this->request->isPost()) { if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters")); $this->error(__("Invalid parameters"));
@ -317,6 +307,10 @@ class Dispatch2 extends Backend
} }
$list = $this->model->where($pk, 'in', $ids)->whereIn('status', $this->model->deleteStatusList())->select(); $list = $this->model->where($pk, 'in', $ids)->whereIn('status', $this->model->deleteStatusList())->select();
if(count($list) != count($ids)){
$this->error(__("任务状态不可操作,请刷新页面后再操作"));
}
$remark = $reason; $remark = $reason;
$count = 0; $count = 0;
Db::startTrans(); Db::startTrans();

View File

@ -10,7 +10,7 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label> <label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>
<div class="col-xs-12 col-sm-8"> <div class="col-xs-12 col-sm-8">
<input id="c-order_id" data-field="order_no" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value=""> <input id="c-order_id" data-field="order_no" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value="{$row.order_id|htmlentities}">
</div> </div>
</div> </div>

View File

@ -24,7 +24,7 @@
<a href="javascript:;" class="btn btn-warning btn-add btn-disabled disabled {:$auth->check('orders/abnormal/add')}?'':'hide'}" title="{:__('创建异常')}" ><i class="fa fa-plus"></i> {:__('创建异常')}</a> <a href="javascript:;" class="btn btn-warning btn-add btn-disabled disabled {:$auth->check('orders/abnormal/add')}?'':'hide'}" title="{:__('创建异常')}" ><i class="fa fa-plus"></i> {:__('创建异常')}</a>
<a href="javascript:;" class="btn btn-danger btn-cancel-selected btn-disabled disabled {:$auth->check('orders/dispatch2/cancel')?'':'hide'}" title="{:__('取消任务')}" ><i class="fa fa-trash"></i> {:__('取消任务')}</a> <a href="javascript:;" class="btn btn-danger btn-cancel-selected btn-disabled disabled {:$auth->check('orders/dispatch2/del')?'':'hide'}" title="{:__('取消任务')}" ><i class="fa fa-trash"></i> {:__('取消任务')}</a>

View File

@ -121,7 +121,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($,
//这里可以加入 Ajax 请求处理逻辑 //这里可以加入 Ajax 请求处理逻辑
$.ajax({ $.ajax({
url: 'orders/dispatch2/cancel', url: 'orders/dispatch2/del',
type: 'POST', type: 'POST',
data: { data: {
ids: selectedIds, ids: selectedIds,