ts-glitter 19.2.4 → 19.2.6

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.
@@ -28,6 +28,7 @@ import { SharePermission } from './share-permission.js';
28
28
  import { TermsCheck } from './terms-check.js';
29
29
  import { App as GeneralApp } from '../../services/app.js';
30
30
  import { UserUpdate } from './user-update.js';
31
+ import { ApiPublic } from './public-table-check.js';
31
32
 
32
33
  interface UserQuery {
33
34
  page?: number;
@@ -38,14 +39,14 @@ interface UserQuery {
38
39
  order_string?: string;
39
40
  created_time?: string;
40
41
  last_order_time?: string;
41
- last_shipment_date?:string;
42
+ last_shipment_date?: string;
42
43
  birth?: string;
43
44
  level?: string;
44
45
  rebate?: string;
45
46
  last_order_total?: string;
46
47
  total_amount?: string;
47
48
  total_count?: string;
48
- member_levels?:string;
49
+ member_levels?: string;
49
50
  groupType?: string;
50
51
  groupTag?: string;
51
52
  filter_type?: string;
@@ -122,9 +123,9 @@ export class User {
122
123
  const authData = (
123
124
  await db.query(
124
125
  `SELECT *
125
- FROM \`${saasConfig.SAAS_NAME}\`.app_auth_config
126
- WHERE JSON_EXTRACT(config, '$.verifyEmail') = ?;
127
- `,
126
+ FROM \`${saasConfig.SAAS_NAME}\`.app_auth_config
127
+ WHERE JSON_EXTRACT(config, '$.verifyEmail') = ?;
128
+ `,
128
129
  [email || '-21']
129
130
  )
130
131
  )[0];
@@ -246,7 +247,7 @@ export class User {
246
247
  userData.verify_code_phone = undefined;
247
248
  await db.execute(
248
249
  `INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
249
- VALUES (?, ?, ?, ?, ?);`,
250
+ VALUES (?, ?, ?, ?, ?);`,
250
251
  [
251
252
  userID,
252
253
  account,
@@ -283,8 +284,8 @@ export class User {
283
284
  usData.userData.repeatPwd = undefined;
284
285
  await db.query(
285
286
  `update \`${this.app}\`.t_user
286
- set userData=?
287
- where userID = ?`,
287
+ set userData=?
288
+ where userID = ?`,
288
289
  [
289
290
  JSON.stringify(
290
291
  await this.checkUpdate({
@@ -347,9 +348,9 @@ export class User {
347
348
  const data: any = (
348
349
  (await db.execute(
349
350
  `select *
350
- from \`${this.app}\`.t_user
351
- where (userData ->>'$.email' = ? or userData->>'$.phone'=? or account=?)
352
- and status = 1`,
351
+ from \`${this.app}\`.t_user
352
+ where (userData ->>'$.email' = ? or userData->>'$.phone'=? or account=?)
353
+ and status = 1`,
353
354
  [account.toLowerCase(), account.toLowerCase(), account.toLowerCase()]
354
355
  )) as any
355
356
  )[0];
@@ -395,8 +396,8 @@ export class User {
395
396
  (
396
397
  await db.query(
397
398
  `select count(1)
398
- from \`${this.app}\`.t_user
399
- where userData ->>'$.email' = ?`,
399
+ from \`${this.app}\`.t_user
400
+ where userData ->>'$.email' = ?`,
400
401
  [fbResponse.email]
401
402
  )
402
403
  )[0]['count(1)'] == 0
@@ -405,7 +406,7 @@ export class User {
405
406
  const userID = findAuth ? findAuth.user : User.generateUserID();
406
407
  await db.execute(
407
408
  `INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
408
- VALUES (?, ?, ?, ?, ?);`,
409
+ VALUES (?, ?, ?, ?, ?);`,
409
410
  [
410
411
  userID,
411
412
  fbResponse.email,
@@ -423,18 +424,18 @@ export class User {
423
424
  const data: any = (
424
425
  (await db.execute(
425
426
  `select *
426
- from \`${this.app}\`.t_user
427
- where userData ->>'$.email' = ?
428
- and status = 1`,
427
+ from \`${this.app}\`.t_user
428
+ where userData ->>'$.email' = ?
429
+ and status = 1`,
429
430
  [fbResponse.email]
430
431
  )) as any
431
432
  )[0];
432
433
  data.userData['fb-id'] = fbResponse.id;
433
434
  await db.execute(
434
435
  `update \`${this.app}\`.t_user
435
- set userData=?
436
- where userID = ?
437
- and id > 0`,
436
+ set userData=?
437
+ where userID = ?
438
+ and id > 0`,
438
439
  [JSON.stringify(data.userData), data.userID]
439
440
  );
440
441
  const usData: any = await this.getUserData(data.userID, 'userID');
@@ -518,14 +519,14 @@ export class User {
518
519
  async function getUsData() {
519
520
  return (await db.execute(
520
521
  `select *
521
- from \`${app}\`.t_user
522
- where (userData ->>'$.email' = ?)
523
- or (userData ->>'$.lineID' = ?)
524
- ORDER BY CASE
525
- WHEN (userData ->>'$.lineID' = ?) THEN 1
526
- ELSE 3
527
- END
528
- `,
522
+ from \`${app}\`.t_user
523
+ where (userData ->>'$.email' = ?)
524
+ or (userData ->>'$.lineID' = ?)
525
+ ORDER BY CASE
526
+ WHEN (userData ->>'$.lineID' = ?) THEN 1
527
+ ELSE 3
528
+ END
529
+ `,
529
530
  [line_profile.email, (userData as any).sub, (userData as any).sub]
530
531
  )) as any;
531
532
  }
