diff --git a/miniprogram/pages/profile/profile.ts b/miniprogram/pages/profile/profile.ts index 6703be0..4b65bb8 100644 --- a/miniprogram/pages/profile/profile.ts +++ b/miniprogram/pages/profile/profile.ts @@ -1,7 +1,7 @@ import { request, uploadFile, redirectToLogin } from '../../utils/request' import * as auth from '../../utils/auth' import { UserInfo, QuotaItem } from '../../types/models' -import { QuotaType, STORAGE_KEYS } from '../../utils/config' +import { QuotaType, QUOTA_NAMES, VIP_TYPE_NAMES, STORAGE_KEYS } from '../../utils/config' import { formatDate } from '../../utils/format' import { setTabBarSelected, setTabBarUnread, setTabBarHidden } from '../../utils/tabbar' import { navScroll } from '../../utils/nav' @@ -30,6 +30,8 @@ function getZodiac(birthDay: number): string { Page({ data: { userInfo: {} as UserInfo, + // 会员标签(vip_type 2/3/4 → 月度/年度/体验会员;非会员为空不展示) + vipLabel: '', uploadRemain: 0, zodiac: '', unread: 0, @@ -116,7 +118,11 @@ Page({ const cached = wx.getStorageSync(STORAGE_KEYS.USER_INFO) if (cached && Object.keys(cached).length) { logger.debug(LOG, '用户信息未就绪,使用本地缓存预填编辑表单') - this.setData({ userInfo: cached, zodiac: getZodiac(cached.birth_day) }) + this.setData({ + userInfo: cached, + zodiac: getZodiac(cached.birth_day), + vipLabel: VIP_TYPE_NAMES[cached.vip_type] || '', + }) } } this.onEdit() @@ -130,9 +136,14 @@ Page({ fetchUser() { request({ url: '/user/info', showError: false }) .then((user) => { - logger.debug(LOG, '用户信息加载成功') + logger.debug(LOG, '用户信息加载成功, vipType=', user.vip_type) wx.setStorageSync(STORAGE_KEYS.USER_INFO, user) - this.setData({ userInfo: user, zodiac: getZodiac(user.birth_day) }) + // 会员标签按 vip_type 判定:2 月度 / 3 年度 / 4 体验(新用户默认赠送),非会员不展示 + this.setData({ + userInfo: user, + zodiac: getZodiac(user.birth_day), + vipLabel: VIP_TYPE_NAMES[user.vip_type] || '', + }) }) .catch((e: any) => logger.warn(LOG, '用户信息加载失败, code=', e && e.code)) }, @@ -140,9 +151,22 @@ Page({ fetchQuota() { request<{ quotas: QuotaItem[] }>({ url: '/quota/info', showError: false, silentAuth: true }) .then((res) => { - const upload = res.quotas.find((q) => q.quota_type === QuotaType.UPLOAD) + const quotas = res && Array.isArray(res.quotas) ? res.quotas : [] + const upload = quotas.find((q) => q.quota_type === QuotaType.UPLOAD) if (upload) this.setData({ uploadRemain: upload.remain }) - logger.debug(LOG, '额度加载成功, 上传剩余=', upload ? upload.remain : 0) + // 四栏额度条按固定顺序取数,缺失类型补 0,保证栏位不塌陷 + const order = [QuotaType.UPLOAD, QuotaType.AI, QuotaType.OUTFIT_SHARE, QuotaType.CLOSET_SHARE] + const quotaStats = order.map((type) => { + const hit = quotas.find((q) => q.quota_type === type) + return { + key: type, + label: QUOTA_NAMES[type] || '额度', + remain: hit ? hit.remain : 0, + total: hit ? hit.total : 0, + } + }) + this.setData({ quotaStats }) + logger.debug(LOG, '额度加载成功, 上传剩余=', upload ? upload.remain : 0, '栏位=', quotaStats.length) }) .catch((e: any) => logger.warn(LOG, '额度加载失败(静默降级), code=', e && e.code)) }, diff --git a/miniprogram/pages/profile/profile.wxml b/miniprogram/pages/profile/profile.wxml index 27a0c05..b41b091 100644 --- a/miniprogram/pages/profile/profile.wxml +++ b/miniprogram/pages/profile/profile.wxml @@ -18,7 +18,7 @@ 男 女 - 月度会员 + {{vipLabel}} {{zodiac}} 设置生日 diff --git a/miniprogram/types/models.ts b/miniprogram/types/models.ts index 07942d8..1e25ef4 100644 --- a/miniprogram/types/models.ts +++ b/miniprogram/types/models.ts @@ -117,10 +117,12 @@ export interface QuotaFlowItem { quota_flow_uuid: string quota_type: number change_target: number - change_type: number // 1 购买 2 活动 3 上传消耗 4 删除回退 5 人工 6 退款回收 - change_num: number // 正增负减 + // 1 购买获赠 2 活动赠送 3 消耗 4 删除回退 5 人工调整 6 退款回收 7 到期失效(固定有效期凭证过期) + change_type: number + change_num: number // 正增负减(到期失效为负) new_value: number reason: string + // 购买/退款类为真实订单号;赠送/消耗/回退/到期类由后端填充流水 UUID 或凭证 ref_id(幂等用),不代表订单 order_no: string created_at: number } diff --git a/miniprogram/utils/config.ts b/miniprogram/utils/config.ts index 464eb91..10c7c3b 100644 --- a/miniprogram/utils/config.ts +++ b/miniprogram/utils/config.ts @@ -45,6 +45,21 @@ export enum QuotaType { CLOSET_SHARE = 4, // 衣柜分享 } +// 会员类型(与后端 UserInfo.vip_type 对齐) +export enum VipType { + NONE = 1, // 非会员 + MONTHLY = 2, // 月度会员 + YEARLY = 3, // 年度会员 + TRIAL = 4, // 体验会员(新用户注册赠送,固定有效期,不随续费延长) +} + +// 会员标签映射:非会员不在资料区展示标签,故意不提供 NONE 的文案 +export const VIP_TYPE_NAMES: Record = { + [VipType.MONTHLY]: '月度会员', + [VipType.YEARLY]: '年度会员', + [VipType.TRIAL]: '体验会员', +} + // 通知类型 export enum MsgType { LIKE = 1, // 点赞通知