Explorar o código

更新支付逻辑

lex %!s(int64=2) %!d(string=hai) anos
pai
achega
0635b58a41

+ 1 - 1
src/school/companion-teacher/compontent/teacher.tsx

@@ -90,7 +90,7 @@ export default defineComponent({
     return () => (
       <>
         <OSticky position="top">
-          <OHeader title="交接老师" />
+          <OHeader title="交接老师" desotry={false} />
           <OSearch
             placeholder="请输入老师姓名"
             inputBackground="white"

+ 32 - 33
src/student/music-group/layout/login.tsx

@@ -23,6 +23,7 @@ export default defineComponent({
       // countDownRef: null as any, // 倒计时实例
       imgCodeStatus: false,
       showPopup: false,
+      wxAppId: '', //
       code: '' // 授权code码
     }
   },
@@ -38,40 +39,36 @@ export default defineComponent({
     this.directNext()
 
     // 判断是否是微信,只能微信中打开
-    if (browser().weixin) {
-      // 微信公众号支付
-      //授权
-      const code = getUrlCode()
-      console.log('login mounted code: ' + code)
-      if (!code) {
-        this.getAppIdAndCode()
-      } else {
-        this.code = code
-      }
-    } else {
+    if (!browser().weixin) {
       this.showPopup = true
     }
+    // if (browser().weixin) {
+    // 微信公众号支付
+    //授权
+    // const code = getUrlCode()
+    // console.log('login mounted code: ' + code)
+    // if (!code) {
+    //   this.getAppIdAndCode()
+    // } else {
+    //   this.code = code
+    // }
+    // this.getAppIdAndCode()
+    // } else {
+    //   this.showPopup = true
+    // }
   },
   methods: {
-    async getAppIdAndCode() {
-      try {
-        const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
-        // 判断是否有微信appId
-        if (data) {
-          this.goAuth(data)
-        }
-      } catch {
-        //
-      }
-    },
-    goAuth(wxAppId: string) {
-      // 用户授权
-      const urlNow = encodeURIComponent(window.location.href)
-      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
-      const appid = wxAppId || 'wx8654c671631cfade'
-      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
-      window.location.replace(url)
-    },
+    // async getAppIdAndCode() {
+    //   try {
+    //     const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
+    //     // 判断是否有微信appId
+    //     if (data) {
+    //       this.wxAppId = data
+    //     }
+    //   } catch {
+    //     //
+    //   }
+    // },
     directNext() {
       if (state.user.status === 'login' || state.user.status === 'error') {
         const { returnUrl, isRegister, ...rest } = this.$route.query
@@ -82,6 +79,8 @@ export default defineComponent({
           },
           'jump pre registration'
         )
+
+        // this.goAuth(data)
         // console.log(returnUrl, isRegister, { ...rest })
         // this.$router.replace({
         //   path: returnUrl as any,
@@ -97,15 +96,15 @@ export default defineComponent({
           returnUrl +
           '?' +
           qs.stringify({
-            ...rest,
-            code: this.code
+            ...rest
+            // wxAppId: this.wxAppId
           })
         this.locationReplace(newUrl)
       }
     },
     locationReplace(url: any) {
       // 只允许同域名
-      console.log(history.replaceState, 'window.history.replaceState')
+      console.log(history.replaceState, 'window.history.replaceState', url)
       if (history.replaceState) {
         history.replaceState(null, document.title, url)
         history.go(0)

+ 19 - 15
src/student/music-group/pre-apply/component/apply.tsx

@@ -33,6 +33,10 @@ export default defineComponent({
     registerInfo: {
       type: Object,
       defualt: {}
+    },
+    code: {
+      type: String,
+      default: ''
     }
   },
   emits: ['next'],
@@ -40,7 +44,7 @@ export default defineComponent({
     const route = useRoute()
     const router = useRouter()
     const state = reactive({
-      code: '' as any, // 微信授权code码
+      // code: '' as any, // 微信授权code码
       detail: {} as any, // 学生详情
       currentGrade: [
         { text: '一年级', value: 1 },
@@ -157,7 +161,7 @@ export default defineComponent({
         await request.post('/api-student/orchestraRegister/save', {
           data: {
             ...params,
-            code: state.code
+            code: props.code
           }
         })
         setTimeout(() => {
@@ -170,8 +174,8 @@ export default defineComponent({
     }
 
     onMounted(async () => {
-      state.code = route.query.code || ''
-      console.log('pre register code: ' + state.code)
+      // state.code = route.query.code || ''
+      // console.log('pre register code: ' + state.code)
       await getSubjects()
       // 判断学年制
       if (props.schoolSystem === 'sixYearSystem') {
@@ -180,17 +184,17 @@ export default defineComponent({
       await studentRegister()
 
       // 判断是否有授权码
-      if (!state.code) {
-        setLogout()
-        const query = {
-          returnUrl: route.path,
-          ...route.query
-        } as any
-        router.replace({
-          path: '/loginMusic',
-          query: query
-        })
-      }
+      // if (!props.code) {
+      //   setLogout()
+      //   const query = {
+      //     returnUrl: route.path,
+      //     ...route.query
+      //   } as any
+      //   router.replace({
+      //     path: '/loginMusic',
+      //     query: query
+      //   })
+      // }
     })
     return () => (
       <>

+ 38 - 23
src/student/music-group/pre-apply/index.tsx

@@ -22,9 +22,9 @@ export default defineComponent({
       heightV: 235,
       registerInfo: {} as any,
       purchase: false, // 购买状态
-      register: true // 是否注册
+      register: true, // 是否注册
       // showPopup: false,
-      // code: '' as any
+      code: '' as any
     })
 
     const onNext = async (name: string) => {
@@ -87,6 +87,7 @@ export default defineComponent({
           return
         }
 
+        // 判断乐团
         if (data.registerOrchestra >= 1) {
           showDialog({
             title: '提示',
@@ -104,6 +105,20 @@ export default defineComponent({
           })
           return
         }
+
+        // 判断是否有openId 并且 purchase
+        if (!data.openId && !data.purchase) {
+          if (browser().weixin) {
+            // 微信公众号支付
+            //授权
+            const code = getUrlCode()
+            if (!code || !state.code) {
+              goAuth(data.wxAppId)
+            } else {
+              state.code = code
+            }
+          }
+        }
       } catch {
         //
       }
@@ -123,25 +138,26 @@ export default defineComponent({
       }
     }
 
-    // const getAppIdAndCode = async () => {
-    //   try {
-    //     const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
-    //     // 判断是否有微信appId
-    //     if (data) {
-    //       goAuth(data)
-    //     }
-    //   } catch {
-    //     //
-    //   }
-    // }
-    // const goAuth = (wxAppId: string) => {
-    //   // 用户授权
-    //   const urlNow = encodeURIComponent(window.location.href)
-    //   const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
-    //   const appid = wxAppId || 'wx8654c671631cfade'
-    //   const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
-    //   window.location.replace(url)
-    // }
+    const goAuth = (wxAppId: string) => {
+      // 用户授权
+      const urlNow = encodeURIComponent(window.location.href)
+      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+      const appid = wxAppId || 'wx8654c671631cfade'
+      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+      window.location.replace(url)
+    }
+
+    const getAppIdAndCode = async () => {
+      try {
+        const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
+        // 判断是否有微信appId
+        if (data) {
+          goAuth(data)
+        }
+      } catch {
+        //
+      }
+    }
 
     // 先请求接口
     getRegisterStatus()
@@ -160,8 +176,6 @@ export default defineComponent({
       //   } else {
       //     state.code = code
       //   }
-      // } else {
-      //   state.showPopup = true
       // }
     })
     return () => (
@@ -188,6 +202,7 @@ export default defineComponent({
         {state.tabValue === 'apply' && (
           <Apply
             onNext={onNext}
+            code={state.code}
             registerInfo={state.registerInfo}
             schoolSystem={state.registerInfo.schoolSystem}
           />

+ 27 - 5
src/student/music-group/pre-apply/order-detail.tsx

@@ -13,6 +13,7 @@ import { browser, moneyFormat } from '@/helpers/utils'
 import OProtocol from '@/components/o-protocol'
 import OPopup from '@/components/o-popup'
 import UserAuth from './component/user-auth'
+import qs from 'query-string'
 
 export default defineComponent({
   name: 'order-detail',
@@ -106,17 +107,27 @@ export default defineComponent({
       const config: any = state.config
       state.pay_channel = val.pay_channel
       if (val.payCode === 'payResult') {
-        router.push({
-          path: '/payResult',
-          query: {
+        // router.push({
+        //   path: '/payResult',
+        //   query: {
+        //     pay_channel: val.pay_channel,
+        //     wxAppId: config.wxAppId,
+        //     body: config.body,
+        //     price: config.price,
+        //     orderNo: config.merOrderNo,
+        //     userId: config.userId
+        //   }
+        // })
+        window.location.href = window.location.origin
+        '/orchestra-student/#/payResult?' +
+          qs.stringify({
             pay_channel: val.pay_channel,
             wxAppId: config.wxAppId,
             body: config.body,
             price: config.price,
             orderNo: config.merOrderNo,
             userId: config.userId
-          }
-        })
+          })
       } else {
         state.qrCodeUrl =
           window.location.origin +
@@ -176,6 +187,17 @@ export default defineComponent({
       }, 5000)
     }
 
+    // const locationReplace = (url: any) => {
+    //   // 只允许同域名
+    //   console.log(history.replaceState, 'window.history.replaceState', url)
+    //   if (history.replaceState) {
+    //     history.replaceState(null, document.title, url)
+    //     history.go(0)
+    //   } else {
+    //     location.replace(url)
+    //   }
+    // }
+
     const beforeSubmit = () => {
       const pt = state.pay_channel
       let payCode = 'qrCode'