Sfoglia il codice sorgente

Merge branch 'feature/历史订单页面接口整合' into develop

Zhenghanjv 4 mesi fa
parent
commit
087e84d538

+ 2 - 1
app.json

@@ -12,7 +12,8 @@
     "components/orderItem/orderItem",
     "components/orderInfo/orderInfo",
     "components/orderItemInfo/orderItemInfo",
-    "components/pay/pay"
+    "components/pay/pay",
+    "pages/payResult/payResult"
   ],
   "window": {
     "navigationBarTextStyle": "black",

+ 1 - 1
components/orderItemInfo/orderItemInfo.wxml

@@ -58,6 +58,6 @@
     </view>
   </view>
 
-  <text class="botton" bind:tap="buttonClick2">{{bottonText2}}</text>
+  <text wx:if="{{bottonText2 != ''}}" class="botton" bind:tap="buttonClick2">{{bottonText2}}</text>
 
 </view>

+ 3 - 1
components/orderItemInfo/orderItemInfo.wxss

@@ -22,11 +22,13 @@
 }
 .nozzle{
   font-weight: 600;
+  margin-top: 3%;
 }
 .status{
   position: absolute;
   font-weight: 600;
   margin-left: 70%;
+  margin-top: 3%;
 }
 
 .orderInfo{
@@ -94,6 +96,7 @@
   display: flex;
   flex-direction: column;
   width: 100%;
+  margin-bottom: 3%;
 }
 .orderDetailInfo view{
   display: flex;
@@ -115,5 +118,4 @@
   height: 5vh;
   font-size: small;
   border-radius: 0 0 15rpx 15rpx ;
-  margin-top: 3%;
 }

+ 53 - 32
js/api.js

@@ -1,35 +1,39 @@
 const sm4 = require('../js/SM4');
 const SM4Exten = require('../js/SM4Exten');
 const miniprogramsm4 = require("../miniprogram_npm/miniprogram-sm-crypto/index").sm4;
