@pisell/pisellos 2.2.192 → 2.2.194

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.
Files changed (41) hide show
  1. package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
  2. package/dist/modules/Order/index.d.ts +12 -9
  3. package/dist/modules/Order/index.js +503 -580
  4. package/dist/modules/Order/types.d.ts +5 -5
  5. package/dist/modules/Order/utils/manualProductDiscount.js +1 -1
  6. package/dist/modules/Order/utils.js +3 -3
  7. package/dist/modules/Payment/utils.js +2 -1
  8. package/dist/modules/SalesSummary/index.d.ts +0 -25
  9. package/dist/modules/SalesSummary/types.d.ts +1 -0
  10. package/dist/modules/SalesSummary/utils.d.ts +2 -25
  11. package/dist/modules/SalesSummary/utils.js +529 -160
  12. package/dist/server/index.d.ts +8 -1
  13. package/dist/server/index.js +653 -466
  14. package/dist/server/modules/order/index.d.ts +3 -2
  15. package/dist/server/modules/order/index.js +68 -52
  16. package/dist/server/modules/products/index.js +4 -4
  17. package/dist/solution/BaseSales/index.d.ts +2 -1
  18. package/dist/solution/BaseSales/index.js +116 -122
  19. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  20. package/dist/solution/ScanOrder/index.js +3 -1
  21. package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
  22. package/lib/modules/Order/index.d.ts +12 -9
  23. package/lib/modules/Order/index.js +124 -120
  24. package/lib/modules/Order/types.d.ts +5 -5
  25. package/lib/modules/Order/utils/manualProductDiscount.js +1 -1
  26. package/lib/modules/Order/utils.js +4 -4
  27. package/lib/modules/Payment/utils.js +2 -1
  28. package/lib/modules/SalesSummary/index.d.ts +0 -25
  29. package/lib/modules/SalesSummary/types.d.ts +1 -0
  30. package/lib/modules/SalesSummary/utils.d.ts +2 -25
  31. package/lib/modules/SalesSummary/utils.js +420 -92
  32. package/lib/server/index.d.ts +8 -1
  33. package/lib/server/index.js +145 -26
  34. package/lib/server/modules/order/index.d.ts +3 -2
  35. package/lib/server/modules/order/index.js +25 -15
  36. package/lib/server/modules/products/index.js +0 -4
  37. package/lib/solution/BaseSales/index.d.ts +2 -1
  38. package/lib/solution/BaseSales/index.js +53 -16
  39. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -1
  40. package/lib/solution/ScanOrder/index.js +3 -1
  41. package/package.json +1 -1
