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 { getSignGet, getFrontUserInfo } = await import('@/api/user.js');
|
||||||
|
|
||||||
const [userInfoRes, streakRes, tasksRes, signRes] = await Promise.all([
|
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 } })),
|
getCheckinStreak().catch(() => ({ data: { streakDays: 7, currentStreak: 0 } })),
|
||||||
getCheckinTasks().catch(() => ({ data: { tasks: [] } })),
|
getCheckinTasks().catch(() => ({ data: { tasks: [] } })),
|
||||||
getSignGet().catch(() => ({ data: { today: false } }))
|
getSignGet().catch(() => ({ data: { today: false } }))
|
||||||
@@ -256,8 +256,8 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* BUG-001-A:打卡 API 成功前不得修改 currentPoints(禁止本地 +30 或与跳转前的乐观更新)。
|
* BUG-001-A:打卡 API 成功前不得修改 currentPoints(禁止本地累加或与跳转前的乐观更新)。
|
||||||
* BUG-001-B:仅 GET /api/front/user/info(getFrontUserInfo)解析账户 integral;打卡接口返回的 integral 为当日奖励分值,绝非总积分。
|
* BUG-001-B:打卡成功后仅 GET /api/front/user/info(getFrontUserInfo)取账户积分;禁止用打卡/签到接口 body 里的 integral(多为当日奖励分,非账户余额);禁止硬编码 +30。
|
||||||
*/
|
*/
|
||||||
async handleCheckin() {
|
async handleCheckin() {
|
||||||
if (this._checkinSubmitting) {
|
if (this._checkinSubmitting) {
|
||||||
@@ -267,24 +267,16 @@ export default {
|
|||||||
uni.showToast({ title: '今日已打卡', icon: 'none' });
|
uni.showToast({ title: '今日已打卡', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 先置位,避免与 onShow/loadCheckinData 并发写 currentPoints(BUG-001-A)
|
||||||
this._checkinSubmitting = true;
|
this._checkinSubmitting = true;
|
||||||
this._suppressStalePointsLoad = 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 {
|
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);
|
await this._requestCheckin(userCheckin, userCheckinDaily);
|
||||||
// 2) 成功后必须 GET user/info,用服务端账户积分更新展示
|
// 2) 仅在打卡接口成功后:GET /api/front/user/info(getFrontUserInfo → request.get('user/info'))拉取服务端最新 integral 写入 currentPoints
|
||||||
let refreshed = await this._refreshCurrentPointsFromUserInfo(getFrontUserInfo).catch((err) => {
|
const refreshed = await this._refreshUserInfoPointsAfterCheckin(getFrontUserInfo);
|
||||||
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;
|
|
||||||
}
|
|
||||||
if (!refreshed) {
|
if (!refreshed) {
|
||||||
await this.loadCheckinData({ includePointsRefresh: true });
|
await this.loadCheckinData({ includePointsRefresh: true });
|
||||||
}
|
}
|
||||||
@@ -312,7 +304,7 @@ export default {
|
|||||||
/** 优先 GET user/checkin,路由类失败时回退 user/sign/integral;返回值勿用于 currentPoints(data 为签到档位配置,integral 为奖励分非余额)。 */
|
/** 优先 GET user/checkin,路由类失败时回退 user/sign/integral;返回值勿用于 currentPoints(data 为签到档位配置,integral 为奖励分非余额)。 */
|
||||||
async _requestCheckin(userCheckin, userCheckinDaily) {
|
async _requestCheckin(userCheckin, userCheckinDaily) {
|
||||||
try {
|
try {
|
||||||
await userCheckin();
|
void (await userCheckin());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const msg = String((typeof err === 'string' ? err : (err && (err.message || err.msg))) || '');
|
const msg = String((typeof err === 'string' ? err : (err && (err.message || err.msg))) || '');
|
||||||
const m = msg.toLowerCase();
|
const m = msg.toLowerCase();
|
||||||
@@ -325,35 +317,81 @@ export default {
|
|||||||
msg.includes('没有找到相关数据') ||
|
msg.includes('没有找到相关数据') ||
|
||||||
msg.includes('找不到');
|
msg.includes('找不到');
|
||||||
if (!needFallback) throw err;
|
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 =
|
const getInfo =
|
||||||
typeof getFrontUserInfoFn === 'function'
|
typeof getFrontUserInfoFn === 'function'
|
||||||
? getFrontUserInfoFn
|
? getFrontUserInfoFn
|
||||||
: (await import('@/api/user.js')).getFrontUserInfo;
|
: (await import('@/api/user.js')).getFrontUserInfo;
|
||||||
const infoRes = await getInfo({ _: Date.now() });
|
const lockGen = ++this._userInfoFetchGen;
|
||||||
if (gen !== this._userInfoFetchGen) {
|
const maxAttempts = 4;
|
||||||
return false;
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
||||||
}
|
if (attempt > 0) {
|
||||||
const serverPoints = this._parsePointsFromUserInfo(infoRes);
|
await new Promise((r) => setTimeout(r, 120 * attempt));
|
||||||
if (serverPoints != null && !Number.isNaN(Number(serverPoints))) {
|
}
|
||||||
this.currentPoints = Number(serverPoints);
|
try {
|
||||||
return true;
|
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;
|
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) {
|
_parsePointsFromUserInfo(infoRes) {
|
||||||
if (!infoRes) return null;
|
if (!infoRes) return null;
|
||||||
|
if (infoRes.code != null && Number(infoRes.code) !== 200) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const payload = infoRes.data;
|
const payload = infoRes.data;
|
||||||
const d = (payload && payload.data != null && typeof payload === 'object') ? payload.data : payload;
|
const d = (payload && payload.data != null && typeof payload === 'object') ? payload.data : payload;
|
||||||
if (d == null || typeof d !== 'object') return null;
|
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
|
// 勿把打卡/签到接口的 SystemGroupDataSignConfigVo(含 day + integral 奖励)当成个人中心 integral
|
||||||
if (d.day != null && d.nickname == null && d.nowMoney == null) {
|
if (d.day != null && d.nickname == null && d.nowMoney == null) {
|
||||||
return 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));
|
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;
|
return v != null && v !== '' ? v : null;
|
||||||
},
|
},
|
||||||
@@ -364,6 +402,7 @@ export default {
|
|||||||
return index >= 0 ? index : this.streakDays.length - 1
|
return index >= 0 ? index : this.streakDays.length - 1
|
||||||
},
|
},
|
||||||
handleTask(task) {
|
handleTask(task) {
|
||||||
|
// test-0415 P2-1:内容分享类任务跳转到社区
|
||||||
switch (task.id) {
|
switch (task.id) {
|
||||||
case 1: // 饮食记录上传
|
case 1: // 饮食记录上传
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
@@ -375,9 +414,9 @@ export default {
|
|||||||
url: '/pages/tool/checkin-publish?type=video'
|
url: '/pages/tool/checkin-publish?type=video'
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 3: // 内容分享
|
case 3: // 内容分享 → 社区(tabBar)
|
||||||
uni.navigateTo({
|
uni.switchTab({
|
||||||
url: '/pages/tool/invite-rewards'
|
url: '/pages/tool_main/community'
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
@@ -388,8 +427,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleExchange(item) {
|
handleExchange(item) {
|
||||||
uni.navigateTo({
|
// test-0415 P2-1:积分兑换类任务统一跳转到商城首页(tabBar)
|
||||||
url: '/pages/tool/welcome-gift'
|
uni.switchTab({
|
||||||
|
url: '/pages/index/index'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<view class="welcome-gift-page">
|
<view class="welcome-gift-page">
|
||||||
<!-- 内容区域 -->
|
<!-- 内容区域 -->
|
||||||
<scroll-view class="content-scroll" scroll-y>
|
<scroll-view class="content-scroll" scroll-y>
|
||||||
<!-- 新人福利大礼包卡片 -->
|
<!-- 新人福利大礼包卡片:点击跳商城福利商品详情(test-0415 P2-1) -->
|
||||||
<view class="gift-banner">
|
<view class="gift-banner" @click="goWelfareProduct">
|
||||||
<view class="gift-icon">
|
<view class="gift-icon">
|
||||||
<image :src="giftIcon" mode="aspectFit"></image>
|
<image :src="giftIcon" mode="aspectFit"></image>
|
||||||
</view>
|
</view>
|
||||||
@@ -45,43 +45,37 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 领取方式 -->
|
<!-- 领取方式(test-0415 P2-1:去除长按识别二维码,改为客服按钮直接联系) -->
|
||||||
<view class="section">
|
<view class="section">
|
||||||
<view class="section-title">领取方式</view>
|
<view class="section-title">领取方式</view>
|
||||||
<view class="claim-card">
|
<view class="claim-card">
|
||||||
<!-- 步骤1 -->
|
<!-- 步骤1:联系客服 -->
|
||||||
<view class="claim-step">
|
<view class="claim-step">
|
||||||
<view class="step-number">1</view>
|
<view class="step-number">1</view>
|
||||||
<view class="step-content">
|
<text class="step-text">点击下方按钮联系营养专家客服,备注「领取福利」</text>
|
||||||
<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>
|
|
||||||
</view>
|
</view>
|
||||||
|
<!-- 步骤2:等待发放 -->
|
||||||
<!-- 步骤2 -->
|
|
||||||
<view class="claim-step">
|
<view class="claim-step">
|
||||||
<view class="step-number">2</view>
|
<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>
|
<text class="step-text">专家将在 24 小时内发送福利大礼包</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</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">
|
<view class="add-btn" @click="handleAddWeChat">
|
||||||
<text class="btn-icon">🎁</text>
|
<text class="btn-icon">🎁</text>
|
||||||
<text class="btn-text">立即添加,领取福利</text>
|
<text class="btn-text">立即联系客服,领取福利</text>
|
||||||
</view>
|
</view>
|
||||||
|
<!-- #endif -->
|
||||||
|
|
||||||
|
|
||||||
<!-- 免责声明 -->
|
<!-- 免责声明 -->
|
||||||
<view class="disclaimer">
|
<view class="disclaimer">
|
||||||
@@ -101,7 +95,9 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
giftIcon: 'https://www.figma.com/api/mcp/asset/b31b3ad1-05c7-43b4-9541-caff8bab7a95',
|
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: [
|
giftItems: [
|
||||||
{
|
{
|
||||||
icon: '📚',
|
icon: '📚',
|
||||||
@@ -131,16 +127,34 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
// 页面加载
|
// 读取福利商品 ID(运营可在缓存或全局配置中写入;先简单从 storage 读,无值则点击时跳商城首页)
|
||||||
|
try {
|
||||||
|
const id = uni.getStorageSync('welfareProductId')
|
||||||
|
if (id) this.welfareProductId = String(id)
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
handleAddWeChat() {
|
||||||
// 这里可以调用微信API打开企业微信或显示二维码
|
// H5 / APP 兜底:尝试打开 chatUrl 或拨打热线(小程序走 button open-type='contact')
|
||||||
uni.showToast({
|
const chatUrl = uni.getStorageSync('chatUrl')
|
||||||
title: '请长按识别二维码添加',
|
if (chatUrl) {
|
||||||
icon: 'none',
|
const arr = String(chatUrl).split('?')
|
||||||
duration: 2000
|
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;
|
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 {
|
.disclaimer {
|
||||||
|
|||||||
Reference in New Issue
Block a user