Commit e9568380 by jscat

nyx weapp: 流程更新

1. 为小程序添加正式的支付流程
2. 如果未授权, 则先授权, 后支付
parent 4a539323
......@@ -38,13 +38,13 @@
"list": [
{
"pagePath": "pages/activity/activity",
"text": "饮事",
"text": "活动",
"iconPath": "./icon/my/activity.png",
"selectedIconPath": "./icon/my/activity.png"
},
{
"pagePath": "pages/share/share",
"text": "互动",
"text": "大厅",
"iconPath": "./icon/fair/fair.png",
"selectedIconPath": "./icon/fair/fair.png"
},
......
......@@ -3,7 +3,7 @@
// env = 0; //本地java测试,需要启动java后台
// env = 1; //阿里云服务器测试版本
// env = 2; //阿里云服务器生产版本
var env = 1;
var env = 2;
var debug = 0; //是否打印调试信息
var host_key = "https://fun.hisuhong.com";
......@@ -76,5 +76,7 @@ var config={
collect_like_del_url: host_key + "/api/nyx/collect/like/del",
check_text_url: host_key + "/api/nyx/wx/check/text",
check_pic_url: host_key + "/api/nyx/wx/check/pic",
pay_url: host_key + "/api/nyx/wx/pay/orders",
pay_callback_url: host_key + "/api/nyx/wx/pay/notify",
}
module.exports=config;
\ No newline at end of file
......@@ -437,8 +437,13 @@ Page({
jscat 2020/11/17 支付成功
*/
toPay_ok: function (e) {
var datas = this.data;
var strUrl = 'https://wx.hisuhong.com/api/nyx/wx/pay/orders?openId=onuaY5fagtbB9zyEQ3fQ6jaesgrM&money=1&body=123'
var _this = this;
var nyxCode = _this.__data__.nyxCode
var body = _this.__data__.orderInfo.member_name
var money = _this.__data__.totalPrice
var query_url = '?userId=' + nyxCode + '&money=' + money + '&body=' + body
var strUrl = config.pay_url + query_url
config.debug == 1?console.log("===toPay_ok strUrl "+strUrl):""
wx.request({
url: strUrl,
method: "GET",
......@@ -457,7 +462,7 @@ Page({
if (res.errMsg == "requestPayment:ok"){
//这里是支付成功后的操作,你可以在此提交表单或者进行其他减少库存量等一系列操作
console.log("pay:ok");
_this.toOrder();
}
},
fail : function(res)
......@@ -469,6 +474,86 @@ Page({
});
},
// 跳转到支付页面
// 目前暂时跳转到 /page/my/my.wxml
toOrder: function (e) {
var _this = this;
var strUrl = config.order_add_url
config.debug == 1?console.log("===uploadOrder strUrl "+strUrl):""
//先设置支付按钮不可点击
var canClick = false;
_this.setData({ canClick })
// 订单处理, 添加到订单项的条件
// 1. 商品中某一类别的quantity>=1,
// 2. defaultStatus==1
var items = _this.data.orderItems
var orderItems = []
for(var i=0; i<items.length;i++)
{
if(items[i].quantity >= 1 && items[i].defaultStatus == 1)
{
orderItems.push(items[i])
}
}
wx.request({
url: strUrl,
method: 'POST',
data: {
activityId: _this.__data__.orderInfo["activity_id"],
userId: _this.data.nyxCode,
productImage: _this.__data__.orderInfo['product_image'],
totalPrice: _this.data.totalPrice,
totalCount: _this.data.totalCount,
orderItemString: JSON.stringify(orderItems),
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': wx.getStorageSync('cookieKey'),
},
dataType: "json",
success: function (res) {
if ( res.data.resultCode == 200 ) {
//表示提交成功
console.log("===订单上传成功");
//重置数据
//设置支付按钮可点击
var canClick = true;
_this.setData({ canClick })
//回到首页
_this.toHome();
}
else if(res.data.resultCode == '000601')
{
//表示重复提交
console.log("===订单重复提交触发");
//重置数据
//设置支付按钮可点击
var canClick = true;
var showToast = true;
_this.setData({ canClick, showToast })
wx.showToast({
icon: 'none',
title: '重复提交, 请3分钟后再试',
duration: 2000,
success: function(){
setTimeout(function(){
var showToast = false
_this.setData({ showToast })
}, 2000)
}
})
}
}
})
},
//跳转到首页
toHome: function (e) {
var _this = this;
......@@ -503,5 +588,63 @@ Page({
},
// 授权入口: 获取用户授权信息
// authStatus=='00'
// jscat 2020/11/18
onGetUserInfo: function(e)
{
var _this = this;
_this.getUserInfo()
},
getUserInfo() {
let _this = this;
//先设置点击按钮不可点击
var canClick = false;
_this.setData({ canClick })
config.debug==1?console.log("===getUserInfo"):""
// 获取用户信息
wx.getSetting({
success(res) {
config.debug == 1 ? console.log("===getUserInfo_res_" + res) : ""
if (res.authSetting['scope.userInfo']) { // 判断获取用户信息是否授权
config.debug == 1 ? console.log("已授权=====") : ""
// 已经授权, 可以直接调用 getUserInfo 获取用户信息
let promise_login = new Promise(function (resolve, reject) {
app.login(resolve, reject)
})
promise_login.then(
function (value) {
console.log("===enter promise_login then_pass_" + value)
_this.toPay_ok()
},
function (value) {
console.log("===enter promise_login then_failed_" + value)
});
} else {
config.debug == 1 ? console.log("未授权=====") : ""
//再设置支付按钮可点击
var canClick = true;
_this.setData({ canClick })
// 无法重新进行授权; jscat 20200901
// 因为 openSetting:fail can only be invoked by user TAP gesture.
wx.showModal({
title: '授权提示',
content: '活动预订需要您的授权哦'
})
}
}
})
},
})
\ No newline at end of file
......@@ -71,14 +71,22 @@
<button class="button-red" bindtap="toBuy">立即购买</button>
</view>
</view> -->
<!-- toOrder 仅仅是先预定 -->
<!--
toOrder 仅仅是先预定
refer activity-submit.wxml
-->
<view class="weui-tabbar__item">
<view class="note-row align" style="margin-bottom:0; justify-content: flex-end">
<view style="font-size:30rpx;margin-right:20rpx;color:#000">合计:
<text style="color:#FF6600">¥{{totalPrice}}</text>
</view>
<view style="width:200rpx">
<button class="button-red" disabled="{{!canClick}}" bindtap="toPay">确定({{totalCount}})</button>
<block wx:if="{{authStatus=='00'}}">
<button class="button-red" disabled="{{!canClick}}" open-type="getUserInfo" bindgetuserinfo="onGetUserInfo">授权&确定</button>
</block>
<block wx:else>
<button class="button-red" disabled="{{!canClick}}" bindtap="toPay_ok">确定({{totalCount}})</button>
</block>
</view>
</view>
</view>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论