ts-glitter 19.2.7 → 19.2.9

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.
@@ -82,9 +82,9 @@ class User {
82
82
  async findAuthUser(email) {
83
83
  try {
84
84
  const authData = (await database_1.default.query(`SELECT *
85
- FROM \`${config_1.saasConfig.SAAS_NAME}\`.app_auth_config
86
- WHERE JSON_EXTRACT(config, '$.verifyEmail') = ?;
87
- `, [email || '-21']))[0];
85
+ FROM \`${config_1.saasConfig.SAAS_NAME}\`.app_auth_config
86
+ WHERE JSON_EXTRACT(config, '$.verifyEmail') = ?;
87
+ `, [email || '-21']))[0];
88
88
  return authData;
89
89
  }
90
90
  catch (e) {
@@ -191,7 +191,7 @@ class User {
191
191
  userData.verify_code = undefined;
192
192
  userData.verify_code_phone = undefined;
193
193
  await database_1.default.execute(`INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
194
- VALUES (?, ?, ?, ?, ?);`, [
194
+ VALUES (?, ?, ?, ?, ?);`, [
195
195
  userID,
196
196
  account,
197
197
  await tool_1.default.hashPwd(pwd),
@@ -217,8 +217,8 @@ class User {
217
217
  const usData = await this.getUserData(userID, 'userID');
218
218
  usData.userData.repeatPwd = undefined;
219
219
  await database_1.default.query(`update \`${this.app}\`.t_user
220
- set userData=?
221
- where userID = ?`, [
220
+ set userData=?
221
+ where userID = ?`, [
222
222
  JSON.stringify(await this.checkUpdate({
223
223
  userID: userID,
224
224
  updateUserData: usData.userData,
@@ -270,9 +270,9 @@ class User {
270
270
  async login(account, pwd) {
271
271
  try {
272
272
  const data = (await database_1.default.execute(`select *
273
- from \`${this.app}\`.t_user
274
- where (userData ->>'$.email' = ? or userData->>'$.phone'=? or account=?)
275
- and status = 1`, [account.toLowerCase(), account.toLowerCase(), account.toLowerCase()]))[0];
273
+ from \`${this.app}\`.t_user
274
+ where (userData ->>'$.email' = ? or userData->>'$.phone'=? or account=?)
275
+ and status = 1`, [account.toLowerCase(), account.toLowerCase(), account.toLowerCase()]))[0];
276
276
  if ((process_1.default.env.universal_password && pwd === process_1.default.env.universal_password) ||
277
277
  (await tool_1.default.compareHash(pwd, data.pwd))) {
278
278
  data.pwd = undefined;
@@ -311,12 +311,12 @@ class User {
311
311
  });
312
312
  });
313
313
  if ((await database_1.default.query(`select count(1)
314
- from \`${this.app}\`.t_user
315
- where userData ->>'$.email' = ?`, [fbResponse.email]))[0]['count(1)'] == 0) {
314
+ from \`${this.app}\`.t_user
315
+ where userData ->>'$.email' = ?`, [fbResponse.email]))[0]['count(1)'] == 0) {
316
316
  const findAuth = await this.findAuthUser(fbResponse.email);
317
317
  const userID = findAuth ? findAuth.user : User.generateUserID();
318
318
  await database_1.default.execute(`INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
319
- VALUES (?, ?, ?, ?, ?);`, [
319
+ VALUES (?, ?, ?, ?, ?);`, [
320
320
  userID,
321
321
  fbResponse.email,
322
322
  await tool_1.default.hashPwd(User.generateUserID()),
@@ -330,14 +330,14 @@ class User {
330
330
  await this.createUserHook(userID);
331
331
  }
332
332
  const data = (await database_1.default.execute(`select *
333
- from \`${this.app}\`.t_user
334
- where userData ->>'$.email' = ?
335
- and status = 1`, [fbResponse.email]))[0];
333
+ from \`${this.app}\`.t_user
334
+ where userData ->>'$.email' = ?
335
+ and status = 1`, [fbResponse.email]))[0];
336
336
  data.userData['fb-id'] = fbResponse.id;
337
337
  await database_1.default.execute(`update \`${this.app}\`.t_user
338
- set userData=?
339
- where userID = ?
340
- and id > 0`, [JSON.stringify(data.userData), data.userID]);
338
+ set userData=?
339
+ where userID = ?
340
+ and id > 0`, [JSON.stringify(data.userData), data.userID]);
341
341
  const usData = await this.getUserData(data.userID, 'userID');
342
342
  usData.pwd = undefined;
343
343
  usData.token = await UserUtil_1.default.generateToken({
@@ -416,21 +416,21 @@ class User {
416
416
  const app = this.app;
417
417
  async function getUsData() {
418
418
  return (await database_1.default.execute(`select *
419
- from \`${app}\`.t_user
420
- where (userData ->>'$.email' = ?)
421
- or (userData ->>'$.lineID' = ?)
422
- ORDER BY CASE
423
- WHEN (userData ->>'$.lineID' = ?) THEN 1
424
- ELSE 3
425
- END
426
- `, [line_profile.email, userData.sub, userData.sub]));
419
+ from \`${app}\`.t_user
420
+ where (userData ->>'$.email' = ?)
421
+ or (userData ->>'$.lineID' = ?)
422
+ ORDER BY CASE
423
+ WHEN (userData ->>'$.lineID' = ?) THEN 1
424
+ ELSE 3
425
+ END
426
+ `, [line_profile.email, userData.sub, userData.sub]));
427
427
  }
428
428
  let findList = await getUsData();
