完成订单重构

This commit is contained in:
xman 2025-06-02 13:55:57 +08:00
parent 7a6bc2940a
commit 5a6642ea1f
11 changed files with 189 additions and 62 deletions

View File

@ -2,6 +2,7 @@
namespace app\admin\behavior; namespace app\admin\behavior;
use think\Exception;
use think\Lang; use think\Lang;
class OrderDispatchLog class OrderDispatchLog
@ -9,22 +10,27 @@ class OrderDispatchLog
//记录订单任务日志 //记录订单任务日志
public function run(&$response) public function run(&$response)
{ {
try {
Lang::load(APP_PATH . 'admin/lang/zh-cn/orders/dispatch2.php'); Lang::load(APP_PATH . 'admin/lang/zh-cn/orders/dispatch2.php');
$Model = new \app\admin\model\OrderDispatch(); $Model = new \app\admin\model\OrderDispatch();
$statusList = $Model->getStatusList(); $statusList = $Model->getStatusList();
$dispatch = $response['dispatch']; //订单对象 $dispatch = $response['dispatch']; //订单对象
$remark = $response['remark'] ?? ''; //备注 $remark = $response['remark'] ?? ''; //备注
$data = [ $data = [
'dispatch_id' => $dispatch->id, 'dispatch_id' => $dispatch->id,
'order_id' => $dispatch->order_id, 'order_id' => $dispatch->order_id,
'worker_id' => $dispatch->worker_id, 'worker_id' => $dispatch->worker_id,
'status' => $dispatch->status, 'status' => $dispatch->status,
'status_text' => $statusList[$dispatch->status], 'status_text' => $statusList[$dispatch->status],
'remark' => $remark, 'remark' => $remark,
]; 'admin_user' => $dispatch->admin_user??'sys',
\app\admin\model\OrderDispatchLog::create($data); ];
//(new \app\admin\model\OrderDispatchLog())->cre($data); \app\admin\model\OrderDispatchLog::create($data);
//(new \app\admin\model\OrderDispatchLog())->cre($data);
}catch (Exception $exception){
}
} }
} }

View File

@ -396,7 +396,7 @@ class Order extends Backend
//日志 //日志
$hookParams = [ $hookParams = [
'dispatch' => (new OrderDispatch())->where('id', $res)->find(), 'dispatch' => (new OrderDispatch())->where('id', $res)->find(),
'remark' => '自动派单,操作人:' . $this->auth->nickname, 'remark' => '系统自动派单',
]; ];
Hook::listen('order_dispatch_change', $hookParams); Hook::listen('order_dispatch_change', $hookParams);

View File

@ -170,10 +170,12 @@ class Dispatch extends Backend
$hookparams['remark'] = ''; $hookparams['remark'] = '';
Hook::listen('order_change', $hookparams); Hook::listen('order_change', $hookparams);
$dispatch = $this->model->get($this->model->id);
$dispatch->admin_user = $this->auth->nickname;
//dispatch log //dispatch log
$hookParams2 = [ $hookParams2 = [
'dispatch' => $this->model->get($this->model->id), 'dispatch' => $dispatch,
'remark' => '手动派单,操作人:' . $this->auth->nickname, 'remark' => '手动派单',
]; ];
Hook::listen('order_dispatch_change', $hookParams2); Hook::listen('order_dispatch_change', $hookParams2);

View File

