ts-glitter 21.8.6 → 21.8.8

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 (35) hide show
  1. package/lowcode/Entry.js +1 -1
  2. package/lowcode/Entry.ts +1 -1
  3. package/lowcode/editor/basic-component.js +10 -0
  4. package/lowcode/editor/basic-component.ts +11 -1
  5. package/lowcode/glitter-base/route/post.js +9 -0
  6. package/lowcode/glitter-base/route/post.ts +9 -0
  7. package/lowcode/glitter-base/route/user.js +50 -19
  8. package/lowcode/glitter-base/route/user.ts +49 -18
  9. package/lowcode/glitterBundle/plugins/html-render.js +0 -2
  10. package/lowcode/glitterBundle/plugins/html-render.ts +0 -1
  11. package/lowcode/jspage/function-page/tool-setting.js +1 -5
  12. package/lowcode/jspage/function-page/tool-setting.ts +5 -4
  13. package/lowcode/jspage/main.js +1 -6
  14. package/lowcode/jspage/main.ts +1 -6
  15. package/lowcode/modules/image-library.js +0 -1
  16. package/lowcode/modules/image-library.ts +1 -1
  17. package/lowcode/official_view_component/official/component.js +1 -1
  18. package/lowcode/official_view_component/official/component.ts +1 -1
  19. package/lowcode/public-components/banner/first-banner.js +50 -85
  20. package/lowcode/public-components/banner/first-banner.ts +59 -96
  21. package/lowcode/public-components/public/ad.ts +1 -6
  22. package/package.json +1 -1
  23. package/src/api-public/controllers/user.js +1 -0
  24. package/src/api-public/controllers/user.js.map +1 -1
  25. package/src/api-public/controllers/user.ts +2 -1
  26. package/src/api-public/services/checkout-event.js +0 -2
  27. package/src/api-public/services/checkout-event.js.map +1 -1
  28. package/src/api-public/services/data-analyze.d.ts +1 -1
  29. package/src/api-public/services/shopping.d.ts +1 -0
  30. package/src/api-public/services/shopping.js +60 -49
  31. package/src/api-public/services/shopping.js.map +1 -1
  32. package/src/api-public/services/shopping.ts +87 -62
  33. package/src/api-public/services/user.js +1 -0
  34. package/src/api-public/services/user.js.map +1 -1
  35. package/src/api-public/services/user.ts +1 -0
@@ -647,55 +647,7 @@ export class Shopping {
647
647
  }
648
648
 
649
649
  if (query.status) {
650
- const statusSplit = query.status.split(',').map(status => status.trim());
651
- const statusJoin = statusSplit.map(status => `"${status}"`).join(',');
652
-
653
- // 基本條件
654
- const statusCondition = `JSON_EXTRACT(content, '$.status') IN (${statusJoin})`;
655
-
656
- // 時間條件
657
- const currentDate = db.escape(new Date().toISOString());
658
-
659
- const scheduleConditions = statusSplit
660
- .map(status => {
661
- switch (status) {
662
- case 'inRange':
663
- return `OR (
664
- JSON_EXTRACT(content, '$.status') IN ('active', 1)
665
- AND (
666
- content->>'$.active_schedule' IS NULL OR
667
- (
668
- (
669
- ((CONCAT(content->>'$.active_schedule.start_ISO_Date') IS NULL) and (CONCAT(content->>'$.active_schedule.startDate') IS NULL)) or
670
- ((CONCAT(content->>'$.active_schedule.start_ISO_Date') <= ${currentDate}) or (CONCAT(content->>'$.active_schedule.startDate') <= ${db.escape(moment().format('YYYY-MM-DD'))}))
671
- )
672
- AND (
673
- ((CONCAT(content->>'$.active_schedule.end_ISO_Date') IS NULL) and (CONCAT(content->>'$.active_schedule.endDate') IS NULL)) or
674
- (CONCAT(content->>'$.active_schedule.end_ISO_Date') >= ${currentDate}) or (CONCAT(content->>'$.active_schedule.endDate') >= ${db.escape(moment().format('YYYY-MM-DD'))})
675
- )
676
- )
677
- )
678
- )`;
679
- case 'beforeStart':
680
- return `
681
- OR (
682
- JSON_EXTRACT(content, '$.status') IN ('active', 1)
683
- AND CONCAT(content->>'$.active_schedule.start_ISO_Date') > ${currentDate}
684
- )`;
685
- case 'afterEnd':
686
- return `
687
- OR (
688
- JSON_EXTRACT(content, '$.status') IN ('active', 1)
689
- AND CONCAT(content->>'$.active_schedule.end_ISO_Date') < ${currentDate}
690
- )`;
691
- default:
692
- return '';
693
- }
694
- })
695
- .join('');
696
-
697
- // 組合 SQL 條件
698
- querySql.push(`(${statusCondition} ${scheduleConditions})`);
650
+ querySql.push(Shopping.productStatusSQL(query.status));
699
651
  }
