功能:完善订单流程和加固

This commit is contained in:
xiaowang
2026-05-23 15:16:40 +08:00
parent 9227ec6175
commit 3e6e1cc4e8
90 changed files with 6859 additions and 368 deletions
+260 -6
View File
@@ -12,6 +12,212 @@ const STATUS_OPTIONS = [
{ label: '已取消', value: 0 }
]
function toId(value) {
return value === undefined || value === null ? '' : String(value)
}
function sameId(left, right) {
const leftId = toId(left)
const rightId = toId(right)
return leftId !== '' && leftId === rightId
}
function safeList(value) {
return Array.isArray(value) ? value : []
}
function trimText(value) {
return String(value || '').trim()
}
function formatRating(value) {
const rating = Number(value)
if (!isFinite(rating) || rating <= 0) {
return ''
}
return rating % 1 === 0 ? String(rating) : rating.toFixed(1)
}
function isSubmittedReview(review) {
if (!review) {
return false
}
if (Number(review.status) === 1) {
return true
}
return Boolean(review.rating)
}
function resolveRelatedRecord(source, orderItemId) {
if (Array.isArray(source)) {
return source.find(item => sameId(item && item.orderItemId, orderItemId)) || null
}
if (source && typeof source === 'object') {
if (!source.orderItemId || sameId(source.orderItemId, orderItemId)) {
return source
}
}
return null
}
function buildReviewSummary(review) {
if (!review || !isSubmittedReview(review)) {
return null
}
const ratingText = formatRating(review.rating)
return {
...review,
ratingText,
contentText: trimText(review.content),
displayText: ratingText ? `已评价:${ratingText} 分` : (review.statusText || '已评价')
}
}
function buildArtistChangeSummary(request) {
if (!request) {
return null
}
const originalName = request.originalArtistName || '原美甲师'
const requestedName = request.requestedArtistName || '新美甲师'
return {
...request,
displayText: `${originalName} → ${requestedName}`,
reasonText: trimText(request.reason)
}
}
function indexByOrderItemId(list) {
return safeList(list).reduce((result, item) => {
if (item && item.orderItemId) {
result[toId(item.orderItemId)] = item
}
return result
}, {})
}
async function safeCall(factory, fallbackValue) {
try {
const result = await factory()
return result === undefined || result === null ? fallbackValue : result
} catch (error) {
return fallbackValue
}
}
async function loadAssistData(orders) {
const pendingChangesPromise = safeCall(() => orderApi.listMyPendingArtistChangeRequests(), [])
const orderReviewListsPromise = Promise.all(orders.map(order => (
safeCall(() => orderApi.listOrderReviews(order.id), [])
)))
const [pendingChanges, orderReviewLists] = await Promise.all([
pendingChangesPromise,
orderReviewListsPromise
])
const submittedReviews = []
safeList(orderReviewLists).forEach(list => {
safeList(list).forEach(review => {
if (isSubmittedReview(review)) {
submittedReviews.push(review)
}
})
})
return {
pendingChangeByItemId: indexByOrderItemId(pendingChanges),
submittedReviewByItemId: indexByOrderItemId(submittedReviews)
}
}
function hasProductionFlag(userInfo) {
const sources = [
userInfo && userInfo.participateProduction,
userInfo && userInfo.participateProductionFlag,
userInfo && userInfo.artistParticipateProduction,
userInfo && userInfo.nailArtistInfo && userInfo.nailArtistInfo.participateProduction,
userInfo && userInfo.artistInfo && userInfo.artistInfo.participateProduction
]
return sources.some(value => value === true || Number(value) === 1)
}
function canRequestArtistChangeForItem(userInfo, order, item, pendingChange) {
if (!userInfo || !order || !item || pendingChange || Number(order.status) !== 1) {
return false
}
if (permission.isNailArtist(userInfo)) {
return !item.artistId || sameId(item.artistId, userInfo.id)
}
if (sameId(item.artistId, userInfo.id)) {
return true
}
return permission.isShopManager(userInfo) && hasProductionFlag(userInfo)
}
function formatOrderItem(order, item, userInfo, assistData) {
const itemId = toId(item.id)
const inlineReviewSummary = resolveRelatedRecord(item.reviewSummary || order.reviewSummary, item.id)
const inlinePendingChange = resolveRelatedRecord(item.pendingArtistChangeRequest || order.pendingArtistChangeRequest, item.id)
const reviewSummary = buildReviewSummary(inlineReviewSummary || assistData.submittedReviewByItemId[itemId])
const pendingArtistChangeRequest = buildArtistChangeSummary(inlinePendingChange || assistData.pendingChangeByItemId[itemId])
return {
...item,
displayPrice: format.formatPrice(item.price),
displayAppointmentTime: format.formatDateTime(item.appointmentTime),
reviewSummary,
reviewStatusText: reviewSummary ? reviewSummary.displayText : '待评价',
pendingArtistChangeRequest,
canRequestArtistChange: canRequestArtistChangeForItem(userInfo, order, item, pendingArtistChangeRequest)
}
}
function formatOrder(order, userInfo, assistData) {
const items = safeList(order.items).map(item => formatOrderItem(order, item, userInfo, assistData))
const orderReviewSummary = buildReviewSummary(order.reviewSummary)
return {
...order,
displayStatusText: format.getOrderStatusText(order),
displayCreateTime: format.formatDateTime(order.createTime),
displayPayAmount: format.formatPrice(order.payAmount || order.actualAmount),
items,
reviewSummary: orderReviewSummary,
reviewStatusText: orderReviewSummary ? orderReviewSummary.displayText : ''
}
}
function selectArtist(artists) {
return new Promise(resolve => {
wx.showActionSheet({
itemList: artists.map(item => item.artistName || `美甲师 ${item.artistId}`),
success: result => resolve(artists[result.tapIndex] || null),
fail: () => resolve(null)
})
})
}
function promptChangeReason() {
return new Promise(resolve => {
wx.showModal({
title: '改派原因',
content: '可填写改派原因,留空也可以提交。',
editable: true,
placeholderText: '例如档期冲突、客户沟通调整',
confirmText: '提交',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(trimText(result.content))
},
fail: () => resolve(null)
})
})
}
Page({
data: {
keyword: '',
@@ -29,8 +235,9 @@ Page({
return
}
const userInfo = getApp().globalData.userInfo
this.setData({
userInfo: getApp().globalData.userInfo
userInfo
})
if (!this.data.initialized || consumeDirty('admin-orders')) {
@@ -73,16 +280,15 @@ Page({
status: this.data.status === '' ? undefined : this.data.status
})
const rawList = safeList(result && result.list)
const assistData = await loadAssistData(rawList)
if (requestId !== this._loadRequestId) {
return
}
this.setData({
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
...item,
displayStatusText: format.getOrderStatusText(item),
displayCreateTime: format.formatDateTime(item.createTime)
})),
list: rawList.map(item => formatOrder(item, this.data.userInfo, assistData)),
total: Number(result && result.total) || 0,
initialized: true
})
@@ -119,6 +325,54 @@ Page({
}).catch(() => undefined)
},
async handleRequestArtistChange(event) {
const orderId = event.currentTarget.dataset.orderId
const orderItemId = event.currentTarget.dataset.orderItemId
if (!orderId || !orderItemId) {
return
}
try {
const options = await orderApi.getArtistChangeOptions(orderId, orderItemId)
const artists = safeList(options && options.artists)
if (!artists.length) {
wx.showToast({
title: '暂无可改派美甲师',
icon: 'none'
})
return
}
const targetArtist = await selectArtist(artists)
if (!targetArtist) {
return
}
const reason = await promptChangeReason()
if (reason === null) {
return
}
await orderApi.requestArtistChange({
orderId,
orderItemId,
requestedArtistId: targetArtist.artistId,
reason
})
markDirty('admin-workbench')
wx.showToast({
title: '改派申请已提交',
icon: 'none'
})
this.loadOrders()
} catch (error) {
wx.showToast({
title: error.message || '改派申请失败',
icon: 'none'
})
}
},
async handleProcessOrder(event) {
const order = event.currentTarget.dataset.order
if (!order) {
+22 -1
View File
@@ -33,7 +33,7 @@
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">订单金额</text>
<text class="meta-value">¥{{item.payAmount}}</text>
<text class="meta-value">¥{{item.displayPayAmount}}</text>
</view>
<view class="meta-item">
<text class="meta-label">所属门店</text>
@@ -48,6 +48,27 @@
<text class="meta-value">{{item.displayCreateTime}}</text>
</view>
</view>
<view wx:if="{{item.items.length}}" class="order-items">
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="order-item-row">
<view class="order-item-main">
<text class="order-item-title">{{orderItem.productTitle || '订单项目'}}</text>
<text class="order-item-line">美甲师:{{orderItem.artistName || '--'}}</text>
<text wx:if="{{orderItem.displayAppointmentTime}}" class="order-item-line">预约时间:{{orderItem.displayAppointmentTime}}</text>
<text class="order-item-review">{{orderItem.reviewStatusText}}</text>
<text wx:if="{{orderItem.reviewSummary && orderItem.reviewSummary.contentText}}" class="order-item-line">评价内容:{{orderItem.reviewSummary.contentText}}</text>
<view wx:if="{{orderItem.pendingArtistChangeRequest}}" class="change-note">
<text class="change-note-title">改派申请待处理</text>
<text class="change-note-desc">{{orderItem.pendingArtistChangeRequest.displayText}}</text>
<text wx:if="{{orderItem.pendingArtistChangeRequest.reasonText}}" class="change-note-desc">原因:{{orderItem.pendingArtistChangeRequest.reasonText}}</text>
</view>
</view>
<view wx:if="{{orderItem.canRequestArtistChange}}" class="mini-btn soft" data-order-id="{{item.id}}" data-order-item-id="{{orderItem.id}}" bindtap="handleRequestArtistChange">申请改派</view>
</view>
</view>
<view wx:elif="{{item.reviewStatusText}}" class="order-review-line">{{item.reviewStatusText}}</view>
<view class="list-actions">
<view class="mini-btn" data-order="{{item}}" bindtap="handleOpenOrder">查看详情</view>
<view wx:if="{{item.status !== 2}}" class="mini-btn primary" data-order="{{item}}" bindtap="handleProcessOrder">处理订单</view>
@@ -1,3 +1,82 @@
.page-shell {
background: transparent;
}
.order-items {
margin-top: 22rpx;
border-top: 1rpx solid rgba(246, 239, 231, 0.12);
}
.order-item-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18rpx;
padding: 18rpx 0;
border-bottom: 1rpx solid rgba(246, 239, 231, 0.1);
}
.order-item-row:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.order-item-main {
flex: 1;
min-width: 0;
}
.order-item-title,
.order-item-line,
.order-item-review,
.order-review-line,
.change-note-title,
.change-note-desc {
display: block;
}
.order-item-title {
color: #f6efe7;
font-size: 26rpx;
font-weight: 700;
line-height: 1.5;
}
.order-item-line,
.order-review-line,
.change-note-desc {
margin-top: 8rpx;
color: rgba(246, 239, 231, 0.68);
font-size: 23rpx;
line-height: 1.55;
}
.order-item-review {
margin-top: 10rpx;
color: #f0c987;
font-size: 23rpx;
font-weight: 700;
line-height: 1.5;
}
.change-note {
margin-top: 14rpx;
padding: 16rpx;
border-radius: 14rpx;
background: rgba(240, 201, 135, 0.1);
border: 1rpx solid rgba(240, 201, 135, 0.3);
}
.change-note-title {
color: #f0c987;
font-size: 23rpx;
font-weight: 700;
line-height: 1.5;
}
.mini-btn.soft {
color: #081518;
background: #f0c987;
border-color: #f0c987;
white-space: nowrap;
}
@@ -111,31 +111,5 @@ Page({
icon: 'none'
})
})
},
handleDelete(event) {
const shop = event.currentTarget.dataset.shop
wx.showModal({
title: '删除店铺',
content: `确认删除店铺“${shop.shopName}”吗?该操作会联动清理店铺下资源。`,
success: async result => {
if (!result.confirm) {
return
}
try {
await shopApi.deleteShop(shop.id)
wx.showToast({
title: '店铺已删除',
icon: 'none'
})
this.loadShops()
} catch (error) {
wx.showToast({
title: error.message || '店铺删除失败',
icon: 'none'
})
}
}
})
}
})
@@ -32,7 +32,6 @@
<view class="list-actions">
<view class="mini-btn primary" data-shop="{{item}}" bindtap="handleEdit">编辑</view>
<view class="mini-btn" data-shop="{{item}}" bindtap="handleStatus">{{item.status === 0 ? '启用' : '停用'}}</view>
<view class="mini-btn danger" data-shop="{{item}}" bindtap="handleDelete">删除</view>
</view>
</view>
</block>