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

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.