diff --git a/addons/shopro_wechat_trade/application/admin/controller/shopro_wechat_trade/Sync.php b/addons/shopro_wechat_trade/application/admin/controller/shopro_wechat_trade/Sync.php index 72f713f..6527a63 100644 --- a/addons/shopro_wechat_trade/application/admin/controller/shopro_wechat_trade/Sync.php +++ b/addons/shopro_wechat_trade/application/admin/controller/shopro_wechat_trade/Sync.php @@ -40,6 +40,49 @@ class Sync extends Backend return $stats; } + protected function formatListItem(array $row) + { + $typeMap = [ + 'shipping' => '发货同步', + 'confirm' => '确认收货同步', + ]; + $row['sync_type_text'] = $typeMap[$row['sync_type'] ?? ''] ?? ($row['sync_type'] ?? '-'); + + $status = $row['status'] ?? ''; + $retryCount = intval($row['retry_count'] ?? 0); + if ($status === 'success') { + $row['status_text'] = '成功'; + } elseif ($status === 'failed') { + $row['status_text'] = '失败'; + } elseif ($status === 'pending') { + $row['status_text'] = $retryCount > 0 ? '待重试' : '处理中'; + } else { + $row['status_text'] = $status ?: '-'; + } + + if (($row['sync_type'] ?? '') !== 'shipping') { + $row['delivery_mode_text'] = '-'; + } else { + $modeMap = [1 => '统一发货', 2 => '分拆发货']; + $row['delivery_mode_text'] = $modeMap[intval($row['delivery_mode'] ?? 0)] ?? ('模式' . $row['delivery_mode']); + } + + if ($status === 'success') { + $row['error_text'] = '-'; + } else { + $parts = []; + if ($row['errcode'] !== null && $row['errcode'] !== '') { + $parts[] = '[' . $row['errcode'] . ']'; + } + if (!empty($row['errmsg'])) { + $parts[] = $row['errmsg']; + } + $row['error_text'] = $parts ? implode(' ', $parts) : '-'; + } + + return $row; + } + public function index() { if ($this->request->isAjax()) { @@ -52,6 +95,9 @@ class Sync extends Backend $query = $this->buildQuery($status, $syncType, $orderSn)->order('id', 'desc'); $total = (clone $query)->count(); $list = $query->page($page, $limit)->select(); + foreach ($list as $key => $row) { + $list[$key] = $this->formatListItem($row); + } return json(['total' => $total, 'rows' => $list]); } @@ -67,7 +113,7 @@ class Sync extends Backend if (!$row) { $this->error('记录不存在'); } - $this->success('', null, $row); + $this->success('', null, $this->formatListItem($row)); } public function retry() diff --git a/addons/shopro_wechat_trade/application/admin/view/shopro_wechat_trade/sync/index.html b/addons/shopro_wechat_trade/application/admin/view/shopro_wechat_trade/sync/index.html index 72c7f22..0e978c1 100644 --- a/addons/shopro_wechat_trade/application/admin/view/shopro_wechat_trade/sync/index.html +++ b/addons/shopro_wechat_trade/application/admin/view/shopro_wechat_trade/sync/index.html @@ -24,7 +24,11 @@ font-size: 13px; background: #f5f7fa; color: #606266; + cursor: pointer; + border: 1px solid transparent; + user-select: none; } + .wx-sync-page .stat-item:hover { opacity: 0.85; } .wx-sync-page .stat-item .num { font-weight: 600; margin-left: 4px; @@ -32,15 +36,19 @@ .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 { + .wx-sync-page .stat-item-active { + border-color: currentColor; + box-shadow: 0 0 0 1px currentColor inset; + } + .wx-sync-page .filter-bar { 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-page .filter-bar .form-control { width: auto; min-width: 140px; } + .wx-sync-page .filter-bar .order-sn-input { min-width: 220px; } .wx-sync-detail pre { max-height: 280px; overflow: auto; @@ -70,34 +78,34 @@
说明:本页展示商城向微信「发货信息管理服务」同步的记录,包括 - 发货同步(upload_shipping_info)与确认收货同步(notify_confirm_receive)。 + 发货同步与确认收货同步。 「同步成功」仅表示微信接口返回成功,不代表商城订单状态;订单实际状态请到「订单管理」查看。 失败记录会按配置自动重试,也可在此手动重试。
- 全部{$stats.total|default=0} - 成功{$stats.success|default=0} - 待重试/处理中{$stats.pending|default=0} - 失败{$stats.failed|default=0} + 全部{$stats.total|default=0} + 成功{$stats.success|default=0} + 待重试/处理中{$stats.pending|default=0} + 失败{$stats.failed|default=0}
-
- - - - - - + + + +
diff --git a/addons/shopro_wechat_trade/public/assets/js/backend/shopro_wechat_trade/sync.js b/addons/shopro_wechat_trade/public/assets/js/backend/shopro_wechat_trade/sync.js index b772d75..daecdd9 100644 --- a/addons/shopro_wechat_trade/public/assets/js/backend/shopro_wechat_trade/sync.js +++ b/addons/shopro_wechat_trade/public/assets/js/backend/shopro_wechat_trade/sync.js @@ -13,55 +13,44 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin return $('
').text(text == null ? '' : text).html(); } - function formatSyncType(value) { - var text = SYNC_TYPE_MAP[value] || value || '-'; - if (value === 'shipping') { - return '' + text + ''; + function formatSyncTypeBadge(row) { + var key = row.sync_type || ''; + var text = row.sync_type_text || SYNC_TYPE_MAP[key] || key || '-'; + if (key === 'shipping') { + return '' + escapeHtml(text) + ''; } - if (value === 'confirm') { - return '' + text + ''; + if (key === 'confirm') { + return '' + escapeHtml(text) + ''; } - return text; + return escapeHtml(text); } - function formatStatus(row) { - var status = row.status; - var retryCount = parseInt(row.retry_count, 10) || 0; + function formatStatusBadge(row) { + var text = row.status_text || ''; + var status = row.status || ''; + if (!text) { + var retryCount = parseInt(row.retry_count, 10) || 0; + if (status === 'success') { + text = '成功'; + } else if (status === 'failed') { + text = '失败'; + } else if (status === 'pending') { + text = retryCount > 0 ? '待重试' : '处理中'; + } else { + text = status || '-'; + } + } if (status === 'success') { - return '成功'; + return '' + escapeHtml(text) + ''; } if (status === 'failed') { - return '失败'; + return '' + escapeHtml(text) + ''; } if (status === 'pending') { - if (retryCount > 0) { - return '待重试'; - } - return '处理中'; + var pendingClass = (parseInt(row.retry_count, 10) || 0) > 0 ? 'label-warning' : 'label-default'; + return '' + escapeHtml(text) + ''; } - return status || '-'; - } - - function formatDeliveryMode(value, row) { - if (row.sync_type !== 'shipping') { - return '-'; - } - var text = DELIVERY_MODE_MAP[value] || ('模式' + value); - return text; - } - - function formatErrorInfo(value, row) { - if (row.status === 'success') { - return '-'; - } - var parts = []; - if (row.errcode !== null && row.errcode !== undefined && row.errcode !== '') { - parts.push('[' + row.errcode + ']'); - } - if (row.errmsg) { - parts.push(row.errmsg); - } - return parts.length ? escapeHtml(parts.join(' ')) : '-'; + return escapeHtml(text); } function formatJsonText(raw) { @@ -81,6 +70,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin var Controller = { index: function () { + var $page = $('.wx-sync-page'); + var $statusFilter = $('#wx-sync-status-filter'); + var $typeFilter = $('#wx-sync-type-filter'); + var $orderSnFilter = $('#wx-sync-order-sn-filter'); + Table.api.init({ extend: { index_url: 'shopro_wechat_trade/sync/index', @@ -88,7 +82,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin } }); - var table = $("#table"); + var table = $('#table'); + + function highlightStat(status) { + $page.find('.stat-item').removeClass('stat-item-active'); + $page.find('.stat-item[data-status="' + (status || '') + '"]').addClass('stat-item-active'); + } + + function refreshTable() { + table.bootstrapTable('refresh', { pageNumber: 1 }); + } + + function applyStatusFilter(status) { + $statusFilter.val(status || ''); + highlightStat(status || ''); + refreshTable(); + } table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, @@ -99,9 +108,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin commonSearch: false, showExport: false, queryParams: function (params) { - params.status = $('#status-filter').val(); - params.sync_type = $('#type-filter').val(); - params.order_sn = $.trim($('#order-sn-filter').val()); + params.status = $statusFilter.val(); + params.sync_type = $typeFilter.val(); + params.order_sn = $.trim($orderSnFilter.val()); return params; }, columns: [ @@ -120,31 +129,39 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin } }, { - field: 'sync_type', - title: '同步类型', - formatter: function (value) { - return formatSyncType(value); - } - }, - { - field: 'status', - title: '同步状态', + field: 'sync_type_text', + title: '类型', + escape: false, formatter: function (value, row) { - return formatStatus(row); + return formatSyncTypeBadge(row); } }, { - field: 'delivery_mode', + field: 'status_text', + title: '状态', + escape: false, + formatter: function (value, row) { + return formatStatusBadge(row); + } + }, + { + field: 'delivery_mode_text', title: '发货模式', formatter: function (value, row) { - return formatDeliveryMode(value, row); + if ((row.sync_type || '') !== 'shipping') { + return '-'; + } + return escapeHtml(value || '-'); } }, { - field: 'errmsg', + field: 'error_text', title: '错误信息', formatter: function (value, row) { - return formatErrorInfo(value, row); + if (row.status === 'success' || value === '-') { + return '-'; + } + return escapeHtml(value || '-'); } }, { @@ -167,6 +184,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin field: 'operate', title: '操作', width: 140, + escape: false, table: table, events: Table.api.events.operate, formatter: function (value, row) { @@ -181,36 +199,46 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ] }); - function refreshTable() { - table.bootstrapTable('refresh'); - } + $page.on('click', '.stat-item', function () { + applyStatusFilter($(this).data('status') || ''); + }); - $('#status-filter, #type-filter').on('change', refreshTable); + $statusFilter.on('change', function () { + highlightStat($(this).val() || ''); + refreshTable(); + }); - $('.btn-search').on('click', refreshTable); + $typeFilter.on('change', refreshTable); - $('#order-sn-filter').on('keypress', function (e) { + $page.on('click', '#wx-sync-btn-search', function (e) { + e.preventDefault(); + refreshTable(); + }); + + $page.on('click', '#wx-sync-btn-reset', function (e) { + e.preventDefault(); + $statusFilter.val(''); + $typeFilter.val(''); + $orderSnFilter.val(''); + highlightStat(''); + refreshTable(); + }); + + $page.on('click', '#wx-sync-btn-failed', function (e) { + e.preventDefault(); + applyStatusFilter('failed'); + $typeFilter.val(''); + }); + + $orderSnFilter.on('keypress', function (e) { if (e.which === 13) { + e.preventDefault(); refreshTable(); } }); - $('.btn-reset').on('click', function () { - $('#status-filter').val(''); - $('#type-filter').val(''); - $('#order-sn-filter').val(''); - refreshTable(); - }); - - $('.btn-filter-failed').on('click', function () { - $('#status-filter').val('failed'); - $('#type-filter').val(''); - refreshTable(); - }); - table.on('click', '.btn-order', function () { - var orderId = $(this).data('id'); - Fast.api.open('shopro/order/order/detail?id=' + orderId, '订单详情'); + Fast.api.open('shopro/order/order/detail?id=' + $(this).data('id'), '订单详情'); }); table.on('click', '.btn-retry', function () { @@ -235,10 +263,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin var $tpl = $('#sync-detail-template').clone().removeAttr('id').removeClass('hide'); $tpl.find('.detail-id').text(row.id || '-'); $tpl.find('.detail-order-sn').text(row.order_sn || '-'); - $tpl.find('.detail-sync-type').html(formatSyncType(row.sync_type)); - $tpl.find('.detail-status').html(formatStatus(row)); + $tpl.find('.detail-sync-type').html(formatSyncTypeBadge(row)); + $tpl.find('.detail-status').html(formatStatusBadge(row)); if (row.sync_type === 'shipping') { - $tpl.find('.detail-delivery-mode').text(DELIVERY_MODE_MAP[row.delivery_mode] || ('模式' + row.delivery_mode)); + $tpl.find('.detail-delivery-mode').text(row.delivery_mode_text || DELIVERY_MODE_MAP[row.delivery_mode] || '-'); $tpl.find('.detail-delivery-mode-row').show(); } else { $tpl.find('.detail-delivery-mode-row').hide(); @@ -247,14 +275,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin if (row.status === 'success') { $tpl.find('.detail-error-row').hide(); } else { - var errParts = []; - if (row.errcode !== null && row.errcode !== undefined && row.errcode !== '') { - errParts.push('[' + row.errcode + ']'); - } - if (row.errmsg) { - errParts.push(row.errmsg); - } - $tpl.find('.detail-error').text(errParts.join(' ') || '-'); + $tpl.find('.detail-error').text(row.error_text && row.error_text !== '-' ? row.error_text : '-'); $tpl.find('.detail-error-row').show(); } $tpl.find('.detail-create').text(formatDatetime(row.createtime)); diff --git a/application/admin/controller/shopro_wechat_trade/Sync.php b/application/admin/controller/shopro_wechat_trade/Sync.php index 72f713f..6527a63 100644 --- a/application/admin/controller/shopro_wechat_trade/Sync.php +++ b/application/admin/controller/shopro_wechat_trade/Sync.php @@ -40,6 +40,49 @@ class Sync extends Backend return $stats; } + protected function formatListItem(array $row) + { + $typeMap = [ + 'shipping' => '发货同步', + 'confirm' => '确认收货同步', + ]; + $row['sync_type_text'] = $typeMap[$row['sync_type'] ?? ''] ?? ($row['sync_type'] ?? '-'); + + $status = $row['status'] ?? ''; + $retryCount = intval($row['retry_count'] ?? 0); + if ($status === 'success') { + $row['status_text'] = '成功'; + } elseif ($status === 'failed') { + $row['status_text'] = '失败'; + } elseif ($status === 'pending') { + $row['status_text'] = $retryCount > 0 ? '待重试' : '处理中'; + } else { + $row['status_text'] = $status ?: '-'; + } + + if (($row['sync_type'] ?? '') !== 'shipping') { + $row['delivery_mode_text'] = '-'; + } else { + $modeMap = [1 => '统一发货', 2 => '分拆发货']; + $row['delivery_mode_text'] = $modeMap[intval($row['delivery_mode'] ?? 0)] ?? ('模式' . $row['delivery_mode']); + } + + if ($status === 'success') { + $row['error_text'] = '-'; + } else { + $parts = []; + if ($row['errcode'] !== null && $row['errcode'] !== '') { + $parts[] = '[' . $row['errcode'] . ']'; + } + if (!empty($row['errmsg'])) { + $parts[] = $row['errmsg']; + } + $row['error_text'] = $parts ? implode(' ', $parts) : '-'; + } + + return $row; + } + public function index() { if ($this->request->isAjax()) { @@ -52,6 +95,9 @@ class Sync extends Backend $query = $this->buildQuery($status, $syncType, $orderSn)->order('id', 'desc'); $total = (clone $query)->count(); $list = $query->page($page, $limit)->select(); + foreach ($list as $key => $row) { + $list[$key] = $this->formatListItem($row); + } return json(['total' => $total, 'rows' => $list]); } @@ -67,7 +113,7 @@ class Sync extends Backend if (!$row) { $this->error('记录不存在'); } - $this->success('', null, $row); + $this->success('', null, $this->formatListItem($row)); } public function retry() diff --git a/application/admin/view/shopro_wechat_trade/sync/index.html b/application/admin/view/shopro_wechat_trade/sync/index.html index 72c7f22..0e978c1 100644 --- a/application/admin/view/shopro_wechat_trade/sync/index.html +++ b/application/admin/view/shopro_wechat_trade/sync/index.html @@ -24,7 +24,11 @@ font-size: 13px; background: #f5f7fa; color: #606266; + cursor: pointer; + border: 1px solid transparent; + user-select: none; } + .wx-sync-page .stat-item:hover { opacity: 0.85; } .wx-sync-page .stat-item .num { font-weight: 600; margin-left: 4px; @@ -32,15 +36,19 @@ .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 { + .wx-sync-page .stat-item-active { + border-color: currentColor; + box-shadow: 0 0 0 1px currentColor inset; + } + .wx-sync-page .filter-bar { 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-page .filter-bar .form-control { width: auto; min-width: 140px; } + .wx-sync-page .filter-bar .order-sn-input { min-width: 220px; } .wx-sync-detail pre { max-height: 280px; overflow: auto; @@ -70,34 +78,34 @@
说明:本页展示商城向微信「发货信息管理服务」同步的记录,包括 - 发货同步(upload_shipping_info)与确认收货同步(notify_confirm_receive)。 + 发货同步与确认收货同步。 「同步成功」仅表示微信接口返回成功,不代表商城订单状态;订单实际状态请到「订单管理」查看。 失败记录会按配置自动重试,也可在此手动重试。
- 全部{$stats.total|default=0} - 成功{$stats.success|default=0} - 待重试/处理中{$stats.pending|default=0} - 失败{$stats.failed|default=0} + 全部{$stats.total|default=0} + 成功{$stats.success|default=0} + 待重试/处理中{$stats.pending|default=0} + 失败{$stats.failed|default=0}
-
- - - - - - + + + +
diff --git a/public/assets/js/backend/shopro_wechat_trade/sync.js b/public/assets/js/backend/shopro_wechat_trade/sync.js index 60d37d1..daecdd9 100644 --- a/public/assets/js/backend/shopro_wechat_trade/sync.js +++ b/public/assets/js/backend/shopro_wechat_trade/sync.js @@ -1,6 +1,80 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + var SYNC_TYPE_MAP = { + shipping: '发货同步', + confirm: '确认收货同步' + }; + + var DELIVERY_MODE_MAP = { + 1: '统一发货', + 2: '分拆发货' + }; + + function escapeHtml(text) { + return $('
').text(text == null ? '' : text).html(); + } + + function formatSyncTypeBadge(row) { + var key = row.sync_type || ''; + var text = row.sync_type_text || SYNC_TYPE_MAP[key] || key || '-'; + if (key === 'shipping') { + return '' + escapeHtml(text) + ''; + } + if (key === 'confirm') { + return '' + escapeHtml(text) + ''; + } + return escapeHtml(text); + } + + function formatStatusBadge(row) { + var text = row.status_text || ''; + var status = row.status || ''; + if (!text) { + var retryCount = parseInt(row.retry_count, 10) || 0; + if (status === 'success') { + text = '成功'; + } else if (status === 'failed') { + text = '失败'; + } else if (status === 'pending') { + text = retryCount > 0 ? '待重试' : '处理中'; + } else { + text = status || '-'; + } + } + if (status === 'success') { + return '' + escapeHtml(text) + ''; + } + if (status === 'failed') { + return '' + escapeHtml(text) + ''; + } + if (status === 'pending') { + var pendingClass = (parseInt(row.retry_count, 10) || 0) > 0 ? 'label-warning' : 'label-default'; + return '' + escapeHtml(text) + ''; + } + return escapeHtml(text); + } + + function formatJsonText(raw) { + if (!raw) { + return '(无)'; + } + try { + return JSON.stringify(JSON.parse(raw), null, 2); + } catch (e) { + return raw; + } + } + + function formatDatetime(value) { + return value ? Table.api.formatter.datetime(value) : '-'; + } + var Controller = { index: function () { + var $page = $('.wx-sync-page'); + var $statusFilter = $('#wx-sync-status-filter'); + var $typeFilter = $('#wx-sync-type-filter'); + var $orderSnFilter = $('#wx-sync-order-sn-filter'); + Table.api.init({ extend: { index_url: 'shopro_wechat_trade/sync/index', @@ -8,56 +82,214 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin } }); - var table = $("#table"); + var table = $('#table'); + + function highlightStat(status) { + $page.find('.stat-item').removeClass('stat-item-active'); + $page.find('.stat-item[data-status="' + (status || '') + '"]').addClass('stat-item-active'); + } + + function refreshTable() { + table.bootstrapTable('refresh', { pageNumber: 1 }); + } + + function applyStatusFilter(status) { + $statusFilter.val(status || ''); + highlightStat(status || ''); + refreshTable(); + } + table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', sortOrder: 'desc', + search: false, + commonSearch: false, + showExport: false, queryParams: function (params) { - params.status = $('#status-filter').val(); + params.status = $statusFilter.val(); + params.sync_type = $typeFilter.val(); + params.order_sn = $.trim($orderSnFilter.val()); return params; }, columns: [ - { field: 'id', title: 'ID' }, - { field: 'order_sn', title: '订单号' }, - { field: 'sync_type', title: '类型' }, - { field: 'status', title: '状态' }, - { field: 'delivery_mode', title: '发货模式' }, - { field: 'errcode', title: 'errcode' }, - { field: 'errmsg', title: 'errmsg' }, - { field: 'retry_count', title: '重试次数' }, + { field: 'id', title: 'ID', width: 70 }, + { + field: 'order_sn', + title: '订单号', + formatter: function (value, row) { + if (!value) { + return '-'; + } + if (row.order_id) { + return '' + escapeHtml(value) + ''; + } + return escapeHtml(value); + } + }, + { + field: 'sync_type_text', + title: '类型', + escape: false, + formatter: function (value, row) { + return formatSyncTypeBadge(row); + } + }, + { + field: 'status_text', + title: '状态', + escape: false, + formatter: function (value, row) { + return formatStatusBadge(row); + } + }, + { + field: 'delivery_mode_text', + title: '发货模式', + formatter: function (value, row) { + if ((row.sync_type || '') !== 'shipping') { + return '-'; + } + return escapeHtml(value || '-'); + } + }, + { + field: 'error_text', + title: '错误信息', + formatter: function (value, row) { + if (row.status === 'success' || value === '-') { + return '-'; + } + return escapeHtml(value || '-'); + } + }, + { + field: 'retry_count', + title: '重试次数', + width: 90, + formatter: function (value, row) { + if (row.status === 'success') { + return '-'; + } + return value || 0; + } + }, { field: 'createtime', title: '创建时间', - formatter: function (value) { - return value ? Table.api.formatter.datetime(value) : ''; - } + formatter: formatDatetime }, { field: 'operate', title: '操作', + width: 140, + escape: false, table: table, events: Table.api.events.operate, formatter: function (value, row) { - if (row.status === 'success') { - return '-'; + var html = []; + html.push('详情'); + if (row.status !== 'success') { + html.push(' 重试'); } - return '重试'; + return html.join(''); } } ] }); - $('#status-filter').on('change', function () { - table.bootstrapTable('refresh'); + $page.on('click', '.stat-item', function () { + applyStatusFilter($(this).data('status') || ''); + }); + + $statusFilter.on('change', function () { + highlightStat($(this).val() || ''); + refreshTable(); + }); + + $typeFilter.on('change', refreshTable); + + $page.on('click', '#wx-sync-btn-search', function (e) { + e.preventDefault(); + refreshTable(); + }); + + $page.on('click', '#wx-sync-btn-reset', function (e) { + e.preventDefault(); + $statusFilter.val(''); + $typeFilter.val(''); + $orderSnFilter.val(''); + highlightStat(''); + refreshTable(); + }); + + $page.on('click', '#wx-sync-btn-failed', function (e) { + e.preventDefault(); + applyStatusFilter('failed'); + $typeFilter.val(''); + }); + + $orderSnFilter.on('keypress', function (e) { + if (e.which === 13) { + e.preventDefault(); + refreshTable(); + } + }); + + table.on('click', '.btn-order', function () { + Fast.api.open('shopro/order/order/detail?id=' + $(this).data('id'), '订单详情'); }); table.on('click', '.btn-retry', function () { var id = $(this).data('id'); - $.post('shopro_wechat_trade/sync/retry', { id: id }, function (ret) { - Backend.api.toastr[ret.code === 1 ? 'success' : 'error'](ret.msg); - table.bootstrapTable('refresh'); + Layer.confirm('将重新向微信发起同步请求,是否继续?', { icon: 3, title: '确认重试' }, function (index) { + Layer.close(index); + $.post('shopro_wechat_trade/sync/retry', { id: id }, function (ret) { + Backend.api.toastr[ret.code === 1 ? 'success' : 'error'](ret.msg); + refreshTable(); + }); + }); + }); + + table.on('click', '.btn-detail', function () { + var id = $(this).data('id'); + $.get('shopro_wechat_trade/sync/detail', { id: id }, function (ret) { + if (ret.code !== 1) { + Backend.api.toastr.error(ret.msg || '加载失败'); + return; + } + var row = ret.data || {}; + var $tpl = $('#sync-detail-template').clone().removeAttr('id').removeClass('hide'); + $tpl.find('.detail-id').text(row.id || '-'); + $tpl.find('.detail-order-sn').text(row.order_sn || '-'); + $tpl.find('.detail-sync-type').html(formatSyncTypeBadge(row)); + $tpl.find('.detail-status').html(formatStatusBadge(row)); + if (row.sync_type === 'shipping') { + $tpl.find('.detail-delivery-mode').text(row.delivery_mode_text || DELIVERY_MODE_MAP[row.delivery_mode] || '-'); + $tpl.find('.detail-delivery-mode-row').show(); + } else { + $tpl.find('.detail-delivery-mode-row').hide(); + } + $tpl.find('.detail-retry').text(row.retry_count || 0); + if (row.status === 'success') { + $tpl.find('.detail-error-row').hide(); + } else { + $tpl.find('.detail-error').text(row.error_text && row.error_text !== '-' ? row.error_text : '-'); + $tpl.find('.detail-error-row').show(); + } + $tpl.find('.detail-create').text(formatDatetime(row.createtime)); + $tpl.find('.detail-update').text(formatDatetime(row.updatetime)); + $tpl.find('.detail-request').text(formatJsonText(row.request_payload)); + $tpl.find('.detail-response').text(formatJsonText(row.response_payload)); + + Layer.open({ + type: 1, + title: '同步记录详情 #' + row.id, + area: ['720px', '80%'], + shadeClose: true, + content: $tpl.prop('outerHTML') + }); }); });