修改订单支付详情优惠券积分等逻辑

This commit is contained in:
2024-11-22 14:41:13 +08:00
parent b69159d965
commit 70933ce1e4
6 changed files with 149 additions and 82 deletions

View File

@@ -126,8 +126,8 @@
function open() { function open() {
model.value.open() model.value.open()
form.price=props.price form.price=props.price
form.currentPrice=props.price
form.discount=props.discount form.discount=props.discount
form.currentPrice=(props.discount*props.price/100).toFixed(2)
} }
function close() { function close() {

View File

@@ -17,10 +17,10 @@ import infoBox from "@/commons/utils/infoBox.js"
import go from '@/commons/utils/go.js'; import go from '@/commons/utils/go.js';
import { reject } from 'lodash'; import { reject } from 'lodash';
// 测试服 // 测试服
// let baseUrl = 'https://admintestpapi.sxczgkj.cn' let baseUrl = 'https://admintestpapi.sxczgkj.cn'
//预发布 //预发布
let baseUrl = 'https://pre-cashieradmin.sxczgkj.cn' // let baseUrl = 'https://pre-cashieradmin.sxczgkj.cn'
//正式 //正式
// let baseUrl = 'https://cashieradmin.sxczgkj.cn' // let baseUrl = 'https://cashieradmin.sxczgkj.cn'

View File

@@ -38,7 +38,7 @@
</uni-tag> </uni-tag>
</view> </view>
<view class="u-m-r-20 u-flex " v-if="item.userCouponId"> <view class="u-m-r-20 u-flex " v-if="item.userCouponId">
<uni-tag :text="'商品券抵扣'+item.priceAmount" <uni-tag :text=" productCouponDikou(item)"
custom-style="background-color: #FFF0DF; border-color: #FFF0DF; color: #FF9F2E;"> custom-style="background-color: #FFF0DF; border-color: #FFF0DF; color: #FF9F2E;">
</uni-tag> </uni-tag>
</view> </view>
@@ -58,7 +58,7 @@
<view class="u-text-right u-m-t-28"> <view class="u-text-right u-m-t-28">
<template v-if="isTui(item)"> <template v-if="isTui(item)">
<view>0.00</view> <view>0.00</view>
<view class="line-th color-666 " >{{returnTotalMoney(item)}} <view class="line-th color-666 ">{{returnTotalMoney(item)}}
</view> </view>
</template> </template>
<template v-else-if="isGift(item)||item.userCouponId"> <template v-else-if="isGift(item)||item.userCouponId">
@@ -67,9 +67,8 @@
</view> </view>
</template> </template>
<template v-else> <template v-else>
<template <template v-if="returnCanTuiMoney(item)*1!=returnTotalMoney(item)*1">
v-if="item.priceAmount*1!=returnTotalMoney(item)*1"> <view>{{returnCanTuiMoney(item)}}</view>
<view>{{item.priceAmount}}</view>
<view class=" color-666 line-th"> <view class=" color-666 line-th">
{{returnTotalMoney(item)}}</view> {{returnTotalMoney(item)}}</view>
</template> </template>
@@ -214,14 +213,21 @@
<text>{{to2(orderInfo.fullCouponDiscountAmount) }}</text> <text>{{to2(orderInfo.fullCouponDiscountAmount) }}</text>
</view> </view>
</view> </view>
<view class="u-flex u-row-between u-m-t-18" <view class="u-flex u-row-between u-m-t-18" v-if="productCouponDiscountAmount*1>0">
<view>商品券抵扣</view>
<view class="color-red">
<text></text>
<text> {{productCouponDiscountAmount }}</text>
</view>
</view>
<!-- <view class="u-flex u-row-between u-m-t-18"
v-if="orderInfo.productCouponDiscountAmount||productCoupPrice*1>0"> v-if="orderInfo.productCouponDiscountAmount||productCoupPrice*1>0">
<view>商品券抵扣</view> <view>商品券抵扣</view>
<view class="color-red"> <view class="color-red">
<text></text> <text></text>
<text> {{to2(orderInfo.productCouponDiscountAmount||productCoupPrice) }}</text> <text> {{to2(orderInfo.productCouponDiscountAmount||productCoupPrice) }}</text>
</view> </view>
</view> </view> -->
<view class="u-flex u-row-between u-m-t-18" v-if="orderInfo.pointsDiscountAmount"> <view class="u-flex u-row-between u-m-t-18" v-if="orderInfo.pointsDiscountAmount">
<view>积分抵扣</view> <view>积分抵扣</view>
<view class="color-red"> <view class="color-red">
@@ -261,6 +267,10 @@
pop.youhui = true pop.youhui = true
} }
function productCouponDikou(item) {
return '商品券抵扣¥' + returnProductCoupPrice(item)
}
function youhuiDetailHide() { function youhuiDetailHide() {
pop.youhui = false pop.youhui = false
} }
@@ -287,6 +297,30 @@
} }
} }
}) })
function returnProductCoupPrice(item) {
if (!item.isMember) {
return item.price * item.num
}
const price = item.memberPrice ? item.memberPrice : item.price
return price * item.num
}
const productCouponDiscountAmount = computed(() => {
// if(props.orderInfo.productCouponDiscountAmount){
// return orderInfo.productCouponDiscountAmount.toFixed(2)
// }
if (!props.data.length) {
return 0
}
const n = props.data.reduce((prve, cur) => {
const curTotal = cur.info.filter(v => v.userCouponId).reduce((a, b) => {
return a + returnProductCoupPrice(b)
}, 0)
return prve + curTotal
}, 0)
console.log(n);
return n.toFixed(2)
})
const emits = defineEmits(['tuicai', 'tuikuan', 'printOrder']) const emits = defineEmits(['tuicai', 'tuikuan', 'printOrder'])
function returnVipMoney(item) { function returnVipMoney(item) {
@@ -299,6 +333,21 @@
function returnTotalMoney(item) { function returnTotalMoney(item) {
return (item.price * item.num).toFixed(2) return (item.price * item.num).toFixed(2)
} }
const canTuiKuanPrice = computed(() => {
return props.data.reduce((prve,cur)=>{
const curTotal=cur.info.filter(v=>!v.userCouponId).reduce((a,b)=>{
return a+b.priceAmount*1
},0)
// const curTotal=cur.info.filter(v=>canTuiKuan(props.orderInfo,v)&&!v.userCouponId).reduce((a,b)=>{
// return a+b.priceAmount*1
// },0)
return prve+curTotal
},0)
})
function returnCanTuiMoney(item) {
return (item.priceAmount/canTuiKuanPrice.value*props.orderInfo.amount).toFixed(2)
}
function to2(n) { function to2(n) {
if (!n) { if (!n) {
@@ -314,7 +363,7 @@
function tuikuan(item, index) { function tuikuan(item, index) {
hasPermission('允许退款').then(res => { hasPermission('允许退款').then(res => {
if (res) { if (res) {
emits('tuikuan', item, index) emits('tuikuan', {...item,priceAmount:returnCanTuiMoney(item)}, index)
} }
}) })
} }
@@ -331,12 +380,12 @@
const n = props.seatFee.priceAmount * (isTui(props.seatFee) ? 0 : 1) const n = props.seatFee.priceAmount * (isTui(props.seatFee) ? 0 : 1)
return n.toFixed(2) return n.toFixed(2)
}) })
const discountAmount=computed(()=>{ const discountAmount = computed(() => {
if(props.orderInfo.discountAmount){ if (props.orderInfo.discountAmount) {
return props.orderInfo.discountAmount return props.orderInfo.discountAmount
} }
console.log(props.orderInfo.originAmount*(1-props.orderInfo.discountRatio)); console.log(props.orderInfo.originAmount * (1 - props.orderInfo.discountRatio));
return (props.orderInfo.originAmount*(1-props.orderInfo.discountRatio)) return (props.orderInfo.originAmount * (1 - props.orderInfo.discountRatio))
}) })
const goodsOriginAllPrice = computed(() => { const goodsOriginAllPrice = computed(() => {
const goodsPrice = props.data.reduce((prve, cur) => { const goodsPrice = props.data.reduce((prve, cur) => {
@@ -348,13 +397,8 @@
}, 0) }, 0)
return goodsPrice.toFixed(2) return goodsPrice.toFixed(2)
}) })
const canTuiKuanPrice=computed(()=>{
const discountAmount=props.orderInfo.originAmount||(100-props.orderInfo.discountRatio)*props.orderInfo.originAmount/100
const n= props.orderInfo.originAmount-discountAmount
console.log(n);
return m
})
const freePrice = computed(() => { const freePrice = computed(() => {
const goodsPrice = props.data.reduce((prve, cur) => { const goodsPrice = props.data.reduce((prve, cur) => {
@@ -372,7 +416,8 @@
return 0 return 0
} }
const goodsPrice = props.data.reduce((prve, cur) => { const goodsPrice = props.data.reduce((prve, cur) => {
const curTotal = cur.info.filter(v => v.gift != true && v.status !== "return" && (v.isMember && v.memberPrice) && (v.memberPrice != v.price)).reduce(( const curTotal = cur.info.filter(v => v.gift != true && v.status !== "return" && (v.isMember &&
v.memberPrice) && (v.memberPrice != v.price)).reduce((
a, a,
b) => { b) => {
return a + (b.num * (b.price - b.memberPrice)) return a + (b.num * (b.price - b.memberPrice))
@@ -402,7 +447,8 @@
const youhuiAllPrice = computed(() => { const youhuiAllPrice = computed(() => {
return (freePrice.value * 1 + vipDiscountPrice.value * 1 + props.orderInfo.fullCouponDiscountAmount + props return (freePrice.value * 1 + vipDiscountPrice.value * 1 + props.orderInfo.fullCouponDiscountAmount + props
.orderInfo.pointsDiscountAmount + productCoupPrice.value * 1 + (props.orderInfo.discountAmount || .orderInfo.pointsDiscountAmount + (props.orderInfo.status == 'unpaid' ? productCoupPrice.value :
productCouponDiscountAmount.value) * 1 + (props.orderInfo.discountAmount ||
0)).toFixed(2) 0)).toFixed(2)
@@ -419,8 +465,12 @@
}) })
const allPrice = computed(() => { const allPrice = computed(() => {
const n = goodsOriginAllPrice.value - youhuiAllPrice.value
return (n < 0 ? 0 : n).toFixed(2) if (props.orderInfo.status == 'unpaid') {
const n = goodsOriginAllPrice.value - youhuiAllPrice.value
return (n < 0 ? 0 : n).toFixed(2)
}
return props.orderInfo.amount
}) })
const goodsNumber = computed(() => { const goodsNumber = computed(() => {

View File

@@ -47,16 +47,9 @@
<view class="u-m-l-18 color-999">x{{item.num}}</view> <view class="u-m-l-18 color-999">x{{item.num}}</view>
</view> </view>
<view class="u-flex"> <view class="u-flex">
<template v-if="item.type==1"> <view class="color-red">
<view class="color-red"> -{{item.discountAmount}}
-{{item.discountAmount}} </view>
</view>
</template>
<template v-if="item.type==2">
<view class="color-red">
-{{(item.discountAmount*discount.discount/100).toFixed(2)}}
</view>
</template>
<view class="u-m-l-12" @click="delQuan(index)"> <view class="u-m-l-12" @click="delQuan(index)">
<up-icon :size="16" name="minus-circle-fill" color="rgb(255, 0, 0)"></up-icon> <up-icon :size="16" name="minus-circle-fill" color="rgb(255, 0, 0)"></up-icon>
</view> </view>
@@ -68,12 +61,11 @@
</view> </view>
<view class="border-bottom u-p-b-30" v-if="(discount.price&&discount.currentPrice!=order.amount)||accountPoints.sel"> <view class="border-bottom u-p-b-30" v-if="discount.value||accountPoints.sel">
<view class="u-flex u-p-l-24 u-p-r-24 u-row-between u-p-t-30 " <view class="u-flex u-p-l-24 u-p-r-24 u-row-between u-p-t-30 " v-if="discount.value">
v-if="discount.price&&discount.currentPrice!=order.amount">
<view>服务员改价</view> <view>服务员改价</view>
<view class=" u-flex u-col-center"> <view class=" u-flex u-col-center">
<text style="color: rgb(255, 95, 46);">-{{to2(order.amount- discount.currentPrice)}}</text> <text style="color: rgb(255, 95, 46);">-{{to2(discount.value)}}</text>
</view> </view>
</view> </view>
<view class="u-flex u-p-l-24 u-p-r-24 u-row-between u-p-t-30 " <view class="u-flex u-p-l-24 u-p-r-24 u-row-between u-p-t-30 "
@@ -210,7 +202,7 @@
<edit-discount @confirm="editDiscountConfirm" title="优惠金额" :ref="setModel" name="editMoney" <edit-discount @confirm="editDiscountConfirm" title="优惠金额" :ref="setModel" name="editMoney"
:price="order.amount"></edit-discount> :price="order.amount-productCouponDiscountAmount" :discount="discount.discount"></edit-discount>
<up-modal :title="modal.title" :content="modal.content" :show="modal.show" :confirmText="modal.confirmText" <up-modal :title="modal.title" :content="modal.content" :show="modal.show" :confirmText="modal.confirmText"
:cancelText="modal.cancelText" showCancelButton closeOnClickOverlay @confirm="confirmModelConfirm" :cancelText="modal.cancelText" showCancelButton closeOnClickOverlay @confirm="confirmModelConfirm"
@@ -265,15 +257,15 @@
}) })
function confirmModelCancel() { function confirmModelCancel() {
modal.show=false modal.show = false
modal.key='' modal.key = ''
modal.data='' modal.data = ''
} }
function cashConfirmShow() { function cashConfirmShow() {
modal.content = '是否确认已现金收款' + payPrice.value modal.content = '是否确认已现金收款' + payPrice.value
modal.key='cash' modal.key = 'cash'
modal.show=true modal.show = true
} }
async function confirmModelConfirm() { async function confirmModelConfirm() {
if (modal.key == 'cash') { if (modal.key == 'cash') {
@@ -318,7 +310,7 @@
} }
const res = await Api.$calcUsablePoints({ const res = await Api.$calcUsablePoints({
memberId: order.memberId, memberId: order.memberId,
orderAmount: pointCanDicountPrice.value orderAmount:payPrice.value
}) })
accountPoints.calcRes = res accountPoints.calcRes = res
accountPoints.num = res.maxUsablePoints accountPoints.num = res.maxUsablePoints
@@ -326,7 +318,7 @@
} }
watch(() => accountPoints.sel, (newval) => { watch(() => accountPoints.sel, (newval) => {
if (newval) { if (newval) {
calcUsablePoints() calcDeDuctionPoints()
} }
}) })
async function calcDeDuctionPoints() { async function calcDeDuctionPoints() {
@@ -366,8 +358,7 @@
go.to('PAGES_ORDER_QUAN', { go.to('PAGES_ORDER_QUAN', {
orderId: order.id, orderId: order.id,
memberId: order.memberId, memberId: order.memberId,
orderPrice: (payPrice.value * 1 + coupAllPrice.value * 1).toFixed(2), orderPrice: (payPrice.value * 1 + coupAllPrice.value * 1).toFixed(2)
discuount:discount.discount
}) })
} }
async function discountShow() { async function discountShow() {
@@ -406,7 +397,7 @@
if (!n) { if (!n) {
return '' return ''
} }
return n.toFixed(2) return Number(n).toFixed(2)
} }
const pays = reactive({ const pays = reactive({
list: ['扫码收款', '二维码收款'], list: ['扫码收款', '二维码收款'],
@@ -439,6 +430,7 @@
uni.$off('choose-user') uni.$off('choose-user')
uni.$on('choose-user', (data) => { uni.$on('choose-user', (data) => {
console.log(data); console.log(data);
pays.quan = []
setUser({ setUser({
vipUserId: data.id ? data.id : '', vipUserId: data.id ? data.id : '',
type: data.id ? 0 : 1 //0 设置 1 取消 type: data.id ? 0 : 1 //0 设置 1 取消
@@ -454,6 +446,9 @@
uni.$off('choose-quan') uni.$off('choose-quan')
uni.$on('choose-quan', (arr) => { uni.$on('choose-quan', (arr) => {
console.log(arr); console.log(arr);
discount.discount = 100
discount.value = 0
discount.currentPrice = order.amount
const manjianCoup = arr.filter(v => v.type == 1 && v.num >= 1) const manjianCoup = arr.filter(v => v.type == 1 && v.num >= 1)
let productCoup = arr.filter(v => v.type == 2) let productCoup = arr.filter(v => v.type == 2)
console.log(productCoup); console.log(productCoup);
@@ -478,14 +473,17 @@
coup.num) coup.num)
const num = Math.min($goodsPayPriceMap[coup.proId].length, coupUseNum) const num = Math.min($goodsPayPriceMap[coup.proId].length, coupUseNum)
coup.num = num coup.num = num
console.log($goodsPayPriceMap[coup.proId]);
const findGoods = order.detailList.find(v => v.productId == coup.proId)
const isMember = findGoods.isMember
coup.discountAmount = returnProductCoupAllPrice($goodsPayPriceMap[coup.proId], coup.discountAmount = returnProductCoupAllPrice($goodsPayPriceMap[coup.proId],
proCoupStartIndex, num).toFixed(2) proCoupStartIndex, num, isMember).toFixed(2)
console.log(coup.discountAmount);
} }
} }
productCoup = productCoup.filter(v => v.num >= 1) productCoup = productCoup.filter(v => v.num >= 1)
console.log(productCoup); console.log(productCoup);
pays.quan = [...manjianCoup, ...productCoup] pays.quan = [...manjianCoup, ...productCoup]
console.log(pays.quan);
}) })
} }
@@ -525,12 +523,18 @@
//打折相关数据 //打折相关数据
const discount = reactive({ const discount = reactive({
discount: 100 discount: 100,
currentPrice: 0,
value: 0
}) })
function editDiscountConfirm(form) { function editDiscountConfirm(form) {
console.log(form); console.log(form);
Object.assign(discount, form) accountPoints.sel = false
Object.assign(discount, {
...form,
value: form.price - form.currentPrice
})
getPayUrl() getPayUrl()
} }
@@ -590,7 +594,7 @@
infoBox.showToast('余额不足') infoBox.showToast('余额不足')
return return
} }
if (payStatus) { if (payStatus) {
return infoBox.showToast(tipsMap[payStatus]) return infoBox.showToast(tipsMap[payStatus])
} }
@@ -637,7 +641,9 @@
success: function(res) { success: function(res) {
console.log('条码类型:' + res.scanType); console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result); console.log('条码内容:' + res.result);
pay({code: res.result}) pay({
code: res.result
})
} }
}); });
} }
@@ -682,18 +688,28 @@
}) })
} }
const coupAllPrice = computed(() => { const coupAllPrice = computed(() => {
return pays.quan.reduce((prve, cur) => { const n = pays.quan.reduce((prve, cur) => {
if(cur.type==1){ return prve + cur.discountAmount * 1
return prve + cur.discountAmount * 1
}else{
return prve + (cur.discountAmount * discount.discount/100)
}
}, 0) }, 0)
return n
}) })
const payPrice = computed(() => { const payPrice = computed(() => {
const discountPrice = discount.currentPrice ? discount.currentPrice : order.amount // const discountPrice = discount.currentPrice ? discount.currentPrice : order.amount
const calcPrice = discountPrice - coupAllPrice.value - accountPoints.price * (accountPoints.sel ? 1 : 0) // const calcPrice = discountPrice - coupAllPrice.value - accountPoints.price * (accountPoints.sel ? 1 : 0)
return (calcPrice <= 0 ? 0 : calcPrice).toFixed(2) // return (calcPrice <= 0 ? 0 : calcPrice).toFixed(2)
const total = (order.amount || 0) - productCouponDiscountAmount.value - discount.value -
fullCouponDiscountAmount.value - accountPoints.price * (accountPoints.sel ? 1 : 0)
return (total < 0 ? 0 : total).toFixed(2)
})
const fullCouponDiscountAmount = computed(() => {
return pays.quan.filter(v => v.type == 1).reduce((prve, cur) => {
return prve + cur.discountAmount * 1
}, 0)
})
const productCouponDiscountAmount = computed(() => {
return pays.quan.filter(v => v.type == 2).reduce((prve, cur) => {
return prve + cur.discountAmount * 1
}, 0)
}) })
watch(() => payPrice.value, (newval) => { watch(() => payPrice.value, (newval) => {
getPayUrl() getPayUrl()
@@ -715,9 +731,9 @@
} }
}) })
const pointCanDicountPrice = computed(() => { const pointCanDicountPrice = computed(() => {
const discountPrice = discount.currentPrice ? discount.currentPrice : order.amount const total = (order.amount || 0) - productCouponDiscountAmount.value - discount.value -
const calcPrice = discountPrice - coupAllPrice.value fullCouponDiscountAmount.value
return (calcPrice <= 0 ? 0 : calcPrice).toFixed(2) return (total < 0 ? 0 : total).toFixed(2)
}) })
watch(() => pointCanDicountPrice.value, (newval) => { watch(() => pointCanDicountPrice.value, (newval) => {
calcUsablePoints() calcUsablePoints()

View File

@@ -315,12 +315,15 @@
memberId: option.memberId memberId: option.memberId
}) })
canDikouGoodsArr = returnNewGoodsList(order.value.detailList || []) canDikouGoodsArr = returnNewGoodsList(order.value.detailList || [])
res.fullReductionCoupon = res.fullReductionCoupon.filter((v) => { res.fullReductionCoupon = res.fullReductionCoupon.map((v) => {
if(option.orderPrice<=0){ if(option.orderPrice<=0){
return false return {...v,use:false}
}else{ }else{
return v.use && option.orderPrice * 1 >= v return{
.fullAmount * 1 ...v,
use:v.use && option.orderPrice * 1 >= v
.fullAmount * 1
}
} }
}) })
@@ -340,8 +343,7 @@
const option = reactive({ const option = reactive({
orderId: '', orderId: '',
memberId: '', memberId: '',
orderPrice: 0, orderPrice: 0
discuount:100
}) })
function toEmitChooseQuan(item) { function toEmitChooseQuan(item) {
@@ -362,7 +364,7 @@
const goodsQuan = myQuan.res.productCoupon.filter(v => v.checked) const goodsQuan = myQuan.res.productCoupon.filter(v => v.checked)
const fullReductionCoupon = myQuan.fullReductionCouponSel.id ? [myQuan.fullReductionCouponSel] : [] const fullReductionCoupon = myQuan.fullReductionCouponSel.id ? [myQuan.fullReductionCouponSel] : []
let coupArr = [...fullReductionCoupon, ...goodsQuan] let coupArr = [...fullReductionCoupon, ...goodsQuan]
return returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value,option.discuount) return returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
}) })
const payPrice = computed(() => { const payPrice = computed(() => {
const pay = option.orderPrice - discountAmount.value const pay = option.orderPrice - discountAmount.value

View File

@@ -91,11 +91,12 @@ export function returnProductPayPrice(goods,vipUser){
return price return price
} }
//返回商品券抵扣的商品价格 //返回商品券抵扣的商品价格
export function returnProductCoupAllPrice(productPriceArr,startIndex,num){ export function returnProductCoupAllPrice(productPriceArr,startIndex,num,isMember=true){
console.log(productPriceArr);
return productPriceArr.slice(startIndex,startIndex+num).reduce((prve,cur)=>{ return productPriceArr.slice(startIndex,startIndex+num).reduce((prve,cur)=>{
let curPrice=0 let curPrice=0
if(typeof cur==='object'){ if(typeof cur==='object'){
curPrice=cur.memberPrice*1 curPrice=isMember?cur.memberPrice*1:cur.price
}else{ }else{
curPrice=cur*1 curPrice=cur*1
} }
@@ -206,10 +207,8 @@ export function returnFullReductionCouponAllPrice(coupArr) {
} }
//计算优惠券总价格 //计算优惠券总价格
export function returnCouponAllPrice(coupArr, goodsArr, vipUser,discount) { export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
console.log(discount); const poductAllprice = returnProductCouponAllPrice(coupArr, goodsArr, vipUser)
const poductAllprice = (returnProductCouponAllPrice(coupArr, goodsArr, vipUser)*discount/100)
console.log(poductAllprice);
const pointAllPrice = returnFullReductionCouponAllPrice(coupArr) const pointAllPrice = returnFullReductionCouponAllPrice(coupArr)
return (poductAllprice * 1 + pointAllPrice * 1).toFixed(2); return (poductAllprice * 1 + pointAllPrice * 1).toFixed(2);
} }