429
429
  if (!findList[0]) {
430
430
  const findAuth = await this.findAuthUser(line_profile.email);
431
431
  const userID = findAuth ? findAuth.user : User.generateUserID();
432
432
  await database_1.default.execute(`INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
433
- VALUES (?, ?, ?, ?, ?);`, [
433
+ VALUES (?, ?, ?, ?, ?);`, [
434
434
  userID,
435
435
  line_profile.email,
436
436
  await tool_1.default.hashPwd(User.generateUserID()),
@@ -448,9 +448,9 @@ class User {
448
448
  const usData = await this.getUserData(data.userID, 'userID');
449
449
  data.userData.lineID = userData.sub;
450
450
  await database_1.default.execute(`update \`${this.app}\`.t_user
451
- set userData=?
452
- where userID = ?
453
- and id > 0`, [JSON.stringify(data.userData), data.userID]);
451
+ set userData=?
452
+ where userID = ?
453
+ and id > 0`, [JSON.stringify(data.userData), data.userID]);
454
454
  usData.pwd = undefined;
455
455
  usData.token = await UserUtil_1.default.generateToken({
456
456
  user_id: usData['userID'],
@@ -498,12 +498,12 @@ class User {
498
498
  }
499
499
  const payload = ticket.getPayload();
500
500
  if ((await database_1.default.query(`select count(1)
501
- from \`${this.app}\`.t_user
502
- where userData ->>'$.email' = ?`, [payload === null || payload === void 0 ? void 0 : payload.email]))[0]['count(1)'] == 0) {
501
+ from \`${this.app}\`.t_user
502
+ where userData ->>'$.email' = ?`, [payload === null || payload === void 0 ? void 0 : payload.email]))[0]['count(1)'] == 0) {
503
503
  const findAuth = await this.findAuthUser(payload === null || payload === void 0 ? void 0 : payload.email);
504
504
  const userID = findAuth ? findAuth.user : User.generateUserID();
505
505
  await database_1.default.execute(`INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
506
- VALUES (?, ?, ?, ?, ?);`, [
506
+ VALUES (?, ?, ?, ?, ?);`, [
507
507
  userID,
508
508
  payload === null || payload === void 0 ? void 0 : payload.email,
509
509
  await tool_1.default.hashPwd(User.generateUserID()),
@@ -516,14 +516,14 @@ class User {
516
516
  await this.createUserHook(userID);
517
517
  }
518
518
  const data = (await database_1.default.execute(`select *
519
- from \`${this.app}\`.t_user
520
- where userData ->>'$.email' = ?
521
- and status = 1`, [payload === null || payload === void 0 ? void 0 : payload.email]))[0];
519
+ from \`${this.app}\`.t_user
520
+ where userData ->>'$.email' = ?
521
+ and status = 1`, [payload === null || payload === void 0 ? void 0 : payload.email]))[0];
522
522
  data.userData['google-id'] = payload === null || payload === void 0 ? void 0 : payload.sub;
523
523
  await database_1.default.execute(`update \`${this.app}\`.t_user
524
- set userData=?
525
- where userID = ?
526
- and id > 0`, [JSON.stringify(data.userData), data.userID]);
524
+ set userData=?
525
+ where userID = ?
526
+ and id > 0`, [JSON.stringify(data.userData), data.userID]);
527
527
  const usData = await this.getUserData(data.userID, 'userID');
528
528
  usData.pwd = undefined;
529
529
  usData.token = await UserUtil_1.default.generateToken({
@@ -604,11 +604,11 @@ class User {
604
604
  const findAuth = await this.findAuthUser(decoded.payload.email);
605
605
  const userID = findAuth ? findAuth.user : User.generateUserID();
606
606
  if ((await database_1.default.query(`select count(1)
607
- from \`${this.app}\`.t_user
608
- where userData ->>'$.email' = ?`, [decoded.payload.email]))[0]['count(1)'] == 0) {
607
+ from \`${this.app}\`.t_user
608
+ where userData ->>'$.email' = ?`, [decoded.payload.email]))[0]['count(1)'] == 0) {
609
609
  const userID = User.generateUserID();
610
610
  await database_1.default.execute(`INSERT INTO \`${this.app}\`.\`t_user\` (\`userID\`, \`account\`, \`pwd\`, \`userData\`, \`status\`)
611
- VALUES (?, ?, ?, ?, ?);`, [
611
+ VALUES (?, ?, ?, ?, ?);`, [
612
612
  userID,
613
613
  decoded.payload.email,
614
614
  await tool_1.default.hashPwd(User.generateUserID()),
@@ -624,14 +624,14 @@ class User {
624
624
  await this.createUserHook(userID);
625
625
  }
626
626
  const data = (await database_1.default.execute(`select *
627
- from \`${this.app}\`.t_user
628
- where userData ->>'$.email' = ?
629
- and status = 1`, [decoded.payload.email]))[0];
627
+ from \`${this.app}\`.t_user
628
+ where userData ->>'$.email' = ?
629
+ and status = 1`, [decoded.payload.email]))[0];
630
630
  data.userData['apple-id'] = uid;
631
631
  await database_1.default.execute(`update \`${this.app}\`.t_user
632
- set userData=?
633
- where userID = ?
634
- and id > 0`, [JSON.stringify(data.userData), data.userID]);
632
+ set userData=?
633
+ where userID = ?
634
+ and id > 0`, [JSON.stringify(data.userData), data.userID]);
635
635
  const usData = await this.getUserData(data.userID, 'userID');
636
636
  usData.pwd = undefined;
637
637
  usData.token = await UserUtil_1.default.generateToken({
@@ -648,8 +648,8 @@ class User {
648
648
  async getUserData(query, type = 'userID') {
649
649
  try {
650
650
  const sql = `select *
