fix: 代客下单优化购物车以及优惠价格展示,修复后付费去结账未生成订单问题

This commit is contained in:
YeMingfei666 2025-03-14 10:47:19 +08:00
parent 814ca603d7
commit c371df05ce
4 changed files with 195 additions and 169 deletions

View File

@ -122,6 +122,8 @@
</template> </template>
<script setup> <script setup>
import { customTruncateToTwoDecimals } from "@/views/tool/Instead/util";
const props = defineProps({ const props = defineProps({
useVipPrice: { useVipPrice: {
type: Boolean, type: Boolean,
@ -173,7 +175,7 @@ const props = defineProps({
}, },
}); });
function to2(n) { function to2(n) {
return n.toFixed(2); return customTruncateToTwoDecimals(n);
} }
let number = ref(0); let number = ref(0);

View File

@ -73,15 +73,15 @@
<template #content> <template #content>
<div class="u-flex color-000 u-font-14 u-row-between"> <div class="u-flex color-000 u-font-14 u-row-between">
<span class="font-bold">会员优惠</span> <span class="font-bold">会员优惠</span>
<span class="u-m-l-30">{{ carts.vipDiscount }}</span> <span class="u-m-l-30">{{ carts.giftMoney(carts.vipDiscount) }}</span>
</div> </div>
<div class="u-flex color-000 u-font-14 u-row-between"> <div class="u-flex color-000 u-font-14 u-row-between">
<span class="font-bold">赠送</span> <span class="font-bold">赠送</span>
<span class="u-m-l-30">{{ carts.giftMoney }}</span> <span class="u-m-l-30">{{ customTruncateToTwoDecimals(carts.giftMoney) }}</span>
</div> </div>
<div class="u-flex color-000 u-font-14 u-row-between"> <div class="u-flex color-000 u-font-14 u-row-between">
<span class="font-bold">单品改价优惠</span> <span class="font-bold">单品改价优惠</span>
<span class="u-m-l-30">{{ carts.singleDiscount }}</span> <span class="u-m-l-30">{{ customTruncateToTwoDecimals(carts.singleDiscount) }}</span>
</div> </div>
</template> </template>
<div class="yiyouhui">{{ carts.yiyouhui }}</div> <div class="yiyouhui">{{ carts.yiyouhui }}</div>
@ -159,7 +159,7 @@
<script setup> <script setup>
import cartsItem from "./item.vue"; import cartsItem from "./item.vue";
import extraFee from "./extra-fee.vue"; import extraFee from "./extra-fee.vue";
import { customTruncateToTwoDecimals } from "@/views/tool/Instead/util";
import { useCartsStore } from "@/store/modules/carts"; import { useCartsStore } from "@/store/modules/carts";
import { useUserStore } from "@/store/modules/user"; import { useUserStore } from "@/store/modules/user";

View File

@ -354,7 +354,7 @@ async function createOrder(key) {
loading.close(); loading.close();
}, 1000 * 20); }, 1000 * 20);
try { try {
if (key == "to-pay" && carts.list.length <= 0) { if (key == "to-pay" && carts.list.length <= 0 && oldOrder.value.id) {
showOrder.value = true; showOrder.value = true;
return; return;
} }

View File

@ -1,4 +1,6 @@
import {isTui} from '../../order_manage/order_goods_util.js' export function isTui(item) {
return item.status == "return" || item.status == "refund" || item.status == "refunding";
}
//计算打包费 //计算打包费
export function returnPackFee(arr, isOld = true) { export function returnPackFee(arr, isOld = true) {
if (isOld) { if (isOld) {
@ -11,26 +13,34 @@ export function returnPackFee(arr, isOld = true) {
return a + bTotal; return a + bTotal;
}, 0); }, 0);
} else { } else {
return arr.filter(v => v.status !== 'return' && v.isGift !== 'true').reduce((a, b) => { return arr
.filter((v) => v.status !== "return" && v.isGift !== "true")
.reduce((a, b) => {
return a + (b.packFee || b.packAmount || 0); return a + (b.packFee || b.packAmount || 0);
}, 0); }, 0);
} }
} }
//判断商品是否可以下单 //判断商品是否可以下单
export function isCanBuy(skuGoods, goods) { export function isCanBuy(skuGoods, goods) {
if (goods.typeEnum == 'normal') { if (goods.typeEnum == "normal") {
//单规格 //单规格
return goods.isGrounding && goods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true); return (
goods.isGrounding && goods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true)
);
} else { } else {
//多规格 //多规格
return goods.isGrounding && goods.isPauseSale == 0 && skuGoods.isGrounding && skuGoods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true); return (
goods.isGrounding &&
goods.isPauseSale == 0 &&
skuGoods.isGrounding &&
skuGoods.isPauseSale == 0 &&
(goods.isStock ? goods.stockNumber > 0 : true)
);
} }
} }
//字符匹配 //字符匹配
export function $strMatch(matchStr, str) { export function $strMatch(matchStr, str) {
return matchStr.toLowerCase().includes(str.toLowerCase()) return matchStr.toLowerCase().includes(str.toLowerCase());
} }
// 一个数组是否包含另外一个数组全部元素 // 一个数组是否包含另外一个数组全部元素
@ -45,8 +55,8 @@ export function arrayContainsAll(arr1, arr2) {
//n项 n-1项组合生成全部结果 //n项 n-1项组合生成全部结果
export function generateCombinations(arr, k) { export function generateCombinations(arr, k) {
console.log(arr) console.log(arr);
console.log(k) console.log(k);
let result = []; let result = [];
function helper(index, current) { function helper(index, current) {
@ -79,101 +89,100 @@ export function returnReverseVal(val, isReturnString = true) {
} }
export function returnGiftArr(arr) { export function returnGiftArr(arr) {
let result = [] let result = [];
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
const info = arr[i].info const info = arr[i].info;
for (let j = 0; j < info.length; j++) { for (let j = 0; j < info.length; j++) {
if (info[j].isGift === 'true') { if (info[j].isGift === "true") {
result.push(info[j]) result.push(info[j]);
} }
} }
} }
return result return result;
} }
export function formatOrderGoodsList(arr) { export function formatOrderGoodsList(arr) {
const goodsMap = {} const goodsMap = {};
for (let i in arr) { for (let i in arr) {
const goods = arr[i] const goods = arr[i];
if (goods.productName != '客座费') { if (goods.productName != "客座费") {
if (goodsMap.hasOwnProperty(goods.placeNum)) { if (goodsMap.hasOwnProperty(goods.placeNum)) {
goodsMap[goods.placeNum || 1].push(goods) goodsMap[goods.placeNum || 1].push(goods);
} else { } else {
goodsMap[goods.placeNum || 1] = [goods] goodsMap[goods.placeNum || 1] = [goods];
} }
} }
} }
return Object.entries(goodsMap).map(([key, value]) => ({ return Object.entries(goodsMap).map(([key, value]) => ({
info: value, info: value,
placeNum: key || 1 placeNum: key || 1,
})) }));
} }
export function returnIsSeatFee(item) { export function returnIsSeatFee(item) {
if (!item) { if (!item) {
return false return false;
} }
return item.productId == "-999"?true:false; return item.productId == "-999" ? true : false;
} }
/** /**
* 计算购物车会员优惠价格 * 计算购物车会员优惠价格
*/ */
export function returnVipDiscountPrice() { export function returnVipDiscountPrice() {}
}
//计算商品券优惠价格 //计算商品券优惠价格
export function returnProductCouponPrice(coup, goodsArr, vipUser) { export function returnProductCouponPrice(coup, goodsArr, vipUser) {
const item = goodsArr.find(v => v.productId == coup.proId); const item = goodsArr.find((v) => v.productId == coup.proId);
if(!item){ if (!item) {
return 0 return 0;
} }
const memberPrice = item.memberPrice ? item.memberPrice : item.price; const memberPrice = item.memberPrice ? item.memberPrice : item.price;
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0; const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
return price*coup.num return price * coup.num;
} }
//返回新的商品列表,过滤掉退菜的,退单的商品 //返回新的商品列表,过滤掉退菜的,退单的商品
export function returnNewGoodsList(arr) { export function returnNewGoodsList(arr) {
let goodsMap={} let goodsMap = {};
return arr.filter(v => !isTui(v)) return arr.filter((v) => !isTui(v));
} }
//根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用 //根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用
export function returnCoupCanUse(goodsArr=[],coup,selCoupArr=[]) { export function returnCoupCanUse(goodsArr = [], coup, selCoupArr = []) {
if(!coup.use){ if (!coup.use) {
return false return false;
} }
const findGoods=goodsArr.filter(v=>v.productId==coup.proId) const findGoods = goodsArr.filter((v) => v.productId == coup.proId);
if(!findGoods.length){ if (!findGoods.length) {
return false return false;
} }
const findGoodsTotalNumber=findGoods.reduce((prve,cur)=>{ const findGoodsTotalNumber = findGoods.reduce((prve, cur) => {
return prve+cur.num*1 return prve + cur.num * 1;
},0) }, 0);
const selCoupNumber=selCoupArr.filter(v=>v.proId==coup.proId).reduce((prve,cur)=>{ const selCoupNumber = selCoupArr
return prve+cur.num*1 .filter((v) => v.proId == coup.proId)
},0) .reduce((prve, cur) => {
if(selCoupNumber>=findGoodsTotalNumber){ return prve + cur.num * 1;
return false }, 0);
if (selCoupNumber >= findGoodsTotalNumber) {
return false;
} }
return findGoodsTotalNumber<(coup.num+selCoupNumber)?false:true return findGoodsTotalNumber < coup.num + selCoupNumber ? false : true;
} }
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求) //查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
export function returnProductCoupon(coup, goodsArr, vipUser,selCoupArr=[]) { export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
const newGoodsArr = returnNewGoodsList(goodsArr) const newGoodsArr = returnNewGoodsList(goodsArr);
const item = newGoodsArr.find(v => v.productId == coup.proId); const item = newGoodsArr.find((v) => v.productId == coup.proId);
if(!item){ if (!item) {
return {...coup, discountAmount: 0,use:false} return { ...coup, discountAmount: 0, use: false };
} }
const memberPrice = item.memberPrice ? item.memberPrice : item.price; const memberPrice = item.memberPrice ? item.memberPrice : item.price;
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0; const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
const discountAmount=(price*coup.num).toFixed(2) const discountAmount = (price * coup.num).toFixed(2);
console.log(discountAmount); console.log(discountAmount);
const canUse=!coup.use?false:(discountAmount>0&&returnCoupCanUse(goodsArr,coup,selCoupArr)) const canUse = !coup.use
? false
: discountAmount > 0 && returnCoupCanUse(goodsArr, coup, selCoupArr);
// const canUse=discountAmount>0 // const canUse=discountAmount>0
return { ...coup, discountAmount: discountAmount,use:canUse} return { ...coup, discountAmount: discountAmount, use: canUse };
} }
/** /**
* 根据购物车商品计算商品券抵扣价格以及是否满足可用需求 * 根据购物车商品计算商品券抵扣价格以及是否满足可用需求
@ -184,48 +193,63 @@ export function returnProductCoupon(coup, goodsArr, vipUser,selCoupArr=[]) {
* @param {*} vipUser * @param {*} vipUser
* @returns * @returns
*/ */
export function returnProductAllCoup(coupArr, goodsArr, vipUser){ export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
return coupArr.map((v) => { return coupArr.map((v) => {
return returnProductCoupon(v, goodsArr, vipUser) return returnProductCoupon(v, goodsArr, vipUser);
}) });
} }
//计算商品券总优惠价格 //计算商品券总优惠价格
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) { export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
if(coupArr.length == 0){ if (coupArr.length == 0) {
return 0; return 0;
} }
return coupArr.reduce((a, b) => { return coupArr
const price = returnProductCouponPrice(b, goodsArr, vipUser) .reduce((a, b) => {
const price = returnProductCouponPrice(b, goodsArr, vipUser);
return a + price; return a + price;
}, 0).toFixed(2); }, 0)
.toFixed(2);
} }
//计算满减券总优惠价格 //计算满减券总优惠价格
export function returnFullReductionCouponAllPrice(coupArr) { export function returnFullReductionCouponAllPrice(coupArr) {
if(coupArr.length == 0){ if (coupArr.length == 0) {
return 0; return 0;
} }
return coupArr.filter(v => v.type == 1).reduce((a, b) => { return coupArr
const price = b.discountAmount .filter((v) => v.type == 1)
.reduce((a, b) => {
const price = b.discountAmount;
return a + price; return a + price;
}, 0).toFixed(2); }, 0)
.toFixed(2);
} }
//计算优惠券总价格 //计算优惠券总价格
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) { export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
const poductAllprice=returnProductCouponAllPrice(coupArr, goodsArr, vipUser) const poductAllprice = returnProductCouponAllPrice(coupArr, goodsArr, vipUser);
const pointAllPrice=returnFullReductionCouponAllPrice(coupArr) const pointAllPrice = returnFullReductionCouponAllPrice(coupArr);
return (poductAllprice*1+pointAllPrice*1).toFixed(2); return (poductAllprice * 1 + pointAllPrice * 1).toFixed(2);
} }
//返回购物车商品价格 //返回购物车商品价格
export function returnCartPrice(goods, vipUser) { export function returnCartPrice(goods, vipUser) {
const price=goods.price||goods.salePrice const price = goods.price || goods.salePrice;
if(!vipUser||!vipUser.id ||!vipUser.isVip){ if (!vipUser || !vipUser.id || !vipUser.isVip) {
return price return price;
}
const memberPrice = goods.memberPrice ? goods.memberPrice : price;
return memberPrice;
}
// 价格保留两位小数不四舍五入
export function customTruncateToTwoDecimals(number) {
let stringNumber = number.toString();
let dotIndex = stringNumber.indexOf(".");
if (dotIndex === -1) {
return number; // 如果没有小数点,直接返回原数
} else {
let integerPart = stringNumber.substring(0, dotIndex); // 整数部分
let decimalPart = stringNumber.substring(dotIndex + 1, dotIndex + 3); // 小数部分,取两位
return parseFloat(integerPart + "." + decimalPart); // 重新组合并返回
} }
const memberPrice = goods.memberPrice ? goods.memberPrice :price;
return memberPrice
} }