ts-glitter 13.3.4 → 13.3.7

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 (101) hide show
  1. package/lowcode/Entry.js +1 -1
  2. package/lowcode/Entry.ts +1 -1
  3. package/lowcode/backend-manager/bg-blog.js +2 -7
  4. package/lowcode/backend-manager/bg-blog.ts +8 -13
  5. package/lowcode/backend-manager/bg-customer-message.js +4 -2
  6. package/lowcode/backend-manager/bg-customer-message.ts +4 -2
  7. package/lowcode/backend-manager/bg-graph-api.js +6 -11
  8. package/lowcode/backend-manager/bg-graph-api.ts +14 -20
  9. package/lowcode/backend-manager/bg-line.js +526 -1002
  10. package/lowcode/backend-manager/bg-line.ts +1815 -2354
  11. package/lowcode/backend-manager/bg-notify.js +392 -746
  12. package/lowcode/backend-manager/bg-notify.ts +436 -835
  13. package/lowcode/backend-manager/bg-project.js +176 -293
  14. package/lowcode/backend-manager/bg-project.ts +214 -344
  15. package/lowcode/backend-manager/bg-recommend.js +39 -148
  16. package/lowcode/backend-manager/bg-recommend.ts +43 -162
  17. package/lowcode/backend-manager/bg-sns.js +489 -814
  18. package/lowcode/backend-manager/bg-sns.ts +1876 -2238
  19. package/lowcode/backend-manager/bg-widget.js +301 -171
  20. package/lowcode/backend-manager/bg-widget.ts +324 -193
  21. package/lowcode/cms-plugin/ai-points.js +84 -67
  22. package/lowcode/cms-plugin/ai-points.ts +280 -247
  23. package/lowcode/cms-plugin/auto-reply.js +6 -7
  24. package/lowcode/cms-plugin/auto-reply.ts +6 -7
  25. package/lowcode/cms-plugin/data-analyze.js +5 -6
  26. package/lowcode/cms-plugin/data-analyze.ts +5 -6
  27. package/lowcode/cms-plugin/form-setting.js +122 -220
  28. package/lowcode/cms-plugin/form-setting.ts +124 -240
  29. package/lowcode/cms-plugin/line-auto-reply.js +17 -18
  30. package/lowcode/cms-plugin/line-auto-reply.ts +29 -36
  31. package/lowcode/cms-plugin/member-group-list.js +5 -2
  32. package/lowcode/cms-plugin/member-group-list.ts +5 -2
  33. package/lowcode/cms-plugin/member-type-list.js +36 -84
  34. package/lowcode/cms-plugin/member-type-list.ts +39 -92
  35. package/lowcode/cms-plugin/menus-setting.js +8 -73
  36. package/lowcode/cms-plugin/menus-setting.ts +8 -78
  37. package/lowcode/cms-plugin/permission-setting.js +73 -106
  38. package/lowcode/cms-plugin/permission-setting.ts +236 -278
  39. package/lowcode/cms-plugin/shopping-collections.js +95 -137
  40. package/lowcode/cms-plugin/shopping-collections.ts +103 -147
  41. package/lowcode/cms-plugin/shopping-discount-setting.js +310 -416
  42. package/lowcode/cms-plugin/shopping-discount-setting.ts +1269 -1386
  43. package/lowcode/cms-plugin/shopping-finance-setting.js +1 -0
  44. package/lowcode/cms-plugin/shopping-finance-setting.ts +1 -0
  45. package/lowcode/cms-plugin/shopping-order-manager.js +742 -973
  46. package/lowcode/cms-plugin/shopping-order-manager.ts +1928 -2164
  47. package/lowcode/cms-plugin/shopping-order-return.js +147 -267
  48. package/lowcode/cms-plugin/shopping-order-return.ts +154 -292
  49. package/lowcode/cms-plugin/shopping-product-setting.js +6 -2
  50. package/lowcode/cms-plugin/shopping-product-setting.ts +8 -4
  51. package/lowcode/cms-plugin/shopping-product-stock.js +12 -92
  52. package/lowcode/cms-plugin/shopping-product-stock.ts +14 -94
  53. package/lowcode/cms-plugin/shopping-product-text.js +0 -3
  54. package/lowcode/cms-plugin/shopping-product-text.ts +0 -3
  55. package/lowcode/cms-plugin/shopping-rebate.js +95 -151
  56. package/lowcode/cms-plugin/shopping-rebate.ts +101 -159
  57. package/lowcode/cms-plugin/sms-points.js +83 -67
  58. package/lowcode/cms-plugin/sms-points.ts +281 -241
  59. package/lowcode/cms-plugin/sns-auto-reply.js +18 -18
  60. package/lowcode/cms-plugin/sns-auto-reply.ts +34 -40
  61. package/lowcode/cms-plugin/user-list.js +71 -90
  62. package/lowcode/cms-plugin/user-list.ts +76 -95
  63. package/lowcode/cms-plugin/web-config-setting.js +61 -111
  64. package/lowcode/cms-plugin/web-config-setting.ts +65 -124
  65. package/lowcode/css/editor.css +5 -2
  66. package/lowcode/glitter-base/route/shopping.js +1 -1
  67. package/lowcode/glitter-base/route/shopping.ts +19 -19
  68. package/lowcode/jspage/editor.js +1 -1
  69. package/lowcode/jspage/editor.ts +1 -1
  70. package/lowcode/jspage/main.js +3 -0
  71. package/lowcode/jspage/main.ts +3 -0
  72. package/package.json +1 -2
  73. package/src/api-public/controllers/ai-chat.js.map +5 -1
  74. package/src/api-public/controllers/article.js.map +1 -1
  75. package/src/api-public/controllers/chat.js.map +1 -1
  76. package/src/api-public/controllers/fb-message.js.map +1 -1
  77. package/src/api-public/controllers/index.js.map +1 -1
  78. package/src/api-public/controllers/line-message.js.map +1 -1
  79. package/src/api-public/controllers/rebate.js.map +1 -1
  80. package/src/api-public/controllers/shop.js.map +1 -1
  81. package/src/api-public/controllers/user.js.map +1 -1
  82. package/src/api-public/services/auto-send-email.js.map +1 -1
  83. package/src/api-public/services/chat.js +3 -3
  84. package/src/api-public/services/chat.js.map +1 -1
  85. package/src/api-public/services/chat.ts +3 -4
  86. package/src/api-public/services/fb-message.js.map +5 -1
  87. package/src/api-public/services/filter-protect-data.js.map +1 -1
  88. package/src/api-public/services/line-message.js.map +1 -1
  89. package/src/api-public/services/monitor.js.map +1 -1
  90. package/src/api-public/services/notify.js.map +1 -1
  91. package/src/api-public/services/rebate.js.map +1 -1
  92. package/src/api-public/services/schedule.js.map +1 -1
  93. package/src/api-public/services/share-permission.js.map +1 -1
  94. package/src/api-public/services/shopping.js.map +1 -1
  95. package/src/api-public/services/user.js +67 -66
  96. package/src/api-public/services/user.js.map +1 -1
  97. package/src/api-public/services/user.ts +212 -182
  98. package/src/helper/glitter-util.js.map +1 -1
  99. package/src/modules/firebase.d.ts +1 -0
  100. package/src/modules/firebase.js +1 -1
  101. package/src/modules/firebase.js.map +1 -1