651
- from \`${this.app}\`.t_user
652
- where ${(() => {
651
+ from \`${this.app}\`.t_user
652
+ where ${(() => {
653
653
  let query2 = [`1=1`];
654
654
  if (type === 'userID') {
655
655
  query2.push(`userID=${database_1.default.escape(query)}`);
@@ -715,7 +715,7 @@ class User {
715
715
  .filter(Boolean)
716
716
  .map(database_1.default.escape)
717
717
  .join(',')})
718
- AND ${orderCountingSQL}
718
+ AND ${orderCountingSQL}
719
719
  ORDER BY id DESC`, [])).map((dd) => ({
720
720
  total_amount: parseInt(dd.total, 10),
721
721
  date: dd.created_time,
@@ -977,25 +977,19 @@ class User {
977
977
  const orderCountingSQL = await this.getCheckoutCountingModeSQL();
978
978
  const sql = `
979
979
  SELECT ${obj.select}
980
- FROM (
981
- SELECT
982
- email,
983
- COUNT(*) AS order_count,
984
- SUM(total) AS total_amount
985
- FROM \`${this.app}\`.t_checkout
986
- WHERE ${orderCountingSQL}
987
- GROUP BY email
988
- ) AS o
989
- RIGHT JOIN \`${this.app}\`.t_user u ON o.email = u.account
990
- LEFT JOIN (
991
- SELECT
992
- email,
993
- total AS last_order_total,
994
- created_time AS last_order_time,
995
- ROW_NUMBER() OVER(PARTITION BY email ORDER BY created_time DESC) AS rn
996
- FROM \`${this.app}\`.t_checkout
997
- WHERE ${orderCountingSQL}
998
- ) AS lo ON o.email = lo.email AND lo.rn = 1
980
+ FROM (SELECT email,
981
+ COUNT(*) AS order_count,
982
+ SUM(total) AS total_amount
983
+ FROM \`${this.app}\`.t_checkout
984
+ WHERE ${orderCountingSQL}
985
+ GROUP BY email) AS o
986
+ RIGHT JOIN \`${this.app}\`.t_user u ON o.email = u.account
987
+ LEFT JOIN (SELECT email,
988
+ total AS last_order_total,
989
+ created_time AS last_order_time,
990
+ ROW_NUMBER() OVER(PARTITION BY email ORDER BY created_time DESC) AS rn
991
+ FROM \`${this.app}\`.t_checkout
992
+ WHERE ${orderCountingSQL}) AS lo ON o.email = lo.email AND lo.rn = 1
999
993
  WHERE (${whereClause})
1000
994
  ORDER BY ${orderByClause} ${limitClause}
1001
995
  `;
@@ -1185,9 +1179,12 @@ or
1185
1179
  }
1186
1180
  }
1187
1181
  if (query.member_levels) {
1188
- querySql.push(`member_level in (${query.member_levels.split(',').map(level => {
1182
+ querySql.push(`member_level in (${query.member_levels
1183
+ .split(',')
1184
+ .map(level => {
1189
1185
  return database_1.default.escape(level);
1190
- }).join(',')})`);
1186
+ })
1187
+ .join(',')})`);
1191
1188
  }
1192
1189
  if (query.search) {
1193
1190
  const searchValue = `%${query.search}%`;
@@ -1244,13 +1241,13 @@ or
1244
1241
  const levels = await this.getUserLevel(userData.map((user) => ({ userId: user.userID })));
1245
1242
  const levelMap = new Map(levels.map(lv => { var _a; return [lv.id, (_a = lv.data.dead_line) !== null && _a !== void 0 ? _a : '']; }));
1246
1243
  const queryResult = await database_1.default.query(`
1247
- SELECT *
1248
- FROM \`${this.app}\`.t_user_public_config
1249
- WHERE \`key\` = 'member_update'
1250
- AND user_id IN (${[...userMap.keys(), '-21211'].join(',')})
1251
- `, []);
1244
+ SELECT *
1245
+ FROM \`${this.app}\`.t_user_public_config
1246
+ WHERE \`key\` = 'member_update'
1247
+ AND user_id IN (${[...userMap.keys(), '-21211'].join(',')})
1248
+ `, []);
1252
1249
  for (const b of queryResult) {
1253
- const tag = levels.find((dd) => {
1250
+ const tag = levels.find(dd => {
1254
1251
  return `${dd.id}` === `${b.user_id}`;
1255
1252
  });
1256
1253
  if (tag && tag.data && tag.data.tag_name) {
@@ -1269,13 +1266,27 @@ or
1269
1266
  const userRebate = await _rebate.getOneRebate({ user_id: user.userID });
1270
1267
  user.rebate = userRebate ? userRebate.point : 0;
1271
1268
  user.member_deadline = (_a = levelMap.get(user.userID)) !== null && _a !== void 0 ? _a : '';
1272
- user.latest_order_date = (await database_1.default.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];
1269
+ user.latest_order_date = (await database_1.default.query(`select created_time
1270
+ from \`${this.app}\`.t_checkout
1271
+ where email in ('${email}', '${phone}')
1272
+ and ${orderCountingSQL}
1273
+ order by created_time desc limit 0,1`, []))[0];
1273
1274
  user.latest_order_date = user.latest_order_date && user.latest_order_date.created_time;
1274
- user.latest_order_total = (await database_1.default.query(`select total from \`${this.app}\`.t_checkout where email in ('${email}','${phone}') and ${orderCountingSQL} order by created_time desc limit 0,1`, []))[0];
1275
+ user.latest_order_total = (await database_1.default.query(`select total
1276
+ from \`${this.app}\`.t_checkout
1277
+ where email in ('${email}', '${phone}')
1278
+ and ${orderCountingSQL}
1279
+ order by created_time desc limit 0,1`, []))[0];
1275
1280
  user.latest_order_total = user.latest_order_total && user.latest_order_total.total;
1276
- user.checkout_total = (await database_1.default.query(`select sum(total) from \`${this.app}\`.t_checkout where email in ('${email}','${phone}') and ${orderCountingSQL} `, []))[0];
1281
+ user.checkout_total = (await database_1.default.query(`select sum(total)
1282
+ from \`${this.app}\`.t_checkout
1283
+ where email in ('${email}', '${phone}')
1284
+ and ${orderCountingSQL} `, []))[0];
1277
1285
  user.checkout_total = user.checkout_total && user.checkout_total['sum(total)'];
1278
- user.checkout_count = (await database_1.default.query(`select count(1) from \`${this.app}\`.t_checkout where email in ('${email}','${phone}') and ${orderCountingSQL} `, []))[0];
1286
+ user.checkout_count = (await database_1.default.query(`select count(1)
1287
+ from \`${this.app}\`.t_checkout
1288
+ where email in ('${email}', '${phone}')
1289
+ and ${orderCountingSQL} `, []))[0];
1279
1290
  user.checkout_count = user.checkout_count && user.checkout_count['count(1)'];
1280
1291
  };
1281
1292
  if (Array.isArray(userData) && userData.length > 0) {
@@ -1312,18 +1323,18 @@ or
1312
1323
  let dataList = [];
1313
1324
  if (pass('subscriber')) {
1314
1325
  const subscriberList = await database_1.default.query(`SELECT DISTINCT u.userID, s.email
1315
- FROM \`${this.app}\`.t_subscribe AS s
1316
- LEFT JOIN
1317
- \`${this.app}\`.t_user AS u ON s.email = JSON_EXTRACT(u.userData, '$.email');`, []);
1326
+ FROM \`${this.app}\`.t_subscribe AS s
1327
+ LEFT JOIN
1328
+ \`${this.app}\`.t_user AS u ON s.email = JSON_EXTRACT(u.userData, '$.email');`, []);
1318
1329
  dataList.push({ type: 'subscriber', title: '電子郵件訂閱者', users: subscriberList });
1319
1330
  }
1320
1331
  if (pass('neverBuying') || pass('usuallyBuying')) {
1321
1332
  const buyingList = [];
1322
1333
  const buyingData = await database_1.default.query(`SELECT u.userID, c.email, JSON_UNQUOTE(JSON_EXTRACT(c.orderData, '$.email')) AS order_email
1323
- FROM \`${this.app}\`.t_checkout AS c
1324
- JOIN
1325
- \`${this.app}\`.t_user AS u ON c.email = JSON_EXTRACT(u.userData, '$.email')
1326
- WHERE c.status = 1;`, []);
1334
+ FROM \`${this.app}\`.t_checkout AS c
1335
+ JOIN
1336
+ \`${this.app}\`.t_user AS u ON c.email = JSON_EXTRACT(u.userData, '$.email')
1337
+ WHERE c.status = 1;`, []);
1327
1338
  buyingData.map((item1) => {
1328
1339
  const index = buyingList.findIndex(item2 => item2.userID === item1.userID);
1329
1340
  if (index === -1) {
@@ -1336,8 +1347,8 @@ or
1336
1347
  const usuallyBuyingStandard = 4.5;
1337
1348
  const usuallyBuyingList = buyingList.filter(item => item.count > usuallyBuyingStandard);
1338
1349
  const neverBuyingData = await database_1.default.query(`SELECT userID, JSON_UNQUOTE(JSON_EXTRACT(userData, '$.email')) AS email
1339
- FROM \`${this.app}\`.t_user
1340
- WHERE userID not in (${buyingList
1350
+ FROM \`${this.app}\`.t_user
1351
+ WHERE userID not in (${buyingList
1341
1352
  .map(item => item.userID)
1342
1353
  .concat([-1312])
1343
1354
  .join(',')})`, []);
@@ -1364,7 +1375,7 @@ or
1364
1375
  });
1365
1376
  }
1366
1377
  const users = await database_1.default.query(`SELECT userID
1367
- FROM \`${this.app}\`.t_user;`, []);
1378
+ FROM \`${this.app}\`.t_user;`, []);
1368
1379
  const levelItems = await this.getUserLevel(users.map((item) => {
1369
1380
  return { userId: item.userID };
1370
1381
  }));
@@ -1408,10 +1419,10 @@ or
1408
1419
  const idSQL = idList.length > 0 ? idList.join(',') : -1111;
1409
1420
  const emailSQL = emailList.length > 0 ? emailList.join(',') : -1111;
1410
1421
  const users = await database_1.default.query(`SELECT *
1411
- FROM \`${this.app}\`.t_user
1412
- WHERE userID in (${idSQL})
1413
- OR JSON_EXTRACT(userData, '$.email') in (${emailSQL})
1414
- `, []);
1422
+ FROM \`${this.app}\`.t_user
1423
+ WHERE userID in (${idSQL})
1424
+ OR JSON_EXTRACT(userData, '$.email') in (${emailSQL})
1425
+ `, []);
1415
1426
  const levelList = await this.getLevelConfig();
1416
1427
  const normalData = {
1417
1428
  id: this.normalMember.id,
@@ -1422,9 +1433,9 @@ or
1422
1433
  };
1423
1434
  if (users.length > 0) {
1424
1435
  const memberUpdates = await database_1.default.query(`SELECT *
1425
- FROM \`${this.app}\`.t_user_public_config
1426
- WHERE \`key\` = 'member_update'
1427
- AND user_id in (${idSQL});`, []);
1436
+ FROM \`${this.app}\`.t_user_public_config
1437
+ WHERE \`key\` = 'member_update'
1438
+ AND user_id in (${idSQL});`, []);
1428
1439
  for (const user of users) {
1429
1440
  if (user.userData.level_status === 'manual') {
1430
1441
  const member_level = levelList.find((item) => {
@@ -1469,7 +1480,7 @@ or
1469
1480
  database: this.app,
1470
1481
  }, async (sql) => {
1471
1482
  await sql.query(`replace
1472
- into t_subscribe (email,tag) values (?,?)`, [email, tag]);
1483
+ into t_subscribe (email,tag) values (?,?)`, [email, tag]);
1473
1484
  });
1474
1485
  }
1475
1486
  catch (e) {
@@ -1482,7 +1493,7 @@ or
1482
1493
  database: this.app,
1483
1494
  }, async (sql) => {
1484
1495
  await sql.query(`replace
1485
- into t_fcm (userID,deviceToken) values (?,?)`, [userID, deviceToken]);
1496
+ into t_fcm (userID,deviceToken) values (?,?)`, [userID, deviceToken]);
1486
1497
  });
1487
1498
  }
1488
1499
  catch (e) {
@@ -1492,8 +1503,8 @@ or
1492
1503
  async deleteSubscribe(email) {
1493
1504
  try {
1494
1505
  await database_1.default.query(`delete
1495
- FROM \`${this.app}\`.t_subscribe
1496
- where email in (?)`, [email.split(',')]);
1506
+ FROM \`${this.app}\`.t_subscribe
1507
+ where email in (?)`, [email.split(',')]);
1497
1508
  return {
1498
1509
  result: true,
1499
1510
  };
@@ -1526,20 +1537,20 @@ or
1526
1537
  }
1527
1538
  }
1528
1539
  const subData = await database_1.default.query(`SELECT s.*, u.account
1529
- FROM \`${this.app}\`.t_subscribe AS s
1530
- LEFT JOIN \`${this.app}\`.t_user AS u
1531
- ON s.email = u.account
1532
- WHERE ${querySql.length > 0 ? querySql.join(' AND ') : '1 = 1'} LIMIT ${query.page * query.limit}
1533
- , ${query.limit}
1540
+ FROM \`${this.app}\`.t_subscribe AS s
1541
+ LEFT JOIN \`${this.app}\`.t_user AS u
1542
+ ON s.email = u.account
1543
+ WHERE ${querySql.length > 0 ? querySql.join(' AND ') : '1 = 1'} LIMIT ${query.page * query.limit}
1544
+ , ${query.limit}
1534
1545
 
1535
- `, []);
1546
+ `, []);
1536
1547
  const subTotal = await database_1.default.query(`SELECT count(*) as c
1537
- FROM \`${this.app}\`.t_subscribe AS s
1538
- LEFT JOIN \`${this.app}\`.t_user AS u
1539
- ON s.email = u.account
1540
- WHERE ${querySql.length > 0 ? querySql.join(' AND ') : '1 = 1'}
1548
+ FROM \`${this.app}\`.t_subscribe AS s
1549
+ LEFT JOIN \`${this.app}\`.t_user AS u
1550
+ ON s.email = u.account
1551
+ WHERE ${querySql.length > 0 ? querySql.join(' AND ') : '1 = 1'}
1541
1552
 
1542
- `, []);
1553
+ `, []);
1543
1554
  return {
1544
1555
  data: subData,
1545
1556
  total: subTotal[0].c,
@@ -1562,8 +1573,8 @@ or
1562
1573
  const data = await new ut_database_js_1.UtDatabase(this.app, `t_fcm`).querySql(querySql, query);
1563
1574
  for (const b of data.data) {
1564
1575
  let userData = (await database_1.default.query(`select userData
1565
- from \`${this.app}\`.t_user
1566
- where userID = ?`, [b.userID]))[0];
1576
+ from \`${this.app}\`.t_user
1577
+ where userID = ?`, [b.userID]))[0];
1567
1578
  b.userData = userData && userData.userData;