@@ -536,7 +537,7 @@ export class User {
536
537
  const userID = findAuth ? findAuth.user : User.generateUserID();
537
538
  await db.execute(
538
539
  `INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
539
- VALUES (?, ?, ?, ?, ?);`,
540
+ VALUES (?, ?, ?, ?, ?);`,
540
541
  [
541
542
  userID,
542
543
  line_profile.email,
@@ -557,9 +558,9 @@ export class User {
557
558
  data.userData.lineID = (userData as any).sub;
558
559
  await db.execute(
559
560
  `update \`${this.app}\`.t_user
560
- set userData=?
561
- where userID = ?
562
- and id > 0`,
561
+ set userData=?
562
+ where userID = ?
563
+ and id > 0`,
563
564
  [JSON.stringify(data.userData), data.userID]
564
565
  );
565
566
  usData.pwd = undefined;
@@ -618,8 +619,8 @@ export class User {
618
619
  (
619
620
  await db.query(
620
621
  `select count(1)
621
- from \`${this.app}\`.t_user
622
- where userData ->>'$.email' = ?`,
622
+ from \`${this.app}\`.t_user
623
+ where userData ->>'$.email' = ?`,
623
624
  [payload?.email]
624
625
  )
625
626
  )[0]['count(1)'] == 0
@@ -628,7 +629,7 @@ export class User {
628
629
  const userID = findAuth ? findAuth.user : User.generateUserID();
629
630
  await db.execute(
630
631
  `INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
631
- VALUES (?, ?, ?, ?, ?);`,
632
+ VALUES (?, ?, ?, ?, ?);`,
632
633
  [
633
634
  userID,
634
635
  payload?.email,
@@ -645,18 +646,18 @@ export class User {
645
646
  const data: any = (
646
647
  (await db.execute(
647
648
  `select *
648
- from \`${this.app}\`.t_user
649
- where userData ->>'$.email' = ?
650
- and status = 1`,
649
+ from \`${this.app}\`.t_user
650
+ where userData ->>'$.email' = ?
651
+ and status = 1`,
651
652
  [payload?.email]
652
653
  )) as any
653
654
  )[0];
654
655
  data.userData['google-id'] = payload?.sub;
655
656
  await db.execute(
656
657
  `update \`${this.app}\`.t_user
657
- set userData=?
658
- where userID = ?
659
- and id > 0`,
658
+ set userData=?
659
+ where userID = ?
660
+ and id > 0`,
660
661
  [JSON.stringify(data.userData), data.userID]
661
662
  );
662
663
  const usData: any = await this.getUserData(data.userID, 'userID');
@@ -753,8 +754,8 @@ export class User {
753
754
  (
754
755
  await db.query(
755
756
  `select count(1)
756
- from \`${this.app}\`.t_user
757
- where userData ->>'$.email' = ?`,
757
+ from \`${this.app}\`.t_user
758
+ where userData ->>'$.email' = ?`,
758
759
  [decoded.payload.email]
759
760
  )
760
761
  )[0]['count(1)'] == 0
@@ -763,7 +764,7 @@ export class User {
763
764
 
764
765
  await db.execute(
765
766
  `INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
766
- VALUES (?, ?, ?, ?, ?);`,
767
+ VALUES (?, ?, ?, ?, ?);`,
767
768
  [
768
769
  userID,
769
770
  decoded.payload.email,
@@ -783,18 +784,18 @@ export class User {
783
784
  const data: any = (
784
785
  (await db.execute(
785
786
  `select *
786
- from \`${this.app}\`.t_user
787
- where userData ->>'$.email' = ?
788
- and status = 1`,
787
+ from \`${this.app}\`.t_user
788
+ where userData ->>'$.email' = ?
789
+ and status = 1`,
789
790
  [decoded.payload.email]
790
791
  )) as any
791
792
  )[0];
792
793
  data.userData['apple-id'] = uid;
