CommonController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. class CommonController extends Controller
  3. {
  4. /**
  5. * 发送验证码
  6. */
  7. public function actionSendCode()
  8. {
  9. $phone = Helper::getPostString('phone', '');
  10. if (!Helper::isPhone($phone)) {
  11. Helper::error('手机号码格式错误');
  12. }
  13. // 验证码发送限制
  14. Helper::dealCommonResult(Helper::limitSmsSend(10, $phone, 5), false);
  15. if (!DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'))) {
  16. Helper::error('该手机号用户不存在');
  17. }
  18. $code = (string)random_int(100000,999999);
  19. RedisInstance::getInstance()->set('user_code:'.$phone, $code, 600);
  20. // 发送短信
  21. Helper::dealCommonResult(SMS::getInstance()->send($phone, '2094847', [$code]));
  22. }
  23. /**
  24. * 找回密码
  25. */
  26. public function actionSetPassword()
  27. {
  28. $phone = Helper::getPostString('phone');
  29. $code = Helper::getPostString('code');
  30. $password = Helper::getPostString('password');
  31. if (!Helper::isPhone($phone)) {
  32. Helper::error('手机号码格式错误');
  33. }
  34. if (!$code || !$password) {
  35. Helper::error('参数错误');
  36. }
  37. if (RedisInstance::getInstance()->get('user_code:'.$phone) != $code) {
  38. Helper::error('验证码错误');
  39. }
  40. $id = DB::getScalerWithCriteria('useradmin', DbCriteria::simpleCompare(['phone' => $phone])->setSelect('id'));
  41. if (!$id) {
  42. Helper::error('该手机号用户不存在');
  43. }
  44. DB::updateById('useradmin', ['password' => md5($password)], $id);
  45. Helper::ok();
  46. }
  47. /**
  48. * 图片上传
  49. */
  50. public function actionUploadImg()
  51. {
  52. Helper::ok();
  53. }
  54. /******************************* 测试相关代码 ***************************************/
  55. public function actionPhp()
  56. {
  57. (new DBTable(Helper::getGetString('t1')))->echoEditHtml();
  58. }
  59. public function actionTs()
  60. {
  61. echo (new DBTable(Helper::getGetString('t1')))->getTsInterFace();
  62. }
  63. public function actionForm()
  64. {
  65. (new DBTable(Helper::getGetString('t1')))->editVue();
  66. }
  67. public function actionTable()
  68. {
  69. echo (new DBTable(Helper::getGetString('t1')))->getTableHtml();
  70. }
  71. public function actionInfo()
  72. {
  73. echo (new DBTable(Helper::getGetString('t1')))->getDetailHtml();
  74. }
  75. }