mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2026-08-06 02:47:25 +08:00
feat: 更新电子卡券卡密详情页及相关逻辑
- 修改卡密详情页以支持多种卡密展示,优化卡密信息的结构和样式 - 增加卡密履约状态管理,支持卡密发放状态的显示 - 更新 utils/goodsType.js,增加卡密履约状态的处理逻辑 - 优化数据加载逻辑,确保卡密信息的准确性和完整性
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @Author Mike
|
||||
* @Date 2026-07-31
|
||||
* @Date 2026-08-03
|
||||
*
|
||||
* 卡密商品(电子卡券 E_COUPON)类型与订单工具。
|
||||
*
|
||||
@@ -71,18 +71,105 @@ export function hasECouponInCheckout(orderMessage) {
|
||||
)
|
||||
}
|
||||
|
||||
/** 将 orderItems[].cardKeys 展平为列表,供卡密二级页展示 */
|
||||
export function flattenOrderCardKeys(orderItems) {
|
||||
const rows = []
|
||||
/** 卡密履约状态(与后端 CardKeyFulfillStatusEnum 一致) */
|
||||
export const CARD_KEY_FULFILL_STATUS = {
|
||||
PENDING: 'PENDING',
|
||||
DELIVERED: 'DELIVERED',
|
||||
FAILED: 'FAILED',
|
||||
NOT_APPLICABLE: 'NOT_APPLICABLE',
|
||||
}
|
||||
|
||||
export const CARD_KEY_FULFILL_STATUS_TEXT = {
|
||||
PENDING: '待发放',
|
||||
DELIVERED: '已发放',
|
||||
FAILED: '发放失败',
|
||||
NOT_APPLICABLE: '不适用',
|
||||
}
|
||||
|
||||
export function resolveCardKeyFulfillMessage(line) {
|
||||
if (line && line.message) return line.message
|
||||
return CARD_KEY_FULFILL_STATUS_TEXT[line?.status] || line?.status || '—'
|
||||
}
|
||||
|
||||
export function isCardKeyFulfillApplicable(item) {
|
||||
if (!item) return false
|
||||
const status = item.cardKeyFulfillStatus
|
||||
if (status) return status !== CARD_KEY_FULFILL_STATUS.NOT_APPLICABLE
|
||||
if (item.cardKeyDelivered != null || (item.cardKeys && item.cardKeys.length)) {
|
||||
return true
|
||||
}
|
||||
return item.goodsType === E_COUPON_GOODS_TYPE
|
||||
}
|
||||
|
||||
function normalizeCardKeyFulfillLine(source) {
|
||||
const status =
|
||||
source.cardKeyFulfillStatus ||
|
||||
(source.cardKeyDelivered
|
||||
? CARD_KEY_FULFILL_STATUS.DELIVERED
|
||||
: CARD_KEY_FULFILL_STATUS.PENDING)
|
||||
const cardKeys =
|
||||
status === CARD_KEY_FULFILL_STATUS.DELIVERED ? source.cardKeys || [] : []
|
||||
return {
|
||||
key: source.sn || source.orderSn || source.id || source.skuId,
|
||||
goodsName: source.goodsName,
|
||||
status,
|
||||
message: source.cardKeyFulfillMessage,
|
||||
cardKeys,
|
||||
isGift: !!source.isGift,
|
||||
}
|
||||
}
|
||||
|
||||
/** 汇总 E_COUPON 主单行 + 满赠子单摘要的履约行 */
|
||||
export function collectCardKeyFulfillLines(orderItems = [], giftSummaries = []) {
|
||||
const lines = []
|
||||
;(orderItems || []).forEach((item) => {
|
||||
;(item.cardKeys || []).forEach((ck) => {
|
||||
rows.push({ ...ck })
|
||||
if (!isCardKeyFulfillApplicable(item)) return
|
||||
lines.push(normalizeCardKeyFulfillLine(item))
|
||||
})
|
||||
;(giftSummaries || []).forEach((gift) => {
|
||||
lines.push(normalizeCardKeyFulfillLine({ ...gift, isGift: true }))
|
||||
})
|
||||
return lines
|
||||
}
|
||||
|
||||
function flattenCardKeyFulfillLines(lines, withGoodsName = false) {
|
||||
const rows = []
|
||||
;(lines || []).forEach((line) => {
|
||||
if (line.status !== CARD_KEY_FULFILL_STATUS.DELIVERED) return
|
||||
;(line.cardKeys || []).forEach((ck) => {
|
||||
rows.push(withGoodsName ? { ...ck, goodsName: line.goodsName } : { ...ck })
|
||||
})
|
||||
})
|
||||
return rows
|
||||
}
|
||||
|
||||
/** 是否已发卡(API-B-01:cardKeyDelivered 或 orderItems 内标记) */
|
||||
export function isCardKeyDelivered(orderItems) {
|
||||
return (orderItems || []).some((item) => item.cardKeyDelivered)
|
||||
/** 订单是否含已交付卡密(含满赠 E_COUPON 子单) */
|
||||
export function orderHasCardKeyContent(orderItems, giftSummaries) {
|
||||
const lines = collectCardKeyFulfillLines(orderItems, giftSummaries)
|
||||
return flattenCardKeyFulfillLines(lines).length > 0
|
||||
}
|
||||
|
||||
/** 将 orderItems[].cardKeys 展平为明文列表(DELIVERED 且含 cardSecret) */
|
||||
export function flattenOrderCardKeys(
|
||||
orderItems,
|
||||
withGoodsName = false,
|
||||
giftSummaries
|
||||
) {
|
||||
const lines = collectCardKeyFulfillLines(orderItems, giftSummaries)
|
||||
if (lines.some((line) => line.status)) {
|
||||
return flattenCardKeyFulfillLines(lines, withGoodsName)
|
||||
}
|
||||
const rows = []
|
||||
;(orderItems || []).forEach((item) => {
|
||||
if (!item.cardKeyDelivered || !item.cardKeys || !item.cardKeys.length) return
|
||||
item.cardKeys.forEach((ck) => {
|
||||
rows.push(withGoodsName ? { ...ck, goodsName: item.goodsName } : { ...ck })
|
||||
})
|
||||
})
|
||||
return rows
|
||||
}
|
||||
|
||||
/** 是否已发卡(兼容旧调用;含满赠子单) */
|
||||
export function isCardKeyDelivered(orderItems, giftSummaries) {
|
||||
return orderHasCardKeyContent(orderItems, giftSummaries)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user