@@ -69,9 +69,9 @@ export declare class OrderModule extends BaseModule implements Module {
69
69
  preload(): Promise<void>;
70
70
  getOrders(): OrderData[];
71
71
  getOrderById(id: OrderId): OrderData | undefined;
72
- /** 按 order_id 查询(推荐) */
72
+ /** 按 order_id 查询内存订单。 */
73
73
  getOrderByOrderId(orderId: OrderId): OrderData | undefined;
74
- getLocalOrderByOrderId(orderId: OrderId): Promise<OrderData | null>;
74
+ getLocalOrderByLookup(lookup: OrderId): Promise<OrderData | null>;
75
75
  loadOrdersByServer(): Promise<OrderData[]>;
76
76
  /**
77
77
  * 静默全量刷新:后台重新拉取全量 SSE 订单数据并更新本地
@@ -152,6 +152,7 @@ export declare class OrderModule extends BaseModule implements Module {
152
152
  private normalizeOrderSyncPayload;
153
153
  private uniqueOrderIds;
154
154
  private getIdKey;
155
+ private isOrderLookupMatch;
155
156
  /**
156
157
  * 解析订单 SQLite 主键,规则与宿主 OrderDataSource.getOrderStorageKey 一致。
157
158
  *
@@ -491,59 +491,64 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
491
491
  return this.store.map.get(this.getIdKey(id));
492
492
  }
493
493
 
494
- /** 按 order_id 查询(推荐) */
494
+ /** 按 order_id 查询内存订单。 */
495
495
  }, {
496
496
  key: "getOrderByOrderId",
497
497
  value: function getOrderByOrderId(orderId) {
498
498
  return this.store.map.get(this.getIdKey(orderId));
499
499
  }
500
500
  }, {
501
- key: "getLocalOrderByOrderId",
501
+ key: "getLocalOrderByLookup",
502
502
  value: function () {
503
- var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(orderId) {
503
+ var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(lookup) {
504
504
  var _this3 = this;
505
- var key, memoryOrder, orders, localOrder;
505
+ var key, memoryOrderById, memoryOrder, orders, localOrder;
506
506
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
507
507
  while (1) switch (_context4.prev = _context4.next) {
508
508
  case 0:
509
- key = this.getIdKey(orderId);
510
- memoryOrder = this.store.map.get(key);
511
- if (!memoryOrder) {
509
+ key = this.getIdKey(lookup);
510
+ memoryOrderById = this.store.map.get(key);
511
+ if (!memoryOrderById) {
512
512
  _context4.next = 4;
513
513
  break;
514
514
  }
515
- return _context4.abrupt("return", memoryOrder);
515
+ return _context4.abrupt("return", memoryOrderById);
516
516
  case 4:
517
- _context4.next = 6;
517
+ memoryOrder = this.store.list.find(function (order) {
518
+ return _this3.isOrderLookupMatch(order, key);
519
+ });
520
+ if (!memoryOrder) {
521
+ _context4.next = 7;
522
+ break;
523
+ }
524
+ return _context4.abrupt("return", memoryOrder);
525
+ case 7:
526
+ _context4.next = 9;
518
527
  return this.loadOrdersFromSQLite();
519
- case 6:
528
+ case 9:
520
529
  orders = _context4.sent;
521
530
  localOrder = orders.find(function (order) {
522
- var shopOrderNumber = order === null || order === void 0 ? void 0 : order.shop_order_number;
523
- if (shopOrderNumber && _this3.getIdKey(shopOrderNumber) === key) return true;
524
- var id = order === null || order === void 0 ? void 0 : order.order_id;
525
- if (id === undefined || id === null) return false;
526
- return _this3.getIdKey(id) === key;
531
+ return _this3.isOrderLookupMatch(order, key);
527
532
  });
528
533
  if (localOrder) {
529
- _context4.next = 10;
534
+ _context4.next = 13;
530
535
  break;
531
536
  }
532
537
  return _context4.abrupt("return", null);
533
- case 10:
538
+ case 13:
534
539
  this.store.list = orders;
535
540
  this.syncOrdersMap();
536
541
  return _context4.abrupt("return", localOrder);
537
- case 13:
542
+ case 16:
538
543
  case "end":
539
544
  return _context4.stop();
540
545
  }
541
546
  }, _callee4, this);
542
547
  }));
543
- function getLocalOrderByOrderId(_x3) {
544
- return _getLocalOrderByOrderId.apply(this, arguments);
548
+ function getLocalOrderByLookup(_x3) {
549
+ return _getLocalOrderByLookup.apply(this, arguments);
545
550
  }
546
- return getLocalOrderByOrderId;
551
+ return getLocalOrderByLookup;
547
552
  }()
