问题修复

This commit is contained in:
hant 2025-06-16 23:12:01 +08:00
parent 808c8801d3
commit f78d784441
12 changed files with 316 additions and 63 deletions

View File

@ -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);
}

View File

@ -22,6 +22,7 @@ class AutoDispatchLogic
$worker_id = (new DispatchLogic())->getMaxScoreWorker($order);
// dd($worker_id);
if (!$worker_id) {
$order->dispatch_type = 1;
$order->save();

View File

@ -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();

View File

@ -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')

View File

@ -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());

View File

@ -56,7 +56,7 @@
<div class='address line' style="position: relative">
<input id="c-address"
class="form-control"
placeholder="请通过地图查找选择"
placeholder="输入地址搜索"
autocomplete="off"
name="row[address]"
type="text" />

View File

@ -97,7 +97,7 @@
<div class="form-group">
<label class="col-sm-2" style="text-align: left;padding-left: 0px;">工种:</label>
<div style="width: 300px;display: inline-block;">
<input type="text" id="item_id" name="item_id" value="{$row.item_title}" class="zd-input__inner">
<input type="text" id="item_id" name="item_id" data-myvalue="{$row.item_id}" value="{$row.item_title}" data-value="{$row.item_title}" class="zd-input__inner">
</div>
</div>

View File

@ -13,18 +13,22 @@
<input id="c-tel" data-rule="required" class="form-control" name="row[tel]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Area_id')}:</label>
<div class='col-xs-12 col-sm-8'>
<input id="c-city" data-rule="required" class="form-control" data-toggle="city-picker" name="row[address]" type="text" value="" />
<input id="area_id" style="display: none" class="form-control" name="row[area_id]" hidden type="text" value="" />
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('详细地址')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-address" data-rule="required" class="form-control" name="row[address]" type="text" value="">
<input id="c-address"
class="form-control"
placeholder="请通过地图查找选择"
autocomplete="off"
name="row[address]"
type="text" />
<ul id="suggestionList"></ul>
<input type="text" style="display: none"
name="row[lng]" id="lng" >
<input type="text" style="display: none"
name="row[lat]" id="lat">
<input id="area_id" style="display: none" class="form-control" name="row[area_id]" hidden type="text" value="" />
</div>
</div>
@ -84,11 +88,6 @@
<ul class="row list-inline faupload-preview" id="p-images"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">师傅技能:</label>
<div class="col-xs-12 col-sm-8">
@ -108,4 +107,42 @@
</form>
<script>
var nodeData = {:json_encode($tree); };
</script>
</script>
<style>
#suggestionList {
position: absolute;
top: 100%;
left: 0;
width: 100%;
max-height: 240px;
overflow-y: auto;
margin-top: 4px;
padding: 0;
list-style: none;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
z-index: 9999;
font-size: 14px;
}
#suggestionList li {
padding: 10px 14px;
cursor: pointer;
transition: background-color 0.2s;
border-bottom: 1px solid #f1f1f1;
}
#suggestionList li:last-child {
border-bottom: none;
}
#suggestionList li:hover {
background-color: #f5f8fa;
color: #007aff;
}
#suggestionList li.active {
background-color: #82b0e1;
color: white;
}
</style>

View File

@ -29,20 +29,21 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Area_id')}:</label>
<div class='col-xs-12 col-sm-8'>
<input id="c-city" data-rule="required" class="form-control" data-toggle="city-picker" value="{$row.area_name}"
type="text" name="row[address]"/>
<input id="area_id" style="display: none" class="form-control" name="row[area_id]" hidden type="text"
value="{$row.area_id}"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('详细地址')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-address" data-rule="required" class="form-control" name="row[address]" type="text" value="{$row.address}">
<input id="c-address"
class="form-control"
placeholder="输入地址搜索"
autocomplete="off"
value="{$row.address}"
name="row[address]"
type="text" />
<ul id="suggestionList"></ul>
<input type="text" style="display: none"
name="row[lng]" id="lng" value="{$row.lng}">
<input type="text" style="display: none"
name="row[lat]" id="lat" value="{$row.lat}">
</div>
</div>
@ -122,4 +123,42 @@
</form>
<script>
var nodeData = {:json_encode($tree);};
</script>
</script>
<style>
#suggestionList {
position: absolute;
top: 100%;
left: 0;
width: 100%;
max-height: 240px;
overflow-y: auto;
margin-top: 4px;
padding: 0;
list-style: none;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
z-index: 9999;
font-size: 14px;
}
#suggestionList li {
padding: 10px 14px;
cursor: pointer;
transition: background-color 0.2s;
border-bottom: 1px solid #f1f1f1;
}
#suggestionList li:last-child {
border-bottom: none;
}
#suggestionList li:hover {
background-color: #f5f8fa;
color: #007aff;
}
#suggestionList li.active {
background-color: #82b0e1;
color: white;
}
</style>

View File

@ -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'); // "经度,纬度"

View File

@ -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);

View File

@ -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 += `<li data-name="${tip.district} ${tip.name}" data-area_id="${tip.adcode}" data-location="${tip.location}">
${tip.district} ${tip.name}
</li>`;
}
});
$('#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;
}
}
}
};