采用最新结算函数优化代客下单
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
ENV = test
|
||||
|
||||
# 测试ws
|
||||
VITE_API_WSS = 'ws://192.168.1.42:2348'
|
||||
# VITE_API_WSS = 'ws://192.168.1.42:2348'
|
||||
|
||||
# 测试ws
|
||||
# VITE_API_WSS = 'wss://sockets.sxczgkj.com/wss'
|
||||
|
||||
# 正式ws
|
||||
# VITE_API_WSS = 'wss://czgeatws.sxczgkj.com/wss'
|
||||
VITE_API_WSS = 'wss://czgeatws.sxczgkj.com/wss'
|
||||
|
||||
# 正式 php
|
||||
VITE_API_PHP_URL = 'https://newblockwlx.sxczgkj.cn/index.php/api'
|
||||
@@ -23,7 +23,7 @@ VITE_API_KP_URL = 'https://invoice.sxczgkj.cn/api'
|
||||
# VITE_API_URL = 'https://fv901fw8033.vicp.fun/'
|
||||
|
||||
# 正式Java
|
||||
# VITE_API_URL = 'https://cashier.sxczgkj.com/'
|
||||
VITE_API_URL = 'https://cashier.sxczgkj.com/'
|
||||
|
||||
# 本地调试连接
|
||||
VITE_API_URL = 'http://192.168.1.42/'
|
||||
# VITE_API_URL = 'http://192.168.1.42/'
|
||||
17003
dist-electron/main.js
17003
dist-electron/main.js
File diff suppressed because one or more lines are too long
8
package-lock.json
generated
8
package-lock.json
generated
@@ -27,7 +27,7 @@
|
||||
"uuid": "^10.0.0",
|
||||
"vue": "^3.3.8",
|
||||
"vue-router": "^4.2.5",
|
||||
"ysk-utils": "^1.0.56"
|
||||
"ysk-utils": "^1.0.69"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^4.5.0",
|
||||
@@ -7642,9 +7642,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ysk-utils": {
|
||||
"version": "1.0.56",
|
||||
"resolved": "https://registry.npmmirror.com/ysk-utils/-/ysk-utils-1.0.56.tgz",
|
||||
"integrity": "sha512-TsRQGo1TEIVWZTc/j084eKVhTeI4r73dJRrzJHPUI56861hy40ekwYtozoa8v+LURXgEVIwXlMHM6zkgv8zBZw==",
|
||||
"version": "1.0.69",
|
||||
"resolved": "https://registry.npmmirror.com/ysk-utils/-/ysk-utils-1.0.69.tgz",
|
||||
"integrity": "sha512-HP/m/QeGfDI30JD7q3FXP0ChCc1a+cJ5qxNSTQaCA0wI9gpt6MxnqkumqY+aCBugPhFRq0S+MHUPwA7UWWs1DQ==",
|
||||
"dependencies": {
|
||||
"bignumber.js": "^9.3.1",
|
||||
"loadsh": "^0.0.4",
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
"uuid": "^10.0.0",
|
||||
"vue": "^3.3.8",
|
||||
"vue-router": "^4.2.5",
|
||||
"ysk-utils": "^1.0.56"
|
||||
"ysk-utils": "^1.0.69"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^4.5.0",
|
||||
|
||||
@@ -24,4 +24,31 @@ export function getLimitTimeDiscount(params) {
|
||||
url: "/market/admin/limitTimeDiscount",
|
||||
params,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前可用的满减活动
|
||||
* @param {shopId} params
|
||||
* @returns
|
||||
*/
|
||||
export function getDiscountActivity(params) {
|
||||
return request({
|
||||
method: "get",
|
||||
url: "/market/admin/discountActivity",
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户id获取新客立减金额,返回null代表不可用
|
||||
* @param {shopId} params
|
||||
* @returns
|
||||
*/
|
||||
export function getDiscountByUserId(params) {
|
||||
return request({
|
||||
method: "get",
|
||||
url: "/market/admin/consumeDiscount/getDiscountByUserId",
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ import { ref, reactive, computed } from 'vue'
|
||||
import { useGoods } from '@/store/goods.js'
|
||||
import { findCoupon } from '@/api/account.js'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import * as UTILS from '@/utils/coupon-utils.js';
|
||||
import { useUser } from "@/store/user.js";
|
||||
import { couponUtils } from "ysk-utils";
|
||||
|
||||
const props = defineProps({
|
||||
orderList: {
|
||||
@@ -255,13 +255,13 @@ function updateSelCoupon() {
|
||||
if (!shopInfo.isMemberPrice) {
|
||||
shopInfo = {};
|
||||
}
|
||||
const canDikouGoodsArr = UTILS.returnCanDikouGoods(goodsStore.cartInfo.allGoods, [], user);
|
||||
const canDikouGoodsArr = couponUtils.returnCanDikouGoods(goodsStore.cartInfo.allGoods, [], user);
|
||||
|
||||
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(
|
||||
const discount = couponUtils.returnCouponDiscount(
|
||||
canDikouGoodsArr,
|
||||
v,
|
||||
user,
|
||||
@@ -276,7 +276,7 @@ function updateSelCoupon() {
|
||||
};
|
||||
});
|
||||
otherCoupon = otherCoupon.map((v) => {
|
||||
const canuseResult = UTILS.returnCouponCanUse({
|
||||
const canuseResult = couponUtils.returnCouponCanUse({
|
||||
canDikouGoodsArr,
|
||||
coupon: v,
|
||||
orderPrice: orderPrice.value,
|
||||
@@ -285,7 +285,7 @@ function updateSelCoupon() {
|
||||
shopInfo: shopInfo,
|
||||
});
|
||||
|
||||
const discount = UTILS.returnCouponDiscount(
|
||||
const discount = couponUtils.returnCouponDiscount(
|
||||
canDikouGoodsArr,
|
||||
v,
|
||||
user,
|
||||
@@ -382,10 +382,10 @@ function formatCoupon() {
|
||||
console.log('goodsOrderPrice==========', goodsOrderPrice);
|
||||
|
||||
|
||||
const canDikouGoodsArr = UTILS.returnCanDikouGoods(goodsStore.cartInfo.allGoods, [], user);
|
||||
const canDikouGoodsArr = couponUtils.returnCanDikouGoods(goodsStore.cartInfo.allGoods, [], user);
|
||||
for (let i = 0; i < couponList.value.length; i++) {
|
||||
const coupon = couponList.value[i];
|
||||
const canuseResult = UTILS.returnCouponCanUse({
|
||||
const canuseResult = couponUtils.returnCouponCanUse({
|
||||
canDikouGoodsArr,
|
||||
coupon,
|
||||
goodsOrderPrice,
|
||||
@@ -416,7 +416,7 @@ function formatCoupon() {
|
||||
}
|
||||
//商品券
|
||||
canUseGoodsCoupon = canUseGoodsCoupon.map((v) => {
|
||||
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
|
||||
const discount = couponUtils.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
|
||||
return {
|
||||
...v,
|
||||
discount,
|
||||
@@ -425,7 +425,7 @@ function formatCoupon() {
|
||||
});
|
||||
//非商品券
|
||||
canUseDiscountCoupon = canUseDiscountCoupon.map((v) => {
|
||||
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
|
||||
const discount = couponUtils.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
|
||||
return {
|
||||
...v,
|
||||
discount,
|
||||
|
||||
@@ -438,23 +438,30 @@ async function payTypeChange(index, item) {
|
||||
|
||||
// 更新支付参数
|
||||
function upadatePayData() {
|
||||
// console.log(goodsStore.cartInfo);
|
||||
payData.value.checkOrderPay = {
|
||||
vipPrice: store.shopInfo.isMemberPrice ? goodsStore.showVipPrice : 0,
|
||||
orderId: goodsStore.orderListInfo.id,
|
||||
vipPrice: store.shopInfo.isMemberPrice ? goodsStore.showVipPrice : 0, // 是否使用会员价
|
||||
allPack: goodsStore.allSelected, // 是否整单打包
|
||||
// discountRatio: (checkOrderPay.discount / 100).toFixed(2),
|
||||
discountRatio: 0,
|
||||
seatNum: goodsStore.allSelected ? 0 : goodsStore.tableInfo.num,
|
||||
originAmount: goodsStore.cartInfo.costSummary.goodsRealAmount,
|
||||
discountAmount: discountRateNumber.value,
|
||||
productCouponDiscountAmount: goodsStore.cartInfo.costSummary.productCouponDeduction,
|
||||
otherCouponDiscountAmount: goodsStore.cartInfo.costSummary.fullCouponDeduction,
|
||||
orderAmount: goodsStore.cartInfo.costSummary.finalPayAmount, // 最终订单金额
|
||||
roundAmount: 0,
|
||||
pointsDiscountAmount: goodsStore.cartInfo.costSummary.pointDeductionAmount, //积分抵扣金额
|
||||
pointsNum: goodsStore.cartInfo.costSummary.pointUsed,
|
||||
discountActAmount: goodsStore.cartInfo.costSummary.fullReduction.actualAmount, // 满减活动金额
|
||||
discountActId: goodsStore.cartInfo.costSummary.fullReduction.usedThreshold !== undefined ? goodsStore.cartInfo.costSummary.fullReduction.usedThreshold.activityId : '', // 满减活动id
|
||||
couponList: couponResList1.value.map(item => item.id),
|
||||
userId: goodsStore.vipUserInfo.userId || '',
|
||||
seatNum: goodsStore.allSelected ? 0 : goodsStore.tableInfo.num, // 用餐人数
|
||||
originAmount: formatDecimal(goodsStore.cartInfo.costSummary.goodsRealAmount), // 订单原金额(包含打包费+餐位费) 不含折扣价格
|
||||
discountRatio: 1, // 折扣比例(计算时 向上取整保留 两位小数)
|
||||
discountAmount: discountRateNumber.value, // 手动优惠金额
|
||||
productCouponDiscountAmount: goodsStore.cartInfo.costSummary.productCouponDeduction, //商品优惠券抵扣金额
|
||||
otherCouponDiscountAmount: goodsStore.cartInfo.costSummary.fullCouponDeduction, //其他优惠券抵扣金额
|
||||
couponList: couponResList1.value.map(item => item.id), // 用户使用的卡券
|
||||
orderAmount: goodsStore.cartInfo.costSummary.finalPayAmount, // 订单金额
|
||||
roundAmount: 0, // 抹零金额 减免多少钱
|
||||
pointsDiscountAmount: goodsStore.cartInfo.costSummary.pointDeductionAmount, // 积分抵扣金额(tb_points_basic_setting表)
|
||||
pointsNum: goodsStore.cartInfo.costSummary.pointUsed, // 使用的积分数量 (扣除各类折扣 enable_deduction后使用)
|
||||
isPrint: 1
|
||||
allPack: goodsStore.allSelected,
|
||||
limitRate: goodsStore.limitDiscountRes,
|
||||
newCustomerDiscountId: goodsStore.newCustomerDiscount !== null ? goodsStore.newCustomerDiscount.id : '', // 新客立减Id
|
||||
newCustomerDiscountAmount: goodsStore.newCustomerDiscount !== null ? goodsStore.newCustomerDiscount.amount : 0, // 新客立减金额
|
||||
vipDiscountAmount: goodsStore.cartInfo.costSummary.vipDiscountAmount, // 超级会员折扣
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,28 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table :data="tableData.list" height="400px" border stripe v-loading="tableData.loading">
|
||||
<el-table-column prop="nickName" label="昵称" width="150px" />
|
||||
<el-table-column prop="nickName" label="昵称" width="200px">
|
||||
<template #default="scope">
|
||||
<div class="center">
|
||||
<el-avatar :src="scope.row.headImg" :size="20"></el-avatar>
|
||||
<span>{{ scope.row.nickName }}</span>
|
||||
<el-tag type="success" size="small" disable-transitions v-if="scope.row.new">新</el-tag>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="phone" label="手机" width="150px" />
|
||||
<el-table-column prop="code" label="编号" width="150px" />
|
||||
<el-table-column prop="level" label="等级" />
|
||||
<!-- <el-table-column prop="code" label="编号" width="150px" /> -->
|
||||
<el-table-column prop="level" label="等级">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.isVip">
|
||||
<span v-if="scope.row.memberLevelName">
|
||||
{{ scope.row.memberLevelName }}
|
||||
</span>
|
||||
<span v-else>是</span>
|
||||
</span>
|
||||
<span v-else>否</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="accountPoints" label="积分" />
|
||||
<el-table-column prop="amount" label="余额" width="120px">
|
||||
<template v-slot="scope">
|
||||
@@ -115,4 +133,12 @@ function show() {
|
||||
defineExpose({
|
||||
show
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.center {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -4,7 +4,7 @@ import { defineStore } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
import { productPage, categoryList } from "@/api/product_new.js";
|
||||
import { historyOrder, cancelOrder, rmPlaceOrder } from "@/api/order.js";
|
||||
import { getLimitTimeDiscount } from '@/api/market'
|
||||
import { getLimitTimeDiscount, getDiscountActivity, getDiscountByUserId } from '@/api/market'
|
||||
import { useUser } from "@/store/user.js";
|
||||
import { useSocket } from "@/store/socket.js";
|
||||
import useStorage from "@/utils/useStorage.js";
|
||||
@@ -12,7 +12,14 @@ import { formatDecimal } from "@/utils/index.js";
|
||||
import { shopUserDetail } from "@/api/account.js";
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
import yskUtils from "ysk-utils";
|
||||
import {
|
||||
OrderPriceCalculator, limitUtils,
|
||||
BaseCartItem,
|
||||
BackendCoupon,
|
||||
ActivityConfig,
|
||||
OrderExtraConfig, MerchantReductionConfig, MerchantReductionType,
|
||||
GoodsType, FullReductionActivity
|
||||
} from "ysk-utils";
|
||||
|
||||
const initialCostSummary = {
|
||||
finalPayAmount: 0,
|
||||
@@ -74,6 +81,9 @@ export const useGoods = defineStore("goods", {
|
||||
cartType: "cart", // cart order
|
||||
cartOrderItem: "",
|
||||
pendingList: useStorage.get("pendingList") || [],
|
||||
fullReductionActivities: '', // 满减活动配置信息
|
||||
limitDiscountRes: '', // 限时折扣
|
||||
newCustomerDiscount: '' // 新客立减
|
||||
}),
|
||||
actions: {
|
||||
// 清除历史订单
|
||||
@@ -254,6 +264,8 @@ export const useGoods = defineStore("goods", {
|
||||
if (userInfo.isVip && store.shopInfo.isMemberPrice) {
|
||||
this.showVipPrice = 1;
|
||||
}
|
||||
|
||||
await updateGoodsList()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,6 +363,9 @@ export const useGoods = defineStore("goods", {
|
||||
// 获取商品列表/更新商品列表
|
||||
async getGoodsList() {
|
||||
try {
|
||||
const socket = useSocket();
|
||||
const store = useUser()
|
||||
|
||||
this.goodsListLoading = true;
|
||||
const res = await productPage({
|
||||
categoryId:
|
||||
@@ -360,20 +375,40 @@ export const useGoods = defineStore("goods", {
|
||||
name: this.goodsName,
|
||||
});
|
||||
|
||||
const originGoodsListRes = await productPage();
|
||||
this.originGoodsList = originGoodsListRes;
|
||||
this.originGoodsList = await productPage();
|
||||
|
||||
const socket = useSocket();
|
||||
if (socket.ws == null) {
|
||||
socket.init();
|
||||
// 获取限时折扣
|
||||
this.limitDiscountRes = await getLimitTimeDiscount({ shopId: store.shopInfo.id })
|
||||
|
||||
// 获取满减活动
|
||||
this.fullReductionActivities = await getDiscountActivity({ shopId: store.shopInfo.id })
|
||||
|
||||
// 新客立减
|
||||
if (this.vipUserInfo.id) {
|
||||
this.newCustomerDiscount = await getDiscountByUserId({
|
||||
shopId: store.shopInfo.id,
|
||||
shopUserId: this.vipUserInfo.id,
|
||||
orderId: this.orderListInfo.id || ''
|
||||
})
|
||||
}
|
||||
|
||||
res.map((val, index) => {
|
||||
val.showMore = false;
|
||||
val.orderCount = 0;
|
||||
this.originGoodsList.forEach(item => {
|
||||
item.showMore = false;
|
||||
item.orderCount = 0;
|
||||
item.is_time_discount = limitUtils.canUseLimitTimeDiscount(item,
|
||||
this.limitDiscountRes,
|
||||
store.shopInfo,
|
||||
this.vipUserInfo) ? 1 : 0
|
||||
});
|
||||
|
||||
// // 将数组分割成每页12个
|
||||
if (socket.ws == null) {
|
||||
await socket.init();
|
||||
if (this.limitDiscountRes !== null) {
|
||||
this.operateCart({ data: this.limitDiscountRes }, 'time_discount_save')
|
||||
}
|
||||
}
|
||||
|
||||
// 将数组分割成每页12个
|
||||
this.goodsList = _.chunk(res, 12);
|
||||
|
||||
let index = useStorage.get("categoryIndex") || 0;
|
||||
@@ -403,6 +438,8 @@ export const useGoods = defineStore("goods", {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
console.log('this.goodsList===', this.goodsList);
|
||||
|
||||
setTimeout(() => {
|
||||
this.goodsListLoading = false;
|
||||
}, 500);
|
||||
@@ -488,6 +525,7 @@ export const useGoods = defineStore("goods", {
|
||||
// 添加商品到购物车
|
||||
addCart(params) {
|
||||
console.log("添加商品到购物车===", params);
|
||||
const store = useUser()
|
||||
|
||||
let tableCode = "";
|
||||
if (this.tableInfo.tableCode) {
|
||||
@@ -524,8 +562,13 @@ export const useGoods = defineStore("goods", {
|
||||
pro_group_info: params.pro_group_info || [],
|
||||
goods_type: params.goods_type || "",
|
||||
product_type: params.type,
|
||||
is_time_discount: limitUtils.canUseLimitTimeDiscount(params, this.limitDiscountRes, store.shopInfo, this.vipUserInfo, 'productId') ? 1 : 0
|
||||
};
|
||||
this.operateCart(sendData, "add");
|
||||
|
||||
console.log('sendData', sendData);
|
||||
|
||||
|
||||
this.operateCart(sendData);
|
||||
},
|
||||
// 购物添加成功
|
||||
successAddCart(goodsInfoItem) {
|
||||
@@ -562,6 +605,8 @@ export const useGoods = defineStore("goods", {
|
||||
},
|
||||
// 补全商品信息
|
||||
completeGoodsInfo(item) {
|
||||
const store = useUser()
|
||||
|
||||
console.log('补全商品信息===', item);
|
||||
if (item.is_temporary) {
|
||||
item.salePrice = item.discount_sale_amount
|
||||
@@ -603,6 +648,7 @@ export const useGoods = defineStore("goods", {
|
||||
item.unitName = val.unitName;
|
||||
item.stockNumber = val.stockNumber;
|
||||
item.isStock = val.isStock;
|
||||
item.is_time_discount = limitUtils.canUseLimitTimeDiscount(val, this.limitDiscountRes, store.shopInfo, this.vipUserInfo) ? 1 : 0
|
||||
}
|
||||
});
|
||||
|
||||
@@ -647,6 +693,7 @@ export const useGoods = defineStore("goods", {
|
||||
item.is_temporary = item.isTemporary;
|
||||
item.discount_sale_amount = item.discountSaleAmount
|
||||
item.is_gift = item.isGift
|
||||
item.is_time_discount = item.isTimeDiscount
|
||||
});
|
||||
return item;
|
||||
},
|
||||
@@ -690,10 +737,37 @@ export const useGoods = defineStore("goods", {
|
||||
},
|
||||
// 商品更新后,需要对购物车、订单进行更新
|
||||
async updateGoodsList() {
|
||||
console.log('选择用户后更新所有===', this.vipUserInfo);
|
||||
const socket = useSocket();
|
||||
const store = useUser()
|
||||
|
||||
await this.getCategoryList();
|
||||
await this.getGoodsList();
|
||||
socket.cartInit();
|
||||
|
||||
console.log('选择用户后更新所有.cartList===', this.cartList);
|
||||
console.log('选择用户后更新所有.cartList===', this.orderList);
|
||||
|
||||
if (this.cartList.length || this.orderList.length) {
|
||||
let data = {
|
||||
cart: this.cartList.map(item => {
|
||||
return {
|
||||
id: item.id,
|
||||
is_time_discount: limitUtils.canUseLimitTimeDiscount(item, this.limitDiscountRes, store.shopId, this.vipUserInfo, 'product_id') ? 1 : 0
|
||||
}
|
||||
}),
|
||||
history: this.orderList
|
||||
.map((item) => item.goods)
|
||||
.flat().map(item => {
|
||||
return {
|
||||
id: item.id,
|
||||
is_time_discount: limitUtils.canUseLimitTimeDiscount(item, this.limitDiscountRes, store.shopId, this.vipUserInfo, 'productId') ? 1 : 0
|
||||
}
|
||||
})
|
||||
}
|
||||
this.operateCart({ data }, 'bulk_edit')
|
||||
}
|
||||
|
||||
await socket.cartInit();
|
||||
},
|
||||
// 清空购物车回执操作
|
||||
async successClearCart() {
|
||||
@@ -885,8 +959,6 @@ export const useGoods = defineStore("goods", {
|
||||
|
||||
const store = useUser();
|
||||
|
||||
const { OrderPriceCalculator } = yskUtils;
|
||||
|
||||
const shopInfo = ref(store.shopInfo) || {
|
||||
isMemberPrice: 0,
|
||||
isTableFee: 1,
|
||||
@@ -899,9 +971,6 @@ export const useGoods = defineStore("goods", {
|
||||
|
||||
var getAllGoodsList = () => {
|
||||
console.log('this.cartList===', this.cartList);
|
||||
|
||||
|
||||
|
||||
const currentGoods = (this.cartList).map(item => {
|
||||
return {
|
||||
...this.completeGoodsInfo(item),
|
||||
@@ -935,7 +1004,6 @@ export const useGoods = defineStore("goods", {
|
||||
|
||||
console.log('seatFeeConfig', seatFeeConfig.value);
|
||||
|
||||
|
||||
//积分规则
|
||||
const pointDeductionRule = ref({
|
||||
pointsPerYuan: options.pointsPerYuan,
|
||||
@@ -959,10 +1027,14 @@ export const useGoods = defineStore("goods", {
|
||||
additionalFee: 0,
|
||||
pointDeductionRule: pointDeductionRule.value,
|
||||
seatFeeConfig: seatFeeConfig.value,
|
||||
currentStoreId: "",
|
||||
currentStoreId: store.shopInfo.shopId,
|
||||
userPoints: userPoints.value,
|
||||
isMember: this.showVipPrice,
|
||||
memberDiscountRate: 1,
|
||||
fullReductionActivities: [this.fullReductionActivities],
|
||||
currentDinnerType: dinnerType.value,
|
||||
limitTimeDiscount: this.limitDiscountRes,
|
||||
shopUserInfo: this.vipUserInfo,
|
||||
newUserDiscount: newUserDiscount.value,
|
||||
}));
|
||||
|
||||
@@ -999,12 +1071,12 @@ export const useGoods = defineStore("goods", {
|
||||
},
|
||||
// 购物车操作
|
||||
operateCart(data, operate_type = "add") {
|
||||
|
||||
console.log(`购物车操作${operate_type}===`, data);
|
||||
|
||||
|
||||
const socket = useSocket();
|
||||
const store = useUser();
|
||||
|
||||
// data.is_time_discount = limitUtils.canUseLimitTimeDiscount(data, this.limitDiscountRes, store.shopInfo, this.vipUserInfo) ? 1 : 0
|
||||
|
||||
console.log(`购物车操作${operate_type}===`, data);
|
||||
if (socket.online) {
|
||||
socket.ws.send(
|
||||
JSON.stringify({
|
||||
|
||||
@@ -53,152 +53,157 @@ export const useSocket = defineStore("socket", {
|
||||
},
|
||||
// 初始化
|
||||
init(wsUrl = import.meta.env.VITE_API_WSS) {
|
||||
const store = useUser();
|
||||
const printStore = usePrint();
|
||||
const goodsStore = useGoods();
|
||||
return new Promise((resolve, reject) => {
|
||||
const store = useUser();
|
||||
const printStore = usePrint();
|
||||
const goodsStore = useGoods();
|
||||
|
||||
if (!store.shopInfo.id) return;
|
||||
if (!store.shopInfo.id) return;
|
||||
|
||||
printStore.init();
|
||||
printStore.init();
|
||||
|
||||
if (this.ws == null) {
|
||||
if (this.log) console.log("创建新的ws连接");
|
||||
if (this.ws == null) {
|
||||
if (this.log) console.log("创建新的ws连接");
|
||||
|
||||
const protocols = []; // 可选的子协议数组
|
||||
const options = {
|
||||
// 自动重新连接的选项(可选)
|
||||
connectionTimeout: 1000,
|
||||
maxRetries: 100,
|
||||
};
|
||||
this.ws = new ReconnectingWebSocket(wsUrl, protocols, options);
|
||||
} else {
|
||||
if (this.log) console.log("重新连接ws");
|
||||
this.wsReconnect();
|
||||
}
|
||||
|
||||
this.ws.addEventListener("open", (event) => {
|
||||
if (this.log) console.log("wss连接成功");
|
||||
this.online = true;
|
||||
// 清除心跳
|
||||
this.clearHeartBeat();
|
||||
if (this.log) console.log(this);
|
||||
this.cartInit();
|
||||
this.startheartbeat();
|
||||
});
|
||||
|
||||
this.ws.addEventListener("message", async (e) => {
|
||||
let data = JSON.parse(e.data);
|
||||
if (data.operate_type == "init") {
|
||||
// console.log("接收消息", data);
|
||||
if (!goodsStore.tableInfo.tableCode) {
|
||||
useStorage.set("tableCode", data.table_code);
|
||||
}
|
||||
goodsStore.getCartList(data.data);
|
||||
const protocols = []; // 可选的子协议数组
|
||||
const options = {
|
||||
// 自动重新连接的选项(可选)
|
||||
connectionTimeout: 1000,
|
||||
maxRetries: 100,
|
||||
};
|
||||
this.ws = new ReconnectingWebSocket(wsUrl, protocols, options);
|
||||
} else {
|
||||
if (this.log) console.log("重新连接ws");
|
||||
this.wsReconnect();
|
||||
}
|
||||
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
type: "receipt",
|
||||
msg_id: data.msg_id,
|
||||
})
|
||||
);
|
||||
this.ws.addEventListener("open", (event) => {
|
||||
if (this.log) console.log("wss连接成功");
|
||||
this.online = true;
|
||||
// 清除心跳
|
||||
this.clearHeartBeat();
|
||||
if (this.log) console.log(this);
|
||||
this.cartInit();
|
||||
this.startheartbeat();
|
||||
|
||||
if (data.data_type == "cart") {
|
||||
if (data.status == 1) {
|
||||
// 返回成功状态
|
||||
switch (data.operate_type) {
|
||||
case "add":
|
||||
// 添加购物车商品
|
||||
goodsStore.successAddCart(data.data);
|
||||
break;
|
||||
case "edit":
|
||||
// 编辑购物车商品
|
||||
goodsStore.successEditCart(data.data);
|
||||
break;
|
||||
case "del":
|
||||
// 删除购物车商品
|
||||
if (data.type && data.type == "bc") {
|
||||
goodsStore.successDeleteCartItem(data.data);
|
||||
} else {
|
||||
goodsStore.successDeleteCartItem();
|
||||
}
|
||||
break;
|
||||
case "cleanup":
|
||||
// 清空购物车
|
||||
if (
|
||||
data.data.table_code == goodsStore.orderListInfo.tableCode &&
|
||||
!data.type
|
||||
)
|
||||
return;
|
||||
goodsStore.successClearCart();
|
||||
break;
|
||||
case "batch":
|
||||
// 整单打包
|
||||
this.cartInit();
|
||||
break;
|
||||
case "rottable":
|
||||
// 转桌
|
||||
useStorage.set("tableCode", data.data.new_table_code);
|
||||
goodsStore.successClearCart();
|
||||
goodsStore.historyOrderAjax(data.data.new_table_code);
|
||||
this.cartInit();
|
||||
break;
|
||||
case "clearOrder":
|
||||
// 清空订单或删除订单
|
||||
goodsStore.historyOrderAjax(data.data.table_code);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
resolve()
|
||||
});
|
||||
|
||||
this.ws.addEventListener("message", async (e) => {
|
||||
let data = JSON.parse(e.data);
|
||||
if (data.operate_type == "init") {
|
||||
// console.log("接收消息", data);
|
||||
if (!goodsStore.tableInfo.tableCode) {
|
||||
useStorage.set("tableCode", data.table_code);
|
||||
}
|
||||
} else {
|
||||
if (data.type == "no_suit_num") {
|
||||
let product = goodsStore.cartList[goodsStore.cartActiveIndex];
|
||||
ElMessage.error(
|
||||
`${product.product_name}库存不足,已删除,请选择其他商品`
|
||||
);
|
||||
goodsStore.operateCart(product, "del");
|
||||
goodsStore.getCartList(data.data);
|
||||
}
|
||||
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
type: "receipt",
|
||||
msg_id: data.msg_id,
|
||||
})
|
||||
);
|
||||
|
||||
if (data.data_type == "cart") {
|
||||
if (data.status == 1) {
|
||||
// 返回成功状态
|
||||
switch (data.operate_type) {
|
||||
case "add":
|
||||
// 添加购物车商品
|
||||
goodsStore.successAddCart(data.data);
|
||||
break;
|
||||
case "edit":
|
||||
// 编辑购物车商品
|
||||
goodsStore.successEditCart(data.data);
|
||||
break;
|
||||
case "del":
|
||||
// 删除购物车商品
|
||||
if (data.type && data.type == "bc") {
|
||||
goodsStore.successDeleteCartItem(data.data);
|
||||
} else {
|
||||
goodsStore.successDeleteCartItem();
|
||||
}
|
||||
break;
|
||||
case "cleanup":
|
||||
// 清空购物车
|
||||
if (
|
||||
data.data.table_code == goodsStore.orderListInfo.tableCode &&
|
||||
!data.type
|
||||
)
|
||||
return;
|
||||
goodsStore.successClearCart();
|
||||
break;
|
||||
case "batch":
|
||||
// 整单打包
|
||||
this.cartInit();
|
||||
break;
|
||||
case "rottable":
|
||||
// 转桌
|
||||
useStorage.set("tableCode", data.data.new_table_code);
|
||||
goodsStore.successClearCart();
|
||||
goodsStore.historyOrderAjax(data.data.new_table_code);
|
||||
this.cartInit();
|
||||
break;
|
||||
case "clearOrder":
|
||||
// 清空订单或删除订单
|
||||
goodsStore.historyOrderAjax(data.data.table_code);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ElMessage.error(data.msg || "操作失败");
|
||||
if (data.type == "no_suit_num") {
|
||||
let product = goodsStore.cartList[goodsStore.cartActiveIndex];
|
||||
ElMessage.error(
|
||||
`${product.product_name}库存不足,已删除,请选择其他商品`
|
||||
);
|
||||
goodsStore.operateCart(product, "del");
|
||||
} else {
|
||||
ElMessage.error(data.msg || "操作失败");
|
||||
}
|
||||
}
|
||||
} else if (data.data_type == "order") {
|
||||
// 收到订单消息,打印订单小票
|
||||
let orderInfo = data.data.split("_");
|
||||
let orderId = orderInfo[0]; // 订单ID
|
||||
let orderModel = orderInfo[1]; // 订单类型
|
||||
let orderStatus = orderInfo[2]; // 订单状态
|
||||
|
||||
let printList = useStorage.get("printList") || [];
|
||||
|
||||
if (goodsStore.orderListInfo.tableCode) {
|
||||
goodsStore.historyOrderAjax(goodsStore.orderListInfo.tableCode);
|
||||
}
|
||||
|
||||
// 防止重复打印
|
||||
if (!printList.some((el) => el == orderId) && orderStatus == 1) {
|
||||
printList.push(orderId);
|
||||
useStorage.set("printList", _.uniq(printList));
|
||||
|
||||
this.orderList.push(orderId);
|
||||
this.startPrintInterval();
|
||||
}
|
||||
} else if (data.data_type == "product_update") {
|
||||
// 商品更新
|
||||
this.updateGoods();
|
||||
}
|
||||
} else if (data.data_type == "order") {
|
||||
// 收到订单消息,打印订单小票
|
||||
let orderInfo = data.data.split("_");
|
||||
let orderId = orderInfo[0]; // 订单ID
|
||||
let orderModel = orderInfo[1]; // 订单类型
|
||||
let orderStatus = orderInfo[2]; // 订单状态
|
||||
});
|
||||
|
||||
let printList = useStorage.get("printList") || [];
|
||||
this.ws.addEventListener("error", () => {
|
||||
if (this.log) console.log("WebSocket连接发生错误");
|
||||
this.online = false;
|
||||
this.clearHeartBeat();
|
||||
reject('WebSocket连接发生错误')
|
||||
});
|
||||
|
||||
if (goodsStore.orderListInfo.tableCode) {
|
||||
goodsStore.historyOrderAjax(goodsStore.orderListInfo.tableCode);
|
||||
}
|
||||
|
||||
// 防止重复打印
|
||||
if (!printList.some((el) => el == orderId) && orderStatus == 1) {
|
||||
printList.push(orderId);
|
||||
useStorage.set("printList", _.uniq(printList));
|
||||
|
||||
this.orderList.push(orderId);
|
||||
this.startPrintInterval();
|
||||
}
|
||||
} else if (data.data_type == "product_update") {
|
||||
// 商品更新
|
||||
this.updateGoods();
|
||||
}
|
||||
});
|
||||
|
||||
this.ws.addEventListener("error", () => {
|
||||
if (this.log) console.log("WebSocket连接发生错误");
|
||||
this.online = false;
|
||||
this.clearHeartBeat();
|
||||
});
|
||||
|
||||
this.ws.addEventListener("error", (e) => {
|
||||
if (this.log) console.log("ws关闭了", e);
|
||||
this.online = false;
|
||||
this.clearHeartBeat();
|
||||
});
|
||||
this.ws.addEventListener("error", (e) => {
|
||||
if (this.log) console.log("ws关闭了", e);
|
||||
this.online = false;
|
||||
this.clearHeartBeat();
|
||||
});
|
||||
})
|
||||
},
|
||||
updateGoods: _.throttle(function () {
|
||||
const goodsStore = useGoods();
|
||||
|
||||
@@ -68,6 +68,9 @@
|
||||
</div>
|
||||
<div class="num">
|
||||
<div class="left">
|
||||
<div class="icon_item zen" v-if="item.is_time_discount">
|
||||
<span class="t">限时折扣</span>
|
||||
</div>
|
||||
<div class="icon_item zen" v-if="props.item.is_gift">
|
||||
<span class="t">赠</span>
|
||||
</div>
|
||||
|
||||
@@ -76,9 +76,9 @@
|
||||
</transition>
|
||||
<div class="dot" v-if="item.number">{{ item.number }}</div>
|
||||
<div class="cover" v-if="shopListType == 'img'">
|
||||
<div class="xxzk" v-if="item.is_time_discount == 1">限时折扣</div>
|
||||
<el-image :src="`${item.coverImg}?x-oss-process=image/resize,m_lfit,w_120,h_120`"
|
||||
class="el_img" fit="cover"></el-image>
|
||||
|
||||
<!-- 已下架 -->
|
||||
<div class="sell_out" v-if="!item.isSale">
|
||||
<img class="sell_out_icon" src="@/assets/icon_goods_yxj.svg">
|
||||
@@ -96,7 +96,6 @@
|
||||
<div class="sell_out" v-else-if="item.isStock && item.stockNumber <= 0">
|
||||
<img class="sell_out_icon" src="@/assets/icon_goods_kcbz.svg">
|
||||
</div>
|
||||
|
||||
<div class="weight" v-if="item.type == 'weight'">称重</div>
|
||||
<div class="weight" v-if="item.type == 'package' && item.groupType == 1">可选套餐</div>
|
||||
<div class="weight" v-if="item.type == 'package' && item.groupType == 0">固定套餐</div>
|
||||
@@ -110,7 +109,7 @@
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-text tag="del" class="del" size="small">¥{{ item.skuList[0].salePrice
|
||||
}}</el-text>
|
||||
}}</el-text>
|
||||
<el-text>¥{{ +item.skuList[0].memberPrice || item.skuList[0].salePrice }}</el-text>
|
||||
</template>
|
||||
</div>
|
||||
@@ -1124,6 +1123,18 @@ onMounted(() => {
|
||||
height: 60%;
|
||||
position: relative;
|
||||
|
||||
.xxzk {
|
||||
padding: 1px 3px 2px 6px;
|
||||
border-radius: 0 0 0 10px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 10;
|
||||
font-size: 12px;
|
||||
color: #fff;
|
||||
background-color: var(--el-color-danger);
|
||||
}
|
||||
|
||||
.weight {
|
||||
position: absolute;
|
||||
left: 4px;
|
||||
|
||||
@@ -265,13 +265,16 @@ function printReloadHandle() {
|
||||
}
|
||||
|
||||
// 选择会员
|
||||
function selectUser(row) {
|
||||
async function selectUser(row) {
|
||||
console.log('selectUser===', row);
|
||||
|
||||
goodsStore.vipUserInfo = { ...row }
|
||||
if (store.shopInfo.isMemberPrice && row.isVip) {
|
||||
goodsStore.showVipPrice = 1
|
||||
}
|
||||
|
||||
await goodsStore.updateGoodsList()
|
||||
|
||||
goodsStore.calcCartInfo()
|
||||
}
|
||||
|
||||
@@ -297,13 +300,14 @@ async function createOrderHandle(t = 0) {
|
||||
shopId: store.shopInfo.id, // 店铺id
|
||||
seatNum: goodsStore.tableInfo.num || 0, // 用餐人数
|
||||
packFee: goodsStore.cartInfo.packFee, // 打包费
|
||||
originAmount: formatDecimal(+goodsStore.cartInfo.totalAmount, 2, true), // 订单原金额(包含打包费+餐位费) 不含折扣价格
|
||||
originAmount: goodsStore.cartInfo.costSummary.goodsOriginalAmount,
|
||||
tableCode: goodsStore.cartList[0].table_code, // 台桌号
|
||||
dineMode: goodsStore.allSelected ? store.shopInfo.eatModel.split(',')[1] : store.shopInfo.eatModel.split(',')[0], // 用餐方式
|
||||
remark: remark.value, // 备注
|
||||
placeNum: (goodsStore.orderListInfo.placeNum || 0) + 1, // 下单次数
|
||||
waitCall: 0, // 是否叫号
|
||||
userId: goodsStore.vipUserInfo.userId, // 会员用户id
|
||||
userId: goodsStore.vipUserInfo.userId || '', // 会员用户id
|
||||
limitRate: goodsStore.limitDiscountRes
|
||||
}
|
||||
|
||||
createOrderLoading.value = true;
|
||||
|
||||
Reference in New Issue
Block a user