This commit is contained in:
gyq
2025-10-13 13:30:26 +08:00
parent aabbeced98
commit aa82851361
2 changed files with 365 additions and 677 deletions

300
package-lock.json generated
View File

@@ -7,6 +7,7 @@
"": { "": {
"name": "vite-electron", "name": "vite-electron",
"version": "2.0.7", "version": "2.0.7",
"hasInstallScript": true,
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "^2.3.1", "@element-plus/icons-vue": "^2.3.1",
"axios": "^1.6.2", "axios": "^1.6.2",
@@ -21,7 +22,6 @@
"pinia-plugin-persistedstate": "^3.2.1", "pinia-plugin-persistedstate": "^3.2.1",
"qrcode": "^1.5.3", "qrcode": "^1.5.3",
"reconnecting-websocket": "^4.4.0", "reconnecting-websocket": "^4.4.0",
"serialport": "^12.0.0",
"speak-tts": "^2.0.8", "speak-tts": "^2.0.8",
"swiper": "^11.1.1", "swiper": "^11.1.1",
"uuid": "^10.0.0", "uuid": "^10.0.0",
@@ -1646,252 +1646,6 @@
"win32" "win32"
] ]
}, },
"node_modules/@serialport/binding-mock": {
"version": "10.2.2",
"resolved": "https://registry.npmmirror.com/@serialport/binding-mock/-/binding-mock-10.2.2.tgz",
"integrity": "sha512-HAFzGhk9OuFMpuor7aT5G1ChPgn5qSsklTFOTUX72Rl6p0xwcSVsRtG/xaGp6bxpN7fI9D/S8THLBWbBgS6ldw==",
"dependencies": {
"@serialport/bindings-interface": "^1.2.1",
"debug": "^4.3.3"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/@serialport/bindings-cpp": {
"version": "12.0.1",
"resolved": "https://registry.npmmirror.com/@serialport/bindings-cpp/-/bindings-cpp-12.0.1.tgz",
"integrity": "sha512-r2XOwY2dDvbW7dKqSPIk2gzsr6M6Qpe9+/Ngs94fNaNlcTRCV02PfaoDmRgcubpNVVcLATlxSxPTIDw12dbKOg==",
"hasInstallScript": true,
"dependencies": {
"@serialport/bindings-interface": "1.2.2",
"@serialport/parser-readline": "11.0.0",
"debug": "4.3.4",
"node-addon-api": "7.0.0",
"node-gyp-build": "4.6.0"
},
"engines": {
"node": ">=16.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/bindings-cpp/node_modules/@serialport/parser-delimiter": {
"version": "11.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-delimiter/-/parser-delimiter-11.0.0.tgz",
"integrity": "sha512-aZLJhlRTjSmEwllLG7S4J8s8ctRAS0cbvCpO87smLvl3e4BgzbVgF6Z6zaJd3Aji2uSiYgfedCdNc4L6W+1E2g==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/bindings-cpp/node_modules/@serialport/parser-readline": {
"version": "11.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-readline/-/parser-readline-11.0.0.tgz",
"integrity": "sha512-rRAivhRkT3YO28WjmmG4FQX6L+KMb5/ikhyylRfzWPw0nSXy97+u07peS9CbHqaNvJkMhH1locp2H36aGMOEIA==",
"dependencies": {
"@serialport/parser-delimiter": "11.0.0"
},
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/bindings-cpp/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/@serialport/bindings-cpp/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/@serialport/bindings-cpp/node_modules/node-addon-api": {
"version": "7.0.0",
"resolved": "https://registry.npmmirror.com/node-addon-api/-/node-addon-api-7.0.0.tgz",
"integrity": "sha512-vgbBJTS4m5/KkE16t5Ly0WW9hz46swAstv0hYYwMtbG7AznRhNyfLRe8HZAiWIpcHzoO7HxhLuBQj9rJ/Ho0ZA=="
},
"node_modules/@serialport/bindings-cpp/node_modules/node-gyp-build": {
"version": "4.6.0",
"resolved": "https://registry.npmmirror.com/node-gyp-build/-/node-gyp-build-4.6.0.tgz",
"integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==",
"bin": {
"node-gyp-build": "bin.js",
"node-gyp-build-optional": "optional.js",
"node-gyp-build-test": "build-test.js"
}
},
"node_modules/@serialport/bindings-interface": {
"version": "1.2.2",
"resolved": "https://registry.npmmirror.com/@serialport/bindings-interface/-/bindings-interface-1.2.2.tgz",
"integrity": "sha512-CJaUd5bLvtM9c5dmO9rPBHPXTa9R2UwpkJ0wdh9JCYcbrPWsKz+ErvR0hBLeo7NPeiFdjFO4sonRljiw4d2XiA==",
"engines": {
"node": "^12.22 || ^14.13 || >=16"
}
},
"node_modules/@serialport/parser-byte-length": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-byte-length/-/parser-byte-length-12.0.0.tgz",
"integrity": "sha512-0ei0txFAj+s6FTiCJFBJ1T2hpKkX8Md0Pu6dqMrYoirjPskDLJRgZGLqoy3/lnU1bkvHpnJO+9oJ3PB9v8rNlg==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/parser-cctalk": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-cctalk/-/parser-cctalk-12.0.0.tgz",
"integrity": "sha512-0PfLzO9t2X5ufKuBO34DQKLXrCCqS9xz2D0pfuaLNeTkyGUBv426zxoMf3rsMRodDOZNbFblu3Ae84MOQXjnZw==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/parser-delimiter": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-delimiter/-/parser-delimiter-12.0.0.tgz",
"integrity": "sha512-gu26tVt5lQoybhorLTPsH2j2LnX3AOP2x/34+DUSTNaUTzu2fBXw+isVjQJpUBFWu6aeQRZw5bJol5X9Gxjblw==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/parser-inter-byte-timeout": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-inter-byte-timeout/-/parser-inter-byte-timeout-12.0.0.tgz",
"integrity": "sha512-GnCh8K0NAESfhCuXAt+FfBRz1Cf9CzIgXfp7SdMgXwrtuUnCC/yuRTUFWRvuzhYKoAo1TL0hhUo77SFHUH1T/w==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/parser-packet-length": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-packet-length/-/parser-packet-length-12.0.0.tgz",
"integrity": "sha512-p1hiCRqvGHHLCN/8ZiPUY/G0zrxd7gtZs251n+cfNTn+87rwcdUeu9Dps3Aadx30/sOGGFL6brIRGK4l/t7MuQ==",
"engines": {
"node": ">=8.6.0"
}
},
"node_modules/@serialport/parser-readline": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-readline/-/parser-readline-12.0.0.tgz",
"integrity": "sha512-O7cywCWC8PiOMvo/gglEBfAkLjp/SENEML46BXDykfKP5mTPM46XMaX1L0waWU6DXJpBgjaL7+yX6VriVPbN4w==",
"dependencies": {
"@serialport/parser-delimiter": "12.0.0"
},
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/parser-ready": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-ready/-/parser-ready-12.0.0.tgz",
"integrity": "sha512-ygDwj3O4SDpZlbrRUraoXIoIqb8sM7aMKryGjYTIF0JRnKeB1ys8+wIp0RFMdFbO62YriUDextHB5Um5cKFSWg==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/parser-regex": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-regex/-/parser-regex-12.0.0.tgz",
"integrity": "sha512-dCAVh4P/pZrLcPv9NJ2mvPRBg64L5jXuiRxIlyxxdZGH4WubwXVXY/kBTihQmiAMPxbT3yshSX8f2+feqWsxqA==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/parser-slip-encoder": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-slip-encoder/-/parser-slip-encoder-12.0.0.tgz",
"integrity": "sha512-0APxDGR9YvJXTRfY+uRGhzOhTpU5akSH183RUcwzN7QXh8/1jwFsFLCu0grmAUfi+fItCkR+Xr1TcNJLR13VNA==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/parser-spacepacket": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/parser-spacepacket/-/parser-spacepacket-12.0.0.tgz",
"integrity": "sha512-dozONxhPC/78pntuxpz/NOtVps8qIc/UZzdc/LuPvVsqCoJXiRxOg6ZtCP/W58iibJDKPZPAWPGYeZt9DJxI+Q==",
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/stream": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/@serialport/stream/-/stream-12.0.0.tgz",
"integrity": "sha512-9On64rhzuqKdOQyiYLYv2lQOh3TZU/D3+IWCR5gk0alPel2nwpp4YwDEGiUBfrQZEdQ6xww0PWkzqth4wqwX3Q==",
"dependencies": {
"@serialport/bindings-interface": "1.2.2",
"debug": "4.3.4"
},
"engines": {
"node": ">=12.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/@serialport/stream/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/@serialport/stream/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/@sindresorhus/is": { "node_modules/@sindresorhus/is": {
"version": "4.6.0", "version": "4.6.0",
"resolved": "https://registry.npmmirror.com/@sindresorhus/is/-/is-4.6.0.tgz", "resolved": "https://registry.npmmirror.com/@sindresorhus/is/-/is-4.6.0.tgz",
@@ -3570,6 +3324,7 @@
"version": "4.4.3", "version": "4.4.3",
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.4.3.tgz", "resolved": "https://registry.npmmirror.com/debug/-/debug-4.4.3.tgz",
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
"dev": true,
"dependencies": { "dependencies": {
"ms": "^2.1.3" "ms": "^2.1.3"
}, },
@@ -5832,7 +5587,8 @@
"node_modules/ms": { "node_modules/ms": {
"version": "2.1.3", "version": "2.1.3",
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz", "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"dev": true
}, },
"node_modules/nanoid": { "node_modules/nanoid": {
"version": "3.3.11", "version": "3.3.11",
@@ -6881,54 +6637,6 @@
"randombytes": "^2.1.0" "randombytes": "^2.1.0"
} }
}, },
"node_modules/serialport": {
"version": "12.0.0",
"resolved": "https://registry.npmmirror.com/serialport/-/serialport-12.0.0.tgz",
"integrity": "sha512-AmH3D9hHPFmnF/oq/rvigfiAouAKyK/TjnrkwZRYSFZxNggJxwvbAbfYrLeuvq7ktUdhuHdVdSjj852Z55R+uA==",
"dependencies": {
"@serialport/binding-mock": "10.2.2",
"@serialport/bindings-cpp": "12.0.1",
"@serialport/parser-byte-length": "12.0.0",
"@serialport/parser-cctalk": "12.0.0",
"@serialport/parser-delimiter": "12.0.0",
"@serialport/parser-inter-byte-timeout": "12.0.0",
"@serialport/parser-packet-length": "12.0.0",
"@serialport/parser-readline": "12.0.0",
"@serialport/parser-ready": "12.0.0",
"@serialport/parser-regex": "12.0.0",
"@serialport/parser-slip-encoder": "12.0.0",
"@serialport/parser-spacepacket": "12.0.0",
"@serialport/stream": "12.0.0",
"debug": "4.3.4"
},
"engines": {
"node": ">=16.0.0"
},
"funding": {
"url": "https://opencollective.com/serialport/donate"
}
},
"node_modules/serialport/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/serialport/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/set-blocking": { "node_modules/set-blocking": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmmirror.com/set-blocking/-/set-blocking-2.0.0.tgz", "resolved": "https://registry.npmmirror.com/set-blocking/-/set-blocking-2.0.0.tgz",

View File

@@ -1,10 +1,6 @@
import { import { BigNumber } from "bignumber.js";
BigNumber
} from "bignumber.js";
import _ from "lodash"; import _ from "lodash";
/** /**
* 返回商品单价 * 返回商品单价
* @param goods 商品 * @param goods 商品
@@ -12,19 +8,19 @@ import _ from "lodash";
* @param {Object} shopInfo * @param {Object} shopInfo
*/ */
export function returnGoodsPrice(goods, user, shopInfo) { export function returnGoodsPrice(goods, user, shopInfo) {
if (!goods) { if (!goods) {
return 0 return 0;
} }
if (goods.discount_sale_amount * 1 > 0) { if (goods.discount_sale_amount * 1 > 0) {
return goods.discount_sale_amount; return goods.discount_sale_amount;
} }
if (shopInfo && !shopInfo.isMemberPrice) { if (shopInfo && !shopInfo.isMemberPrice) {
return goods.salePrice; return goods.salePrice;
} }
if (user.isVip && goods.memberPrice * 1 <= goods.salePrice * 1 && goods.memberPrice * 1 > 0) { if (user.isVip && goods.memberPrice * 1 <= goods.salePrice * 1 && goods.memberPrice * 1 > 0) {
return goods.memberPrice; return goods.memberPrice;
} }
return goods.salePrice; return goods.salePrice;
} }
/** /**
@@ -32,15 +28,15 @@ export function returnGoodsPrice(goods, user, shopInfo) {
* @param arr 商品列表 * @param arr 商品列表
*/ */
export function returnGoodsGroupMap(arr) { export function returnGoodsGroupMap(arr) {
let map = {}; let map = {};
arr.forEach((v) => { arr.forEach((v) => {
const key = v.productId + "_" + v.skuId; const key = v.productId + "_" + v.skuId;
if (!map[key]) { if (!map[key]) {
map[key] = []; map[key] = [];
} }
map[key].push(v); map[key].push(v);
}); });
return map; return map;
} }
/** /**
@@ -48,17 +44,17 @@ export function returnGoodsGroupMap(arr) {
* @param coupon * @param coupon
*/ */
export function returnCoupType(coupon) { export function returnCoupType(coupon) {
const couponTypes = { const couponTypes = {
1: "满减券", 1: "满减券",
2: "商品券", 2: "商品券",
3: "折扣券", 3: "折扣券",
4: "第二件半价券", 4: "第二件半价券",
5: "消费送券", 5: "消费送券",
6: "买一送一券", 6: "买一送一券",
7: "固定价格券", 7: "固定价格券",
8: "免配送费券", 8: "免配送费券",
}; };
return couponTypes[coupon.type] || "未知类型"; return couponTypes[coupon.type] || "未知类型";
} }
/** /**
@@ -68,37 +64,37 @@ export function returnCoupType(coupon) {
* @param user 用户信息 * @param user 用户信息
*/ */
export function returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user) { export function returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user) {
const types = [2, 4, 6]; const types = [2, 4, 6];
// 收集已抵扣商品并关联对应的优惠券类型 // 收集已抵扣商品并关联对应的优惠券类型
const goodsCouponGoods = selCoupon const goodsCouponGoods = selCoupon
.filter((v) => types.includes(v.type)) .filter((v) => types.includes(v.type))
.reduce((prev, cur) => { .reduce((prev, cur) => {
// 给每个抵扣商品添加所属优惠券类型 // 给每个抵扣商品添加所属优惠券类型
const goodsWithType = cur.discount.hasDiscountGoodsArr.map(goods => ({ const goodsWithType = cur.discount.hasDiscountGoodsArr.map((goods) => ({
...goods, ...goods,
couponType: cur.type // 记录该商品是被哪种类型的优惠券抵扣的 couponType: cur.type, // 记录该商品是被哪种类型的优惠券抵扣的
})); }));
prev.push(...goodsWithType); prev.push(...goodsWithType);
return prev; return prev;
}, []); }, []);
const arr = _.cloneDeep(canDikouGoodsArr) const arr = _.cloneDeep(canDikouGoodsArr)
.map((v) => { .map((v) => {
const findCart = goodsCouponGoods.find((carts) => carts.id == v.id); const findCart = goodsCouponGoods.find((carts) => carts.id == v.id);
if (findCart) { if (findCart) {
// 根据优惠券类型判断扣减数量 // 根据优惠券类型判断扣减数量
if ([4, 6].includes(findCart.couponType)) { if ([4, 6].includes(findCart.couponType)) {
// 类型4第二件半价或6买一送一数量减2 // 类型4第二件半价或6买一送一数量减2
v.num -= 2; v.num -= 2;
} else { } else {
// 其他类型如类型2商品券按原逻辑扣减对应数量 // 其他类型如类型2商品券按原逻辑扣减对应数量
v.num -= findCart.num; v.num -= findCart.num;
} }
} }
return v; return v;
}) })
.filter((v) => v.num > 0); // 过滤掉数量<=0的商品 .filter((v) => v.num > 0); // 过滤掉数量<=0的商品
return arr; return arr;
} }
/** /**
@@ -118,177 +114,178 @@ export function returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user) {
* @returns {Object} - { canUse: boolean, reason: string } 可用状态及不可用原因 * @returns {Object} - { canUse: boolean, reason: string } 可用状态及不可用原因
*/ */
export function returnCouponCanUse(args) { export function returnCouponCanUse(args) {
let { let { canDikouGoodsArr, coupon, goodsOrderPrice, user, selCoupon, shopInfo } = args;
canDikouGoodsArr, // 优惠券未启用
coupon, if (!coupon.use) {
goodsOrderPrice, return {
user, canUse: false,
selCoupon, reason: coupon.noUseRestrictions || "不在可用时间段内",
shopInfo };
} = args; }
// 优惠券未启用
if (!coupon.use) {
return {
canUse: false,
reason:coupon.noUseRestrictions|| "不在可用时间段内"
};
}
// 计算门槛金额 // 计算门槛金额
let fullAmount = goodsOrderPrice; let fullAmount = goodsOrderPrice;
canDikouGoodsArr = returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user, shopInfo); canDikouGoodsArr = returnCanDikouGoodsArr(canDikouGoodsArr, selCoupon, user, shopInfo);
//优惠券指定门槛商品列表 //优惠券指定门槛商品列表
let canCalcGoodsArr = [...canDikouGoodsArr] let canCalcGoodsArr = [...canDikouGoodsArr];
//部分商品参与门槛计算 //部分商品参与门槛计算
if (coupon.thresholdFoods.length) { if (coupon.thresholdFoods.length) {
canCalcGoodsArr = canDikouGoodsArr.filter((v) => { canCalcGoodsArr = canDikouGoodsArr.filter((v) => {
return coupon.thresholdFoods.find((food) => food.id == v.productId); return coupon.thresholdFoods.find((food) => food.id == v.productId);
}); });
fullAmount = canCalcGoodsArr.reduce((pre, cur) => { fullAmount = canCalcGoodsArr.reduce((pre, cur) => {
return pre + returnGoodsPrice(cur, user, shopInfo) * cur.num; return pre + returnGoodsPrice(cur, user, shopInfo) * cur.num;
}, 0); }, 0);
} }
// 是否全部商品可用
const isDikouAll = coupon.useFoods.length === 0;
// 订单可用商品列表
let canUseGoodsArr = [];
if (!isDikouAll) {
canUseGoodsArr = canDikouGoodsArr.filter((v) => {
return coupon.useFoods.find((food) => food.id == v.productId);
});
}
if (user.isVip && !coupon.vipPriceShare) {
return {
canUse: false,
reason: "非会员可用",
};
}
if (selCoupon.length > 0 && !selCoupon[0].otherCouponShare) {
return {
canUse: false,
reason: "当前选中的券不可与其他券同享",
};
}
if (selCoupon.length > 0 && !coupon.otherCouponShare) {
return {
canUse: false,
reason: "当前选中的券不可与其他券同享",
};
}
// 满减券和折扣券计算门槛金额是否满足
if ([1, 3].includes(coupon.type)) {
if (canCalcGoodsArr.length <= 0) {
return {
canUse: false,
reason: "没有可参与计算门槛的商品",
};
}
// 不满足门槛金额
if (fullAmount < coupon.fullAmount) {
return {
canUse: false,
reason: `${coupon.fullAmount}元可用,当前可参与金额${fullAmount}`,
};
}
}
// 商品兑换券,第二件半价和买一送一判断是否有可用商品
if ([2, 4, 5].includes(coupon.type)) {
console.log("商品兑换券", fullAmount, coupon.fullAmount);
if (coupon.type == 2 && fullAmount < coupon.fullAmount) {
console.log("商品兑换券", coupon);
return {
canUse: false,
reason: `${coupon.fullAmount}元可用,当前可参与金额${fullAmount}`,
};
}
// 没有符合条件的商品
if (isDikouAll && canDikouGoodsArr.length === 0) {
return {
canUse: false,
reason: "没有符合条件的商品",
};
}
if (!isDikouAll && canUseGoodsArr.length === 0) {
return {
canUse: false,
reason: "没有符合条件的商品",
};
}
}
//商品兑换券是否达到门槛金额
if (coupon.type == 2 && goodsOrderPrice < coupon.fullAmount) {
return {
canUse: false,
reason: `${coupon.fullAmount}元可用,当前可参与金额${fullAmount}`,
};
}
// 是否全部商品可用 // 买一送一券特殊验证
const isDikouAll = coupon.useFoods.length === 0; if (coupon.type === 6) {
// 订单可用商品列表 let canUse = false;
let canUseGoodsArr = []; if (isDikouAll) {
if (!isDikouAll) { canUse = canDikouGoodsArr.some((v) => v.num >= 2);
canUseGoodsArr = canDikouGoodsArr.filter((v) => { } else if (canCalcGoodsArr.length > 0) {
return coupon.useFoods.find((food) => food.id == v.productId); canUse = canCalcGoodsArr.some((v) => v.num >= 2);
}); }
}
if (user.isVip && !coupon.vipPriceShare) {
return {
canUse: false,
reason: "非会员可用"
};
}
if (selCoupon.length > 0 && !selCoupon[0].otherCouponShare) {
return {
canUse: false,
reason: "当前选中的券不可与其他券同享"
};
}
if (selCoupon.length > 0 && !coupon.otherCouponShare) {
return {
canUse: false,
reason: "当前选中的券不可与其他券同享"
};
}
// 满减券和折扣券计算门槛金额是否满足
if ([1, 3].includes(coupon.type)) {
if (canCalcGoodsArr.length <= 0) {
return {
canUse: false,
reason: "没有可参与计算门槛的商品"
};
}
// 不满足门槛金额
if (fullAmount < coupon.fullAmount) {
return {
canUse: false,
reason: `${coupon.fullAmount}元可用,当前可参与金额${fullAmount}`
};
}
}
// 商品兑换券,第二件半价和买一送一判断是否有可用商品
if ([2, 4, 5].includes(coupon.type)) {
// 没有符合条件的商品
if (isDikouAll && canDikouGoodsArr.length === 0) {
return {
canUse: false,
reason: "没有符合条件的商品"
};
}
if (!isDikouAll && canUseGoodsArr.length === 0) {
return {
canUse: false,
reason: "没有符合条件的商品"
};
}
}
//商品兑换券是否达到门槛金额
if (coupon.type == 2 && goodsOrderPrice < coupon.fullAmount) {
return {
canUse: false,
reason: `${coupon.fullAmount}元可用,当前可参与金额${fullAmount}`
};
}
// 买一送一券特殊验证 if (!canUse) {
if (coupon.type === 6) { return {
let canUse = false; canUse: false,
if (isDikouAll) { reason: "需要购买至少2件相同的商品才能使用",
canUse = canDikouGoodsArr.some((v) => v.num >= 2); };
} else if (canCalcGoodsArr.length > 0) { }
canUse = canCalcGoodsArr.some((v) => v.num >= 2); }
}
if (!canUse) { // 第二件半价券特殊验证
return { if (coupon.type === 4) {
canUse: false, let canUse = false;
reason: "需要购买至少2件相同的商品才能使用" if (isDikouAll) {
}; canUse = canDikouGoodsArr.some((v) => v.num >= 2);
} } else if (canCalcGoodsArr.length > 0) {
} canUse = canCalcGoodsArr.some((v) => v.num >= 2);
}
// 第二件半价券特殊验证 if (!canUse) {
if (coupon.type === 4) { return {
let canUse = false; canUse: false,
if (isDikouAll) { reason: "需要购买至少2件相同的商品才能使用",
canUse = canDikouGoodsArr.some((v) => v.num >= 2); };
} else if (canCalcGoodsArr.length > 0) { }
canUse = canCalcGoodsArr.some((v) => v.num >= 2); }
}
if (!canUse) { // 所有条件都满足
return { return {
canUse: false, canUse: true,
reason: "需要购买至少2件相同的商品才能使用" reason: "",
}; };
}
}
// 所有条件都满足
return {
canUse: true,
reason: ""
};
} }
/** /**
* 计算抵扣商品金额 * 计算抵扣商品金额
* @param discountGoodsArr 可抵扣商品列表 * @param discountGoodsArr 可抵扣商品列表
* @param discountNum 抵扣数量 * @param discountNum 抵扣数量
* @param user 用户信息 * @param user 用户信息
* @param {Object} shopInfo 店铺信息 * @param {Object} shopInfo 店铺信息
*/ */
export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, shopInfo) { export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, shopInfo) {
let hasCountNum = 0; let hasCountNum = 0;
let discountPrice = 0; let discountPrice = 0;
let hasDiscountGoodsArr = []; let hasDiscountGoodsArr = [];
for (let i = 0; i < discountGoodsArr.length; i++) { for (let i = 0; i < discountGoodsArr.length; i++) {
if (hasCountNum >= discountNum) { if (hasCountNum >= discountNum) {
break; break;
} }
const goods = discountGoodsArr[i]; const goods = discountGoodsArr[i];
const shengyuNum = discountNum - hasCountNum; const shengyuNum = discountNum - hasCountNum;
const num = Math.min(goods.num, shengyuNum); const num = Math.min(goods.num, shengyuNum);
discountPrice += returnGoodsPrice(goods, user, shopInfo) * num; discountPrice += returnGoodsPrice(goods, user, shopInfo) * num;
hasCountNum += num;
hasDiscountGoodsArr.push({ hasCountNum += num;
...goods, hasDiscountGoodsArr.push({
num ...goods,
}); num,
} });
return { }
discountPrice,
hasDiscountGoodsArr return {
}; discountPrice,
hasDiscountGoodsArr,
};
} }
/** /**
@@ -301,20 +298,20 @@ export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, s
* @param shopInfo 店铺信息 * @param shopInfo 店铺信息
*/ */
export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoupon, shopInfo) { export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoupon, shopInfo) {
const canDikouGoodsArr = returnCanDikouGoodsArr(arr, selCoupon, user); const canDikouGoodsArr = returnCanDikouGoodsArr(arr, selCoupon, user);
if (coupon.type == 2) { if (coupon.type == 2) {
return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo); return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo);
} }
if (coupon.type == 6) { if (coupon.type == 6) {
const result = returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo); const result = returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo);
return result return result;
} }
if (coupon.type == 4) { if (coupon.type == 4) {
return returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo); return returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo);
} }
if (coupon.type == 3) { if (coupon.type == 3) {
return returnCouponZhekouDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice, selCoupon); return returnCouponZhekouDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice, selCoupon);
} }
} }
/** /**
@@ -327,45 +324,42 @@ export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoup
* *
*/ */
export function returnCouponZhekouDiscount( export function returnCouponZhekouDiscount(
canDikouGoodsArr, canDikouGoodsArr,
coupon, coupon,
user, user,
goodsOrderPrice, goodsOrderPrice,
selCoupon selCoupon
) { ) {
const { const { discountRate, maxDiscountAmount } = coupon;
discountRate,
maxDiscountAmount
} = coupon;
// 计算商品优惠券折扣总和使用BigNumber避免精度问题 // 计算商品优惠券折扣总和使用BigNumber避免精度问题
const goodsCouponDiscount = selCoupon const goodsCouponDiscount = selCoupon
.filter((v) => v.type == 2) .filter((v) => v.type == 2)
.reduce((prve, cur) => { .reduce((prve, cur) => {
return new BigNumber(prve).plus(new BigNumber(cur.discount.discountPrice)); return new BigNumber(prve).plus(new BigNumber(cur.discount.discountPrice));
}, new BigNumber(0)); }, new BigNumber(0));
// 将商品订单价格转换为BigNumber并减去优惠券折扣 // 将商品订单价格转换为BigNumber并减去优惠券折扣
const adjustedGoodsOrderPrice = new BigNumber(goodsOrderPrice).minus(goodsCouponDiscount); const adjustedGoodsOrderPrice = new BigNumber(goodsOrderPrice).minus(goodsCouponDiscount);
console.log('adjustedGoodsOrderPrice', adjustedGoodsOrderPrice.toNumber());
// 计算优惠比例:(100 - 折扣率) / 100 // 计算优惠比例:(100 - 折扣率) / 100
const discountAmountRatio = new BigNumber(100).minus(discountRate).dividedBy(100); const discountAmountRatio = new BigNumber(100).minus(discountRate).dividedBy(100);
// 计算折扣金额:调整后的商品订单金额 × 优惠比例 // 计算折扣金额:调整后的商品订单金额 × 优惠比例
let discountPrice = adjustedGoodsOrderPrice.times(discountAmountRatio) let discountPrice = adjustedGoodsOrderPrice
.decimalPlaces(2, BigNumber.ROUND_FLOOR) .times(discountAmountRatio)
.toNumber(); .decimalPlaces(2, BigNumber.ROUND_FLOOR)
.toNumber();
// 应用最大折扣金额限制 // 应用最大折扣金额限制
if (maxDiscountAmount !== 0) { if (maxDiscountAmount !== 0) {
discountPrice = discountPrice >= maxDiscountAmount ? maxDiscountAmount : discountPrice; discountPrice = discountPrice >= maxDiscountAmount ? maxDiscountAmount : discountPrice;
} }
return { return {
discountPrice, // 折扣抵扣金额(即优惠的金额) discountPrice, // 折扣抵扣金额(即优惠的金额)
hasDiscountGoodsArr: [], hasDiscountGoodsArr: [],
}; };
} }
/** /**
@@ -376,37 +370,29 @@ export function returnCouponZhekouDiscount(
* @param shopInfo 店铺信息 * @param shopInfo 店铺信息
*/ */
export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo) { export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo) {
const { const { useFoods, discountNum, useRule } = coupon;
useFoods, //抵扣商品数组
discountNum, let discountGoodsArr = [];
useRule //抵扣全部商品
} = coupon; if (useFoods.length === 0) {
//抵扣商品数组 if (useRule == "price_asc") {
let discountGoodsArr = []; discountGoodsArr = canDikouGoodsArr.slice(discountNum * -1).reverse();
//抵扣全部商品 } else {
if (useFoods.length === 0) { discountGoodsArr = canDikouGoodsArr.slice(0, discountNum);
if (useRule == "price_asc") { }
discountGoodsArr = canDikouGoodsArr } else {
.slice(canDikouGoodsArr.length - discountNum, canDikouGoodsArr.length) //抵扣选中商品
.reverse(); const discountSelGoodsArr = canDikouGoodsArr.filter((v) =>
} else { useFoods.find((food) => food.id == v.productId)
discountGoodsArr = canDikouGoodsArr.slice(0, discountNum); );
} if (useRule == "price_asc") {
} else { discountGoodsArr = discountSelGoodsArr.slice(discountNum * -1).reverse();
//抵扣选中商品 } else {
const discountSelGoodsArr = canDikouGoodsArr.filter((v) => discountGoodsArr = discountSelGoodsArr.slice(0, discountNum);
useFoods.find((food) => food.id == v.productId) }
); }
if (useRule == "price_asc") { const result = calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, shopInfo);
discountGoodsArr = discountSelGoodsArr return result;
.slice(discountSelGoodsArr.length - discountNum, discountSelGoodsArr.length)
.reverse();
} else {
discountGoodsArr = discountSelGoodsArr.slice(0, discountNum);
}
}
const result = calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, shopInfo);
return result;
} }
// 返回买一送一券抵扣详情 // 返回买一送一券抵扣详情
@@ -417,41 +403,38 @@ export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shop
* @param shopInfo 店铺信息 * @param shopInfo 店铺信息
*/ */
function returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo) { function returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo) {
const { const { useFoods, useRule } = coupon;
useFoods, //抵扣商品
useRule let discountGoods = undefined;
} = coupon; //符合买一送一条件的商品
//抵扣商品 const canUseGoods = canDikouGoodsArr.filter((v) => v.num >= 2);
let discountGoods = undefined; //抵扣全部商品
//符合买一送一条件的商品 if (useFoods.length === 0) {
const canUseGoods = canDikouGoodsArr.filter((v) => v.num >= 2); if (useRule == "price_asc") {
//抵扣全部商品 discountGoods = canUseGoods[canUseGoods.length - 1];
if (useFoods.length === 0) { } else {
if (useRule == "price_asc") { discountGoods = canUseGoods[0];
discountGoods = canUseGoods[canUseGoods.length - 1] }
} else { } else {
discountGoods = canUseGoods[0]; //符合抵扣条件的商品
} const canUseGoods1 = canUseGoods.filter((v) => useFoods.find((food) => food.id == v.productId));
} else { if (useRule == "price_asc") {
//符合抵扣条件的商品 discountGoods = canUseGoods1[canUseGoods1.length - 1];
const canUseGoods1 = canUseGoods.filter((v) => useFoods.find((food) => food.id == v.productId)); } else {
if (useRule == "price_asc") { discountGoods = canUseGoods1[0];
discountGoods = canUseGoods1[canUseGoods1.length - 1] }
} else { }
discountGoods = canUseGoods1[0] let discountPrice = 0;
} let hasDiscountGoodsArr = [];
} console.log("returnCouponBuyOneGiveOneDiscount:discountGoods", discountGoods);
let discountPrice = 0; if (discountGoods) {
let hasDiscountGoodsArr = [] discountPrice = returnGoodsPrice(discountGoods, user, shopInfo);
console.log('returnCouponBuyOneGiveOneDiscount:discountGoods',discountGoods); hasDiscountGoodsArr = [discountGoods];
if (discountGoods) { }
discountPrice = returnGoodsPrice(discountGoods, user, shopInfo); return {
hasDiscountGoodsArr = [discountGoods]; discountPrice: discountPrice <= 0 ? 0 : discountPrice,
} hasDiscountGoodsArr,
return { };
discountPrice:discountPrice<=0?0:discountPrice,
hasDiscountGoodsArr
};
} }
/** /**
@@ -462,41 +445,38 @@ function returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopI
* @param shopInfo 店铺信息 * @param shopInfo 店铺信息
*/ */
function returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo) { function returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo) {
const { const { useFoods, useRule } = coupon;
useFoods, //抵扣商品
useRule let discountGoods = undefined;
} = coupon; //符合条件的商品
//抵扣商品 const canUseGoods = canDikouGoodsArr.filter((v) => v.num >= 2);
let discountGoods = undefined; //抵扣全部商品
//符合条件的商品 if (useFoods.length === 0) {
const canUseGoods = canDikouGoodsArr.filter((v) => v.num >= 2); if (useRule == "price_asc") {
//抵扣全部商品 discountGoods = canUseGoods[canUseGoods.length - 1];
if (useFoods.length === 0) { } else {
if (useRule == "price_asc") { discountGoods = canUseGoods[0];
discountGoods = canUseGoods[canUseGoods.length - 1] }
} else { } else {
discountGoods = canUseGoods[0] //符合抵扣条件的商品
} const canUseGoods1 = canUseGoods.filter((v) => useFoods.find((food) => food.id == v.productId));
} else { if (useRule == "price_asc") {
//符合抵扣条件的商品 discountGoods = canUseGoods1[canUseGoods1.length - 1];
const canUseGoods1 = canUseGoods.filter((v) => useFoods.find((food) => food.id == v.productId)); } else {
if (useRule == "price_asc") { discountGoods = canUseGoods1[0];
discountGoods = canUseGoods1[canUseGoods1.length - 1] }
} else { }
discountGoods = canUseGoods1[0] let discountPrice = 0;
} let hasDiscountGoodsArr = [];
} if (discountGoods) {
let discountPrice = 0; discountPrice = returnGoodsPrice(discountGoods, user, shopInfo);
let hasDiscountGoodsArr = [] hasDiscountGoodsArr = [discountGoods];
if (discountGoods) { }
discountPrice = returnGoodsPrice(discountGoods, user, shopInfo); //返回半价价格
hasDiscountGoodsArr = [discountGoods]; return {
} discountPrice: discountPrice <= 0 ? 0 : new BigNumber(discountPrice).dividedBy(2).toNumber(),
//返回半价价格 hasDiscountGoodsArr,
return { };
discountPrice: discountPrice <= 0 ? 0 : new BigNumber(discountPrice).dividedBy(2).toNumber(),
hasDiscountGoodsArr,
};
} }
/** /**
@@ -506,15 +486,15 @@ function returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo) {
* @param shopInfo 店铺信息 * @param shopInfo 店铺信息
*/ */
export function returnCanDikouGoods(arr, user, shopInfo) { export function returnCanDikouGoods(arr, user, shopInfo) {
const result = arr const result = arr
.filter((v) => { .filter((v) => {
return v.is_temporary != 1 && v.is_gift != 1; return v.is_temporary != 1 && v.is_gift != 1;
}) })
.filter((v) => { .filter((v) => {
return v.num > 0; return v.num > 0;
}) })
.sort((a, b) => { .sort((a, b) => {
return returnGoodsPrice(b, user, shopInfo) - returnGoodsPrice(a, user, shopInfo); return returnGoodsPrice(b, user, shopInfo) - returnGoodsPrice(a, user, shopInfo);
}); });
return result; return result;
} }