700
652
 
701
653
  if (query.channel) {
@@ -4482,12 +4434,31 @@ export class Shopping {
4482
4434
  `,
4483
4435
  [{ content: JSON.stringify(content) }, content.id]
4484
4436
  );
4485
- // 同步更新蝦皮
4486
- if (content.shopee_id) {
4487
- await new Shopee(this.app, this.token).asyncStockToShopee({
4488
- product: { content },
4489
- callback: () => {},
4490
- });
4437
+
4438
+ // 刪除不存在的商品規格
4439
+ const null_variant_id_array = (
4440
+ await db.query(
4441
+ `SELECT v.id
4442
+ FROM \`${this.app}\`.t_variants v
4443
+ LEFT JOIN \`${this.app}\`.t_manager_post p ON v.product_id = p.id
4444
+ WHERE p.content->>'$.type' <> 'product' OR p.id IS NULL`,
4445
+ []
4446
+ )
4447
+ ).map((item: any) => item.id);
4448
+
4449
+ if (null_variant_id_array.length > 0) {
4450
+ await db.query(
4451
+ `DELETE FROM \`${this.app}\`.t_variants WHERE id IN (${null_variant_id_array.join(',')})
4452
+ `,
4453
+ []
4454
+ );
4455
+ }
4456
+ // 同步更新蝦皮
4457
+ if (content.shopee_id) {
4458
+ await new Shopee(this.app, this.token).asyncStockToShopee({
4459
+ product: { content },
4460
+ callback: () => {},
4461
+ });
4491
4462
  }
4492
4463
  } catch (error) {
4493
4464
  console.error(error);
@@ -5557,6 +5528,59 @@ export class Shopping {
5557
5528
  }
5558
5529
  }
5559
5530
 
