You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

91 line
2.9 KiB

  1. const Base = require('../../base');
  2. module.exports = class extends Base {
  3. async indexAction() {
  4. this.assign('currentPage', 'sys-sms');
  5. this.assign('pageTitle', '短信记录');
  6. this.assign('breadcrumb', [
  7. { name: '系统管理', url: '/admin/system/user.html' },
  8. { name: '短信记录' }
  9. ]);
  10. return this.display();
  11. }
  12. async listAction() {
  13. const keyword = this.get('keyword') || '';
  14. const status = this.get('status');
  15. const bizType = this.get('bizType') || '';
  16. const startDate = this.get('startDate') || '';
  17. const endDate = this.get('endDate') || '';
  18. const page = this.get('page') || 1;
  19. const pageSize = this.get('pageSize') || 20;
  20. const model = this.model('sms_log');
  21. const where = {};
  22. if (keyword) {
  23. where.mobile = ['like', `%${keyword}%`];
  24. }
  25. if (status !== '' && status !== undefined) {
  26. where.status = parseInt(status);
  27. }
  28. if (bizType) {
  29. where.biz_type = bizType;
  30. }
  31. if (startDate && endDate) {
  32. where.create_time = ['between', [startDate + ' 00:00:00', endDate + ' 23:59:59']];
  33. } else if (startDate) {
  34. where.create_time = ['>=', startDate + ' 00:00:00'];
  35. } else if (endDate) {
  36. where.create_time = ['<=', endDate + ' 23:59:59'];
  37. }
  38. const list = await model.where(where)
  39. .order('id DESC')
  40. .page(page, pageSize)
  41. .countSelect();
  42. // 验证码脱敏:6位验证码中间4位替换为****
  43. const codeBizTypes = ['real_name_auth', 'login', 'change_phone'];
  44. if (list.data && list.data.length) {
  45. list.data.forEach(item => {
  46. if (item.code && codeBizTypes.includes(item.biz_type)) {
  47. item.code = item.code.slice(0, 1) + '****' + item.code.slice(-1);
  48. }
  49. });
  50. }
  51. return this.json({ code: 0, data: list });
  52. }
  53. // 清除短信发送限制(手机号或IP)
  54. async clearLimitAction() {
  55. const { type, value } = this.post();
  56. if (!type || !value) return this.fail('参数错误');
  57. const dayjs = require('dayjs');
  58. const today = dayjs().format('YYYY-MM-DD');
  59. let cleared = [];
  60. if (type === 'phone') {
  61. // 清除手机号相关的所有限制
  62. const bizTypes = ['real_name_auth', 'change_phone', 'login'];
  63. for (const biz of bizTypes) {
  64. await think.cache(`sms:rate_limit:${value}:${biz}`, null);
  65. await think.cache(`sms:daily:${value}:${today}`, null);
  66. await think.cache(`sms:code:${value}:${biz}`, null);
  67. }
  68. cleared = ['频率限制', '每日上限', '验证码缓存'];
  69. } else if (type === 'ip') {
  70. await think.cache(`sms:ip_hour:${value}`, null);
  71. await think.cache(`sms:ip_day:${value}:${today}`, null);
  72. cleared = ['IP小时限制', 'IP每日限制'];
  73. } else {
  74. return this.fail('类型错误');
  75. }
  76. await this.log('edit', '系统管理', `清除短信限制: ${type === 'phone' ? '手机号' : 'IP'} ${value} (${cleared.join('、')})`);
  77. return this.success();
  78. }
  79. };