hook
This commit is contained in:
parent
8316a1dfdc
commit
24dc01baf3
|
|
@ -27,7 +27,7 @@ class OrderLog
|
|||
'role' => $role,
|
||||
'remark' => $remark,
|
||||
'admin_id' => $auth->id ?? 0,
|
||||
'admin_user' => $role==1 ? $auth->nickname : $auth->name
|
||||
'admin_user' => $role==1 ? ($auth->nickname ?? 'sys') : $auth->name
|
||||
];
|
||||
(new \app\admin\model\OrderLog())->save($data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -353,6 +353,9 @@ class Dispatch2 extends Backend
|
|||
|
||||
$remark = $reason;
|
||||
$count = 0;
|
||||
|
||||
$OrderLogic = new OrderLogic();
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($list as $item) {
|
||||
|
|
@ -362,23 +365,19 @@ class Dispatch2 extends Backend
|
|||
$this->error('订单状态已变更,请刷新后操作');
|
||||
}
|
||||
//取消
|
||||
$item->allowField(true)->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]);
|
||||
// $item->allowField(true)->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]);
|
||||
//回退订单状态
|
||||
$order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]);
|
||||
$params['order'] = $order;
|
||||
$params['role'] = 1;
|
||||
$params['auth'] = $this->auth;
|
||||
$params['remark'] = '派单被取消[ID:' . $item->id . '],订单状态回退';
|
||||
if (!empty($remark)) {
|
||||
$params['remark'] .= ',操作备注:' . $remark;
|
||||
}
|
||||
Hook::listen('order_change', $params);
|
||||
//$order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]);
|
||||
|
||||
/* Hook::listen('order_change', $params);
|
||||
|
||||
$hookParams = [
|
||||
'dispatch' => $item,
|
||||
'remark' => '后台取消,adminId:'.$this->auth->id
|
||||
];
|
||||
Hook::listen('order_dispatch_change', $hookParams);
|
||||
Hook::listen('order_dispatch_change', $hookParams);*/
|
||||
|
||||
$OrderLogic->cancelOrderDispatch($item,$this->auth,$remark);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (PDOException | Exception $e) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
namespace app\common\Logic;
|
||||
|
||||
use app\admin\controller\orders\Dispatch;
|
||||
use app\admin\model\Order;
|
||||
use app\admin\model\OrderDispatch;
|
||||
use fast\Auth;
|
||||
use think\Db;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
|
|
@ -66,4 +69,75 @@ class OrderLogic
|
|||
Hook::listen('order_dispatch_change', $hookParams);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* todo...
|
||||
* 师傅超时未接单的处理逻辑
|
||||
* @return void
|
||||
*/
|
||||
public function noWorkerCanGetIt(OrderDispatch $dispatch)
|
||||
{
|
||||
$maxNoticeNum = 3;
|
||||
if($dispatch->notice > $maxNoticeNum){ //超过三次,直接取消
|
||||
Db::startTrans();
|
||||
try {
|
||||
$dispatch->notice_num ++;
|
||||
$dispatch->notice_time = date('Y-m-d H:i:s');
|
||||
$remark = '师傅超时未接单,任务取消';
|
||||
$this->cancelOrderDispatch($dispatch,null,$remark);
|
||||
Db::commit();
|
||||
}catch (Exception $exception){
|
||||
Db::rollback();
|
||||
$remark = '任务取消异常,请联系技术人员:'.$exception->getMessage();
|
||||
$dispatch->notice_num ++;
|
||||
$dispatch->remark = $remark;
|
||||
$dispatch->notice_time = date('Y-m-d H:i:s');
|
||||
$dispatch->save();
|
||||
}
|
||||
}else{ //未超过最大值,则通知短信通知
|
||||
|
||||
$dispatch->notice_num ++;
|
||||
$dispatch->notice_time = date('Y-m-d H:i:s');
|
||||
$dispatch->save();
|
||||
|
||||
//发送短信通知师傅
|
||||
$smsLogic = new SmsLogic();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 取消任务
|
||||
* @param Dispatch $dispatch
|
||||
* @return void
|
||||
*/
|
||||
public function cancelOrderDispatch(OrderDispatch $dispatch,$auth=null,$remark='')
|
||||
{
|
||||
$order = Order::where('id',$dispatch->id)->where('status',Order::STATUS_DISPATCHED)->find();
|
||||
if(!empty($order)){
|
||||
throw new Exception('未找到关联订单');
|
||||
}
|
||||
|
||||
//取消
|
||||
$dispatch->allowField(true)->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]);
|
||||
//回退订单状态
|
||||
$order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]);
|
||||
|
||||
$params['order'] = $order;
|
||||
$params['role'] = 1;
|
||||
$params['auth'] = $auth;
|
||||
$params['remark'] = '任务被取消[ID:' . $dispatch->id . '],订单状态回退';
|
||||
if (!empty($remark)) {
|
||||
$params['remark'] .= ',备注:' . $remark;
|
||||
}
|
||||
Hook::listen('order_change', $params);
|
||||
|
||||
$hookParams = [
|
||||
'dispatch' => $dispatch,
|
||||
'remark' => '后台取消,admin:'.$auth->nickname??0,
|
||||
];
|
||||
Hook::listen('order_dispatch_change', $hookParams);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
11
application/common/Logic/SmsLogic.php
Normal file
11
application/common/Logic/SmsLogic.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\Logic;
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
*/
|
||||
class SmsLogic
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -10,13 +10,10 @@ use think\Hook;
|
|||
|
||||
class CheckOrderDispatchCommand extends Command
|
||||
{
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('check:dispatch-overtime')
|
||||
->setDescription('检测dispatch表超时任务');
|
||||
|
||||
->setDescription('检测dispatch表超时任务,每分钟检测一次');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output){
|
||||
|
|
|
|||
42
application/common/command/CheckOrderDispatchGotCommand.php
Normal file
42
application/common/command/CheckOrderDispatchGotCommand.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\admin\model\Order;
|
||||
use app\admin\model\OrderDispatch;
|
||||
use app\common\Logic\OrderLogic;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Hook;
|
||||
|
||||
class CheckOrderDispatchGotCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('check:dispatch-toget')
|
||||
->setDescription('dispatch未接单通知,每五分钟检测一次');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output){
|
||||
|
||||
$Model = new OrderDispatch();
|
||||
|
||||
$now = date('Y-m-d H:i:s',time()-30*60); //创建三十分名以上未接的任务
|
||||
|
||||
$now2 = date('Y-m-d H:i:s',time()-30*600); //上次通知在30分钟以前
|
||||
|
||||
$OrderLogic = new OrderLogic();
|
||||
|
||||
$Model->where('status',OrderDispatch::STATUS_TOGET)
|
||||
->where('create_time','<=',$now)
|
||||
->where('notice_time','<=',$now2)
|
||||
->chunk(100, function ($list) use ($OrderLogic){
|
||||
foreach ($list as $item) {
|
||||
$OrderLogic->noWorkerCanGetIt($item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user