|
|
@@ -244,6 +244,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import api from '@/utils/api.js'
|
|
|
+
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -671,48 +673,64 @@ export default {
|
|
|
},
|
|
|
|
|
|
// 加载签到信息
|
|
|
- loadCheckinInfo() {
|
|
|
+ async loadCheckinInfo() {
|
|
|
// 确保有用户ID
|
|
|
if (!this.userInfo.userId) {
|
|
|
console.error('用户ID不存在,无法加载签到信息')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- uni.request({
|
|
|
- url: this.gatewayURL + '/api/checkin/info',
|
|
|
- method: 'GET',
|
|
|
- data: {
|
|
|
- userId: this.userInfo.userId
|
|
|
- },
|
|
|
- success: (res) => {
|
|
|
- console.log('签到信息:', res.data)
|
|
|
-
|
|
|
- if (res.data.code === 200) {
|
|
|
- const data = res.data.data
|
|
|
-
|
|
|
- // 更新签到数据
|
|
|
- this.checkinData = {
|
|
|
- continuousDays: data.continuousDays,
|
|
|
- totalDays: data.totalDays,
|
|
|
- todayChecked: data.todayChecked,
|
|
|
- checkedDates: data.checkedDates
|
|
|
- }
|
|
|
-
|
|
|
- // 更新奖励列表
|
|
|
- this.checkinRewards = data.rewards
|
|
|
-
|
|
|
- // 生成日历
|
|
|
- this.generateCalendarFromBackend(data.checkedDates)
|
|
|
+ try {
|
|
|
+ // 检查用户是否为红娘
|
|
|
+ const matchmakerStatusRes = await api.user.getMatchmakerStatus(this.userInfo.userId)
|
|
|
+ console.log('用户红娘状态:', matchmakerStatusRes)
|
|
|
+
|
|
|
+ if (matchmakerStatusRes && matchmakerStatusRes.isMatchmaker) {
|
|
|
+ // 是红娘,使用红娘签到接口
|
|
|
+ console.log('用户是红娘,使用红娘签到接口')
|
|
|
+
|
|
|
+ // 获取当前年月
|
|
|
+ const today = new Date()
|
|
|
+ const year = today.getFullYear()
|
|
|
+ const month = today.getMonth() + 1
|
|
|
+
|
|
|
+ // 调用红娘签到信息接口
|
|
|
+ const checkinInfoRes = await api.matchmaker.checkinInfo(
|
|
|
+ matchmakerStatusRes.matchmakerId,
|
|
|
+ year,
|
|
|
+ month
|
|
|
+ )
|
|
|
+
|
|
|
+ console.log('红娘签到信息:', checkinInfoRes)
|
|
|
+
|
|
|
+ // 更新签到数据
|
|
|
+ this.checkinData = {
|
|
|
+ continuousDays: checkinInfoRes.continuousDays,
|
|
|
+ totalDays: checkinInfoRes.totalDays,
|
|
|
+ todayChecked: checkinInfoRes.todayChecked,
|
|
|
+ checkedDates: checkinInfoRes.checkedDates
|
|
|
}
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- console.error('获取签到信息失败:', err)
|
|
|
- uni.showToast({
|
|
|
- title: '加载签到信息失败',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
+
|
|
|
+ // 生成日历
|
|
|
+ this.generateCalendarFromBackend(checkinInfoRes.checkedDates)
|
|
|
+
|
|
|
+ // 简单的奖励列表
|
|
|
+ this.checkinRewards = [
|
|
|
+ { day: 7, icon: '👑', reward: '积分+10', received: checkinInfoRes.continuousDays >= 7, isCurrent: checkinInfoRes.continuousDays < 7 },
|
|
|
+ { day: 14, icon: '💎', reward: '积分+20', received: checkinInfoRes.continuousDays >= 14, isCurrent: checkinInfoRes.continuousDays >= 7 && checkinInfoRes.continuousDays < 14 },
|
|
|
+ { day: 30, icon: '🏆', reward: '积分+50', received: checkinInfoRes.continuousDays >= 30, isCurrent: checkinInfoRes.continuousDays >= 14 && checkinInfoRes.continuousDays < 30 }
|
|
|
+ ]
|
|
|
+ } else {
|
|
|
+ // 不是红娘,普通用户签到功能暂未实现
|
|
|
+ console.log('用户不是红娘,普通用户签到功能暂未实现')
|
|
|
}
|
|
|
- })
|
|
|
+ } catch (err) {
|
|
|
+ console.error('加载签到信息失败:', err)
|
|
|
+ uni.showToast({
|
|
|
+ title: '加载签到信息失败',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// 根据后端数据生成日历(修复版本)
|
|
|
@@ -781,7 +799,7 @@ export default {
|
|
|
this.$refs.checkinPopup.close()
|
|
|
},
|
|
|
// 处理签到(通过网关)
|
|
|
- handleCheckin() {
|
|
|
+ async handleCheckin() {
|
|
|
if (this.checkinData.todayChecked) {
|
|
|
uni.showToast({
|
|
|
title: '今日已签到',
|
|
|
@@ -792,61 +810,62 @@ export default {
|
|
|
|
|
|
// 确保有用户ID
|
|
|
if (!this.userInfo.userId) {
|
|
|
- uni.showToast({
|
|
|
- title: '请先登录',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
+ uni.showToast({ title: '请先登录', icon: 'none' })
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 调用后端签到接口(通过网关)
|
|
|
- uni.request({
|
|
|
- url: this.gatewayURL + '/api/checkin/sign?userId=' + this.userInfo.userId,
|
|
|
- method: 'POST',
|
|
|
- success: (res) => {
|
|
|
- console.log('签到结果:', res.data)
|
|
|
-
|
|
|
- if (res.data.code === 200) {
|
|
|
- // 显示签到成功提示
|
|
|
- uni.showToast({
|
|
|
- title: res.data.message,
|
|
|
- icon: 'success',
|
|
|
- duration: 2500
|
|
|
- })
|
|
|
-
|
|
|
- const data = res.data.data
|
|
|
-
|
|
|
- // 更新签到数据
|
|
|
- this.checkinData = {
|
|
|
- continuousDays: data.continuousDays,
|
|
|
- totalDays: data.totalDays,
|
|
|
- todayChecked: data.todayChecked,
|
|
|
- checkedDates: data.checkedDates
|
|
|
- }
|
|
|
-
|
|
|
- // 更新奖励列表
|
|
|
- this.checkinRewards = data.rewards
|
|
|
-
|
|
|
- // 重新生成日历
|
|
|
- this.generateCalendarFromBackend(data.checkedDates)
|
|
|
-
|
|
|
- } else {
|
|
|
- // 签到失败
|
|
|
- uni.showToast({
|
|
|
- title: res.data.message,
|
|
|
- icon: 'none',
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
+ try {
|
|
|
+ // 检查用户是否为红娘
|
|
|
+ const matchmakerStatusRes = await api.user.getMatchmakerStatus(this.userInfo.userId)
|
|
|
+ console.log('用户红娘状态:', matchmakerStatusRes)
|
|
|
+
|
|
|
+ if (matchmakerStatusRes && matchmakerStatusRes.isMatchmaker) {
|
|
|
+ // 是红娘,使用红娘签到接口
|
|
|
+ console.log('用户是红娘,使用红娘签到接口')
|
|
|
+
|
|
|
+ // 调用红娘签到接口
|
|
|
+ const signRes = await api.matchmaker.doCheckin(matchmakerStatusRes.matchmakerId)
|
|
|
+
|
|
|
+ // 签到成功后更新状态
|
|
|
+ this.checkinData.todayChecked = true
|
|
|
+ this.checkinData.totalDays++
|
|
|
+ this.checkinData.continuousDays++
|
|
|
+
|
|
|
+ // 获取当前日期字符串
|
|
|
+ const today = new Date()
|
|
|
+ const todayStr = this.formatDate(today)
|
|
|
+
|
|
|
+ // 更新签到日期列表
|
|
|
+ if (!this.checkinData.checkedDates.includes(todayStr)) {
|
|
|
+ this.checkinData.checkedDates.push(todayStr)
|
|
|
}
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- console.error('签到失败:', err)
|
|
|
+
|
|
|
+ // 重新生成日历
|
|
|
+ this.generateCalendarFromBackend(this.checkinData.checkedDates)
|
|
|
+
|
|
|
uni.showToast({
|
|
|
- title: '签到失败,请稍后重试',
|
|
|
+ title: '签到成功 +5积分',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 2500
|
|
|
+ })
|
|
|
+
|
|
|
+ // 重新加载签到信息,确保数据最新
|
|
|
+ await this.loadCheckinInfo()
|
|
|
+ } else {
|
|
|
+ // 不是红娘,普通用户签到功能暂未实现
|
|
|
+ console.log('用户不是红娘,普通用户签到功能暂未实现')
|
|
|
+ uni.showToast({
|
|
|
+ title: '功能开发中,敬请期待',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
- })
|
|
|
+ } catch (err) {
|
|
|
+ console.error('签到失败:', err)
|
|
|
+ uni.showToast({
|
|
|
+ title: err.message || '签到失败,请稍后重试',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
goVerify() {
|
|
|
uni.showToast({
|