@ -208,6 +208,7 @@ class Dispatch2 extends Backend
} }
$result = $row->allowField(true)->save($params); $result = $row->allowField(true)->save($params);
$row->admin_user = $this->auth->nickname;
if($workerChange){ if($workerChange){
$hookParams = [ $hookParams = [
'dispatch' => $row, 'dispatch' => $row,

View File

@ -52,6 +52,15 @@ class Dispatchlog extends Backend
$dispatch_id = $this->request->get('dispatch_id'); $dispatch_id = $this->request->get('dispatch_id');
if (false === $this->request->isAjax()) { if (false === $this->request->isAjax()) {
//page2变更日志
$logs = $this->model
->where('dispatch_id',$dispatch_id)
->order('id','desc')
->select();
$this->view->assign('logs',json_encode($logs));
return $this->view->fetch(); return $this->view->fetch();
} }
//如果发送的来源是 Selectpage则转发到 Selectpage //如果发送的来源是 Selectpage则转发到 Selectpage

View File

@ -128,9 +128,10 @@ class Dispatchrecord extends Backend
if($dispatch->status != $params['rate']){ if($dispatch->status != $params['rate']){
$dispatch->status = $params['rate']; $dispatch->status = $params['rate'];
$dispatch->save(); $dispatch->save();
$dispatch->admin_user = '管理员:'. $this->auth->nickname;
$hookParams = [ $hookParams = [
'dispatch' => $dispatch, 'dispatch' => $dispatch,
'remark' => '管理员跟进:'.$this->auth->nickname.',备注内容:'.$params['remark'], 'remark' => '人工跟进订单,备注内容:'.$params['remark'],
]; ];
Hook::listen('order_dispatch_change', $hookParams); Hook::listen('order_dispatch_change', $hookParams);

View File

@ -28,13 +28,4 @@ class Dispatchlog extends Model
]; ];
} }

View File

@ -1,3 +1,69 @@
<style>
.timeline-container {
padding: 20px;
position: relative;
}
.timeline {
position: relative;
margin: 0;
padding: 0;
}
.timeline::before {
content: '';
position: absolute;
left: 18px;
top: 0;
bottom: 0;
width: 2px;
background: #e4e7ed;
}
.timeline-item {
position: relative;
padding-left: 40px;
margin-bottom: 30px;
}
.timeline-item:last-child {
margin-bottom: 0;
}
.timeline-marker {
position: absolute;
left: 10px;
top: 4px;
width: 16px;
height: 16px;
background-color: #409EFF;
border: 2px solid #fff;
border-radius: 50%;
box-shadow: 0 0 0 2px #409EFF;
z-index: 1;
}
.timeline-content {
background: #f9f9f9;
border-radius: 4px;
padding: 10px 15px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.timeline-title {
font-weight: bold;
color: #333;
margin-bottom: 4px;
}
.timeline-time {
font-size: 12px;
color: #999;
margin-top: 8px;
}
</style>
<div class="panel panel-default panel-intro"> <div class="panel panel-default panel-intro">
<div class="panel-heading"> <div class="panel-heading">
@ -16,9 +82,46 @@
</table> </table>
</div> </div>
<div class="tab-pane fade" id="second"> <div class="tab-pane fade" id="second">
<table id="table2" class="table table-striped table-bordered table-hover" width="100%"> <!-- <table id="table2" class="table table-striped table-bordered table-hover" width="100%">-->
</table> <!-- </table>-->
<div class="timeline" id="log-timeline"></div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<script>
const logs = {$logs}; // 你可以用后端模板变量渲染进去
renderTimeline(logs);
function renderTimeline(logs) {
const container = document.getElementById('log-timeline');
container.innerHTML = '';
// 按时间倒序排序(最新在上)
logs.sort((a, b) => new Date(b.create_time) - new Date(a.create_time));
logs.forEach(log => {
const item = document.createElement('div');
item.className = 'timeline-item';
item.innerHTML = `
<div class="timeline-marker"></div>
<div class="timeline-content">
<h4 class="timeline-title">${log.status_text || '无状态'}</h4>
<h4 class="timeline-title">${log.admin_user || '系统'}</h4>
<p>${log.remark || '无备注'}</p>
<p class="timeline-time">${log.create_time || ''}</p>
</div>
`;
container.appendChild(item);
});
}
</script>

View File

@ -74,7 +74,11 @@ class OrderLogic
Hook::listen('order_change', $params); Hook::listen('order_change', $params);
if($roleInfo['role'] == 1){ //后台操作
$orderDispatch->admin_user = '管理员:'. $roleInfo['auth']->nickname;
}else{
$orderDispatch->admin_user = '师傅:'. $roleInfo['auth']->name;
}
$hookParams = [ $hookParams = [
'dispatch' => $orderDispatch, 'dispatch' => $orderDispatch,
'remark' => $roleInfo['remark'] ?? $orderDispatch->remark, 'remark' => $roleInfo['remark'] ?? $orderDispatch->remark,
@ -129,9 +133,14 @@ class OrderLogic
//取消 //取消
$dispatch->allowField(true)->save(['status' => OrderDispatch::STATUS_CANCEL, 'follow'=>2,'remark' => $remark]); $dispatch->allowField(true)->save(['status' => OrderDispatch::STATUS_CANCEL, 'follow'=>2,'remark' => $remark]);
if(!empty($auth)){
$dispatch->admin_user = '管理员:'.$auth->nickname;
}else{
$dispatch->admin_user = 'sys';
}
$hookParams = [ $hookParams = [
'dispatch' => $dispatch, 'dispatch' => $dispatch,
'remark' => '后台取消,操作说明:'.$remark?:'无'.',操作人:'.$auth->nickname 'remark' => '后台取消,操作说明:'.$remark?:'无'
]; ];
Hook::listen('order_dispatch_change', $hookParams); Hook::listen('order_dispatch_change', $hookParams);

View File

@ -166,6 +166,7 @@ class OrderDispatchService extends BaseService
$orderDispatch->save(); $orderDispatch->save();
$orderDispatch->admin_user = '师傅:'. $orderDispatch->worker_name;
$orderDispatchChangeParams = [ $orderDispatchChangeParams = [
'dispatch' => $orderDispatch, 'dispatch' => $orderDispatch,
'remark' => $type == 'accept' ? '师傅接单' : '师傅拒接', 'remark' => $type == 'accept' ? '师傅接单' : '师傅拒接',
@ -291,6 +292,7 @@ class OrderDispatchService extends BaseService
$orderDispatch->plan_time = $planTime; $orderDispatch->plan_time = $planTime;
$orderDispatch->save(); $orderDispatch->save();
$orderDispatch->admin_user = '师傅:'. $orderDispatch->worker_name;
$orderDispatchChangeParams = [ $orderDispatchChangeParams = [
'dispatch' => $orderDispatch, 'dispatch' => $orderDispatch,
'remark' => '师傅已和客户预约,预约时间:' . $planTime, 'remark' => '师傅已和客户预约,预约时间:' . $planTime,
@ -310,6 +312,7 @@ class OrderDispatchService extends BaseService
$orderDispatch->plan_time = $planTime; $orderDispatch->plan_time = $planTime;
$orderDispatch->save(); $orderDispatch->save();
$orderDispatch->admin_user = '师傅:'. $orderDispatch->worker_name;
$orderDispatchChangeParams = [ $orderDispatchChangeParams = [
'dispatch' => $orderDispatch, 'dispatch' => $orderDispatch,
'remark' => "师傅修改上门时间,旧的时间:{$orderDispatch->plan_time},新的时间:$planTime" 'remark' => "师傅修改上门时间,旧的时间:{$orderDispatch->plan_time},新的时间:$planTime"
@ -335,6 +338,7 @@ class OrderDispatchService extends BaseService
$orderDispatch->arrive_time = $time; $orderDispatch->arrive_time = $time;
$orderDispatch->save(); $orderDispatch->save();
$orderDispatch->admin_user = '师傅:'. $orderDispatch->worker_name;
//派单状态变更 //派单状态变更
$orderDispatchChangeParams = [ $orderDispatchChangeParams = [
'dispatch' => $orderDispatch, 'dispatch' => $orderDispatch,
@ -417,6 +421,7 @@ class OrderDispatchService extends BaseService
$orderDispatch->save(); $orderDispatch->save();
$orderDispatch->admin_user = '师傅:'. $orderDispatch->worker_name;
//派单状态变更 //派单状态变更
$orderDispatchChangeParams = [ $orderDispatchChangeParams = [
'dispatch' => $orderDispatch, 'dispatch' => $orderDispatch,

View File

@ -100,36 +100,36 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// 为表格1绑定事件 // 为表格1绑定事件
Table.api.bindevent(table1); Table.api.bindevent(table1);
}, },
second: function () { // second: function () {
// 表格2 // // 表格2
var table2 = $("#table2"); // var table2 = $("#table2");
table2.bootstrapTable({ // table2.bootstrapTable({
url: 'orders/dispatchlog/index' + location.search, // url: 'orders/dispatchlog/index' + location.search,
toolbar: '#toolbar1', // toolbar: '#toolbar1',
sortName: 'id', // sortName: 'id',
search: false, // search: false,
commonSearch:false, // commonSearch:false,
visible: false, // visible: false,
showToggle: false, // showToggle: false,
showColumns: false, // showColumns: false,
showExport: false, // showExport: false,
columns: [ // columns: [
[ // [
{field: 'id', title: __('Id')}, // {field: 'id', title: __('Id')},
// {field: 'dispatch_id', title: __('Dispatch_id')}, // // {field: 'dispatch_id', title: __('Dispatch_id')},
//{field: 'order_id', title: __('Order_id')}, // //{field: 'order_id', title: __('Order_id')},
//{field: 'worker_id', title: __('Worker_id')}, // //{field: 'worker_id', title: __('Worker_id')},
// {field: 'status', title: __('Status')}, // // {field: 'status', title: __('Status')},
{field: 'status_text', title: __('Status_text'), operate: 'LIKE'}, // {field: 'status_text', title: __('Status_text'), operate: 'LIKE'},
{field: 'remark', title: __('Remark'), operate: false, table: table2, class: 'autocontent', formatter: Table.api.formatter.content}, // {field: 'remark', title: __('Remark'), operate: false, table: table2, class: 'autocontent', formatter: Table.api.formatter.content},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, // {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
// {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} // // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
] // ]
] // ]
}); // });
// 为表格2绑定事件 // // 为表格2绑定事件
Table.api.bindevent(table2); // Table.api.bindevent(table2);
} // }
}, },