后置付费

This commit is contained in:
2025-06-03 09:48:31 +08:00
parent 5205361ac0
commit 3b311aa292
5 changed files with 295 additions and 17 deletions

View File

@@ -21,14 +21,28 @@
</view>
<view class="box_show" v-if="!wait">
<image class="showImage" :src="showImage" mode="aspectFill" @tap="previewImage(showImage)"/>
<image class="image-sy" v-if="template.paymentType == 3 && template.fee != 0 && !isPay"
src="https://humeng-res.oss-cn-beijing.aliyuncs.com/humeng/vlog/whiteboard_portraitmode.png" mode="aspectFill"></image>
<view class="printTip" v-if="buyType == 2">{{ printScreenTip }}</view>
<view class="upload-btn" @tap="saveImage()">保存到手机</view>
<view class="upload-btn" v-if="template.paymentType != 3" @tap="saveImage()">保存到手机</view>
<view class="btn_content" v-if="template.paymentType == 3 && template.fee != 0">
<view class="buyBtn" v-if="!isPay" @tap="toPay()">
{{template.fee}}购买高清版
</view>
<view class="buyBtn" v-if="isPay" @tap="saveImage()">
保存到手机
</view>
<view class="skipBtn" @tap="jumpApplet()">
去定制
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import { mul } from "@/utils/calculate/calculate.js"
const getNowTime = require('../../utils/timeUtil/timeUtil.js')
let pageNumber = 4;
let startTime = '';
@@ -49,7 +63,14 @@
downloading: false,
buyType: 0,
printCode: '',
printScreenTip: ''
printScreenTip: '',
template: {},
templateSet: {},
payId: '',
isPay: false,
record: {},
templateSetId: '',
isOnUnload: 0
}
},
onLoad(option) {
@@ -61,25 +82,187 @@
this.uniMenuInfo = uni.getStorageSync('uniMenuInfo');
this.code = option.code;
this.templateId = Number(option.templateId);
this.templateSetId = Number(option.templateSetId);
this.mchId = Number(option.mchId);
this.buyType = Number(option.buyType);
this.firstGetPhoto(_this.code);
this.getPhoto(this.code);
if(option.myPhoto == "1") {
this.wait = false
this.record = uni.getStorageSync('record')
this.isPay = this.record.payId != "-1"
this.showImage = 'https://oss.humengfilms.com/' + this.record.aiPhoto;
if(this.record.printCode != null) {
_this.printCode = this.record.printCode;
let text = _this.template.printScreenTip;
_this.printScreenTip = text.replace("*", resData.printCode);
}
} else {
this.getPhotoGenerationRecord();
this.firstGetPhoto(_this.code);
this.getPhoto(this.code);
}
this.getTemplate(this.templateId)
this.getTemplateSet(this.templateSetId);
},
onShow() {
startTime = getNowTime();
},
onHide() {
console.log('onHide')
if(uni.getStorageSync('userInfo').id) {
this.logRecord();
}
},
onUnload() {
this.isOnUnload = 1
if(uni.getStorageSync('userInfo').id) {
this.logRecord();
}
},
methods: {
getTemplateSet(id) {
var _this = this;
uni.request({
url: _this.java_http_url + '/aiweb/templateSet/getTemplateSetById',
method: "POST",
header: {
'content-type': "application/x-www-form-urlencoded"
},
data: {
id: id
},
success(res) {
_this.templateSet = res.data.data
}
})
},
getTemplate(id) {
var _this = this;
uni.request({
url: _this.java_http_url + '/aiweb/sdTemplate/getSdTemplateById',
method: "POST",
data: {
id: id
},
success(res) {
_this.template = res.data.data
}
})
},
recordBindPayId(payId) {
var _this = this;
uni.request({
url: _this.java_http_url + '/applet/photo_generation_record/updateRecord',
method: 'POST',
data: {
id: _this.record.id,
payId: payId
},
success(res) {
console.log('payIdRes:', res)
}
})
},
getPhotoGenerationRecord() {
var _this = this;
uni.request({
url: _this.java_http_url + '/applet/photo_generation_record/getRecordByCode',
method: 'POST',
data: {
userId: uni.getStorageSync('userInfo').id,
code: _this.code,
},
success(res) {
console.log('res:', res)
_this.record = res.data.data
}
})
},
toPay(e) {
uni.showLoading({
title: '请稍候',
mask: true
})
var _this = this;
let totalFee = mul(_this.template.fee, 100);
let triesLimit = 1;
let data = {
open_id: uni.getStorageSync('userInfo').openId,
user_id: uni.getStorageSync('userInfo').id,
total_fee: totalFee,
merchant_id: _this.templateSet.mchId,
template_id: _this.template.id,
template_name: _this.template.templateName,
payment_type: _this.template.paymentType,
tries_limit: triesLimit
};
console.log('支付参数', data)
if (e != 0) {
console.log('data', data)
uni.request({
url: _this.pay_http_url + '/wxpay/pay',
method: 'POST',
data: data,
success: res => {
console.log('pay request success', res);
if (res.statusCode !== 200) {
uni.showModal({
content: '支付失败,请重试!',
showCancel: false,
success() {
uni.hideLoading();
}
});
} else {
if (res.data.code == 'pay') {
console.log('res', res.data)
let payId = res.data.order_id;
uni.requestPayment({
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: 'MD5',
paySign: res.data.paySign,
success: res => {
console.log('res', res)
_this.payId = payId;
_this.isPay = true;
console.log('支付成功')
_this.recordBindPayId(payId);
uni.hideLoading()
},
fail() {
uni.hideLoading()
}
})
}
}
},
fail() {
uni.hideLoading();
uni.showToast({
title: '支付失败',
icon: "error",
mask: true
})
}
})
}
},
jumpApplet() {
wx.navigateToMiniProgram({
appId: 'wx1aee6186e7cfd004',
path: 'pages/home/home?aid=33304411&yid=1&storeId=1&_r=1',
//develop开发版trial体验版release正式版
envVersion: 'release',
success(res) {
// 打开成功
console.log("跳转小程序成功!",res);
},
fail(err) {
console.log('跳转失败', err)
}
})
},
logRecord() {
var _this = this;
destroyTime = getNowTime();
@@ -224,6 +407,9 @@
pageNumber = 5;
_this.wait = false;
}
if(_this.isOnUnload == 1) {
clearInterval(stateInterval)
}
}
}
})