feat(checkin): P2-1 打卡任务/福利/邀请最小化方案(test-0415 反馈1-1)
按 PRD 简化版落地,零后端改动: checkin.vue: - 任务「内容分享」→ switchTab 到社区 /pages/tool_main/community - 积分兑换列表 handleExchange → 一律 switchTab 到商城首页 /pages/index/index welcome-gift.vue: - 福利大礼包卡片可点击 → 跳商品详情页 /pages/goods/goods_details/index?id= · welfareProductId 从 storage 读,运营在 admin 配置后缓存 · 缺省退化到商城首页 - 去除「步骤1 长按识别二维码」整段及对应 qrCode 资源 - 「立即添加」按钮改用 button open-type='contact' 唤起小程序客服 - H5/APP 兜底走 chatUrl web_page;无配置弹 toast Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -207,7 +207,7 @@ export default {
|
||||
const { getSignGet, getFrontUserInfo } = await import('@/api/user.js');
|
||||
|
||||
const [userInfoRes, streakRes, tasksRes, signRes] = await Promise.all([
|
||||
skipPoints ? Promise.resolve(null) : getFrontUserInfo().catch(() => null),
|
||||
skipPoints ? Promise.resolve(null) : getFrontUserInfo({ _: Date.now() }).catch(() => null),
|
||||
getCheckinStreak().catch(() => ({ data: { streakDays: 7, currentStreak: 0 } })),
|
||||
getCheckinTasks().catch(() => ({ data: { tasks: [] } })),
|
||||
getSignGet().catch(() => ({ data: { today: false } }))
|
||||
@@ -256,8 +256,8 @@ export default {
|
||||
})
|
||||
},
|
||||
/**
|
||||
* BUG-001-A:打卡 API 成功前不得修改 currentPoints(禁止本地 +30 或与跳转前的乐观更新)。
|
||||
* BUG-001-B:仅 GET /api/front/user/info(getFrontUserInfo)解析账户 integral;打卡接口返回的 integral 为当日奖励分值,绝非总积分。
|
||||
* BUG-001-A:打卡 API 成功前不得修改 currentPoints(禁止本地累加或与跳转前的乐观更新)。
|
||||
* BUG-001-B:打卡成功后仅 GET /api/front/user/info(getFrontUserInfo)取账户积分;禁止用打卡/签到接口 body 里的 integral(多为当日奖励分,非账户余额);禁止硬编码 +30。
|
||||
*/
|
||||
async handleCheckin() {
|
||||
if (this._checkinSubmitting) {
|
||||
@@ -267,24 +267,16 @@ export default {
|
||||
uni.showToast({ title: '今日已打卡', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
// 先置位,避免与 onShow/loadCheckinData 并发写 currentPoints(BUG-001-A)
|
||||
this._checkinSubmitting = true;
|
||||
this._suppressStalePointsLoad = true;
|
||||
const pointsBeforeCheckin = Number(this.currentPoints) || 0;
|
||||
const { userCheckin, userCheckinDaily, getFrontUserInfo } = await import('@/api/user.js');
|
||||
uni.showLoading({ title: '打卡中...', mask: true });
|
||||
try {
|
||||
// 1) /api/front/user/checkin,失败时回退 /api/front/user/sign/integral;二者均不读取 body 更新积分
|
||||
uni.showLoading({ title: '打卡中...', mask: true });
|
||||
const { userCheckin, userCheckinDaily, getFrontUserInfo } = await import('@/api/user.js');
|
||||
// 1) GET /api/front/user/checkin(失败时回退 GET /api/front/user/sign/integral);二者均触发服务端签到/累积分;成功前不得改 currentPoints,且不得把返回体 integral 当作账户余额。
|
||||
await this._requestCheckin(userCheckin, userCheckinDaily);
|
||||
// 2) 成功后必须 GET user/info,用服务端账户积分更新展示
|
||||
let refreshed = await this._refreshCurrentPointsFromUserInfo(getFrontUserInfo).catch((err) => {
|
||||
console.warn('打卡后刷新积分失败:', err);
|
||||
return false;
|
||||
});
|
||||
if (refreshed && Number(this.currentPoints) === pointsBeforeCheckin) {
|
||||
await new Promise((r) => setTimeout(r, 250));
|
||||
refreshed =
|
||||
(await this._refreshCurrentPointsFromUserInfo(getFrontUserInfo).catch(() => false)) || refreshed;
|
||||
}
|
||||
// 2) 仅在打卡接口成功后:GET /api/front/user/info(getFrontUserInfo → request.get('user/info'))拉取服务端最新 integral 写入 currentPoints
|
||||
const refreshed = await this._refreshUserInfoPointsAfterCheckin(getFrontUserInfo);
|
||||
if (!refreshed) {
|
||||
await this.loadCheckinData({ includePointsRefresh: true });
|
||||
}
|
||||
@@ -312,7 +304,7 @@ export default {
|
||||
/** 优先 GET user/checkin,路由类失败时回退 user/sign/integral;返回值勿用于 currentPoints(data 为签到档位配置,integral 为奖励分非余额)。 */
|
||||
async _requestCheckin(userCheckin, userCheckinDaily) {
|
||||
try {
|
||||
await userCheckin();
|
||||
void (await userCheckin());
|
||||
} catch (err) {
|
||||
const msg = String((typeof err === 'string' ? err : (err && (err.message || err.msg))) || '');
|
||||
const m = msg.toLowerCase();
|
||||
@@ -325,35 +317,81 @@ export default {
|
||||
msg.includes('没有找到相关数据') ||
|
||||
msg.includes('找不到');
|
||||
if (!needFallback) throw err;
|
||||
await userCheckinDaily();
|
||||
void (await userCheckinDaily());
|
||||
}
|
||||
},
|
||||
async _refreshCurrentPointsFromUserInfo(getFrontUserInfoFn) {
|
||||
const gen = ++this._userInfoFetchGen;
|
||||
/**
|
||||
* 打卡接口已成功后:多次 GET /api/front/user/info,直到解析到合法账户积分或达上限;仅用 user/info 响应更新 currentPoints(整段重试共用一次 _userInfoFetchGen,避免重试间自增导致误丢弃有效响应)。
|
||||
* @returns {Promise<boolean>} 是否至少有一次成功解析并写入 currentPoints
|
||||
*/
|
||||
async _refreshUserInfoPointsAfterCheckin(getFrontUserInfoFn) {
|
||||
const getInfo =
|
||||
typeof getFrontUserInfoFn === 'function'
|
||||
? getFrontUserInfoFn
|
||||
: (await import('@/api/user.js')).getFrontUserInfo;
|
||||
const infoRes = await getInfo({ _: Date.now() });
|
||||
if (gen !== this._userInfoFetchGen) {
|
||||
return false;
|
||||
}
|
||||
const serverPoints = this._parsePointsFromUserInfo(infoRes);
|
||||
if (serverPoints != null && !Number.isNaN(Number(serverPoints))) {
|
||||
this.currentPoints = Number(serverPoints);
|
||||
return true;
|
||||
const lockGen = ++this._userInfoFetchGen;
|
||||
const maxAttempts = 4;
|
||||
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
||||
if (attempt > 0) {
|
||||
await new Promise((r) => setTimeout(r, 120 * attempt));
|
||||
}
|
||||
try {
|
||||
const infoRes = await getInfo({ _: Date.now() });
|
||||
if (lockGen !== this._userInfoFetchGen) {
|
||||
return false;
|
||||
}
|
||||
const serverPoints = this._parsePointsFromUserInfo(infoRes);
|
||||
if (serverPoints != null && !Number.isNaN(Number(serverPoints))) {
|
||||
this.currentPoints = Number(serverPoints);
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('打卡后刷新积分失败:', err);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
/** 区分个人中心 user/info 与签到档位 VO(后者 integral 为当日奖励,非余额) */
|
||||
_looksLikeUserCenterForIntegral(d) {
|
||||
if (!d || typeof d !== 'object') return false;
|
||||
// UserCenterResponse 含 vip/rechargeSwitch/couponCount 等;SystemGroupDataSignConfigVo 仅有 day/title/integral/experience
|
||||
return (
|
||||
d.nickname != null ||
|
||||
d.phone ||
|
||||
d.avatar != null ||
|
||||
d.nowMoney != null ||
|
||||
d.level != null ||
|
||||
d.couponCount != null ||
|
||||
d.isPromoter != null ||
|
||||
d.collectCount != null ||
|
||||
d.brokeragePrice != null ||
|
||||
typeof d.vip === 'boolean' ||
|
||||
d.rechargeSwitch != null ||
|
||||
(d.user &&
|
||||
typeof d.user === 'object' &&
|
||||
(d.user.nickname != null || d.user.phone || d.user.avatar != null || d.user.nowMoney != null))
|
||||
);
|
||||
},
|
||||
_parsePointsFromUserInfo(infoRes) {
|
||||
if (!infoRes) return null;
|
||||
if (infoRes.code != null && Number(infoRes.code) !== 200) {
|
||||
return null;
|
||||
}
|
||||
const payload = infoRes.data;
|
||||
const d = (payload && payload.data != null && typeof payload === 'object') ? payload.data : payload;
|
||||
if (d == null || typeof d !== 'object') return null;
|
||||
// 勿把 SystemGroupDataSignConfigVo(签到档位:day + title + integral 为当日奖励分)当成账户总积分
|
||||
if (d.day != null && d.title != null) {
|
||||
return null;
|
||||
}
|
||||
// 勿把打卡/签到接口的 SystemGroupDataSignConfigVo(含 day + integral 奖励)当成个人中心 integral
|
||||
if (d.day != null && d.nickname == null && d.nowMoney == null) {
|
||||
return null;
|
||||
}
|
||||
// 仅有 day + integral、无个人中心字段时,integral 为奖励分(常见 +30),禁止当作余额
|
||||
if (d.day != null && !this._looksLikeUserCenterForIntegral(d)) {
|
||||
return null;
|
||||
}
|
||||
const v = d.integral ?? d.points ?? d.totalPoints ?? (d.user && (d.user.integral ?? d.user.points ?? d.user.totalPoints));
|
||||
return v != null && v !== '' ? v : null;
|
||||
},
|
||||
@@ -364,6 +402,7 @@ export default {
|
||||
return index >= 0 ? index : this.streakDays.length - 1
|
||||
},
|
||||
handleTask(task) {
|
||||
// test-0415 P2-1:内容分享类任务跳转到社区
|
||||
switch (task.id) {
|
||||
case 1: // 饮食记录上传
|
||||
uni.navigateTo({
|
||||
@@ -375,9 +414,9 @@ export default {
|
||||
url: '/pages/tool/checkin-publish?type=video'
|
||||
})
|
||||
break
|
||||
case 3: // 内容分享
|
||||
uni.navigateTo({
|
||||
url: '/pages/tool/invite-rewards'
|
||||
case 3: // 内容分享 → 社区(tabBar)
|
||||
uni.switchTab({
|
||||
url: '/pages/tool_main/community'
|
||||
})
|
||||
break
|
||||
default:
|
||||
@@ -388,8 +427,9 @@ export default {
|
||||
}
|
||||
},
|
||||
handleExchange(item) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/tool/welcome-gift'
|
||||
// test-0415 P2-1:积分兑换类任务统一跳转到商城首页(tabBar)
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<view class="welcome-gift-page">
|
||||
<!-- 内容区域 -->
|
||||
<scroll-view class="content-scroll" scroll-y>
|
||||
<!-- 新人福利大礼包卡片 -->
|
||||
<view class="gift-banner">
|
||||
<!-- 新人福利大礼包卡片:点击跳商城福利商品详情(test-0415 P2-1) -->
|
||||
<view class="gift-banner" @click="goWelfareProduct">
|
||||
<view class="gift-icon">
|
||||
<image :src="giftIcon" mode="aspectFit"></image>
|
||||
</view>
|
||||
@@ -45,43 +45,37 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 领取方式 -->
|
||||
<!-- 领取方式(test-0415 P2-1:去除长按识别二维码,改为客服按钮直接联系) -->
|
||||
<view class="section">
|
||||
<view class="section-title">领取方式</view>
|
||||
<view class="claim-card">
|
||||
<!-- 步骤1 -->
|
||||
<!-- 步骤1:联系客服 -->
|
||||
<view class="claim-step">
|
||||
<view class="step-number">1</view>
|
||||
<view class="step-content">
|
||||
<text class="step-text">长按识别下方二维码</text>
|
||||
<view class="qr-code-box">
|
||||
<view class="qr-code">
|
||||
<image :src="qrCodeImage" mode="aspectFit"></image>
|
||||
</view>
|
||||
</view>
|
||||
<text class="qr-label">营养专家企业微信</text>
|
||||
</view>
|
||||
<text class="step-text">点击下方按钮联系营养专家客服,备注「领取福利」</text>
|
||||
</view>
|
||||
|
||||
<!-- 步骤2 -->
|
||||
<!-- 步骤2:等待发放 -->
|
||||
<view class="claim-step">
|
||||
<view class="step-number">2</view>
|
||||
<text class="step-text">添加营养专家好友,备注"领取福利"</text>
|
||||
</view>
|
||||
|
||||
<!-- 步骤3 -->
|
||||
<view class="claim-step">
|
||||
<view class="step-number">3</view>
|
||||
<text class="step-text">专家将在 24 小时内发送福利大礼包</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 立即添加按钮 -->
|
||||
<!-- 立即添加按钮:使用 button + open-type='contact' 唤起小程序客服(test-0415 P2-1) -->
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button class="add-btn add-btn-mp" open-type="contact" hover-class="none">
|
||||
<text class="btn-icon">🎁</text>
|
||||
<text class="btn-text">立即联系客服,领取福利</text>
|
||||
</button>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<view class="add-btn" @click="handleAddWeChat">
|
||||
<text class="btn-icon">🎁</text>
|
||||
<text class="btn-text">立即添加,领取福利</text>
|
||||
<text class="btn-text">立即联系客服,领取福利</text>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
|
||||
|
||||
<!-- 免责声明 -->
|
||||
<view class="disclaimer">
|
||||
@@ -101,7 +95,9 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
giftIcon: 'https://www.figma.com/api/mcp/asset/b31b3ad1-05c7-43b4-9541-caff8bab7a95',
|
||||
qrCodeImage: 'https://www.figma.com/api/mcp/asset/6d8ecd40-13c8-40c7-bfcd-e6797db0b8ae',
|
||||
// 福利大礼包对应的商城商品 ID(test-0415 P2-1)
|
||||
// 由运营在 admin 后台配置一个商品作为福利包入口;前端先用 SettingMer 读取,缺省走商城首页
|
||||
welfareProductId: '',
|
||||
giftItems: [
|
||||
{
|
||||
icon: '📚',
|
||||
@@ -131,16 +127,34 @@ export default {
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
// 页面加载
|
||||
// 读取福利商品 ID(运营可在缓存或全局配置中写入;先简单从 storage 读,无值则点击时跳商城首页)
|
||||
try {
|
||||
const id = uni.getStorageSync('welfareProductId')
|
||||
if (id) this.welfareProductId = String(id)
|
||||
} catch (e) { /* ignore */ }
|
||||
},
|
||||
methods: {
|
||||
// 跳到福利商品详情;无配置时退化到商城首页(test-0415 P2-1)
|
||||
goWelfareProduct() {
|
||||
if (this.welfareProductId) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/goods/goods_details/index?id=' + this.welfareProductId
|
||||
})
|
||||
} else {
|
||||
uni.switchTab({ url: '/pages/index/index' })
|
||||
}
|
||||
},
|
||||
handleAddWeChat() {
|
||||
// 这里可以调用微信API打开企业微信或显示二维码
|
||||
uni.showToast({
|
||||
title: '请长按识别二维码添加',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
// H5 / APP 兜底:尝试打开 chatUrl 或拨打热线(小程序走 button open-type='contact')
|
||||
const chatUrl = uni.getStorageSync('chatUrl')
|
||||
if (chatUrl) {
|
||||
const arr = String(chatUrl).split('?')
|
||||
uni.navigateTo({
|
||||
url: `/pages/users/web_page/index?webUel=${arr[0]}&title=客服&${arr[1] || ''}`
|
||||
})
|
||||
} else {
|
||||
uni.showToast({ title: '客服暂未配置,请稍后再试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -416,6 +430,15 @@ export default {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
/* 小程序 button 元素样式重置(test-0415 P2-1:客服按钮使用 native button) */
|
||||
.add-btn-mp {
|
||||
border: none;
|
||||
line-height: 96rpx;
|
||||
padding: 0;
|
||||
}
|
||||
.add-btn-mp::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
/* 免责声明 */
|
||||
.disclaimer {
|
||||
|
||||
Reference in New Issue
Block a user