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.
Files changed (41) hide show
  1. package/lowcode/Entry.js +1 -1
  2. package/lowcode/Entry.ts +1 -1
  3. package/lowcode/backend-manager/bg-product.js +21 -15
  4. package/lowcode/backend-manager/bg-product.ts +32 -22
  5. package/lowcode/backend-manager/bg-widget.ts +1 -1
  6. package/lowcode/cms-plugin/model/order.d.ts +1 -0
  7. package/lowcode/cms-plugin/module/order-setting.js +118 -22
  8. package/lowcode/cms-plugin/module/order-setting.ts +133 -22
  9. package/lowcode/cms-plugin/order/order-module.js +366 -0
  10. package/lowcode/cms-plugin/order/order-module.ts +404 -0
  11. package/lowcode/cms-plugin/shopping-order-manager.js +21 -9
  12. package/lowcode/cms-plugin/shopping-order-manager.ts +21 -9
  13. package/lowcode/css/editor.css +14 -0
  14. package/package.json +1 -1
  15. package/src/api-public/controllers/ai-points.js.map +1 -1
  16. package/src/api-public/controllers/index.js.map +1 -1
  17. package/src/api-public/controllers/track.js.map +1 -1
  18. package/src/api-public/services/filter-protect-data.js.map +1 -1
  19. package/src/api-public/services/shopping.d.ts +6 -0
  20. package/src/api-public/services/shopping.js +158 -123
  21. package/src/api-public/services/shopping.js.map +1 -1
  22. package/src/api-public/services/shopping.ts +204 -166
  23. package/src/api-public/services/user.js.map +1 -1
  24. package/src/controllers/backend-server.js.map +1 -1
  25. package/src/firebase/message.js +2 -1
  26. package/src/firebase/message.js.map +1 -1
  27. package/src/helper/glitter-util.d.ts +1 -0
  28. package/src/helper/glitter-util.js.map +1 -1
  29. package/src/modules/caught-error.js.map +1 -1
  30. package/src/modules/firebase.js.map +1 -1
  31. package/src/services/app.js +1 -1
  32. package/src/services/app.ts +1 -1
  33. package/src/services/backend-service.js +1 -1
  34. package/src/services/backend-service.js.map +5 -1
  35. package/src/services/backend-service.ts +1 -1
  36. package/src/services/ios-release.js.map +1 -1
  37. package/src/services/release.js.map +1 -1
  38. package/src/services/saas-table-check.js +2 -2
  39. package/src/services/saas-table-check.js.map +1 -1
  40. package/src/services/template.js.map +1 -1
  41. package/src/api-public/services/product-migrate.js +0 -9
@@ -9,10 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { ShareDialog } from '../../glitterBundle/dialog/ShareDialog.js';
11
11
  import { BgWidget } from '../../backend-manager/bg-widget.js';
12
+ import { BgProduct } from '../../backend-manager/bg-product.js';
12
13
  import { ApiDelivery } from '../../glitter-base/route/delivery.js';
14
+ import { ApiShop } from '../../glitter-base/route/shopping.js';
13
15
  import { PaymentConfig } from '../../glitter-base/global/payment-config.js';
14
16
  import { ShipmentConfig } from '../../glitter-base/global/shipment-config.js';
15
17
  import { PaymentPage } from '../pos-pages/payment-page.js';
18
+ import { PosFunction } from '../pos-pages/pos-function.js';
16
19
  const html = String.raw;