793
794
  await db.execute(
794
795
  `update \`${this.app}\`.t_user
795
- set userData=?
796
- where userID = ?
797
- and id > 0`,
796
+ set userData=?
797
+ where userID = ?
798
+ and id > 0`,
798
799
  [JSON.stringify(data.userData), data.userID]
799
800
  );
800
801
  const usData: any = await this.getUserData(data.userID, 'userID');
@@ -813,20 +814,20 @@ export class User {
813
814
  public async getUserData(query: string, type: 'userID' | 'account' | 'email_or_phone' = 'userID') {
814
815
  try {
815
816
  const sql = `select *
816
- from \`${this.app}\`.t_user
817
- where ${(() => {
818
- let query2 = [`1=1`];
819
- if (type === 'userID') {
820
- query2.push(`userID=${db.escape(query)}`);
821
- } else if (type === 'email_or_phone') {
822
- query2.push(
823
- `((userData->>'$.email'=${db.escape(query)}) or (userData->>'$.phone'=${db.escape(query)}))`
824
- );
825
- } else {
826
- query2.push(`userData->>'$.email'=${db.escape(query)}`);
827
- }
828
- return query2.join(` and `);
829
- })()}`;
817
+ from \`${this.app}\`.t_user
818
+ where ${(() => {
819
+ let query2 = [`1=1`];
820
+ if (type === 'userID') {
821
+ query2.push(`userID=${db.escape(query)}`);
822
+ } else if (type === 'email_or_phone') {
823
+ query2.push(
824
+ `((userData->>'$.email'=${db.escape(query)}) or (userData->>'$.phone'=${db.escape(query)}))`
825
+ );
826
+ } else {
827
+ query2.push(`userData->>'$.email'=${db.escape(query)}`);
828
+ }
829
+ return query2.join(` and `);
830
+ })()}`;
830
831
  const data: any = ((await db.execute(sql, [])) as any)[0];
831
832
  let cf = {
832
833
  userData: data,
@@ -896,7 +897,7 @@ export class User {
896
897
  .filter(Boolean) // 過濾掉 falsy 值
897
898
  .map(db.escape) // 轉義輸入以防止 SQL 注入
898
899
  .join(',')})
899
- AND ${orderCountingSQL}
900
+ AND ${orderCountingSQL}
900
901
  ORDER BY id DESC`,
901
902
  []
902
903
  )
@@ -1189,25 +1190,19 @@ export class User {
1189
1190
  //o.email, o.order_count, o.total_amount, u.*, lo.last_order_total, lo.last_order_time
1190
1191
  const sql = `
1191
1192
  SELECT ${obj.select}
1192
- FROM (
1193
- SELECT
1194
- email,
1195
- COUNT(*) AS order_count,
1196
- SUM(total) AS total_amount
1197
- FROM \`${this.app}\`.t_checkout
1198
- WHERE ${orderCountingSQL}
1199
- GROUP BY email
1200
- ) AS o
1201
- RIGHT JOIN \`${this.app}\`.t_user u ON o.email = u.account
1202
- LEFT JOIN (
1203
- SELECT
1204
- email,
1205
- total AS last_order_total,
1206
- created_time AS last_order_time,
1207
- ROW_NUMBER() OVER(PARTITION BY email ORDER BY created_time DESC) AS rn
1208
- FROM \`${this.app}\`.t_checkout
1209
- WHERE ${orderCountingSQL}
1210
- ) AS lo ON o.email = lo.email AND lo.rn = 1
1193
+ FROM (SELECT email,
1194
+ COUNT(*) AS order_count,
1195
+ SUM(total) AS total_amount
1196
+ FROM \`${this.app}\`.t_checkout
1197
+ WHERE ${orderCountingSQL}
1198
+ GROUP BY email) AS o
1199
+ RIGHT JOIN \`${this.app}\`.t_user u ON o.email = u.account
1200
+ LEFT JOIN (SELECT email,
1201
+ total AS last_order_total,
1202
+ created_time AS last_order_time,
1203
+ ROW_NUMBER() OVER(PARTITION BY email ORDER BY created_time DESC) AS rn
1204
+ FROM \`${this.app}\`.t_checkout
1205
+ WHERE ${orderCountingSQL}) AS lo ON o.email = lo.email AND lo.rn = 1
1211
1206
  WHERE (${whereClause})
1212
1207
  ORDER BY ${orderByClause} ${limitClause}
1213
1208
  `;
@@ -1411,10 +1406,15 @@ or
1411
1406
  }
1412
1407
  }
1413
1408
 
