支付订单逻辑整理完毕
parent
e7755657fd
commit
a8400f9d95
|
|
@ -116,7 +116,12 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { getGuildStoreDetail, getGuildCoupon, getPaySign } from "@/api/service";
|
||||
import {
|
||||
getGuildStoreDetail,
|
||||
getGuildCoupon,
|
||||
getPaySign,
|
||||
appBuy,
|
||||
} from "@/api/service";
|
||||
import NavHeader from "@/components/NavHeader/NavHeader.vue";
|
||||
|
||||
export default {
|
||||
|
|
@ -329,40 +334,77 @@ export default {
|
|||
});
|
||||
return;
|
||||
}
|
||||
//
|
||||
//
|
||||
// 把选中的数据拼接成这样的数据 couponId:num;couponId:num 例如 2324:1;2325:2
|
||||
const couponStr = selectedItems
|
||||
.map((item) => `${item.couponId}:${item.quantity}`)
|
||||
.map((item) => `${item.id}:${item.quantity}`)
|
||||
.join(";");
|
||||
|
||||
// this.totalAmount 是元, 要转换成分
|
||||
const trxamt = (this.totalAmount * 100).toFixed(0);
|
||||
|
||||
|
||||
|
||||
// this.totalAmount 是元, 要转换成分
|
||||
const trxamt = (this.totalAmount * 100).toFixed(0);
|
||||
|
||||
console.log("购买信息: " + couponStr);
|
||||
console.log("金额:" + trxamt);
|
||||
const res = await appBuy({
|
||||
shopId: this.shopId,
|
||||
couponData: couponStr,
|
||||
payableAmount: trxamt,
|
||||
});
|
||||
console.log(res);
|
||||
if (!res) {
|
||||
uni.showToast({
|
||||
title: "购买失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
// 调用支付信息 res 为订单信息
|
||||
this.handlePay(res);
|
||||
},
|
||||
// 支付调用
|
||||
async handlePay(){
|
||||
// 测试支付进行
|
||||
const reqsn =
|
||||
"mini" + Date.now() + "" + Math.floor(Math.random() * 10000);
|
||||
async handlePay(order) {
|
||||
// 测试支付进行
|
||||
// const reqsn =
|
||||
// "mini" + Date.now() + "" + Math.floor(Math.random() * 10000);
|
||||
|
||||
const couponArray = order.couponPurchaseRespVOS || [];
|
||||
const couponMap = new Map();
|
||||
|
||||
couponArray.forEach((item) => {
|
||||
const key = item.couponId;
|
||||
if (!key) return;
|
||||
|
||||
// 从 Map 中获取已有数组,没有则取空数组
|
||||
const currentList = couponMap.get(key) || [];
|
||||
currentList.push(item);
|
||||
// 更新 Map 中的值
|
||||
couponMap.set(key, currentList);
|
||||
});
|
||||
let bodyStr = ''
|
||||
couponMap.forEach((couponList, couponId) => {
|
||||
console.log(`优惠券ID:${couponId}`);
|
||||
console.log(`优惠券列表:`, couponList);
|
||||
bodyStr = bodyStr + couponList[0].couponName + 'x' + couponList.length + ';';
|
||||
});
|
||||
|
||||
const randomstr = Math.floor(Math.random() * 10000000) + "";
|
||||
// 定义请求参数
|
||||
// 仅排序,不修改任何字段值,参考对象中没有的字段放在最后
|
||||
// 注意参数 所有参数的类型用STring 不然会造成意外的报错,
|
||||
let params = {
|
||||
appid: "00390105", // 平台分配的appid
|
||||
body: "body订单标题", //
|
||||
body: bodyStr, //
|
||||
cusid: "56479107531MPMN", // 平台分配的商户号
|
||||
notify_url:
|
||||
"http://e989c692.natappfree.cc/admin-api/member/labor-union-coupon-purchase/tlNotice", // 保持原值不变
|
||||
orgid: "56479107392N35H",
|
||||
paytype: "W06",
|
||||
randomstr: randomstr,
|
||||
remark: "remark备注",
|
||||
reqsn: reqsn,
|
||||
remark: order.orderNumber+ ":" + bodyStr,
|
||||
reqsn: order.orderNumber,
|
||||
sign: "",
|
||||
signtype: "RSA",
|
||||
trxamt: "1",
|
||||
// trxamt: "" + order.payableAmount,
|
||||
trxamt: "1",// 测试金额 生产 是上面那条
|
||||
version: "12",
|
||||
//"asinfo":"56479107392MP4J:01:0.01" //(后台已经设置固定比例, 会自动分账) 分账, 第一个是分账商户号,第二个是01 类型, 根据金额分账,0.01 元
|
||||
};
|
||||
|
|
@ -370,10 +412,6 @@ export default {
|
|||
const sign = await getPaySign(params);
|
||||
console.log("测试返回的签名:" + sign);
|
||||
params["sign"] = sign;
|
||||
|
||||
console.log(params);
|
||||
// params = this.sortObjectByKey(params);
|
||||
console.log(params);
|
||||
// 统一使用 navigateToMiniProgram 跳转小程序
|
||||
uni.navigateToMiniProgram({
|
||||
appId: "wxef277996acc166c3", // 目标小程序appid
|
||||
|
|
@ -395,7 +433,7 @@ export default {
|
|||
});
|
||||
|
||||
//---- 支付
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue