This commit is contained in:
@fawn-nine
2023-05-18 13:23:11 +08:00
parent db2beb84e5
commit 078aa9af06
113 changed files with 17985 additions and 288 deletions

View File

@@ -57,8 +57,7 @@
<image src="../../static/icon/midBtn_06.png" mode="aspectFit"></image>
</view>
</view>
</view>
<view class="head_line" v-if="seckillList!=null">
<b></b>
<text>商品秒杀</text>
@@ -190,9 +189,22 @@
</template>
<script>
import repciptData from '@/static/json/repcipt.json'
import $http from '@/config/requestConfig.js';
import {
mapState,mapMutations
} from 'vuex';
export default {
data() {
return {
transaction: { // 成功回调
},
maxTimes:1, // 轮询最大次数
ComplateRequestInterval:null, // 轮询定时器
checking:false, // 正在检测
ComplateRequestArr:[],
iapChannel:null,
scrollTop: 0,
list3: [
// '../../static/icon/home_ban_1.jpg',
@@ -205,7 +217,7 @@
seckillList: [],
goodsList: [],
bgiStyle: {
background: '#2ab58833'
background: '#2ab588'
},
iconStyle: {
fontSize: '40rpx',
@@ -221,18 +233,25 @@
onLoad(e) {
// 隐藏原生的tabbar
uni.hideTabBar();
// this.requestIapOrder()
},
//页面显示
onShow() {
// 隐藏原生的tabbar
uni.hideTabBar();
this.getData();
this.getData();
},
// 页面加载完毕
onReady() {
this.requestIapOrder()
},
// 下拉刷新
onPullDownRefresh() {
this.getData()
uni.stopPullDownRefresh()
this.requestIapOrder()
},
@@ -249,9 +268,177 @@
return value
},
},
computed: {
...mapState(['userInfo']),
},
//方法
methods: {
...mapMutations(['setUserInfo']),
// 检测未完成订单
requestIapOrder(){
console.log('检测支付环境...')
plus.payment.getChannels((channels) => {
console.log(channels, 'channels')
for (var i in channels) {
// 判断是否苹果支付1
if (channels[i].id === 'appleiap') {
this.iapChannel = channels[i]
// console.log(this.userInfo.restoreFlag,'this.userInfo.restoreFlag')
if(this.userInfo.restoreFlag){ // 如果存在异常回调订单
this.restoreComplateRequest()
}
}
}
})
},
// 查询未关闭订单
restoreComplateRequest(){
let that = this
console.log('检测未完成订单')
console.log(this.iapChannel,'this.iapChannel')
this.iapChannel.restoreComplateRequest({
manualFinishTransaction: true
}, function(results) {
if(!that.checking){
that.checking = true
// console.log(that.checking)
// results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction通用需将返回的支付凭证传给后端进行二次认证
that.ComplateRequestArr = results
console.log(that.ComplateRequestArr,'未完成订单数组')
if(results && results.length>0){
// for(var j = 0; j<results.length; j++){
// if(results[j].transactionState == '1'){
// // 已经支付,但是没有走逻辑的内购订单
// that.iapCheck(results[j])
// // that.iapCheck(repciptData)
// }else{
// // 其他状态的内购订单 直接关闭
// that.finishTransaction(results[j])
// }
// }
results.map((item,index)=>{
// "0"为正在支付;"1"为支付成功;"2"为支付失败;"3"为支付已恢复。
if(item.transactionState == '1'){
// 已经支付,但是没有走逻辑的内购订单
that.iapCheck(item,index)
}else{
// 其他状态的内购订单
that.finishTransaction(item)
}
})
}
}
});
},
// 关闭交易订单
finishTransaction(trans,index){
this.iapChannel.finishTransaction(trans, (success) => {
console.log('关闭订单成功',index);
if(index == this.ComplateRequestArr.length-1){ // 最后一个支付订单
this.setUserInfo({restoreFlag:false});
// console.log(this.userInfo.restoreFlag,'this.ComplateRequestArr.length+++')
}
}, (fail) => {
console.log('关闭订单失败');
});
},
iapCheck(result,index) {
const that = this
console.log('进入后台验证')
let data = {
transactionId: result.transactionIdentifier, // 支付交易id
customerOid: that.userInfo.id,
productId: result.payment.productid, // 产品id
orderId: result.payment.username, // 系统订单号
receiptData: result.transactionReceipt ,// 苹果返回收据
loadAnimate:'none', // 请求加载动画
}
console.log(data,'data')
$http.request({
url: "/Ipa/veri",
method: "POST", // POST、GET、PUT、DELETE具体说明查看官方文档
data,
header: { //默认 无 说明:请求头
'Content-Type': 'application/json'
},
}).then(res => {
console.log(JSON.stringify(res))
console.log(res.code)
if(res.code == 0){
// uni.hideLoading()
console.log('充值订单已处理,请留意账户金额变动....')
// 服务器验证票据有效后在客户端关闭订单
that.finishTransaction(result,index)
}else if(res.code == 200){ // 重复验证订单
console.log('重复验证....')
that.finishTransaction(result,index)
}
}).catch(e => {
console.log('支付验证失败,进入轮询程序...')
that.getIapPayResult(result,index)
})
console.log('--------------')
},
// 轮询验证支付结果
getIapPayResult(result,index){
// let interval = null
this.ComplateRequestInterval = setTimeout(() => {
if(this.maxTimes <= 3){
this.iapCheck(result,index)
console.log('执行1', this.maxTimes,this.ComplateRequestInterval)
this.maxTimes += 1
}else{
this.maxTimes = 0
console.log('停止轮询', this.maxTimes,this.ComplateRequestInterval, this.maxTimes)
this.checking = false
this.saveErrorIapOrder(result,index)
clearTimeout(this.ComplateRequestInterval)
}
},10000)
},
// 轮询失败接口
saveErrorIapOrder(result,index){
console.log('提交到充值问题单里面...')
let data = {
transactionId : result.transactionIdentifier,
failureflag: 1,
orderId:result.payment.username,
receiptData:result.transactionReceipt,
productId:result.payment.productid,
customerOid:this.userInfo.id
}
console.log(data,'data')
$http.request({
url: "Ipa/failure",
method: "POST", // POST、GET、PUT、DELETE具体说明查看官方文档
data,
header: { //默认 无 说明:请求头
'Content-Type': 'application/json'
},
}).then(res => {
console.log(JSON.stringify(res))
if(res.code == 200){
console.log('提交成功,关闭订单')
this.finishTransaction(result,index)
}
}).catch(e => {
console.log(e)
if(e.statusCode == 0){ // 重复提交,直接关闭订单
this.finishTransaction(result,index)
}
})
},
// 获取列表数据
getData() {
this.$http
@@ -266,8 +453,8 @@
this.$http
.get(`book/shopseckill/getSeckillProd`)
.then(res => {
//this.seckillList = res.list
this.seckillList = null
this.seckillList = res.list
// this.seckillList = null
})
// 获取精选商品