ts-glitter 20.3.2 → 20.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lowcode/Entry.js +1 -1
- package/lowcode/Entry.ts +1 -1
- package/lowcode/backend-manager/bg-product.js +21 -15
- package/lowcode/backend-manager/bg-product.ts +32 -22
- package/lowcode/backend-manager/bg-widget.ts +1 -1
- package/lowcode/cms-plugin/model/order.d.ts +1 -0
- package/lowcode/cms-plugin/module/order-setting.js +118 -22
- package/lowcode/cms-plugin/module/order-setting.ts +133 -22
- package/lowcode/cms-plugin/order/order-module.js +366 -0
- package/lowcode/cms-plugin/order/order-module.ts +404 -0
- package/lowcode/cms-plugin/shopping-order-manager.js +21 -9
- package/lowcode/cms-plugin/shopping-order-manager.ts +21 -9
- package/lowcode/css/editor.css +14 -0
- package/package.json +1 -1
- package/src/api-public/controllers/ai-points.js.map +1 -1
- package/src/api-public/controllers/index.js.map +1 -1
- package/src/api-public/controllers/track.js.map +1 -1
- package/src/api-public/services/filter-protect-data.js.map +1 -1
- package/src/api-public/services/shopping.d.ts +6 -0
- package/src/api-public/services/shopping.js +158 -123
- package/src/api-public/services/shopping.js.map +1 -1
- package/src/api-public/services/shopping.ts +204 -166
- package/src/api-public/services/user.js.map +1 -1
- package/src/controllers/backend-server.js.map +1 -1
- package/src/firebase/message.js +2 -1
- package/src/firebase/message.js.map +1 -1
- package/src/helper/glitter-util.d.ts +1 -0
- package/src/helper/glitter-util.js.map +1 -1
- package/src/modules/caught-error.js.map +1 -1
- package/src/modules/firebase.js.map +1 -1
- package/src/services/app.js +1 -1
- package/src/services/app.ts +1 -1
- package/src/services/backend-service.js +1 -1
- package/src/services/backend-service.js.map +5 -1
- package/src/services/backend-service.ts +1 -1
- package/src/services/ios-release.js.map +1 -1
- package/src/services/release.js.map +1 -1
- package/src/services/saas-table-check.js +2 -2
- package/src/services/saas-table-check.js.map +1 -1
- package/src/services/template.js.map +1 -1
- package/src/api-public/services/product-migrate.js +0 -9
|
@@ -1476,6 +1476,103 @@ export class Shopping {
|
|
|
1476
1476
|
}
|
|
1477
1477
|
}
|
|
1478
1478
|
|
|
1479
|
+
async getShipmentRefer(user_info: any) {
|
|
1480
|
+
user_info = user_info || {};
|
|
1481
|
+
let def = (
|
|
1482
|
+
(
|
|
1483
|
+
await Private_config.getConfig({
|
|
1484
|
+
appName: this.app,
|
|
1485
|
+
key: 'glitter_shipment',
|
|
1486
|
+
})
|
|
1487
|
+
)[0] ?? {
|
|
1488
|
+
value: {
|
|
1489
|
+
volume: [],
|
|
1490
|
+
weight: [],
|
|
1491
|
+
selectCalc: 'volume',
|
|
1492
|
+
},
|
|
1493
|
+
}
|
|
1494
|
+
).value;
|
|
1495
|
+
|
|
1496
|
+
// 參照運費設定
|
|
1497
|
+
const refer =
|
|
1498
|
+
user_info.shipment === 'global_express'
|
|
1499
|
+
? (
|
|
1500
|
+
(
|
|
1501
|
+
await Private_config.getConfig({
|
|
1502
|
+
appName: this.app,
|
|
1503
|
+
key: 'glitter_shipment_global_' + user_info.country,
|
|
1504
|
+
})
|
|
1505
|
+
)[0] ?? {
|
|
1506
|
+
value: {
|
|
1507
|
+
volume: [],
|
|
1508
|
+
weight: [],
|
|
1509
|
+
selectCalc: 'volume',
|
|
1510
|
+
},
|
|
1511
|
+
}
|
|
1512
|
+
).value
|
|
1513
|
+
: (
|
|
1514
|
+
(
|
|
1515
|
+
await Private_config.getConfig({
|
|
1516
|
+
appName: this.app,
|
|
1517
|
+
key: 'glitter_shipment_' + user_info.shipment,
|
|
1518
|
+
})
|
|
1519
|
+
)[0] ?? {
|
|
1520
|
+
value: {
|
|
1521
|
+
volume: [],
|
|
1522
|
+
weight: [],
|
|
1523
|
+
selectCalc: 'def',
|
|
1524
|
+
},
|
|
1525
|
+
}
|
|
1526
|
+
).value;
|
|
1527
|
+
|
|
1528
|
+
if (refer.selectCalc !== 'def') {
|
|
1529
|
+
def = refer;
|
|
1530
|
+
}
|
|
1531
|
+
return def;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
calculateShipment(dataList: { key: string; value: string }[], value: number | string) {
|
|
1535
|
+
if (value === 0) {
|
|
1536
|
+
return 0;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
const productValue = parseFloat(`${value}`);
|
|
1540
|
+
if (isNaN(productValue) || dataList.length === 0) {
|
|
1541
|
+
return 0;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
for (let i = 0; i < dataList.length; i++) {
|
|
1545
|
+
const currentKey = parseFloat(dataList[i].key);
|
|
1546
|
+
const currentValue = parseFloat(dataList[i].value);
|
|
1547
|
+
if (productValue < currentKey) {
|
|
1548
|
+
return i === 0 ? 0 : parseFloat(dataList[i - 1].value);
|
|
1549
|
+
} else if (productValue === currentKey) {
|
|
1550
|
+
return currentValue;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// 如果商品值大於所有的key,返回最後一個value
|
|
1555
|
+
return parseInt(dataList[dataList.length - 1].value);
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
getShipmentFee(user_info: any, lineItems: CartItem[], shipment: any) {
|
|
1559
|
+
if (user_info.shipment === 'now') return 0;
|
|
1560
|
+
|
|
1561
|
+
let total_volume = 0;
|
|
1562
|
+
let total_weight = 0;
|
|
1563
|
+
lineItems.map(item => {
|
|
1564
|
+
if (item.shipment_obj.type === 'volume') {
|
|
1565
|
+
total_volume += item.shipment_obj.value;
|
|
1566
|
+
}
|
|
1567
|
+
if (item.shipment_obj.type === 'weight') {
|
|
1568
|
+
total_weight += item.shipment_obj.value;
|
|
1569
|
+
}
|
|
1570
|
+
});
|
|
1571
|
+
return (
|
|
1572
|
+
this.calculateShipment(shipment.volume, total_volume) + this.calculateShipment(shipment.weight, total_weight)
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1479
1576
|
async toCheckout(
|
|
1480
1577
|
data: {
|
|
1481
1578
|
line_items: CartItem[];
|
|
@@ -1533,7 +1630,7 @@ export class Shopping {
|
|
|
1533
1630
|
timer.count++;
|
|
1534
1631
|
const n = timer.count.toString().padStart(2, '0');
|
|
1535
1632
|
|
|
1536
|
-
console.
|
|
1633
|
+
console.info(`TO-CHECKOUT-TIME-${n} [${name}] `.padEnd(40, '=') + '>', {
|
|
1537
1634
|
totalTime,
|
|
1538
1635
|
spendTime,
|
|
1539
1636
|
});
|
|
@@ -1728,60 +1825,7 @@ export class Shopping {
|
|
|
1728
1825
|
checkPoint('check rebate');
|
|
1729
1826
|
|
|
1730
1827
|
// 運費設定
|
|
1731
|
-
const shipment: ShipmentConfig = await (
|
|
1732
|
-
data.user_info = data.user_info || {};
|
|
1733
|
-
let def = (
|
|
1734
|
-
(
|
|
1735
|
-
await Private_config.getConfig({
|
|
1736
|
-
appName: this.app,
|
|
1737
|
-
key: 'glitter_shipment',
|
|
1738
|
-
})
|
|
1739
|
-
)[0] ?? {
|
|
1740
|
-
value: {
|
|
1741
|
-
volume: [],
|
|
1742
|
-
weight: [],
|
|
1743
|
-
selectCalc: 'volume',
|
|
1744
|
-
},
|
|
1745
|
-
}
|
|
1746
|
-
).value;
|
|
1747
|
-
|
|
1748
|
-
// 參照運費設定
|
|
1749
|
-
const refer =
|
|
1750
|
-
data.user_info.shipment === 'global_express'
|
|
1751
|
-
? (
|
|
1752
|
-
(
|
|
1753
|
-
await Private_config.getConfig({
|
|
1754
|
-
appName: this.app,
|
|
1755
|
-
key: 'glitter_shipment_global_' + data.user_info.country,
|
|
1756
|
-
})
|
|
1757
|
-
)[0] ?? {
|
|
1758
|
-
value: {
|
|
1759
|
-
volume: [],
|
|
1760
|
-
weight: [],
|
|
1761
|
-
selectCalc: 'volume',
|
|
1762
|
-
},
|
|
1763
|
-
}
|
|
1764
|
-
).value
|
|
1765
|
-
: (
|
|
1766
|
-
(
|
|
1767
|
-
await Private_config.getConfig({
|
|
1768
|
-
appName: this.app,
|
|
1769
|
-
key: 'glitter_shipment_' + data.user_info.shipment,
|
|
1770
|
-
})
|
|
1771
|
-
)[0] ?? {
|
|
1772
|
-
value: {
|
|
1773
|
-
volume: [],
|
|
1774
|
-
weight: [],
|
|
1775
|
-
selectCalc: 'def',
|
|
1776
|
-
},
|
|
1777
|
-
}
|
|
1778
|
-
).value;
|
|
1779
|
-
|
|
1780
|
-
if (refer.selectCalc !== 'def') {
|
|
1781
|
-
def = refer;
|
|
1782
|
-
}
|
|
1783
|
-
return def;
|
|
1784
|
-
})();
|
|
1828
|
+
const shipment: ShipmentConfig = await this.getShipmentRefer(data.user_info);
|
|
1785
1829
|
|
|
1786
1830
|
// 物流設定
|
|
1787
1831
|
const shipment_setting: any = await (async () => {
|
|
@@ -1883,30 +1927,6 @@ export class Shopping {
|
|
|
1883
1927
|
carData.user_info.phone = userData.userData.phone;
|
|
1884
1928
|
}
|
|
1885
1929
|
|
|
1886
|
-
function calculateShipment(dataList: { key: string; value: string }[], value: number | string) {
|
|
1887
|
-
if (value === 0) {
|
|
1888
|
-
return 0;
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
const productValue = parseFloat(`${value}`);
|
|
1892
|
-
if (isNaN(productValue) || dataList.length === 0) {
|
|
1893
|
-
return 0;
|
|
1894
|
-
}
|
|
1895
|
-
|
|
1896
|
-
for (let i = 0; i < dataList.length; i++) {
|
|
1897
|
-
const currentKey = parseFloat(dataList[i].key);
|
|
1898
|
-
const currentValue = parseFloat(dataList[i].value);
|
|
1899
|
-
if (productValue < currentKey) {
|
|
1900
|
-
return i === 0 ? 0 : parseFloat(dataList[i - 1].value);
|
|
1901
|
-
} else if (productValue === currentKey) {
|
|
1902
|
-
return currentValue;
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
// 如果商品值大於所有的key,返回最後一個value
|
|
1907
|
-
return parseInt(dataList[dataList.length - 1].value);
|
|
1908
|
-
}
|
|
1909
|
-
|
|
1910
1930
|
const add_on_items: any[] = [];
|
|
1911
1931
|
const gift_product: any[] = [];
|
|
1912
1932
|
const saveStockArray: (() => Promise<boolean>)[] = [];
|
|
@@ -2250,22 +2270,7 @@ export class Shopping {
|
|
|
2250
2270
|
|
|
2251
2271
|
checkPoint('set max product');
|
|
2252
2272
|
|
|
2253
|
-
carData.shipment_fee = (
|
|
2254
|
-
if (data.user_info.shipment === 'now') return 0;
|
|
2255
|
-
|
|
2256
|
-
let total_volume = 0;
|
|
2257
|
-
let total_weight = 0;
|
|
2258
|
-
carData.lineItems.map(item => {
|
|
2259
|
-
if (item.shipment_obj.type === 'volume') {
|
|
2260
|
-
total_volume += item.shipment_obj.value;
|
|
2261
|
-
}
|
|
2262
|
-
if (item.shipment_obj.type === 'weight') {
|
|
2263
|
-
total_weight += item.shipment_obj.value;
|
|
2264
|
-
}
|
|
2265
|
-
});
|
|
2266
|
-
return calculateShipment(shipment.volume, total_volume) + calculateShipment(shipment.weight, total_weight);
|
|
2267
|
-
})();
|
|
2268
|
-
|
|
2273
|
+
carData.shipment_fee = this.getShipmentFee(data.user_info, carData.lineItems, shipment);
|
|
2269
2274
|
carData.total += carData.shipment_fee;
|
|
2270
2275
|
const f_rebate = await this.formatUseRebate(carData.total, carData.use_rebate);
|
|
2271
2276
|
carData.useRebateInfo = f_rebate;
|
|
@@ -2417,7 +2422,7 @@ export class Shopping {
|
|
|
2417
2422
|
(carData as any).payment_info_atm = keyData.payment_info_atm;
|
|
2418
2423
|
const defaultPayArray = onlinePayArray.map(item => item.key);
|
|
2419
2424
|
(keyData as any).cash_on_delivery.shipmentSupport = (keyData as any).cash_on_delivery.shipmentSupport ?? [];
|
|
2420
|
-
|
|
2425
|
+
|
|
2421
2426
|
// 透過特定金流,取得指定物流
|
|
2422
2427
|
carData.shipment_support = checkoutPayment
|
|
2423
2428
|
? ((() => {
|
|
@@ -2437,8 +2442,6 @@ export class Shopping {
|
|
|
2437
2442
|
})().shipmentSupport ?? [])
|
|
2438
2443
|
: [];
|
|
2439
2444
|
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
2445
|
// 防止帶入購物金時,總計小於0
|
|
2443
2446
|
let subtotal = 0;
|
|
2444
2447
|
carData.lineItems.map(item => {
|
|
@@ -2883,18 +2886,18 @@ export class Shopping {
|
|
|
2883
2886
|
)) {
|
|
2884
2887
|
let sns = new SMS(this.app);
|
|
2885
2888
|
await sns.sendCustomerSns('auto-sns-order-create', carData.orderID, phone);
|
|
2886
|
-
console.
|
|
2889
|
+
console.info('訂單簡訊寄送成功');
|
|
2887
2890
|
}
|
|
2888
2891
|
|
|
2889
2892
|
if (carData.customer_info.lineID) {
|
|
2890
2893
|
let line = new LineMessage(this.app);
|
|
2891
2894
|
await line.sendCustomerLine('auto-line-order-create', carData.orderID, carData.customer_info.lineID);
|
|
2892
|
-
console.
|
|
2895
|
+
console.info('訂單line訊息寄送成功');
|
|
2893
2896
|
}
|
|
2894
2897
|
// if (carData.customer_info.fb_id) {
|
|
2895
2898
|
// let fb = new FbMessage(this.app)
|
|
2896
2899
|
// await fb.sendCustomerFB('auto-fb-order-create', carData.orderID, carData.customer_info.fb_id);
|
|
2897
|
-
// console.
|
|
2900
|
+
// console.info('訂單FB訊息寄送成功');
|
|
2898
2901
|
// }
|
|
2899
2902
|
for (const email of new Set(
|
|
2900
2903
|
[carData.customer_info, carData.user_info].map(dd => {
|
|
@@ -3637,28 +3640,15 @@ export class Shopping {
|
|
|
3637
3640
|
try {
|
|
3638
3641
|
const update: any = {};
|
|
3639
3642
|
const storeConfig = await new User(this.app).getConfigV2({ key: 'store_manager', user_id: 'manager' });
|
|
3640
|
-
let origin
|
|
3643
|
+
let origin: any;
|
|
3641
3644
|
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
await db.query(
|
|
3645
|
-
`SELECT *
|
|
3646
|
-
FROM \`${this.app}\`.t_checkout
|
|
3647
|
-
WHERE id = ?;`,
|
|
3648
|
-
[data.id]
|
|
3649
|
-
)
|
|
3650
|
-
)[0];
|
|
3651
|
-
}
|
|
3645
|
+
const whereClause = data.cart_token ? 'cart_token = ?' : data.id ? 'id = ?' : null;
|
|
3646
|
+
const value = data.cart_token ?? data.id;
|
|
3652
3647
|
|
|
3653
|
-
if (
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
FROM \`${this.app}\`.t_checkout
|
|
3658
|
-
WHERE cart_token = ?;`,
|
|
3659
|
-
[data.cart_token]
|
|
3660
|
-
)
|
|
3661
|
-
)[0];
|
|
3648
|
+
if (whereClause && value) {
|
|
3649
|
+
const query = `SELECT * FROM \`${this.app}\`.t_checkout WHERE ${whereClause};`;
|
|
3650
|
+
const result = await db.query(query, [value]);
|
|
3651
|
+
origin = result[0];
|
|
3662
3652
|
}
|
|
3663
3653
|
|
|
3664
3654
|
if (!origin) {
|
|
@@ -3674,19 +3664,20 @@ export class Shopping {
|
|
|
3674
3664
|
|
|
3675
3665
|
// lineItems 庫存修正
|
|
3676
3666
|
const resetLineItems = (lineItems: any[]) => {
|
|
3677
|
-
return lineItems.map(item =>
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3667
|
+
return lineItems.map(item => {
|
|
3668
|
+
return {
|
|
3669
|
+
...item,
|
|
3670
|
+
stockList: undefined,
|
|
3671
|
+
deduction_log: Object.keys(item.deduction_log || {}).length
|
|
3672
|
+
? item.deduction_log
|
|
3673
|
+
: { [storeConfig.list[0].id]: item.count },
|
|
3674
|
+
};
|
|
3675
|
+
});
|
|
3684
3676
|
};
|
|
3685
3677
|
|
|
3686
3678
|
if (data.orderData) {
|
|
3687
3679
|
const orderData = data.orderData;
|
|
3688
3680
|
update.orderData = structuredClone(orderData);
|
|
3689
|
-
const updateProgress = update.orderData.progress;
|
|
3690
3681
|
|
|
3691
3682
|
// 恢復取消訂單的庫存
|
|
3692
3683
|
orderData.lineItems = resetLineItems(orderData.lineItems);
|
|
@@ -3697,7 +3688,7 @@ export class Shopping {
|
|
|
3697
3688
|
|
|
3698
3689
|
// 當訂單變成已取消時,執行庫存回填
|
|
3699
3690
|
const prevStatus = origin.orderData.orderStatus;
|
|
3700
|
-
const prevProgress = origin.orderData.progress;
|
|
3691
|
+
const prevProgress = origin.orderData.progress || 'wait';
|
|
3701
3692
|
|
|
3702
3693
|
//變成已取消加回庫存
|
|
3703
3694
|
if (prevStatus !== '-1' && orderData.orderStatus === '-1') {
|
|
@@ -3730,6 +3721,7 @@ export class Shopping {
|
|
|
3730
3721
|
}
|
|
3731
3722
|
|
|
3732
3723
|
// 當訂單出貨狀態變更,觸發通知事件
|
|
3724
|
+
const updateProgress = update.orderData.progress;
|
|
3733
3725
|
if (prevProgress !== updateProgress) {
|
|
3734
3726
|
if (updateProgress === 'shipping') {
|
|
3735
3727
|
await this.sendNotifications(orderData, 'shipment');
|
|
@@ -3747,6 +3739,7 @@ export class Shopping {
|
|
|
3747
3739
|
}
|
|
3748
3740
|
}
|
|
3749
3741
|
|
|
3742
|
+
update.orderData.lineItems = update.orderData.lineItems.filter((item: any) => item.count > 0);
|
|
3750
3743
|
this.writeRecord(origin, update);
|
|
3751
3744
|
|
|
3752
3745
|
// ======= 更新訂單 =======
|
|
@@ -3758,9 +3751,8 @@ export class Shopping {
|
|
|
3758
3751
|
{}
|
|
3759
3752
|
);
|
|
3760
3753
|
await db.query(
|
|
3761
|
-
`UPDATE \`${this.app}\`.t_checkout
|
|
3762
|
-
|
|
3763
|
-
WHERE id = ?;`,
|
|
3754
|
+
`UPDATE \`${this.app}\`.t_checkout SET ? WHERE id = ?;
|
|
3755
|
+
`,
|
|
3764
3756
|
[updateData, origin.id]
|
|
3765
3757
|
);
|
|
3766
3758
|
|
|
@@ -3908,21 +3900,37 @@ export class Shopping {
|
|
|
3908
3900
|
}
|
|
3909
3901
|
|
|
3910
3902
|
private async resetStore(lineItems: any[], plus_or_minus: 'plus' | 'minus' = 'plus') {
|
|
3911
|
-
const
|
|
3903
|
+
const shoppingClass = new Shopping(this.app, this.token);
|
|
3904
|
+
const calcMap = new Map();
|
|
3905
|
+
|
|
3906
|
+
function updateCalcData(calc: number, stock_id: string, product_id: string, spec: string[]) {
|
|
3907
|
+
const getCalc = calcMap.get(product_id);
|
|
3908
|
+
calcMap.set(product_id, [...(getCalc ?? []), { calc, stock_id, product_id, spec }]);
|
|
3909
|
+
}
|
|
3910
|
+
|
|
3911
|
+
lineItems.map(item => {
|
|
3912
3912
|
if (item.product_category === 'kitchen' && item.spec?.length) {
|
|
3913
|
-
|
|
3913
|
+
updateCalcData(item.count, '', item.id, item.spec);
|
|
3914
|
+
return;
|
|
3914
3915
|
}
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
);
|
|
3916
|
+
|
|
3917
|
+
Object.entries(item.deduction_log).map(([location, count]) => {
|
|
3918
|
+
let intCount = parseInt(`${count || 0}`, 10);
|
|
3919
|
+
if (plus_or_minus === 'minus') {
|
|
3920
|
+
intCount = intCount * -1;
|
|
3921
|
+
}
|
|
3922
|
+
updateCalcData(intCount, location, item.id, item.spec);
|
|
3923
|
+
});
|
|
3924
3924
|
});
|
|
3925
|
-
|
|
3925
|
+
|
|
3926
|
+
return await Promise.all(
|
|
3927
|
+
[...calcMap.values()].map(async dataArray => {
|
|
3928
|
+
for (const data of dataArray) {
|
|
3929
|
+
const { calc, stock_id, product_id, spec } = data;
|
|
3930
|
+
await shoppingClass.calcVariantsStock(calc, stock_id, product_id, spec);
|
|
3931
|
+
}
|
|
3932
|
+
})
|
|
3933
|
+
);
|
|
3926
3934
|
}
|
|
3927
3935
|
|
|
3928
3936
|
/**
|
|
@@ -3966,25 +3974,53 @@ export class Shopping {
|
|
|
3966
3974
|
}
|
|
3967
3975
|
|
|
3968
3976
|
private async adjustStock(origin: any, orderData: any) {
|
|
3969
|
-
|
|
3977
|
+
try {
|
|
3978
|
+
if (orderData.orderStatus === '-1') return;
|
|
3970
3979
|
|
|
3971
|
-
|
|
3972
|
-
const
|
|
3973
|
-
(item: any) => item.id === newItem.id && item.spec.join('') === newItem.spec.join('')
|
|
3974
|
-
);
|
|
3980
|
+
const shoppingClass = new Shopping(this.app, this.token);
|
|
3981
|
+
const calcMap = new Map();
|
|
3975
3982
|
|
|
3976
|
-
|
|
3977
|
-
|
|
3983
|
+
function updateCalcData(calc: number, stock_id: string, product_id: string, spec: string[]) {
|
|
3984
|
+
const getCalc = calcMap.get(product_id);
|
|
3985
|
+
calcMap.set(product_id, [...(getCalc ?? []), { calc, stock_id, product_id, spec }]);
|
|
3978
3986
|
}
|
|
3979
3987
|
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
+
orderData.lineItems.map((newItem: any) => {
|
|
3989
|
+
if (newItem.product_category === 'kitchen' && newItem.spec?.length) {
|
|
3990
|
+
updateCalcData(newItem.count, '', newItem.id, newItem.spec);
|
|
3991
|
+
return;
|
|
3992
|
+
}
|
|
3993
|
+
|
|
3994
|
+
const originalItem = origin.lineItems.find(
|
|
3995
|
+
(item: any) => item.id === newItem.id && item.spec.join('') === newItem.spec.join('')
|
|
3996
|
+
);
|
|
3997
|
+
|
|
3998
|
+
Object.entries(newItem.deduction_log).map(([location, newCount]) => {
|
|
3999
|
+
const parsedNewCount = Number(newCount || 0);
|
|
4000
|
+
const formatNewCount = isNaN(parsedNewCount) ? 0 : parsedNewCount;
|
|
4001
|
+
|
|
4002
|
+
if (!originalItem) {
|
|
4003
|
+
updateCalcData(formatNewCount * -1, location, newItem.id, newItem.spec);
|
|
4004
|
+
return;
|
|
4005
|
+
}
|
|
4006
|
+
|
|
4007
|
+
const originalCount = originalItem.deduction_log[location] || 0;
|
|
4008
|
+
const delta = formatNewCount - originalCount;
|
|
4009
|
+
updateCalcData(delta * -1, location, newItem.id, newItem.spec);
|
|
4010
|
+
});
|
|
4011
|
+
});
|
|
4012
|
+
|
|
4013
|
+
return await Promise.all(
|
|
4014
|
+
[...calcMap.values()].map(async dataArray => {
|
|
4015
|
+
for (const data of dataArray) {
|
|
4016
|
+
const { calc, stock_id, product_id, spec } = data;
|
|
4017
|
+
await shoppingClass.calcVariantsStock(calc, stock_id, product_id, spec);
|
|
4018
|
+
}
|
|
4019
|
+
})
|
|
4020
|
+
);
|
|
4021
|
+
} catch (error) {
|
|
4022
|
+
console.error(`adjustStock has error: ${error}`);
|
|
4023
|
+
}
|
|
3988
4024
|
}
|
|
3989
4025
|
|
|
3990
4026
|
async manualCancelOrder(order_id: string) {
|
|
@@ -4087,13 +4123,13 @@ export class Shopping {
|
|
|
4087
4123
|
)) {
|
|
4088
4124
|
let sns = new SMS(this.app);
|
|
4089
4125
|
await sns.sendCustomerSns('sns-proof-purchase', order_id, phone);
|
|
4090
|
-
console.
|
|
4126
|
+
console.info('訂單待核款簡訊寄送成功');
|
|
4091
4127
|
}
|
|
4092
4128
|
|
|
4093
4129
|
if (orderData.customer_info.lineID) {
|
|
4094
4130
|
let line = new LineMessage(this.app);
|
|
4095
4131
|
await line.sendCustomerLine('line-proof-purchase', order_id, orderData.customer_info.lineID);
|
|
4096
|
-
console.
|
|
4132
|
+
console.info('付款成功line訊息寄送成功');
|
|
4097
4133
|
}
|
|
4098
4134
|
await this.putOrder({
|
|
4099
4135
|
orderData: orderData,
|
|
@@ -4604,7 +4640,7 @@ export class Shopping {
|
|
|
4604
4640
|
)) {
|
|
4605
4641
|
let sns = new SMS(this.app);
|
|
4606
4642
|
await sns.sendCustomerSns('auto-sns-payment-successful', order_id, phone);
|
|
4607
|
-
console.
|
|
4643
|
+
console.info('付款成功簡訊寄送成功');
|
|
4608
4644
|
}
|
|
4609
4645
|
|
|
4610
4646
|
if (cartData.orderData.customer_info.lineID) {
|
|
@@ -4614,7 +4650,7 @@ export class Shopping {
|
|
|
4614
4650
|
order_id,
|
|
4615
4651
|
cartData.orderData.customer_info.lineID
|
|
4616
4652
|
);
|
|
4617
|
-
console.
|
|
4653
|
+
console.info('付款成功line訊息寄送成功');
|
|
4618
4654
|
}
|
|
4619
4655
|
|
|
4620
4656
|
const userData = await new User(this.app).getUserData(cartData.email, 'account');
|
|
@@ -4827,6 +4863,7 @@ export class Shopping {
|
|
|
4827
4863
|
const storeConfig = await _user.getConfigV2({ key: 'store_manager', user_id: 'manager' });
|
|
4828
4864
|
|
|
4829
4865
|
const sourceMap: Record<string, string> = {};
|
|
4866
|
+
|
|
4830
4867
|
const insertPromises = content.variants.map(async (variant: any) => {
|
|
4831
4868
|
content.total_sales += variant.sold_out ?? 0;
|
|
4832
4869
|
content.min_price = Math.min(content.min_price ?? variant.sale_price, variant.sale_price);
|
|
@@ -4844,8 +4881,8 @@ export class Shopping {
|
|
|
4844
4881
|
}
|
|
4845
4882
|
|
|
4846
4883
|
const insertData = await db.query(
|
|
4847
|
-
`INSERT INTO \`${this.app}\`.t_variants
|
|
4848
|
-
|
|
4884
|
+
`INSERT INTO \`${this.app}\`.t_variants SET ?
|
|
4885
|
+
`,
|
|
4849
4886
|
[
|
|
4850
4887
|
{
|
|
4851
4888
|
content: JSON.stringify(variant),
|
|
@@ -4952,6 +4989,7 @@ export class Shopping {
|
|
|
4952
4989
|
is_manger: true,
|
|
4953
4990
|
})
|
|
4954
4991
|
).data.content;
|
|
4992
|
+
|
|
4955
4993
|
const variant_s: any = pd_data.variants.find((dd: any) => {
|
|
4956
4994
|
return dd.spec.join('-') === spec.join('-');
|
|
4957
4995
|
});
|