自动派单
This commit is contained in:
parent
2b32306511
commit
e52eb48f0b
76
application/admin/command/Test.php
Normal file
76
application/admin/command/Test.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace app\admin\command;
|
||||
|
||||
use app\admin\model\Order;
|
||||
use app\admin\model\OrderDispatch;
|
||||
use app\admin\model\Worker;
|
||||
use app\admin\model\WorkerItem;
|
||||
use Overtrue\Pinyin\Converter;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use Overtrue\Pinyin\Pinyin;
|
||||
use think\Model;
|
||||
|
||||
class Test extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('test')
|
||||
->setDescription('批量生成区域名称的拼音');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$order = (new Order())->where('id',66)->find();
|
||||
$this->autoDispatch($order);
|
||||
}
|
||||
|
||||
private function autoDispatch($order) {
|
||||
// if ($order->dispatch_type != 2){
|
||||
// return false;
|
||||
// }
|
||||
|
||||
$worker_ids = (new Worker())->where('area_id',$order->area_id)
|
||||
->where('status',1)
|
||||
->field(['id','area_id','lng'],'lat')
|
||||
->column('id');
|
||||
|
||||
$worker_items_ids = (new WorkerItem())
|
||||
->where('item_id',$order->item_id)
|
||||
->whereIn('worker_id',$worker_ids)
|
||||
->field(['worker_id'],'lat')
|
||||
->column('worker_id');
|
||||
|
||||
$out_workers = array_intersect($worker_ids,$worker_items_ids);
|
||||
|
||||
$worker_id = $out_workers[0] ?? false;
|
||||
|
||||
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' => 1,
|
||||
'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'];
|
||||
(new OrderDispatch())->allowField(true)->save($insert);
|
||||
$order->status = \app\admin\model\Order::STATUS_DISPATCHED;
|
||||
$order->save();
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -2,11 +2,15 @@
|
|||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\OrderDispatch;
|
||||
use app\admin\model\Worker;
|
||||
use app\admin\model\WorkerItem;
|
||||
use app\common\controller\Backend;
|
||||
use fast\Tree;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 订单列管理
|
||||
|
|
@ -173,6 +177,9 @@ class Order extends Backend
|
|||
$params['update_time'] = date('Y-m-d H:i:s');
|
||||
|
||||
$result = $this->model->allowField(true)->save($params);
|
||||
if ($params['dispatch_type'] == 2){
|
||||
$this->autoDispatch($this->model);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
|
|
@ -283,4 +290,51 @@ class Order extends Backend
|
|||
|
||||
return $orderNumber;
|
||||
}
|
||||
|
||||
|
||||
private function autoDispatch($order) {
|
||||
if ($order->dispatch_type != 2){
|
||||
return false;
|
||||
}
|
||||
|
||||
$worker_ids = (new Worker())->where('area_id',$order->area_id)
|
||||
->where('status',1)
|
||||
->field(['id','area_id','lng'],'lat')
|
||||
->column('id');
|
||||
|
||||
$worker_items_ids = (new WorkerItem())
|
||||
->where('item_id',$order->item_id)
|
||||
->whereIn('worker_id',$worker_ids)
|
||||
->field(['worker_id'],'lat')
|
||||
->column('worker_id');
|
||||
|
||||
$out_workers = array_intersect($worker_ids,$worker_items_ids);
|
||||
|
||||
$worker_id = $out_workers[0] ?? false;
|
||||
|
||||
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' => 1,
|
||||
'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'];
|
||||
(new OrderDispatch())->allowField(true)->save($insert);
|
||||
$order->status = \app\admin\model\Order::STATUS_DISPATCHED;
|
||||
$order->save();
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,4 +20,5 @@ return [
|
|||
'app\admin\command\AreaPinyinCommand',
|
||||
'app\admin\command\ItemImportCommand',
|
||||
'app\admin\command\ImportServiceItems',
|
||||
'app\admin\command\Test',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
define([], function () {
|
||||
require([], function () {
|
||||
//绑定data-toggle=addresspicker属性点击事件
|
||||
console.log('111');
|
||||
|
||||
$(document).on('click', "[data-toggle='addresspicker']", function () {
|
||||
var that = this;
|
||||
var callback = $(that).data('callback');
|
||||
|
|
@ -14,7 +12,7 @@ define([], function () {
|
|||
var lng = lng_id ? $("#" + lng_id).val() : '';
|
||||
var city_code = $("#area_id").val();
|
||||
var zoom = zoom_id ? $("#" + zoom_id).val() : '';
|
||||
var url = "/addons/address/index/select?1=1";
|
||||
var url = "/addons/address/index/select?abc=1";
|
||||
url += (lat && lng) ? 'lat=' + lat + '&lng=' + lng +
|
||||
(input_id ? "&address=" + $("#" + input_id).val() : "")
|
||||
+(zoom ? "&zoom=" + zoom : "") : ''
|
||||
|
|
|
|||
|
|
@ -74,9 +74,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'],
|
|||
{
|
||||
field: 'operate', title: __('Operate'), table: table,
|
||||
events: Table.api.events.operate, formatter: function (value, row, index) {
|
||||
if (row.id == Config.admin.id) {
|
||||
return '';
|
||||
}
|
||||
// if (row.id == Config.admin.id) {
|
||||
// return '';
|
||||
// }
|
||||
return Table.api.formatter.operate.call(this, value, row, index);
|
||||
},
|
||||
buttons: [
|
||||
|
|
@ -127,7 +127,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'],
|
|||
},
|
||||
success: function (data) {
|
||||
// console.log(data);
|
||||
Controller.api.rendertree(data);
|
||||
// Controller.api.rendertree(data);
|
||||
},
|
||||
error: function () {
|
||||
console.error("请求失败");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user