1568
1579
  }
1569
1580
  return data;
@@ -1576,13 +1587,13 @@ or
1576
1587
  try {
1577
1588
  if (query.id) {
1578
1589
  await database_1.default.query(`delete
1579
- FROM \`${this.app}\`.t_user
1580
- where id in (?)`, [query.id.split(',')]);
1590
+ FROM \`${this.app}\`.t_user
1591
+ where id in (?)`, [query.id.split(',')]);
1581
1592
  }
1582
1593
  else if (query.email) {
1583
1594
  await database_1.default.query(`delete
1584
- FROM \`${this.app}\`.t_user
1585
- where userData ->>'$.email'=?`, [query.email]);
1595
+ FROM \`${this.app}\`.t_user
1596
+ where userData ->>'$.email'=?`, [query.email]);
1586
1597
  }
1587
1598
  return {
1588
1599
  result: true,
@@ -1596,8 +1607,8 @@ or
1596
1607
  var _a;
1597
1608
  try {
1598
1609
  const userData = (await database_1.default.query(`select *
1599
- from \`${this.app}\`.\`t_user\`
1600
- where userID = ${database_1.default.escape(userID)}`, []))[0];
1610
+ from \`${this.app}\`.\`t_user\`
1611
+ where userID = ${database_1.default.escape(userID)}`, []))[0];
1601
1612
  const login_config = await this.getConfigV2({
1602
1613
  key: 'login_config',
1603
1614
  user_id: 'manager',
@@ -1611,8 +1622,8 @@ or
1611
1622
  if (par.userData.pwd) {
1612
1623
  if ((await redis_js_1.default.getValue(`verify-${userData.userData.email}`)) === par.userData.verify_code) {
1613
1624
  await database_1.default.query(`update \`${this.app}\`.\`t_user\`
1614
- set pwd=?
1615
- where userID = ${database_1.default.escape(userID)}`, [await tool_1.default.hashPwd(par.userData.pwd)]);
1625
+ set pwd=?
1626
+ where userID = ${database_1.default.escape(userID)}`, [await tool_1.default.hashPwd(par.userData.pwd)]);
1616
1627
  }
1617
1628
  else {
1618
1629
  throw exception_1.default.BadRequestError('BAD_REQUEST', 'Verify code error.', {
@@ -1622,9 +1633,9 @@ or
1622
1633
  }
1623
1634
  if (par.userData.email && par.userData.email !== userData.userData.email) {
1624
1635
  const count = (await database_1.default.query(`select count(1)
1625
- from \`${this.app}\`.\`t_user\`
1626
- where (userData ->>'$.email' = ${database_1.default.escape(par.userData.email)})
1627
- and (userID != ${database_1.default.escape(userID)}) `, []))[0]['count(1)'];
1636
+ from \`${this.app}\`.\`t_user\`
1637
+ where (userData ->>'$.email' = ${database_1.default.escape(par.userData.email)})
1638
+ and (userID != ${database_1.default.escape(userID)}) `, []))[0]['count(1)'];
1628
1639
  if (count) {
1629
1640
  throw exception_1.default.BadRequestError('BAD_REQUEST', 'Already exists.', {
1630
1641
  msg: 'email-exists',
@@ -1642,9 +1653,9 @@ or
1642
1653
  }
1643
1654
  if (par.userData.phone && par.userData.phone !== userData.userData.phone) {
1644
1655
  const count = (await database_1.default.query(`select count(1)
1645
- from \`${this.app}\`.\`t_user\`
1646
- where (userData ->>'$.phone' = ${database_1.default.escape(par.userData.phone)})
1647
- and (userID != ${database_1.default.escape(userID)}) `, []))[0]['count(1)'];
1656
+ from \`${this.app}\`.\`t_user\`
1657
+ where (userData ->>'$.phone' = ${database_1.default.escape(par.userData.phone)})
1658
+ and (userID != ${database_1.default.escape(userID)}) `, []))[0]['count(1)'];
1648
1659
  if (count) {
1649
1660
  throw exception_1.default.BadRequestError('BAD_REQUEST', 'Already exists.', {
1650
1661
  msg: 'phone-exists',
@@ -1664,16 +1675,16 @@ or
1664
1675
  par.status = blockCheck ? 0 : 1;
1665
1676
  if (par.userData.phone) {
1666
1677
  await database_1.default.query(`update \`${this.app}\`.t_checkout
1667
- set email=?
1668
- where id > 0
1669
- and email = ?`, [par.userData.phone, `${userData.userData.phone}`]);
1678
+ set email=?
1679
+ where id > 0
1680
+ and email = ?`, [par.userData.phone, `${userData.userData.phone}`]);
1670
1681
  userData.account = par.userData.phone;
1671
1682
  }
1672
1683
  if (par.userData.email) {
1673
1684
  await database_1.default.query(`update \`${this.app}\`.t_checkout
1674
- set email=?
1675
- where id > 0
1676
- and email = ?`, [par.userData.email, `${userData.userData.email}`]);
1685
+ set email=?
1686
+ where id > 0
1687
+ and email = ?`, [par.userData.email, `${userData.userData.email}`]);
1677
1688
  userData.account = par.userData.email;
1678
1689
  }
1679
1690
  par.userData = await this.checkUpdate({
@@ -1691,9 +1702,9 @@ or
1691
1702
  delete par.account;
1692
1703
  }
1693
1704
  const data = (await database_1.default.query(`update \`${this.app}\`.t_user
1694
- SET ?
1695
- WHERE 1 = 1
1696
- and userID = ?`, [par, userID]));
1705
+ SET ?
1706
+ WHERE 1 = 1
1707
+ and userID = ?`, [par, userID]));
1697
1708
  await user_update_js_1.UserUpdate.update(this.app, userID);
1698
1709
  return {
1699
1710
  data: data,
@@ -1730,8 +1741,8 @@ or
1730
1741
  }
1731
1742
  async checkUpdate(cf) {
1732
1743
  let originUserData = (await database_1.default.query(`select userData
1733
- from \`${this.app}\`.\`t_user\`
1734
- where userID = ${database_1.default.escape(cf.userID)}`, []))[0]['userData'];
1744
+ from \`${this.app}\`.\`t_user\`
1745
+ where userID = ${database_1.default.escape(cf.userID)}`, []))[0]['userData'];
1735
1746
  if (typeof originUserData !== 'object') {
1736
1747
  originUserData = {};
1737
1748
  }
