Browse Source

Merge branch 'colexiu-payment'

lex 1 year ago
parent
commit
0db965f091

+ 5 - 1
src/student/live-class/live-detail.tsx

@@ -233,7 +233,11 @@ export default defineComponent({
               orderStatus.orderObject.orderNo = result.orderNo
               orderStatus.orderObject.actualPrice = result.actualPrice
               orderStatus.orderObject.discountPrice = result.discountPrice
-              orderStatus.orderObject.paymentConfig = result.paymentConfig
+              orderStatus.orderObject.paymentConfig = {
+                ...result.paymentConfig,
+                paymentVendor: result.paymentVendor,
+                paymentVersion: result.paymentVersion
+              }
               this.routerTo()
             })
             .catch(() => {

+ 8 - 2
src/student/trade/tradeOrder.ts

@@ -247,7 +247,9 @@ export const tradeOrder = (result: any, callBack?: any) => {
     orderDetailList,
     couponAmount, // 优惠金额
     discountPrice,
-    paymentConfig
+    paymentConfig,
+    paymentVendor,
+    paymentVersion
   } = result
   orderStatus.orderObject.orderType = orderType
   orderStatus.orderObject.orderName = orderName
@@ -255,7 +257,11 @@ export const tradeOrder = (result: any, callBack?: any) => {
   orderStatus.orderObject.actualPrice = actualPrice
   orderStatus.orderObject.orderNo = orderNo
   orderStatus.orderObject.discountPrice = discountPrice
-  orderStatus.orderObject.paymentConfig = paymentConfig
+  orderStatus.orderObject.paymentConfig = {
+    ...paymentConfig,
+    paymentVendor,
+    paymentVersion
+  }
   orderStatus.orderObject.orderList = []
   try {
     orderDetailList.forEach(async (item: any) => {

+ 5 - 1
src/tenant/music/train-tool/index.tsx

@@ -248,7 +248,11 @@ export default defineComponent({
             orderStatus.orderObject.orderNo = result.orderNo
             orderStatus.orderObject.actualPrice = result.actualPrice
             orderStatus.orderObject.discountPrice = result.discountPrice
-            orderStatus.orderObject.paymentConfig = result.paymentConfig
+            orderStatus.orderObject.paymentConfig = {
+              ...result.paymentConfig,
+              paymentVendor: result.paymentVendor,
+              paymentVersion: result.paymentVersion
+            }
             routerTo()
           })
           .catch(() => {

+ 8 - 2
src/tenant/trade/tradeOrder.ts

@@ -276,7 +276,9 @@ export const tradeOrder = (result: any, callBack?: any) => {
     orderDetailList,
     couponAmount, // 优惠金额
     discountPrice,
-    paymentConfig // v2 类型的订单才会用
+    paymentConfig, // v2 类型的订单才会用
+    paymentVendor,
+    paymentVersion
   } = result
   orderStatus.orderObject.orderType = orderType
   orderStatus.orderObject.orderName = orderName
@@ -285,7 +287,11 @@ export const tradeOrder = (result: any, callBack?: any) => {
   orderStatus.orderObject.orderNo = orderNo
   orderStatus.orderObject.discountPrice = discountPrice
   orderStatus.orderObject.orderList = []
-  orderStatus.orderObject.paymentConfig = paymentConfig
+  orderStatus.orderObject.paymentConfig = {
+    ...paymentConfig,
+    paymentVendor,
+    paymentVersion
+  }
   try {
     orderDetailList.forEach(async (item: any) => {
       await formatOrderDetail(item, {

+ 222 - 72
src/views/adapay/payment/index.tsx

@@ -1,5 +1,14 @@
-import { Button, Cell, CellGroup, Icon, RadioGroup, Radio, Dialog } from 'vant'
-import { defineComponent, reactive } from 'vue'
+import {
+  Button,
+  Cell,
+  CellGroup,
+  Icon,
+  RadioGroup,
+  Radio,
+  Dialog,
+  Toast
+} from 'vant'
+import { computed, defineComponent, reactive } from 'vue'
 import styles from './index.module.less'
 import { browser, moneyFormat } from '@/helpers/utils'
 import { useEventTracking } from '@/helpers/hooks'
@@ -11,6 +20,11 @@ import inactiveButtonIcon from '@common/images/icon_checkbox_default.png'
 import activeButtonIconTenant from '@common/images/icon_checkbox-tenant.png'
 import iconWechat from '@common/images/icon-wechat.png'
 import iconAlipay from '@common/images/icon-alipay.png'
+import {
+  listenerMessage,
+  postMessage,
+  removeListenerMessage
+} from '@/helpers/native-message'
 
 const urlFix =
   baseState.platformType === 'TEACHER' ? '/api-teacher' : '/api-student'
@@ -23,7 +37,15 @@ export default defineComponent({
     },
     paymentConfig: {
       type: Object,
-      default: {}
+      default: () => ({})
+    },
+    paymentVendor: {
+      type: String,
+      default: ''
+    },
+    paymentChannels: {
+      type: Array,
+      default: () => []
     }
   },
   emits: ['backOut', 'close', 'confirm', 'update:modelValue'],
@@ -52,6 +74,35 @@ export default defineComponent({
         })
     }
 
+    const isWxPay = computed(() => {
+      if (
+        props.paymentVendor === 'yeepay' ||
+        props.paymentVendor === 'adapay'
+      ) {
+        return true
+      }
+
+      const channelStr = props.paymentChannels?.join(',')
+      if (channelStr && channelStr.indexOf('wxpay') !== -1) {
+        return true
+      }
+      return false
+    })
+
+    const isAliPay = computed(() => {
+      if (
+        props.paymentVendor === 'yeepay' ||
+        props.paymentVendor === 'adapay'
+      ) {
+        return true
+      }
+      const channelStr = props.paymentChannels?.join(',')
+      if (channelStr && channelStr.indexOf('alipay') !== -1) {
+        return true
+      }
+      return false
+    })
+
     // 需要关闭订单
     //    orderPay: {
     //   cancelUrl: urlFix + '/userOrder/orderCancel',
@@ -69,16 +120,111 @@ export default defineComponent({
       }
       // 不管接口是否报错,都返回
       emit('update:modelValue', false)
-      // 为了单独处理支付 曲目购买  && orderStatus.orderObject.orderType == 'MUSIC'
-      // if (!noBack) {
-      //   postMessage({ api: 'back', content: {} })
-      //   return
-      // }
 
       !noBack && router.go(-1)
       emit('backOut')
     }
     const onSubmit = async () => {
+      if (
+        props.paymentVendor &&
+        (props.paymentVendor.indexOf('wxpay') > -1 ||
+          props.paymentVendor.indexOf('alipay') > -1)
+      ) {
+        submitNativePay()
+      } else {
+        submitQrCodePay()
+      }
+    }
+
+    // 支付方式,使用原生支付
+    const submitNativePay = async () => {
+      // 支付...
+      try {
+        const payChannel = state.payType === 'zfb' ? 'ali_app' : 'wx_app'
+        console.log(props.paymentConfig, 'paymentConfig')
+        let paymentType = props.paymentVendor
+        props.paymentChannels.forEach((item: any) => {
+          if (state.payType === 'zfb' && item.indexOf('alipay') !== -1) {
+            paymentType = item
+          }
+          if (state.payType === 'wx' && item.indexOf('wxpay') !== -1) {
+            paymentType = item
+          }
+        })
+        const params = {
+          // orderNo: props.paymentConfig.orderNo,
+          merOrderNo: props.paymentConfig.orderNo,
+          paymentChannel: payChannel,
+          paymentVendor: paymentType
+        }
+        const res = await request.post(
+          urlFix + '/userOrder/executePayment/v2',
+          {
+            data: {
+              ...params
+            }
+          }
+        )
+
+        postMessage({
+          api: 'paymentOrder',
+          content: {
+            orderNo: props.paymentConfig.orderNo,
+            payChannel,
+            // payInfo: `alipays://platformapi/startapp?saId=10000007&qrcode=${res.data.pay_info}`
+            payInfo:
+              res.data.reqParams.body || JSON.stringify(res.data.reqParams)
+          }
+        })
+        Toast.loading({
+          message: '支付中...',
+          forbidClick: true,
+          duration: 3000,
+          loadingType: 'spinner'
+        })
+        Toast.clear()
+        emit('update:modelValue', false)
+        // 唤起支付时状态
+        listenerMessage('paymentOperation', result => {
+          console.log(result, 'init paymentOperation')
+          paymentOperation(result?.content)
+        })
+      } catch (e: any) {
+        console.log(e)
+      }
+    }
+
+    const paymentOperation = (res: any) => {
+      console.log(res, 'paymentOperation')
+      // 支付状态
+      // paymentOperation  支付成功:success 支付失败:error 支付取消:cancel 未安装:fail
+      // error 只有安卓端有
+      if (res.status === 'success' || res.status === 'error') {
+        Toast.clear()
+        emit('update:modelValue', false)
+        router.replace({
+          path: '/tradeDetail',
+          query: {
+            orderNo: props.paymentConfig.orderNo
+          }
+        })
+      } else if (res.status === 'cancel') {
+        Toast.clear()
+        emit('update:modelValue', false)
+      } else if (res.status === 'fail') {
+        const message =
+          state.payType === 'zfb' ? '您尚未安装支付宝' : '您尚未安装微信'
+        Dialog.alert({
+          title: '提示',
+          message
+        }).then(() => {
+          Toast.clear()
+          emit('update:modelValue', false)
+        })
+      }
+    }
+    // 支付方式,汇付,易宝支付
+    const submitQrCodePay = () => {
       // 支付...
       const pt = state.payType
       // 判断当前浏览器
@@ -133,70 +279,74 @@ export default defineComponent({
         </div>
         <RadioGroup v-model={state.payType}>
           <CellGroup border={false}>
-            <Cell
-              border={true}
-              center
-              onClick={() => {
-                state.payType = 'wx'
-              }}
-              v-slots={{
-                icon: () => <Icon name={iconWechat} size={18} />,
-                'right-icon': () => (
-                  <Radio
-                    name="wx"
-                    v-slots={{
-                      icon: (props: any) => (
-                        <Icon
-                          class={styles.boxStyle}
-                          name={
-                            props.checked
-                              ? baseState.projectType === 'tenant'
-                                ? activeButtonIconTenant
-                                : activeButtonIcon
-                              : inactiveButtonIcon
-                          }
-                        />
-                      )
-                    }}
-                  />
-                ),
-                title: () => (
-                  <div class={styles.payTypeRe}>
-                    微信支付 <span class={styles.recommend}>推荐</span>
-                  </div>
-                )
-              }}
-            ></Cell>
-            <Cell
-              title="支付宝支付"
-              border={true}
-              center
-              onClick={() => {
-                state.payType = 'zfb'
-              }}
-              v-slots={{
-                icon: () => <Icon name={iconAlipay} size={18} />,
-                'right-icon': () => (
-                  <Radio
-                    name="zfb"
-                    v-slots={{
-                      icon: (props: any) => (
-                        <Icon
-                          class={styles.boxStyle}
-                          name={
-                            props.checked
-                              ? baseState.projectType === 'tenant'
-                                ? activeButtonIconTenant
-                                : activeButtonIcon
-                              : inactiveButtonIcon
-                          }
-                        />
-                      )
-                    }}
-                  />
-                )
-              }}
-            ></Cell>
+            {isWxPay.value && (
+              <Cell
+                border={true}
+                center
+                onClick={() => {
+                  state.payType = 'wx'
+                }}
+                v-slots={{
+                  icon: () => <Icon name={iconWechat} size={18} />,
+                  'right-icon': () => (
+                    <Radio
+                      name="wx"
+                      v-slots={{
+                        icon: (props: any) => (
+                          <Icon
+                            class={styles.boxStyle}
+                            name={
+                              props.checked
+                                ? baseState.projectType === 'tenant'
+                                  ? activeButtonIconTenant
+                                  : activeButtonIcon
+                                : inactiveButtonIcon
+                            }
+                          />
+                        )
+                      }}
+                    />
+                  ),
+                  title: () => (
+                    <div class={styles.payTypeRe}>
+                      微信支付 <span class={styles.recommend}>推荐</span>
+                    </div>
+                  )
+                }}
+              ></Cell>
+            )}
+            {isAliPay.value && (
+              <Cell
+                title="支付宝支付"
+                border={true}
+                center
+                onClick={() => {
+                  state.payType = 'zfb'
+                }}
+                v-slots={{
+                  icon: () => <Icon name={iconAlipay} size={18} />,
+                  'right-icon': () => (
+                    <Radio
+                      name="zfb"
+                      v-slots={{
+                        icon: (props: any) => (
+                          <Icon
+                            class={styles.boxStyle}
+                            name={
+                              props.checked
+                                ? baseState.projectType === 'tenant'
+                                  ? activeButtonIconTenant
+                                  : activeButtonIcon
+                                : inactiveButtonIcon
+                            }
+                          />
+                        )
+                      }}
+                    />
+                  )
+                }}
+              ></Cell>
+            )}
           </CellGroup>
         </RadioGroup>
 

+ 5 - 1
src/views/music/album-detail/index.tsx

@@ -181,7 +181,11 @@ export default defineComponent({
             orderStatus.orderObject.orderNo = result.orderNo
             orderStatus.orderObject.actualPrice = result.actualPrice
             orderStatus.orderObject.discountPrice = result.discountPrice
-            orderStatus.orderObject.paymentConfig = result.paymentConfig
+            orderStatus.orderObject.paymentConfig = {
+              ...result.paymentConfig,
+              paymentVendor: result.paymentVendor,
+              paymentVersion: result.paymentVersion
+            }
             routerTo()
           })
           .catch(() => {

+ 5 - 1
src/views/music/music-detail/index.tsx

@@ -432,7 +432,11 @@ export default defineComponent({
             orderStatus.orderObject.orderNo = result.orderNo
             orderStatus.orderObject.actualPrice = result.actualPrice
             orderStatus.orderObject.discountPrice = result.discountPrice
-            orderStatus.orderObject.paymentConfig = result.paymentConfig
+            orderStatus.orderObject.paymentConfig = {
+              ...result.paymentConfig,
+              paymentVendor: result.paymentVendor,
+              paymentVersion: result.paymentVersion
+            }
             routerTo()
           })
           .catch(() => {

+ 24 - 8
src/views/order-detail/index.tsx

@@ -1,5 +1,5 @@
 import ColProtocol from '@/components/col-protocol'
-import { Button, Dialog, Icon, Popup, Sticky, Toast } from 'vant'
+import { Button, Dialog, Popup, Toast } from 'vant'
 import ColPopup from '@/components/col-popup'
 import { defineComponent } from 'vue'
 import { postMessage } from '@/helpers/native-message'
@@ -14,7 +14,7 @@ import qs from 'query-string'
 //   status: 'success | fail'
 // }})
 
-import iconTips from '@common/images/icon_tips.png'
+// import iconTips from '@common/images/icon_tips.png'
 import Payment from './payment'
 import UrlPayment from '../adapay/payment'
 import ColHeader from '@/components/col-header'
@@ -31,7 +31,7 @@ import OrderLive from './order-live'
 import OrderPractice from './order-practice'
 import OrderVip from './order-vip'
 import OrderMusic from './order-music'
-import { browser, moneyFormat } from '@/helpers/utils'
+import { moneyFormat } from '@/helpers/utils'
 import OrderPinao from './order-pinao'
 import { getMusicDetail } from '@/student/trade/tradeOrder'
 import OrderActive from './order-active'
@@ -61,6 +61,7 @@ export default defineComponent({
       bottomHeight: 0,
       paymentVendor: '', //支付厂商
       paymentVersion: 'V1', // 支付版本,可用值:V1 老版,V2 新版
+      paymentChannels: [] as any, // 可以选择的支付类型
       showQrcode: false,
       orderTimer: null as any,
       qrCodeUrl: '',
@@ -118,7 +119,18 @@ export default defineComponent({
         //
       }
     }
-    await this.getOrderPayType()
+    // 判断是否已经有支付方式了
+    const paymentConfig = orderStatus.orderObject.paymentConfig || {}
+    if (
+      paymentConfig.paymentVendor &&
+      paymentConfig.paymentVersion &&
+      orderStatus.orderObject.orderNo
+    ) {
+      this.paymentVersion = orderStatus.orderObject.paymentVendor || 'V1'
+      this.paymentVendor = orderStatus.orderObject.paymentVersion
+    } else {
+      await this.getOrderPayType()
+    }
     this.orderAmount = orderStatus.orderObject.actualPrice || 0
     this.orderPrice = orderStatus.orderObject.actualPrice || 0
     this.dataLoading = false
@@ -156,7 +168,7 @@ export default defineComponent({
     async getOrderPayType() {
       try {
         const orderObject = orderStatus.orderObject
-        console.log(orderObject)
+        // 单独处理其它支付类型下面用的bizId
         let bizId =
           orderObject.orderList.length > 0 ? orderObject.orderList[0].id : ''
         if (orderObject.orderType === 'PRACTICE') {
@@ -188,6 +200,7 @@ export default defineComponent({
         )
         this.paymentVersion = data.paymentVersion || 'V1'
         this.paymentVendor = data.paymentVendor
+        this.paymentChannels = data.paymentChannels // 可以选择的支付类型
       } catch {
         //
       }
@@ -212,7 +225,6 @@ export default defineComponent({
         }
       }
 
-      console.log(orderStatus.orderObject, 'orderInfo')
       // 判断是否有订单号
       if (orderStatus.orderObject.orderNo) {
         if (this.paymentVersion === 'V1') {
@@ -279,9 +291,7 @@ export default defineComponent({
           const res = await request.post(url, {
             data: {
               activityId: orderObject.activityId || null,
-              // bizId: '',
               couponIds: orderObject.couponId,
-              // currentPrice: 0,
               goodsInfos: [...orderTenantInfos()],
               orderDesc: orderObject.orderDesc,
               orderName: orderObject.orderName,
@@ -512,11 +522,17 @@ export default defineComponent({
               onBackOut={this.onBackOut}
             />
           ) : (
+            //      this.paymentVersion = data.paymentVersion || 'V1'
+            // this.paymentVendor = data.paymentVendor
+            // this.paymentChannels = data.paymentChannels // 可以选择的支付类型
             <UrlPayment
               paymentConfig={{
                 ...orderStatus.orderObject,
                 orderNo: this.orderNo
               }}
+              // paymentVersion={this.paymentVersion}
+              paymentVendor={this.paymentVendor}
+              paymentChannels={this.paymentChannels}
               onClose={() => (this.paymentStatus = false)}
               onBackOut={this.onBackOut}
               onConfirm={(val: any) => this.onConfirm(val)}

+ 1 - 1
vite.config.ts

@@ -12,7 +12,7 @@ function resolve(dir: string) {
 // https://vitejs.dev/config/
 // https://github.com/vitejs/vite/issues/1930 .env
 // const proxyUrl = 'https://online.colexiu.com/';
-const proxyUrl = 'https://dev.colexiu.com/'
+const proxyUrl = 'https://test.colexiu.com/'
 // const proxyUrl = 'http://192.168.3.143:8000/'
 export default defineConfig({
   base: './',