// pages/mine/myorder/myorderdetail/myorderdetail.js const app = getApp() const utilMd5 = require('../../../../utils/md5.js') Page({ /** * 页面的初始数据 */ data: { orderPay: [], od_product_id: '', loaddisplay: true, od_product_name: '', od_status: '', od_user_address: '', od_consultantname: '', od_mmname: '', od_date: '', od_no: '', od_contract: '', od_startdate: '', od_enddate: '', od_date: '', od_order_amount: '', od_discount: '', od_discountName: '', od_paid: '', arrearage: '', discount_show: false, od_refund: '', paySum:'', }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this wx.request({ url: app.globalData.url + '/getYSOrder', method: 'get', data: { id: options.id }, success: function (resp) { // console.log(resp.data.orderPay.length+1) let paySum = resp.data.paySum; let orderInfo = resp.data.orderInfo; let orderPay = resp.data.orderPay; that.setData({ orderPay: orderPay, od_product_id: orderInfo.od_product_id, od_product_name: orderInfo.od_product_name, od_status: orderInfo.od_status, od_user_address: orderInfo.od_user_address, od_consultantname: orderInfo.od_consultantname, od_mmname: orderInfo.od_mmname, od_mmid: orderInfo.od_mmid, od_date: orderInfo.od_date, od_no: orderInfo.od_no, od_contract: orderInfo.od_contract, od_startdate: orderInfo.od_startdate, od_enddate: orderInfo.od_enddate, od_date: orderInfo.od_date, od_order_amount: Number(orderInfo.od_order_amount).toFixed(2), od_paid: (Number(orderInfo.od_earnestpay) + Number(orderInfo.od_balancepay)).toFixed(2), arrearage: Number(resp.data.customerPay).toFixed(2), paySum:paySum }) if (orderInfo.od_promotion_discount !== 0) { that.setData({ od_discountName: '活动优惠', od_discount: Number(orderInfo.od_promotion_discount).toFixed(2), discount_show: true }) } else if (orderInfo.od_other_discount !== 0) { that.setData({ od_discountName: '其他优惠', od_discount: Number(orderInfo.od_other_discount).toFixed(2), discount_show: true }) } else if (orderInfo.od_mgm_discount !== 0) { that.setData({ od_discountName: '推荐优惠', od_discount: Number(orderInfo.od_mgm_discount).toFixed(2), discount_show: true }) } if (orderInfo.od_status == 9) { wx.request({ url: app.globalData.url + '/queryYSOrderReturn', method: 'get', data: { od_no: orderInfo.od_no }, success: function (res) { if (res.data.od_refund != null) { that.setData({ od_refund: res.data.od_refund.toFixed(2), }) } else { that.setData({ od_refund: '0.00' }) } }, fail() { app.timeOut() } }) } that.setData({ loaddisplay: 'none' }) }, fail() { app.timeOut() } }) let _this = this; _this.setData({ navH: app.globalData.navHeight }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, orderSign: function (e) { //验证订单月嫂 首付款时 var that = this if (this.data.od_status == 1) { wx.request({ url: app.globalData.url + '/checkStockDate', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { servant_code: this.data.od_mmid, start_date: this.data.od_startdate, end_date: this.data.od_enddate }, success: function (res) { if (res.data != 1) { wx.showToast({ title: '当前月嫂不能服务,请联系您的专属顾问!', icon: 'none', duration: 2000 }) return false; } else { that.goPay(); } }, fail() { app.timeOut() } }) } else { that.goPay(); } }, randomString: function () { var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ var maxPos = chars.length; var pwd = ''; for (var i = 0; i < 32; i++) { pwd += chars.charAt(Math.floor(Math.random() * maxPos)); } return pwd; }, goPay: function () { if (this.data.arrearage == null) { wx.showToast({ title: '无待支付金额!', icon: 'none', duration: 1500 }) return false; } //支付test // this.setData({ // arrearage: 0.01 // }) //获取支付参数 var that = this //校验是否支付过! var staus = null if (this.data.od_status == 1) { staus = 2 } else if (this.data.od_status == 2) { staus = 3 } wx.request({ url: app.globalData.url + '/checkCustomerPay', method: 'POST', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { cp_ordertype: 2, cp_orderno: this.data.od_no, cp_orderstatus: staus }, success: function (res) { if(res.data === 1) { wx.showToast({ title: '订单已经支付过啦!', icon: 'none', duration: 1500 }) } else { wx.request({ url: app.globalData.payurl, method: 'post', data: { orderNo: that.data.od_no + 'SEQ' +Number(that.data.orderPay.length+1), channel: "wx_mini_ys", price: Number(that.data.arrearage).toFixed(2), originPrice: Number(that.data.od_order_amount).toFixed(2), openId: app.globalData.openid, title: that.data.od_product_name + "*1", productName: that.data.od_product_name, productId: that.data.od_product_id }, success: function (res) { let data = res.data.body; console.log(data) // 调用支付接口 // var timeStamp = String(parseInt(new Date().getTime() / 1000));timeStamp var timeStamp = data.timeStamp; // var nonceStr = that.randomString();nonceStr var nonceStr = data.nonceStr; var newpaySign = "appId=" + res.data.body.appId + "&nonceStr=" + nonceStr + "&package=" + res.data.body.package + "&signType=MD5" + "&timeStamp=" + timeStamp + "&key=" + app.globalData.key; // var paySign = utilMd5.hexMD5(newpaySign).toUpperCase(); var paySign = data.sign; console.log(newpaySign) console.log(paySign) console.log(timeStamp,nonceStr,data.package,paySign) wx.requestPayment( { 'timeStamp': timeStamp, 'nonceStr': nonceStr, 'package': data.package, 'signType': 'MD5', 'paySign': paySign, 'success': function (res) { console.log(res) wx.showToast({ title: '付款成功!', icon: 'none', duration: 1500 }) var date = new Date(); var year = date.getFullYear(); var month = ("0" + (date.getMonth() + 1)).slice(-2);; var strDate = ("0" + (date.getDate())).slice(-2); var hours = ("0" + (date.getHours())).slice(-2); var minutes = ("0" + (date.getMinutes())).slice(-2); var seconds = ("0" + (date.getSeconds())).slice(-2); var eh_time = year + '-' + month + '-' + strDate + ' ' + hours + ':' + minutes + ':' + seconds; //增加用户支付信息,更新订单状态 // wx.request({ // url: app.globalData.url + '/insertYsOrderPay', // method: 'post', // header: { "Content-Type": "application/x-www-form-urlencoded" }, // data: { // cp_ordertype: 2, // cp_orderno: that.data.od_no, // cp_orderstatus: staus, // cp_discount: 0, // cp_paytype: 2, // cp_payamount: that.data.arrearage, // cp_usercode: 1, // cp_date: eh_time // }, // success: function (res) { // //发送消息到微信 // wx.request({ // url: app.globalData.url + '/WXSendYSOrderMessage', // method: 'get', // data: { // orderno: that.data.od_no, // total: that.data.arrearage, // date: eh_time, // type: staus // } // }) // //返回订单列表页面? // wx.navigateBack({ // delta: 1 // }) // }, // fail() { // app.timeOut() // } // }) }, 'fail': function (res1) { console.log(res1,timeStamp,nonceStr,res.data.body.package,paySign) wx.showToast({ title: '付款失败!', icon: 'none', duration: 1500 }) }, 'complete': function (res) { console.log(res) } }) }, fail() { app.timeOut() } }) } }, fail() { app.timeOut() } }) } })