@@ -1,29 +1,29 @@
1
1
  import db from '../../modules/database';
2
2
  import exception from '../../modules/exception';
3
- import tool, {getUUID} from '../../services/tool';
3
+ import tool, { getUUID } from '../../services/tool';
4
4
  import UserUtil from '../../utils/UserUtil';
5
5
  import config from '../../config.js';
6
- import {sendmail} from '../../services/ses.js';
6
+ import { sendmail } from '../../services/ses.js';
7
7
  import App from '../../app.js';
8
8
  import redis from '../../modules/redis.js';
9
9
  import Tool from '../../modules/tool.js';
10
10
  import process from 'process';
11
- import {UtDatabase} from '../utils/ut-database.js';
12
- import {CustomCode} from './custom-code.js';
13
- import {IToken} from '../models/Auth.js';
11
+ import { UtDatabase } from '../utils/ut-database.js';
12
+ import { CustomCode } from './custom-code.js';
13
+ import { IToken } from '../models/Auth.js';
14
14
  import axios from 'axios';
15
- import {AutoSendEmail} from './auto-send-email.js';
15
+ import { AutoSendEmail } from './auto-send-email.js';
16
16
  import qs from 'qs';
17
17
  import jwt from 'jsonwebtoken';
18
- import {OAuth2Client} from 'google-auth-library';
19
- import {Rebate} from './rebate.js';
18
+ import { OAuth2Client } from 'google-auth-library';
19
+ import { Rebate } from './rebate.js';
20
20
  import moment from 'moment';
21
- import {ManagerNotify} from './notify.js';
22
- import {saasConfig} from '../../config';
23
- import {SMS} from "./sms.js";
24
- import {BadRequestError} from "openai/error.js";
25
- import {FormCheck} from "./form-check.js";
26
- import {LoginTicket} from "google-auth-library/build/src/auth/loginticket.js";
21
+ import { ManagerNotify } from './notify.js';
22
+ import { saasConfig } from '../../config';
23
+ import { SMS } from './sms.js';
24
+ import { BadRequestError } from 'openai/error.js';
25
+ import { FormCheck } from './form-check.js';
26
+ import { LoginTicket } from 'google-auth-library/build/src/auth/loginticket.js';
27
27
 
28
28
  interface UserQuery {
29
29
  page?: number;
@@ -120,48 +120,45 @@ export class User {
120
120
  }
121
121
 
122
122
  public async emailVerify(account: string) {
123
- const time: any = await redis.getValue(`verify-${account}-last-time`)
123
+ const time: any = await redis.getValue(`verify-${account}-last-time`);
124
124
  //超過30秒可在次發送
125
- if (!time || ((new Date().getTime() - new Date(time).getTime()) > 1000 * 30)) {
126
- await redis.setValue(`verify-${account}-last-time`, new Date().toISOString())
125
+ if (!time || new Date().getTime() - new Date(time).getTime() > 1000 * 30) {
126
+ await redis.setValue(`verify-${account}-last-time`, new Date().toISOString());
127
127
  const data = await AutoSendEmail.getDefCompare(this.app, 'auto-email-verify-update');
128
128
  const code = Tool.randomNumber(6);
129
129
  await redis.setValue(`verify-${account}`, code);
130
130
  data.content = data.content.replace(`@{{code}}`, code);
131
131
  sendmail(`${data.name} <${process.env.smtp}>`, account, data.title, data.content);
132
132
  return {
133
- result: true
134
- }
133
+ result: true,
134
+ };
135
135
  } else {
136
136
  return {
137
- result: false
138
- }
137
+ result: false,
138
+ };
139
139
  }
140
-
141
140
  }
142
141
 
