lrf402788946 4 tahun lalu
induk
melakukan
f70a43da38

+ 37 - 6
pages/exchange/exchange.js

@@ -9,22 +9,48 @@ Page({
       phone: '17319450324',
       isNum: '100',
     },
-    number: ''
+    number: '',
+    isDisabled: false,
   },
   //提交
   formSubmit: function (e) {
+    this.setData({ isDisabled: true })
     let data = this.data.form;
     data.number = e.detail.value.number;
     // 判断提现金额是否大于已拥有的金额
     if (parseFloat(data.number) <= parseFloat(data.isNum)) {
       if (parseFloat(data.isNum) >= 100 && parseFloat(data.number) >= 100) {
         // 扣除6%手续费
-        data.number = (data.number - data.number * 0.06).toFixed(2);
-        wx.showToast({
-          title: '提现成功',
-          icon: 'success',
-          duration: 2000
+        data.money = (data.number - data.number * 0.06).toFixed(2);
+        data.money = parseInt(data.money) * 100
+        // data.money
+        const query = `id=${data.id}&points=${data.number}&&money=${data.money}`
+        wx.request({
+          url: `${app.globalData.publicUrl}/api/htyd/wxpay/cash?${query}`,
+          success: res => {
+            if (res.data.errcode == '0') {
+              app.globalData.userInfo = res.data.data;
+              wx.showToast({
+                title: '提现成功',
+                icon: 'success',
+                duration: 2000
+              })
+            } else {
+              wx.showToast({
+                title: '提现失败',
+                icon: 'error',
+                duration: 2000
+              })
+            }
+          },
+          error: err => {
+            wx.showToast({
+              title: err.data.errmsg,
+              icon: 'error'
+            })
+          }
         })
+
       } else {
         wx.showToast({
           title: '提现积分最低为100,请输入大于100的积分',
@@ -39,6 +65,7 @@ Page({
         duration: 2000
       })
     }
+    this.setData({ isDisabled: false })
   },
   // 兑换记录
   exchangeList: function () {
@@ -47,5 +74,9 @@ Page({
     })
   },
   onLoad: function () {
+    let data = app.globalData.userInfo;
+    const { points, name, mobile, id } = data
+    const form = { isNum: points, name, phone: mobile, id }
+    this.setData({ form })
   },
 })

+ 1 - 1
pages/exchange/exchange.wxml

@@ -24,7 +24,7 @@
           <text bindtap="exchangeList">兑换记录</text>
         </view>
         <view>
-          <button form-type="submit">确认</button>
+          <button form-type="submit" disabled="{{isDisabled}}">确认</button>
         </view>
       </view>
     </form>

+ 17 - 0
pages/exchange/exchangeList.js

@@ -16,5 +16,22 @@ Page({
   //提交
 
   onLoad: function () {
+    let data = app.globalData.userInfo;
+    wx.request({
+      url: `${app.globalData.publicUrl}/api/htyd/cash?mobile=${data.mobile}`,
+      success: res => {
+        console.log(res);
+        if (res.data.errcode == 0) {
+          this.setData({ exchangeList: res.data.data })
+        }
+      },
+      error: err => {
+        wx.showToast({
+          title: err.data.errmsg,
+          icon: 'error'
+        })
+      }
+    })
+
   },
 })

+ 3 - 3
pages/exchange/exchangeList.wxml

@@ -5,12 +5,12 @@
   <view class="two">
     <view class="list" wx:key="unique" wx:for="{{exchangeList}}" wx:for-item="item">
       <view class="top">
-        <text>兑换到{{item.type}}</text>
-        <text>{{item.number}}</text>
+        <text>兑换到微信零钱</text>
+        <text>{{item.i_point}}</text>
       </view>
       <view class="down">
         <text>{{item.create_time}}</text>
-        <text>{{item.status}}</text>
+        <text>已到账</text>
       </view>
     </view>
   </view>

+ 17 - 0
pages/home/home.js

@@ -117,10 +117,27 @@ Page({
       wx.getUserInfo({
         success: res => {
           if (res.userInfo) {
+            console.log(res.userInfo)
             this.setData({ 'userInfo.avatarUrl': res.userInfo.avatarUrl })
           }
         }
       })
+      // 存储openid以便后面功能使用
+      wx.login({
+        success: res => {
+          // 发送 res.code 到后台换取 openId, sessionKey, unionId
+          wx.request({
+            url: `${app.globalData.publicUrl}/api/htyd/wxpay/auth?code=${res.code}&id=${data.id}`,
+            success: res => { },
+            error: err => {
+              wx.showToast({
+                title: '请重新登陆!',
+                icon: 'error'
+              })
+            }
+          })
+        }
+      })
       this.indexCount();
       this.searchPicker();
     }

+ 0 - 8
pages/integral/integral.js

@@ -51,10 +51,6 @@ Page({
       method: 'get',
       success: res => {
         let { data } = res.data
-        if (data.length <= 0) wx.showToast({
-          title: '未查到相关直推积分数据',
-          icon: "none"
-        })
         data = data.map(i => {
           i.word = ` ${i.name.split('')[0]} `;
           i.mobile = `${i.mobile.substring(0, 3)}****${i.mobile.substring(7, 11)}`
@@ -78,10 +74,6 @@ Page({
       method: 'get',
       success: res => {
         let { data } = res.data
-        if (data.length <= 0) wx.showToast({
-          title: '未查到相关卡单分红数据',
-          icon: "none"
-        })
         data = data.map(i => {
           i.word = ` ${i.name.split('')[0]} `;
           i.mobile = `${i.mobile.substring(0, 3)}****${i.mobile.substring(7, 11)}`