This commit is contained in:
2026-09-13 02:28:46 +08:00
parent df5492a48a
commit 42f9530a59
27 changed files with 979 additions and 149 deletions
+29 -7
View File
@@ -3,6 +3,10 @@ import { QuotaItem, UserInfo, GoodsItem, QuotaFlowItem, PagedResult, VirtualPayR
import { QUOTA_NAMES, GoodsType, GOODS_TYPE_NAMES } from '../../utils/config'
import { fenToYuan, formatDate, formatDateTime } from '../../utils/format'
import { normalizePaged } from '../../utils/paged'
import { logger } from '../../utils/logger'
// 日志模块名
const LOG = 'mall'
const GOODS_ICONS: Record<number, string> = {
[GoodsType.MEMBER]: 'icon-crown',
@@ -54,6 +58,7 @@ Page({
},
onLoad(query: Record<string, string>) {
logger.debug(LOG, 'onLoad, query=', JSON.stringify(query))
if (query.tab === 'flow') this.setData({ view: 'flow' })
},
@@ -67,6 +72,7 @@ Page({
fetchUser() {
request<UserInfo>({ url: '/user/info', showError: false })
.then((user) => {
logger.debug(LOG, '用户信息加载成功, vipType=', user.vip_type)
const isVip = user.vip_type !== 1
this.setData({
userInfo: user,
@@ -74,7 +80,7 @@ Page({
vipExpireText: isVip && user.vip_expire ? `有效期至 ${formatDate(user.vip_expire)}` : '',
})
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, '用户信息加载失败(静默降级), code=', e && e.code))
},
fetchQuota() {
@@ -87,7 +93,7 @@ Page({
}))
this.setData({ quotas })
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, '额度加载失败(静默降级), code=', e && e.code))
},
fetchGoods() {
@@ -103,9 +109,13 @@ Page({
_priceText: fenToYuan(g.discount_price),
_originText: fenToYuan(g.price),
}))
logger.debug(LOG, '商品列表加载成功, 条数=', goods.length)
this.setData({ goods, loading: false })
})
.catch(() => this.setData({ loading: false }))
.catch((e: any) => {
logger.warn(LOG, '商品列表加载失败, code=', e && e.code)
this.setData({ loading: false })
})
},
fetchFlow() {
@@ -119,7 +129,7 @@ Page({
}))
this.setData({ flowList: list })
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, '额度流水加载失败(静默降级), code=', e && e.code))
},
onGoodsFilter(e: WechatMiniprogram.TouchEvent) {
@@ -166,13 +176,18 @@ Page({
},
})
.then((res) => {
logger.info(LOG, '下单成功, orderNo=', res.order_no)
this.setData({ orderVisible: false, submitting: false })
this.doPayment(res)
})
.catch(() => this.setData({ submitting: false }))
.catch((e: any) => {
logger.warn(LOG, '下单失败, code=', e && e.code)
this.setData({ submitting: false })
})
},
doPayment(res: VirtualPayResult) {
logger.debug(LOG, '拉起虚拟支付, orderNo=', res.order_no)
wx.requestVirtualPayment({
signData: res.sign_data,
paySig: res.pay_sig,
@@ -180,9 +195,12 @@ Page({
mode: 'short_series_goods',
success: () => {
// 拉起成功仅代表进入支付页,最终到账以后端发货推送为准,轮询订单确认
logger.info(LOG, '支付页拉起成功, orderNo=', res.order_no)
this.pollOrder(res.order_no)
},
fail: () => {},
fail: (e: any) => {
logger.error(LOG, '拉起支付失败, orderNo=', res.order_no, 'err=', e && e.errMsg)
},
})
},
@@ -196,18 +214,22 @@ Page({
const order = normalizePaged<OrderItem>(res).list.find((it) => it.order_no === orderNo)
if (order && order.order_status === 2) {
this.clearPayTimer()
logger.info(LOG, '支付成功, orderNo=', orderNo)
wx.showToast({ title: '支付成功', icon: 'success' })
this.fetchQuota()
this.fetchUser()
} else if (order && (order.order_status === 3 || order.order_status === 4 || order.order_status === 5)) {
this.clearPayTimer()
logger.warn(LOG, '订单未成功支付, orderNo=', orderNo, 'status=', order.order_status)
const msg = order.order_status === 5 ? '订单已退款' : '订单未支付成功'
wx.showToast({ title: msg, icon: 'none' })
} else if (count >= 10) {
logger.warn(LOG, '支付轮询超时, orderNo=', orderNo)
this.finishPayTimeout()
}
})
.catch(() => {
.catch((e: any) => {
logger.warn(LOG, '支付轮询请求失败, orderNo=', orderNo, 'code=', e && e.code)
if (count >= 10) this.finishPayTimeout()
})
}, 1500)