-const secretId = "D2BCF8DE-AA24-4BF6-9C34-C8DD325E412B";//小程序应用ID
-const Secret = "6C680A47B87740138DFB299FC69A64E1";//小程序应用密钥
-const api_root = 'http://192.168.5.5:5006/'
+const secretId = "D2BCF8DE-AA24-4BF6-9C34-C8DD325E412B"; //小程序应用ID
+const Secret = "6C680A47B87740138DFB299FC69A64E1"; //小程序应用密钥
+const api_root = 'http://192.168.0.202:5006/'
 const CurrentBuId = '12345678-9abc-def0-1234-56789abcdef0';
 
 function request(path, method = 'GET', data = null) {
   var WachatID = wx.getStorageSync('WachatID')
-  return new Promise((resolve, reject) => { 
+  return new Promise((resolve, reject) => {
     var sign_method = "HMAC_SM4";
-    var url = api_root +  path;
+    var url = api_root + path;
     var nonce = generateRandomString();
     const timestamp = Date.now();
     console.log('data :' + data);
     let jsonString = (data != null && method != 'GET') ? JSON.stringify(data) : '';
     console.log('request :' + jsonString);
-     var stringToSign = "sign_method=" +sign_method + 
-                       "&secret_id=" +secretId+
-                       "&nonce=" +  nonce +
-                       "&timestamp=" + timestamp;
-    if(jsonString != '')
-    {
-      stringToSign +=  "&"+jsonString
-    }
+    var stringToSign = "sign_method=" + sign_method +
+      "&secret_id=" + secretId +
+      "&nonce=" + nonce +
+      "&timestamp=" + timestamp;
+    if (jsonString != '') {
+      stringToSign += "&" + jsonString
+    }
+    const resultArray = path.split('?');
+    if (resultArray.length == 2) {
+      stringToSign += "&" + resultArray[1]
+    }
     console.log('加密串 :' + stringToSign);
-    let key =  stringToHex(Secret);//key转16进制
-    key = getFirst32Chars(key);//截取前16位
-    let signature = miniprogramsm4.encrypt(stringToSign, key)//sm4加密
+    if(path == 'api/Site/GetSiteInfo') console.log('获取站点信息加密串 :' + stringToSign);
+    let key = stringToHex(Secret); //key转16进制
+    key = getFirst32Chars(key); //截取前16位
+    let signature = miniprogramsm4.encrypt(stringToSign, key) //sm4加密
     //signature = signature.toUpperCase();
-    signature = stringToBase64(signature);//加密字符串转base64
+    signature = stringToBase64(signature); //加密字符串转base64
     console.log('signature :' + signature);
     wx.request({
       header: {
@@ -38,10 +42,10 @@ function request(path, method = 'GET', data = null) {
         "nonce": nonce,
         "timestamp": timestamp,
         "signature": signature,
-        "CurrentBuId" : CurrentBuId,
-        "WachatID":WachatID
+        "CurrentBuId": CurrentBuId,
+        "WachatID": WachatID
       },
-      url: url, 
+      url: url,
       method: method,
       data: data,
       success: res => {
@@ -61,12 +65,12 @@ function request(path, method = 'GET', data = null) {
 function stringToBase64(str) {
   // 定义Base64字符集
   const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
-  
+
   // 将字符串转换为UTF-8字节数组
   let utf8Bytes = [];
   for (let i = 0; i < str.length; i++) {
     let charCode = str.charCodeAt(i);
-    
+
     if (charCode < 128) { // 1字节字符
       utf8Bytes.push(charCode);
     } else if (charCode < 2048) { // 2字节字符
@@ -115,7 +119,7 @@ function getFirst32Chars(str) {
   if (typeof str !== 'string') {
     throw new Error('Input must be a string');
   }
-  
+
   // 如果字符串长度小于等于32,则返回整个字符串;否则返回前32个字符
   return str.length <= 32 ? str : str.slice(0, 32);
 }
@@ -156,7 +160,7 @@ function generateRandomString(minLength = 6, maxLength = 10) {
 // }
 //支付
 function request_wechatPay(data) {
-  return request('api/Transactions/UnifiedOrder?trxid='+ data, "GET",data);
+  return request('api/Transactions/UnifiedOrder?trxid=' + data, "POST", data);
 }
 
 //获取站点信息与用户信息
@@ -166,37 +170,51 @@ function request_GetSiteInfo() {
 
 //小程序用户查询未支付订单
 function request_GetMiniProgramTransactionsUnpaidQuery(data) {
-  return request('api/Transactions/GetMiniProgramTransactionsUnpaidQuery', "GET",data);
+  return request('api/Transactions/GetMiniProgramTransactionsUnpaidQuery', "GET", data);
 }
 
 //小程序用户根据抢号查询未支付订单
 function request_GetMiniProgramTransactionsUnpaidNozzle(data) {
-  return request('api/Transactions/GetMiniProgramTransactionsUnpaidNozzle?NozzleId='+data, "GET",data);
+  return request('api/Transactions/GetMiniProgramTransactionsUnpaidNozzle?NozzleId=' + data, "GET", data);
 }
 //小程序登录
 function request_Wechatlogin(data) {
-  return request('api/Auth/Wechatlogin?code='+ data, "GET",data);
+  return request('api/Auth/Wechatlogin?code=' + data, "GET", data);
+}
+
+//获取历史订单
+function request_WXFindOrders(dateTime,pageNum,lineCount) {
+  return request('api/Transactions/WXFindOrders?dateTime='+ dateTime + '&pageNum='+ pageNum+ '&lineCount='+ lineCount, "GET");
 }
 
 //添加用户信息
 function request_AddMiniprogramUser(data) {
-  return request('api/Site/AddMiniprogramUser', "POST",data);
+  return request('api/Site/AddMiniprogramUser', "POST", data);
 }
 
 //向fcc发起油枪授权
 function request_NozzleAuthorization(data) {
-  return request('api/Nozzle/NozzleAuthorization?trxid=' +data, "GET",data);
+  return request('api/Nozzle/NozzleAuthorization?trxid=' + data, "GET", data);
 }
 
 //向fcc发起取消油枪授权
 function request_CancelNozzleAuthorization(data) {
-  return request('api/Nozzle/CancelNozzleAuthorization?trxid=' +data, "GET",data);
+  return request('api/Nozzle/CancelNozzleAuthorization?trxid=' + data, "GET", data);
 }
 //退款
 function request_RefundTrx(data) {
-  return request('api/Transactions/RefundTrx', "POST",data);
+  return request('api/Transactions/RefundTrx', "POST", data);
 }
 
+//根据油枪id获取油枪信息
+function request_GetNozzleInfo(data) {
+  return request('api/Nozzle/GetFuelNozzleInfoById', 'GET', data)
+}
+
+//发送消息模板
+function request_sendMessage(data) {
+  return request('api/Transactions/SendMessage','POST',data)
+}
 export default {
   request_GetSiteInfo,
   request_wechatPay,
@@ -207,5 +225,8 @@ export default {
   request_GetMiniProgramTransactionsUnpaidQuery,
   request_GetMiniProgramTransactionsUnpaidNozzle,
   request_AddMiniprogramUser,
-  request_RefundTrx
+  request_RefundTrx,
+  request_GetNozzleInfo,
+  request_WXFindOrders,
+  request_sendMessage
 }

+ 131 - 59
pages/TransactionPage/TransactionPage.js

@@ -1,4 +1,6 @@
-const { default: api } = require("../../js/api");
+const {
+  default: api
+} = require("../../js/api");
 const util = require('../../utils/util.js')
 
 // pages/orderConfirm/orderConfirm.js
@@ -8,11 +10,11 @@ Page({
    * 页面的初始数据
    */
   data: {
-    nozzleId:0,
-    type:'后支付',
-    order:{},
-    oprationBtn1:'',
-    oprationBtn2:'对此订单有疑问?',
+    nozzleId: 0,
+    type: '后支付',
+    order: null,
+    oprationBtn1: '',
+    oprationBtn2: '对此订单有疑问?',
   },
 
   /**
@@ -20,16 +22,15 @@ Page({
    */
   onLoad(options) {
     const link = decodeURIComponent(options.q) // 获取到二维码原始链接
-    console.log("link",link);
     var id = link.split('wxapp?id=')[1];
-    console.log("id1",id);
-    if(id == undefined) {
+    if (id == undefined) {
       id = options.id;
     }
-    console.log("id2",id)
     this.setData({
-      nozzleId:id
+      nozzleId: id
     })
+
+    this.getOrder()
   },
 
   /**
@@ -43,7 +44,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-    this.getOrder()
+
   },
 
   /**
@@ -84,62 +85,107 @@ Page({
   /** 获取订单信息 */
   getOrder() {
     api.request_GetMiniProgramTransactionsUnpaidNozzle(Number(this.data.nozzleId))
-    .then(res => {
-      if(res.data.statusCode == 203) {
-        wx.navigateTo({
-          url: '../login/login',
-        })
-        return
-      }
-      console.log("获取到未支付订单",res)
-      var order = res.data.data[0];
-      var time = util.formatDateNotSecond(order.fuelItemTransactionEndTime);
-      this.setData({
-        order:{
-          oilName:order.productName,
-          nozzle:order.nozzleId,
-          volume:order.originalQty,
-          amount:order.originalAmount,
-          payAmount:order.actualPaymentAmount,
-          discount:order.originalAmount - order.actualPaymentAmount,
-          orderId:order.id,
-          time:time
+      .then(res => {
+        if (res.data.statusCode == 203) {
+          //若为203,证明还未登录,跳转到登录页,这里可能刚从主页跳转过来,频繁的跳转可能会跳转页面超时,故而加上延时
+          setTimeout(() => {
+            wx.navigateTo({
+              url: '../login/login'
+            })
+          }, 500)
+          return
         }
+
+        console.log("获取到未支付订单", res)
+        var order = res.data.data[0];
+        var time = util.formatDateNotSecond(order.fuelItemTransactionEndTime);
+        this.setData({
+          order: {
+            oilName: order.productName,
+            nozzle: order.nozzleId,
+            volume: order.originalQty,
+            amount: order.originalAmount,
+            payAmount: order.actualPaymentAmount,
+            discount: order.originalAmount - order.actualPaymentAmount,
+            orderId: order.id,
+            time: time
+          }
+        })
+
+
+      }).catch(err => {
+        console.log("未获取到未支付订单")
       })
-    }).catch(err => {
-      console.log("未获取到未支付订单")
-    })
   },
 
   /** 后支付查看更多交易 */
-  toMordOrderPage(){
+  toMordOrderPage() {
     var that = this;
     wx.navigateTo({
-      url: '../moreOrder/moreOrder?nozzle='+this.data.nozzleId,
-      events:{
-        acceptOrderFromMoreOrder:function(data) {
-          console.log("获取到传送过来的订单",data)
-          this.setData({
-            order:data
-          })
+      url: '../moreOrder/moreOrder?nozzle=' + this.data.nozzleId,
+      events: {
+        acceptOrderFromMoreOrder: function (data) {
+          console.log("获取到传送过来的订单", data)
           that.setData({
-            order:data
+            order: data
           })
         }
       }
     })
   },
-
+  
   /** 支付按钮点击事件 */
-  toPay(){
-    api.request_wechatPay(19).then(res => {
-      console.log("支付结果",res)
-      this.pay()
+  toPay() {
+    var that = this;
+    api.request_wechatPay(this.data.order.orderId).then(res => {
+      console.log("支付结果", res)
+      this.subMessage()
+      // this.pay()
     }).catch(err => {
-      console.log("支付失败",err)
+      console.log("支付失败", err)
     })
+  },
+  /** 订阅消息模板 */
+  subMessage() {
+    const that = this;
+    wx.requestSubscribeMessage({
+      tmplIds: ['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'], // 最多支持3条
+      success(res) {
+        that.pay()
+        // 'accept'表示用户同意订阅该条id对应的模板消息
+        if (res['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'] === 'accept') {
+          // 用户同意订阅,调用云函数或服务器接口发送订阅消息
+          // wx.cloud.callFunction({
+          //   name: 'sendSubscribeMessage',
+          //   data: {
+          //     templateId: '配置好的模板ID',
+          //     openid: 'o8pFb5cWH1KkBDvGls2X7yMiFkGA',
+          //     data: {
+          //       thing1: {
+          //         value: '活动名称'
+          //       },
+          //       // 其他参数...
+          //     }
+          //   },
+          //   success(res) {
+          //     console.log('订阅消息发送成功', res)
+          //   },
+          //   fail(err) {
+          //     console.error('订阅消息发送失败', err)
+          //   }
+          // })
+          
+        }
+      },
+      fail(err) {
+        that.pay()
+      }
+    })
+
+    
   },
   pay() {
+    const that = this;
     api.request_wechatPay(this.data.order.orderId)
       .then(res => {
         wx.requestPayment({
@@ -150,14 +196,9 @@ Page({
           paySign: res.data.data.unifiedOrderResult.paySign,
           success: res => {
             wx.hideLoading()
-            wx.showToast({
-              title: '支付成功!',
-            })
-            setTimeout(function () {
-              wx.redirectTo({
-                url: '../scan/scan',
-              })
-            }, 2000)
+            that.sendMessage()
+            that.toPayResult()
+            
           },
           fail: res => {
             wx.hideLoading()
@@ -166,11 +207,42 @@ Page({
               content: res.errMsg + '请稍后再试',
               showCancel: false,
               success(res) {
-                
+
               }
             })
           }
         })
       });
   },
+
+  /** 发送消息模板 */
+  sendMessage() {
+    const message = {
+      trxid:this.data.order.orderId,
+      orderType:'支付成功'
+    }
+    api.request_sendMessage(message).then(res => {
+      console.log("发送消息模板结果",res)
+    }).catch(err => {
+      console.log("发送消息模板失败",err)
+    })
+  },
+
+  /** 跳转到支付结果页 */
+  toPayResult(){
+    const that = this;
+    setTimeout(function () {
+      wx.navigateTo({
+        url: '../payResult/payResult?nozzle=' + that.data.nozzleId,
+        events: {
+          acceptOrderFromPayResult: function (data) {
+            console.log("获取到来自result页面传送过来的订单", data)
+            that.setData({
+              order: data
+            })
+          }
+        }
+      })
+    }, 500)
+  }
 })

+ 2 - 1
pages/TransactionPage/TransactionPage.json

@@ -2,5 +2,6 @@
   "usingComponents": {
     "orderInfo":"../../components/orderItemInfo/orderItemInfo",
     "pay":"../../components/pay/pay"
-  }
+  },
+  "navigationBarTitleText": "确认支付"
 }

+ 1 - 1
pages/TransactionPage/TransactionPage.wxml

@@ -6,7 +6,7 @@
   </view>
 
   <!-- 订单 -->
-  <orderInfo class="orderInfo" order="{{order}}" bottonText2="{{oprationBtn2}}" bind:bottonEvent2="toMordOrderPage" />
+  <orderInfo wx:if="{{order != null}}" class="orderInfo" order="{{order}}" bottonText2="{{oprationBtn2}}" bind:bottonEvent2="toMordOrderPage" />
 
   <text class="moreOrderTip" bind:tap="toMordOrderPage">更多交易</text>
   

+ 148 - 38
pages/historyOrder/historyOrder.js

@@ -1,4 +1,7 @@
-const { default: api } = require("../../js/api");
+const {
+  default: api
+} = require("../../js/api");
+const util = require('../../utils/util.js')
 
 // pages/historyOrderAfter/historyOrderAfter.js
 Page({
@@ -7,38 +10,87 @@ Page({
    * 页面的初始数据
    */
   data: {
-    date:'',
-    startDate:'',
-    endDate:'',
-    orders:[
+    date: '',
+    startDate: '',
+    endDate: '',
+    pageNum:1,//查询页码
+    pageSize:5,//页数
+    isHaveOrder:true,//是否还有订单
+    paymentMode: -1,
+    /** 根据当前模式(后支付:0或预支付:1)+ 授权状态(未授权:0;已授权:1)
+     * + 订单状态(0:未支付; 1:已支付; 2:订单全额退款;3:订单部分退款;5:已完成)
+     * 获取订单状态及颜色 */
+    statusValue: [{
+        paymentMode: "0",
+        authorizationStatus: 0,
+        orderStatus: 0,
+        status: '未支付',
+        statusColor: '#ff8d1a'
+      },
+      {
+        paymentMode: "0",
+        authorizationStatus: 0,
+        orderStatus: 1,
+        status: '已完成',
+        statusColor: '#a6a6a6'
+      },
+      {
+        paymentMode: "0",
+        authorizationStatus: 0,
+        orderStatus: 5,
+        status: '已完成',
+        statusColor: '#a6a6a6'
+      },
+      {
+        paymentMode: "1",
+        authorizationStatus: 0,
+        orderStatus: 1,
+        status: '已失效',
+        statusColor: '#a6a6a6'
+      },
+      {
+        paymentMode: "1",
+        authorizationStatus: 1,
+        orderStatus: 1,
+        status: '已授权',
+        statusColor: '#b1db5a'
+      },
+      {
+        paymentMode: "1",
+        authorizationStatus: 0,
+        orderStatus: 2,
+        status: '已完成',
+        statusColor: '#a6a6a6'
+      },
+      {
+        paymentMode: "1",
+        authorizationStatus: 0,
+        orderStatus: 3,
+        status: '已完成',
+        statusColor: '#a6a6a6'
+      },
       {
-        order:{
-          nozzle:5,
-          status:'已授权',
-          statusColor:'#bbe06e',
-          oilName:"92#",
-          volume:20.0,
-          amount:46.8,
-          payAmount:46.8,
-          discount:0.00,
-          time:'2024-11-24 09:08',
-        },
-        bottonText2:'请尽快提枪'
+        paymentMode: "1",
+        authorizationStatus: 0,
+        orderStatus: 5,
+        status: '已完成',
+        statusColor: '#a6a6a6'
       },
-    ]
+    ],
+    orders: []
   },
 
   /** 获取当前日期 */
-  getNowDate(){
+  getNowDate() {
     const date = new Date(); // 获取当前日期
     const year = date.getFullYear(); // 获取年份
     const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份,补零
     const day = String(date.getDate()).padStart(2, '0'); // 获取日期,补零
-  
+
     return `${year}-${month}-${day}`; // 拼接成 yyyy-MM-dd 格式
   },
   /** 获取上个月日期 */
-  getLastMouthDate(){
+  getLastMouthDate() {
     const currentDate = new Date(); // 获取当前日期
     const year = currentDate.getFullYear(); // 当前年份
     const month = currentDate.getMonth(); // 当前月份(0-11)
@@ -57,28 +109,28 @@ Page({
   },
 
   /** 计算倒计时,倒计时结束后发起取消授权 */
-  startCountdow(){
+  startCountdow() {
     this.timer = setInterval(() => {
       const countDownZeroOrders = []
       const orders = this.data.orders.map(order => {
-        if(order.countdown && order.countdown != '0') {
+        if (order.countdown && order.countdown != '0') {
           const currentCountDown = (Number(order.countdown) - 1);
           order.countdown = currentCountDown.toString();
-          if(currentCountDown <= 0) countDownZeroOrders.push(order)
+          if (currentCountDown <= 0) countDownZeroOrders.push(order)
         }
         return order
       })
 
       this.setData({
-        orders:orders
+        orders: orders
       })
       this.toUnAnthorization(countDownZeroOrders)
-    },1000);
+    }, 1000);
   },
 
   /** 结束倒计时 */
-  endCountDown(){
-    if(this.timer) {
+  endCountDown() {
+    if (this.timer) {
       clearInterval(this.timer)
       this.timer = null
     }
@@ -94,11 +146,14 @@ Page({
     const today = this.getNowDate();
     const lastMouthDay = this.getLastMouthDate();
     this.setData({
-      date:today,
-      startDate:today,
-      endDate:lastMouthDay
+      date: today,
+      paymentMode: options.paymentMode,
+      startDate: today,
+      endDate: lastMouthDay
     });
+    console.log("历史页当前data",this.data)
 
+    this.getOrder();
 
     // this.startCountdow();
   },
@@ -142,7 +197,13 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom() {
-
+    console.log("chudi")
+    if(!this.data.isHaveOrder) return;
+    var page = this.data.pageNum + 1;
+    this.setData({
+      pageNum:page
+    })
+    this.getOrder()
   },
 
   /**
@@ -158,24 +219,73 @@ Page({
       date: date.detail.value
     });
     console.log(date)
+    this.getOrder()
   },
 
   /** 组件按钮一点击事件 */
-  onOrderButtonClick1(event){
+  onOrderButtonClick1(event) {
     console.log(event)
   },
 
   /** 组件按钮二点击事件 */
-  onOrderButtonClick2(event){
+  onOrderButtonClick2(event) {
     console.log(event)
   },
 
   /** 获取订单 */
-  getOrder(){
-    api.request_GetMiniProgramTransactionsUnpaidQuery(null).then(res => {
-      console.log("未支付订单",res)
+  getOrder() {
+    const that = this;
+    api.request_WXFindOrders(this.data.date, this.data.pageNum, this.data.pageSize).then(res => {
+      // api.request_WXFindOrders(this.data.date, 3, 5).then(res => {
+      console.log("获取历史订单", res)
+      const datas = res.data.data;
+      if(datas.length <= 0) {
+        that.data.isHaveOrder = false;
+        return
+      }
+      var getOrders = datas.map(order => {
+        var times = [order.authorizationTime, order.createTime, order.fuelItemTransactionEndTime, order.transactionTime];
+        var timeFormate = times.find(t => t != undefined && t != null && t != '');
+        var time = util.formatDateNotSecond(timeFormate);
+        var volume = (order.originalQty != null && order.originalQty != undefined) ? order.originalQty : order.qty
+        var status = that.data.statusValue.find(state =>
+          state.paymentMode == this.data.paymentMode &&
+          state.authorizationStatus == order.authorizationStatus &&
+          state.orderStatus == order.orderStatus
+        )
+        var stute = '';
+        var stateColor = '';
+        var bt2 = ''
+        if (status != undefined) {
+          stute = status.status
+          stateColor = status.statusColor
+        }
+        if(stute == '未支付') bt2 = '重新支付';
+        return {
+          order: {
+            status: stute,
+            statusColor: stateColor,
+            oilName: order.productName,
+            nozzle: order.nozzleId,
+            volume: volume,
+            amount: order.originalAmount,
+            payAmount: order.actualPaymentAmount,
+            discount: order.originalAmount - order.actualPaymentAmount,
+            orderId: order.id,
+            time: time
+          },
+          bottonText2: bt2
+        }
+      })
+
+      var orderList = [...this.data.orders,...getOrders]
+      this.setData({
+        orders: orderList
+      })
+
+      console.log("转换后的订单", this.data.orders)
     }).catch(err => {
-      console.log("获取未支付订单失败",err)
+      console.log("获取历史订单失败", err)
     })
   }
 })

+ 2 - 1
pages/historyOrder/historyOrder.json

@@ -1,5 +1,6 @@
 {
   "usingComponents": {
     "orderItem":"../../components/orderItemInfo/orderItemInfo"
-  }
+  },
+  "navigationBarTitleText": "历史订单"
 }

+ 1 - 1
pages/historyOrder/historyOrder.wxml

@@ -15,7 +15,7 @@
 
   <!-- 订单列表 -->
   <view class="order">
-    <view class="orderItem" wx:for="{{orders}}">
+    <view class="orderItem" wx:for="{{orders}}" wx:key="index">
       <orderItem 
       order="{{item.order}}"
       bottonText2="{{item.bottonText2}}"

+ 5 - 0
pages/historyOrder/historyOrder.wxss

@@ -2,6 +2,8 @@
   display: flex;
   flex-direction: column;
   align-items: center;
+  background-color: #f2f2f2;
+  height: 100vh;
 }
 
 .dataSelect {
@@ -13,6 +15,8 @@
   box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
   padding: 2% 3%;
   border-radius: 3%;
+  background-color: #FFFFFF;
+  margin-top: 1%;
 }
 .dateTip{
   display: flex;
@@ -36,4 +40,5 @@
   width: 100%;
   box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
   border-radius: 1%;
+  margin-top: 5%;
 }

+ 77 - 76
pages/login/login.js

@@ -66,82 +66,82 @@ Page({
 
   },
 
-  pay(){
+  pay() {
     api.request_wechatPay(23)
-    .then(res => {
-     wx.requestPayment({
-       timeStamp: res.data.data.unifiedOrderResult.timeStamp,
-       nonceStr: res.data.data.unifiedOrderResult.nonceStr,
-       package: res.data.data.unifiedOrderResult.package,
-       signType: res.data.data.unifiedOrderResult.signType,
-       paySign: res.data.data.unifiedOrderResult.paySign,
-       success: res => {
-         wx.hideLoading()
-         wx.showToast({
-           title: '支付成功!',
-         })
-         setTimeout(function () {
-           wx.switchTab({
-             url: '../index/index',
-           })
-         }, 2000)
+      .then(res => {
+        wx.requestPayment({
+          timeStamp: res.data.data.unifiedOrderResult.timeStamp,
+          nonceStr: res.data.data.unifiedOrderResult.nonceStr,
+          package: res.data.data.unifiedOrderResult.package,
+          signType: res.data.data.unifiedOrderResult.signType,
+          paySign: res.data.data.unifiedOrderResult.paySign,
+          success: res => {
+            wx.hideLoading()
+            wx.showToast({
+              title: '支付成功!',
+            })
+            setTimeout(function () {
+              wx.switchTab({
+                url: '../index/index',
+              })
+            }, 2000)
 
-       },
-       fail: res => {
-         wx.hideLoading()
-         wx.showModal({
-           title: '支付失败',
-           content: res.errMsg + '请稍后再试',
-           showCancel: false,
-           success(res) {
-             if (res.confirm) {
-               wx.switchTab({
-                 url: '../home/home',
-               })
-             }
-           }
-         })
-       }
-     })
-    });
+          },
+          fail: res => {
+            wx.hideLoading()
+            wx.showModal({
+              title: '支付失败',
+              content: res.errMsg + '请稍后再试',
+              showCancel: false,
+              success(res) {
+                if (res.confirm) {
+                  wx.switchTab({
+                    url: '../home/home',
+                  })
+                }
+              }
+            })
+          }
+        })
+      });
   },
-  RefundTrx:function(e){
+  RefundTrx: function (e) {
     var RefundTrx = {
-      trxId : 31,
-      longitude :116.4074,
-      latitude:39.9042
+      trxId: 31,
+      longitude: 116.4074,
+      latitude: 39.9042
     };
     api.request_RefundTrx(RefundTrx)
-    .then(res => {
-      debugger
-    });
+      .then(res => {
+        debugger
+      });
   },
-  handleGetPhoneNumber: function(e) {
+  handleGetPhoneNumber: function (e) {
     if (e.detail.errMsg === 'getPhoneNumber:ok') {
-        // 用户同意授权,获取加密数据
-        const encryptedData = e.detail.encryptedData;
-        const iv = e.detail.iv;
-debugger
-        // 调用后端接口进行解密
-        wx.request({
-            url: 'https://your-backend-api-endpoint.com/decryptPhoneNumber', // 替换为你的后端API地址
-            method: 'POST',
-            data: {
-                encryptedData: encryptedData,
-                iv: iv,
-                sessionKey: 'your-session-key' // 替换为实际的session_key
-            },
-            success(res) {
-                console.log('解密后的手机号:', res.data);
-            },
-            fail(err) {
-                console.error('解密失败:', err);
-            }
-        });
+      // 用户同意授权,获取加密数据
+      const encryptedData = e.detail.encryptedData;
+      const iv = e.detail.iv;
+      debugger
+      // 调用后端接口进行解密
+      wx.request({
+        url: 'https://your-backend-api-endpoint.com/decryptPhoneNumber', // 替换为你的后端API地址
+        method: 'POST',
+        data: {
+          encryptedData: encryptedData,
+          iv: iv,
+          sessionKey: 'your-session-key' // 替换为实际的session_key
+        },
+        success(res) {
+          console.log('解密后的手机号:', res.data);
+        },
+        fail(err) {
+          console.error('解密失败:', err);
+        }
+      });
     } else {
-        console.log('用户拒绝授权');
+      console.log('用户拒绝授权');
     }
-},
+  },
   subMessage() {
     wx.requestSubscribeMessage({
       tmplIds: ['ldkKXfnHj-uKo6SBep08f_kaSjtxMOccJywHOEgxyPg'], // 最多支持3条
@@ -163,7 +163,7 @@ debugger
             },
             success(res) {
               console.log('订阅消息发送成功', res)
-            },   
+            },
             fail(err) {
               console.error('订阅消息发送失败', err)
             }
@@ -180,7 +180,7 @@ debugger
     })
 
     if (e.type == "getphonenumber") {
-      console.log("添加手机信息",this.data.userInfo)
+      console.log("添加手机信息", this.data.userInfo)
       var user = {
         UserName: this.data.userInfo.UserName,
         UserAvatarUrl: this.data.userInfo.UserAvatarUrl,
@@ -196,7 +196,7 @@ debugger
     }
 
     if (e.type == "tap") {
-      console.log("添加用户信息",this.data.userInfo)
+      console.log("添加用户信息", this.data.userInfo)
       // 获取用户信息授权
       const that = this;
       wx.getUserProfile({
@@ -228,8 +228,8 @@ debugger
   },
 
   toLogin() {
-    if(!this.cheackUserInfo()) {
-      console.log("userInfo 信息不全",this.data.userInfo)
+    if (!this.cheackUserInfo()) {
+      console.log("userInfo 信息不全", this.data.userInfo)
       wx.hideLoading()
       return
     }
@@ -247,10 +247,11 @@ debugger
               return api.request_AddMiniprogramUser(that.data.userInfo)
             }).then(res => {
               console.log("添加user", res)
+              return api.request_GetSiteInfo();
+            }).then(res => {
+              console.log("站点信息", res)
               wx.hideLoading()
-              wx.redirectTo({
-                url: '../scan/scan',
-              })
+              wx.navigateBack();
             }).catch(err => {
               console.log("报错", res)
               wx.hideLoading()
@@ -267,8 +268,8 @@ debugger
     });
   },
 
-  cheackUserInfo(){
+  cheackUserInfo() {
     var userInfo = this.data.userInfo;
-    return userInfo.UserAvatarUrl != '' && userInfo.UserAvatarUrl != undefined && userInfo.UserName != '' && userInfo.UserName != undefined && userInfo.encryptedData != '' && userInfo.encryptedData != undefined && userInfo.iv != '' && userInfo.iv != undefined 
+    return userInfo.UserAvatarUrl != '' && userInfo.UserAvatarUrl != undefined && userInfo.UserName != '' && userInfo.UserName != undefined && userInfo.encryptedData != '' && userInfo.encryptedData != undefined && userInfo.iv != '' && userInfo.iv != undefined
   }
 })

+ 1 - 2
pages/login/login.wxml

@@ -3,10 +3,9 @@
     <image src="/images/v2_sony48.svg" mode="widthFix" class="auto-image"></image>
   </view>
   <view class="action-text">立码加油</view>
-  <open-data></open-data>
   <button class="auth-button" open-type="getPhoneNumber" style="width: 547rpx; height: 94rpx; display: block; box-sizing: border-box; left: 0rpx; top: 0rpx"  bindtap="handleAuthLogin" bindgetphonenumber="handleAuthLogin">一键授权登录</button>
   <view class="agreement">
-    <button class="auth-button"   bindtap="pay">支付</button>
+    <button class="auth-button"   bindtap="subMessage">支付</button>
     <button class="auth-button"   bindtap="RefundTrx">退款</button>
     <button open-type="getPhoneNumber" bindgetphonenumber="handleGetPhoneNumber">获取手机号</button>
     <checkbox checked="{{true}}" disabled="{{true}}" />

+ 2 - 1
pages/moreOrder/moreOrder.json

@@ -1,5 +1,6 @@
 {
   "usingComponents": {
     "orderItem":"../../components/orderItemInfo/orderItemInfo"
-  }
+  },
+  "navigationBarTitleText": "确认支付"
 }

+ 94 - 0
pages/payResult/payResult.js

@@ -0,0 +1,94 @@
+// pages/payResult/payResult.js
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    nozzleId:-1
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options) {
+    this.setData({
+      nozzleId:options.nozzle
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload() {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh() {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage() {
+
+  },
+
+  /** 查看订单 */
+  toMoreOrder(){
+    const that = this;
+    wx.navigateTo({
+      url: '../moreOrder/moreOrder?nozzle=' + this.data.nozzleId,
+      events: {
+        acceptOrderFromMoreOrder: function (data) {
+          console.log("【支付结果页】获取到传送过来的订单", data)
+          that.setData({
+            order: data
+          })
+          const eventChannel = that.getOpenerEventChannel()
+          eventChannel.emit('acceptOrderFromPayResult', data);
+          wx.navigateBack()
+        }
+      }
+    })
+  },
+
+  /** 完成 */
+  finish() {
+    wx.redirectTo({
+      url: '../scan/scan',
+    })
+  }
+})

+ 4 - 0
pages/payResult/payResult.json

@@ -0,0 +1,4 @@
+{
+  "usingComponents": {},
+  "navigationBarTitleText": ""
+}

+ 14 - 0
pages/payResult/payResult.wxml

@@ -0,0 +1,14 @@
+<view class="payResultContainer">
+  <!-- 标识区 -->
+  <view class="signBox">
+    <icon type="success" size="100" />
+    <text>支付成功</text>
+  </view>
+
+  <view class="buttonBox">
+    <text class="checkOrderBtn" bind:tap="toMoreOrder">查看订单</text>
+    <text class="finishBtn" bind:tap="finish">完成</text>
+  </view>
+
+  <text class="bottomTip">客服帮助 | 隐私政策等</text>
+</view>

+ 70 - 0
pages/payResult/payResult.wxss

@@ -0,0 +1,70 @@
+.payResultContainer{
+  height: 100vh;
+  background-color: #f2f2f2;
+  display: flex;
+  flex-direction: column;
+  justify-content: space-around;
+  align-items: center;
+}
+
+.signBox{
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+  align-items: center;
+  flex-grow: 1;
+}
+.signBox icon{
+  flex-grow: 2;
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+}
+.signBox text {
+  font-weight: 600;
+  flex-grow: 1;
+}
+
+.buttonBox{
+  display: flex;
+  flex-direction: column;
+  justify-content: start;
+  align-items: center;
+  flex-grow: 1;
+  width: 90%;
+  margin-top: 8%;
+}
+.checkOrderBtn{
+  background-color: #d81e07;
+  color: #FFFFFF;
+  height: 6vh;
+  width: 100%;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  font-size: small;
+  font-weight: 600;
+  border-radius: 10rpx;
+  margin-bottom: 10%;
+}
+.finishBtn{
+  background-color: #FFFFFF;
+  color: #d81e07;
+  height: 6vh;
+  width: 100%;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  font-size: small;
+  font-weight: 600;
+  border-radius: 10rpx;
+  border: #d81e07 solid 5rpx;
+}
+
+.bottomTip{
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+  flex-grow: 1;
+  color: #999999;
+}

+ 46 - 13
pages/scan/scan.js

@@ -1,6 +1,7 @@
 const {
   default: api
 } = require("../../js/api");
+const utils = require('../../utils/util')
 
 Page({
   data: {
@@ -15,16 +16,31 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+
+  },
+
+  onShow(){
+    this.getSiteInfo()
+  },
+
+  /** 获取站点信息 */
+  getSiteInfo(){
     api.request_GetSiteInfo().then(res => {
       if(res.data.statusCode == 203) {
         console.log("获取站点信息失败",res)
         return
       }
       console.log("站点信息",res)
+      var formatePhone = utils.formatPhone(res.data.data.userInfo.userPhoneNumber);
       this.setData({
         isLoggedIn: true,
         site:res.data.data.site,
-        userInfo: res.data.data.userInfo,
+        userInfo: {
+          userAddress:res.data.data.userInfo.userAddress,
+          userAvatarUrl:res.data.data.userInfo.userAvatarUrl,
+          userPhoneNumber:formatePhone,
+          userName:res.data.data.userInfouserName
+        },
         scanTitle: '扫码加油',
         scanTip: '请扫码加油机键盘上的二维码'
       })
@@ -32,15 +48,14 @@ Page({
       console.log("获取站点信息失败",err)
     })
   },
-
   toLoginOrOrderPage: function () {
     if (!this.data.isLoggedIn) {
-      wx.redirectTo({
+      wx.navigateTo({
         url: '../login/login'
       })
     } else {
       wx.navigateTo({
-        url: '../historyOrder/historyOrder',
+        url: '../historyOrder/historyOrder?paymentMode=' + this.data.site.paymentMode,
       })
     }
   },
@@ -50,15 +65,33 @@ Page({
     const that = this;
     wx.scanCode({
       success(res) {
-        wx.redirectTo({
-          url: res.result,
-          fail(err){
-            wx.showToast({
-              title: '跳转页面失败',
-              icon: 'none'
-            });
-          }
-        })
+        console.log("扫码内容",res.result)
+        const scanStr = res.result;
+        if(scanStr.includes('wxapp')) {
+          const id = scanStr.split('wxapp?id=')[1];
+          wx.redirectTo({
+            url: '../TransactionPage/TransactionPage?id=' + id,
+            fail(err){
+              wx.showToast({
+                title: '跳转页面失败',
+                icon: 'none'
+              });
+            }
+          })
+        }
+        if(scanStr.includes('yuwxapp')) {
+          const id = scanStr.split('yuwxapp?id=')[1];
+          wx.redirectTo({
+            url: '../quantify/quantify?id=' + id,
+            fail(err){
+              wx.showToast({
+                title: '跳转页面失败',
+                icon: 'none'
+              });
+            }
+          })
+        }
+        
       },
       fail(err) {
         console.error('扫码失败:', err);

+ 2 - 1
pages/scan/scan.json

@@ -1,3 +1,4 @@
 {
-  "usingComponents": {}
+  "usingComponents": {},
+  "navigationBarTitleText": ""
 }

+ 22 - 3
utils/util.js

@@ -10,12 +10,13 @@ const formatTime = date => {
 }
 
 const formatDateNotSecond = isoString => {
+  if (isoString == undefined) return '';
   const date = new Date(isoString);
 
   const year = date.getFullYear();
   const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are zero-based
   const day = String(date.getDate()).padStart(2, '0');
-  
+
   const hours = String(date.getHours()).padStart(2, '0');
   const minutes = String(date.getMinutes()).padStart(2, '0');
 
@@ -27,7 +28,25 @@ const formatNumber = n => {
   return n[1] ? n : `0${n}`
 }
 
+const formatPhone = phone => {
+  // 检查手机号是否有效
+  if (!phone || phone.length !== 11) {
+    return phone;
+  }
+
+  // 获取手机号前3位和后4位
+  const start = phone.substring(0, 3);
+  const end = phone.substring(7);
+
+  // 将中间4位数字替换为星号
+  const hidden = '****';
+
+  // 返回处理后的手机号
+  return start + hidden + end;
+}
+
 module.exports = {
   formatTime,
-  formatDateNotSecond
-}
+  formatDateNotSecond,
+  formatPhone
+}