17
20
  export class OrderModule {
18
21
  static getPaymentMethodText(gvc, orderData) {
@@ -301,4 +304,367 @@ export class OrderModule {
301
304
  value: 0,
302
305
  };
303
306
  }
307
+ static editOrderLineItems(gvc, orderData, callback) {
308
+ const id = gvc.glitter.getUUID();
309
+ const dialog = new ShareDialog(gvc.glitter);
310
+ const cloneData = structuredClone(orderData);
311
+ function getNewItem(id, product, variant) {
312
+ return {
313
+ id: id,
314
+ sku: variant.sku,
315
+ spec: variant.spec,
316
+ count: 1,
317
+ stock: variant.stockList
318
+ ? Number(Object.values(variant.stockList).reduce((sum, val) => sum + val.count, 0))
319
+ : 0,
320
+ times: 0,
321
+ title: product.content.title,
322
+ rebate: 0,
323
+ weight: Number(variant.weight),
324
+ is_gift: false,
325
+ is_hidden: false,
326
+ stockList: variant.stockList,
327
+ sale_price: variant.sale_price,
328
+ origin_price: variant.origin_price,
329
+ preview_image: variant.preview_image,
330
+ discount_price: 0,
331
+ is_add_on_items: false,
332
+ show_understocking: variant.show_understocking,
333
+ deduction_log: (() => {
334
+ const obj = {};
335
+ const stockKey = Object.keys(variant.stockList).find(key => { var _a; return ((_a = variant.stockList[key]) === null || _a === void 0 ? void 0 : _a.count) > 0; });
336
+ if (stockKey) {
337
+ obj[stockKey] = 1;
338
+ }
339
+ return obj;
340
+ })(),
341
+ };
342
+ }
343
+ function showTag(color, text) {
344
+ return html ` <div class="product-show-tag" style="background: ${color};">${text}</div> `;
345
+ }
346
+ function getLineItemSubtotal(lineItems) {
347
+ return lineItems
348
+ .map(dd => Number(dd.count) * Number(dd.sale_price))
349
+ .reduce((accumulator, currentValue) => accumulator + currentValue, 0);
350
+ }
351
+ return BgWidget.settingDialog({
352
+ gvc,
353
+ title: '編輯訂單明細',
354
+ width: 800,
355
+ height: 600,
356
+ innerHTML: gvc => {
357
+ return gvc.bindView({
358
+ bind: id,
359
+ view: () => {
360
+ var _a;
361
+ const subtotal = getLineItemSubtotal(orderData.orderData.lineItems);
362
+ return html `<div class="d-flex flex-column">
363
+ ${orderData.orderData.lineItems
364
+ .filter((dd) => dd.count > 0)
365
+ .map((dd) => {
366
+ function countInput() {
367
+ return BgWidget.editeInput({
368
+ gvc,
369
+ title: '',
370
+ default: `${dd.count}`,
371
+ placeHolder: '',
372
+ callback: (value) => {
373
+ const n = Number(value);
374
+ if (isNaN(n) || n < 0) {
375
+ dialog.errorMessage({ text: '請填寫大於 0 的數值' });
376
+ return;
377
+ }
378
+ const storeKeys = Object.keys(dd.deduction_log || {});
379
+ if (storeKeys.length > 0) {
380
+ let selectStore = '';
381
+ for (const key of storeKeys) {
382
+ if (dd.deduction_log[key] === 0) {
383
+ delete dd.deduction_log[key];
384
+ }
385
+ else if (!selectStore && dd.deduction_log[key] > 0) {
386
+ selectStore = key;
387
+ }
388
+ }
389
+ if (selectStore) {
390
+ dd.deduction_log[selectStore] = n;
391
+ }
392
+ }
393
+ dd.count = n;
394
+ gvc.notifyDataChange(id);
395
+ },
396
+ style: 'width: 64px;',
397
+ });
398
+ }
399
+ return html `<div class="d-flex align-items-center gap-1">
400
+ <div
401
+ class="d-flex flex-column align-items-center justify-content-center"
402
+ style="gap: 5px; margin-right: 12px;"
403
+ >
404
+ ${BgWidget.validImageBox({
405
+ gvc,
406
+ image: dd.preview_image,
407
+ width: 60,
408
+ class: 'border rounded',
409
+ style: '',
410
+ })}
411
+ </div>
412
+ <div class="d-flex flex-column">
413
+ ${dd.is_hidden
414
+ ? html `<div style="width:auto;">${BgWidget.secondaryInsignia('隱形商品')}</div>`
415
+ : ''}
416
+ <div class="tx_700 d-flex align-items-center" style="gap:4px;">
417
+ <div>${dd.title}</div>
418
+ ${dd.is_gift ? html `<div>${showTag('#FFE9B2', '贈品')}</div>` : ''}
419
+ ${dd.is_add_on_items ? html `<div>${showTag('#D8E7EC', '加購品')}</div>` : ''}
420
+ ${dd.pre_order ? html `<div>${showTag('#D8E7EC', '預購')}</div>` : ''}
421
+ </div>
422
+ ${dd.spec.length > 0 ? BgWidget.grayNote(dd.spec.join(', ')) : ''}
423
+ ${BgWidget.grayNote(`存貨單位 (SKU):${dd.sku && dd.sku.length > 0 ? dd.sku : '無'}`)}
424
+ </div>
425
+ <div class="flex-fill"></div>
426
+ <div class="tx_normal_16 d-none d-lg-flex justify-content-end" style="min-width: 80px;">
427
+ <div class="d-flex align-items-center gap-2">
428
+ $${dd.sale_price.toLocaleString()} × ${countInput()}
429
+ </div>
430
+ </div>
431
+ <div
432
+ class="tx_normal d-sm-none d-flex flex-column"
433
+ style="display: flex;justify-content: end;${document.body.clientWidth > 800
434
+ ? 'width: 110px'
435
+ : 'width: 140px'}"
436
+ >
437
+ <div>$${dd.sale_price.toLocaleString()} × ${countInput()}</div>
438
+ </div>
439
+ <div
440
+ class="tx_normal d-none d-sm-flex"
441
+ style="display: flex;justify-content: end;${document.body.clientWidth > 800
442
+ ? 'width: 110px'
443
+ : ''}"
444
+ >
445
+ $${(dd.sale_price * dd.count).toLocaleString()}
446
+ </div>
447
+ <div
448
+ class="hoverBtn d-flex align-items-center justify-content-center fs-6"
449
+ style="width: 24px; height: 24px;"
450
+ onclick="${gvc.event(() => {
451
+ const findData = orderData.orderData.lineItems.find(item => {
452
+ return item.id === dd.id && item.spec.join('') === dd.spec.join('');
453
+ });
454
+ if (findData) {
455
+ findData.count = 0;
456
+ Object.keys(findData.deduction_log).map(key => {
457
+ findData.deduction_log[key] = 0;
458
+ });
459
+ }
460
+ gvc.notifyDataChange(id);
461
+ })}"
462
+ >
463
+ <i class="fa-sharp fa-regular fa-trash"></i>
464
+ </div>
465
+ </div>`;
466
+ })
467
+ .join(html ` <div style="margin-top: 12px;"></div>`)}
468
+ <div class="d-flex align-items-center justify-content-center">
469
+ <div style="width: 50px;">
470
+ ${BgWidget.plusButton({
471
+ title: '新增商品',
472
+ event: gvc.event(() => {
473
+ return BgProduct.productsDialog({
474
+ gvc,
475
+ title: '新增商品',
476
+ default: [],
477
+ with_variants: true,
478
+ callback: (dataArray) => __awaiter(this, void 0, void 0, function* () {
479
+ const specArray = [];
480
+ const idSet = new Set(dataArray.map((data) => {
481
+ const id = data.split('-')[0];
482
+ const spec = data.substring(data.indexOf('-') + 1);
483
+ specArray.push({ id, spec });
484
+ return id;
485
+ }));
486
+ dialog.dataLoading({ visible: true });
487
+ yield ApiShop.getProduct({
488
+ page: 0,
489
+ limit: 99999,
490
+ id_list: [...idSet].join(','),
491
+ status: 'inRange',
492
+ }).then(r => {
493
+ setTimeout(() => dialog.dataLoading({ visible: false }), 100);
494
+ if (r.result && r.response.total > 0) {
495
+ const productMap = new Map(r.response.data.map((product) => [`${product.id}`, product]));
496
+ specArray.forEach(specData => {
497
+ const product = productMap.get(`${specData.id}`);
498
+ if (!product) {
499
+ return;
500
+ }
501
+ const variant = product.content.variants.find((variant) => variant.spec.join('-') === specData.spec);
502
+ if (!variant) {
503
+ return;
504
+ }
505
+ const lineItemData = orderData.orderData.lineItems.find(item => {
506
+ return (item.id === Number(specData.id) && item.spec.join('') === variant.spec.join(''));
507
+ });
508
+ if (lineItemData) {
509
+ lineItemData.count++;
510
+ if (Object.keys(lineItemData.deduction_log || {}).length > 0) {
511
+ const key = Object.keys(lineItemData.deduction_log)[0];
512
+ lineItemData.deduction_log[key]++;
513
+ }
514
+ }
515
+ else {
516
+ const itemObject = getNewItem(Number(specData.id), product, variant);
517
+ orderData.orderData.lineItems.push(itemObject);
518
+ }
519
+ });
520
+ }
521
+ gvc.notifyDataChange(id);
522
+ });
523
+ }),
524
+ });
525
+ }),
526
+ })}
527
+ </div>
528
+ </div>
529
+ ${BgWidget.horizontalLine()}
530
+ ${[
531
+ {
532
+ title: '小計',
533
+ description: `${orderData.orderData.lineItems
534
+ .map(dd => Number(dd.count))
535
+ .reduce((accumulator, currentValue) => accumulator + currentValue, 0)} 件商品`,
536
+ total: `$${subtotal.toLocaleString()}`,
537
+ },
538
+ {
539
+ title: '運費',
540
+ description: '',
541
+ total: `$${orderData.orderData.shipment_fee.toLocaleString()}`,
542
+ },
543
+ ...(orderData.orderData.use_rebate
544
+ ? [
545
+ {
546
+ title: '回饋金',
547
+ description: '',
548
+ total: `- $${orderData.orderData.use_rebate.toLocaleString()}`,
549
+ },
550
+ ]
551
+ : []),
552
+ ...(orderData.orderData.use_wallet && `${orderData.orderData.use_wallet}` !== '0'
553
+ ? [
554
+ {
555
+ title: '錢包',
556
+ description: `使用錢包扣款`,
557
+ total: `- $${orderData.orderData.use_wallet.toLocaleString()}`,
558
+ },
559
+ ]
560
+ : []),
561
+ ...orderData.orderData.voucherList.map((dd) => {
562
+ var _a;
563
+ const descHTML = html ` <div
564
+ style="color: #8D8D8D; font-size: 14px; white-space: nowrap; text-overflow: ellipsis;"
565
+ >
566
+ ${dd.title}
567
+ </div>`;
568
+ const rebackMaps = {
569
+ add_on_items: {
570
+ title: '加購優惠',
571
+ description: descHTML,
572
+ total: '-',
573
+ },
574
+ giveaway: {
575
+ title: '滿額贈送',
576
+ description: descHTML,
577
+ total: '-',
578
+ },
579
+ rebate: {
580
+ title: '回饋購物金',
581
+ description: descHTML,
582
+ total: `${dd.rebate_total} 點`,
583
+ },
584
+ default: {
585
+ title: dd.id == 0 ? '手動調整' : '折扣',
586
+ description: descHTML,
587
+ total: (() => {
588
+ const status = dd.discount_total > 0;
589
+ const isMinus = status ? '-' : '';
590
+ const isNegative = status ? 1 : -1;
591
+ return `${isMinus} $${(dd.discount_total * isNegative).toLocaleString()}`;
592
+ })(),
593
+ },
594
+ };
595
+ return (_a = rebackMaps[dd.reBackType]) !== null && _a !== void 0 ? _a : rebackMaps.default;
596
+ }),
597
+ {
598
+ title: html `<span class="tx_700">總金額</span>`,
599
+ description: '',
600
+ total: html `<span class="tx_700"
601
+ >$${(subtotal -
602
+ orderData.orderData.discount +
603
+ orderData.orderData.shipment_fee -
604
+ orderData.orderData.use_rebate).toLocaleString()}</span
605
+ >`,
606
+ },
607
+ ]
608
+ .map(dd => {
609
+ var _a;
610
+ return html ` <div class="d-flex align-items-center justify-content-end">
611
+ <div class="tx_normal_16" style="text-align: end;">${dd.title} ${(_a = dd.description) !== null && _a !== void 0 ? _a : ''}</div>
612
+ <div class="tx_normal" style="width: 114px;display: flex;justify-content: end;">${dd.total}</div>
613
+ </div>`;
614
+ })
615
+ .join(BgWidget.mbContainer(18))}
616
+ ${`${(_a = orderData.orderData.orderStatus) !== null && _a !== void 0 ? _a : 0}` === '0'
617
+ ? html `<div class="d-flex justify-content-end mt-3">
618
+ ${BgWidget.blueNote('手動調整訂單價格', gvc.event(() => {
619
+ PosFunction.manualDiscount({
620
+ gvc,
621
+ orderDetail: orderData.orderData,
622
+ reload: voucher => {
623
+ orderData.orderData.total -= voucher.discount_total;
624
+ orderData.orderData.discount += voucher.discount_total;
625
+ gvc.notifyDataChange(id);
626
+ },
627
+ });
628
+ }))}
629
+ </div>`
630
+ : ''}
631
+ </div>`;
632
+ },
633
+ });
634
+ },
635
+ footer_html: footerGVC => {
636
+ return [
637
+ BgWidget.cancel(footerGVC.event(() => {
638
+ orderData = cloneData;
639
+ footerGVC.closeDialog();
640
+ })),
641
+ BgWidget.save(footerGVC.event(() => {
642
+ function updateEvent() {
643
+ orderData.orderData.total =
644
+ getLineItemSubtotal(orderData.orderData.lineItems) -
645
+ orderData.orderData.discount +
646
+ orderData.orderData.shipment_fee -
647
+ orderData.orderData.use_rebate;
648
+ dialog.dataLoading({ visible: true });
649
+ ApiShop.putOrder({
650
+ id: `${orderData.id}`,
651
+ order_data: orderData.orderData,
652
+ }).then(() => {
653
+ dialog.dataLoading({ visible: false });
654
+ footerGVC.closeDialog();
655
+ callback();
656
+ });
657
+ }
658
+ dialog.checkYesOrNot({
659
+ text: '此操作將會直接更新訂單明細,確定要更新嗎?',
660
+ callback: bool => bool && updateEvent(),
661
+ });
662
+ }), '更新'),
663
+ ].join('');
664
+ },
665
+ closeCallback: () => {
666
+ orderData = cloneData;
667
+ },
668
+ });
669
+ }
304
670
  }