```
feat(shopro_wechat_trade): 增加微信发货/确认收货同步页面功能 增加统计信息显示、筛选搜索功能和详细信息弹窗,优化用户体验 - 添加buildQuery方法用于构建查询条件,支持状态、同步类型和订单号筛选 - 添加getStats方法获取各状态统计数据并在页面显示统计栏 - 在index页面增加类型筛选、订单号搜索、重置和仅看失败按钮 - 实现detail方法用于获取同步记录详情 - 增加详细的CSS样式和前端交互逻辑 - 添加防止重复重试成功记录的验证 - 格式化JSON数据显示和错误信息展示 ```
这个提交包含在:
@@ -8,25 +8,68 @@ use think\Db;
|
||||
|
||||
class Sync extends Backend
|
||||
{
|
||||
protected function buildQuery($status = '', $syncType = '', $orderSn = '')
|
||||
{
|
||||
$query = Db::name('shopro_wechat_trade_sync');
|
||||
if ($status !== '') {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
if ($syncType !== '') {
|
||||
$query->where('sync_type', $syncType);
|
||||
}
|
||||
if ($orderSn !== '') {
|
||||
$query->where('order_sn', 'like', '%' . $orderSn . '%');
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getStats()
|
||||
{
|
||||
$rows = Db::name('shopro_wechat_trade_sync')
|
||||
->field('status, COUNT(*) AS cnt')
|
||||
->group('status')
|
||||
->select();
|
||||
$stats = ['success' => 0, 'pending' => 0, 'failed' => 0, 'total' => 0];
|
||||
foreach ($rows as $row) {
|
||||
$key = $row['status'] ?? '';
|
||||
if (isset($stats[$key])) {
|
||||
$stats[$key] = intval($row['cnt']);
|
||||
}
|
||||
$stats['total'] += intval($row['cnt']);
|
||||
}
|
||||
return $stats;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$page = max(1, intval($this->request->get('page', 1)));
|
||||
$limit = max(1, min(100, intval($this->request->get('limit', 20))));
|
||||
$status = trim($this->request->get('status', ''));
|
||||
$syncType = trim($this->request->get('sync_type', ''));
|
||||
$orderSn = trim($this->request->get('order_sn', ''));
|
||||
|
||||
$query = Db::name('shopro_wechat_trade_sync')->order('id', 'desc');
|
||||
if ($status !== '') {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
$total = $query->count();
|
||||
$query = $this->buildQuery($status, $syncType, $orderSn)->order('id', 'desc');
|
||||
$total = (clone $query)->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
|
||||
return json(['total' => $total, 'rows' => $list]);
|
||||
}
|
||||
|
||||
$this->view->assign('stats', $this->getStats());
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
$id = intval($this->request->get('id'));
|
||||
$row = Db::name('shopro_wechat_trade_sync')->where('id', $id)->find();
|
||||
if (!$row) {
|
||||
$this->error('记录不存在');
|
||||
}
|
||||
$this->success('', null, $row);
|
||||
}
|
||||
|
||||
public function retry()
|
||||
{
|
||||
$id = intval($this->request->post('id'));
|
||||
@@ -34,6 +77,9 @@ class Sync extends Backend
|
||||
if (!$row) {
|
||||
$this->error('记录不存在');
|
||||
}
|
||||
if ($row['status'] === 'success') {
|
||||
$this->error('该记录已同步成功,无需重试');
|
||||
}
|
||||
try {
|
||||
$service = new WxShippingService();
|
||||
if ($row['sync_type'] === 'confirm') {
|
||||
|
||||
@@ -1,14 +1,122 @@
|
||||
<div class="panel panel-default panel-intro">
|
||||
<div class="panel-heading">微信发货/确认收货同步日志</div>
|
||||
<style>
|
||||
.wx-sync-page .page-tip {
|
||||
margin-bottom: 14px;
|
||||
padding: 12px 14px;
|
||||
background: #f4f8ff;
|
||||
border: 1px solid #d9e8ff;
|
||||
border-radius: 4px;
|
||||
color: #606266;
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.wx-sync-page .page-tip strong { color: #303133; }
|
||||
.wx-sync-page .stats-bar {
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.wx-sync-page .stat-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 6px 12px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
background: #f5f7fa;
|
||||
color: #606266;
|
||||
}
|
||||
.wx-sync-page .stat-item .num {
|
||||
font-weight: 600;
|
||||
margin-left: 4px;
|
||||
}
|
||||
.wx-sync-page .stat-success { background: #f0f9eb; color: #67c23a; }
|
||||
.wx-sync-page .stat-pending { background: #fdf6ec; color: #e6a23c; }
|
||||
.wx-sync-page .stat-failed { background: #fef0f0; color: #f56c6c; }
|
||||
.wx-sync-page .toolbar-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.wx-sync-page .toolbar-row .form-control { width: auto; min-width: 140px; }
|
||||
.wx-sync-page .toolbar-row .order-sn-input { min-width: 220px; }
|
||||
.wx-sync-detail pre {
|
||||
max-height: 280px;
|
||||
overflow: auto;
|
||||
background: #f5f7fa;
|
||||
border: 1px solid #ebeef5;
|
||||
border-radius: 4px;
|
||||
padding: 10px;
|
||||
font-size: 12px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
.wx-sync-detail .detail-row {
|
||||
margin-bottom: 10px;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.wx-sync-detail .detail-label {
|
||||
color: #909399;
|
||||
margin-right: 6px;
|
||||
}
|
||||
</style>
|
||||
<div class="panel panel-default panel-intro wx-sync-page">
|
||||
<div class="panel-heading">
|
||||
微信发货/确认收货同步日志
|
||||
<span class="text-muted" style="font-size:12px;margin-left:10px;">记录向微信平台同步的操作结果,供排查与手动重试</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div id="toolbar" class="toolbar">
|
||||
<select id="status-filter" class="form-control" style="width:160px;display:inline-block;">
|
||||
<div class="page-tip">
|
||||
<strong>说明:</strong>本页展示商城向微信「发货信息管理服务」同步的记录,包括
|
||||
<strong>发货同步</strong>(upload_shipping_info)与<strong>确认收货同步</strong>(notify_confirm_receive)。
|
||||
「同步成功」仅表示微信接口返回成功,<strong>不代表</strong>商城订单状态;订单实际状态请到「订单管理」查看。
|
||||
失败记录会按配置自动重试,也可在此手动重试。
|
||||
</div>
|
||||
|
||||
<div class="stats-bar">
|
||||
<span class="stat-item">全部<span class="num">{$stats.total|default=0}</span></span>
|
||||
<span class="stat-item stat-success">成功<span class="num">{$stats.success|default=0}</span></span>
|
||||
<span class="stat-item stat-pending">待重试/处理中<span class="num">{$stats.pending|default=0}</span></span>
|
||||
<span class="stat-item stat-failed">失败<span class="num">{$stats.failed|default=0}</span></span>
|
||||
</div>
|
||||
|
||||
<div id="toolbar" class="toolbar toolbar-row">
|
||||
<select id="status-filter" class="form-control">
|
||||
<option value="">全部状态</option>
|
||||
<option value="pending">pending</option>
|
||||
<option value="success">success</option>
|
||||
<option value="failed">failed</option>
|
||||
<option value="success">成功</option>
|
||||
<option value="pending">待重试/处理中</option>
|
||||
<option value="failed">失败</option>
|
||||
</select>
|
||||
<select id="type-filter" class="form-control">
|
||||
<option value="">全部类型</option>
|
||||
<option value="shipping">发货同步</option>
|
||||
<option value="confirm">确认收货同步</option>
|
||||
</select>
|
||||
<input type="text" id="order-sn-filter" class="form-control order-sn-input" placeholder="搜索订单号">
|
||||
<button type="button" class="btn btn-primary btn-search"><i class="fa fa-search"></i> 搜索</button>
|
||||
<button type="button" class="btn btn-default btn-reset">重置</button>
|
||||
<button type="button" class="btn btn-warning btn-filter-failed">仅看失败</button>
|
||||
</div>
|
||||
<table id="table" class="table table-striped table-bordered table-hover" width="100%"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="sync-detail-template" class="hide wx-sync-detail">
|
||||
<div style="padding:16px;">
|
||||
<div class="detail-row"><span class="detail-label">记录ID:</span><span class="detail-id"></span></div>
|
||||
<div class="detail-row"><span class="detail-label">订单号:</span><span class="detail-order-sn"></span></div>
|
||||
<div class="detail-row"><span class="detail-label">同步类型:</span><span class="detail-sync-type"></span></div>
|
||||
<div class="detail-row"><span class="detail-label">同步状态:</span><span class="detail-status"></span></div>
|
||||
<div class="detail-row detail-delivery-mode-row"><span class="detail-label">发货模式:</span><span class="detail-delivery-mode"></span></div>
|
||||
<div class="detail-row"><span class="detail-label">重试次数:</span><span class="detail-retry"></span></div>
|
||||
<div class="detail-row detail-error-row"><span class="detail-label">错误信息:</span><span class="detail-error"></span></div>
|
||||
<div class="detail-row"><span class="detail-label">创建时间:</span><span class="detail-create"></span></div>
|
||||
<div class="detail-row"><span class="detail-label">更新时间:</span><span class="detail-update"></span></div>
|
||||
<div class="detail-row"><span class="detail-label">请求内容:</span></div>
|
||||
<pre class="detail-request"></pre>
|
||||
<div class="detail-row"><span class="detail-label">响应内容:</span></div>
|
||||
<pre class="detail-response"></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
在新工单中引用
屏蔽一个用户