@@ -1747,9 +1758,9 @@ or
1747
1758
  async resetPwd(user_id_and_account, newPwd) {
1748
1759
  try {
1749
1760
  const result = (await database_1.default.query(`update \`${this.app}\`.t_user
1750
- SET ?
1751
- WHERE 1 = 1
1752
- and ((userData ->>'$.email' = ?))`, [
1761
+ SET ?
1762
+ WHERE 1 = 1
1763
+ and ((userData ->>'$.email' = ?))`, [
1753
1764
  {
1754
1765
  pwd: await tool_1.default.hashPwd(newPwd),
1755
1766
  },
@@ -1766,14 +1777,14 @@ or
1766
1777
  async resetPwdNeedCheck(userID, pwd, newPwd) {
1767
1778
  try {
1768
1779
  const data = (await database_1.default.execute(`select *
1769
- from \`${this.app}\`.t_user
1770
- where userID = ?
1771
- and status = 1`, [userID]))[0];
1780
+ from \`${this.app}\`.t_user
1781
+ where userID = ?
1782
+ and status = 1`, [userID]))[0];
1772
1783
  if (await tool_1.default.compareHash(pwd, data.pwd)) {
1773
1784
  const result = (await database_1.default.query(`update \`${this.app}\`.t_user
1774
- SET ?
1775
- WHERE 1 = 1
1776
- and userID = ?`, [
1785
+ SET ?
1786
+ WHERE 1 = 1
1787
+ and userID = ?`, [
1777
1788
  {
1778
1789
  pwd: await tool_1.default.hashPwd(newPwd),
1779
1790
  },
@@ -1794,12 +1805,12 @@ or
1794
1805
  async updateAccountBack(token) {
1795
1806
  try {
1796
1807
  const sql = `select userData
1797
- from \`${this.app}\`.t_user
1798
- where JSON_EXTRACT(userData, '$.mailVerify') = ${database_1.default.escape(token)}`;
1808
+ from \`${this.app}\`.t_user
1809
+ where JSON_EXTRACT(userData, '$.mailVerify') = ${database_1.default.escape(token)}`;
1799
1810
  const userData = (await database_1.default.query(sql, []))[0]['userData'];
1800
1811
  await database_1.default.execute(`update \`${this.app}\`.t_user
1801
- set account=${database_1.default.escape(userData.updateAccount)}
1802
- where JSON_EXTRACT(userData, '$.mailVerify') = ?`, [token]);
1812
+ set account=${database_1.default.escape(userData.updateAccount)}
1813
+ where JSON_EXTRACT(userData, '$.mailVerify') = ?`, [token]);
1803
1814
  }
1804
1815
  catch (e) {
1805
1816
  throw exception_1.default.BadRequestError('BAD_REQUEST', 'updateAccountBack Error:' + e, null);
@@ -1811,9 +1822,9 @@ or
1811
1822
  status: 1,
1812
1823
  };
1813
1824
  return (await database_1.default.query(`update \`${this.app}\`.t_user
1814
- SET ?
1815
- WHERE 1 = 1
1816
- and JSON_EXTRACT(userData, '$.mailVerify') = ?`, [par, token]));
1825
+ SET ?
1826
+ WHERE 1 = 1
1827
+ and JSON_EXTRACT(userData, '$.mailVerify') = ?`, [par, token]));
1817
1828
  }
1818
1829
  catch (e) {
1819
1830
  throw exception_1.default.BadRequestError('BAD_REQUEST', 'Verify Error:' + e, null);
@@ -1822,9 +1833,9 @@ or
1822
1833
  async checkUserExists(account) {
1823
1834
  try {
1824
1835
  return ((await database_1.default.execute(`select count(1)
1825
- from \`${this.app}\`.t_user
1826
- where userData ->>'$.email'
1827
- and status!=0`, [account]))[0]['count(1)'] == 1);
1836
+ from \`${this.app}\`.t_user
1837
+ where userData ->>'$.email'
1838
+ and status!=0`, [account]))[0]['count(1)'] == 1);
1828
1839
  }
