65 lines
2.1 KiB
PHP
65 lines
2.1 KiB
PHP
<?php
|
||
|
||
namespace app\common\command;
|
||
|
||
use app\admin\controller\AutoDispatchLogic;
|
||
use app\admin\model\Admin;
|
||
use app\admin\model\Message;
|
||
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\Db;
|
||
use think\Exception;
|
||
use think\Hook;
|
||
use function Symfony\Component\Clock\now;
|
||
|
||
class CheckOrderDispatchCommand extends Command
|
||
{
|
||
protected $title = '鞭策牛马是否派单,每分钟执行一次';
|
||
protected function configure()
|
||
{
|
||
$this->setName('check:dispatch')
|
||
->setDescription($this->title);
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output){
|
||
// 查询所有待派单,且未通知过的订单
|
||
$orders = Db::name('order')
|
||
->alias('o')
|
||
->join('order_dispatch_notify n', 'o.id = n.order_id','left')
|
||
->where('o.status', Order::STATUS_DISPATCHING)
|
||
->whereNull('n.id') // 没有记录就表示还没通知
|
||
->where('o.create_time', '<=', now()->format('Y-m-d H:i:s'))
|
||
->field(['o.id','o.area_id','o.order_no'])
|
||
->select();
|
||
$log_insert = [];
|
||
$now = now()->format('Y-m-d H:i:s');
|
||
|
||
foreach ($orders as $order){
|
||
$area_id = substr($order['area_id'], 0, 4);
|
||
$res = Admin::where('area_ids', 'like', '%' . $area_id . '%')
|
||
->column('id');
|
||
|
||
$insert = [];
|
||
foreach ($res as $re) {
|
||
$insert [] = [
|
||
'to_id' => $re,
|
||
'type' => 1,
|
||
'title' => '订单未派单超时通知',
|
||
'content' => '您有一条订单号为 ' . $order['order_no'] . ' 超过20分钟未派单,请及时派单!'
|
||
];
|
||
}
|
||
$build = new Message();
|
||
$build->saveAll($insert);
|
||
$log_insert [] = [
|
||
'order_id' => $order['id'],
|
||
'notified_at' => $now,
|
||
'created_at' => $now,
|
||
];
|
||
}
|
||
Db::name('order_dispatch_notify')->insertAll($log_insert);
|
||
}
|
||
} |