From fa7a9f87fb78a0971211353d720f7d4b998b0622 Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Thu, 13 Nov 2025 18:16:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E5=AE=A2=E4=B8=8B?= =?UTF-8?q?=E5=8D=95=E9=99=90=E6=97=B6=E6=8A=98=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/store/modules/carts.ts | 160 ++++++-- src/store/modules/limit.js | 185 ++++++++++ src/store/modules/limit.ts | 345 ------------------ .../tool/Instead/components/carts/item.vue | 8 +- .../tool/Instead/components/goods-item.vue | 10 +- src/views/tool/Instead/components/order.vue | 4 + src/views/tool/Instead/index.vue | 14 +- 8 files changed, 330 insertions(+), 398 deletions(-) create mode 100644 src/store/modules/limit.js delete mode 100644 src/store/modules/limit.ts diff --git a/package.json b/package.json index ddb5008..f7d5241 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/store/modules/carts.ts b/src/store/modules/carts.ts index de120db..60ddf66 100644 --- a/src/store/modules/carts.ts +++ b/src/store/modules/carts.ts @@ -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 | null>(null); + + const shopInfoTyped = shopInfo as Record; + 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 | 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("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; - 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(() => { @@ -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 }; }); diff --git a/src/store/modules/limit.js b/src/store/modules/limit.js new file mode 100644 index 0000000..c44d080 --- /dev/null +++ b/src/store/modules/limit.js @@ -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; diff --git a/src/store/modules/limit.ts b/src/store/modules/limit.ts deleted file mode 100644 index 0e5d9c4..0000000 --- a/src/store/modules/limit.ts +++ /dev/null @@ -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; diff --git a/src/views/tool/Instead/components/carts/item.vue b/src/views/tool/Instead/components/carts/item.vue index 7d9cbea..268632c 100644 --- a/src/views/tool/Instead/components/carts/item.vue +++ b/src/views/tool/Instead/components/carts/item.vue @@ -28,6 +28,7 @@
限时折扣
+
{{ item.name }}
@@ -109,9 +110,9 @@