Browse Source

充值功能接口对接

lifanagju_citu 9 tháng trước cách đây
mục cha
commit
1cf6957eea

+ 2 - 2
src/api/common/index.js

@@ -285,7 +285,7 @@ export const getUnpaidOrder = async (params) => {
 export const payOrderSubmit = async (data) => {
   return await request.post({
     // url: '/app-api/menduner/system/recruit/pay/order/submit',
-    url: '/app-admin-api/pay/order/submit',
+    url: '/app-api/pay/order/submit',
     data
   })
 }
@@ -293,7 +293,7 @@ export const payOrderSubmit = async (data) => {
 // 获得支付订单
 export const getOrderPayStatus = async (params) => {
   return await request.get({
-    url: '/app-admin-api/pay/order/get',
+    url: '/app-api/pay/order/get',
     params
   })
 }

+ 16 - 0
src/api/recruit/enterprise/member/points/index.js

@@ -14,4 +14,20 @@ export const getEnterpriseTradeOrderPage = async (params) => {
     url: '/app-api/menduner/system/recruit/trade/order/page',
     params
   })
+}
+
+// 获得货币账户充值套餐列表
+export const getEnterpriseRechargePackageList = async (params) => {
+  return await request.get({
+    url: '/app-api/pay/currency-recharge-package/list',
+    params
+  })
+}
+
+// 创建货币账户充值记录(发起充值)
+export const rechargeOrderCreate = async (data) => {
+  return await request.post({
+    url: '/app-api/pay/currency-recharge/create',
+    data
+  })
 }

+ 2 - 2
src/components/pay/confirmPaymentDialog.vue

@@ -8,13 +8,13 @@
       title="确认支付"
       :footer="false"
       submitText="确认"
-      @paySuccess="paySuccess"
       @close="handleClose"
     >
       <pay
         ref="payRef"
         v-bind="$attrs"
         @payTypeChange="null"
+        @paySuccess="paySuccess"
       ></pay>
     </CtDialog>
   </div>
@@ -37,8 +37,8 @@ const handleClose = () => {
   emit('close')
 }
 const paySuccess = () => {
-  payDialog.value = false
   emit('paySuccess')
+  payDialog.value = false
 }
 </script>
 <style lang="scss" scoped>

+ 57 - 32
src/components/pay/index.vue

@@ -64,6 +64,8 @@ import { definePayTypeList, qrCodePay, walletPay } from './until/payType'
 import { getEnableCodeList, getUnpaidOrder, payOrderSubmit, getOrderPayStatus } from '@/api/common'
 import { createTradeOrder } from '@/api/position'
 import { useSharedState } from '@/store/sharedState'