143
142
  public async phoneVerify(account: string) {
144
- const time: any = await redis.getValue(`verify-phone-${account}-last-time`)
143
+ const time: any = await redis.getValue(`verify-phone-${account}-last-time`);
145
144
  //超過30秒可在次發送
146
- if (!time || ((new Date().getTime() - new Date(time).getTime()) > 1000 * 30)) {
147
- await redis.setValue(`verify-phone-${account}-last-time`, new Date().toISOString())
145
+ if (!time || new Date().getTime() - new Date(time).getTime() > 1000 * 30) {
146
+ await redis.setValue(`verify-phone-${account}-last-time`, new Date().toISOString());
148
147
  const data = await AutoSendEmail.getDefCompare(this.app, 'auto-phone-verify-update');
149
148
  const code = Tool.randomNumber(6);
150
149
  await redis.setValue(`verify-phone-${account}`, code);
151
150
  data.content = data.content.replace(`@{{code}}`, code);
152
151
 
153
152
  const sns = new SMS(this.app, this.token);
154
- await sns.sendSNS({data: data.content as string, phone: account}, () => {
155
- });
153
+ await sns.sendSNS({ data: data.content as string, phone: account }, () => {});
156
154
  return {
157
- result: true
158
- }
155
+ result: true,
156
+ };
159
157
  } else {
160
158
  return {
161
- result: false
162
- }
159
+ result: false,
160
+ };
163
161
  }
164
-
165
162
  }
166
163
 
167
164
  public async createUser(account: string, pwd: string, userData: any, req: any, pass_verify?: boolean) {
@@ -174,42 +171,54 @@ export class User {
174
171
  key: 'custom_form_register',
175
172
  user_id: 'manager',
176
173
  });
177
- register_form.list = register_form.list ?? []
178
- FormCheck.initialRegisterForm(register_form.list)
174
+ register_form.list = register_form.list ?? [];
175
+ FormCheck.initialRegisterForm(register_form.list);
179
176
  userData = userData ?? {};
180
177
  delete userData.pwd;
181
178
  delete userData.repeat_password;
182
179
  const findAuth = await this.findAuthUser(account);
183
180
  const userID = findAuth ? findAuth.user : User.generateUserID();
