Accept Merge Request #117: (feature/hant -> develop)

Merge Request: 处理错误

Created By: @todayswind
Accepted By: @todayswind
URL: https://g-bcrc3009.coding.net/p/allocatr/d/allocatr/git/merge/117?initial=true
This commit is contained in:
todayswind 2025-06-05 22:18:02 +08:00 committed by Coding
commit 21c044789f
11 changed files with 152 additions and 47 deletions

View File

@ -34,11 +34,11 @@ class Test extends Command
protected function execute(Input $input, Output $output)
{
dd(config('system_id'));
$order = Order::where('id',140)->find();
AutoDispatchLogic::autoDispatch($order);
dd(2);
$hookParams = [
'dispatch' => (new OrderDispatch())->where('id', 144)->find(),

View File

@ -27,10 +27,10 @@ class AutoDispatchLogic
$order->save();
return false;
}
$admin = Admin::where('id',100)->find();
//$admin = Admin::where('id',$order->admin_id)->find();
$insert = [
'admin_id' => $admin->id,
'admin_user' => '系统',
'admin_id' => config('system_id'),
'admin_user' => config('system_name'),
'order_id' => $order->id,
'type' => 2,
'worker_id' => $worker_id,
@ -45,9 +45,10 @@ class AutoDispatchLogic
$res = $orderDispatch->allowField(true)->save($insert);
$order->status = \app\admin\model\Order::STATUS_DISPATCHED;
$order->dispatch_time = date('Y-m-d H:i:s');
$order->dispatch_admin_id = $admin->id;
$order->dispatch_admin_user =$admin->nickname;
$order->dispatch_admin_id = config('system_id');
$order->dispatch_admin_user = config('system_name');
$order->worker_id = $worker_id;
$order->dispatch_type = 2;
$order->save();

View File

@ -120,7 +120,7 @@ class Order extends Backend
public function index()
{
$this->request->filter(['strip_tags', 'trim']);
$group = \model('auth_group_access')->where('uid',$this->auth->id)->find()->group_id ?? 0;
$group = \model('auth_group_access')->where('uid', $this->auth->id)->find()->group_id ?? 0;
$user = \model('admin')->find($this->auth->id);
@ -132,7 +132,7 @@ class Order extends Backend
return $this->selectpage();
}
$type = request()->get('type',1);
$type = request()->get('type', 1);
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$build = $this->model
@ -148,25 +148,25 @@ class Order extends Backend
$filter = (array)json_decode(input()['filter'] ?? '', true);
$admin_filter = $filter['user.nickname'] ?? false;
if ($admin_filter){
$admin_ids = Admin::where('nickname','like','%'.$admin_filter.'%')->column('id');
$build->whereIn('admin_id',$admin_ids);
if ($admin_filter) {
$admin_ids = Admin::where('nickname', 'like', '%' . $admin_filter . '%')->column('id');
$build->whereIn('admin_id', $admin_ids);
}
if ($type == 1){
$build->where('status','>=', 0);
if ($type == 1) {
$build->where('status', '>=', 0);
}
if ($type == 2){
$build->where('status','<', 0);
if ($type == 2) {
$build->where('status', '<', 0);
}
if ($group == 2 || $group == 6) {
// 生成 SQL 语句
$ids = $user->area_ids??'';
if ($ids == ''){
$ids = $user->area_ids ?? '';
if ($ids == '') {
return ['total' => 0, 'rows' => []];
}
$ids = explode(',',$ids);
$ids = explode(',', $ids);
$area_codes = $this->filterAreaCodes($ids);
$build->where(function ($q) use ($area_codes) {
@ -185,15 +185,15 @@ class Order extends Backend
$q->field('id,area_code,merge_name');
}, 'phone' => function ($q) {
$q->field('id,model');
},'coupon' => function ($q) {
}, 'coupon' => function ($q) {
$q->field('id,code,description');
}])
->order($sort, $order)
->paginate($limit);
foreach ($list as &$item){
foreach ($list as &$item) {
$item->aftersale_btn = false;
if($item->aftersale_id==0 && $this->auth->check('aftersales/aftersale/add') && $item->status == \app\admin\model\Order::STATUS_FINISHED){ //$item->status == \app\admin\model\Order::STATUS_FINISHED &&
if ($item->aftersale_id == 0 && $this->auth->check('aftersales/aftersale/add') && $item->status == \app\admin\model\Order::STATUS_FINISHED) { //$item->status == \app\admin\model\Order::STATUS_FINISHED &&
$item->aftersale_btn = true;
}
}
@ -248,7 +248,7 @@ class Order extends Backend
$result = $this->model->allowField(true)->save($params);
if ($params['dispatch_type'] == 2) {
AutoDispatchLogic::autoDispatch($this->model,$this->auth);
AutoDispatchLogic::autoDispatch($this->model, $this->auth);
}
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
@ -361,9 +361,6 @@ class Order extends Backend
}
public function smart()
{
$this->success(data: Address::smart(request()->get('str')));
@ -466,12 +463,13 @@ class Order extends Backend
$result = false;
Db::startTrans();
try {
$abnormal_title = model('abnormal')->get($params['abnormal_id'])->title ?? '';
$insert = [
'order_id' => $params['order_id'],
'status' => 0,
'level' => $params['level'],
'abnormal_id' => $params['abnormal_id'],
'abnormal_title' => model('abnormal')->get($params['abnormal_id'])->title ?? '',
'abnormal_title' => $abnormal_title,
'detail' => $params['detail'],
'admin_id' => $this->auth->id,
'admin_user' => $this->auth->getUserInfo()['nickname'] ?? '',
@ -479,16 +477,59 @@ class Order extends Backend
'update_time' => now()->format('Y-m-d H:m:s'),
];
Message::create([
'to_id' => $order->admin_id,
'type' => 1,
'title' => '订单报错通知',
'content' => '【订单报错通知】您有一条订单号为' . $order->order_no . '的订单订单信息录入错误,请前往报错订单界面进行查看,并立即处理!'
]);
if ($params['abnormal_id'] == 2 || $params['abnormal_id'] == 3) {
$order->status = \app\admin\model\Order::STATUS_CANCEL;
$order->save();
if (!empty($order->dispatch->id)) {
$orderLogic = new OrderLogic();
$orderLogic->cancelOrderDispatch($order->dispatch, $this->auth, '订单被取消', false);
//日志
$hookparams['order'] = $order;
$hookparams['role'] = 1;
$hookparams['auth'] = $this->auth;
$hookparams['remark'] = $params['remark'] ?? '';
Hook::listen('order_change', $hookparams);
}
$insert['deal_type'] = 2;
$insert['handle_detail'] = '系统取消订单';
$insert['handle_admin_user'] = config('system_name');
$insert['handle_admin_id'] = config('system_id');
$insert['handle_time'] = now()->format('Y-m-d H:i:s');
$insert['status'] = 1;
} else if ($params['abnormal_id'] == 5 || $params['abnormal_id'] == 15) {
$order->status = \app\admin\model\Order::STATUS_DISPATCHING;
$order->save();
if (!empty($order->dispatch->id)) {
$OrderLogic = new OrderLogic();
$OrderLogic->noWorkerCanGetIt($order->dispatch, '系统取消' . $abnormal_title);
AutoDispatchLogic::autoDispatch($order);
}
$insert['deal_type'] = 3;
$insert['handle_detail'] = '系统重新派单';
$insert['handle_admin_user'] = config('system_name');
$insert['handle_admin_id'] = config('system_id');
$insert['handle_time'] = now()->format('Y-m-d H:i:s');
$insert['status'] = 1;
} else {
Message::create([
'to_id' => $order->admin_id,
'type' => 1,
'title' => '订单报错通知',
'content' => '【订单报错通知】您有一条订单号为' . $order->order_no . '的订单订单信息录入错误,请前往报错订单界面进行查看,并立即处理!'
]);
}
$result = \model('order_abnormal')->insert($insert);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
throw $e;
Db::rollback();
$this->error($e->getMessage());
}
@ -536,11 +577,11 @@ class Order extends Backend
if (!empty($order->dispatch->id)) {
$orderLogic = new OrderLogic();
$orderLogic->cancelOrderDispatch($order->dispatch, $this->auth, '订单被取消', false);
$orderLogic->cancelOrderDispatch($order->dispatch, null, '订单被取消', false);
//日志
$hookparams['order'] = $order;
$hookparams['role'] = 1;
$hookparams['auth'] = $this->auth;
$hookparams['auth'] = null;
$hookparams['remark'] = $params['remark'] ?? '';
Hook::listen('order_change', $hookparams);
}

View File

@ -2,13 +2,16 @@
namespace app\admin\controller\orders;
use app\admin\controller\AutoDispatchLogic;
use app\admin\model\Order;
use app\common\controller\Backend;
use app\common\Logic\OrderLogic;
use think\Db;
use think\Exception;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\Hook;
/**
* 订单异常记录
@ -114,7 +117,7 @@ class Abnormal extends Backend
$this->model->validateFailException()->validate($validate);
}
$order = Order::where('id',$params['order_id'])->find();
$order = Order::where('id',$params['order_id'])->find()->with('dispatch');
if(empty($order)){
throw new Exception('请选择订单');
}
@ -124,6 +127,46 @@ class Abnormal extends Backend
$params['abnormal_title'] = $abnormal_title;
$params['admin_id'] = $this->auth->id;
$params['admin_user'] = $this->auth->username;
if ($params['abnormal_id'] == 2 || $params['abnormal_id'] == 3){
$order->status = Order::STATUS_CANCEL;
$order->save();
if (!empty($order->dispatch->id)) {
$orderLogic = new OrderLogic();
$orderLogic->cancelOrderDispatch($order->dispatch, $this->auth, '订单被取消', false);
//日志
$hookparams['order'] = $order;
$hookparams['role'] = 1;
$hookparams['auth'] = $this->auth;
$hookparams['remark'] = $params['remark'] ?? '';
Hook::listen('order_change', $hookparams);
}
$params['deal_type'] = 2;
$params['handle_detail'] = '系统取消订单';
$params['handle_admin_user'] = config('system_name');
$params['handle_admin_id'] = config('system_id');
$params['status'] = 1;
}
if ($params['abnormal_id'] == 5 || $params['abnormal_id'] == 15){
if (!empty($order->dispatch->id)) {
$OrderLogic = new OrderLogic();
$OrderLogic->noWorkerCanGetIt($order->dispatch,'系统取消'.$abnormal_title);
AutoDispatchLogic::autoDispatch($order);
}
$params['deal_type'] =3;
$params['handle_detail'] = '系统重新派单';
$params['handle_admin_user'] = config('system_name');
$params['handle_admin_id'] = config('system_id');
$params['status'] = 1;
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {

View File

@ -10,9 +10,9 @@ return [
'Set status to 1' => '设为已处理',
'Status -1' => '不予处理',
'Set status to -1' => '设为不予处理',
'Abnormal_id' => '异常类型',
'Abnormal_title' => '异常类型',
'Detail' => '异常详情',
'Abnormal_id' => '报错类型',
'Abnormal_title' => '报错类型',
'Detail' => '报错详情',
'Handle_detail' => '处理详情',
'Handle_admin_user' => '处理人',
'Handle_time' => '处理时间',

View File

@ -30,7 +30,17 @@
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">处理方式:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-source" data-live-search="true" title="请选择" data-rule="required" name="row[source]" class="form-control show-tick">
<option value="0"></option>
<option value="1" selected> 修改订单</option>
<option value="2"> 取消订单</option>
<option value="3"> 重新派单</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Handle_detail')}:</label>

View File

@ -92,11 +92,13 @@ class OrderLogic
* 师傅超时未接单的处理逻辑
* @return void
*/
public function noWorkerCanGetIt(OrderDispatch $dispatch)
public function noWorkerCanGetIt(OrderDispatch $dispatch,$remark = null)
{//超过三次,直接取消
Db::startTrans();
try {
$remark = '师傅超时未接单,任务取消';
if (is_null($remark)){
$remark = '师傅超时未接单,任务取消';
}
$this->cancelOrderDispatch($dispatch,null,$remark);
Db::commit();
}catch (Exception $exception){
@ -121,7 +123,7 @@ class OrderLogic
if(!empty($auth)){
$dispatch->admin_user = '管理员:'.$auth->nickname;
}else{
$dispatch->admin_user = '系统';
$dispatch->admin_user = config('system_name');
}
$hookParams = [
'dispatch' => $dispatch,

View File

@ -324,5 +324,7 @@ return [
'mini_program' => [
'app_id' => Env::get('mini_program.app_id', ''),
'secret' => Env::get('mini_program.secret', ''),
]
],
'system_id' => 100,
'system_name' => '系统',
];

View File

@ -69,11 +69,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
fixedRightNumber: 1,
fixedNumber: 3,
fixedColumns: true,
renderDefault:true,
searchFormVisible:true,
search:false,
columns: [
[
{checkbox: true},

View File

@ -48,7 +48,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'abnormal_id', title: __('Abnormal_id'),visible:false},
{field: 'abnormal_title', title: __('Abnormal_title'), operate: false},
{field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"-1":__('Status -1')}, formatter: Table.api.formatter.status},
{field: 'deal_type', title: '处理方式', operate: false,
searchList: {"1": '修改订单', "2": '取消订单', '3': '重新派单','0':'无'},
formatter: Table.api.formatter.label,},
//{field: 'order.customer', title: __('Order.customer'), operate: 'LIKE'},
//{field: 'order.tel', title: __('Order.tel'), operate: 'LIKE'},
// {field: 'order.worker_name', title: __('Order.worker_name'), operate: 'LIKE'},
@ -74,6 +76,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
//title: __('Edit'),
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-success btn-editone',
visible: function (item) {
return item.abnormal_id == 1 || item.abnormal_id == 4;
}
}
],

View File

@ -771,7 +771,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
content: function (value, row, index) {
var width = this.width != undefined ? (this.width.toString().match(/^\d+$/) ? this.width + "px" : this.width) : "250px";
var hover = this.hover != undefined && this.hover ? "autocontent-hover" : "";
return "<div class='autocontent-item " + hover + "' style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + ";'>" + value + "</div>";
return "<div class='autocontent-item " + hover + "' style='white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:" + width + ";'>" + (value??'') + "</div>";
},
status: function (value, row, index) {
var custom = {normal: 'success', hidden: 'gray', deleted: 'danger', locked: 'info'};