diff --git a/application/admin/command/Test.php b/application/admin/command/Test.php
index df65a22..a9190af 100644
--- a/application/admin/command/Test.php
+++ b/application/admin/command/Test.php
@@ -35,9 +35,8 @@ class Test extends Command
protected function execute(Input $input, Output $output)
{
- $key = 'ae0ab397a2febfa1ce0a2c780f3f23a3';
- $res = $this->getAddressByKeyword('重庆武隆区凤山街道锦江竹苑6幢31-4');
- dd($res);
+ $order = Order::where('id',221)->select()[0];
+ AutoDispatchLogic::autoDispatch($order);
}
diff --git a/application/admin/controller/AutoDispatchLogic.php b/application/admin/controller/AutoDispatchLogic.php
index 9bbf842..617cabe 100644
--- a/application/admin/controller/AutoDispatchLogic.php
+++ b/application/admin/controller/AutoDispatchLogic.php
@@ -22,6 +22,7 @@ class AutoDispatchLogic
$worker_id = (new DispatchLogic())->getMaxScoreWorker($order);
+// dd($worker_id);
if (!$worker_id) {
$order->dispatch_type = 1;
$order->save();
diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php
index b1978f4..be2967e 100644
--- a/application/admin/controller/Order.php
+++ b/application/admin/controller/Order.php
@@ -634,6 +634,9 @@ class Order extends Backend
$op[] = ['id' => $option->id, 'title' => $option->title];
}
$order = model('order')->get($ids);
+ if ($order){
+ $this->error('订单未找到,请重试');
+ }
return $this->fetch('delete', ['row' => $order, 'options' => $op]);
}
$params = $this->request->post('row/a');
@@ -666,7 +669,7 @@ class Order extends Backend
$hookparams['order'] = $order;
$hookparams['role'] = 1;
$hookparams['auth'] = null;
- $hookparams['remark'] = $params['remark'] ?? '';
+ $hookparams['remark'] = $params['remark'] ?? '取消订单';
Hook::listen('order_change', $hookparams);
}
Db::commit();
diff --git a/application/admin/controller/orders/DispatchLogic.php b/application/admin/controller/orders/DispatchLogic.php
index 4f47a5c..30b00d8 100644
--- a/application/admin/controller/orders/DispatchLogic.php
+++ b/application/admin/controller/orders/DispatchLogic.php
@@ -29,11 +29,13 @@ FROM (
point(lng, lat),
point(?, ?)
) AS distance
- FROM fa_worker where deletetime is null
+ FROM fa_worker where deletetime is null and type = 1 and status = 1
) AS t
WHERE distance < 40000
ORDER BY distance;",[$order->lng,$order->lat]);
+
+
$worker_ids = array_column($worker_info,'id');
@@ -47,7 +49,7 @@ ORDER BY distance;",[$order->lng,$order->lat]);
$out_worker_ids = array_intersect($worker_ids, $worker_items_ids);
$out_worker_ids = array_values(array_diff($out_worker_ids, $out_worker));
-
+// dd($out_worker_ids);
$worker_doings = (new OrderDispatch())
->whereIn('worker_id', $out_worker_ids)
->group('worker_id')
diff --git a/application/admin/controller/workers/Worker.php b/application/admin/controller/workers/Worker.php
index ed455b1..619a9a4 100644
--- a/application/admin/controller/workers/Worker.php
+++ b/application/admin/controller/workers/Worker.php
@@ -6,6 +6,7 @@ use app\admin\model\Area;
use app\admin\model\AuthGroup;
use app\admin\model\Item;
use app\admin\model\Order;
+use app\admin\model\WorkerItem;
use app\common\controller\Backend;
use fast\Tree;
use think\Db;
@@ -160,7 +161,7 @@ class Worker extends Backend
}
$params['admin_id'] = $this->auth->id;
- if(!empty($params['area_id'])){
+ if((!empty($params['area_id'])) && isset($params['lng'])){
$area = Area::getByCode($params['area_id']);
if($area){
@@ -171,7 +172,9 @@ class Worker extends Backend
}
}
}
+// dd($params);
$result = $this->model->allowField(true)->save($params);
+// dd($result);
$item_map = model('item')->getAll();
$item_map = array_column($item_map, 'level', 'id');
if ($result) {
@@ -275,6 +278,7 @@ class Worker extends Backend
public function dispatchList()
{
$area_id = request()->get('area_id');
+ $item_id = request()->get('item_id');
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$build = model('worker')
@@ -297,6 +301,10 @@ class Worker extends Backend
$code = $this->getSelectAreaCode(substr_replace($area_id, '00', -2));
$build->where('area_id', 'like', $code . '%');
}
+ if ($item_id) {
+ $worker_ids = WorkerItem::where('item_id',$item_id)->column('worker_id');
+ $build->whereIn('id',$worker_ids);
+ }
$list = $build
->paginate($limit);
$result = array("total" => $list->total(), "rows" => $list->items());
diff --git a/application/admin/view/order/add.html b/application/admin/view/order/add.html
index 57b8f9b..69f8c17 100644
--- a/application/admin/view/order/add.html
+++ b/application/admin/view/order/add.html
@@ -56,7 +56,7 @@
-
@@ -84,11 +88,6 @@
-
-
-
-
-
-
-
@@ -122,4 +123,42 @@
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/public/assets/js/backend/order.js b/public/assets/js/backend/order.js
index 9c8de83..9286b0d 100644
--- a/public/assets/js/backend/order.js
+++ b/public/assets/js/backend/order.js
@@ -293,6 +293,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
table.bootstrapTable('refresh');
}
},
+ {
+ name: "dispatch",
+ text: "派单",
+ title: "派单",
+ extend: 'data-toggle="tooltip" data-container="body"',
+ classname: 'btn btn-xs btn-info btn-dialog',
+ icon: 'fa fa-add',
+ url: function (row) {
+ return 'orders/dispatch/add?order_id=' + row.id;
+ },
+ visible: function (row) {
+ if (row.status == 10) {
+ return true;
+ }
+ return false;
+ },
+ refresh: true,
+ },
{
name: "reminder",
text: "催单",
@@ -425,9 +443,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
table.bootstrapTable('refresh', {});
return false;
});
- const timer = setInterval(function () {
- table.bootstrapTable('refresh', {});
- }, 1000 * 120);
+ let idleTimer = null;
+
+ function resetIdleTimer() {
+ clearTimeout(idleTimer);
+ idleTimer = setTimeout(function () {
+ // 30秒无操作后执行刷新
+ table.bootstrapTable('refresh', {});
+ }, 30 * 1000); // 30 秒
+ }
+
+ ['mousemove', 'keydown', 'click', 'scroll'].forEach(function (event) {
+ document.addEventListener(event, resetIdleTimer, false);
+ });
+
+ resetIdleTimer();
+
},
add: function () {
$("#mybuttom").on("click", function () {
@@ -625,7 +656,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
$('#item_id_value').val(data.value);
}
});
- $('#item_id').val($('#item_id').data('value')).focus();
+ $('#item_id').val($('#item_id').data('value'));
const mainSelect = document.getElementById('receive_type');
const otherSelect = document.getElementById('coupon');
@@ -730,7 +761,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
}
}
-
function handleInput(e) {
selectedIndex = -1;
addressSelected = false;
@@ -768,7 +798,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'cascader'], function
};
}
-
$('#suggestionList').on('mousedown', 'li', function (e) {
const name = $(this).data('name');
const location = $(this).data('location'); // "经度,纬度"
diff --git a/public/assets/js/backend/orders/dispatch.js b/public/assets/js/backend/orders/dispatch.js
index b7c65b8..7747e2f 100644
--- a/public/assets/js/backend/orders/dispatch.js
+++ b/public/assets/js/backend/orders/dispatch.js
@@ -320,10 +320,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'layer', 'cascader'],
$("#reset_btn").on("click", function () {
$("#c-city-search").citypicker('reset');
$("#area_id").val('');
- $("#test").val('');
- $("#test").data('myvalue', '');
+ $("#item_id").data('myvalue', '');
$("#keyword").val('');
- $('#item_id').zdCascader.reload(_data,true);
table.bootstrapTable('refresh', {
url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(),
});
@@ -336,27 +334,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'layer', 'cascader'],
$('#c-worker_id').val(worker.id).trigger('input').trigger('change');
});
$('#add_worker').on('click',function (){
- console.log(1);
Fast.api.open('workers/worker/add?type=2', '添加工人',{
callback: function (value) {
- console.log(2222,value);
+ table.bootstrapTable('refresh', {
+ url: $.fn.bootstrapTable.defaults.extend.index_url + '?' + getQueryData(),
+ });
}
});
});
-
-
$('#item_id').zdCascader({
data: _data,
onChange: function ($this, data, allPathData) {
- // console.log(data,allPathData);
$('#item_id').data('myvalue', data.value);
},
- defaultValue:$('#item_id_name').val(),
- clear:true,
- clickParent:true
+ // clear:true,
+ // clickParent:true
});
-
+ $('#item_id').val($('#item_id').data('value'));
// 为表格绑定事件
Table.api.bindevent(table);
diff --git a/public/assets/js/backend/workers/worker.js b/public/assets/js/backend/workers/worker.js
index b1727cf..6184ef1 100644
--- a/public/assets/js/backend/workers/worker.js
+++ b/public/assets/js/backend/workers/worker.js
@@ -218,11 +218,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'],
Form.events.citypicker($("form"));
},
add: function () {
- $("#c-city").on("cp:updated", function () {
- var citypicker = $(this).data("citypicker");
- var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
- $("#area_id").val(code);
- });
+
const urlParams = new URLSearchParams(window.location.search);
const type = urlParams.get('type');
if (type) {
@@ -232,14 +228,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'],
}
}
Controller.api.bindevent();
+ Controller.api.area();
},
edit: function () {
- $("#c-city").on("cp:updated", function () {
- var citypicker = $(this).data("citypicker");
- var code = citypicker.getCode("district") || citypicker.getCode("city") || citypicker.getCode("province");
- $("#area_id").val(code);
- });
+
Controller.api.bindevent();
+ Controller.api.area();
},
api: {
bindevent: function () {
@@ -290,6 +284,152 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'],
"data": content
}
});
+ },
+
+ area: function (){
+ const amapKey = 'c299da50c080dfccf9b1d00560ff9639';
+
+ let isComposing = false;
+ let addressSelected = false;
+ let selectedIndex = -1;
+ $('#c-address')
+ .on('compositionstart', () => {
+ isComposing = true;
+ })
+ .on('compositionend', () => {
+ isComposing = false;
+ // 不执行 handleInput,由 input 触发
+ })
+ .on('input', debounce(function (e) {
+ if (!isComposing) handleInput(e);
+ }, 300))
+ .on('blur', function () {
+ // 如果还没有选择地址,且列表中有内容,则默认选择第一个
+
+ // 如果还没有选择地址,且列表中有内容,则默认选择第一个
+ if (!addressSelected && $('#suggestionList li').length > 0) {
+ choseFirst();
+ }
+
+ $('#suggestionList').hide();
+ })
+ .on('focus', function () {
+ // 如果还没有选择地址,且列表中有内容,则默认选择第一个
+ $('#suggestionList').show();
+ })
+ .on('keydown', function (e) {
+ const $items = $('#suggestionList li');
+ const len = $items.length;
+
+ if (!len) return;
+
+ if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ selectedIndex = (selectedIndex + 1) % len;
+ updateActiveItem($items);
+ } else if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ selectedIndex = (selectedIndex - 1 + len) % len;
+ updateActiveItem($items);
+ } else if (e.key === 'Enter') {
+ if (selectedIndex >= 0 && selectedIndex < len) {
+ e.preventDefault();
+ $items.eq(selectedIndex).trigger('mousedown');
+ }
+ }
+ });
+ function updateActiveItem($items) {
+ $items.removeClass('active');
+ if (selectedIndex >= 0) {
+ const $active = $items.eq(selectedIndex);
+ $active.addClass('active');
+
+ // 自动滚动使其可见
+ const container = $('#suggestionList')[0];
+ const item = $active[0];
+
+ if (item && container) {
+ const itemTop = item.offsetTop;
+ const itemBottom = itemTop + item.offsetHeight;
+ const containerTop = container.scrollTop;
+ const containerBottom = containerTop + container.clientHeight;
+
+ if (itemTop < containerTop) {
+ container.scrollTop = itemTop;
+ } else if (itemBottom > containerBottom) {
+ container.scrollTop = itemBottom - container.clientHeight;
+ }
+ }
+ }
+ }
+
+ function handleInput(e) {
+ selectedIndex = -1;
+ addressSelected = false;
+ const keyword = $(e.target).val();
+ if (!keyword.trim() || /^[\s\p{P}]+$/u.test(keyword)) return;
+ if (!keyword) return $('#c-address').empty();
+
+ $.getJSON('https://restapi.amap.com/v3/assistant/inputtips', {
+ key: amapKey,
+ keywords: keyword,
+ datatype: 'all',
+ city: '全国',
+ }, function (res) {
+ if (res.tips) {
+ let html = '';
+ res.tips.forEach(tip => {
+ if (tip.location) {
+ html += `
+ ${tip.district} ${tip.name}
+ `;
+ }
+ });
+ $('#suggestionList').html(html).show();
+ }
+ });
+ }
+
+ function debounce(fn, delay = 300) {
+ let timer = null;
+ return function (...args) {
+ clearTimeout(timer);
+ timer = setTimeout(() => {
+ fn.apply(this, args);
+ }, delay);
+ };
+ }
+
+ $('#suggestionList').on('mousedown', 'li', function (e) {
+ const name = $(this).data('name');
+ const location = $(this).data('location'); // "经度,纬度"
+ const area_id = $(this).data('area_id'); // "经度,纬度"
+ const [lng, lat] = location.split(',');
+ $('#c-address').val(name);
+ $('#lng').val(lng);
+ $('#lat').val(lat);
+ $('#area_id').val(area_id);
+ // 隐藏提示列表
+ $('#suggestionList').hide();
+ selectedIndex = -1;
+ addressSelected = true;
+ });
+
+ function choseFirst(){
+ const first = $('#suggestionList li').first();
+ const name = first.data('name');
+ const location = first.data('location'); // "经度,纬度"
+ const area_id = first.data('area_id'); // "经度,纬度"
+ const [lng, lat] = location.split(',');
+ console.log('chose');
+ $('#lng').val(lng);
+ $('#lat').val(lat);
+ $('#area_id').val(area_id);
+ // 隐藏提示列表
+ $('#suggestionList').hide();
+ selectedIndex = -1;
+ addressSelected = true;
+ }
}
}
};