自动派单
This commit is contained in:
parent
459f094718
commit
d1a8960ef6
|
|
@ -47,7 +47,7 @@ class OrderDispatchLog
|
|||
'status' => $alibaba_dyvms['sync']?1:0
|
||||
];
|
||||
$service = new NoticeLogic();
|
||||
$service->dispatchNotice($dispatch,$data);
|
||||
$service->dispatchNotice($dispatch);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace app\admin\command;
|
||||
|
||||
use app\admin\addresmart\Address;
|
||||
use app\admin\controller\AutoDispatchLogic;
|
||||
use app\admin\controller\orders\DispatchLogic;
|
||||
use app\admin\controller\SendMailLogic;
|
||||
use app\admin\model\Order;
|
||||
|
|
@ -17,6 +18,7 @@ use think\console\Output;
|
|||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\Hook;
|
||||
use think\Lang;
|
||||
use think\Model;
|
||||
use function Symfony\Component\Clock\now;
|
||||
|
||||
|
|
@ -32,10 +34,36 @@ class Test extends Command
|
|||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
// $ret = SendMailLogic::sendToCustomStart('13038128325','今日的风儿','173xxxxxxxx');
|
||||
$ret = SendMailLogic::sendToCustomStop('17381847365');
|
||||
dd($ret);
|
||||
// dd($ret);
|
||||
|
||||
|
||||
$order = Order::where('id',140)->find();
|
||||
AutoDispatchLogic::autoDispatch($order);
|
||||
dd(2);
|
||||
|
||||
$hookParams = [
|
||||
'dispatch' => (new OrderDispatch())->where('id', 144)->find(),
|
||||
'remark' => '系统自动派单给师傅:'. '时间嗯' .'('.'12312'.')',
|
||||
];
|
||||
|
||||
Lang::load(APP_PATH . 'admin/lang/zh-cn/orders/dispatch2.php');
|
||||
|
||||
$Model = new \app\admin\model\OrderDispatch();
|
||||
$statusList = $Model->getStatusList();
|
||||
$dispatch = $hookParams['dispatch']; //订单对象
|
||||
$remark = $hookParams['remark'] ?? ''; //备注
|
||||
$data = [
|
||||
'dispatch_id' => $dispatch->id,
|
||||
'order_id' => $dispatch->order_id,
|
||||
'worker_id' => $dispatch->worker_id,
|
||||
'status' => $dispatch->status,
|
||||
'status_text' => $statusList[$dispatch->status],
|
||||
'remark' => $remark,
|
||||
'admin_user' => $dispatch->admin_user??'sys',
|
||||
];
|
||||
dd($data);
|
||||
|
||||
|
||||
dd($res);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
64
application/admin/controller/AutoDispatchLogic.php
Normal file
64
application/admin/controller/AutoDispatchLogic.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use app\admin\controller\orders\DispatchLogic;
|
||||
use app\admin\model\Admin;
|
||||
use app\admin\model\OrderDispatch;
|
||||
use app\admin\model\Worker;
|
||||
use think\Hook;
|
||||
|
||||
class AutoDispatchLogic
|
||||
{
|
||||
|
||||
public static function autoDispatch($order)
|
||||
{
|
||||
//
|
||||
// if ($order->dispatch_type != 2) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
|
||||
$worker_id = (new DispatchLogic())->getMaxScoreWorker($order);
|
||||
// dd($worker_id);
|
||||
if (!$worker_id) {
|
||||
$order->dispatch_type = 1;
|
||||
$order->save();
|
||||
return false;
|
||||
}
|
||||
$admin = Admin::where('id',$order->admin_id)->find();
|
||||
$insert = [
|
||||
'admin_id' => $admin->id,
|
||||
'admin_user' => $admin->nickname,
|
||||
'order_id' => $order->id,
|
||||
'type' => 2,
|
||||
'worker_id' => $worker_id,
|
||||
'plan_time' => $order->plan_time,
|
||||
'is_receipt' => $order->receive_type == 1,
|
||||
];
|
||||
|
||||
$worker = (new Worker())->where('id', $worker_id)->find();
|
||||
$insert ['worker_name'] = $worker['name'];
|
||||
$insert ['worker_tel'] = $worker['tel'];
|
||||
$orderDispatch = new OrderDispatch();
|
||||
$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 = $this->auth->id;
|
||||
$order->worker_id = $worker_id;
|
||||
$order->save();
|
||||
|
||||
//日志
|
||||
$hookParams = [
|
||||
'dispatch' => (new OrderDispatch())->where('id', $orderDispatch->id)->find(),
|
||||
'remark' => '系统自动派单给师傅:'. $worker->name .'('.$worker->tel.')',
|
||||
];
|
||||
Hook::listen('order_dispatch_change', $hookParams);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -248,7 +248,7 @@ class Order extends Backend
|
|||
$result = $this->model->allowField(true)->save($params);
|
||||
|
||||
if ($params['dispatch_type'] == 2) {
|
||||
$this->autoDispatch($this->model);
|
||||
AutoDispatchLogic::autoDispatch($this->model);
|
||||
}
|
||||
//日志
|
||||
|
||||
|
|
@ -369,54 +369,8 @@ class Order extends Backend
|
|||
}
|
||||
|
||||
|
||||
public function autoDispatch($order)
|
||||
{
|
||||
//
|
||||
// if ($order->dispatch_type != 2) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
|
||||
$worker_id = (new DispatchLogic())->getMaxScoreWorker($order);
|
||||
|
||||
if (!$worker_id) {
|
||||
$order->dispatch_type = 1;
|
||||
$order->save();
|
||||
return false;
|
||||
}
|
||||
|
||||
$insert = [
|
||||
'admin_id' => $this->auth->id,
|
||||
'admin_user' => $this->auth->nickname,
|
||||
'order_id' => $order->id,
|
||||
'type' => 2,
|
||||
'worker_id' => $worker_id,
|
||||
'plan_time' => $order->plan_time,
|
||||
'is_receipt' => $order->receive_type == 1
|
||||
];
|
||||
|
||||
$worker = (new Worker())->where('id', $worker_id)->find();
|
||||
$insert ['worker_name'] = $worker['name'];
|
||||
$insert ['worker_tel'] = $worker['tel'];
|
||||
$orderDispatch = new OrderDispatch();
|
||||
$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 = $this->auth->id;
|
||||
$order->worker_id = $worker_id;
|
||||
$order->save();
|
||||
|
||||
//日志
|
||||
$hookParams = [
|
||||
'dispatch' => (new OrderDispatch())->where('id', $res)->find(),
|
||||
'remark' => '系统自动派单给师傅:'. $worker->name .'('.$worker->tel.')',
|
||||
];
|
||||
Hook::listen('order_dispatch_change', $hookParams);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function smart()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ FROM (
|
|||
point(lng, lat),
|
||||
point(?, ?)
|
||||
) AS distance
|
||||
FROM fa_worker
|
||||
FROM fa_worker where deletetime is null
|
||||
) AS t
|
||||
WHERE distance < 40000
|
||||
ORDER BY distance;",[$order->lng,$order->lat]);
|
||||
|
|
@ -40,10 +40,13 @@ ORDER BY distance;",[$order->lng,$order->lat]);
|
|||
$worker_items_ids = (new WorkerItem())
|
||||
->where('item_id', $order->item_id)
|
||||
->whereIn('worker_id', $worker_ids)
|
||||
->field(['worker_id'])
|
||||
->column('worker_id');
|
||||
|
||||
$out_worker = OrderDispatch::where('order_id',$order->id)
|
||||
->where('status',-30)->column('worker_id');
|
||||
|
||||
$out_worker_ids = array_intersect($worker_ids, $worker_items_ids);
|
||||
$out_worker_ids = array_values(array_diff($out_worker_ids, $out_worker));
|
||||
|
||||
$worker_doings = (new OrderDispatch())
|
||||
->whereIn('worker_id', $out_worker_ids)
|
||||
|
|
|
|||
|
|
@ -8,10 +8,6 @@ use think\Model;
|
|||
class OrderDispatchLog extends Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 表名
|
||||
protected $name = 'order_dispatch_log';
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\admin\controller\AutoDispatchLogic;
|
||||
use app\admin\model\Order;
|
||||
use app\admin\model\OrderDispatch;
|
||||
use app\common\Logic\OrderLogic;
|
||||
|
|
@ -45,8 +46,7 @@ class CheckOrderDispatchGotCommand extends Command
|
|||
$OrderLogic->noWorkerCanGetIt($item);
|
||||
//自动重派新单
|
||||
$order = Order::get($item->order_id);
|
||||
$orderService = new \app\admin\controller\Order();
|
||||
$orderService->autoDispatch($order);
|
||||
AutoDispatchLogic::autoDispatch($order,$order->admin_id);
|
||||
echo 'succ:' . $item->id . PHP_EOL;
|
||||
} catch (Exception $exception) {
|
||||
echo $exception->getMessage() . PHP_EOL;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user