Procházet zdrojové kódy

[订单支付][新增]:添加订单支付接口实现

tags/2.2.4
Stormeye.Wu před 6 roky
rodič
revize
bce4dc0905
2 změnil soubory, kde provedl 132 přidání a 190 odebrání
  1. +120
    -178
      pages/order/detail/index.js
  2. +12
    -12
      pages/order/detail/index.wxml

+ 120
- 178
pages/order/detail/index.js Zobrazit soubor

@@ -8,7 +8,9 @@ Page({
*/ */
data: { data: {
showModalStatus: false, showModalStatus: false,
flag: 0
flag: 0,
order: null,
orderId: null
}, },


/** /**
@@ -73,6 +75,10 @@ Page({
console.log(options.orderId); console.log(options.orderId);
console.log(options.flag + "我是付款的标识"); console.log(options.flag + "我是付款的标识");


this.setData({
orderId: options.orderId
})

Http.get({ Http.get({
url: config.api.orderDetail, url: config.api.orderDetail,
data: { data: {
@@ -82,7 +88,7 @@ Page({
console.log(res); console.log(res);
console.log("我是订单详情"); console.log("我是订单详情");
that.setData({ that.setData({
data: res.data
order: res.data
}); });


//createDate 创建时间 //createDate 创建时间
@@ -98,185 +104,121 @@ Page({
/** /**
* 发起支付 * 发起支付
*/ */
// orderFunc(e) {
// var that = this;
// console.log(e.currentTarget.dataset.couponchannelid);
// wx.showLoading({
// title: "加载中..."
// });
// Http.post({
// url: config.api.checkPhoneStatus,
// data: {}
// })
// .then(res => {
// console.log(res);
// /**
// * orderSave 下单
// */
// return Http.post({
// url: config.api.orderSave,
// data: {
// couponChannelId: "" + e.currentTarget.dataset.couponchannelid,
// couponId: "" + that.data.couponId
// }
// });
// })
// .catch(err => {
// console.log(err);
// if (err.code == 11005) {
// // 用户手机未授权
// wx.redirectTo({
// url:
// "../../getphoneInfo/index?couponChannelId=" +
// that.data.couponChannelId +
// "&couponId=" +
// that.data.couponId
// });
// }
// if (err.code == 11006) {
// // 用户手机已加密
// wx.redirectTo({
// url:
// "../../phoneinput/phoneinput?couponChannelId=" +
// that.data.couponChannelId +
// "& couponId=" +
// that.data.couponId
// });
// }
// })
// .then(res => {
// if (res != "undefined") {
// const orderId = "" + res.data.id;
// that.setData({
// orderId: orderId
// });
// if (res.data.payment > 0) {
// // 支付金额不为0
// /**
// * 支付订单创建
// */
// Http.post({
// url: config.api.payOrderCreate,
// data: {
// orderId: orderId
// }
// }).then(res => {
// console.log(res);

// /// Begin payment ----
// var payOrderId = "" + res.data.payOrderId;
// wx.hideLoading();
// wx.requestPayment({
// timeStamp: res.data.timeStamp,
// nonceStr: res.data.nonceStr,
// package: res.data.package,
// signType: "MD5",
// paySign: res.data.paySign,
// success: res => {
// console.log(res);
// console.log("姐在检查付款异常");

// that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功

// console.log(res);
// if (res.errMsg == "requestPayment:ok") {
// wx.showToast({
// title: "购买成功",
// duration: 2500
// });
// }

// wx.navigateBack({
// delta: 2
// });
// },

// fail: res => {
// that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
// console.log(res);
// return;
// },
// complete: res => {
// console.log(res);
// console.log("支付完成");
// // var url = res.data.url;
// // console.log("get url", url);
// if (res.errMsg == "requestPayment:ok") {
// wx.showModal({
// title: "提示",
// content: "支付成功"
// });
// // if (url) {
// // setTimeout(function () {
// // wx.redirectTo({
// // url: "/pages" + url
// // });
// // }, 2000);
// // } else {
// // setTimeout(() => {
// // wx.navigateBack();
// // }, 2000);
// // }
// } else {
// wx.showToast({
// title: "支付失败",
// image: "./../../../assets/img/fail.png",
// duration: 1500,
// mask: false
// });
// }
// return;
// }
// });
// /// End payment --------
orderFunc(e) {
var that = this;
wx.showLoading({
title: "加载中..."
});


// ///// virtual pay
// //var payOrderId = "" + res.data.out_trade_no;
// //that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
// ///// end virtual pay
// });
// } else {
// // 免费券
// that
// .payOrderUpdate(orderId, "0", 1) // 支付成功
// .then(res => {
// wx.showToast({
// title: "支付成功",
// duration: 3000
// });
// });
// }
// }
// })
// .catch(err => {
// console.log(err);
// });
// },
const orderId = "" + that.data.orderId;
if (that.data.order.payment > 0) {
// 支付金额不为0
Http.post({
url: config.api.payOrderCreate,
data: {
orderId: orderId
}
}).then(res => {
console.log(res);
/// Begin payment ----
var payOrderId = "" + res.data.payOrderId;
wx.hideLoading();
wx.requestPayment({
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: "MD5",
paySign: res.data.paySign,
success: res => {
console.log(res);
console.log("姐在检查付款异常");
that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
console.log(res);
if (res.errMsg == "requestPayment:ok") {
wx.showToast({
title: "购买成功",
duration: 2500
});
}
wx.navigateBack({
delta: 2
});
},
fail: res => {
that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
console.log(res);
return;
},
complete: res => {
console.log(res);
console.log("支付完成");
// var url = res.data.url;
// console.log("get url", url);
if (res.errMsg == "requestPayment:ok") {
wx.showModal({
title: "提示",
content: "支付成功"
});
// if (url) {
// setTimeout(function () {
// wx.redirectTo({
// url: "/pages" + url
// });
// }, 2000);
// } else {
// setTimeout(() => {
// wx.navigateBack();
// }, 2000);
// }
} else {
wx.showToast({
title: "支付失败",
image: "./../../../assets/img/fail.png",
duration: 1500,
mask: false
});
}
return;
}
});
/// End payment --------
});
} else {
// 免费券
that.payOrderUpdate(orderId, "0", 1) // 支付成功
.then(res => {
wx.showToast({
title: "支付成功",
duration: 3000
});
});
}
},
/** /**
* 支付订单更新 * 支付订单更新
*/ */
// payOrderUpdate: (orderId, payOrderId, status, reason) => {
// // 支付成功
// Http.post({
// url: config.api.payOrderUpdate,
// data: {
// payOrderId: payOrderId,
// orderId: orderId,
// status: status,
// reason: reason
// }
// })
// .then(res => {
// console.log("payOrderUpdate then", res);
// // wx.showToast({
// // title: "购买成功",
// // duration: 2500
// // });
// })
// .catch(err => {
// console.log("payOrderUpdate catch", err);
// });
// },
payOrderUpdate: (orderId, payOrderId, status, reason) => {
// 支付成功
Http.post({
url: config.api.payOrderUpdate,
data: {
payOrderId: payOrderId,
orderId: orderId,
status: status,
reason: reason
}
})
.then(res => {
console.log("payOrderUpdate then", res);
// wx.showToast({
// title: "购买成功",
// duration: 2500
// });
})
.catch(err => {
console.log("payOrderUpdate catch", err);
});
},


/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
@@ -312,4 +254,4 @@ Page({
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage: function() {} onShareAppMessage: function() {}
});
});

