功能:新增下一阶段运营能力和生产部署

This commit is contained in:
xiaowang
2026-05-24 18:09:11 +08:00
parent 8116abc9b5
commit 1d077d4089
157 changed files with 9206 additions and 74 deletions
+260 -1
View File
@@ -3,6 +3,8 @@
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const orderApi = require('../../api/order')
const paymentApi = require('../../api/payment')
const afterSaleApi = require('../../api/after-sale')
const cartApi = require('../../api/cart')
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
@@ -35,6 +37,19 @@ const { buildRecoveryState, clearRecoveryState } = require('../../utils/recovery
*/
const REVIEW_SCORE_OPTIONS = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
const PAYMENT_STATUS_TEXT = {
UNPAID: '待支付',
PAYING: '待确认支付',
PAID: '已支付',
REFUNDED: '已退款'
}
const AFTER_SALE_STATUS_TEXT = {
PENDING: '审核中',
APPROVED: '已通过',
REJECTED: '已拒绝'
}
/**
* Purpose: toId supports index.js by holding or executing the to id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
@@ -69,6 +84,120 @@ function trimText(value) {
return String(value || '').trim()
}
function normalizeStatus(value) {
return String(value || '').trim().toUpperCase()
}
function firstFilled(values) {
return values.find(value => value !== undefined && value !== null && value !== '')
}
function toAmount(value) {
const amount = Number(value)
return isFinite(amount) ? amount : 0
}
function getOrderPayAmount(order) {
return toAmount(firstFilled([
order && order.payAmount,
order && order.actualAmount,
order && order.totalAmount
]))
}
function resolvePaymentStatus(order) {
const status = normalizeStatus(order && (order.paymentStatus || order.payStatus || order.paymentState))
if (status) {
return status
}
if (Number(order && order.status) === 2 || getOrderPayAmount(order) <= 0) {
return 'PAID'
}
return 'UNPAID'
}
function buildPaymentInfo(order) {
const status = resolvePaymentStatus(order)
const payAmount = getOrderPayAmount(order)
const paidAmount = toAmount(firstFilled([
order && order.paidAmount,
status === 'PAID' ? payAmount : ''
]))
return {
status,
statusText: PAYMENT_STATUS_TEXT[status] || status || '待支付',
statusClass: `payment-${status.toLowerCase() || 'unpaid'}`,
amountText: `¥${formatPrice(payAmount)}`,
paidAmountText: `¥${formatPrice(paidAmount)}`,
payNoText: (order && (order.paymentOrderNo || order.payNo)) || '',
canPay: status === 'UNPAID' || status === 'PAYING',
isPaid: status === 'PAID',
isRefunded: status === 'REFUNDED'
}
}
function getAfterSaleStatusText(record) {
const status = normalizeStatus(record && record.status)
return AFTER_SALE_STATUS_TEXT[status] || status || '已申请'
}
function buildAfterSaleSummary(record) {
if (!record) {
return null
}
const amount = firstFilled([record.refundAmount, record.amount])
return {
...record,
status: normalizeStatus(record.status),
statusText: getAfterSaleStatusText(record),
typeText: record.type === 'REFUND' ? '退款' : (record.type || '售后'),
amountText: amount === undefined || amount === null || amount === '' ? '' : `¥${formatPrice(amount)}`,
reasonText: trimText(record.reason),
auditReasonText: trimText(record.auditReason),
createdText: formatDateTime(record.createTime)
}
}
function latestRecordTime(record) {
return String((record && (record.auditTime || record.updateTime || record.createTime)) || '')
}
function extractListPayload(payload) {
if (Array.isArray(payload)) {
return payload
}
if (payload && Array.isArray(payload.list)) {
return payload.list
}
if (payload && Array.isArray(payload.records)) {
return payload.records
}
return []
}
function indexLatestAfterSaleByOrderId(list) {
return safeList(list).reduce((result, item) => {
const orderId = toId(item && item.orderId)
if (!orderId) {
return result
}
const current = result[orderId]
if (!current || latestRecordTime(item).localeCompare(latestRecordTime(current)) > 0) {
result[orderId] = item
}
return result
}, {})
}
function canApplyAfterSale(order, afterSaleSummary) {
const paymentInfo = order && order.paymentInfo ? order.paymentInfo : buildPaymentInfo(order)
const afterSaleStatus = normalizeStatus(afterSaleSummary && afterSaleSummary.status)
return paymentInfo.isPaid
&& Number(order && order.status) !== 3
&& afterSaleStatus !== 'PENDING'
&& afterSaleStatus !== 'APPROVED'
}
/**
* Purpose: formatRating supports index.js by holding or executing the format rating page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
@@ -289,15 +418,20 @@ async function safeCall(factory, fallbackValue) {
async function loadAssistData(orders) {
const pendingReviewsPromise = safeCall(() => orderApi.listMyPendingReviews(), [])
const pendingChangesPromise = safeCall(() => orderApi.listMyPendingArtistChangeRequests(), [])
const afterSalesPromise = safeCall(() => afterSaleApi.getMyAfterSales({
page: 1,
size: 50
}), { list: [] })
const orderReviewListsPromise = Promise.all(orders.map(order => (
safeCall(() => orderApi.listOrderReviews(order.id), [])
)))
const orderChangeListsPromise = Promise.all(orders.map(order => (
safeCall(() => orderApi.listOrderArtistChangeRequests(order.id), [])
)))
const [pendingReviews, pendingChanges, orderReviewLists, orderChangeLists] = await Promise.all([
const [pendingReviews, pendingChanges, afterSales, orderReviewLists, orderChangeLists] = await Promise.all([
pendingReviewsPromise,
pendingChangesPromise,
afterSalesPromise,
orderReviewListsPromise,
orderChangeListsPromise
])
@@ -315,6 +449,7 @@ async function loadAssistData(orders) {
pendingReviewByItemId: indexByOrderItemId(pendingReviews),
submittedReviewByItemId: indexByOrderItemId(submittedReviews),
pendingChangeByItemId: indexByOrderItemId(pendingChanges),
afterSaleByOrderId: indexLatestAfterSaleByOrderId(extractListPayload(afterSales)),
pendingReviews,
reviewsByOrderId: safeList(orders).reduce((result, order, index) => {
result[toId(order && order.id)] = safeList(orderReviewLists[index])
@@ -435,6 +570,8 @@ Page({
statusClass: getOrderStatusClass(order),
shopNameText: order.shopName ? `所属店铺:${order.shopName}` : '',
actualAmountText: `\u00a5${formatPrice(order.actualAmount)}`,
paymentInfo: buildPaymentInfo(order),
afterSaleSummary: buildAfterSaleSummary(order.afterSaleSummary || assistData.afterSaleByOrderId[toId(order.id)]),
timeline: buildOrderTimeline(order, assistData.reviewsByOrderId[toId(order.id)], assistData.changesByOrderId[toId(order.id)], assistData.pendingReviews),
items: await Promise.all(safeList(order.items).map(async item => {
const itemId = toId(item.id)
@@ -461,6 +598,7 @@ Page({
formattedOrders.forEach(order => {
order.canRebook = Number(order.status) === 2 && getRebookableOrderItems(order).length > 0
order.canApplyAfterSale = canApplyAfterSale(order, order.afterSaleSummary)
})
this.setData({
@@ -708,6 +846,127 @@ Page({
}
},
async handlePayOrder(event) {
const orderId = event.currentTarget.dataset.orderId
const order = findOrderById(this.data.orders, orderId)
if (!order || !order.paymentInfo || !order.paymentInfo.canPay) {
wx.showToast({
title: '当前订单无需支付',
icon: 'none'
})
return
}
try {
await actionGuard.run(this, `order:pay:${orderId}`, async () => {
await runWithLoading(() => paymentApi.prepareOrderPayment(orderId), {
title: '准备支付'
})
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '模拟支付',
content: `本次需支付 ${order.paymentInfo.amountText},确认模拟支付成功吗?`,
confirmText: '确认支付',
success: res => resolve(Boolean(res.confirm)),
fail: () => resolve(false)
})
})
if (!confirmed) {
return
}
await runWithLoading(() => paymentApi.mockOrderPaymentSuccess(orderId), {
title: '确认支付'
})
wx.showToast({
title: '支付已确认',
icon: 'none'
})
await this.loadOrders()
}, {
message: '支付处理中,请勿重复点击'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '支付失败',
icon: 'none'
})
}
},
async handleApplyAfterSale(event) {
const orderId = event.currentTarget.dataset.orderId
const order = findOrderById(this.data.orders, orderId)
if (!order || !order.canApplyAfterSale) {
wx.showToast({
title: '当前订单暂不可申请售后',
icon: 'none'
})
return
}
try {
await actionGuard.run(this, `order:after-sale:${orderId}`, async () => {
const reason = await this.promptAfterSaleReason()
if (!reason) {
return
}
await runWithLoading(() => afterSaleApi.applyAfterSale({
orderId,
type: 'REFUND',
reason,
refundAmount: getOrderPayAmount(order)
}), {
title: '提交售后'
})
wx.showToast({
title: '售后已提交',
icon: 'none'
})
await this.loadOrders()
}, {
message: '售后申请提交中,请勿重复点击'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '售后申请失败',
icon: 'none'
})
}
},
promptAfterSaleReason() {
return new Promise(resolve => {
wx.showModal({
title: '申请售后',
content: '请填写售后原因,提交后门店会尽快处理。',
editable: true,
placeholderText: '例如:需要退款或调整服务',
confirmText: '提交',
success: res => {
if (!res.confirm) {
resolve('')
return
}
const reason = trimText(res.content)
if (!reason) {
wx.showToast({
title: '请填写售后原因',
icon: 'none'
})
}
resolve(reason)
},
fail: () => resolve('')
})
})
},
/**
* Purpose: promptRejectReason collects an optional customer reason before rejecting an artist-change request.
* Usage: call it after the confirmation dialog and pass the returned text to rejectArtistChange.
+22
View File
@@ -25,6 +25,26 @@
</view>
<view wx:if="{{item.shopNameText}}" class="order-shop">{{item.shopNameText}}</view>
<view class="payment-panel">
<view class="payment-copy">
<text class="assist-label">支付状态</text>
<text class="assist-main">{{item.paymentInfo.statusText}}</text>
<text wx:if="{{item.paymentInfo.payNoText}}" class="assist-desc">支付单:{{item.paymentInfo.payNoText}}</text>
</view>
<view class="payment-amount">
<text>{{item.paymentInfo.amountText}}</text>
<text wx:if="{{item.paymentInfo.isPaid}}">实付 {{item.paymentInfo.paidAmountText}}</text>
</view>
</view>
<view wx:if="{{item.afterSaleSummary}}" class="after-sale-summary">
<text class="assist-label">售后进度</text>
<text class="assist-main">{{item.afterSaleSummary.typeText}} · {{item.afterSaleSummary.statusText}}</text>
<text wx:if="{{item.afterSaleSummary.amountText}}" class="assist-desc">申请金额:{{item.afterSaleSummary.amountText}}</text>
<text wx:if="{{item.afterSaleSummary.reasonText}}" class="assist-desc">原因:{{item.afterSaleSummary.reasonText}}</text>
<text wx:if="{{item.afterSaleSummary.auditReasonText}}" class="assist-desc">处理说明:{{item.afterSaleSummary.auditReasonText}}</text>
</view>
<view wx:if="{{item.timeline && item.timeline.length}}" class="order-timeline">
<view
wx:for="{{item.timeline}}"
@@ -104,6 +124,8 @@
<view class="order-foot">
<text class="order-amount">总计:{{item.actualAmountText}}</text>
<view class="order-actions">
<view wx:if="{{item.paymentInfo.canPay}}" class="pay-btn" data-order-id="{{item.id}}" bindtap="handlePayOrder">去支付</view>
<view wx:if="{{item.canApplyAfterSale}}" class="after-sale-btn" data-order-id="{{item.id}}" bindtap="handleApplyAfterSale">申请售后</view>
<view wx:if="{{item.canRebook}}" class="rebook-btn" data-order-id="{{item.id}}" bindtap="handleRebookOrder">复刻同款</view>
<view wx:if="{{item.status == 1}}" class="cancel-btn" data-order-id="{{item.id}}" bindtap="handleCancelOrder">取消订单</view>
</view>
+53
View File
@@ -82,6 +82,46 @@
line-height: 1.5;
}
.payment-panel {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
margin-top: 18rpx;
padding: 18rpx 20rpx;
border-radius: 18rpx;
background: var(--theme-primary-soft);
}
.payment-copy {
flex: 1;
min-width: 0;
}
.payment-amount {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 6rpx;
color: #2d2430;
font-size: 26rpx;
font-weight: 800;
}
.payment-amount text:last-child {
color: #8d7a84;
font-size: 22rpx;
font-weight: 600;
}
.after-sale-summary {
margin-top: 16rpx;
padding: 18rpx 20rpx;
border-radius: 18rpx;
background: rgba(255, 247, 249, 0.82);
border: 2rpx solid var(--theme-border);
}
.order-timeline {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
@@ -230,6 +270,8 @@
color: #2d2430;
}
.pay-btn,
.after-sale-btn,
.cancel-btn,
.rebook-btn {
display: inline-flex;
@@ -243,6 +285,17 @@
font-weight: 700;
}
.pay-btn {
background: var(--theme-primary);
color: #ffffff;
}
.after-sale-btn {
background: #ffffff;
border: 2rpx solid var(--theme-border);
color: #5d4b55;
}
.rebook-btn {
background: var(--theme-primary);
color: #ffffff;