浏览代码

优化兑换

fly 6 天之前
父节点
当前提交
c85063f6a4
共有 3 个文件被更改,包括 140 次插入16 次删除
  1. 1 1
      .env.production
  2. 80 7
      src/views/Dynamic.vue
  3. 59 8
      src/views/jifen.vue

+ 1 - 1
.env.production

@@ -2,4 +2,4 @@
 ENV = 'production'
 
 # 生产环境
-VUE_APP_BASE_API = 'https://jianshekeji.com/api'
+VUE_APP_BASE_API = '/api'

+ 80 - 7
src/views/Dynamic.vue

@@ -54,7 +54,7 @@ export default {
   data() {
     return {
       rewards: [
-        { renshu: 6, title: '邀请6人实名认证', reward: '奖励30积分以及60000元保障金', status: 'not-reached' },
+        { renshu: 6, title: '邀请6人实名认证', reward: '奖励60积分以及60000元保障金', status: 'not-reached' },
         { renshu: 15, title: '邀请15人实名认证', reward: '奖励150积分以及150000元保障金', status: 'not-reached' },
         { renshu: 30, title: '邀请30人实名认证', reward: '奖励300积分以及300000元保障金', status: 'not-reached' },
         { renshu: 60, title: '邀请60人实名认证', reward: '奖励600积分以及600000元保障金', status: 'not-reached' },
@@ -69,33 +69,105 @@ export default {
       try {
         const res = await getUserInfo();
         this.userInfo = res.data;
+        console.log('用户信息:', this.userInfo);
+        console.log('直推人数 totleone:', this.userInfo.totleone);
+        
         // 检查是否已实名认证
         if (this.userInfo.if_real === 0) {
           this.showAuthDialog = true;
         }
+        
+        // 获取用户信息后立即更新奖励状态
+        this.updateRewardStatus();
       } catch (error) {
         console.error('获取用户信息失败:', error);
       }
     },
+    
+    // 新增方法:根据直推人数更新奖励状态
+    updateRewardStatus() {
+      const directCount = this.userInfo.totleone || 0;
+      console.log('根据直推人数更新奖励状态,当前直推人数:', directCount);
+      
+      this.rewards = this.rewards.map(item => {
+        if (directCount >= item.renshu) {
+          console.log(`${item.renshu}人奖励:达标,可领取`);
+          return { ...item, status: 'can-receive' };
+        } else {
+          console.log(`${item.renshu}人奖励:未达标 (需要${item.renshu}人,当前${directCount}人)`);
+          return { ...item, status: 'not-reached' };
+        }
+      });
+    },
     async getShareccbList() {
       try {
         const res = await getShareccbList();
+        console.log('getShareccbList接口返回:', res);
+        
+        // 获取当前直推人数
+        const directCount = this.userInfo.totleone || 0;
+        console.log('当前直推人数:', directCount);
+        
         if (res.code === 1 && Array.isArray(res.data)) {
           // 根据接口返回的received状态,更新rewards
           this.rewards = this.rewards.map(item => {
             const found = res.data.find(d => d.renshu === item.renshu);
             if (found) {
-              // 假设接口返回的状态有 received(已领取), canReceive(可领取), notReached(未达标)
-              let status = 'not-reached';
-              if (found.received) status = 'received';
-              else if (found.canReceive) status = 'can-receive';
-              return { ...item, status };
+              console.log(`找到${item.renshu}人的奖励状态:`, found);
+              
+              // 判断是否已领取:received_coins 和 received_jifen 都为 true 表示已领取
+              if (found.received_coins === true && found.received_jifen === true) {
+                console.log(`${item.renshu}人奖励:已领取`);
+                return { ...item, status: 'received' };
+              } else if (directCount >= item.renshu) {
+                // 直推人数达标且未领取,可以领取
+                console.log(`${item.renshu}人奖励:达标可领取`);
+                return { ...item, status: 'can-receive' };
+              } else {
+                // 直推人数未达标
+                console.log(`${item.renshu}人奖励:未达标`);
+                return { ...item, status: 'not-reached' };
+              }
+            } else {
+              // 如果接口没有返回该奖励的状态,根据用户直推人数判断
+              console.log(`接口未返回${item.renshu}人的状态,根据直推人数判断`);
+              console.log(`当前直推人数: ${directCount}, 需要人数: ${item.renshu}`);
+              
+              if (directCount >= item.renshu) {
+                // 直推人数达标,可以领取
+                return { ...item, status: 'can-receive' };
+              } else {
+                // 直推人数未达标
+                return { ...item, status: 'not-reached' };
+              }
+            }
+          });
+        } else {
+          console.log('接口返回异常,根据直推人数判断状态');
+          // 如果接口异常,根据用户直推人数判断状态
+          console.log(`当前直推人数: ${directCount}`);
+          
+          this.rewards = this.rewards.map(item => {
+            if (directCount >= item.renshu) {
+              return { ...item, status: 'can-receive' };
+            } else {
+              return { ...item, status: 'not-reached' };
             }
-            return item;
           });
         }
       } catch (error) {
         console.error('获取奖励列表失败:', error);
+        // 接口异常时,根据用户直推人数判断状态
+        const directCount = this.userInfo.totleone || 0;
+        console.log(`接口异常,根据直推人数${directCount}判断状态`);
+        
+        this.rewards = this.rewards.map(item => {
+          if (directCount >= item.renshu) {
+            return { ...item, status: 'can-receive' };
+          } else {
+            return { ...item, status: 'not-reached' };
+          }
+        });
       }
     },
     async receiveReward(renshu, received) {
@@ -118,6 +190,7 @@ export default {
   },
   created() {
     this.getUserInfo();
+    // 可选:也调用接口获取服务器端的奖励状态
     this.getShareccbList();
   }
 }

+ 59 - 8
src/views/jifen.vue

@@ -55,6 +55,23 @@
               <div class="confirm-points">需要 {{ selectedProduct.probability }} 积分</div>
             </div>
           </div>
+          
+          <!-- 用户收货信息 -->
+          <div class="user-info-section">
+            <div class="user-info-item">
+              <span class="info-label">收货人:</span>
+              <span class="info-value">{{ userInfo.name || '-' }}</span>
+            </div>
+            <div class="user-info-item">
+              <span class="info-label">电话:</span>
+              <span class="info-value">{{ userInfo.phone || '-' }}</span>
+            </div>
+            <div class="user-info-item">
+              <span class="info-label">地址:</span>
+              <span class="info-value">{{ userInfo.address || '-' }}</span>
+            </div>
+          </div>
+          
           <p>确认要兑换此商品吗?</p>
           <div class="confirm-buttons">
             <button class="btn-cancel" @click="cancelExchange">取消</button>
@@ -86,7 +103,8 @@ export default {
       showConfirmDialog: false,
       selectedProduct: null,
       products: [],
-      userPoints: 0  // 添加用户积分属性
+      userPoints: 0,  // 添加用户积分属性
+      userInfo: {} // 添加用户信息属性
     }
   },
   mounted() {
@@ -99,6 +117,7 @@ export default {
       try {
         const res = await getUserInfo();
         this.userPoints = res.data.jifen || 0; // 获取用户积分
+        this.userInfo = res.data; // 获取用户收货信息
       } catch (error) {
         console.error('获取用户信息失败:', error);
         this.$refs.toast.show('获取用户信息失败', 'error');
@@ -109,6 +128,8 @@ export default {
     async loadProducts() {
       try {
         const res = await getLotteryPrize();
+        console.log('getLotteryPrize接口返回:', res);
+        console.log('商品数据:', res.data);
         this.products = res.data;
         // 当前使用模拟数据,实际开发时替换为API调用
         console.log('商品列表加载完成');
@@ -133,26 +154,31 @@ export default {
     // 确认兑换
     async confirmExchange() {
       try {
-       const res = await exchangePrize({
-        prize_id: this.selectedProduct.id,
-       });
-       console.log(res);
+        console.log('开始兑换,商品信息:', this.selectedProduct);
+        const res = await exchangePrize({
+          prize_id: this.selectedProduct.id,
+        });
+        console.log('兑换接口返回:', res);
+        
         if(res.code == 1){
           this.$refs.toast.show('兑换成功!', 'success');
           this.userPoints -= this.selectedProduct.probability; // 修正为probability字段
           this.showConfirmDialog = false;
           this.selectedProduct = null;
+          // 重新加载商品列表
+          await this.loadProducts();
         }else{
-          this.$refs.toast.show('兑换失败,请重试', 'error');
+          // 使用接口返回的msg字段作为提示信息
+          this.$refs.toast.show(res.msg || '兑换失败', 'error');
         }
         
         this.showConfirmDialog = false;
         this.selectedProduct = null;
         
-        
       } catch (error) {
         console.error('兑换失败:', error);
-        this.$refs.toast.show('兑换失败,请重试', 'error');
+        // 网络异常时才显示通用错误信息
+        this.$refs.toast.show('网络异常,请重试', 'error');
       }
     }
   }
@@ -359,6 +385,31 @@ export default {
   font-weight: 500;
 }
 
+.user-info-section {
+  background: #f8f8f8;
+  border-radius: 8px;
+  padding: 15px;
+  margin-bottom: 20px;
+  text-align: left;
+}
+
+.user-info-item {
+  display: flex;
+  justify-content: space-between;
+  margin-bottom: 8px;
+  font-size: 14px;
+  color: #555;
+}
+
+.info-label {
+  font-weight: 500;
+  color: #333;
+}
+
+.info-value {
+  font-weight: 400;
+}
+
 .confirm-content p {
   margin: 0 0 25px 0;
   color: #666;