5531
+ static productStatusSQL(queryStatus: string, table: string = '') {
5532
+ const tableName = table ? `${table}.` : '';
5533
+ const statusSplit = queryStatus.split(',').map(status => status.trim());
5534
+ const statusJoin = statusSplit.map(status => `"${status}"`).join(',');
5535
+
5536
+ // 基本條件
5537
+ const statusCondition = `JSON_EXTRACT(${tableName}content, '$.status') IN (${statusJoin})`;
5538
+
5539
+ // 時間條件
5540
+ const currentDate = db.escape(new Date().toISOString());
5541
+
5542
+ const scheduleConditions = statusSplit
5543
+ .map(status => {
5544
+ switch (status) {
5545
+ case 'inRange':
5546
+ return `OR (
5547
+ JSON_EXTRACT(${tableName}content, '$.status') IN ('active', 1)
5548
+ AND (
5549
+ ${tableName}content->>'$.active_schedule' IS NULL OR
5550
+ (
5551
+ (
5552
+ ((CONCAT(${tableName}content->>'$.active_schedule.start_ISO_Date') IS NULL) and (CONCAT(${tableName}content->>'$.active_schedule.startDate') IS NULL)) or
5553
+ ((CONCAT(${tableName}content->>'$.active_schedule.start_ISO_Date') <= ${currentDate}) or (CONCAT(${tableName}content->>'$.active_schedule.startDate') <= ${db.escape(moment().format('YYYY-MM-DD'))}))
5554
+ )
5555
+ AND (
5556
+ ((CONCAT(${tableName}content->>'$.active_schedule.end_ISO_Date') IS NULL) and (CONCAT(${tableName}content->>'$.active_schedule.endDate') IS NULL)) or
5557
+ (CONCAT(${tableName}content->>'$.active_schedule.end_ISO_Date') >= ${currentDate}) or (CONCAT(${tableName}content->>'$.active_schedule.endDate') >= ${db.escape(moment().format('YYYY-MM-DD'))})
5558
+ )
5559
+ )
5560
+ )
5561
+ )`;
5562
+ case 'beforeStart':
5563
+ return `
5564
+ OR (
5565
+ JSON_EXTRACT(${tableName}content, '$.status') IN ('active', 1)
5566
+ AND CONCAT(${tableName}content->>'$.active_schedule.start_ISO_Date') > ${currentDate}
5567
+ )`;
5568
+ case 'afterEnd':
5569
+ return `
5570
+ OR (
5571
+ JSON_EXTRACT(${tableName}content, '$.status') IN ('active', 1)
5572
+ AND CONCAT(${tableName}content->>'$.active_schedule.end_ISO_Date') < ${currentDate}
5573
+ )`;
5574
+ default:
5575
+ return '';
5576
+ }
5577
+ })
5578
+ .join('');
5579
+
5580
+ // 組合 SQL 條件
5581
+ return `(${statusCondition} ${scheduleConditions})`;
5582
+ }
5583
+
5560
5584
  async getVariants(query: {
5561
5585
  page: number;
5562
5586
  limit: number;
@@ -5621,11 +5645,14 @@ export class Shopping {
5621
5645
  })
5622
5646
  .join(' or ')})`
5623
5647
  );
5624
- query.status &&
5648
+
5649
+ if (query.status) {
5625
5650
  querySql.push(`
5626
- v.product_id in (select p.id
5627
- from \`${this.app}\`.t_manager_post as p where (JSON_EXTRACT(p.content, '$.status') = '${query.status}'))
5628
- `);
5651
+ v.product_id IN (SELECT p.id
5652
+ FROM \`${this.app}\`.t_manager_post AS p WHERE ${Shopping.productStatusSQL(query.status, 'p')})
5653
+ `);
5654
+ }
5655
+
5629
5656
  query.min_price && querySql.push(`(v.content->>'$.sale_price' >= ${query.min_price})`);
5630
5657
  query.max_price && querySql.push(`(v.content->>'$.sale_price' <= ${query.min_price})`);
5631
5658
 
@@ -5967,9 +5994,7 @@ export class Shopping {
5967
5994
  async getProductComment(product_id: number) {
5968
5995
  try {
5969
5996
  const comments = await db.query(
5970
- `SELECT *
5971
- FROM \`${this.app}\`.t_product_comment
5972
- WHERE product_id = ?;
5997
+ `SELECT * FROM \`${this.app}\`.t_product_comment WHERE product_id = ?;
5973
5998
  `,
5974
5999
  [product_id]
5975
6000
  );
@@ -237,6 +237,7 @@ class User {
237
237
  }
238
238
  }
239
239
  async createUserHook(userID, req) {
240
+ req.body.create_user_success = true;
240
241
  const usData = await this.getUserData(userID, 'userID');
241
242
  usData.userData.repeatPwd = undefined;
242
243
  await database_1.default.query(`update \`${this.app}\`.t_user