This commit is contained in:
gyq 2025-10-11 13:51:25 +08:00
commit b65955f2cc
11 changed files with 920 additions and 531 deletions

View File

@ -8,13 +8,13 @@ VITE_APP_PORT=3000
# VITE_APP_API_URL=https://tapi.cashier.sxczgkj.cn/ # 测试
# VITE_APP_API_URL=https://cashier.sxczgkj.com/ # 正式
VITE_APP_API_URL=http://192.168.1.31/ # 本地
VITE_APP_API_URL=http://192.168.1.42/ # 本地
# WebSocket 端点(不配置则关闭),线上 ws://api.youlai.tech/ws ,本地 ws://localhost:8989/ws
# VITE_APP_WS_ENDPOINT=wss://sockets.sxczgkj.com/wss
# VITE_APP_WS_ENDPOINT=wss://czgeatws.sxczgkj.com/wss # 正式
VITE_APP_WS_ENDPOINT=ws://192.168.1.31:2348 # 本地
VITE_APP_WS_ENDPOINT=ws://192.168.1.42:2348 # 本地
# 启用 Mock 服务

View File

@ -34,8 +34,8 @@ vscode如果无代码提示
映射地址
<https://fv901fw8033.vicp.fun/>
1. 上传.zip文件解压到服务器的 /home/web下
2. cd到/home/web
1. ***cd /usr/share/nginx/html***
2. 上传.zip文件服务器的 /usr/share/nginx/html
3. 执行命令
```unzip -o dist.zip```

View File