1414
- if(query.member_levels){
1415
- querySql.push(`member_level in (${query.member_levels.split(',').map(level => {
1416
- return db.escape(level)
1417
- }).join(',')})`)
1409
+ if (query.member_levels) {
1410
+ querySql.push(
1411
+ `member_level in (${query.member_levels
1412
+ .split(',')
1413
+ .map(level => {
1414
+ return db.escape(level);
1415
+ })
1416
+ .join(',')})`
1417
+ );
1418
1418
  }
1419
1419
 
1420
1420
  if (query.search) {
@@ -1487,18 +1487,18 @@ or
1487
1487
 
1488
1488
  const queryResult = await db.query(
1489
1489
  `
1490
- SELECT *
1491
- FROM \`${this.app}\`.t_user_public_config
1492
- WHERE \`key\` = 'member_update'
1493
- AND user_id IN (${[...userMap.keys(), '-21211'].join(',')})
1494
- `,
1490
+ SELECT *
1491
+ FROM \`${this.app}\`.t_user_public_config
1492
+ WHERE \`key\` = 'member_update'
1493
+ AND user_id IN (${[...userMap.keys(), '-21211'].join(',')})
1494
+ `,
1495
1495
  []
1496
1496
  );
1497
1497
 
1498
1498
  // 更新 userData
1499
1499
  for (const b of queryResult) {
1500
- const tag = levels.find((dd)=>{
1501
- return `${dd.id}`===`${b.user_id}`
1500
+ const tag = levels.find(dd => {
1501
+ return `${dd.id}` === `${b.user_id}`;
1502
1502
  });
1503
1503
  if (tag && tag.data && tag.data.tag_name) {
1504
1504
  const user = userMap.get(String(b.user_id)) as any;
@@ -1509,23 +1509,56 @@ or
1509
1509
  }
1510
1510
  const orderCountingSQL = await this.getCheckoutCountingModeSQL();
1511
1511
  const processUserData = async (user: any) => {
1512
- const phone=user.userData.phone || 'asnhsauh';
1513
- const email=user.userData.email || 'asnhsauh';
1512
+ const phone = user.userData.phone || 'asnhsauh';
1513
+ const email = user.userData.email || 'asnhsauh';
1514
1514
  // 取得購物金餘額
1515
1515
  const _rebate = new Rebate(this.app);
1516
1516
  const userRebate = await _rebate.getOneRebate({ user_id: user.userID });
1517
1517
  user.rebate = userRebate ? userRebate.point : 0;
1518
1518
  // 取得會員等級截止日
1519
1519
  user.member_deadline = levelMap.get(user.userID) ?? '';
1520
- user.latest_order_date=(await db.query(`select created_time from \`${this.app}\`.t_checkout where email in ('${email}','${phone}') and ${orderCountingSQL} order by created_time desc limit 0,1`,[]))[0];
1521
- user.latest_order_date=user.latest_order_date && user.latest_order_date.created_time;
1522
- user.latest_order_total=(await db.query(`select total from \`${this.app}\`.t_checkout where email in ('${email}','${phone}') and ${orderCountingSQL} order by created_time desc limit 0,1`,[]))[0];
1523
- user.latest_order_total=user.latest_order_total && user.latest_order_total.total;
1524
- user.checkout_total=(await db.query(`select sum(total) from \`${this.app}\`.t_checkout where email in ('${email}','${phone}') and ${orderCountingSQL} `,[]))[0];
1525
- user.checkout_total=user.checkout_total && user.checkout_total['sum(total)'];
1526
- user.checkout_count=(await db.query(`select count(1) from \`${this.app}\`.t_checkout where email in ('${email}','${phone}') and ${orderCountingSQL} `,[]))[0];
1527
- user.checkout_count=user.checkout_count && user.checkout_count['count(1)'];
1528
-
1520
+ user.latest_order_date = (
1521
+ await db.query(
1522
+ `select created_time
1523
+ from \`${this.app}\`.t_checkout
1524
+ where email in ('${email}', '${phone}')
1525
+ and ${orderCountingSQL}
1526
+ order by created_time desc limit 0,1`,
1527
+ []
1528
+ )
1529
+ )[0];
1530
+ user.latest_order_date = user.latest_order_date && user.latest_order_date.created_time;
1531
+ user.latest_order_total = (
1532
+ await db.query(
1533
+ `select total
1534
+ from \`${this.app}\`.t_checkout
1535
+ where email in ('${email}', '${phone}')
1536
+ and ${orderCountingSQL}
1537
+ order by created_time desc limit 0,1`,
1538
+ []
1539
+ )
1540
+ )[0];
1541
+ user.latest_order_total = user.latest_order_total && user.latest_order_total.total;
1542
+ user.checkout_total = (
1543
+ await db.query(
1544
+ `select sum(total)
1545
+ from \`${this.app}\`.t_checkout
1546
+ where email in ('${email}', '${phone}')
1547
+ and ${orderCountingSQL} `,
1548
+ []
1549
+ )
1550
+ )[0];
1551
+ user.checkout_total = user.checkout_total && user.checkout_total['sum(total)'];
1552
+ user.checkout_count = (
1553
+ await db.query(
1554
+ `select count(1)
1555
+ from \`${this.app}\`.t_checkout
1556
+ where email in ('${email}', '${phone}')
1557
+ and ${orderCountingSQL} `,
1558
+ []
1559
+ )
1560
+ )[0];
1561
+ user.checkout_count = user.checkout_count && user.checkout_count['count(1)'];
1529
1562
  };
1530
1563
 
1531
1564
  // 批次處理會員資料
@@ -1585,9 +1618,9 @@ or
1585
1618
  if (pass('subscriber')) {
1586
1619
  const subscriberList = await db.query(
1587
1620
  `SELECT DISTINCT u.userID, s.email
1588
- FROM \`${this.app}\`.t_subscribe AS s
1589
- LEFT JOIN
1590
- \`${this.app}\`.t_user AS u ON s.email = JSON_EXTRACT(u.userData, '$.email');`,
1621
+ FROM \`${this.app}\`.t_subscribe AS s
1622
+ LEFT JOIN
1623
+ \`${this.app}\`.t_user AS u ON s.email = JSON_EXTRACT(u.userData, '$.email');`,
1591
1624
  []
1592
1625
  );
1593
1626
  dataList.push({ type: 'subscriber', title: '電子郵件訂閱者', users: subscriberList });
@@ -1598,10 +1631,10 @@ or
1598
1631
  const buyingList = [] as GroupUserItem[];
1599
1632
  const buyingData = await db.query(
1600
1633
  `SELECT u.userID, c.email, JSON_UNQUOTE(JSON_EXTRACT(c.orderData, '$.email')) AS order_email
1601
- FROM \`${this.app}\`.t_checkout AS c
1602
- JOIN
1603
- \`${this.app}\`.t_user AS u ON c.email = JSON_EXTRACT(u.userData, '$.email')
1604
- WHERE c.status = 1;`,
1634
+ FROM \`${this.app}\`.t_checkout AS c
1635
+ JOIN
1636
+ \`${this.app}\`.t_user AS u ON c.email = JSON_EXTRACT(u.userData, '$.email')
1637
+ WHERE c.status = 1;`,
1605
1638
  []
1606
1639
  );
1607
1640
  buyingData.map((item1: { userID: number; email: string }) => {
@@ -1618,11 +1651,11 @@ or
1618
1651
  const usuallyBuyingList = buyingList.filter(item => item.count > usuallyBuyingStandard);
1619
1652
  const neverBuyingData = await db.query(
1620
1653
  `SELECT userID, JSON_UNQUOTE(JSON_EXTRACT(userData, '$.email')) AS email
1621
- FROM \`${this.app}\`.t_user
1622
- WHERE userID not in (${buyingList
1623
- .map(item => item.userID)
1624
- .concat([-1312])
1625
- .join(',')})`,
1654
+ FROM \`${this.app}\`.t_user
1655
+ WHERE userID not in (${buyingList
1656
+ .map(item => item.userID)
1657
+ .concat([-1312])
1658
+ .join(',')})`,
1626
1659
  []
1627
1660
  );
1628
1661
 
@@ -1654,7 +1687,7 @@ or
1654
1687
 
1655
1688
  const users = await db.query(
1656
1689
  `SELECT userID
1657
- FROM \`${this.app}\`.t_user;`,
1690
+ FROM \`${this.app}\`.t_user;`,
1658
1691
  []
1659
1692
  );
1660
1693
 
@@ -1729,10 +1762,10 @@ or
1729
1762
 
1730
1763
  const users = await db.query(
1731
1764
  `SELECT *
1732
- FROM \`${this.app}\`.t_user
1733
- WHERE userID in (${idSQL})
1734
- OR JSON_EXTRACT(userData, '$.email') in (${emailSQL})
1735
- `,
1765
+ FROM \`${this.app}\`.t_user
1766
+ WHERE userID in (${idSQL})
1767
+ OR JSON_EXTRACT(userData, '$.email') in (${emailSQL})
1768
+ `,
1736
1769
  []
1737
1770
  );
1738
1771
 
@@ -1748,9 +1781,9 @@ or
1748
1781
  if (users.length > 0) {
1749
1782
  const memberUpdates = await db.query(
1750
1783
  `SELECT *
1751
- FROM \`${this.app}\`.t_user_public_config
1752
- WHERE \`key\` = 'member_update'
1753
- AND user_id in (${idSQL});`,
1784
+ FROM \`${this.app}\`.t_user_public_config
1785
+ WHERE \`key\` = 'member_update'
1786
+ AND user_id in (${idSQL});`,
1754
1787
  []
1755
1788
  );
1756
1789
  for (const user of users) {
@@ -1804,7 +1837,7 @@ or
1804
1837
  async sql => {
1805
1838
  await sql.query(
1806
1839
  `replace
1807
- into t_subscribe (email,tag) values (?,?)`,
1840
+ into t_subscribe (email,tag) values (?,?)`,
1808
1841
  [email, tag]
1809
1842
  );
1810
1843
  }
@@ -1823,7 +1856,7 @@ or
1823
1856
  async sql => {
1824
1857
  await sql.query(
1825
1858
  `replace
1826
- into t_fcm (userID,deviceToken) values (?,?)`,
1859
+ into t_fcm (userID,deviceToken) values (?,?)`,
1827
1860
  [userID, deviceToken]
1828
1861
  );
1829
1862
  }
@@ -1837,8 +1870,8 @@ or
1837
1870
  try {
1838
1871
  await db.query(
1839
1872
  `delete
1840
- FROM \`${this.app}\`.t_subscribe
1841
- where email in (?)`,
1873
+ FROM \`${this.app}\`.t_subscribe
1874
+ where email in (?)`,
1842
1875
  [email.split(',')]
1843
1876
  );
1844
1877
  return {
@@ -1875,23 +1908,23 @@ or
1875
1908
  }
1876
1909
  const subData = await db.query(
1877
1910
  `SELECT s.*, u.account
1878
- FROM \`${this.app}\`.t_subscribe AS s
1879
- LEFT JOIN \`${this.app}\`.t_user AS u
1880
- ON s.email = u.account
1881
- WHERE ${querySql.length > 0 ? querySql.join(' AND ') : '1 = 1'} LIMIT ${query.page * query.limit}
1882
- , ${query.limit}
1911
+ FROM \`${this.app}\`.t_subscribe AS s
1912
+ LEFT JOIN \`${this.app}\`.t_user AS u
1913
+ ON s.email = u.account
1914
+ WHERE ${querySql.length > 0 ? querySql.join(' AND ') : '1 = 1'} LIMIT ${query.page * query.limit}
1915
+ , ${query.limit}
1883
1916
 
1884
- `,
1917
+ `,
1885
1918
  []
1886
1919
  );
1887
1920
  const subTotal = await db.query(
1888
1921
  `SELECT count(*) as c
1889
- FROM \`${this.app}\`.t_subscribe AS s
1890
- LEFT JOIN \`${this.app}\`.t_user AS u
1891
- ON s.email = u.account
1892
- WHERE ${querySql.length > 0 ? querySql.join(' AND ') : '1 = 1'}
1922
+ FROM \`${this.app}\`.t_subscribe AS s
1923
+ LEFT JOIN \`${this.app}\`.t_user AS u
1924
+ ON s.email = u.account
1925
+ WHERE ${querySql.length > 0 ? querySql.join(' AND ') : '1 = 1'}
1893
1926
 
1894
- `,
1927
+ `,
1895
1928
  []
1896
1929
  );
1897
1930
  return {
@@ -1919,8 +1952,8 @@ or
1919
1952
  let userData = (
1920
1953
  await db.query(
1921
1954
  `select userData
1922
- from \`${this.app}\`.t_user
1923
- where userID = ?`,
1955
+ from \`${this.app}\`.t_user
1956
+ where userID = ?`,
1924
1957
  [b.userID]
1925
1958
  )
1926
1959
  )[0];
@@ -1938,15 +1971,15 @@ or
1938
1971
  if (query.id) {
1939
1972
  await db.query(
1940
1973
  `delete
1941
- FROM \`${this.app}\`.t_user
1942
- where id in (?)`,
1974
+ FROM \`${this.app}\`.t_user
1975
+ where id in (?)`,
1943
1976
  [query.id.split(',')]
1944
1977
  );
1945
1978
  } else if (query.email) {
1946
1979
  await db.query(
1947
1980
  `delete
1948
- FROM \`${this.app}\`.t_user
1949
- where userData ->>'$.email'=?`,
1981
+ FROM \`${this.app}\`.t_user
1982
+ where userData ->>'$.email'=?`,
1950
1983
  [query.email]
1951
1984
  );
1952
1985
  }
@@ -1963,8 +1996,8 @@ or
1963
1996
  const userData = (
1964
1997
  await db.query(
1965
1998
  `select *
1966
- from \`${this.app}\`.\`t_user\`
1967
- where userID = ${db.escape(userID)}`,
1999
+ from \`${this.app}\`.\`t_user\`
2000
+ where userID = ${db.escape(userID)}`,
1968
2001
  []
1969
2002
  )
1970
2003
  )[0];
@@ -1983,8 +2016,8 @@ or
1983
2016
  if ((await redis.getValue(`verify-${userData.userData.email}`)) === par.userData.verify_code) {
1984
2017
  await db.query(
1985
2018
  `update \`${this.app}\`.\`t_user\`
1986
- set pwd=?
1987
- where userID = ${db.escape(userID)}`,
2019
+ set pwd=?
2020
+ where userID = ${db.escape(userID)}`,
1988
2021
  [await tool.hashPwd(par.userData.pwd)]
1989
2022
  );
1990
2023
  } else {
@@ -1997,9 +2030,9 @@ or
1997
2030
  const count = (
1998
2031
  await db.query(
1999
2032
  `select count(1)
2000
- from \`${this.app}\`.\`t_user\`
2001
- where (userData ->>'$.email' = ${db.escape(par.userData.email)})
2002
- and (userID != ${db.escape(userID)}) `,
2033
+ from \`${this.app}\`.\`t_user\`
2034
+ where (userData ->>'$.email' = ${db.escape(par.userData.email)})
2035
+ and (userID != ${db.escape(userID)}) `,
2003
2036
  []
2004
2037
  )
2005
2038
  )[0]['count(1)'];
@@ -2024,9 +2057,9 @@ or
2024
2057
  const count = (
2025
2058
  await db.query(
2026
2059
  `select count(1)
2027
- from \`${this.app}\`.\`t_user\`
2028
- where (userData ->>'$.phone' = ${db.escape(par.userData.phone)})
2029
- and (userID != ${db.escape(userID)}) `,
2060
+ from \`${this.app}\`.\`t_user\`
2061
+ where (userData ->>'$.phone' = ${db.escape(par.userData.phone)})
2062
+ and (userID != ${db.escape(userID)}) `,
2030
2063
  []
2031
2064
  )
2032
2065
  )[0]['count(1)'];
@@ -2052,9 +2085,9 @@ or
2052
2085
  if (par.userData.phone) {
2053
2086
  await db.query(
2054
2087
  `update \`${this.app}\`.t_checkout
2055
- set email=?
2056
- where id > 0
2057
- and email = ?`,
2088
+ set email=?
2089
+ where id > 0
2090
+ and email = ?`,
2058
2091
  [par.userData.phone, `${userData.userData.phone}`]
2059
2092
  );
2060
2093
  userData.account = par.userData.phone;
@@ -2062,9 +2095,9 @@ or
2062
2095
  if (par.userData.email) {
2063
2096
  await db.query(
2064
2097
  `update \`${this.app}\`.t_checkout
2065
- set email=?
2066
- where id > 0
2067
- and email = ?`,
2098
+ set email=?
2099
+ where id > 0
2100
+ and email = ?`,
2068
2101
  [par.userData.email, `${userData.userData.email}`]
2069
2102
  );
2070
2103
  userData.account = par.userData.email;
@@ -2083,15 +2116,15 @@ or
2083
2116
  if (!par.account) {
2084
2117
  delete par.account;
2085
2118
  }
2086
- const data=(await db.query(
2119
+ const data = (await db.query(
2087
2120
  `update \`${this.app}\`.t_user
2088
- SET ?
2089
- WHERE 1 = 1
2090
- and userID = ?`,
2121
+ SET ?
2122
+ WHERE 1 = 1
2123
+ and userID = ?`,
2091
2124
  [par, userID]
2092
- )) as any
2125
+ )) as any;
2093
2126
 
2094
- await UserUpdate.update(this.app,userID)
2127
+ await UserUpdate.update(this.app, userID);
2095
2128
 
2096
2129
  return {
2097
2130
  data: data,
@@ -2138,8 +2171,8 @@ or
2138
2171
  let originUserData = (
2139
2172
  await db.query(
2140
2173
  `select userData
2141
- from \`${this.app}\`.\`t_user\`
2142
- where userID = ${db.escape(cf.userID)}`,
2174
+ from \`${this.app}\`.\`t_user\`
2175
+ where userID = ${db.escape(cf.userID)}`,
2143
2176
  []
2144
2177
  )
2145
2178
  )[0]['userData'];
@@ -2164,9 +2197,9 @@ or
2164
2197
  try {
2165
2198
  const result = (await db.query(
2166
2199
  `update \`${this.app}\`.t_user
2167
- SET ?
2168
- WHERE 1 = 1
2169
- and ((userData ->>'$.email' = ?))`,
2200
+ SET ?
2201
+ WHERE 1 = 1
2202
+ and ((userData ->>'$.email' = ?))`,
2170
2203
  [
2171
2204
  {
2172
2205
  pwd: await tool.hashPwd(newPwd),
@@ -2187,18 +2220,18 @@ or
2187
2220
  const data: any = (
2188
2221
  (await db.execute(
2189
2222
  `select *
2190
- from \`${this.app}\`.t_user
2191
- where userID = ?
2192
- and status = 1`,
2223
+ from \`${this.app}\`.t_user
2224
+ where userID = ?
2225
+ and status = 1`,
2193
2226
  [userID]
2194
2227
  )) as any
2195
2228
  )[0];
2196
2229
  if (await tool.compareHash(pwd, data.pwd)) {
2197
2230
  const result = (await db.query(
2198
2231
  `update \`${this.app}\`.t_user
2199
- SET ?
2200
- WHERE 1 = 1
2201
- and userID = ?`,
2232
+ SET ?
2233
+ WHERE 1 = 1
2234
+ and userID = ?`,
2202
2235
  [
2203
2236
  {
2204
2237
  pwd: await tool.hashPwd(newPwd),
@@ -2220,13 +2253,13 @@ or
2220
2253
  public async updateAccountBack(token: string) {
2221
2254
  try {
2222
2255
  const sql = `select userData
2223
- from \`${this.app}\`.t_user
2224
- where JSON_EXTRACT(userData, '$.mailVerify') = ${db.escape(token)}`;
2256
+ from \`${this.app}\`.t_user
2257
+ where JSON_EXTRACT(userData, '$.mailVerify') = ${db.escape(token)}`;
2225
2258
  const userData = (await db.query(sql, []))[0]['userData'];
2226
2259
  await db.execute(
2227
2260
  `update \`${this.app}\`.t_user
2228
- set account=${db.escape(userData.updateAccount)}
2229
- where JSON_EXTRACT(userData, '$.mailVerify') = ?`,
2261
+ set account=${db.escape(userData.updateAccount)}
2262
+ where JSON_EXTRACT(userData, '$.mailVerify') = ?`,
2230
2263
  [token]
2231
2264
  );
2232
2265
  } catch (e) {
@@ -2241,9 +2274,9 @@ or
2241
2274
  };
2242
2275
  return (await db.query(
2243
2276
  `update \`${this.app}\`.t_user
2244
- SET ?
2245
- WHERE 1 = 1
2246
- and JSON_EXTRACT(userData, '$.mailVerify') = ?`,
2277
+ SET ?
2278
+ WHERE 1 = 1
2279
+ and JSON_EXTRACT(userData, '$.mailVerify') = ?`,
2247
2280
  [par, token]
2248
2281
  )) as any;
2249
2282
  } catch (e) {
@@ -2257,9 +2290,9 @@ or
2257
2290
  (
2258
2291
  (await db.execute(
2259
2292
  `select count(1)
2260
- from \`${this.app}\`.t_user
2261
- where userData ->>'$.email'
2262
- and status!=0`,
2293
+ from \`${this.app}\`.t_user
2294
+ where userData ->>'$.email'
2295
+ and status!=0`,
2263
2296
  [account]
2264
2297
  )) as any
2265
2298
  )[0]['count(1)'] == 1
@@ -2286,9 +2319,9 @@ or
2286
2319
  if (email) {
2287
2320
  const emailResult = await db.execute(
2288
2321
  `SELECT COUNT(1) AS count
2289
- FROM \`${this.app}\`.t_user
2290
- WHERE userData ->>'$.email' = ?
2291
- `,
2322
+ FROM \`${this.app}\`.t_user
2323
+ WHERE userData ->>'$.email' = ?
2324
+ `,
2292
2325
  [email]
2293
2326
  );
2294
2327
  emailExists = (emailResult as any)[0]?.count > 0;
@@ -2297,9 +2330,9 @@ or
2297
2330
  if (phone) {
2298
2331
  const phoneResult = await db.execute(
2299
2332
  `SELECT COUNT(1) AS count
2300
- FROM \`${this.app}\`.t_user
2301
- WHERE userData ->>'$.phone' = ?
2302
- `,
2333
+ FROM \`${this.app}\`.t_user
2334
+ WHERE userData ->>'$.phone' = ?
2335
+ `,
2303
2336
  [phone]
2304
2337
  );
2305
2338
  phoneExists = (phoneResult as any)[0]?.count > 0;
@@ -2322,8 +2355,8 @@ or
2322
2355
  const count = (
2323
2356
  await db.query(
2324
2357
  `select count(1)
2325
- from \`${this.app}\`.t_user
2326
- where userID = ?`,
2358
+ from \`${this.app}\`.t_user
2359
+ where userID = ?`,
2327
2360
  [id]
2328
2361
  )
2329
2362
  )[0]['count(1)'];
@@ -2342,30 +2375,39 @@ or
2342
2375
  (
2343
2376
  await db.query(
2344
2377
  `select count(1)
2345
- from \`${this.app}\`.t_user_public_config
2346
- where \`key\` = ?
2347
- and user_id = ? `,
2378
+ from \`${this.app}\`.t_user_public_config
2379
+ where \`key\` = ?
2380
+ and user_id = ? `,
2348
2381
  [config.key, config.user_id ?? this.token!.userID]
2349
2382
  )
2350
2383
  )[0]['count(1)'] === 1
2351
2384
  ) {
2352
2385
  await db.query(
2353
2386
  `update \`${this.app}\`.t_user_public_config
2354
- set value=?,
2355
- updated_at=?
2356
- where \`key\` = ?
2357
- and user_id = ?`,
2387
+ set value=?,
2388
+ updated_at=?
2389
+ where \`key\` = ?
2390
+ and user_id = ?`,
2358
2391
  [config.value, new Date(), config.key, config.user_id ?? this.token!.userID]
2359
2392
  );
2360
2393
  } else {
2361
2394
  await db.query(
2362
2395
  `insert
2363
- into \`${this.app}\`.t_user_public_config (\`user_id\`, \`key\`, \`value\`, updated_at)
2364
- values (?, ?, ?, ?)
2365
- `,
2396
+ into \`${this.app}\`.t_user_public_config (\`user_id\`, \`key\`, \`value\`, updated_at)
2397
+ values (?, ?, ?, ?)
2398
+ `,
2366
2399
  [config.user_id ?? this.token!.userID, config.key, config.value, new Date()]
2367
2400
  );
2368
2401
  }
2402
+ //如果重新設定301轉址的話會需要將ApiPublic.app301重新清理過
2403
+ if (config.key === 'domain_301') {
2404
+ const find_app_301 = ApiPublic.app301.find(dd => {
2405
+ return dd.app_name === this.app;
2406
+ });
2407
+ if (find_app_301) {
2408
+ find_app_301.router = JSON.parse(config.value).list;
2409
+ }
2410
+ }
2369
2411
  } catch (e) {
2370
2412
  console.error(e);
2371
2413
  throw exception.BadRequestError('ERROR', 'ERROR.' + e, null);
@@ -2376,10 +2418,10 @@ or
2376
2418
  try {
2377
2419
  return await db.execute(
2378
2420
  `select *
2379
- from \`${this.app}\`.t_user_public_config
2380
- where \`key\` = ${db.escape(config.key)}
2381
- and user_id = ${db.escape(config.user_id)}
2382
- `,
2421
+ from \`${this.app}\`.t_user_public_config
2422
+ where \`key\` = ${db.escape(config.key)}
2423
+ and user_id = ${db.escape(config.user_id)}
2424
+ `,
2383
2425
  []
2384
2426
  );
2385
2427
  } catch (e) {
@@ -2403,7 +2445,7 @@ or
2403
2445
  .join(',')})`
2404
2446
  : `\`key\` = ${db.escape(config.key)}`
2405
2447
  }
2406
- AND user_id = ${db.escape(config.user_id)}`,
2448
+ AND user_id = ${db.escape(config.user_id)}`,
2407
2449
  []
2408
2450
  );
2409
2451
 
@@ -2523,8 +2565,8 @@ or
2523
2565
  const count = (
2524
2566
  await db.query(
2525
2567
  `select count(1)
2526
- from \`${this.app}\`.t_user
2527
- where userData ->>'$.email' = ?`,
2568
+ from \`${this.app}\`.t_user
2569
+ where userData ->>'$.email' = ?`,
2528
2570
  [email]
2529
2571
  )
2530
2572
  )[0]['count(1)'];
@@ -2539,8 +2581,8 @@ or
2539
2581
  const count = (
2540
2582
  await db.query(
2541
2583
  `select count(1)
2542
- from \`${this.app}\`.t_user
2543
- where userData ->>'$.phone' = ?`,
2584
+ from \`${this.app}\`.t_user
2585
+ where userData ->>'$.phone' = ?`,
2544
2586
  [phone]
2545
2587
  )
2546
2588
  )[0]['count(1)'];
@@ -2554,18 +2596,18 @@ or
2554
2596
  try {
2555
2597
  const last_read_time = await db.query(
2556
2598
  `SELECT value
2557
- FROM \`${this.app}\`.t_user_public_config
2558
- where \`key\` = 'notice_last_read'
2559
- and user_id = ?;`,
2599
+ FROM \`${this.app}\`.t_user_public_config
2600
+ where \`key\` = 'notice_last_read'
2601
+ and user_id = ?;`,
2560
2602
  [this.token?.userID]
2561
2603
  );
2562
2604
  const date = !last_read_time[0] ? new Date('2022-01-29') : new Date(last_read_time[0].value.time);
2563
2605
  const count = (
2564
2606
  await db.query(
2565
2607
  `select count(1)
2566
- from \`${this.app}\`.t_notice
2567
- where user_id = ?
2568
- and created_time > ?`,
2608
+ from \`${this.app}\`.t_notice
2609
+ where user_id = ?
2610
+ and created_time > ?`,
2569
2611
  [this.token?.userID, date]
2570
2612
  )
2571
2613
  )[0]['count(1)'];
@@ -2581,16 +2623,16 @@ or
2581
2623
  try {
2582
2624
  const result = await db.query(
2583
2625
  `select count(1)
2584
- from ${process.env.GLITTER_DB}.app_config
2585
- where (appName = ?
2586
- and user = ?)
2587
- OR appName in (
2588
- (SELECT appName
2589
- FROM \`${saasConfig.SAAS_NAME}\`.app_auth_config
2590
- WHERE user = ?
2591
- AND status = 1
2592
- AND invited = 1
2593
- AND appName = ?));`,
2626
+ from ${process.env.GLITTER_DB}.app_config
2627
+ where (appName = ?
2628
+ and user = ?)
2629
+ OR appName in (
2630
+ (SELECT appName
2631
+ FROM \`${saasConfig.SAAS_NAME}\`.app_auth_config
2632
+ WHERE user = ?
2633
+ AND status = 1
2634
+ AND invited = 1
2635
+ AND appName = ?));`,
2594
2636
  [this.app, this.token?.userID, this.token?.userID, this.app]
2595
2637
  );
2596
2638
  return {
@@ -2605,24 +2647,24 @@ or
2605
2647
  let last_time_read = 0;
2606
2648
  const last_read_time = await db.query(
2607
2649
  `SELECT value
2608
- FROM \`${this.app}\`.t_user_public_config
2609
- where \`key\` = 'notice_last_read'
2610
- and user_id = ?;`,
2650
+ FROM \`${this.app}\`.t_user_public_config
2651
+ where \`key\` = 'notice_last_read'
2652
+ and user_id = ?;`,
2611
2653
  [this.token?.userID]
2612
2654
  );
2613
2655
  if (!last_read_time[0]) {
2614
2656
  await db.query(
2615
2657
  `insert into \`${this.app}\`.t_user_public_config (user_id, \`key\`, value, updated_at)
2616
- values (?, ?, ?, ?)`,
2658
+ values (?, ?, ?, ?)`,
2617
2659
  [this.token?.userID, 'notice_last_read', JSON.stringify({ time: new Date() }), new Date()]
2618
2660
  );
2619
2661
  } else {
2620
2662
  last_time_read = new Date(last_read_time[0].value.time).getTime();
2621
2663
  await db.query(
2622
2664
  `update \`${this.app}\`.t_user_public_config
2623
- set \`value\`=?
2624
- where user_id = ?
2625
- and \`key\` = ?`,
2665
+ set \`value\`=?
2666
+ where user_id = ?
2667
+ and \`key\` = ?`,
2626
2668
  [JSON.stringify({ time: new Date() }), `${this.token?.userID}`, 'notice_last_read']
2627
2669
  );
2628
2670
  }
@@ -2655,8 +2697,8 @@ or
2655
2697
  const db_data = (
2656
2698
  await db.query(
2657
2699
  `select *
2658
- from ${saasConfig.SAAS_NAME}.t_ip_info
2659
- where ip = ?`,
2700
+ from ${saasConfig.SAAS_NAME}.t_ip_info
2701
+ where ip = ?`,
2660
2702
  [ip]
2661
2703
  )
2662
2704
  )[0];
@@ -2665,7 +2707,7 @@ or
2665
2707
  ip_data = (await axios.request(config)).data;
2666
2708
  await db.query(
2667
2709
  `insert into ${saasConfig.SAAS_NAME}.t_ip_info (ip, data)
2668
- values (?, ?)`,
2710
+ values (?, ?)`,
2669
2711
  [ip, JSON.stringify(ip_data)]
2670
2712
  );
2671
2713
  }