+import { rechargeOrderCreate } from '@/api/recruit/enterprise/member/points'
+
 const emit = defineEmits(['payTypeChange', 'paySuccess'])
 const props = defineProps({
   params: {
@@ -86,7 +88,15 @@ const props = defineProps({
     type: String,
     default: ''
   },
-  type: {
+  rechargeInfo: {
+    type: Object,
+    default: () => {}
+  },
+  appId: {
+    type: Number,
+    default: 10 // 10为一般情况下支付,11为充值支付
+  },
+  orderType: {
     type: Number,
     default: 2 // 订单类型 0平台订单| 1发布职位订单| 2发布众聘职位订单,示例值(1)
   },
@@ -96,8 +106,8 @@ const loading = ref(true)
 const tip = ref('')
 
 // 步骤:
-//      1. 获取支付方式类型列表getCodeList
-//      2. 创建支付订单(先获取有无创建的,没有就创建)getUnpaidOrderList
+//      1. 获取支付方式类型列表getCodeList (appId不同时数据返回有区别)
+//      2. 创建支付订单(先获取有无创建的,没有就创建)getUnpaidOrderList (appId=11时只有创建,没有获取)
 //      3. 如果是二维码类型支付(isQrCodePay=true)生成二维码(需要绑定支付订单的订单号)
 
 
@@ -113,19 +123,27 @@ onUnmounted(() => {
   if (timer.value) clearInterval(timer.value); timer.value = null
 })
 const initPayQrCode = async () => { // 生成二维码内容
-  if (!payOrder.value?.id || !payOrder.value.notifyUrl || !payType.value) return
-  if (timer.value) clearInterval(timer.value); timer.value = null
+  if (!payType.value) return
   try {
     if (payOrder.value) {
       // 提交支付订单
       const params = {
-        id: payOrder.value.id, // 支付单编号
         channelCode: payType.value, // 支付渠道
-        displayMode: payOrder.value.notifyUrl, // 展示模式 notifyUrl
-        // returnUrl: location.href, // 支付成功后,支付渠道跳转回当前页;再由当前页,跳转回 {@link returnUrl} 对应的地址
+        // returnUrl: , // 支付成功后,支付渠道跳转回当前页;再由当前页,跳转回 {@link returnUrl} 对应的地址
+      }
+      if ((props.appId - 0) === 10) { // 众聘
+        if (!payOrder.value?.id || !payOrder.value.notifyUrl) return
+        params.id = payOrder.value.id // 支付单编号
+        params.displayMode = payOrder.value.notifyUrl // 展示模式 notifyUrl
+      }
+      if ((props.appId - 0) === 11) { // 充值
+        if (!payOrder.value?.payOrderId) return
+        params.id = payOrder.value.payOrderId // 支付单编号
       }
       const res = await payOrderSubmit(params)
       payQrCodeTxt.value = res?.displayContent || '' // 支付二维码
+
+      if (timer.value) clearInterval(timer.value); timer.value = null
       timer.value = setInterval(() => { payStatus() }, 1000) // 轮巡查询用户是否支付
     }
   } catch (error) {
@@ -138,23 +156,34 @@ const payOrder = ref({})
 let maxCount = 0
 const getUnpaidOrderList = async () => {
   try {
-    const data = await getUnpaidOrder({ spuId: props.spuId, type: props.type }) // 获取待支付的订单 (order:业务订单; payOrder:支付订单)
-    if (!data) {
-      // 订单超时,重新提交订单
-      await createTradeOrder({
-        spuId: props.spuId,
-        spuName: props.spuName,
-        price: props.cost,
-        type:  props.type, // 发布众聘职位订单
-      })
-      if (maxCount > 3) return // 避免死循环
-      maxCount++
-      setTimeout(() => {
-        getUnpaidOrderList()
-      }, 1000)
+    if ((props.appId - 0) === 11) {
+      // 充值
+      if (props.rechargeInfo.payPrice === undefined && props.rechargeInfo.packageId === undefined) return
+      const params = {
+        payPrice: props.rechargeInfo.payPrice,
+        packageId: props.rechargeInfo.id,
+      }
+      const data = await rechargeOrderCreate(params)
+      payOrder.value = data || {}
+    } else {
+      const data = await getUnpaidOrder({ spuId: props.spuId, type: props.orderType }) // 获取待支付的订单 (order:业务订单; payOrder:支付订单)
+      if (!data) {
+        // 订单超时,重新提交订单
+        await createTradeOrder({
+          spuId: props.spuId,
+          spuName: props.spuName,
+          price: props.cost,
+          type:  props.orderType, // 发布众聘职位订单
+        })
+        if (maxCount > 3) return // 避免死循环
+        maxCount++
+        setTimeout(() => {
+          getUnpaidOrderList()
+        }, 1000)
+      }
+      // 
+      payOrder.value = data?.payOrder || null
     }
-    // 
-    payOrder.value = data?.payOrder || null
     if (isQrCodePay.value) initPayQrCode() // 生成二维码内容
   } catch (error) {
     console.log(error)
@@ -162,7 +191,6 @@ const getUnpaidOrderList = async () => {
     loading.value = false
   }
 }
-// getUnpaidOrderList() // getUnpaidOrder
 
 
 // 支付方式
@@ -184,7 +212,7 @@ const codeList = ref(sharedState.payCodeList || [])
 const getCodeList = async () => {
   try {
     if (!codeList.value?.length) {
-      const list = await getEnableCodeList({appId: 10})
+      const list = await getEnableCodeList({appId: props.appId})
       codeList.value = list || []
       sharedState.setPayCodeList(codeList.value)
     } else {
@@ -224,13 +252,10 @@ import { useRoute } from 'vue-router'; const route = useRoute()
 import { useRouter } from 'vue-router'; const router = useRouter()
 const payStatus = async () => {
   // if (timer.value) clearInterval(timer.value); timer.value = null
-  // setTimeout(() => {
-  //   console.log('fullPath1', route.fullPath)
-  //   console.log('returnUrl2',props.returnUrl)
-  //   debugger
+  // setTimeout(() => { // 测试代码
   //   if (route.fullPath === props.returnUrl) router.go(0)
   //   else if (props.returnUrl) router.push(props.returnUrl) // 返回指定页面
-  //   else emit('paySuccess')
+  //   emit('paySuccess')
   //   Snackbar.success('付款成功')
   // }, 2000)
   try {
@@ -241,7 +266,7 @@ const payStatus = async () => {
       setTimeout(() => {
         if (route.fullPath === props.returnUrl) router.go(0)
         else if (props.returnUrl) router.push(props.returnUrl) // 返回指定页面
-        else emit('paySuccess')
+        emit('paySuccess')
         Snackbar.success('付款成功')
       }, 1000);
     }

+ 56 - 19
src/views/recruit/enterprise/memberCenter/myMembers/components/pointsAndBalance.vue

@@ -13,11 +13,11 @@
         @click="current = index + 1; price = item.price"
       >
         <div class="d-flex flex-column align-center pb-5" style="position: relative;">  
-          <div class="my-4 font-size-16 font-weight-bold titleColor">{{ item.title }}</div>  
+          <div class="my-4 font-size-16 font-weight-bold titleColor">{{ item.name }}</div>  
           <div class="font-weight-bold priceBox">
             <span v-if="item.custom">
               <input 
-                v-model="item.price" 
+                v-model="item.payPrice" 
                 type="text" 
                 class="custom-input-num" 
                 :style="{'color': current === (index + 1) ? '#ff4747' : '#000'}" 
@@ -25,12 +25,13 @@
                 @focus="item.tip = '输入完成后请按Enter键确认'"
               >
             </span>
-            <span class="font28" v-else>{{ item.price }}</span>
+            <span class="font28" v-else>{{ calcFun(item.payPrice, true) }}</span>
           </div>  
           <div class="dailyPrice font-size-12 mt-3">
-            <span v-if="!item.custom">¥{{ item.price }}</span>
+            <span v-if="!item.custom">¥{{ calcFun(item.payPrice, true) }}</span>
             <span v-else>{{ item.tip }}</span>
           </div>
+          <span class="mt-3" @click="handleRecharge(item)">立即充值</span>
           <div class="vip">
             <svg-icon v-if="current === (index+1)" name="diamond-active" size="50"></svg-icon>
             <svg-icon v-else name="diamond" size="50"></svg-icon>
@@ -38,7 +39,7 @@
         </div> 
       </div>
     </div>
-    <div class="code pa-5 resume-box">
+    <!-- <div class="code pa-5 resume-box">
       <div class="resume-header">
         <div class="resume-title">扫码支付</div>
       </div>
@@ -67,19 +68,29 @@
           </div>
         </div>
       </div>
-    </div>
+    </div> -->
   </div>
 
   <CtDialog :visible="show" :widthType="2" :footer="false" titleClass="text-h6" title="对公账户信息" @close="show = false">
     <Public v-if="show" :price="price"></Public>
   </CtDialog>
+  
+  <confirmPaymentDialog
+    v-if="showConfirmPaymentDialog"
+    :appId="11"
+    :cost="calcFun(rechargeDataItem.payPrice, true)"
+    :rechargeInfo="rechargeDataItem"
+    @paySuccess="paySuccess"
+    @close="showConfirmPaymentDialog = false"
+  ></confirmPaymentDialog>
 </template>
 
 <script setup>
 defineOptions({ name: 'myAccount-pointsAndBalance'})
 import { ref } from 'vue'
 import Public from './public.vue'
-import QrCode from '@/components/QrCode'
+// import QrCode from '@/components/QrCode'
+import { getEnterpriseRechargePackageList } from '@/api/recruit/enterprise/member/points'
 
 defineProps({
   showTitle: {
@@ -92,19 +103,13 @@ const show = ref(false)
 const current = ref(1)
 const price = ref(200)
 
-const list = ref([
-  { title: '200元', price: 200 },
-  { title: '800元', price: 800 },
-  { title: '1000元', price: 1000 },
-  { title: '1200元', price: 1200 },
-  { title: '自定义充值', price: 100, custom: true, tip: '输入完成后请按Enter键确认' }
-])
+const list = ref([])
 
-const payment = ref('wx_native')
-const paymentList = [
-  { label: '微信扫码', icon: 'weChat', size: 21, color: 'success', value: 'wx_native' },
-  { label: '支付宝扫码', icon: 'alipay', size: 23, color: '#3383c6', value: 'alipay_qr' }
-]
+// const payment = ref('wx_native')
+// const paymentList = [
+//   { label: '微信扫码', icon: 'weChat', size: 21, color: 'success', value: 'wx_native' },
+//   { label: '支付宝扫码', icon: 'alipay', size: 23, color: '#3383c6', value: 'alipay_qr' }
+// ]
 
 const handleCustomEnter = (e) => {
   const num = e.target.value
@@ -116,6 +121,38 @@ const handleCustomEnter = (e) => {
   }
   price.value = num
 }
+
+const getData = async () => {
+  // const params = {}
+  const data = await getEnterpriseRechargePackageList()
+  const end = { name: '自定义充值', payPrice: 100, custom: true, tip: '输入完成后请按Enter键确认' }
+  list.value = data ? [...data, end] : [end]
+}
+getData()
+
+// 支付弹窗
+const rechargeDataItem = ref(null)
+const showConfirmPaymentDialog = ref(false)
+const handleRecharge = (item) => {
+  // rechargeDataItem.value = { ...item, payPrice: calcFun(item.payPrice, show) }
+  rechargeDataItem.value = { ...item }
+  // 打开支付弹窗
+  showConfirmPaymentDialog.value = true
+}
+
+import { useUserStore } from '@/store/user'; const store = useUserStore()
+
+// 支付成功
+const paySuccess = async () => {
+  showConfirmPaymentDialog.value = false
+  await store.getEnterpriseUserAccountInfo()
+}
+
+const calcFun = (value, show) => { // show除以一百,提交乘以一百
+  const Magnification = show ? 1/100 : 100
+  return ((value - 0)*Magnification).toFixed(2)
+}
+
 </script>
 
 <style scoped lang="scss">

+ 1 - 1
src/views/recruit/enterprise/positionManagement/components/add.vue

@@ -121,7 +121,7 @@ const getPositionDetail = async (id) => {
 if (route.query && route.query.id) {
   if (route.query.id) getPositionDetail(route.query.id)
 }
-// getPositionDetail('1824338255638728705') // 测试使用
+// getPositionDetail('1824359989330862081') // 测试使用
 
 // 取消
 const handleCancel = (hire) => { //  hire:是否是众聘岗位

+ 1 - 1
src/views/recruit/enterprise/positionManagement/components/item.vue

@@ -73,7 +73,7 @@
     :cost="cost"
     :spuId="spuId"
     :spuName="spuName"
-    :type="2"
+    :orderType="2"
     returnUrl="/recruit/enterprise/position?hire=1"
     @close="showConfirmPaymentDialog = false"
   ></confirmPaymentDialog>