548
553
  }, {
549
554
  key: "loadOrdersByServer",
@@ -1390,6 +1395,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1390
1395
  value: function getIdKey(id) {
1391
1396
  return String(id);
1392
1397
  }
1398
+ }, {
1399
+ key: "isOrderLookupMatch",
1400
+ value: function isOrderLookupMatch(order, lookupKey) {
1401
+ var _this11 = this;
1402
+ if (!order || !lookupKey) return false;
1403
+ var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
1404
+ return candidates.some(function (value) {
1405
+ if (value === undefined || value === null || value === '') return false;
1406
+ return _this11.getIdKey(value) === lookupKey;
1407
+ });
1408
+ }
1393
1409
 
1394
1410
  /**
1395
1411
  * 解析订单 SQLite 主键,规则与宿主 OrderDataSource.getOrderStorageKey 一致。
@@ -1569,7 +1585,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1569
1585
  key: "patchOrdersInSQLite",
1570
1586
  value: (function () {
1571
1587
  var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orders, source) {
1572
- var _this11 = this;
1588
+ var _this12 = this;
1573
1589
  var mergeActions,
1574
1590
  ordersSnapshot,
1575
1591
  _this$filterRedundant2,
@@ -1587,7 +1603,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1587
1603
  return _context17.abrupt("return");
1588
1604
  case 3:
1589
1605
  ordersSnapshot = cloneDeep(orders).filter(function (order) {
1590
- return _this11.getOrderStorageKey(order);
1606
+ return _this12.getOrderStorageKey(order);
1591
1607
  });
1592
1608
  if (!(ordersSnapshot.length === 0)) {
1593
1609
  _context17.next = 6;
@@ -1610,34 +1626,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1610
1626
  while (1) switch (_context16.prev = _context16.next) {
1611
1627
  case 0:
1612
1628
  writeMethod = 'none';
1613
- _this11.logInfo('patchOrdersInSQLite-开始', {
1629
+ _this12.logInfo('patchOrdersInSQLite-开始', {
1614
1630
  source: source,
1615
1631
  count: toWrite.length,
1616
1632
  dedupedCount: skipped.length
1617
1633
  });
1618
- if (!(typeof _this11.dbManager.bulkUpdate === 'function')) {
1634
+ if (!(typeof _this12.dbManager.bulkUpdate === 'function')) {
1619
1635
  _context16.next = 8;
1620
1636
  break;
1621
1637
  }
1622
1638
  writeMethod = 'bulkUpdate';
1623
1639
  _context16.next = 6;
1624
- return _this11.dbManager.bulkUpdate(INDEXDB_STORE_NAME, toWrite);
1640
+ return _this12.dbManager.bulkUpdate(INDEXDB_STORE_NAME, toWrite);
1625
1641
  case 6:
1626
1642
  _context16.next = 33;
1627
1643
  break;
1628
1644
  case 8:
1629
- if (!(typeof _this11.dbManager.bulkAdd === 'function')) {
1645
+ if (!(typeof _this12.dbManager.bulkAdd === 'function')) {
1630
1646
  _context16.next = 14;
1631
1647
  break;
1632
1648
  }
1633
1649
  writeMethod = 'bulkAdd';
1634
1650
  _context16.next = 12;
1635
- return _this11.dbManager.bulkAdd(INDEXDB_STORE_NAME, toWrite);
1651
+ return _this12.dbManager.bulkAdd(INDEXDB_STORE_NAME, toWrite);
1636
1652
  case 12:
1637
1653
  _context16.next = 33;
1638
1654
  break;
1639
1655
  case 14:
1640
- if (!(typeof _this11.dbManager.update === 'function')) {
1656
+ if (!(typeof _this12.dbManager.update === 'function')) {
1641
1657
  _context16.next = 33;
1642
1658
  break;
1643
1659
  }
@@ -1652,7 +1668,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1652
1668
  }
1653
1669
  order = _step9.value;
1654
1670
  _context16.next = 23;
1655
- return _this11.dbManager.update(INDEXDB_STORE_NAME, order);
1671
+ return _this12.dbManager.update(INDEXDB_STORE_NAME, order);
1656
1672
  case 23:
1657
1673
  _context16.next = 19;
1658
1674
  break;
@@ -1668,8 +1684,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1668
1684
  _iterator9.f();
1669
1685
  return _context16.finish(30);
1670
1686
  case 33:
1671
- _this11.recordRecentSqliteWrite(source, toWrite);
1672
- _this11.logInfo('patchOrdersInSQLite-完成', {
1687
+ _this12.recordRecentSqliteWrite(source, toWrite);
1688
+ _this12.logInfo('patchOrdersInSQLite-完成', {
1673
1689
  source: source,
1674
1690
  count: toWrite.length,
1675
1691
  writeMethod: writeMethod,
@@ -1713,7 +1729,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1713
1729
  key: "updateOrderInSQLite",
1714
1730
  value: (function () {
1715
1731
  var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(order, source) {
1716
- var _this12 = this;
1732
+ var _this13 = this;
1717
1733
  var orderSnapshot, _orderSnapshot$order_3;
1718
1734
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1719
1735
  while (1) switch (_context19.prev = _context19.next) {
@@ -1734,43 +1750,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1734
1750
  while (1) switch (_context18.prev = _context18.next) {
1735
1751
  case 0:
1736
1752
  writeMethod = 'none';
1737
- _this12.logInfo('updateOrderInSQLite-开始', {
1753
+ _this13.logInfo('updateOrderInSQLite-开始', {
1738
1754
  source: source,
1739
1755
  orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
1740
- storageKey: _this12.getOrderStorageKey(orderSnapshot)
1756
+ storageKey: _this13.getOrderStorageKey(orderSnapshot)
1741
1757
  });
1742
- if (!(typeof _this12.dbManager.update === 'function')) {
1758
+ if (!(typeof _this13.dbManager.update === 'function')) {
1743
1759
  _context18.next = 8;
1744
1760
  break;
1745
1761
  }
1746
1762
  writeMethod = 'update';
1747
1763
  _context18.next = 6;
1748
- return _this12.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
1764
+ return _this13.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
1749
1765
  case 6:
1750
1766
  _context18.next = 18;
1751
1767
  break;
1752
1768
  case 8:
1753
- if (!(typeof _this12.dbManager.bulkUpdate === 'function')) {
1769
+ if (!(typeof _this13.dbManager.bulkUpdate === 'function')) {
1754
1770
  _context18.next = 14;
1755
1771
  break;
1756
1772
  }
1757
1773
  writeMethod = 'bulkUpdate';
1758
1774
  _context18.next = 12;
1759
- return _this12.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
1775
+ return _this13.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
1760
1776
  case 12:
1761
1777
  _context18.next = 18;
1762
1778
  break;
1763
1779
  case 14:
1764
- if (!(typeof _this12.dbManager.bulkAdd === 'function')) {
1780
+ if (!(typeof _this13.dbManager.bulkAdd === 'function')) {
1765
1781
  _context18.next = 18;
1766
1782
  break;
1767
1783
  }
1768
1784
  writeMethod = 'bulkAdd';
1769
1785
  _context18.next = 18;
1770
- return _this12.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
1786
+ return _this13.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
1771
1787
  case 18:
1772
- _this12.recordRecentSqliteWrite(source, [orderSnapshot]);
1773
- _this12.logInfo('updateOrderInSQLite-完成', {
1788
+ _this13.recordRecentSqliteWrite(source, [orderSnapshot]);
1789
+ _this13.logInfo('updateOrderInSQLite-完成', {
1774
1790
  source: source,
1775
1791
  orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
1776
1792
  writeMethod: writeMethod
@@ -1813,7 +1829,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1813
1829
  key: "replaceOrdersSnapshotInSQLite",
1814
1830
  value: (function () {
1815
1831
  var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(orderList, source) {
1816
- var _this13 = this;
1832
+ var _this14 = this;
1817
1833
  var orderListSnapshot;
1818
1834
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1819
1835
  while (1) switch (_context21.prev = _context21.next) {
@@ -1831,14 +1847,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1831
1847
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1832
1848
  while (1) switch (_context20.prev = _context20.next) {
1833
1849
  case 0:
1834
- _this13.logInfo('replaceOrdersSnapshotInSQLite-开始', {
1850
+ _this14.logInfo('replaceOrdersSnapshotInSQLite-开始', {
1835
1851
  source: source,
1836
1852
  count: orderListSnapshot.length
1837
1853
  });
1838
1854
  _context20.next = 3;
1839
- return _this13.dbManager.clear(INDEXDB_STORE_NAME);
1855
+ return _this14.dbManager.clear(INDEXDB_STORE_NAME);
1840
1856
  case 3:
1841
- _this13.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
1857
+ _this14.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
1842
1858
  count: orderListSnapshot.length
1843
1859
  });
1844
1860
  if (!(orderListSnapshot.length === 0)) {
@@ -1848,10 +1864,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1848
1864
  return _context20.abrupt("return");
1849
1865
  case 6:
1850
1866
  _context20.next = 8;
1851
- return _this13.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderListSnapshot);
1867
+ return _this14.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderListSnapshot);
1852
1868
  case 8:
1853
- _this13.recordRecentSqliteWrite(source, orderListSnapshot);
1854
- _this13.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
1869
+ _this14.recordRecentSqliteWrite(source, orderListSnapshot);
1870
+ _this14.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
1855
1871
  source: source,
1856
1872
  count: orderListSnapshot.length
1857
1873
  });
@@ -1893,7 +1909,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1893
1909
  key: "clear",
1894
1910
  value: (function () {
1895
1911
  var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1896
- var _this14 = this;
1912
+ var _this15 = this;
1897
1913
  return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1898
1914
  while (1) switch (_context23.prev = _context23.next) {
1899
1915
  case 0:
@@ -1910,7 +1926,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1910
1926
  while (1) switch (_context22.prev = _context22.next) {
1911
1927
  case 0:
1912
1928
  _context22.next = 2;
1913
- return _this14.dbManager.clear(INDEXDB_STORE_NAME);
1929
+ return _this15.dbManager.clear(INDEXDB_STORE_NAME);
1914
1930
  case 2:
1915
1931
  case "end":
1916
1932
  return _context22.stop();
@@ -2048,10 +2048,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2048
2048
  this.productDataSource.run({
2049
2049
  pubsub: {
2050
2050
  callback: function callback(res) {
2051
- console.log('sse_products_callback', res);
2052
- _this8.logInfo('sse_products_callback: 收到同步消息', {
2053
- data: res === null || res === void 0 ? void 0 : res.data
2054
- });
2051
+ // console.log('sse_products_callback', res)
2052
+ // this.logInfo('sse_products_callback: 收到同步消息', {
2053
+ // data: res?.data,
2054
+ // });
2055
2055
  if (!(res !== null && res !== void 0 && res.data)) return;
2056
2056
  var data = res.data;
2057
2057
  var channelKey = data.module || 'product';
@@ -89,7 +89,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
89
89
  destroy(): Promise<void>;
90
90
  /**
91
91
  * 加载销售订单到统一 tempOrder 工作区。
92
- * app.sqlite 时优先读取本地记录;本地未命中或 forceRemote=true 时再拉云端。
92
+ * 统一通过 OrderModule sales detail lookup 加载订单详情。
93
93
  *
94
94
  * 子类可在 `super.loadSalesDetail` 之后基于返回的 `sales` 做业务侧装配
95
95
  * (比如把 `sales.customer` 写入 CustomerModule、emit 业务 hook 等)。
@@ -140,6 +140,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
140
140
  private getHistoricalProductDiscountList;
141
141
  private isPersistedOrderProduct;
142
142
  private mergeHistoricalDiscountList;
143
+ private shouldSkipAutoApplyFetchedDiscountsInEditMode;
143
144
  private mergeCurrentDiscountSelectionState;
144
145
  loadDiscountConfig(params?: {
145
146
  customerId?: number;