@ -1,5 +1,5 @@
import request from "@/utils/request";
const baseURL = "account/admin/shopInfo";
const baseURL = "/account/admin/shopInfo";
const ShopApi = {
/** 获取店铺列表*/

View File

@ -4,8 +4,8 @@
// 商品,耗材相关:<https://tapi.cashier.sxczgkj.cn/product/>
// 系统相关:<https://tapi.cashier.sxczgkj.cn/system/>
export const Account_BaseUrl = "account";
export const Order_BaseUrl = "order";
export const Product_BaseUrl = "product";
export const System_BaseUrl = "system";
export const Market_BaseUrl = "market";
export const Account_BaseUrl = "/account";
export const Order_BaseUrl = "/order";
export const Product_BaseUrl = "/product";
export const System_BaseUrl = "/system";
export const Market_BaseUrl = "/market";

View File

@ -31,6 +31,7 @@ interface PointDeductionRule {
maxDeductionAmount: number;
}
export const useCartsStore = defineStore("carts", () => {
// ------------------------------ 1. 移到内部的工具函数(核心修复) ------------------------------
// 适配工具库 BaseCartItem 接口的商品数据转换函数(原外部函数,现在内部)
@ -93,7 +94,7 @@ export const useCartsStore = defineStore("carts", () => {
const vipUser = ref<{ id?: string | number, isVip?: boolean }>({});
function changeUser(user: any) {
vipUser.value = user;
userPoints.value = 0;
payParamsInit()
}
// 就餐类型
@ -274,6 +275,7 @@ export const useCartsStore = defineStore("carts", () => {
// 订单费用汇总(调用内部的 getAllGoodsList
const orderCostSummary = computed(() => {
allGoods.value = getAllGoodsList();
console.log(' allGoods.value', allGoods.value);
const costSummary = OrderPriceCalculator.calculateOrderCostSummary(
allGoods.value,
dinnerType.value,
@ -283,6 +285,8 @@ export const useCartsStore = defineStore("carts", () => {
cartOrder.value,
new Date()
);
console.log('costSummary', costSummary);
return costSummary;
});
@ -381,10 +385,10 @@ export const useCartsStore = defineStore("carts", () => {
}
function changeSelCart(cart: CartsState) {
console.log(cart)
if (!cart.id) {
return
}
if (cart.placeNum) {
selPlaceNum.value = cart.placeNum
isOldOrder.value = true
@ -394,11 +398,7 @@ export const useCartsStore = defineStore("carts", () => {
})
return
}
if (cart.is_gift) {
isSelGift.value = true
} else {
isSelGift.value = false
}
if (cart.is_gift) {
isSelGift.value = true
@ -407,7 +407,9 @@ export const useCartsStore = defineStore("carts", () => {
} else {
isSelGift.value = false
isOldOrder.value = false
selListIndex.value = list.value.findIndex((item: CartsState) => item.id === cart.id);
console.log('selListIndex.value', selListIndex.value)
}
}
@ -672,10 +674,14 @@ export const useCartsStore = defineStore("carts", () => {
}
if (msg.operate_type === "manage_edit") {
const newCart = msg.data;
const skuData = getProductDetails({ product_id: msg.data.product_id, sku_id: msg.data.sku_id });
console.log('skuData,', skuData);
const newCart = { ...skuData, ...msg.data };
const listIndex = list.value.findIndex(item => item.id === newCart.id);
const giftIndex = giftList.value.findIndex(item => item.id === newCart.id);
if (giftIndex > -1) {
if (!newCart.is_gift) {
giftList.value.splice(giftIndex, 1);

View File

@ -77,7 +77,6 @@ export function returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user) {
prev.push(...goodsWithType);
return prev;
}, []);
const arr = _.cloneDeep(canDikouGoodsArr)
.map((v) => {
const findCart = goodsCouponGoods.find((carts) => carts.id == v.id);
@ -116,19 +115,17 @@ export function returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user) {
*/
export function returnCouponCanUse(args) {
let { canDikouGoodsArr, coupon, goodsOrderPrice, user, selCoupon, shopInfo } = args;
// 优惠券未启用
if (!coupon.use) {
return {
canUse: false,
reason: "优惠券未启用",
reason: coupon.noUseRestrictions || "不在可用时间段内",
};
}
// 计算门槛金额
let fullAmount = goodsOrderPrice;
canDikouGoodsArr = returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user, shopInfo);
//优惠券指定门槛商品列表
let canCalcGoodsArr = [...canDikouGoodsArr];
//部分商品参与门槛计算
@ -187,7 +184,13 @@ export function returnCouponCanUse(args) {
// 商品兑换券,第二件半价和买一送一判断是否有可用商品
if ([2, 4, 5].includes(coupon.type)) {
// 没有符合条件的商品
if (!isDikouAll && canCalcGoodsArr.length === 0) {
if (isDikouAll && canDikouGoodsArr.length === 0) {
return {
canUse: false,
reason: "没有符合条件的商品",
};
}
if (!isDikouAll && canUseGoodsArr.length === 0) {
return {
canUse: false,
reason: "没有符合条件的商品",
@ -289,7 +292,8 @@ export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoup
return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo);
}
if (coupon.type == 6) {
return returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo);
const result = returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo);
return result;
}
if (coupon.type == 4) {
return returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo);
@ -403,7 +407,7 @@ function returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopI
if (useRule == "price_asc") {
discountGoods = canUseGoods[canUseGoods.length - 1];
} else {
discountGoods = canUseGoods.slice(0, 1);
discountGoods = canUseGoods[0];
}
} else {
//符合抵扣条件的商品
@ -411,13 +415,18 @@ function returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopI
if (useRule == "price_asc") {
discountGoods = canUseGoods1[canUseGoods1.length - 1];
} else {
discountGoods = canUseGoods1.slice(0, 1);
discountGoods = canUseGoods1[0];
}
}
const discountPrice = returnGoodsPrice(discountGoods, user, shopInfo);
const hasDiscountGoodsArr = [discountGoods];
let discountPrice = 0;
let hasDiscountGoodsArr = [];
console.log("returnCouponBuyOneGiveOneDiscount:discountGoods", discountGoods);
if (discountGoods) {
discountPrice = returnGoodsPrice(discountGoods, user, shopInfo);
hasDiscountGoodsArr = [discountGoods];
}
return {
discountPrice,
discountPrice: discountPrice <= 0 ? 0 : discountPrice,
hasDiscountGoodsArr,
};
}
@ -433,14 +442,14 @@ function returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo) {
const { useFoods, useRule } = coupon;
//抵扣商品
let discountGoods = undefined;
//符合买一送一条件的商品
//符合条件的商品
const canUseGoods = canDikouGoodsArr.filter((v) => v.num >= 2);
//抵扣全部商品
if (useFoods.length === 0) {
if (useRule == "price_asc") {
discountGoods = canUseGoods[canUseGoods.length - 1];
} else {
discountGoods = canUseGoods.slice(0, 1);
discountGoods = canUseGoods[0];
}
} else {
//符合抵扣条件的商品
@ -448,16 +457,18 @@ function returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo) {
if (useRule == "price_asc") {
discountGoods = canUseGoods1[canUseGoods1.length - 1];
} else {
discountGoods = canUseGoods1.slice(0, 1);
discountGoods = canUseGoods1[0];
}
}
console.log("returnSecoendDiscount:discountGoods", discountGoods);
const discountPrice = returnGoodsPrice(discountGoods[0], user, shopInfo);
console.log("returnSecoendDiscount:discountPrice", discountPrice);
const hasDiscountGoodsArr = [discountGoods];
let discountPrice = 0;
let hasDiscountGoodsArr = [];
if (discountGoods) {
discountPrice = returnGoodsPrice(discountGoods, user, shopInfo);
hasDiscountGoodsArr = [discountGoods];
}
//返回半价价格
return {
discountPrice: new BigNumber(discountPrice).dividedBy(2).toNumber(),
discountPrice: discountPrice <= 0 ? 0 : new BigNumber(discountPrice).dividedBy(2).toNumber(),
hasDiscountGoodsArr,
};
}

File diff suppressed because it is too large Load Diff

View File

@ -212,6 +212,7 @@ const vipAllPrice = computed(() => {
return n;
});
const allPrice = computed(() => {
console.log("allPrice", props.item);
if (props.item.discount_sale_amount * 1 > 0) {
return props.item.discount_sale_amount * props.item.number;
}

View File

@ -125,9 +125,7 @@
<el-button
type="primary"
size="large"
:disabled="
!carts.isLinkFinshed || showOrder || (carts.oldOrder.detailMap.length && !showOrder)
"
:disabled="disabledMorePay"
@click="createOrder('more-pay')"
>
更多支付
@ -146,7 +144,7 @@
<el-button
type="primary"
size="large"
:disabled="!carts.isLinkFinshed"
:disabled="disabledMorePay"
@click="createOrder('to-pay')"
>
去结账
@ -257,6 +255,25 @@ function itemClick(item) {
function changeNumber(step, item) {
carts.changeNumber(step * 1, item);
}
const disabledMorePay = computed(() => {
if (!carts.isLinkFinshed) {
return true;
}
if (props.showOrder) {
return true;
}
if (Array.isArray(carts.oldOrder.detailMap)) {
if (carts.oldOrder.detailMap.length && !props.showOrder) {
return true;
}
} else {
if (carts.isEmpty && JSON.stringify(carts.oldOrder.detailMap) === "{}") {
return true;
}
}
return false;
});
defineExpose({
carts,

View File

@ -81,32 +81,20 @@
<el-icon><ArrowDown /></el-icon>
</div>
</div>
{{ carts.orderCostSummary }}
<div class="u-m-t-20" v-if="carts.coupons.length > 0">
<div class="u-m-t-20" v-if="quansSelArr.length > 0">
<div class="font-bold u-m-b-10">已选优惠券</div>
<el-table empty-text="未选择优惠券" :data="carts.coupons">
<el-table empty-text="未选择优惠券" :data="quansSelArr">
<el-table-column type="index" width="50" label="#"></el-table-column>
<el-table-column prop="name" label="券名称"></el-table-column>
<el-table-column label="券类型" width="80">
<template v-slot="scope">
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
{{ UTILS.returnCoupType(scope.row.type) }}
</template>
</el-table-column>
<el-table-column label="商品信息">
<template v-slot="scope">
<div v-if="scope.row.type == 2">
<div class="u-flex">
<el-image
:src="scope.row.productImg"
fit="cover"
style="width: 40px; height: 40px"
:preview-src-list="[scope.row.productImg]"
></el-image>
</div>
<div class="u-m-t-10">
<div class="">{{ scope.row.productName }}</div>
<div class="u-m-t-4">x{{ scope.row.num || "" }}</div>
</div>
<div>
{{ scope.row.foods }}
</div>
</template>
</el-table-column>
@ -232,6 +220,8 @@
</template>
<script setup>
import * as UTILS from "@/utils/coupon-utils.js";
import * as quanUtil from "../quan_util.js";
import { OrderPriceCalculator } from "@/utils/goods";
import { useCartsStore } from "@/store/modules/carts";
@ -302,6 +292,7 @@ function delQuan(row) {
if (index != -1) {
quansSelArr.value.splice(index, 1);
}
carts.setCoupons(quansSelArr.value);
}
function couponChange(data) {}
@ -406,12 +397,13 @@ watch(
//002-使
const pointsRes = ref({ usable: true, maxUsablePoints: 0, minDeductionPoints: 0 });
const usePointsNumber = ref(0);
const orderAmountOrderAmount = computed(() => {
return (carts.goodsTotal - checkOrderPay.discountAmount).toFixed(2);
//
const scoreMaxMoney = computed(() => {
return carts.orderCostSummary.finalPayAmount - carts.orderCostSummary.pointDeductionAmount;
});
const pointsDiscountAmount = ref(0);
watch(
() => orderAmountOrderAmount.value,
() => scoreMaxMoney.value,
(newval) => {
pointsInit();
}
@ -424,7 +416,7 @@ function returnPointsDiscountAmount() {
}
async function pointsInit() {
if (!props.user.id || score.sel == -1) {
if (!props.user.id) {
return;
}
const res = await PointsApi.calcOrderUsablePoints({
@ -433,6 +425,9 @@ async function pointsInit() {
});
pointsRes.value = res;
carts.pointDeductionRule.pointsPerYuan = res.equivalentPoints;
if (score.sel == -1) {
return;
}
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
if (res.usable) {

View File

@ -32,7 +32,11 @@
</el-table-column>
<el-table-column prop="discountAmount" label="最大抵扣金额" align="center">
<template v-slot="scope">
<span class="color-red">{{ scope.row.maxDiscountAmount }}</span>
<span class="color-red">
{{
!scope.row.maxDiscountAmount ? "无上限" : "¥" + scope.row.maxDiscountAmount
}}
</span>
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="限制" width="180">
@ -70,21 +74,9 @@
<el-table-column label="商品信息" width="220">
<template v-slot="scope">
<div class="u-flex" v-if="scope.row.useFoods.length">
<div class="u-flex">
<el-image
:src="scope.row.productImg"
fit="cover"
style="width: 40px; height: 40px"
:preview-src-list="[scope.row.productImg]"
></el-image>
{{ scope.row.foods }}
</div>
<div class="u-p-l-10">
<!-- <div class="">{{ scope.row.productName }}</div> -->
<div class="">x{{ scope.row.discountNum || 1 }}</div>
</div>
</div>
<div class="u-flex" v-else>任意商品 x{{ scope.row.discountNum || 1 }}</div>
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="抵扣">
@ -107,9 +99,9 @@
</el-table>
</el-tab-pane>
</el-tabs>
<div v-if="quansSelArr.length > 0">
<div class="font-bold u-m-b-10">已选优惠券</div>
<el-table empty-text="未选择优惠券" :data="quansSelArr" max-height="20vh">
<div class="u-m-t-10" v-if="noUseCoupon.length > 0">
<div class="font-bold u-m-b-10">不可用优惠券</div>
<el-table empty-text="" :data="noUseCoupon" max-height="30vh">
<el-table-column type="index" width="50" label="#"></el-table-column>
<el-table-column prop="name" label="券名称"></el-table-column>
<el-table-column label="券类型" width="80">
@ -119,21 +111,38 @@
</el-table-column>
<el-table-column label="商品信息" width="120">
<template v-slot="scope">
<div class="u-flex" v-if="scope.row.type == 2">
<div v-if="scope.row.useFoods.length">
<div class="u-flex">
<el-image
:src="scope.row.productImg"
fit="cover"
style="width: 40px; height: 40px"
></el-image>
{{ scope.row.foods }}
</div>
<div class="u-p-l-10">
<div class="">{{ scope.row.productName }}</div>
<div class="">x{{ scope.row.discountNum || 1 }}</div>
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="抵扣">
<template v-slot="scope">
<span class="color-red">{{ scope.row.discountAmount }}</span>
</template>
</el-table-column>
<el-table-column prop="useRestrictions" label="描述"></el-table-column>
<el-table-column label="不可用原因">
<template v-slot="scope">
<span class="color-red">{{ scope.row.canuseResult.reason }}</span>
</template>
</el-table-column>
</el-table>
</div>
</div>
<div v-else>任意商品 x{{ scope.row.discountNum || 1 }}</div>
<div class="u-m-t-10" v-if="quansSelArr.length > 0">
<div class="font-bold u-m-b-10">已选优惠券</div>
<el-table empty-text="" :data="quansSelArr" max-height="20vh">
<el-table-column type="index" width="50" label="#"></el-table-column>
<el-table-column prop="name" label="券名称"></el-table-column>
<el-table-column label="券类型" width="80">
<template v-slot="scope">
{{ UTILS.returnCoupType(scope.row) }}
</template>
</el-table-column>
<el-table-column label="商品信息" width="120">
<template v-slot="scope">
<div class="u-flex">
{{ scope.row.foods }}
</div>
</template>
</el-table-column>
@ -237,7 +246,7 @@ const {
isSetProductCoup,
} = toRefs(state);
const quansSelArr = computed(() => {
return [couponSel.value, goodsCouponSel.value].filter((v) => v.id);
return [goodsCouponSel.value, couponSel.value].filter((v) => v.id);
});
const refTable = ref();
const refTable1 = ref();
@ -246,6 +255,8 @@ let orderPrice = ref(0);
//
let canDikouGoodsArr = [];
let goodsArr = [];
//
const noUseCoupon = ref([]);
function open(money, orderInfo) {
let arr = [];
@ -260,72 +271,96 @@ function open(money, orderInfo) {
show.value = true;
}
let couponList = [];
async function getcoup() {
const res = await couponApi.findCoupon({ shopUserId: props.user.id });
console.log(res);
//
quans.value.coupon = res
.filter((v) => v.type != 2)
.filter((coupon) => {
const { canUse, msg } = UTILS.returnCouponCanUse({
couponList = res || [];
let canUseGoodsCoupon = [];
let canUseDiscountCoupon = [];
let noUseGoodsCoupon = [];
let noUseDiscountCoupon = [];
for (let i = 0; i < couponList.length; i++) {
const coupon = couponList[i];
const selCoupon =
activeName.value == "goods"
? quansSelArr.value.filter((v) => v.type != 2)
: quansSelArr.value.filter((v) => v.type == 2);
const canuseResult = UTILS.returnCouponCanUse({
canDikouGoodsArr,
coupon,
orderPrice: orderPrice.value,
user: props.user,
selCoupon: quansSelArr.value,
selCoupon,
shopInfo: shopUser.userInfo,
});
return canUse;
})
.map((v) => {
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
quansSelArr.value,
shopUser.userInfo
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
quans.value.productCoupon = res
.filter((v) => v.type == 2)
.filter((coupon) => {
const { canUse, msg } = UTILS.returnCouponCanUse({
canDikouGoodsArr,
coupon,
orderPrice: orderPrice.value,
user: props.user,
selCoupon: quansSelArr.value,
shopInfo: shopUser.userInfo,
});
return canUse;
})
.map((v) => {
const findGoods = goodsArr.find((goods) => goods.productId == v.proId);
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
quansSelArr.value,
shopUser.userInfo
);
return {
...v,
productImg: findGoods ? findGoods.productImg : "",
productName: findGoods ? findGoods.productName : "",
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
const { canUse, reason } = canuseResult;
if (coupon.type == 2) {
if (canUse || goodsCouponSel.value.id == coupon.id) {
canUseGoodsCoupon.push(coupon);
} else {
noUseGoodsCoupon.push({
...coupon,
canuseResult,
});
}
} else {
if (canUse || couponSel.value.id == coupon.id) {
canUseDiscountCoupon.push(coupon);
} else {
noUseDiscountCoupon.push({
...coupon,
canuseResult,
});
}
}
}
//
canUseGoodsCoupon = canUseGoodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
quansSelArr.value,
shopUser.userInfo
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
//
canUseDiscountCoupon = canUseDiscountCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
quansSelArr.value,
shopUser.userInfo
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
quans.value.productCoupon = canUseGoodsCoupon;
quans.value.coupon = canUseDiscountCoupon;
if (activeName.value == "goods") {
noUseCoupon.value = [...noUseGoodsCoupon];
} else {
noUseCoupon.value = [...noUseDiscountCoupon];
}
}
function couponClick(checked, row) {
couponSel.value = checked ? row : { id: "" };
updateSelCoupon();
}
const AllCouponPrice = computed(() => {
return quansSelArr.value.reduce((pre, cur) => pre + cur.discountAmount, 0);
@ -336,6 +371,7 @@ const payPrice = computed(() => {
});
function productCouponClick(checked, item) {
goodsCouponSel.value = checked ? item : { id: "" };
updateSelCoupon();
}
//
@ -369,9 +405,51 @@ watch(
getcoup();
}
);
function updateSelCoupon() {
const newval = quansSelArr.value;
if (newval.length >= 2) {
let goodsCoupon = newval.filter((v) => v.type == 2);
let otherCoupon = newval.filter((v) => v.type != 2);
goodsCoupon = goodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
[],
shopUser.userInfo
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
otherCoupon = otherCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
goodsCoupon,
shopUser.userInfo
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
couponSel.value = otherCoupon[0];
goodsCouponSel.value = goodsCoupon[0];
}
}
watch(
() => quansSelArr.value,
() => {
(newval) => {
console.log("quansSelArr", newval);
getcoup();
}
);