处理错误

This commit is contained in:
hant 2025-06-05 22:01:14 +08:00
parent abdfa0bc28
commit fe115b963e
8 changed files with 106 additions and 41 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

@ -29,8 +29,8 @@ class AutoDispatchLogic
}
//$admin = Admin::where('id',$order->admin_id)->find();
$insert = [
'admin_id' => 1,
'admin_user' => '系统',
'admin_id' => config('system_id'),
'admin_user' => config('system_name'),
'order_id' => $order->id,
'type' => 2,
'worker_id' => $worker_id,
@ -48,6 +48,7 @@ class AutoDispatchLogic
$order->dispatch_admin_id = 1;
$order->dispatch_admin_user = '系统';
$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,6 +2,7 @@
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;
@ -130,10 +131,7 @@ class Abnormal extends Backend
if ($params['abnormal_id'] == 2 || $params['abnormal_id'] == 3){
$order->status = Order::STATUS_CANCEL;
$order->abnormal_id = $params['abnormal_id'];
$order->abnormal_title = $abnormal_title;
$order->save();
if (!empty($order->dispatch->id)) {
$orderLogic = new OrderLogic();
@ -146,8 +144,27 @@ class Abnormal extends Backend
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);

View File

@ -31,7 +31,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Source')}:</label>
<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>

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 = 'sys';
$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

@ -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'},