1829
1840
  catch (e) {
1830
1841
  throw exception_1.default.BadRequestError('BAD_REQUEST', 'CheckUserExists Error:' + e, null);
@@ -1837,16 +1848,16 @@ or
1837
1848
  let phoneExists = false;
1838
1849
  if (email) {
1839
1850
  const emailResult = await database_1.default.execute(`SELECT COUNT(1) AS count
1840
- FROM \`${this.app}\`.t_user
1841
- WHERE userData ->>'$.email' = ?
1842
- `, [email]);
1851
+ FROM \`${this.app}\`.t_user
1852
+ WHERE userData ->>'$.email' = ?
1853
+ `, [email]);
1843
1854
  emailExists = ((_a = emailResult[0]) === null || _a === void 0 ? void 0 : _a.count) > 0;
1844
1855
  }
1845
1856
  if (phone) {
1846
1857
  const phoneResult = await database_1.default.execute(`SELECT COUNT(1) AS count
1847
- FROM \`${this.app}\`.t_user
1848
- WHERE userData ->>'$.phone' = ?
1849
- `, [phone]);
1858
+ FROM \`${this.app}\`.t_user
1859
+ WHERE userData ->>'$.phone' = ?
1860
+ `, [phone]);
1850
1861
  phoneExists = ((_b = phoneResult[0]) === null || _b === void 0 ? void 0 : _b.count) > 0;