+ 12
- 12
pages/order/detail/index.wxml Zobrazit soubor

@@ -1,19 +1,19 @@
<view class='order'> <view class='order'>
<view wx:if="{{data.orderStatus==1}}" class='tips'>
<view wx:if="{{order.orderStatus==1}}" class='tips'>
<text class='iconfont icon-choose'></text> <text class='iconfont icon-choose'></text>
<text>付款成功,请尽快到门店使用</text> <text>付款成功,请尽快到门店使用</text>
</view> </view>
<view class='section'> <view class='section'>
<view class='detail_msg'> <view class='detail_msg'>
<view class='logo'> <view class='logo'>
<image src='{{data.coverImg}}'></image>
<image src='{{order.coverImg}}'></image>
</view> </view>
<view class='info'> <view class='info'>
<view> <view>
<text>{{data.title}}</text>
<text>{{order.title}}</text>
</view> </view>
<view> <view>
<text>{{data.subTitle}}</text>
<text>{{order.subTitle}}</text>
</view> </view>
<!-- <view> <!-- <view>
<text>购买数量:</text>1件 <text>购买数量:</text>1件
@@ -27,12 +27,12 @@
<view class='classif'> <view class='classif'>
<view class="clearfix"> <view class="clearfix">
<text>适用门店</text> <text>适用门店</text>
<text class="fr">{{data.merchantName}}</text>
<text class="fr">{{order.merchantName}}</text>
</view> </view>
<view wx:if="{{data.orderStatus==1}}" data-quancode="{{data.id}}" bindtap="powerDrawer" data-statu="open">
<view wx:if="{{order.orderStatus==1}}" data-quancode="{{order.id}}" bindtap="powerDrawer" data-statu="open">
<view> <view>
<text>兑换码:</text> <text>兑换码:</text>
<text>{{data.id}}</text>
<text>{{order.id}}</text>
</view> </view>
<view> <view>
<image class="spcode" src="./../../../assets/img/spcode.png" mode="widthFix"></image> <image class="spcode" src="./../../../assets/img/spcode.png" mode="widthFix"></image>
@@ -44,22 +44,22 @@
</view> </view>
<view> <view>
<text>订单编号</text> <text>订单编号</text>
<text>{{data.orderNumber}}</text>
<text>{{order.orderNumber}}</text>
</view> </view>
<view> <view>
<text>订单金额</text> <text>订单金额</text>
<text class="jine">¥{{data.salePrice/100}}</text>
<text class="jine">¥{{order.salePrice/100}}</text>
</view> </view>
</view> </view>
<!-- 待付款 显示立即购买的按钮 --> <!-- 待付款 显示立即购买的按钮 -->
<view wx:if="{{data.orderStatus==0}}" class="buy-view app-border-top">
<button bindtap='orderFunc' data-couponChannelId="{{data.id}}" class='buy'>立即购买</button>
<view wx:if="{{order.orderStatus==0}}" class="buy-view app-border-top">
<button bindtap='orderFunc' data-couponChannelId="{{order.id}}" class='buy'>立即支付</button>
</view> </view>
</view> </view>




<!--mask--> <!--mask-->
<view class="drawer_screen" data-quancode="{{data.id}}" wx:if="{{showModalStatus}}" bindtap="powerDrawer" data-statu="close"></view>
<view class="drawer_screen" data-quancode="{{order.id}}" wx:if="{{showModalStatus}}" bindtap="powerDrawer" data-statu="close"></view>
<view animation="{{animationData}}" class="drawer_box" wx:if="{{showModalStatus}}"> <view animation="{{animationData}}" class="drawer_box" wx:if="{{showModalStatus}}">
<view class="panel"> <view class="panel">
<view class="barcode"> <view class="barcode">


Načítá se…
Zrušit
Uložit