lex-xin 7 місяців тому
батько
коміт
0ace4d594f

+ 1 - 1
miniprogram/api/login.ts

@@ -60,7 +60,7 @@ export const api_userPaymentOrderUnpaid = (params: any) => {
 /** 获取配置参数 */
 export const api_queryByParamName = (params: any) => {
   return request({
-    url: `/edu-app/sysParamConfig/queryByParamName`,
+    url: `/edu-app/open/sysParamConfig/queryByParamName`,
     method: "get",
     data: params,
   } as any);

+ 2 - 1
miniprogram/app.json

@@ -6,7 +6,8 @@
     "pages/login/login",
     "pages/orders/order-detail",
     "pages/orders/order-result",
-    "pages/protocol/register"
+    "pages/protocol/register",
+    "pages/order-webview/order-webview"
   ],
   "window": {
     "navigationBarTextStyle": "black",

+ 89 - 13
miniprogram/pages/index/index.ts

@@ -1,6 +1,6 @@
 // index.ts
 
-import { api_shopProduct } from "../../api/login";
+import { api_executeOrder, api_queryByParamName, api_shopProduct } from "../../api/login";
 import { debounce } from '../../utils/util'
 
 // 获取应用实例
@@ -19,13 +19,16 @@ Page({
     list: [] as any,
     isOverSaled: false, // 是否所有商品都没有库存
     selected: {} as any,
+    isH5Pay: true, // 是否公众号支付
+    paymentType: null as any, // 支付类型
+    paymentChannel: null as any,
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad() {
-    this.onInit()
+    this.queryPayType()
   },
   /**
    * 获取基础信息
@@ -149,19 +152,92 @@ Page({
       if(!that.isLogin()) {
         return
       }
-      let info = JSON.stringify({
-        ...that.data.selected
-      });
-      console.log(that.data.selected, "that.data.selected")
-      info = encodeURIComponent(info);
-      wx.navigateTo({
-        url: `../orders/order-detail?orderInfo=${info}`,
-      })
-      that.setData({
-        popupShow: false
-      })
+      if(that.data.isH5Pay) {
+        that.onH5Play(that.data.selected)
+      } else {
+        let info = JSON.stringify({
+          ...that.data.selected
+        });
+        info = encodeURIComponent(info);
+        wx.navigateTo({
+          url: `../orders/order-detail?orderInfo=${info}`,
+        })
+        that.setData({
+          popupShow: false
+        })
+      }
     }, 500)()
   },
+  async onH5Play(goodsInfo: any) {
+    wx.showLoading({
+      mask: true,
+      title: "加载中...",
+    });
+    try {
+      // const { salePrice, shopId, name, id, orderNo } = goodsInfo
+      // const { data } = await api_executeOrder({
+      //   "orderType": "WECHAT_MINI",
+      //   "paymentType": this.data.paymentType,
+      //   "paymentCashAmount": salePrice,
+      //   "paymentCouponAmount": 0,
+      //   "shopId": shopId,
+      //   "openId": app.globalData.userInfo?.liteOpenid,
+      //   "goodsInfos": [{
+      //     "goodsId": id,
+      //     "goodsNum": 1,
+      //     "goodsType": "ACTIVATION_CODE",
+      //     "paymentCashAmount": salePrice,
+      //     "paymentCouponAmount": 0
+      //   }],
+      //   "orderName": name,
+      //   "orderDesc": name
+      // })
+      // if (data.code === 200) {
+        // const { paymentConfig, paymentType, orderNo } = data.data
+        // 测试h5页面支付流程
+        const params = {
+          // paymentType: paymentType, //'adapay-cooleshow-6560',
+          // pay_channel: 'wx_pub',
+          // wxAppId: paymentConfig.wxAppId, //'wxbde13f59d40cb4f2',
+          // body: paymentConfig.body, //'aaa',
+          // price: paymentConfig.price, // '0.01',
+          // orderNo: paymentConfig.merOrderNo,
+          // userId: paymentConfig.userId
+        }
+        wx.navigateTo({
+          url: '../order-webview/order-webview?orderInfo=' + encodeURIComponent(JSON.stringify(params))
+        })
+
+        wx.hideLoading()
+      // } else {
+      //   wx.hideLoading()
+      //   wx.showToast({
+      //     title: '购买失败',
+      //     icon: 'none'
+      //   })
+      // }
+    } catch {
+      wx.hideLoading()
+    }
+  },
+  // 获取后台配置的支付方式
+  async queryPayType() {
+    try {
+      // wxlite_payment_service_provider
+      const { data } = await api_queryByParamName({
+        paramName: 'wxlite_payment_service_provider'
+      });
+      if (data.code == 200) {
+        const paramValue = data.data.paramValue ? JSON.parse(data.data.paramValue) : {}
+        this.setData({
+          paymentType: paramValue.vendor,
+          paymentChannel: paramValue.channel
+        });
+      }
+    } catch (error) {
+      console.log(error, "error");
+    }
+  },     
   /**
    * 生命周期函数--监听页面显示
    */

+ 4 - 0
miniprogram/pages/order-webview/order-webview.json

@@ -0,0 +1,4 @@
+{
+  "navigationStyle": "default",
+  "navigationBarBackgroundColor": "#fff"
+}

+ 1 - 0
miniprogram/pages/order-webview/order-webview.less

@@ -0,0 +1 @@
+/* pages/order-webview/order-webview.wxss */

+ 79 - 0
miniprogram/pages/order-webview/order-webview.ts

@@ -0,0 +1,79 @@
+// pages/protocol/register.ts
+// 获取应用实例
+const app = getApp<IAppOption>()
+Page({
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    src: ''
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options: any) {
+    if(options.orderInfo) {
+      const orderInfo = JSON.parse(decodeURIComponent(options.orderInfo));
+      const url = app.globalData.baseUrl + `/classroom-app/#/payResultWechat?paymentType=${orderInfo.paymentType}&pay_channel=${orderInfo.pay_channel}&wxAppId=${orderInfo.wxAppId}&body=${orderInfo.body}&price=${orderInfo.price}&orderNo=${orderInfo.orderNo}&userId=${orderInfo.userId}`
+      this.setData({
+        src: url
+      })
+    }
+  },
+  onBackPress: function () {
+    // 在这里添加你想要执行的自定义逻辑,比如进行数据保存、提示用户等操作
+    console.log('用户点击了返回按钮');
+
+    // 如果返回 true,则继续执行默认的返回上一页面操作;如果返回 false,则阻止默认返回行为
+    return true;
+  },
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload() {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh() {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage() {
+
+  }
+})

+ 3 - 0
miniprogram/pages/order-webview/order-webview.wxml

@@ -0,0 +1,3 @@
+<view class="container">
+    <web-view src="{{ src }}"></web-view>
+</view>

+ 0 - 14
miniprogram/pages/orders/order-detail.ts

@@ -100,20 +100,6 @@ Page({
         if (data.code === 200) {
           const { paymentConfig, paymentType, orderNo } = data.data
           this.onExecutePay(paymentConfig, paymentType, orderNo)
-          
-          // 测试h5页面支付流程
-          // const params = {
-          //   paymentType: 'adapay-cooleshow-6560',
-          //   pay_channel: 'wx_pub',
-          //   wxAppId: 'wxbde13f59d40cb4f2',
-          //   body: 'aaa',
-          //   price: '0.01',
-          //   orderNo,
-          //   userId: app.globalData.userInfo?.id
-          // }
-          // wx.navigateTo({
-          //   url: '../protocol/register?orderInfo=' + encodeURIComponent(JSON.stringify(params))
-          // })
         } else {
           this.onPayError()
         }

+ 0 - 12
miniprogram/pages/protocol/register.ts

@@ -8,12 +8,10 @@ Page({
   data: {
     src: app.globalData.baseUrl + '/classroom-app/#/preview-protocol'
   },
-
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options: any) {
-    // console.log(options)
     if(options.type) {
       if(options.type === "privacy") {
         this.setData({
@@ -25,16 +23,6 @@ Page({
         })
       }
     }
-    // if(options.orderInfo) {
-    //   const orderInfo = JSON.parse(decodeURIComponent(options.orderInfo));
-    //   // console.log(orderInfo, app.globalData.baseUrl + `/classroom-app/?code=081xNSll2ff0xe4sb4ll2RxTRv0xNSlk#/payResult?paymentType=${orderInfo.paymentType}&pay_channel=${orderInfo.pay_channel}&wxAppId=${orderInfo.wxAppId}&body=${orderInfo.body}&price=${orderInfo.price}&orderNo=${orderInfo.orderNo}&userId=${orderInfo.userId}`)
-    //   const url = app.globalData.baseUrl + `/classroom-app/?code=0811HI0w3EfxT337iM1w3MifZf01HI0G#/payResultWechat?paymentType=${orderInfo.paymentType}&pay_channel=${orderInfo.pay_channel}&wxAppId=${orderInfo.wxAppId}&body=${orderInfo.body}&price=${orderInfo.price}&orderNo=${orderInfo.orderNo}&userId=${orderInfo.userId}`
-    //   this.setData({
-    //     src: url
-    //   }, () => {
-    //     console.log(this.data.src, 'src')
-    //   })
-    // }
   },
 
   /**

+ 1 - 1
project.config.json

@@ -14,7 +14,7 @@
     },
     "coverView": false,
     "postcss": false,
-    "minified": false,
+    "minified": true,
     "enhance": true,
     "showShadowRootInWxmlPanel": false,
     "packNpmRelationList": [],