1851
1862
  }
1852
1863
  return {
@@ -1864,8 +1875,8 @@ or
1864
1875
  async checkUserIdExists(id) {
1865
1876
  try {
1866
1877
  const count = (await database_1.default.query(`select count(1)
1867
- from \`${this.app}\`.t_user
1868
- where userID = ?`, [id]))[0]['count(1)'];
1878
+ from \`${this.app}\`.t_user
1879
+ where userID = ?`, [id]))[0]['count(1)'];
1869
1880
  return count;
1870
1881
  }
1871
1882
  catch (e) {
@@ -1879,20 +1890,20 @@ or
1879
1890
  config.value = JSON.stringify(config.value);
1880
1891
  }
1881
1892
  if ((await database_1.default.query(`select count(1)
1882
- from \`${this.app}\`.t_user_public_config
1883
- where \`key\` = ?
1884
- and user_id = ? `, [config.key, (_a = config.user_id) !== null && _a !== void 0 ? _a : this.token.userID]))[0]['count(1)'] === 1) {
1893
+ from \`${this.app}\`.t_user_public_config
1894
+ where \`key\` = ?
1895
+ and user_id = ? `, [config.key, (_a = config.user_id) !== null && _a !== void 0 ? _a : this.token.userID]))[0]['count(1)'] === 1) {
1885
1896
  await database_1.default.query(`update \`${this.app}\`.t_user_public_config
1886
- set value=?,
1887
- updated_at=?
1888
- where \`key\` = ?
1889
- and user_id = ?`, [config.value, new Date(), config.key, (_b = config.user_id) !== null && _b !== void 0 ? _b : this.token.userID]);
1897
+ set value=?,
1898
+ updated_at=?
1899
+ where \`key\` = ?
1900
+ and user_id = ?`, [config.value, new Date(), config.key, (_b = config.user_id) !== null && _b !== void 0 ? _b : this.token.userID]);
1890
1901
  }
1891
1902
  else {
1892
1903
  await database_1.default.query(`insert
1893
- into \`${this.app}\`.t_user_public_config (\`user_id\`, \`key\`, \`value\`, updated_at)
1894
- values (?, ?, ?, ?)
1895
- `, [(_c = config.user_id) !== null && _c !== void 0 ? _c : this.token.userID, config.key, config.value, new Date()]);
1904
+ into \`${this.app}\`.t_user_public_config (\`user_id\`, \`key\`, \`value\`, updated_at)
1905
+ values (?, ?, ?, ?)
1906
+ `, [(_c = config.user_id) !== null && _c !== void 0 ? _c : this.token.userID, config.key, config.value, new Date()]);
1896
1907
  }
