gemercheung 11 miesięcy temu
rodzic
commit
3755ef20ca

+ 1 - 0
pages/course/course.json

@@ -1,5 +1,6 @@
 {
   "disableScroll": true,
+  "navigationBarTitleText": "我的购买",
   "usingComponents": {
     "t-pull-down-refresh": "tdesign-miniprogram/pull-down-refresh/pull-down-refresh",
     "t-back-top": "tdesign-miniprogram/back-top/back-top",

+ 16 - 4
pages/course_detail/course_detail.js

@@ -1,11 +1,12 @@
 // pages/course_detail/course_detail.js
+import dayjs from 'dayjs'
 import {
   getVRCourseDetail
 } from '../../utils/request';
 
 import {
-  IsNotStart,
-  IsInTime
+
+  getCourseStatus,
 } from '../../utils/courseTime';
 
 Page({
@@ -36,6 +37,13 @@ Page({
       title: "",
       titleSub: "",
       updateTime: "",
+      openRoomTime: '',
+      endRoomTime: ''
+    },
+    courseStaus: {
+      status: 0,
+      time: 0,
+      showTime: ''
     }
   },
 
@@ -57,8 +65,12 @@ Page({
     this.setData({
       detail: data.data
     }, () => {
-      const res = IsNotStart(this.data.detail.createTime)
-      console.log('IsNotStart', res, this.data.detail.createTime)
+      const res = getCourseStatus(this.data.detail.openRoomTime, this.data.detail.endRoomTime)
+      // const res = getCourseStatus(dayjs('2024-09-02 10:00:00'), dayjs('2024-09-04 10:00:00'))
+      console.log('getCourseStatus', res)
+      this.setData({
+        courseStaus: res
+      })
     })
   },
   /**

+ 13 - 5
pages/course_detail/course_detail.wxml

@@ -36,15 +36,23 @@
 
   <view class="bottom_panel">
     <view class="left">
-      <t-count-down class="count" size="small" content="default" time="{{ time }}" format="HH:mm:ss:SSS" theme="square"
-        millisecond> </t-count-down>
-      <text class="desc">开课时间:2024-09-19-20  16:00-20:00</text>
+      <t-count-down class="count" size="small" content="default" time="{{ courseStaus.time }}" format="HH:mm:ss:SSS"
+        theme="square" millisecond> </t-count-down>
+      <text class="desc"
+        wx:if="{{courseStaus.status === 0 || courseStaus.status === 2}}">开课时间:{{courseStaus.showTime}}</text>
+      <text class="desc" wx:if="{{courseStaus.status ===1}}">开课时间: 进行中</text>
     </view>
 
     <view class="right">
       <!-- <button class="btn">立即抢购</button> -->
-      <!-- <t-button class="btn" theme="danger" size="medium" shape="round">立即抢购</t-button> -->
-      <t-button class="btn" theme="danger" size="medium" shape="round" bindtap="openHost">进入课堂</t-button>
+      <t-button class="btn" theme="danger" size="medium" shape="round" wx:if="{{courseStaus.status ===0}}">立即抢购
+      </t-button>
+
+      <t-button class="btn" theme="danger" size="medium" shape="round" bindtap="openHost"
+        wx:if="{{courseStaus.status ===1}}">进入课堂</t-button>
+
+      <t-button class="btn" size="medium" shape="round" bindtap="openHost"
+        wx:if="{{courseStaus.status ===2}}" disabled>课程结束</t-button>
     </view>
 
   </view>

+ 92 - 61
pages/user/index.js

@@ -63,7 +63,7 @@ Page({
     ],
 
     active: false,
-    isLogin: ''
+    isLogin: false
   },
 
   /**
@@ -150,13 +150,14 @@ Page({
           })
           break;
         case 3:
+          console.log('userId', this.data.userInfo.id)
           wx.navigateTo({
-            url: "/pages/user/my_course/my_course"
+            url: `/pages/user/my_course/my_course?userId=${this.data.userInfo.id}`
           })
           break;
         case 4:
           wx.navigateTo({
-            url: "/pages/user/my_host_course/index"
+            url: `/pages/user/my_host_course/index?userId=${this.data.userInfo.id}`
           })
           break;
       }
@@ -293,7 +294,7 @@ Page({
     wx.getUserProfile({
       desc: '获取您的身份信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
       success: (res) => {
-        console.log(123456, res);
+        console.log("getUserProfile", res);
         let {
           encryptedData,
           iv,
@@ -329,9 +330,12 @@ Page({
                 success: res => {
                   if (res.data.code > -1) {
                     let {
-                      loginSessionKey
+                      loginSessionKey,
+                      sessionKey
                     } = res.data.data;
                     wx.setStorageSync('token', loginSessionKey)
+                    wx.setStorageSync('sessionKey', sessionKey)
+                    this.updateUserinfo();
                   } else {
                     Toast.showToast('warn', '登录失败,请重试');
                   }
@@ -399,10 +403,12 @@ Page({
         if (res.data.code > -1) {
           wx.setStorageSync('userInfo', null);
           wx.setStorageSync('token', null);
+          wx.setStorageSync('sessionKey', null);
           console.log(wx.getStorageSync('token'))
           this.setData({
             isLogin: false,
-            avatarUrl: ""
+            avatarUrl: "",
+
           })
           app.globalData.isLogin = false;
         }
@@ -424,10 +430,7 @@ Page({
     this._isLogin();
     if (this.data.isLogin) {
       wx.navigateTo({
-        url: `./my_order/index?status=${status}&&id=${id}`,
-        success: function (res) {},
-        fail: function (res) {},
-        complete: function (res) {},
+        url: `./my_order/index?status=${status}&&id=${id}`
       })
     } else {
       Toast.showToast('tip', '请登录后查看', () => {
@@ -449,51 +452,51 @@ Page({
     })
   },
 
-  newLogin() {
-    wx.login({
-      success: res => {
-        let {
-          code
-        } = res;
-
-        console.log(789, res);
-
-        if (code) {
-          wx.request({
-            url: serverName + '/wx/api/user/getLoginSessionKey',
-            data: {
-              code,
-            },
-            header: {
-              'content-type': 'application/x-www-form-urlencoded'
-            },
-            method: 'post',
-            // dataType: 'json',
-            // responseType: 'text',
-            success: res => {
-              if (res.data.code > -1) {
-                let {
-                  loginSessionKey
-                } = res.data.data;
-                wx.setStorageSync('token', loginSessionKey)
-              } else {
-                Toast.showToast('warn', '登录失败,请重试');
-              }
-            },
-            fail: res => {
-              Toast.showToast('warn', '登录失败,请重试');
-
-            },
-            complete: res => {
-              this._isLogin();
-              Toast.hideLoading();
-            },
-          })
-        }
-      }
-    })
-
-  },
+  // newLogin() {
+  //   wx.login({
+  //     success: res => {
+  //       let {
+  //         code
+  //       } = res;
+
+  //       console.log(789, res);
+
+  //       if (code) {
+  //         wx.request({
+  //           url: serverName + '/wx/api/user/getLoginSessionKey',
+  //           data: {
+  //             code,
+  //           },
+  //           header: {
+  //             'content-type': 'application/x-www-form-urlencoded'
+  //           },
+  //           method: 'post',
+  //           // dataType: 'json',
+  //           // responseType: 'text',
+  //           success: res => {
+  //             if (res.data.code > -1) {
+  //               let {
+  //                 loginSessionKey
+  //               } = res.data.data;
+  //               wx.setStorageSync('token', loginSessionKey)
+  //             } else {
+  //               Toast.showToast('warn', '登录失败,请重试');
+  //             }
+  //           },
+  //           fail: res => {
+  //             Toast.showToast('warn', '登录失败,请重试');
+
+  //           },
+  //           complete: res => {
+  //             this._isLogin();
+  //             Toast.hideLoading();
+  //           },
+  //         })
+  //       }
+  //     }
+  //   })
+
+  // },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
@@ -504,13 +507,19 @@ Page({
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow: function () {
+  onShow: async function () {
     let {
       avatar = ""
     } = this.data;
-    console.log(wx.getStorageSync('userInfo'))
-    let avatarUrl = wx.getStorageSync('userInfo') ? wx.getStorageSync('userInfo').avatarUrl : "";
-    let avatarName = wx.getStorageSync('userInfo') ? wx.getStorageSync('userInfo').nickName : "";
+
+    const userInfo = wx.getStorageSync('userInfo')
+    const sessionKey = wx.getStorageSync('sessionKey')
+    let avatarUrl = userInfo ? userInfo.avatarUrl : "";
+    let avatarName = userInfo ? userInfo.nickName : "";
+    console.log('sessionKey', sessionKey)
+    if (sessionKey) {
+      this.updateUserinfo();
+    }
 
     this.setData({
       avatarUrl: avatarUrl || avatar,
@@ -518,8 +527,30 @@ Page({
     })
     this._isLogin()
 
-    getWxUserInfo('9fbbd7dfca6e49d9b20b77eb0f94e73a')
-    // debugger
+    if (userInfo) {
+      this.setData({
+        userInfo: userInfo,
+      })
+    }
+
+  },
+
+  async updateUserinfo() {
+    const sessionKey = wx.getStorageSync('sessionKey')
+    console.log('sessionKey', sessionKey)
+    if (sessionKey) {
+      const res = await getWxUserInfo(sessionKey)
+      const userInfo = wx.getStorageInfoSync('userInfo')
+      if (res.data) {
+        const mergeObj = {
+          ...userInfo,
+          ...res.data
+        }
+        console.log('userInfo-mergeObj', mergeObj)
+        wx.setStorageSync('userInfo', mergeObj)
+      }
+
+    }
   },
 
   /**

+ 2 - 2
pages/user/index.wxml

@@ -7,8 +7,8 @@
         <image mode="aspectFit" class='user_avatar' src='{{avatarUrl||avatar}}'></image>
         <text class='user_nickName'>{{isLogin?avatarName:"登录"}}</text>
         <!-- <button open-type="getUserInfo" class='user_avatar_btn' bindgetuserinfo="_getUserInfoToLogin"></button> -->
-        <button class='user_avatar_btn' bindtap="getUserProfile"></button>
-        <!-- <button class='user_avatar_btn' bindtap="toPersonal"></button> -->
+        <button class='user_avatar_btn' bindtap="toPersonal" wx:if="{{isLogin}}"></button>
+        <button class='user_avatar_btn' bindtap="getUserProfile" wx:else></button>
       </view>
     </view>
   </view>

+ 14 - 2
pages/user/my_course/my_course.js

@@ -1,4 +1,7 @@
 // pages/user/my_course/my_course.js
+import {
+  getMyPaidlesson
+} from '../../../utils/request'
 Page({
 
   /**
@@ -6,13 +9,22 @@ Page({
    */
   data: {
     testData: 10,
+    list: []
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
-  onLoad(options) {
-
+  async onLoad(options) {
+    if (options.userId) {
+      const res = await getMyPaidlesson(options.userId);
+      console.log('res', res)
+      if (res.code === 0) {
+        this.setData({
+          list: res.data || []
+        })
+      }
+    }
   },
 
   /**

+ 14 - 2
pages/user/my_host_course/index.js

@@ -1,4 +1,7 @@
 // pages/user/my_course/my_course.js
+import {
+  getMyHostlesson
+} from '../../../utils/request'
 Page({
 
   /**
@@ -12,10 +15,19 @@ Page({
   /**
    * 生命周期函数--监听页面加载
    */
-  onLoad(options) {
-
+  async onLoad(options) {
+    if (options.userId) {
+      const res = await getMyHostlesson(options.userId);
+      console.log('getMyHostlesson', res)
+      if (res.code === 0) {
+        this.setData({
+          list: res.data || []
+        })
+      }
+    }
   },
 
+
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 48 - 25
pages/user/personal/personal.js

@@ -9,7 +9,10 @@ import ActionSheet, {
 //   updateUserInfo,
 //   updateAvatar
 // } from '../../api/user'
-
+import {
+  decrptPhone,
+  updateUserInfo
+} from '../../../utils/request'
 let genderHandler = null
 
 const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -26,6 +29,10 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad() {
+    const userInfo = wx.getStorageSync('userInfo')
+    this.setData({
+      userInfo: userInfo
+    })
 
   },
   updateUserInfo(data) {
@@ -37,8 +44,7 @@ Page({
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady() {
-    // const app = getApp();
-    // app.watch('userInfo', this.updateUserInfo)
+
 
   },
 
@@ -135,16 +141,17 @@ Page({
         encryptedData
       } = event.detail
       if (code && iv && encryptedData) {
-        const res = await decrptPhone({
-          iv: iv,
-          code: code,
-          encryptedData: encryptedData
-        })
-        console.log('res', res.phoneNumber)
-        if (res.phoneNumber) {
-          const wxUserId = wx.getStorageSync('wxUserId');
+        // const res = await decrptPhone({
+        //   iv: iv,
+        //   code: code,
+        //   encryptedData: encryptedData
+        // })
+        const userInfo = wx.getStorageSync('userInfo')
+        console.log('decrptPhone', code, userInfo.id)
+        const res = await decrptPhone(code, userInfo.id)
+        console.log('res', res)
+        if (res.code === 0) {
           const result = await updateUserInfo({
-            wxUserId,
             phoneNumber: res.phoneNumber
           })
           if (result.code === 0) {
@@ -180,12 +187,14 @@ Page({
     if (index > -1) {
       // debugger
       console.log('index', index)
-      const wxUserId = wx.getStorageSync('wxUserId');
-      await updateUserInfo({
-        wxUserId,
+
+      const res = await updateUserInfo({
         gender: index + 1
       })
-      await getUserInfo();
+      if (res.code === 0) {
+        this.syncUserInfo(res.data)
+      }
+
     }
 
 
@@ -198,13 +207,14 @@ Page({
 
     console.log('e', e)
     const url = await updateAvatar(avatarUrl)
-    console.log('url', url)
-    const wxUserId = wx.getStorageSync('wxUserId');
-    await updateUserInfo({
-      wxUserId,
+
+    const res = await updateUserInfo({
       avatarUrl: url
     })
-    await getUserInfo();
+    if (res.code === 0) {
+      this.syncUserInfo(res.data)
+    }
+
   },
 
   async updateNickName(e) {
@@ -213,15 +223,28 @@ Page({
     } = e.detail
     console.log('value-1', value)
     if (value) {
-      const wxUserId = wx.getStorageSync('wxUserId');
-      await updateUserInfo({
-        wxUserId,
+      const res = await updateUserInfo({
         nickName: value
       })
-      await getUserInfo();
+      console.log('res', res)
+      // if (res.code === 0) {
+      //   this.syncUserInfo(res.data)
+      // }
+
     }
 
   },
+  syncUserInfo(data) {
+    const userInfo = wx.getStorageSync('userInfo');
+    if (userInfo) {
+      const mergeObj = {
+        ...userInfo,
+        ...data
+      }
+      console.log('syncUserInfo', mergeObj)
+      wx.setStorageSync('userInfo', mergeObj)
+    }
+  },
   handleCancel() {
     genderHandler && genderHandler.close();
   }

+ 10 - 4
pages/user/personal/personal.wxml

@@ -1,8 +1,11 @@
 <!--pages/personal/personal.wxml-->
 <view class="personal-view">
+  <!-- {{userInfo.avatarUrl}} -->
   <t-cell title="头像" arrow hover>
+
     <view class="avatar" slot="note">
-      <t-button wx:if="{{userInfo.avatarUrl}}" class="avatar-btn" variant="text" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
+      <t-button wx:if="{{userInfo.avatarUrl}}" class="avatar-btn" variant="text" open-type="chooseAvatar"
+        bind:chooseavatar="onChooseAvatar">
         <t-avatar image="{{userInfo.avatarUrl}}" class="avatar" size="medium" />
       </t-button>
 
@@ -13,7 +16,8 @@
   </t-cell>
 
   <t-cell title="昵称" hover arrow>
-    <t-input  maxlength="{{32}}"  value="{{userInfo.nickName}}" bind:blur='updateNickName' type='nickname' class="nickname" placeholder="请输入昵称" slot='note'>
+    <t-input maxlength="{{32}}" value="{{userInfo.nickName}}" bind:blur='updateNickName' type='nickname'
+      class="nickname" placeholder="请输入昵称" slot='note'>
     </t-input>
   </t-cell>
 
@@ -21,14 +25,16 @@
     <view slot='note'>
       <text wx:if="{{userInfo.gender == 1}}" bind:tap="handleSexSelectShow">男</text>
       <text wx:if="{{userInfo.gender == 2}}" bind:tap="handleSexSelectShow">女</text>
-      <t-button wx:if="{{userInfo.gender == 0}}" class="phone" variant="text" size="small" bind:tap="handleSexSelectShow">点击选择</t-button>
+      <t-button wx:if="{{userInfo.gender == 0}}" class="phone" variant="text" size="small"
+        bind:tap="handleSexSelectShow">点击选择</t-button>
     </view>
   </t-cell>
 
   <t-cell title="绑定手机" hover arrow>
     <view slot='note'>
       <text wx:if="{{userInfo.phoneNumber}}">{{userInfo.phoneNumber}}</text>
-      <t-button wx:else class="phone" variant="text" size="small" open-type="getPhoneNumber" bindgetphonenumber="handleGetPhoneNumber">点击绑定</t-button>
+      <t-button wx:else class="phone" variant="text" size="small" open-type="getPhoneNumber"
+        bindgetphonenumber="handleGetPhoneNumber">点击绑定</t-button>
     </view>
   </t-cell>
   <view class="btn-container" wx:if="{{isLogin}}">

+ 31 - 0
utils/courseTime.js

@@ -18,4 +18,35 @@ export function IsNotStart(comingStartDate) {
 export function IsInTime(comingStartDate, comingEndDate) {
   const now = dayjs();
   return now.isBetween(dayjs(comingStartDate), dayjs(comingEndDate))
+}
+
+export function getCourseStatus(comingStartDate, comingEndDate) {
+  const now = dayjs();
+  const isOn = now.isBetween(dayjs(comingStartDate), dayjs(comingEndDate));
+  console.log('isOn', isOn)
+  const reMain = dayjs(comingEndDate).diff(now)
+  if (isOn) {
+    return {
+      status: 1,
+      time: 0,
+      showTime: dayjs(comingStartDate).format('YYYY-MM-DD hh:mm:ss')
+    }
+  } else {
+    if (reMain < 0) {
+      return {
+        status: 2,
+        time: 0,
+        showTime: dayjs(comingStartDate).format('YYYY-MM-DD hh:mm:ss')
+      }
+    } else {
+      const nearStart = dayjs(comingStartDate).diff(now)
+      return {
+        status: 0,
+        time: nearStart,
+        showTime: dayjs(comingStartDate).format('YYYY-MM-DD hh:mm:ss')
+      }
+    }
+
+  }
+
 }

+ 46 - 6
utils/request.js

@@ -7,7 +7,15 @@ const urls = {
   //VR课堂详情
   getVRCourseDetail: '/api/show/lesson/detail/',
   // 获取微信用户详情
-  getWxUserInfo: "/api/wxUser/getWxUserInfo/"
+  getWxUserInfo: "/api/wxUser/getWxUserInfo/",
+  //微信用户-我的购买
+  getMylesson: "/api/show/lesson/getList/",
+  //主持人-我的课程
+  getMyHostlesson: "/api/show/compere/getLesson/",
+
+  getPhone: "/api/wxUser/getPhone",
+  updateWxUser: "/api/wxUser/updateWxUser/{sessionKey}",
+
 
 }
 
@@ -29,9 +37,41 @@ export async function getWxUserInfo(key) {
 }
 
 
+export async function getMyPaidlesson(wxUserId) {
+  return await (await wxRequest.get(urls.getMylesson + wxUserId)).data;
+}
+export async function getMyHostlesson(wxUserId) {
+  return await (await wxRequest.get(urls.getMyHostlesson + wxUserId)).data;
+}
+
+export async function decrptPhone(code, wxUserId) {
+  console.log('decrptPhone-params', code, wxUserId)
+  const url = `${urls.getPhone}/${code}/${wxUserId}`
+  console.log('decrptPhone-url', url)
+  return await (await wxRequest.get(url)).data;
+}
+
+export async function updateUserInfo(info) {
+  const sessionKey = wx.getStorageSync('sessionKey')
+  if (sessionKey) {
+    const url = urls.updateWxUser.replace('{sessionKey}', sessionKey)
+    return await (await wxRequest.post(url, info)).data;
+  }
+}
+export const updateAvatar = async (avatarUrl) => {
 
-// module.exports = {
-//   getVRCourseList,
-//   getVRCourseDetail,
-//   getWxUserInfo
-// }
+  const WX_UPLOAD_URL = ''
+  let url = ''
+  wx.uploadFile({
+    filePath: avatarUrl,
+    name: 'file',
+    url: WX_UPLOAD_URL,
+    success: async (res) => {
+      const data = JSON.parse(res.data)
+      console.log('data', data)
+      url = data.data
+    }
+  })
+  await sleep(1200)
+  return Promise.resolve(url)
+}