Sms.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\AdminBaseController;
  4. use app\common\model\SmsAuthModel;
  5. use app\common\model\SmsLogModel;
  6. use app\common\validate\SmsAuthValidate;
  7. use app\common\validate\SmsTemplateValidate;
  8. use app\common\model\SmsTemplateModel;
  9. use think\exception\ValidateException;
  10. class Sms extends AdminBaseController
  11. {
  12. /**
  13. * 授权
  14. */
  15. public function auth()
  16. {
  17. return view();
  18. }
  19. public function authForm()
  20. {
  21. $id = input('id/d, 0');
  22. $info = SmsAuthModel::find($id);
  23. if (empty($info)) {
  24. $info['token'] = rand_str(8) . uniqid();
  25. }
  26. return view('', [
  27. 'info' => $info,
  28. ]);
  29. }
  30. public function listAuth()
  31. {
  32. $list = SmsAuthModel::limit(input('limit'))
  33. ->page(input('page'))
  34. ->select();
  35. $count = SmsAuthModel::count();
  36. if ($count == 0) {
  37. ajax_return(1, '未查询到数据');
  38. }
  39. list_return($list, $count);
  40. }
  41. public function delAuth()
  42. {
  43. $id = input('id/d', 0);
  44. SmsAuthModel::destroy($id);
  45. ajax_return();
  46. }
  47. public function editAuth()
  48. {
  49. $data = input('post.');
  50. try {
  51. validate(SmsAuthValidate::class)->check($data);
  52. } catch (ValidateException $e) {
  53. ajax_return(1, $e->getError());
  54. }
  55. if (empty($data['id'])) {
  56. $check = SmsAuthModel::where('token', $data['token'])->find();
  57. if (!empty($check)) {
  58. ajax_return(1, '该token已存在');
  59. }
  60. SmsAuthModel::create($data);
  61. } else {
  62. $check = SmsAuthModel::where('token', $data['token'])->where('id', '<>', $data['id'])->find();
  63. if (!empty($check)) {
  64. ajax_return(1, '该token已存在');
  65. }
  66. SmsAuthModel::update($data, ['id' => $data['id']]);
  67. }
  68. ajax_return();
  69. }
  70. /**
  71. * 日志
  72. */
  73. public function log()
  74. {
  75. return view('', [
  76. 'status_list' => SmsLogModel::STATUS,
  77. ]);
  78. }
  79. public function listLog()
  80. {
  81. $map = $this->dealEqualInput(['status']);
  82. $list = SmsLogModel::limit(input('limit'))
  83. ->where($map)
  84. ->page(input('page'))
  85. ->append(['status_text'])
  86. ->select();
  87. $count = SmsLogModel::where($map)->count();
  88. if ($count == 0) {
  89. ajax_return(1, '未查询到数据');
  90. }
  91. list_return($list, $count);
  92. }
  93. }