代码更新

This commit is contained in:
GaoHao
2025-03-10 09:14:57 +08:00
parent 4f65b08c06
commit 490c513f48
48 changed files with 1162 additions and 537 deletions

View File

@@ -99,7 +99,19 @@
<text class="u-m-l-10 no-wrap">{{item.payName}}</text>
</view>
<view class="u-flex color-999 u-font-24">
<view class="u-m-r-20" v-if="item.payType=='virtual'&&pageData.user.id"
<view class="u-m-r-20" v-if="item.payType=='virtual'&&pageData.buyer.id"
@click.stop="chooseBuyer">
<view>
<text>挂账人</text>
<text class="u-m-r-4">{{pageData.buyer.debtor}}</text>
</view>
<view>
<text>挂账额度</text>
<text>{{pageData.buyer.creditAmount||'0'}}</text>
</view>
</view>
<view class="u-m-r-20" v-if="item.payType=='member-account'&&pageData.user.id"
@click.stop="chooseUser">
<view>
<text>会员</text>
@@ -228,7 +240,6 @@
import { reactive, onMounted, watch, ref, onBeforeUnmount, computed } from 'vue';
import { onLoad, onBackPress, onShow } from '@dcloudio/uni-app'
import go from '@/commons/utils/go.js'
import * as Api from '@/http/yskApi/Instead.js'
import { hasPermission } from '@/commons/utils/hasPermission.js'
import infoBox from '@/commons/utils/infoBox.js'
@@ -244,8 +255,9 @@
import { getCouponList } from '@/api/coupon.js'
import { getHistoryOrder } from '@/api/order.js'
import { getPayTypeList } from '@/api/payType.js'
import { cashPay,vipPay,getOrderPayUrl } from '@/api/pay.js'
import { scanPay,microPay,cashPay,vipPay,creditPay,getOrderPayUrl } from '@/api/pay.js'
import { shopUserDetail } from '@/api/shopUser.js'
import { calcUsablePoints,calcDeductionAmount,payedDeductPoints,consumeAwardPoints } from '@/api/points.js'
const modal = reactive({
@@ -265,7 +277,8 @@
user: { //会员信息
userId: null,
amount: 0
}
},
buyer: {}
})
const order = reactive({
orderAmount: 0
@@ -279,7 +292,8 @@
list: [],
selIndex: 0
},
quan: []
quan: [],
seatNum: 0
})
//打折相关数据
const discount = reactive({
@@ -305,6 +319,7 @@
let payCodeUrl = ref('') //收款二维码地址
onShow(() => {
watchChooseuser()
watchChoosebuyer()
watchChooseQuan()
})
onLoad(async (opt) => {
@@ -345,19 +360,20 @@
setQuan([...fullReductionCoupon, ...productCoupon])
// 获取用户信息
console.log(order.userId)
console.log(!pageData.user.userId)
if (order.userId&&!pageData.user.userId) {
calcUsablePoints()
if (orderRes.pointsNum) {
accountPoints.sel = true
}
console.log("pageData.user===",pageData.user)
if (order.userId||pageData.user.userId) {
shopUserDetail({
userId: order.userId || pageData.user.userId
}).then(res => {
pageData.user = res
getCalcUsablePoints()
if (orderRes.pointsNum) {
accountPoints.sel = true
}
})
}
pageData.seatNum = order.tableId!=null&&order.tableId!="undefined" ? order.seatNum : 0;
}
const coupAllPrice = computed(() => {
const n = pays.quan.reduce((prve, cur) => {
@@ -383,13 +399,12 @@
* 订单金额
*/
const originPrice = computed(() => {
console.log(order)
console.log(packAmount)
console.log("order===",order)
if(pageData.goodsList){
let goodsPrice = pageData.goodsList.filter(v => v.price != 0 && v.status !== "return").reduce((a, b) => {
return a + (b.num * b.price)
}, 0)
return (goodsPrice + order.seatNum + packAmount.value).toFixed(2)
return (goodsPrice + (pageData.seatNum||0) + packAmount.value).toFixed(2)
}
})
@@ -462,6 +477,16 @@
console.log("accountPoints===",accountPoints)
let total = (originPrice.value*1) - discountSaleAmount.value - (vipDiscount.value*1) - productCouponDiscountAmount.value - discount
.value - fullCouponDiscountAmount.value - accountPoints.price * (accountPoints.sel ? 1 : 0)
console.log("payPrice===",total)
return (total < 0 ? 0 : total).toFixed(2)
})
/**
* 积分使用前金额
*/
const orderAmount = computed(() => {
let total = (originPrice.value*1) - discountSaleAmount.value - (vipDiscount.value*1) - productCouponDiscountAmount.value - discount
.value - fullCouponDiscountAmount.value
console.log(total)
return (total < 0 ? 0 : total).toFixed(2)
})
@@ -473,12 +498,14 @@
}
})
watch(() => pointCanDicountPrice.value, (newval) => {
calcUsablePoints()
if( pageData.user.id ){
getCalcUsablePoints()
}
})
watch(() => payPrice.value, (newval) => {
getPayUrl()
if (newval <= 0) {
const arr = ['cash', 'virtual']
const arr = ['cash', 'member-account']
pays.payTypes.list.map(v => {
if (arr.includes(v.payType)) {
v.disabled = false
@@ -514,27 +541,37 @@
}, 2000)
}
})
function getPayParam () {
return {
shopId: uni.getStorageSync("shopInfo").id,
orderId: order.id,
originAmount: originPrice.value, //订单原金额(包含打包费+餐位费) 不含折扣价格
orderAmount: payPrice.value, // 订单金额
seatNum: pageData.seatNum, // 用餐人数
discountAmount: discount.value, // 手动优惠金额
fullCouponDiscountAmount: fullCouponDiscountAmount.value, // 满减金额
vipPrice: vipDiscount.value != 0 ? 1: 0, // 是否使用会员价
pointsDiscountAmount: accountPoints.sel ? accountPoints.price : 0,
pointsNum: accountPoints.sel ? accountPoints.num : 0,
}
}
/**
* 获取店铺订单支付URL
*/
function getPayUrl() {
console.log(vipDiscount.value)
let par = {
console.log(discount)
console.log(getPayParam())
let par = getPayParam()
let params = {
shopId: uni.getStorageSync("shopInfo").id,
orderId: order.id,
orderAmount: payPrice.value,
seatNum: order.seatNum, // 用餐人数
discountRatio: (discount.discount/100).toFixed(0), // 折扣比例
discountAmount: discount.value, // 手动优惠金额
fullCouponDiscountAmount: fullCouponDiscountAmount.value, // 满减金额
pointsNum: accountPoints.sel ? accountPoints.num : 0,
vipPrice: vipDiscount.value > 0 ? 1: 0, // 是否使用会员价
...par
}
if( order.userId||pageData.user.userId ){
par.userId = order.userId||pageData.user.userId
params.userId = order.userId||pageData.user.userId
}
getOrderPayUrl(par).then(res => {
getOrderPayUrl(params).then(res => {
payCodeUrl.value = res
})
}
@@ -545,10 +582,14 @@
*/
async function getPayType() {
const payTypeList = await getPayTypeList()
pays.payTypes.list = payTypeList.map(v => {
return {
...v,
disabled: false
pays.payTypes.list = [];
payTypeList.map(v => {
if( v.payType != 'bank'){
pays.payTypes.list.push({
...v,
disabled: false
})
}
})
}
@@ -558,13 +599,12 @@
* @param {Object} arr
*/
function setQuan(arr) {
console.log(arr);
console.log("choose-quan===",arr)
discount.discount = 100
discount.value = 0
discount.currentPrice = order.orderAmount
const manjianCoup = arr.filter(v => v.type == 1 && v.number >= 1)
let productCoup = arr.filter(v => v.type == 2)
console.log(productCoup);
//商品券分组
let coupMap = {}
for (let i in productCoup) {
@@ -575,7 +615,6 @@
coupMap[coup.proId] = [coup]
}
}
console.log(coupMap);
for (let key in coupMap) {
const arr = coupMap[key]
for (let i in arr) {
@@ -594,9 +633,7 @@
}
}
productCoup = productCoup.filter(v => v.number >= 1)
console.log(productCoup);
pays.quan = [...manjianCoup, ...productCoup]
console.log(pays.quan);
}
@@ -625,12 +662,18 @@
function pointsConfirm(e) {
accountPoints.num = e
}
async function calcUsablePoints(orderAmount) {
/**
* 获取积分信息
* @param {Object} orderAmount
*/
async function getCalcUsablePoints(orderAmount) {
if (!order.userId&&!pageData.user.userId) {
return
}
const res = await Api.$calcUsablePoints({
userId: order.userId||pageData.user.userId,
console.log("calcUsablePoints",pageData.user)
const res = await calcUsablePoints({
userId: pageData.user.id,
orderAmount: orderAmount ? orderAmount : payPrice.value
})
accountPoints.calcRes = res
@@ -643,9 +686,9 @@
accountPoints.price = 0
return ''
}
const res = await Api.$calcDeDuctionPoints({
userId: order.userId||pageData.user.userId,
orderAmount: originPrice.value,
const res = await calcDeductionAmount({
userId: pageData.user.id,
orderAmount: orderAmount.value,
points: accountPoints.num
})
if (res) {
@@ -733,6 +776,25 @@
})
}
/**
* 选择挂账人
*/
function chooseBuyer() {
go.to('PAGES_CHOOSE_BUYER')
}
/**
* 更新选择挂账人
*/
function watchChoosebuyer() {
uni.$off('choose-buyer')
uni.$on('choose-buyer', (data) => {
console.log(data);
pageData.buyer = data
})
}
/**
* 修改价格确认
* @param {Object} form
@@ -768,9 +830,13 @@
pays.payTypes.selIndex = i
console.log(item.payType)
console.log(pageData.user.id)
if (item.payType == 'virtual' && !pageData.user.id) {
if (item.payType == 'member-account' && !pageData.user.id) {
chooseUser()
}
if (item.payType == 'virtual' && !pageData.buyer.id) {
chooseBuyer()
}
}
@@ -799,13 +865,16 @@
function payOrderClick() {
const payType = pays.payTypes.list[pays.payTypes.selIndex].payType
console.log(payType);
if (payType == 'scanCode' || payType == 'deposit' || payType == 'bank') {
if (payType == 'scanCode' || payType == 'deposit') {
return saomaPay(payType)
}
if (payType == 'cash' && payPrice.value * 1 > 0) {
return cashConfirmShow()
}
if (payType == 'virtual' && pageData.user.amount * 1 < order.orderAmount * 1) {
if (payType == 'virtual') {
// return cashConfirmShow()
}
if (payType == 'member-account' && pageData.user.amount * 1 < payPrice.value * 1) {
infoBox.showToast('余额不足')
return
}
@@ -826,55 +895,60 @@
*/
async function pay(par) {
const payType = pays.payTypes.list[pays.payTypes.selIndex].payType
let pars = getPayParam()
console.log(payType)
console.log(discount)
payStatus = 'paying'
let params = {
shopId: uni.getStorageSync("shopInfo").id,
checkOrderPay: {
orderId: order.id || order.orderId,
seatNum: order.seatNum, // 用餐人数
discountRatio: (discount.discount/100).toFixed(0), // 折扣比例
discountAmount: discount.value, // 手动优惠金额
fullCouponDiscountAmount: fullCouponDiscountAmount.value, // 满减金额
orderAmount: payPrice.value, // 订单金额
vipPrice: vipDiscount.value > 0 ? 1: 0, // 是否使用会员价
pointsNum: accountPoints.sel ? accountPoints.num : 0,
couponList: pays.quan.map(v => {
return {
userCouponId: v.id,
num: v.number
}
}),
...par
...pars
},
...par
}
if( order.userId||pageData.user.userId ){
params.checkOrderPay.userId = order.userId||pageData.user.userId
}
if( payType == 'virtual' ){
params.creditBuyerId = pageData.buyer.id
}
console.log(params)
if (payType == 'scanCode' || payType == 'deposit' || payType == 'bank') {
}
if (payType == 'cash' && payPrice.value * 1 > 0) {
try {
try {
if (payType == 'scanCode') {
await microPay(params)
}
if (payType == 'cash') {
await cashPay(params)
} catch (error) {
payStatus = '';
return false;
}
}
if (payType == 'virtual' && pageData.user.amount * 1 > order.orderAmount * 1) {
params.payType = 'userPay'
params.shopUserId = pageData.user.id
try {
await vipPay(params)
} catch (error) {
payStatus = '';
return false;
if (payType == 'virtual') {
await creditPay(params)
}
if( payType == 'member-account' || payType == 'deposit' ) {
if (pageData.user.amount * 1 >= payPrice.value * 1) {
params.payType = 'userPay'
params.shopUserId = pageData.user.id
await vipPay(params)
} else {
infoBox.showToast('余额不足')
return
}
}
} catch (error) {
payStatus = '';
return false;
}
paySuccess()
}