184
- if (register_form.list.find((dd: any) => {
185
- return dd.key === 'email' && `${dd.hidden}` !== 'true'
186
- }) && !userData.email) {
181
+ if (
182
+ register_form.list.find((dd: any) => {
183
+ return dd.key === 'email' && `${dd.hidden}` !== 'true';
184
+ }) &&
185
+ !userData.email
186
+ ) {
187
187
  throw exception.BadRequestError('BAD_REQUEST', 'Verify code error.', {
188
- msg: 'lead data with email.'
188
+ msg: 'lead data with email.',
189
189
  });
190
190
  }
191
- if (register_form.list.find((dd: any) => {
192
- return dd.key === 'phone' && `${dd.hidden}` !== 'true'
193
- }) && !userData.phone) {
191
+ if (
192
+ register_form.list.find((dd: any) => {
193
+ return dd.key === 'phone' && `${dd.hidden}` !== 'true';
194
+ }) &&
195
+ !userData.phone
196
+ ) {
194
197
  throw exception.BadRequestError('BAD_REQUEST', 'Verify code error.', {
195
- msg: 'lead data with phone.'
198
+ msg: 'lead data with phone.',
196
199
  });
197
200
  }
198
201
  if (!pass_verify) {
199
- if (login_config.email_verify && (userData.verify_code !== (await redis.getValue(`verify-${userData.email}`)))
200
- && register_form.list.find((dd: any) => {
201
- return dd.key === 'email' && `${dd.hidden}` !== 'true'
202
+ if (
203
+ login_config.email_verify &&
204
+ userData.verify_code !== (await redis.getValue(`verify-${userData.email}`)) &&
205
+ register_form.list.find((dd: any) => {
206
+ return dd.key === 'email' && `${dd.hidden}` !== 'true';
202
207
  })
203
208
  ) {
204
209
  throw exception.BadRequestError('BAD_REQUEST', 'Verify code error.', {
205
- msg: 'email-verify-false'
210
+ msg: 'email-verify-false',
206
211
  });
207
212
  }
208
- if (login_config.phone_verify && (userData.verify_code_phone !== (await redis.getValue(`verify-phone-${userData.phone}`))) && register_form.list.find((dd: any) => {
209
- return dd.key === 'phone' && `${dd.hidden}` !== 'true'
210
- })) {
213
+ if (
214
+ login_config.phone_verify &&
215
+ userData.verify_code_phone !== (await redis.getValue(`verify-phone-${userData.phone}`)) &&
216
+ register_form.list.find((dd: any) => {
217
+ return dd.key === 'phone' && `${dd.hidden}` !== 'true';
218
+ })
219
+ ) {
211
220
  throw exception.BadRequestError('BAD_REQUEST', 'Verify code error.', {
212
- msg: 'phone-verify-false'
221
+ msg: 'phone-verify-false',
213
222
  });
214
223
  }
215
224
  }
@@ -233,7 +242,7 @@ export class User {
233
242
 
234
243
  return usData;
235
244
  } catch (e: any) {
236
- console.log(e)
245
+ console.error(e);
237
246
  throw exception.BadRequestError('BAD_REQUEST', 'Register Error:' + e, e.data);
238
247
  }
239
248
  }
@@ -264,7 +273,7 @@ export class User {
264
273
  }
265
274
 
266
275
  //發送購物金
267
- const getRS = await this.getConfig({key: 'rebate_setting', user_id: 'manager'});
276
+ const getRS = await this.getConfig({ key: 'rebate_setting', user_id: 'manager' });
268
277
  const rgs = getRS[0] && getRS[0].value.register ? getRS[0].value.register : {};
269
278
  if (rgs && rgs.switch && rgs.value) {
270
279
  await new Rebate(this.app).insertRebate(userID, rgs.value, '新加入會員', {
@@ -275,7 +284,7 @@ export class User {
275
284
 
276
285
  //發送用戶註冊通知
277
286
  const manager = new ManagerNotify(this.app);
278
- manager.userRegister({user_id: userID});
287
+ manager.userRegister({ user_id: userID });
279
288
  }
280
289
 
281
290
  public async updateAccount(account: string, userID: string): Promise<any> {
@@ -387,14 +396,14 @@ export class User {
387
396
  [fbResponse.email]
388
397
  )) as any
389
398
  )[0];
390
- data.userData["fb-id"] = fbResponse.id;
391
- await db.execute(`update \`${this.app}\`.t_user
399
+ data.userData['fb-id'] = fbResponse.id;
400
+ await db.execute(
401
+ `update \`${this.app}\`.t_user
392
402
  set userData=?
393
403
  where userID = ?
394
- and id > 0`, [
395
- JSON.stringify(data.userData),
396
- data.userID
397
- ]);
404
+ and id > 0`,
405
+ [JSON.stringify(data.userData), data.userID]
406
+ );
398
407
  const usData: any = await this.getUserData(data.userID, 'userID');
399
408
  usData.pwd = undefined;
400
409
  usData.token = await UserUtil.generateToken({
@@ -405,7 +414,6 @@ export class User {
405
414
  return usData;
406
415
  }
407
416
 
408
-
409
417
  public async loginWithLine(code: string, redirect: string) {
410
418
  try {
411
419
  const lineData = await this.getConfigV2({
@@ -416,8 +424,8 @@ export class User {
416
424
  const lineResponse: any = await new Promise((resolve, reject) => {
417
425
  if (redirect === 'app') {
418
426
  resolve({
419
- id_token: code
420
- })
427
+ id_token: code,
428
+ });
421
429
  } else {
422
430
  axios
423
431
  .request({
@@ -439,8 +447,7 @@ export class User {
439
447
  resolve(response.data);
440
448
  })
441
449
  .catch((error) => {
442
- console.log(error)
443
- console.error(error.message);
450
+ console.error(error);
444
451
  resolve(false);
445
452
  });
446
453
  }
@@ -511,13 +518,13 @@ export class User {
511
518
  )[0];
512
519
  const usData: any = await this.getUserData(data.userID, 'userID');
513
520
  data.userData.lineID = (userData as any).sub;
514
- await db.execute(`update \`${this.app}\`.t_user
521
+ await db.execute(
522
+ `update \`${this.app}\`.t_user
515
523
  set userData=?
516
524
  where userID = ?
517
- and id > 0`, [
518
- JSON.stringify(data.userData),
519
- data.userID
520
- ]);
525
+ and id > 0`,
526
+ [JSON.stringify(data.userData), data.userID]
527
+ );
521
528
  usData.pwd = undefined;
522
529
  usData.token = await UserUtil.generateToken({
523
530
  user_id: usData['userID'],
@@ -543,25 +550,28 @@ export class User {
543
550
  try {
544
551
  if (redirect === 'app') {
545
552
  const client = new OAuth2Client(config.app_id);
546
- resolve(await client.verifyIdToken({
547
- idToken: code,
548
- audience: config.app_id, // 這裡是你的應用的 client_id
549
- }));
553
+ resolve(
554
+ await client.verifyIdToken({
555
+ idToken: code,
556
+ audience: config.app_id, // 這裡是你的應用的 client_id
557
+ })
558
+ );
550
559
  } else {
551
560
  const oauth2Client = new OAuth2Client(config.id, config.secret, redirect);
552
561
  // 使用授权码交换令牌
553
- const {tokens} = await oauth2Client.getToken(code);
562
+ const { tokens } = await oauth2Client.getToken(code);
554
563
  oauth2Client.setCredentials(tokens);
555
- resolve(await oauth2Client.verifyIdToken({
556
- idToken: tokens.id_token as any,
557
- audience: config.id,
558
- }));
564
+ resolve(
565
+ await oauth2Client.verifyIdToken({
566
+ idToken: tokens.id_token as any,
567
+ audience: config.id,
568
+ })
569
+ );
559
570
  }
560
571
  } catch (e) {
561
- resolve(undefined)
572
+ resolve(undefined);
562
573
  }
563
-
564
- })
574
+ });
565
575
  if (!ticket) {
566
576
  throw exception.BadRequestError('BAD_REQUEST', 'Google Register Error', null);
567
577
  }
@@ -621,7 +631,7 @@ export class User {
621
631
  key: 'login_apple_setting',
622
632
  user_id: 'manager',
623
633
  });
624
- const private_key = config.secret
634
+ const private_key = config.secret;
625
635
  const client_secret = jwt.sign(
626
636
  {
627
637
  iss: config.team_id, // Team ID, should store in server side
@@ -638,15 +648,15 @@ export class User {
638
648
  kid: config.key_id, // Key ID, should store in a safe place on server side
639
649
  },
640
650
  }
641
- )
651
+ );
642
652
  const res = await axios
643
653
  .post('https://appleid.apple.com/auth/token', `client_id=${config.id}&client_secret=${client_secret}&code=${token}&grant_type=authorization_code`)
644
654
  .then((res) => res.data)
645
655
  .catch((e) => {
646
- console.log(e)
656
+ console.error(e);
647
657
  throw exception.BadRequestError('BAD_REQUEST', 'Verify False', null);
648
658
  });
649
- const decoded = jwt.decode(res['id_token'], {complete: true}) as unknown as {
659
+ const decoded = jwt.decode(res['id_token'], { complete: true }) as unknown as {
650
660
  payload: { sub: string; email: string };
651
661
  };
652
662
  const uid = decoded.payload.sub;
@@ -662,7 +672,6 @@ export class User {
662
672
  ) {
663
673
  const userID = User.generateUserID();
664
674
 
665
-
666
675
  await db.execute(
667
676
  `INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
668
677
  VALUES (?, ?, ?, ?, ?);`,
@@ -674,8 +683,8 @@ export class User {
674
683
  email: decoded.payload.email,
675
684
  name: (() => {
676
685
  const email = decoded.payload.email;
677
- return email.substring(0, email.indexOf('@'))
678
- })()
686
+ return email.substring(0, email.indexOf('@'));
687
+ })(),
679
688
  },
680
689
  1,
681
690
  ]
@@ -691,14 +700,14 @@ export class User {
691
700
  [decoded.payload.email]
692
701
  )) as any
693
702
  )[0];
694
- data.userData["apple-id"] = uid;
695
- await db.execute(`update \`${this.app}\`.t_user
703
+ data.userData['apple-id'] = uid;
704
+ await db.execute(
705
+ `update \`${this.app}\`.t_user
696
706
  set userData=?
697
707
  where userID = ?
698
- and id > 0`, [
699
- JSON.stringify(data.userData),
700
- data.userID
701
- ]);
708
+ and id > 0`,
709
+ [JSON.stringify(data.userData), data.userID]
710
+ );
702
711
  const usData: any = await this.getUserData(data.userID, 'userID');
703
712
  usData.pwd = undefined;
704
713
  usData.token = await UserUtil.generateToken({
@@ -706,7 +715,7 @@ export class User {
706
715
  account: usData['account'],
707
716
  userData: {},
708
717
  });
709
- return usData
718
+ return usData;
710
719
  } catch (e) {
711
720
  throw exception.BadRequestError('BAD_REQUEST', e as any, null);
712
721
  }
@@ -734,8 +743,8 @@ export class User {
734
743
  await new CustomCode(this.app).loginHook(cf);
735
744
  if (data) {
736
745
  data.pwd = undefined;
737
- data.member = await this.checkMember(data, false);
738
- const userLevel = (await this.getUserLevel([{userId: data.userID}]))[0];
746
+ data.member = await this.checkMember(data, true);
747
+ const userLevel = (await this.getUserLevel([{ userId: data.userID }]))[0];
739
748
  data.member_level = userLevel.data;
740
749
  data.member_level_status = userLevel.status;
741
750
  const n = data.member.findIndex((item: { id: string; trigger: boolean }) => {
@@ -761,11 +770,16 @@ export class User {
761
770
  }
762
771
  }
763
772
 
764
- public async checkMember(userData: any, trigger: boolean): Promise<{
765
- id: string;
766
- tag_name: string;
773
+ public async checkMember(
774
+ userData: any,
767
775
  trigger: boolean
768
- }[]> {
776
+ ): Promise<
777
+ {
778
+ id: string;
779
+ tag_name: string;
780
+ trigger: boolean;
781
+ }[]
782
+ > {
769
783
  const member_update = await this.getConfigV2({
770
784
  key: 'member_update',
771
785
  user_id: userData.userID,
@@ -786,19 +800,20 @@ export class User {
786
800
  await db.query(
787
801
  `SELECT orderData ->> '$.total' as total, created_time
788
802
  FROM \`${this.app}\`.t_checkout
789
- where email in (${[userData.userData.email, userData.userData.phone].filter((dd) => {
790
- return dd
791
- }).map((
792
- dd
793
- ) => {
794
- return db.escape(dd)
795
- }).join(',')})
803
+ where email in (${[userData.userData.email, userData.userData.phone]
804
+ .filter((dd) => {
805
+ return dd;
806
+ })
807
+ .map((dd) => {
808
+ return db.escape(dd);
809
+ })
810
+ .join(',')})
796
811
  and status = 1
797
812
  order by id desc`,
798
813
  []
799
814
  )
800
815
  ).map((dd: any) => {
801
- return {total_amount: parseInt(`${dd.total}`, 10), date: dd.created_time};
816
+ return { total_amount: parseInt(`${dd.total}`, 10), date: dd.created_time };
802
817
  });
803
818
 
804
819
  // 判斷是否符合上個等級
@@ -1125,7 +1140,7 @@ export class User {
1125
1140
  userID: -(index + 1),
1126
1141
  email: user.email,
1127
1142
  account: user.email,
1128
- userData: {email: user.email},
1143
+ userData: { email: user.email },
1129
1144
  status: 1,
1130
1145
  });
1131
1146
  }
@@ -1133,13 +1148,13 @@ export class User {
1133
1148
 
1134
1149
  const ids = query.id
1135
1150
  ? query.id.split(',').filter((id) => {
1136
- return users.find((item) => {
1137
- return item.userID === parseInt(`${id}`, 10);
1138
- });
1139
- })
1140
- : users.map((item: { userID: number }) => item.userID);
1141
- // @ts-ignore
1142
- query.id = ids.filter((id: any) => id).join(',');
1151
+ return users.find((item) => {
1152
+ return item.userID === parseInt(`${id}`, 10);
1153
+ });
1154
+ })
1155
+ : users.map((item: { userID: number }) => item.userID).filter((item) => item);
1156
+
1157
+ query.id = ids.length > 0 ? ids.filter((id) => id).join(',') : '0,0';
1143
1158
  } else {
1144
1159
  query.id = '0,0';
1145
1160
  }