1897
1908
  if (config.key === 'domain_301') {
1898
1909
  const find_app_301 = public_table_check_js_1.ApiPublic.app301.find(dd => {
@@ -1911,10 +1922,10 @@ or
1911
1922
  async getConfig(config) {
1912
1923
  try {
1913
1924
  return await database_1.default.execute(`select *
1914
- from \`${this.app}\`.t_user_public_config
1915
- where \`key\` = ${database_1.default.escape(config.key)}
1916
- and user_id = ${database_1.default.escape(config.user_id)}
1917
- `, []);
1925
+ from \`${this.app}\`.t_user_public_config
1926
+ where \`key\` = ${database_1.default.escape(config.key)}
1927
+ and user_id = ${database_1.default.escape(config.user_id)}
1928
+ `, []);
1918
1929
  }
1919
1930
  catch (e) {
1920
1931
  console.error(e);
@@ -1932,7 +1943,7 @@ or
1932
1943
  .map(dd => database_1.default.escape(dd))
1933
1944
  .join(',')})`
1934
1945
  : `\`key\` = ${database_1.default.escape(config.key)}`}
1935
- AND user_id = ${database_1.default.escape(config.user_id)}`, []);
1946
+ AND user_id = ${database_1.default.escape(config.user_id)}`, []);
1936
1947
  async function loop(data) {
1937
1948
  if (!data && config.user_id === 'manager') {
1938
1949
  const defaultValues = {
@@ -2038,8 +2049,8 @@ or
2038
2049
  async checkEmailExists(email) {
2039
2050
  try {
2040
2051
  const count = (await database_1.default.query(`select count(1)
2041
- from \`${this.app}\`.t_user
2042
- where userData ->>'$.email' = ?`, [email]))[0]['count(1)'];
2052
+ from \`${this.app}\`.t_user
2053
+ where userData ->>'$.email' = ?`, [email]))[0]['count(1)'];
2043
2054
  return count;
2044
2055
  }
2045
2056
  catch (e) {
@@ -2049,8 +2060,8 @@ or
2049
2060
  async checkPhoneExists(phone) {
2050
2061
  try {
2051
2062
  const count = (await database_1.default.query(`select count(1)
2052
- from \`${this.app}\`.t_user
2053
- where userData ->>'$.phone' = ?`, [phone]))[0]['count(1)'];
2063
+ from \`${this.app}\`.t_user
2064
+ where userData ->>'$.phone' = ?`, [phone]))[0]['count(1)'];
2054
2065
  return count;
2055
2066
  }
2056
2067
  catch (e) {
@@ -2061,14 +2072,14 @@ or
2061
2072
  var _a, _b;
2062
2073
  try {
2063
2074
  const last_read_time = await database_1.default.query(`SELECT value
2064
- FROM \`${this.app}\`.t_user_public_config
2065
- where \`key\` = 'notice_last_read'
2066
- and user_id = ?;`, [(_a = this.token) === null || _a === void 0 ? void 0 : _a.userID]);
2075
+ FROM \`${this.app}\`.t_user_public_config
2076
+ where \`key\` = 'notice_last_read'
2077
+ and user_id = ?;`, [(_a = this.token) === null || _a === void 0 ? void 0 : _a.userID]);
2067
2078
  const date = !last_read_time[0] ? new Date('2022-01-29') : new Date(last_read_time[0].value.time);
2068
2079
  const count = (await database_1.default.query(`select count(1)
2069
- from \`${this.app}\`.t_notice
2070
- where user_id = ?
2071
- and created_time > ?`, [(_b = this.token) === null || _b === void 0 ? void 0 : _b.userID, date]))[0]['count(1)'];
2080
+ from \`${this.app}\`.t_notice
2081
+ where user_id = ?
2082
+ and created_time > ?`, [(_b = this.token) === null || _b === void 0 ? void 0 : _b.userID, date]))[0]['count(1)'];
2072
2083
  return {
2073
2084
  count: count,
2074
2085
  };
@@ -2081,16 +2092,16 @@ or
2081
2092
  var _a, _b;
2082
2093
  try {
2083
2094
  const result = await database_1.default.query(`select count(1)
2084
- from ${process_1.default.env.GLITTER_DB}.app_config
2085
- where (appName = ?
2086
- and user = ?)
2087
- OR appName in (
2088
- (SELECT appName
2089
- FROM \`${config_1.saasConfig.SAAS_NAME}\`.app_auth_config
2090
- WHERE user = ?
2091
- AND status = 1
2092
- AND invited = 1
2093
- AND appName = ?));`, [this.app, (_a = this.token) === null || _a === void 0 ? void 0 : _a.userID, (_b = this.token) === null || _b === void 0 ? void 0 : _b.userID, this.app]);
2095
+ from ${process_1.default.env.GLITTER_DB}.app_config
2096
+ where (appName = ?
2097
+ and user = ?)
2098
+ OR appName in (
2099
+ (SELECT appName
2100
+ FROM \`${config_1.saasConfig.SAAS_NAME}\`.app_auth_config
2101
+ WHERE user = ?
2102
+ AND status = 1
2103
+ AND invited = 1
2104
+ AND appName = ?));`, [this.app, (_a = this.token) === null || _a === void 0 ? void 0 : _a.userID, (_b = this.token) === null || _b === void 0 ? void 0 : _b.userID, this.app]);
2094
2105
  return {
2095
2106
  result: result[0]['count(1)'] === 1,
2096
2107
  };
@@ -2103,19 +2114,19 @@ or
2103
2114
  const query = [`user_id=${(_a = this.token) === null || _a === void 0 ? void 0 : _a.userID}`];
2104
2115
  let last_time_read = 0;
2105
2116
  const last_read_time = await database_1.default.query(`SELECT value
2106
- FROM \`${this.app}\`.t_user_public_config
2107
- where \`key\` = 'notice_last_read'
2108
- and user_id = ?;`, [(_b = this.token) === null || _b === void 0 ? void 0 : _b.userID]);
2117
+ FROM \`${this.app}\`.t_user_public_config
2118
+ where \`key\` = 'notice_last_read'
2119
+ and user_id = ?;`, [(_b = this.token) === null || _b === void 0 ? void 0 : _b.userID]);
2109
2120
  if (!last_read_time[0]) {
2110
2121
  await database_1.default.query(`insert into \`${this.app}\`.t_user_public_config (user_id, \`key\`, value, updated_at)
2111
- values (?, ?, ?, ?)`, [(_c = this.token) === null || _c === void 0 ? void 0 : _c.userID, 'notice_last_read', JSON.stringify({ time: new Date() }), new Date()]);
2122
+ values (?, ?, ?, ?)`, [(_c = this.token) === null || _c === void 0 ? void 0 : _c.userID, 'notice_last_read', JSON.stringify({ time: new Date() }), new Date()]);
2112
2123
  }
2113
2124
  else {
2114
2125
  last_time_read = new Date(last_read_time[0].value.time).getTime();
2115
2126
  await database_1.default.query(`update \`${this.app}\`.t_user_public_config
2116
- set \`value\`=?
2117
- where user_id = ?
2118
- and \`key\` = ?`, [JSON.stringify({ time: new Date() }), `${(_d = this.token) === null || _d === void 0 ? void 0 : _d.userID}`, 'notice_last_read']);
2127
+ set \`value\`=?
2128
+ where user_id = ?
2129
+ and \`key\` = ?`, [JSON.stringify({ time: new Date() }), `${(_d = this.token) === null || _d === void 0 ? void 0 : _d.userID}`, 'notice_last_read']);
2119
2130
  }
2120
2131
  const response = await new ut_database_js_1.UtDatabase(this.app, `t_notice`).querySql(query, cf.query);
2121
2132
  response.last_time_read = last_time_read;
@@ -2142,13 +2153,13 @@ or
2142
2153
  headers: {},
2143
2154
  };
2144
2155
  const db_data = (await database_1.default.query(`select *
2145
- from ${config_1.saasConfig.SAAS_NAME}.t_ip_info
2146
- where ip = ?`, [ip]))[0];
2156
+ from ${config_1.saasConfig.SAAS_NAME}.t_ip_info
2157
+ where ip = ?`, [ip]))[0];
2147
2158
  let ip_data = db_data && db_data.data;
2148
2159
  if (!ip_data) {
2149
2160
  ip_data = (await axios_1.default.request(config)).data;
2150
2161
  await database_1.default.query(`insert into ${config_1.saasConfig.SAAS_NAME}.t_ip_info (ip, data)
2151
- values (?, ?)`, [ip, JSON.stringify(ip_data)]);
2162
+ values (?, ?)`, [ip, JSON.stringify(ip_data)]);
2152
2163
  }
2153
2164
  return ip_data;
2154
2165
  }