优化代客下单限时折扣

This commit is contained in:
gyq 2025-11-13 18:16:11 +08:00
parent 2db23c3370
commit fa7a9f87fb
8 changed files with 330 additions and 398 deletions

View File

@ -69,7 +69,7 @@
"vue-clipboard3": "^2.0.0",
"vue-i18n": "^11.1.0",
"vue-router": "^4.5.0",
"ysk-utils": "^1.0.62"
"ysk-utils": "^1.0.68"
},
"devDependencies": {
"@commitlint/cli": "^19.7.1",

View File

@ -3,6 +3,7 @@ import WebSocketManager, { type ApifoxModel, msgType } from "@/utils/websocket";
import orderApi from "@/api/order/order";
import { useUserStoreHook } from "@/store/modules/user";
import productApi from "@/api/product/index";
import shopUserApi from '@/api/account/shopUser'
import limitTimeDiscountApi from '@/api/market/limitTimeDiscount.js'
import * as UTILS from "@/utils/coupon-utils.js";
import { BigNumber } from "bignumber.js";
@ -49,6 +50,13 @@ interface PointDeductionRule {
}
export const useCartsStore = defineStore("carts", () => {
const shopInfoStr = localStorage.getItem('userInfo') || '{}';
const shopInfo = JSON.parse(shopInfoStr);
const limitDiscountRes = ref<Record<string, any> | null>(null);
const shopInfoTyped = shopInfo as Record<string, any>;
const ldRes = limitDiscountRes.value as LimitDiscountResult | null;
// ------------------------------ 1. 移到内部的工具函数(核心修复) ------------------------------
// 适配工具库 BaseCartItem 接口的商品数据转换函数(原外部函数,现在内部)
const convertToBaseCartItem = (item: any): BaseCartItem => {
@ -60,6 +68,8 @@ export const useCartsStore = defineStore("carts", () => {
}
: undefined;
// console.log('skuData===========', skuData);
let productType: GoodsType = GoodsType.NORMAL;
switch (item.product_type) {
case 'weight': productType = GoodsType.WEIGHT; break;
@ -68,7 +78,10 @@ export const useCartsStore = defineStore("carts", () => {
default: productType = GoodsType.NORMAL;
}
return {
...item,
id: item.id,
product_id: item.product_id,
number: item.number || 0,
@ -88,9 +101,7 @@ export const useCartsStore = defineStore("carts", () => {
}
: undefined,
skuData,
is_time_discount: item.is_time_discount,
isTimeDiscount: item.is_time_discount,
salePrice: item.limitDiscountPrice || 0
salePrice: item.salePrice
};
};
@ -103,31 +114,72 @@ export const useCartsStore = defineStore("carts", () => {
const oldOrderGoods = Object.values(oldOrder.value.detailMap || {})
.flat()
.map(convertToBaseCartItem);
// console.log('list=====================================', list.value);
// console.log('giftList=====================================', giftList.value);
// console.log('oldOrder.value.detailMap=====================================', oldOrder.value.detailMap);
// console.log('getAllGoodsList.[]===================', [...currentGoods, ...giftGoods, ...oldOrderGoods])
return [...currentGoods, ...giftGoods, ...oldOrderGoods];
};
const limitDiscountRes = ref<Record<string, any> | null>(null);
// ------------------------------ 2. Store 内部原有响应式变量 ------------------------------
// 选择用户
const vipUser = ref<{ id?: string | number, isVip?: boolean }>({});
async function changeUser(user: any) {
vipUser.value = {
...user,
isMemberPrice: shopUser.userInfo.isMemberPrice
};
console.log('changeUser', vipUser.value);
await getGoods({})
// 选择用户后重新刷新历史订单限时折扣信息
setOldOrder(oldOrder.value)
allGoods.value = getAllGoodsList()
console.log('选择用户后刷新所有订单购物车数据====', allGoods.value);
sendWsTimeDiscount()
payParamsInit()
}
// 给长连接发送更新购物车限时折扣信息
const sendWsTimeDiscount = _.throttle(function () {
// 在这里准备给ws发送刷新消息
const cart = (list.value || []).map(convertToBaseCartItem);
const history = Object.values(oldOrder.value.detailMap || {})
.flat()
.map(convertToBaseCartItem);
if (cart.length || history.length) {
WebSocketManager.sendMessage({
type: "shopping",
operate_type: "bulk_edit",
table_code: table_code.value,
shop_id: localStorage.getItem("shopId"),
data: {
cart: cart.map(item => {
return {
id: item.id,
is_time_discount: limitUtils.canUseLimitTimeDiscount(item, limitDiscountRes.value, shopInfoTyped, vipUser.value) ? 1 : 0
}
}),
history: history.map(item => {
return {
id: item.id,
is_time_discount: limitUtils.canUseLimitTimeDiscount(item, limitDiscountRes.value, shopInfoTyped, vipUser.value) ? 1 : 0
}
})
},
})
}
}, 3000)
// 就餐类型
let dinnerType = ref<'dine-in' | 'take-out'>('dine-in');
@ -176,6 +228,16 @@ export const useCartsStore = defineStore("carts", () => {
});
}
const sendThrottledMessage = _.throttle(function () {
WebSocketManager.sendMessage({
type: "shopping",
operate_type: "time_discount_save",
table_code: table_code.value,
shop_id: localStorage.getItem("shopId"),
data: limitDiscountRes.value,
});
}, 3000);
// 代客下单页面商品缓存
const goods = useStorage<any[]>("Instead_goods", []);
async function getGoods(query: any) {
@ -193,13 +255,7 @@ export const useCartsStore = defineStore("carts", () => {
if (limitDiscountRes.value !== null) {
checkLinkFinished().then(() => {
console.log('给ws发送限时折扣信息');
WebSocketManager.sendMessage({
type: "shopping",
operate_type: "time_discount_save",
table_code: table_code.value,
shop_id: localStorage.getItem("shopId"),
data: limitDiscountRes.value,
});
sendThrottledMessage()
})
}
@ -212,9 +268,6 @@ export const useCartsStore = defineStore("carts", () => {
...query,
});
const shopInfoStr = localStorage.getItem('userInfo') || '{}';
const shopInfo = JSON.parse(shopInfoStr);
interface ProductItem {
id: string | number;
lowMemberPrice?: number;
@ -232,21 +285,21 @@ export const useCartsStore = defineStore("carts", () => {
limitDiscountPrice: number;
}
const shopInfoTyped = shopInfo as Record<string, any>;
const ldRes = limitDiscountRes.value as LimitDiscountResult | null;
goods.value = (res.records as ProductItem[]).map((item: ProductItem): GoodsWithDiscount => {
item.salePrice = item.lowPrice
item.memberPrice = item.lowMemberPrice
return {
...item,
isLimitDiscount: ldRes !== null && limitUtils.canUseLimitTimeDiscount(item, ldRes, shopInfoTyped, vipUser.value, 'id'),
limitDiscountPrice: limitUtils.returnPrice({
goods: { ...item, memberPrice: item.lowMemberPrice, salePrice: item.lowPrice },
is_time_discount: limitUtils.canUseLimitTimeDiscount(item, limitDiscountRes.value, shopInfoTyped, vipUser.value) ? 1 : 0,
time_discount_price: limitUtils.returnPrice({
goods: { ...item },
shopInfo: shopInfoTyped,
limitTimeDiscountRes: ldRes,
limitTimeDiscountRes: limitDiscountRes.value,
shopUserInfo: vipUser.value,
idKey: 'id'
})
} as GoodsWithDiscount;
}
});
console.log('代客下单页面商品缓存.goods.value', goods.value);
@ -361,7 +414,7 @@ export const useCartsStore = defineStore("carts", () => {
limitTimeDiscount: limitDiscountRes.value,
shopUserInfo: vipUser.value,
newUserDiscount: newUserDiscount.value
}));
}) as OrderExtraConfig);
// 营销活动列表
const activityList = computed<ActivityConfig[]>(() => {
@ -405,8 +458,6 @@ export const useCartsStore = defineStore("carts", () => {
// 订单费用汇总(调用内部的 getAllGoodsList
const orderCostSummary = computed(() => {
allGoods.value = getAllGoodsList();
console.log('allGoods.value+++++++++++++++++++++++++', allGoods.value);
console.log('orderExtraConfig.value', orderExtraConfig.value);
const costSummary = OrderPriceCalculator.calculateOrderCostSummary(
allGoods.value,
dinnerType.value,
@ -417,7 +468,6 @@ export const useCartsStore = defineStore("carts", () => {
new Date()
);
console.log('costSummary----------------------------', costSummary);
return costSummary;
});
@ -565,7 +615,7 @@ export const useCartsStore = defineStore("carts", () => {
function add(data: any) {
goods.value.map(item => {
if (item.id == data.product_id) {
data.is_time_discount = item.isLimitDiscount ? 1 : 0
data.is_time_discount = item.is_time_discount ? 1 : 0
}
})
@ -667,8 +717,10 @@ export const useCartsStore = defineStore("carts", () => {
}
}
// 获取历史订单信息
async function getOldOrder(table_code: string | number) {
const res = await orderApi.getHistoryList({ tableCode: table_code });
console.log('获取历史订单信息===', res);
if (res) setOldOrder(res);
}
@ -684,9 +736,11 @@ export const useCartsStore = defineStore("carts", () => {
skuData = { ...SnapSku, salePrice: SnapSku ? SnapSku.price : 0 };
}
console.log('skuData===', skuData);
if (skuData) {
return {
limitDiscountPrice: goods.limitDiscountPrice,
salePrice: skuData.salePrice || 0,
memberPrice: skuData.memberPrice || 0,
coverImg: goods.coverImg,
@ -694,12 +748,21 @@ export const useCartsStore = defineStore("carts", () => {
specInfo: skuData.specInfo,
packFee: goods.packFee || 0,
type: goods.type,
skuData
skuData,
is_time_discount: limitUtils.canUseLimitTimeDiscount(goods, limitDiscountRes.value, shopInfo, vipUser.value),
time_discount_price: limitUtils.returnPrice({
goods: skuData,
shopInfo: shopInfoTyped,
limitTimeDiscountRes: limitDiscountRes.value,
shopUserInfo: vipUser.value,
idKey: 'productId'
}),
};
}
return undefined;
}
// 历史订单信息补全
function returnDetailMap(data: any) {
const newData: { [key: string]: any } = {};
for (let i in data) {
@ -722,20 +785,34 @@ export const useCartsStore = defineStore("carts", () => {
sku_name: v.skuName,
sku_id: v.skuId,
product_type: v.productType,
is_time_discount: v.isTimeDiscount
is_time_discount: limitUtils.canUseLimitTimeDiscount(v, limitDiscountRes.value, shopInfoTyped, vipUser.value, 'productId'),
time_discount_price: limitUtils.returnPrice({
goods: { ...v, ...skuData },
shopInfo: shopInfoTyped,
limitTimeDiscountRes: limitDiscountRes.value,
shopUserInfo: vipUser.value,
idKey: 'productId'
})
};
});
}
console.log('returnDetailMap.newData================', newData);
console.log('newData2025年11月13日', newData);
return newData;
}
function setOldOrder(data: any) {
// 初始话订单信息/补全历史订单信息
async function setOldOrder(data: any) {
console.log('补全订单信息', data);
oldOrder.value = {
...data,
detailMap: returnDetailMap(data.detailMap)
};
console.log('oldOrder.value.detailMap==', oldOrder.value.detailMap);
if (!vipUser.value.id && data.userId) {
const res = await shopUserApi.get({ userId: data.userId })
changeUser(res)
}
}
let $initParams = {} as ApifoxModel;
@ -750,6 +827,9 @@ export const useCartsStore = defineStore("carts", () => {
table_code.value = initParams.table_code;
$initParams = initParams;
}
concocatSocket($initParams);
}
@ -875,6 +955,11 @@ export const useCartsStore = defineStore("carts", () => {
msg.operate_type = 'manage_' + msg.operate_type;
concocatSocket(initParams);
}
if (msg.operate_type === "bulk_edit") {
msg.operate_type = 'manage_' + msg.operate_type;
concocatSocket({ ...$initParams, table_code: table_code.value });
}
});
}
@ -955,7 +1040,8 @@ export const useCartsStore = defineStore("carts", () => {
setCoupons,
payParamsInit,
limitDiscountRes,
getAllGoodsList
getAllGoodsList,
vipUser
};
});

185
src/store/modules/limit.js Normal file
View File

@ -0,0 +1,185 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.utils = void 0;
exports.canUseLimitTimeDiscount = canUseLimitTimeDiscount;
exports.returnPrice = returnPrice;
exports.returnLimitPrice = returnLimitPrice;
exports.canReturnMemberPrice = canReturnMemberPrice;
exports.returnMemberPrice = returnMemberPrice;
const bignumber_js_1 = __importDefault(require("bignumber.js"));
/**
* 判断商品是否可以使用限时折扣
* @param goods 商品对象
* @param limitTimeDiscountRes 限时折扣配置
* @param shopInfo 店铺信息
* @param shopUserInfo 店铺用户信息
* @param idKey 商品ID键名默认"id"
* @returns
*/
function canUseLimitTimeDiscount(goods, limitTimeDiscountRes, shopInfo, shopUserInfo, idKey = "id") {
shopInfo = shopInfo || {};
shopUserInfo = shopUserInfo || {};
if (!limitTimeDiscountRes || !limitTimeDiscountRes.id) {
return false;
}
const canUseFoods = (limitTimeDiscountRes.foods || "").split(",");
const goodsCanUse = limitTimeDiscountRes.foodType == 1 ||
canUseFoods.includes(`${goods[idKey]}`);
if (!goodsCanUse) {
return false;
}
if (limitTimeDiscountRes.discountPriority == "limit-time") {
return true;
}
if (limitTimeDiscountRes.discountPriority == "vip-price") {
if (shopUserInfo.isVip != 1 || shopUserInfo.isMemberPrice != 1) {
return true;
}
if (shopUserInfo.isVip == 1 &&
shopUserInfo.isMemberPrice == 1 &&
goods.memberPrice * 1 <= 0) {
return true;
}
}
return false;
}
/**
* 返回商品显示价格
* @params {*} args 参数对象
* @params {*} args.goods 商品对象
* @params {*} args.shopInfo 店铺信息
* @params {*} args.limitTimeDiscountRes 限时折扣信息
* @params {*} args.shopUserInfo 店铺用户信息
* @returns
*/
function returnPrice(args) {
let { goods, shopInfo, limitTimeDiscountRes, shopUserInfo, idKey = "product_id", } = args;
console.log('limits.returnPrice===', args);
limitTimeDiscountRes = limitTimeDiscountRes || {
foods: "",
foodType: 2,
discountPriority: "",
discountRate: 0,
id: 0,
shopId: 0,
useType: "",
};
const canUseFoods = (limitTimeDiscountRes.foods || "").split(",");
const includesGoods = limitTimeDiscountRes.foodType == 1 ||
canUseFoods.includes("" + goods[idKey]);
shopInfo = shopInfo || {};
shopUserInfo = shopUserInfo || {};
if (shopUserInfo.isMemberPrice == 1 &&
shopUserInfo.isVip == 1 &&
shopInfo.isMemberPrice == 1) {
const memberPrice = goods.memberPrice || goods.salePrice;
//是会员而且启用会员价
if (limitTimeDiscountRes) {
//使用限时折扣
//限时折扣优先
if (limitTimeDiscountRes.discountPriority == "limit-time") {
if (includesGoods) {
return returnLimitPrice({
price: goods.salePrice,
limitTimeDiscountRes,
});
}
else {
return memberPrice;
}
}
if (limitTimeDiscountRes.discountPriority == "vip-price" &&
includesGoods) {
if (goods.memberPrice * 1 > 0) {
//会员优先
return memberPrice;
}
else {
const price = returnLimitPrice({
price: goods.salePrice,
limitTimeDiscountRes,
goods: goods,
});
return price;
}
}
else {
return memberPrice;
}
}
else {
//是会员没有限时折扣
return memberPrice;
}
}
else {
// console.log('不是会员或者没有启用会员价',goods,limitTimeDiscountRes);
//不是会员或者没有启用会员价
if (limitTimeDiscountRes && limitTimeDiscountRes.id && includesGoods) {
const price = returnLimitPrice({
price: goods.salePrice,
limitTimeDiscountRes,
goods: goods,
});
return price;
}
else {
return goods.salePrice;
}
}
}
/**
* 返回限时折扣价格
* @params {*} args 参数对象
* @params {*} args.limitTimeDiscountRes 限时折扣信息
* @params {*} args.price 商品价格
* @param {*} args.goods 商品对象
* @returns
*/
function returnLimitPrice(args) {
const { limitTimeDiscountRes, price, goods } = args;
const discountRate = new bignumber_js_1.default(limitTimeDiscountRes ? limitTimeDiscountRes.discountRate : 100).dividedBy(100);
const result = (0, bignumber_js_1.default)(price)
.times(discountRate)
.decimalPlaces(2, bignumber_js_1.default.ROUND_UP)
.toNumber();
return result;
}
/**
* 判断是否返回会员价
* @param {*} args 参数对象
* @param {*} args.shopInfo 店铺信息
* @param {*} args.shopUserInfo 店铺用户信息
* @returns
*/
function canReturnMemberPrice(args) {
const { shopInfo, shopUserInfo } = args;
if (shopUserInfo.isMemberPrice == 1 && shopUserInfo.isVip == 1) {
return true;
}
else {
return false;
}
}
/**
* 返回会员价格
* @param {*} goods
* @returns
*/
function returnMemberPrice(goods) {
return goods.memberPrice || goods.salePrice;
}
exports.utils = {
returnPrice,
canUseLimitTimeDiscount,
returnLimitPrice,
canReturnMemberPrice,
returnMemberPrice,
};
exports.default = exports.utils;

View File

@ -1,345 +0,0 @@
import BigNumber from "bignumber.js";
import _ from "lodash";
export interface Goods {
productId: string | number; // 商品ID唯一标识商品用于优惠券/活动匹配,必选)
skuId: string | number; // 商品规格ID唯一标识商品规格如颜色/尺寸)
id: string | number; // 购物车ID唯一标识购物车中的条目如购物车项主键
product_id: string | number; // 商品ID唯一标识商品用于优惠券/活动匹配,必选)
salePrice: number; // 商品原价(元)
number: number; // 商品数量
product_type: string; // 商品类型
is_temporary?: number; // 是否临时菜默认false
is_gift?: number; // 是否赠菜默认false
returnNum?: number; // 退货数量历史订单用默认0
memberPrice: number; // 商品会员价(元,优先级:商品会员价 > 会员折扣)
discountSaleAmount?: number; // 商家改价后单价(元,优先级最高)
packFee?: number; // 单份打包费默认0
packNumber?: number; // 堂食打包数量默认0
skuData?: {
// SKU扩展数据可选
id: string | number; // SKU ID唯一标识商品规格如颜色/尺寸)
memberPrice?: number; // SKU会员价
salePrice?: number; // SKU原价
};
discount_sale_amount: number; // 商家改价后单价(元,优先级最高)
[property: string]: any;
}
export interface User {
isVip: number; // 是否会员 1是会员
[property: string]: any;
}
export interface ShopInfo {
isMemberPrice: number; // 是否开启会员价 1是开启
[property: string]: any;
}
export interface ThresholdFood {
id: string | number; // 商品ID
[property: string]: any;
}
export interface UseFood {
id: string | number;
[property: string]: any;
}
export interface Coupon {
id: string | number;
use: boolean;
type: number;
thresholdFoods: ThresholdFood[];
useFoods: UseFood[];
noUseRestrictions?: string;
discountShare: number; // 是否与折扣优惠同享 1是同享
vipPriceShare: number; // 是否与会员优惠同享 1是同享
otherCouponShare: number; // 是否与其他优惠券同享 1是同享
fullAmount: number; // 使用门槛金额
discountRate: number; // 折扣率(满减券:折扣金额/门槛金额,折扣券:折扣率)
maxDiscountAmount: number; // 最大折扣金额(满减券:折扣金额,折扣券:折扣金额)
discountNum: number; // 抵扣商品数量商品券抵扣商品数量折扣券0
useRule: string; // 使用规则price_asc按商品单价升序price_desc按商品单价降序
}
export interface couponDiscount {
discountPrice: number;
hasDiscountGoodsArr: Goods[];
}
export interface selCoupon extends Coupon {
discount?: couponDiscount;
}
export interface couponCalcParams {
canDikouGoodsArr: Goods[];
coupon: Coupon;
user: User;
shopInfo: ShopInfo;
selCoupon: selCoupon[];
goodsOrderPrice: number; //商品订单总价
isMemberPrice: number; // 是否开启会员价 1是开启
limitTimeDiscount?: TimeLimitDiscountConfig | null | undefined;
}
//限时折扣配置
export interface TimeLimitDiscountConfig {
/**
* limit-time/vip-price
*/
discountPriority: string;
/**
* % 1-99
*/
discountRate: number;
/**
*
*/
foods: string;
/**
* 1 2
*/
foodType: number;
/**
*
*/
id: number;
/**
* ID
*/
shopId: number;
/**
* 使 dine-in take-out take-away post
*/
useType: string;
[property: string]: any;
}
export interface CanDikouGoodsArrArgs {
canDikouGoodsArr: Goods[];
selCoupon: selCoupon[];
user: User;
shopInfo: ShopInfo;
limitTimeDiscount?: TimeLimitDiscountConfig | null | undefined;
}
/**
* 使
* @param goods
* @param limitTimeDiscountRes
* @param shopInfo
* @param shopUserInfo
* @param idKey ID键名"id"
* @returns
*/
export function canUseLimitTimeDiscount(
goods: Goods,
limitTimeDiscountRes: TimeLimitDiscountConfig | null | undefined,
shopInfo: ShopInfo,
shopUserInfo: User,
idKey = "id"
) {
shopInfo = shopInfo || {};
shopUserInfo = shopUserInfo || {};
if (!limitTimeDiscountRes || !limitTimeDiscountRes.id) {
return false;
}
const canUseFoods = (limitTimeDiscountRes.foods || "").split(",");
const goodsCanUse =
limitTimeDiscountRes.foodType == 1 ||
canUseFoods.includes(`${goods[idKey]}`);
if (!goodsCanUse) {
return false;
}
if (limitTimeDiscountRes.discountPriority == "limit-time") {
return true;
}
if (limitTimeDiscountRes.discountPriority == "vip-price") {
if (goods.id == 727) {
console.log('goods', goods);
console.log('shopUserInfo', shopUserInfo);
}
if (shopUserInfo.isVip != 1 || shopUserInfo.isMemberPrice != 1) {
return true;
}
if (
shopUserInfo.isVip == 1 &&
shopUserInfo.isMemberPrice == 1 &&
goods.memberPrice * 1 <= 0
) {
return true;
}
}
return false;
}
export interface CanDikouGoodsArrArgs {
goods: Goods;
shopInfo: ShopInfo;
limitTimeDiscountRes: TimeLimitDiscountConfig | null | undefined;
shopUserInfo: User;
idKey?: string;
}
/**
*
* @params {*} args
* @params {*} args.goods
* @params {*} args.shopInfo
* @params {*} args.limitTimeDiscountRes
* @params {*} args.shopUserInfo
* @returns
*/
export function returnPrice(args: CanDikouGoodsArrArgs) {
let {
goods,
shopInfo,
limitTimeDiscountRes,
shopUserInfo,
idKey = "product_id",
} = args;
limitTimeDiscountRes = limitTimeDiscountRes || {
foods: "",
foodType: 2,
discountPriority: "",
discountRate: 0,
id: 0,
shopId: 0,
useType: "",
};
const canUseFoods = (limitTimeDiscountRes.foods || "").split(",");
const includesGoods =
limitTimeDiscountRes.foodType == 1 ||
canUseFoods.includes("" + goods[idKey]);
shopInfo = shopInfo || {};
shopUserInfo = shopUserInfo || {};
if (
shopUserInfo.isMemberPrice == 1 &&
shopUserInfo.isVip == 1 &&
shopInfo.isMemberPrice == 1
) {
const memberPrice = goods.memberPrice || goods.salePrice;
//是会员而且启用会员价
if (limitTimeDiscountRes) {
//使用限时折扣
//限时折扣优先
if (limitTimeDiscountRes.discountPriority == "limit-time") {
if (includesGoods) {
return returnLimitPrice({
price: goods.salePrice,
limitTimeDiscountRes,
});
} else {
return memberPrice;
}
}
if (
limitTimeDiscountRes.discountPriority == "vip-price" &&
includesGoods
) {
if (goods.memberPrice * 1 > 0) {
//会员优先
return memberPrice;
} else {
const price = returnLimitPrice({
price: goods.salePrice,
limitTimeDiscountRes,
goods: goods,
});
return price;
}
} else {
return memberPrice;
}
} else {
//是会员没有限时折扣
return memberPrice;
}
} else {
// console.log('不是会员或者没有启用会员价',goods,limitTimeDiscountRes);
//不是会员或者没有启用会员价
if (limitTimeDiscountRes && limitTimeDiscountRes.id && includesGoods) {
const price = returnLimitPrice({
price: goods.salePrice,
limitTimeDiscountRes,
goods: goods,
});
return price;
} else {
return goods.salePrice;
}
}
}
interface returnLimitPriceArgs {
limitTimeDiscountRes: TimeLimitDiscountConfig | null | undefined;
price: number;
goods?: Goods;
}
/**
*
* @params {*} args
* @params {*} args.limitTimeDiscountRes
* @params {*} args.price
* @param {*} args.goods
* @returns
*/
export function returnLimitPrice(args: returnLimitPriceArgs) {
const { limitTimeDiscountRes, price, goods } = args;
const discountRate = new BigNumber(
limitTimeDiscountRes ? limitTimeDiscountRes.discountRate : 100
).dividedBy(100);
const result = BigNumber(price)
.times(discountRate)
.decimalPlaces(2, BigNumber.ROUND_UP)
.toNumber();
return result;
}
/**
*
* @param {*} args
* @param {*} args.shopInfo
* @param {*} args.shopUserInfo
* @returns
*/
interface CanReturnMemberPriceArgs {
shopInfo?: ShopInfo;
shopUserInfo: User;
}
export function canReturnMemberPrice(args: CanReturnMemberPriceArgs) {
const { shopInfo, shopUserInfo } = args;
if (shopUserInfo.isMemberPrice == 1 && shopUserInfo.isVip == 1) {
return true;
} else {
return false;
}
}
/**
*
* @param {*} goods
* @returns
*/
export function returnMemberPrice(goods: Goods) {
return goods.memberPrice || goods.salePrice;
}
export const utils = {
returnPrice,
canUseLimitTimeDiscount,
returnLimitPrice,
canReturnMemberPrice,
returnMemberPrice,
};
export default utils;

View File

@ -28,6 +28,7 @@
<div class="flex u-col-top">
<div class="img">
<div class="xszk" v-if="item.isLimitDiscount || item.is_time_discount">限时折扣</div>
<!-- <div class="xszk" v-if="cartStore.useVipPrice">会员价</div> -->
<div class="isSeatFee img u-line-1 u-flex u-col-center u-row-center" v-if="isSeatFee">
<span>{{ item.name }}</span>
</div>
@ -109,9 +110,9 @@
</div>
</template>
<template v-else>
<div v-if="item.isLimitDiscount || item.is_time_discount">
<div v-if="item.is_time_discount">
<div>
{{ to2(item.limitDiscountPrice) }}
{{ to2(item.time_discount_price) }}
</div>
<div class="free-price">
<span>{{ to2(item.salePrice) }}</span>
@ -135,6 +136,9 @@
<script setup>
import { customTruncateToTwoDecimals } from "@/views/tool/Instead/util";
import { useCartsStore } from '@/store/modules/carts'
const cartStore = useCartsStore()
const props = defineProps({
dinerType: {

View File

@ -3,23 +3,23 @@
<el-image v-if="item.coverImg" class="goods-image"
:src="item.coverImg + '?x-oss-process=image/resize,m_lfit,w_100,h_100'" fit="cover"></el-image>
<div class="info" @click="itemClick">
<div class="dot" v-if="item.isLimitDiscount">限时折扣</div>
<div class="dot" v-if="cartStore.useVipPrice">会员价</div>
<div class="dot" v-if="item.is_time_discount">限时折扣</div>
<!-- <div class="dot" v-if="cartStore.useVipPrice">会员价</div> -->
<div class="btm">
<div class="name u-flex u-flex-wrap">
<span class="weight" v-if="item.type == 'weight'">称重</span>
<span class="u-line-3">{{ item.name }}</span>
</div>
<div class="limit_wrap" v-if="item.isLimitDiscount">
<div class="limit_wrap" v-if="item.is_time_discount">
<span class="o_price">{{ item.lowPrice }}</span>
<span class="sale_price">{{ item.limitDiscountPrice }}</span>
<span class="sale_price">{{ item.time_discount_price }}</span>
</div>
<div class="limit_wrap" v-else>
<template v-if="cartStore.useVipPrice">
<span class="o_price">{{ item.lowPrice }}</span>
<span>{{ item.lowMemberPrice }}</span>
</template>
<template>
<template v-else>
{{ item.lowPrice }}
</template>
</div>

View File

@ -175,6 +175,10 @@
<span class="title">商品优惠券</span>
<span class="u-m-l-10 value">-{{ productCouponDiscountAmount }}</span>
</div>
<div class="u-flex u-m-b-10 u-row-between">
<span class="title">会员折扣</span>
<span class="u-m-l-10 value">-{{ carts.orderCostSummary.vipDiscountAmount }}</span>
</div>
<div class="u-flex u-m-b-10 u-row-between">
<span class="title">其他优惠券</span>
<span class="u-m-l-10 value">-{{ fullCouponDiscountAmount }}</span>

View File

@ -6,20 +6,21 @@
<span class="title">代客下单</span>
<div class="u-m-l-20 flex">
<div class="choose-user flex u-font-14" @click="showChooseUser">
<el-button type="primary" v-if="!user.id">选择用户</el-button>
<el-button type="primary" v-if="!carts.vipUser.id">选择用户</el-button>
<div v-else class="flex cur-pointer">
<img v-if="user.headImg && user.headImg != 'null'" class="headimg" :src="user.headImg" alt="" />
<img v-if="carts.vipUser.headImg && carts.vipUser.headImg != 'null'" class="headimg"
:src="carts.vipUser.headImg" alt="" />
<div v-else class="headimg flex flex-x-y-center">
<i class="el-icon-user"></i>
</div>
<div>
<div class="u-flex">
<div class="ft-13 color-000 no-wrap">{{ user.nickName }}</div>
<div class="vip" v-if="user.isVip">VIP{{ user.isVip }}</div>
<div class="ft-13 color-000 no-wrap">{{ carts.vipUser.nickName }}</div>
<div class="vip" v-if="carts.vipUser.isVip">{{ carts.vipUser.memberLevelName }}</div>
</div>
<div style="margin-top: 2px" class="no-wrap color-666 ft-12">
余额{{ user.amount }}
余额{{ carts.vipUser.amount }}
</div>
</div>
</div>
@ -711,9 +712,6 @@ function clearCarts() {
}
function addCarts(item, isWeight = false) {
console.log('index.addCarts===', item);
if (isWeight) {
carts.add({ pack_number: diners.sel ? 1 : 0, ...item, is_time_discount: item.isLimitDiscount ? 1 : 0 });
return;