@@ -1158,10 +1173,10 @@ export class User {
1158
1173
  if (rebateData && rebateData.total > 0) {
1159
1174
  const ids = query.id
1160
1175
  ? query.id.split(',').filter((id) => {
1161
- return rebateData.data.find((item) => {
1162
- return item.user_id === parseInt(`${id}`, 10);
1163
- });
1164
- })
1176
+ return rebateData.data.find((item) => {
1177
+ return item.user_id === parseInt(`${id}`, 10);
1178
+ });
1179
+ })
1165
1180
  : rebateData.data.map((item) => item.user_id);
1166
1181
  query.id = ids.join(',');
1167
1182
  } else {
@@ -1182,10 +1197,10 @@ export class User {
1182
1197
  if (levelIds.length > 0) {
1183
1198
  const ids = query.id
1184
1199
  ? query.id.split(',').filter((id) => {
1185
- return levelIds.find((item) => {
1186
- return item === parseInt(`${id}`, 10);
1187
- });
1188
- })
1200
+ return levelIds.find((item) => {
1201
+ return item === parseInt(`${id}`, 10);
1202
+ });
1203
+ })
1189
1204
  : levelIds;
1190
1205
  query.id = ids.join(',');
1191
1206
  } else {
@@ -1287,9 +1302,9 @@ export class User {
1287
1302
  ): Promise<
1288
1303
  | { result: false }
1289
1304
  | {
1290
- result: true;
1291
- data: GroupsItem[];
1292
- }
1305
+ result: true;
1306
+ data: GroupsItem[];
1307
+ }
1293
1308
  > {
1294
1309
  try {
1295
1310
  const pass = (text: string) => type === undefined || type.includes(text);
@@ -1304,7 +1319,7 @@ export class User {
1304
1319
  \`${this.app}\`.t_user AS u ON s.email = JSON_EXTRACT(u.userData, '$.email');`,
1305
1320
  []
1306
1321
  );
1307
- dataList.push({type: 'subscriber', title: '電子郵件訂閱者', users: subscriberList});
1322
+ dataList.push({ type: 'subscriber', title: '電子郵件訂閱者', users: subscriberList });
1308
1323
  }
1309
1324
 
1310
1325
  // 購買者清單
@@ -1321,7 +1336,7 @@ export class User {
1321
1336
  buyingData.map((item1: { userID: number; email: string }) => {
1322
1337
  const index = buyingList.findIndex((item2) => item2.userID === item1.userID);
1323
1338
  if (index === -1) {
1324
- buyingList.push({userID: item1.userID, email: item1.email, count: 1});
1339
+ buyingList.push({ userID: item1.userID, email: item1.email, count: 1 });
1325
1340
  } else {
1326
1341
  buyingList[index].count++;
1327
1342
  }
@@ -1335,15 +1350,15 @@ export class User {
1335
1350
  `SELECT userID, JSON_UNQUOTE(JSON_EXTRACT(userData, '$.email')) AS email
1336
1351
  FROM \`${this.app}\`.t_user
1337
1352
  WHERE userID not in (${buyingList
1338
- .map((item) => item.userID)
1339
- .concat([-1312])
1340
- .join(',')})`,
1353
+ .map((item) => item.userID)
1354
+ .concat([-1312])
1355
+ .join(',')})`,
1341
1356
  []
1342
1357
  );
1343
1358
 
1344
1359
  dataList = dataList.concat([
1345
- {type: 'neverBuying', title: '尚未購買過的顧客', users: neverBuyingData},
1346
- {type: 'usuallyBuying', title: '已購買多次的顧客', users: usuallyBuyingList},
1360
+ { type: 'neverBuying', title: '尚未購買過的顧客', users: neverBuyingData },
1361
+ { type: 'usuallyBuying', title: '已購買多次的顧客', users: usuallyBuyingList },
1347
1362
  ]);
1348
1363
  }
1349
1364
 
@@ -1352,7 +1367,7 @@ export class User {
1352
1367
  const levelData = await this.getLevelConfig();
1353
1368
  const levels = levelData
1354
1369
  .map((item: any) => {
1355
- return {id: item.id, name: item.tag_name};
1370
+ return { id: item.id, name: item.tag_name };
1356
1371
  })
1357
1372
  .filter((item: any) => {
1358
1373
  return tag ? item.id === tag : true;
@@ -1375,7 +1390,7 @@ export class User {
1375
1390
 
1376
1391
  const levelItems = await this.getUserLevel(
1377
1392
  users.map((item: { userID: number }) => {
1378
- return {userId: item.userID};
1393
+ return { userId: item.userID };
1379
1394
  })
1380
1395
  );
1381
1396
  for (const levelItem of levelItems) {
@@ -1409,15 +1424,15 @@ export class User {
1409
1424
 
1410
1425
  public normalMember = {
1411
1426
  id: '',
1412
- duration: {type: 'noLimit', value: 0},
1427
+ duration: { type: 'noLimit', value: 0 },
1413
1428
  tag_name: '一般會員',
1414
- condition: {type: 'total', value: 0},
1415
- dead_line: {type: 'noLimit'},
1429
+ condition: { type: 'total', value: 0 },
1430
+ dead_line: { type: 'noLimit' },
1416
1431
  create_date: '2024-01-01T00:00:00.000Z',
1417
1432
  };
1418
1433
 
1419
1434
  public async getLevelConfig() {
1420
- const levelData = await this.getConfigV2({key: 'member_level_config', user_id: 'manager'});
1435
+ const levelData = await this.getConfigV2({ key: 'member_level_config', user_id: 'manager' });
1421
1436
  const levelList = levelData.levels || [];
1422
1437
  levelList.push(this.normalMember);
1423
1438
  return levelList;
@@ -1621,7 +1636,7 @@ export class User {
1621
1636
  query.limit = query.limit ?? 50;
1622
1637
  const querySql: any = [];
1623
1638
  query.search &&
1624
- querySql.push([`(userID in (select userID from \`${this.app}\`.t_user where (UPPER(JSON_UNQUOTE(JSON_EXTRACT(userData, '$.name')) LIKE UPPER('%${query.search}%')))))`].join(` || `));
1639
+ querySql.push([`(userID in (select userID from \`${this.app}\`.t_user where (UPPER(JSON_UNQUOTE(JSON_EXTRACT(userData, '$.name')) LIKE UPPER('%${query.search}%')))))`].join(` || `));
1625
1640
  const data = await new UtDatabase(this.app, `t_fcm`).querySql(querySql, query as any);
1626
1641
  for (const b of data.data) {
1627
1642
  let userData = (
@@ -1640,17 +1655,17 @@ export class User {
1640
1655
  }
1641
1656
  }
1642
1657
 
1643
- public async deleteUser(query: { id?: string,email?:string }) {
1658
+ public async deleteUser(query: { id?: string; email?: string }) {
1644
1659
  try {
1645
1660
  //確保單一進來的元素不會被解析成字串
1646
- if(query.id){
1661
+ if (query.id) {
1647
1662
  await db.query(
1648
1663
  `delete
1649
1664
  FROM \`${this.app}\`.t_user
1650
1665
  where id in (?)`,
1651
1666
  [query.id.split(',')]
1652
1667
  );
1653
- }else if(query.email){
1668
+ } else if (query.email) {
1654
1669
  await db.query(
1655
1670
  `delete
1656
1671
  FROM \`${this.app}\`.t_user
@@ -1684,43 +1699,59 @@ export class User {
1684
1699
  key: 'custom_form_register',
1685
1700
  user_id: 'manager',
1686
1701
  });
1687
- register_form.list = register_form.list ?? []
1688
- FormCheck.initialRegisterForm(register_form.list)
1689
- if (par.userData.email && (par.userData.email !== userData.userData.email)) {
1690
- const count = (await db.query(`select count(1)
1702
+ register_form.list = register_form.list ?? [];
1703
+ FormCheck.initialRegisterForm(register_form.list);
1704
+ if (par.userData.email && par.userData.email !== userData.userData.email) {
1705
+ const count = (
1706
+ await db.query(
1707
+ `select count(1)
1691
1708
  from \`${this.app}\`.\`t_user\`
1692
1709
  where (userData ->>'$.email' = ${db.escape(par.userData.email)})
1693
- and (userID != ${db.escape(userID)}) `, []))[0]['count(1)']
1710
+ and (userID != ${db.escape(userID)}) `,
1711
+ []
1712
+ )
1713
+ )[0]['count(1)'];
1694
1714
  if (count) {
1695
1715
  throw exception.BadRequestError('BAD_REQUEST', 'Already exists.', {
1696
- msg: 'email-exists'
1716
+ msg: 'email-exists',
1697
1717
  });
1698
1718
  }
1699
- if (login_config.email_verify && (par.userData.verify_code !== (await redis.getValue(`verify-${par.userData.email}`)))
1700
- && register_form.list.find((dd: any) => {
1701
- return dd.key === 'email' && `${dd.hidden}` !== 'true'
1719
+ if (
1720
+ login_config.email_verify &&
1721
+ par.userData.verify_code !== (await redis.getValue(`verify-${par.userData.email}`)) &&
1722
+ register_form.list.find((dd: any) => {
1723
+ return dd.key === 'email' && `${dd.hidden}` !== 'true';
1702
1724
  })
1703
1725
  ) {
1704
1726
  throw exception.BadRequestError('BAD_REQUEST', 'Verify code error.', {
1705
- msg: 'email-verify-false'
1727
+ msg: 'email-verify-false',
1706
1728
  });
1707
1729
  }
1708
1730
  }
1709
- if (par.userData.phone && (par.userData.phone !== userData.userData.phone)) {
1710
- const count = (await db.query(`select count(1)
1731
+ if (par.userData.phone && par.userData.phone !== userData.userData.phone) {
1732
+ const count = (
1733
+ await db.query(
1734
+ `select count(1)
1711
1735
  from \`${this.app}\`.\`t_user\`
1712
1736
  where (userData ->>'$.phone' = ${db.escape(par.userData.phone)})
1713
- and (userID != ${db.escape(userID)}) `, []))[0]['count(1)']
1737
+ and (userID != ${db.escape(userID)}) `,
1738
+ []
1739
+ )
1740
+ )[0]['count(1)'];
1714
1741
  if (count) {
1715
1742
  throw exception.BadRequestError('BAD_REQUEST', 'Already exists.', {
1716
- msg: 'phone-exists'
1743
+ msg: 'phone-exists',
1717
1744
  });
1718
1745
  }
1719
- if (login_config.phone_verify && (par.userData.verify_code_phone !== (await redis.getValue(`verify-phone-${par.userData.phone}`))) && register_form.list.find((dd: any) => {
1720
- return dd.key === 'phone' && `${dd.hidden}` !== 'true'
1721
- })) {
1746
+ if (
1747
+ login_config.phone_verify &&
1748
+ par.userData.verify_code_phone !== (await redis.getValue(`verify-phone-${par.userData.phone}`)) &&
1749
+ register_form.list.find((dd: any) => {
1750
+ return dd.key === 'phone' && `${dd.hidden}` !== 'true';
1751
+ })
1752
+ ) {
1722
1753
  throw exception.BadRequestError('BAD_REQUEST', 'Verify code error.', {
1723
- msg: 'phone-verify-false'
1754
+ msg: 'phone-verify-false',
1724
1755
  });
1725
1756
  }
1726
1757
  }
@@ -1734,7 +1765,7 @@ export class User {
1734
1765
  and email = ?`,
1735
1766
  [par.userData.phone, `${userData.userData.phone}`]
1736
1767
  );
1737
- userData.account = par.userData.phone
1768
+ userData.account = par.userData.phone;
1738
1769
  }
1739
1770
  if (par.userData.email) {
1740
1771
  await db.query(
@@ -1744,7 +1775,7 @@ export class User {
1744
1775
  and email = ?`,
1745
1776
  [par.userData.email, `${userData.userData.email}`]
1746
1777
  );
1747
- userData.account = par.userData.email
1778
+ userData.account = par.userData.email;
1748
1779
  }
1749
1780
  par.userData = await this.checkUpdate({
1750
1781
  updateUserData: par.userData,
@@ -1784,7 +1815,7 @@ export class User {
1784
1815
  user_id: 'manager',
1785
1816
  })
1786
1817
  ).list ?? [];
1787
- FormCheck.initialRegisterForm(register_form)
1818
+ FormCheck.initialRegisterForm(register_form);
1788
1819
  let customer_form_user_setting =
1789
1820
  (
1790
1821
  await this.getConfigV2({
@@ -1945,7 +1976,8 @@ export class User {
1945
1976
 
1946
1977
  public async checkMailAndPhoneExists(email?: string, phone?: string) {
1947
1978
  try {
1948
- const emailExists = email && (
1979
+ const emailExists =
1980
+ email &&
1949
1981
  (
1950
1982
  (await db.execute(
1951
1983
  `select count(1)
@@ -1953,9 +1985,9 @@ export class User {
1953
1985
  where userData ->>'$.email'=?`,
1954
1986
  [email]
1955
1987
  )) as any
1956
- )[0]['count(1)'] > 0
1957
- )
1958
- const phoneExists = phone && (
1988
+ )[0]['count(1)'] > 0;
1989
+ const phoneExists =
1990
+ phone &&
1959
1991
  (
1960
1992
  (await db.execute(
1961
1993
  `select count(1)
@@ -1963,8 +1995,7 @@ export class User {
1963
1995
  where userData ->>'$.phone'=?`,
1964
1996
  [phone]
1965
1997
  )) as any
1966
- )[0]['count(1)'] > 0
1967
- )
1998
+ )[0]['count(1)'] > 0;
1968
1999
  return emailExists || phoneExists;
1969
2000
  } catch (e) {
1970
2001
  throw exception.BadRequestError('BAD_REQUEST', 'CheckUserExists Error:' + e, null);
@@ -2052,18 +2083,18 @@ export class User {
2052
2083
  `,
2053
2084
  []
2054
2085
  );
2055
- if ((!data[0]) && config.user_id === 'manager') {
2086
+ if (!data[0] && config.user_id === 'manager') {
2056
2087
  //特定Key沒有值要補值進去
2057
2088
  switch (config.key) {
2058
- case "member_level_config":
2089
+ case 'member_level_config':
2059
2090
  await this.setConfig({
2060
2091
  key: config.key,
2061
2092
  user_id: config.user_id,
2062
2093
  value: {
2063
- "levels": []
2064
- }
2065
- })
2066
- return await this.getConfigV2(config)
2094
+ levels: [],
2095
+ },
2096
+ });
2097
+ return await this.getConfigV2(config);
2067
2098
  }
2068
2099
  }
2069
2100
  return (data[0] && data[0].value) || {};
@@ -2128,8 +2159,7 @@ export class User {
2128
2159
  return {
2129
2160
  result: result[0]['count(1)'] === 1,
2130
2161
  };
2131
- } catch (e) {
2132
- }
2162
+ } catch (e) {}
2133
2163
  }
2134
2164
 
2135
2165
  public async getNotice(cf: { query: any }) {
@@ -2147,7 +2177,7 @@ export class User {
2147
2177
  await db.query(
2148
2178
  `insert into \`${this.app}\`.t_user_public_config (user_id, \`key\`, value, updated_at)
2149
2179
  values (?, ?, ?, ?)`,
2150
- [this.token?.userID, 'notice_last_read', JSON.stringify({time: new Date()}), new Date()]
2180
+ [this.token?.userID, 'notice_last_read', JSON.stringify({ time: new Date() }), new Date()]
2151
2181
  );
2152
2182
  } else {
2153
2183
  last_time_read = new Date(last_read_time[0].value.time).getTime();
@@ -2156,7 +2186,7 @@ export class User {
2156
2186
  set \`value\`=?
2157
2187
  where user_id = ?
2158
2188
  and \`key\` = ?`,
2159
- [JSON.stringify({time: new Date()}), `${this.token?.userID}`, 'notice_last_read']
2189
+ [JSON.stringify({ time: new Date() }), `${this.token?.userID}`, 'notice_last_read']
2160
2190
  );
2161
2191
  }
2162
2192
  const response: any = await new UtDatabase(this.app, `t_notice`).querySql(query, cf.query);