Przeglądaj źródła

Merge branch 'master' of http://git.cc-lotus.info/ball-court/ball-applet

guhongwei 2 lat temu
rodzic
commit
5e47b4aa13

+ 1 - 1
pages/stuAdmin/course/info.js

@@ -66,7 +66,7 @@ Page({
                         }
                         const coach = await app.$get(`/lessonCoach`, { lesson_id: that.data.id })
                         if (coach.errcode == '0') that.setData({ coach: coach.data })
-                        const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id })
+                        const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, is_pay: '1' })
                         if (student.errcode == '0') that.setData({ student: student.data })
                         that.setData({ form: arr.data })
                     } else {

+ 49 - 14
pages/stuAdmin/course/sign.js

@@ -43,11 +43,8 @@ Page({
             content: '您是否确定试课?',
             async success(res) {
                 if (res.confirm) {
-                    let arr;
-                    let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id, result: '0', reason: '' }
-                    const lesson = await app.$get(`/tryLessonApply`, { school_id: form.school_id, lesson_id: that.data.id, student_id: user.info.id })
-                    if (lesson.errcode == '0' && lesson.total > 0) arr = await app.$post(`/tryLessonApply/${lesson.data[0]._id}`, params);
-                    else arr = await app.$post(`/tryLessonApply`, params);
+                    let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id }
+                    let arr = await app.$post(`/tryLessonApply`, params);
                     if (arr.errcode == '0') { wx.showToast({ title: `试课申请完成`, icon: 'success', duration: 2000 }); that.watchLogin(); }
                     else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
                 } else if (res.cancel) { }
@@ -59,18 +56,50 @@ Page({
         const that = this;
         const form = that.data.form;
         const user = that.data.user;
+        var payer_role = '';
+        var money = '';
+        if (form.type == '0') money = form.real_money;
+        else if (form.type == '1') money = form.money;
+        if (user.type == '0') payer_role = 'User';
+        else if (user.type == '2') payer_role = 'Coach';
+        else if (user.type == '3') payer_role = 'Student';
         wx.showModal({
             title: '提示',
             content: '您是否确定报名?',
             async success(res) {
                 if (res.confirm) {
-                    let arr;
-                    let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id, money: form.money || 0, is_try: that.data.is_try, try_status: '0' }
-                    const student = await app.$get(`/lessonStudent`, { school_id: form.school_id, lesson_id: that.data.id, student_id: user.info.id })
-                    if (student.errcode == '0' && student.total > 0) arr = await app.$post(`/lessonStudent/${student.data[0]._id}`, params);
-                    else arr = await app.$post(`/lessonStudent`, params);
-                    if (arr.errcode == '0') { wx.showToast({ title: `报名申请完成`, icon: 'success', duration: 2000 }); that.watchLogin(); }
-                    else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
+                    wx.getStorage({
+                        key: 'user',
+                        success: async (res) => {
+                            let obj = { openid: res.data.openid, money: 0.1, school_id: form.school_id, payer_id: user.info.id, payer_role: payer_role, pay_for: 'lessonStudent' }
+                            const arr = await app.$post(`/payOrder`, obj)
+                            if (arr.errcode == '0') {
+                                wx.requestPayment({
+                                    "timeStamp": arr.data.wxSign.timestamp,
+                                    "nonceStr": arr.data.wxSign.nonceStr,
+                                    "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
+                                    "signType": arr.data.wxSign.signType,
+                                    "paySign": arr.data.wxSign.paySign,
+                                    "success": async function (res) {
+                                        let params = { school_id: form.school_id, lesson_id: form._id, student_id: user.info.id, money: money, is_try: that.data.is_try, pay_id: arr.data.data._id, is_pay: '1' }
+                                        let lessonStudent = await app.$post(`/lessonStudent`, params);
+                                        if (lessonStudent.errcode == '0') {
+                                            wx.showToast({ title: `报名申请完成`, icon: 'success', duration: 2000 });
+                                            const pay = await app.$post(`/payOrder/${arr.data.data._id}`, { from_id: lessonStudent.data._id });
+                                            if (pay.errcode == '0') that.watchLogin();
+                                        }
+                                        else wx.showToast({ title: `${lessonStudent.errmsg}`, icon: 'error', duration: 2000 })
+                                    },
+                                    "fail": async function (res) {
+                                        const pay = await app.$delete(`/payOrder/${arr.data.data._id}`);
+                                    },
+                                })
+                            }
+                        },
+                        fail: async (res) => {
+                            wx.redirectTo({ url: '/pages/index/index' });
+                        },
+                    });
                 } else if (res.cancel) { }
             }
         });
@@ -102,17 +131,23 @@ Page({
             success: async res => {
                 that.setData({ user: res.data })
                 if (that.data.id) {
-                    const arr = await app.$get(`/lesson/${that.data.id}`);
+                    const arr = await app.$post(`/lessonStudent/toComputed`, { lesson_id: that.data.id, student_id: res.data.info.id });
                     if (arr.errcode == '0') {
                         let status = statusList.find(i => i.value == arr.data.status)
                         if (status) arr.data.zhStatus = status.label;
                         if (arr.data.school_id) {
                             const school = await app.$get(`/school/${arr.data.school_id}`)
                             if (school.errcode == '0') arr.data.zhSchool = school.data.name;
+                            const lesson = await app.$post(`/tryLessonApply/checkCanUse`, { school_id: arr.data.school_id, lesson_id: that.data.id, student_id: res.data.info.id })
+                            if (lesson.errcode == '0') arr.data.type_try = '0';
+                            else wx.showToast({ title: `${lesson.errmsg}`, icon: 'none', duration: 2000 })
+                            const lessonStudent = await app.$post(`/lessonStudent/checkCanUse`, { school_id: arr.data.school_id, student_id: res.data.info.id, lesson_id: that.data.id })
+                            if (lessonStudent.errcode == '0') arr.data.sign = '0';
+                            else arr.data.sign = '1';
                         }
                         const coach = await app.$get(`/lessonCoach`, { lesson_id: that.data.id })
                         if (coach.errcode == '0') that.setData({ coach: coach.data })
-                        const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id })
+                        const student = await app.$get(`/lessonStudent`, { lesson_id: that.data.id, is_pay: '1' })
                         if (student.errcode == '0') that.setData({ student: student.data })
                         that.setData({ form: arr.data })
                     } else {

+ 3 - 3
pages/stuAdmin/course/sign.wxml

@@ -44,11 +44,11 @@
                                 <text class="text">简介:</text>
                                 <text class="text1">{{form.brief||'暂无'}}</text>
                             </view>
-                            <view class="one_1" wx:if="{{form.type=='0'&&user.type=='3'}}">
+                            <view class="one_1" wx:if="{{form.type_try=='0'&&user.type=='3'&&form.type=='0'&&form.sign=='0'}}">
                                 <text class="text">是否试课:</text>
                                 <button type="primary" size="mini" bindtap="toClass">试课</button>
                             </view>
-                            <view class="btn" wx:if="{{user.type=='3'}}">
+                            <view class="btn" wx:if="{{user.type=='3'&&form.sign=='0'}}">
                                 <button type="primary" size="mini" formType="submit">报名</button>
                             </view>
                         </form>
@@ -86,7 +86,7 @@
                                 </view>
                                 <view class="other_1">
                                     <text>缴费金额:</text>
-                                    <text>{{item.money||'暂无'}}元</text>
+                                    <text>{{item.money||'0'}}元</text>
                                 </view>
                                 <view class="other_1">
                                     <text>所属学院:</text>