fix: 代客下单优化购物车以及优惠价格展示,修复后付费去结账未生成订单问题
This commit is contained in:
parent
814ca603d7
commit
c371df05ce
|
|
@ -122,6 +122,8 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { customTruncateToTwoDecimals } from "@/views/tool/Instead/util";
|
||||
|
||||
const props = defineProps({
|
||||
useVipPrice: {
|
||||
type: Boolean,
|
||||
|
|
@ -173,7 +175,7 @@ const props = defineProps({
|
|||
},
|
||||
});
|
||||
function to2(n) {
|
||||
return n.toFixed(2);
|
||||
return customTruncateToTwoDecimals(n);
|
||||
}
|
||||
let number = ref(0);
|
||||
|
||||
|
|
|
|||
|
|
@ -73,15 +73,15 @@
|
|||
<template #content>
|
||||
<div class="u-flex color-000 u-font-14 u-row-between">
|
||||
<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 class="u-flex color-000 u-font-14 u-row-between">
|
||||
<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 class="u-flex color-000 u-font-14 u-row-between">
|
||||
<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>
|
||||
</template>
|
||||
<div class="yiyouhui">{{ carts.yiyouhui }}</div>
|
||||
|
|
@ -159,7 +159,7 @@
|
|||
<script setup>
|
||||
import cartsItem from "./item.vue";
|
||||
import extraFee from "./extra-fee.vue";
|
||||
|
||||
import { customTruncateToTwoDecimals } from "@/views/tool/Instead/util";
|
||||
import { useCartsStore } from "@/store/modules/carts";
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ async function createOrder(key) {
|
|||
loading.close();
|
||||
}, 1000 * 20);
|
||||
try {
|
||||
if (key == "to-pay" && carts.list.length <= 0) {
|
||||
if (key == "to-pay" && carts.list.length <= 0 && oldOrder.value.id) {
|
||||
showOrder.value = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,231 +1,255 @@
|
|||
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) {
|
||||
if (isOld) {
|
||||
return arr.reduce((a, b) => {
|
||||
const bTotal = b.info
|
||||
.filter((v) => v.isGift !== "true" && v.status !== "return")
|
||||
.reduce((prve, cur) => {
|
||||
return prve + (cur.packFee || cur.packAmount || 0);
|
||||
}, 0);
|
||||
return a + bTotal;
|
||||
if (isOld) {
|
||||
return arr.reduce((a, b) => {
|
||||
const bTotal = b.info
|
||||
.filter((v) => v.isGift !== "true" && v.status !== "return")
|
||||
.reduce((prve, cur) => {
|
||||
return prve + (cur.packFee || cur.packAmount || 0);
|
||||
}, 0);
|
||||
} else {
|
||||
return arr.filter(v => v.status !== 'return' && v.isGift !== 'true').reduce((a, b) => {
|
||||
return a + (b.packFee || b.packAmount || 0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
return a + bTotal;
|
||||
}, 0);
|
||||
} else {
|
||||
return arr
|
||||
.filter((v) => v.status !== "return" && v.isGift !== "true")
|
||||
.reduce((a, b) => {
|
||||
return a + (b.packFee || b.packAmount || 0);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
//判断商品是否可以下单
|
||||
export function isCanBuy(skuGoods, goods) {
|
||||
if (goods.typeEnum == 'normal') {
|
||||
//单规格
|
||||
return goods.isGrounding && goods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true);
|
||||
} else {
|
||||
//多规格
|
||||
return goods.isGrounding && goods.isPauseSale == 0 && skuGoods.isGrounding && skuGoods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true);
|
||||
|
||||
}
|
||||
if (goods.typeEnum == "normal") {
|
||||
//单规格
|
||||
return (
|
||||
goods.isGrounding && goods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true)
|
||||
);
|
||||
} else {
|
||||
//多规格
|
||||
return (
|
||||
goods.isGrounding &&
|
||||
goods.isPauseSale == 0 &&
|
||||
skuGoods.isGrounding &&
|
||||
skuGoods.isPauseSale == 0 &&
|
||||
(goods.isStock ? goods.stockNumber > 0 : true)
|
||||
);
|
||||
}
|
||||
}
|
||||
//字符匹配
|
||||
export function $strMatch(matchStr, str) {
|
||||
return matchStr.toLowerCase().includes(str.toLowerCase())
|
||||
return matchStr.toLowerCase().includes(str.toLowerCase());
|
||||
}
|
||||
|
||||
// 一个数组是否包含另外一个数组全部元素
|
||||
export function arrayContainsAll(arr1, arr2) {
|
||||
for (let i = 0; i < arr2.length; i++) {
|
||||
if (!arr1.includes(arr2[i])) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < arr2.length; i++) {
|
||||
if (!arr1.includes(arr2[i])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//n项 n-1项组合,生成全部结果
|
||||
export function generateCombinations(arr, k) {
|
||||
console.log(arr)
|
||||
console.log(k)
|
||||
let result = [];
|
||||
console.log(arr);
|
||||
console.log(k);
|
||||
let result = [];
|
||||
|
||||
function helper(index, current) {
|
||||
if (current.length === k) {
|
||||
result.push(current.slice()); // 使用slice()来避免直接修改原始数组
|
||||
} else {
|
||||
for (let i = index; i < arr.length; i++) {
|
||||
current.push(arr[i]); // 将当前元素添加到组合中
|
||||
helper(i + 1, current); // 递归调用,索引增加以避免重复选择相同的元素
|
||||
current.pop(); // 回溯,移除当前元素以便尝试其他组合
|
||||
}
|
||||
}
|
||||
function helper(index, current) {
|
||||
if (current.length === k) {
|
||||
result.push(current.slice()); // 使用slice()来避免直接修改原始数组
|
||||
} else {
|
||||
for (let i = index; i < arr.length; i++) {
|
||||
current.push(arr[i]); // 将当前元素添加到组合中
|
||||
helper(i + 1, current); // 递归调用,索引增加以避免重复选择相同的元素
|
||||
current.pop(); // 回溯,移除当前元素以便尝试其他组合
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
helper(0, []); // 从索引0开始,初始空数组作为起点
|
||||
return result;
|
||||
helper(0, []); // 从索引0开始,初始空数组作为起点
|
||||
return result;
|
||||
}
|
||||
|
||||
export function returnReverseVal(val, isReturnString = true) {
|
||||
const isBol = typeof val === "boolean";
|
||||
const isString = typeof val === "string";
|
||||
let reverseNewval = "";
|
||||
if (isBol) {
|
||||
reverseNewval = !val;
|
||||
}
|
||||
if (isString) {
|
||||
reverseNewval = val === "true" ? "false" : "true";
|
||||
}
|
||||
return reverseNewval;
|
||||
const isBol = typeof val === "boolean";
|
||||
const isString = typeof val === "string";
|
||||
let reverseNewval = "";
|
||||
if (isBol) {
|
||||
reverseNewval = !val;
|
||||
}
|
||||
if (isString) {
|
||||
reverseNewval = val === "true" ? "false" : "true";
|
||||
}
|
||||
return reverseNewval;
|
||||
}
|
||||
|
||||
export function returnGiftArr(arr) {
|
||||
let result = []
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const info = arr[i].info
|
||||
for (let j = 0; j < info.length; j++) {
|
||||
if (info[j].isGift === 'true') {
|
||||
result.push(info[j])
|
||||
}
|
||||
}
|
||||
let result = [];
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const info = arr[i].info;
|
||||
for (let j = 0; j < info.length; j++) {
|
||||
if (info[j].isGift === "true") {
|
||||
result.push(info[j]);
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function formatOrderGoodsList(arr) {
|
||||
const goodsMap = {}
|
||||
for (let i in arr) {
|
||||
const goods = arr[i]
|
||||
if (goods.productName != '客座费') {
|
||||
if (goodsMap.hasOwnProperty(goods.placeNum)) {
|
||||
goodsMap[goods.placeNum || 1].push(goods)
|
||||
} else {
|
||||
goodsMap[goods.placeNum || 1] = [goods]
|
||||
}
|
||||
}
|
||||
|
||||
const goodsMap = {};
|
||||
for (let i in arr) {
|
||||
const goods = arr[i];
|
||||
if (goods.productName != "客座费") {
|
||||
if (goodsMap.hasOwnProperty(goods.placeNum)) {
|
||||
goodsMap[goods.placeNum || 1].push(goods);
|
||||
} else {
|
||||
goodsMap[goods.placeNum || 1] = [goods];
|
||||
}
|
||||
}
|
||||
return Object.entries(goodsMap).map(([key, value]) => ({
|
||||
info: value,
|
||||
placeNum: key || 1
|
||||
}))
|
||||
}
|
||||
return Object.entries(goodsMap).map(([key, value]) => ({
|
||||
info: value,
|
||||
placeNum: key || 1,
|
||||
}));
|
||||
}
|
||||
|
||||
export function returnIsSeatFee(item) {
|
||||
if (!item) {
|
||||
return false
|
||||
}
|
||||
return item.productId == "-999"?true:false;
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
return item.productId == "-999" ? true : false;
|
||||
}
|
||||
/**
|
||||
* 计算购物车会员优惠价格
|
||||
*/
|
||||
export function returnVipDiscountPrice() {
|
||||
|
||||
}
|
||||
export function returnVipDiscountPrice() {}
|
||||
|
||||
//计算商品券优惠价格
|
||||
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
|
||||
const item = goodsArr.find(v => v.productId == coup.proId);
|
||||
if(!item){
|
||||
return 0
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||
return price*coup.num
|
||||
|
||||
const item = goodsArr.find((v) => v.productId == coup.proId);
|
||||
if (!item) {
|
||||
return 0;
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||
return price * coup.num;
|
||||
}
|
||||
//返回新的商品列表,过滤掉退菜的,退单的商品
|
||||
export function returnNewGoodsList(arr) {
|
||||
let goodsMap={}
|
||||
return arr.filter(v => !isTui(v))
|
||||
let goodsMap = {};
|
||||
return arr.filter((v) => !isTui(v));
|
||||
}
|
||||
//根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用
|
||||
export function returnCoupCanUse(goodsArr=[],coup,selCoupArr=[]) {
|
||||
if(!coup.use){
|
||||
return false
|
||||
}
|
||||
const findGoods=goodsArr.filter(v=>v.productId==coup.proId)
|
||||
if(!findGoods.length){
|
||||
return false
|
||||
}
|
||||
const findGoodsTotalNumber=findGoods.reduce((prve,cur)=>{
|
||||
return prve+cur.num*1
|
||||
},0)
|
||||
const selCoupNumber=selCoupArr.filter(v=>v.proId==coup.proId).reduce((prve,cur)=>{
|
||||
return prve+cur.num*1
|
||||
},0)
|
||||
if(selCoupNumber>=findGoodsTotalNumber){
|
||||
return false
|
||||
}
|
||||
return findGoodsTotalNumber<(coup.num+selCoupNumber)?false:true
|
||||
export function returnCoupCanUse(goodsArr = [], coup, selCoupArr = []) {
|
||||
if (!coup.use) {
|
||||
return false;
|
||||
}
|
||||
const findGoods = goodsArr.filter((v) => v.productId == coup.proId);
|
||||
if (!findGoods.length) {
|
||||
return false;
|
||||
}
|
||||
const findGoodsTotalNumber = findGoods.reduce((prve, cur) => {
|
||||
return prve + cur.num * 1;
|
||||
}, 0);
|
||||
const selCoupNumber = selCoupArr
|
||||
.filter((v) => v.proId == coup.proId)
|
||||
.reduce((prve, cur) => {
|
||||
return prve + cur.num * 1;
|
||||
}, 0);
|
||||
if (selCoupNumber >= findGoodsTotalNumber) {
|
||||
return false;
|
||||
}
|
||||
return findGoodsTotalNumber < coup.num + selCoupNumber ? false : true;
|
||||
}
|
||||
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
||||
export function returnProductCoupon(coup, goodsArr, vipUser,selCoupArr=[]) {
|
||||
const newGoodsArr = returnNewGoodsList(goodsArr)
|
||||
const item = newGoodsArr.find(v => v.productId == coup.proId);
|
||||
if(!item){
|
||||
return {...coup, discountAmount: 0,use:false}
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||
const discountAmount=(price*coup.num).toFixed(2)
|
||||
console.log(discountAmount);
|
||||
const canUse=!coup.use?false:(discountAmount>0&&returnCoupCanUse(goodsArr,coup,selCoupArr))
|
||||
// const canUse=discountAmount>0
|
||||
return { ...coup, discountAmount: discountAmount,use:canUse}
|
||||
|
||||
export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
|
||||
const newGoodsArr = returnNewGoodsList(goodsArr);
|
||||
const item = newGoodsArr.find((v) => v.productId == coup.proId);
|
||||
if (!item) {
|
||||
return { ...coup, discountAmount: 0, use: false };
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||
const discountAmount = (price * coup.num).toFixed(2);
|
||||
console.log(discountAmount);
|
||||
const canUse = !coup.use
|
||||
? false
|
||||
: discountAmount > 0 && returnCoupCanUse(goodsArr, coup, selCoupArr);
|
||||
// const canUse=discountAmount>0
|
||||
return { ...coup, discountAmount: discountAmount, use: canUse };
|
||||
}
|
||||
/**
|
||||
* 根据购物车商品计算商品券抵扣价格以及是否满足可用需求
|
||||
* 1.商品券对应商品数量大于购物车对应商品数量不可用
|
||||
* 2.未在购物车找到相关商品不可用
|
||||
* @param {*} coupArr
|
||||
* @param {*} goodsArr
|
||||
* @param {*} vipUser
|
||||
* @returns
|
||||
* @param {*} coupArr
|
||||
* @param {*} goodsArr
|
||||
* @param {*} vipUser
|
||||
* @returns
|
||||
*/
|
||||
export function returnProductAllCoup(coupArr, goodsArr, vipUser){
|
||||
return coupArr.map((v) => {
|
||||
return returnProductCoupon(v, goodsArr, vipUser)
|
||||
})
|
||||
|
||||
export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
|
||||
return coupArr.map((v) => {
|
||||
return returnProductCoupon(v, goodsArr, vipUser);
|
||||
});
|
||||
}
|
||||
|
||||
//计算商品券总优惠价格
|
||||
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
if(coupArr.length == 0){
|
||||
return 0;
|
||||
}
|
||||
return coupArr.reduce((a, b) => {
|
||||
const price = returnProductCouponPrice(b, goodsArr, vipUser)
|
||||
return a + price;
|
||||
}, 0).toFixed(2);
|
||||
|
||||
if (coupArr.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
return coupArr
|
||||
.reduce((a, b) => {
|
||||
const price = returnProductCouponPrice(b, goodsArr, vipUser);
|
||||
return a + price;
|
||||
}, 0)
|
||||
.toFixed(2);
|
||||
}
|
||||
//计算满减券总优惠价格
|
||||
export function returnFullReductionCouponAllPrice(coupArr) {
|
||||
if(coupArr.length == 0){
|
||||
return 0;
|
||||
}
|
||||
return coupArr.filter(v => v.type == 1).reduce((a, b) => {
|
||||
const price = b.discountAmount
|
||||
return a + price;
|
||||
}, 0).toFixed(2);
|
||||
|
||||
if (coupArr.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
return coupArr
|
||||
.filter((v) => v.type == 1)
|
||||
.reduce((a, b) => {
|
||||
const price = b.discountAmount;
|
||||
return a + price;
|
||||
}, 0)
|
||||
.toFixed(2);
|
||||
}
|
||||
//计算优惠券总价格
|
||||
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
const poductAllprice=returnProductCouponAllPrice(coupArr, goodsArr, vipUser)
|
||||
const pointAllPrice=returnFullReductionCouponAllPrice(coupArr)
|
||||
return (poductAllprice*1+pointAllPrice*1).toFixed(2);
|
||||
const poductAllprice = returnProductCouponAllPrice(coupArr, goodsArr, vipUser);
|
||||
const pointAllPrice = returnFullReductionCouponAllPrice(coupArr);
|
||||
return (poductAllprice * 1 + pointAllPrice * 1).toFixed(2);
|
||||
}
|
||||
|
||||
//返回购物车商品价格
|
||||
export function returnCartPrice(goods, vipUser) {
|
||||
const price=goods.price||goods.salePrice
|
||||
if(!vipUser||!vipUser.id ||!vipUser.isVip){
|
||||
return price
|
||||
}
|
||||
const memberPrice = goods.memberPrice ? goods.memberPrice :price;
|
||||
return memberPrice
|
||||
}
|
||||
const price = goods.price || goods.salePrice;
|
||||
if (!vipUser || !vipUser.id || !vipUser.isVip) {
|
||||
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); // 重新组合并返回
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue