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.

119 lines
3.2 KiB

7 years ago
4 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Http\Request;
  6. use App\Common\ReturnData;
  7. use App\Common\Helper;
  8. use App\Common\Token;
  9. use App\Http\Model\VerifyCode;
  10. use App\Http\Logic\VerifyCodeLogic;
  11. class VerifyCodeController extends BaseController
  12. {
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. public function getLogic()
  18. {
  19. return logic('VerifyCode');
  20. }
  21. public function verifyCodeList(Request $request)
  22. {
  23. //参数
  24. $limit = $request->input('limit', 10);
  25. $offset = $request->input('offset', 0);
  26. $where['user_id'] = Token::$uid;
  27. $res = $this->getLogic()->getList($where, array('id', 'desc'), '*', $offset, $limit);
  28. return ReturnData::create(ReturnData::SUCCESS,$res);
  29. }
  30. public function verifyCodeDetail(Request $request)
  31. {
  32. //参数
  33. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  34. $id = $request->input('id');
  35. $where['id'] = $id;
  36. $res = $this->getLogic()->getOne($where);
  37. if(!$res)
  38. {
  39. return ReturnData::create(ReturnData::RECORD_NOT_EXIST);
  40. }
  41. return ReturnData::create(ReturnData::SUCCESS,$res);
  42. }
  43. //添加
  44. public function verifyCodeAdd(Request $request)
  45. {
  46. if(Helper::isPostRequest())
  47. {
  48. $_POST['user_id'] = Token::$uid;
  49. return $this->getLogic()->add($_POST);
  50. }
  51. }
  52. //修改
  53. public function verifyCodeUpdate(Request $request)
  54. {
  55. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  56. $id = $request->input('id');
  57. if(Helper::isPostRequest())
  58. {
  59. unset($_POST['id']);
  60. $where['id'] = $id;
  61. $where['user_id'] = Token::$uid;
  62. return $this->getLogic()->edit($_POST,$where);
  63. }
  64. }
  65. //删除
  66. public function verifyCodeDelete(Request $request)
  67. {
  68. if(!checkIsNumber($request->input('id',null))){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  69. $id = $request->input('id');
  70. if(Helper::isPostRequest())
  71. {
  72. $where['id'] = $id;
  73. $where['user_id'] = Token::$uid;
  74. return $this->getLogic()->del($where);
  75. }
  76. }
  77. //验证码校验
  78. public function verifyCodeCheck(Request $request)
  79. {
  80. $mobile = $request->input('mobile', null); //手机号码
  81. $verifyCode = $request->input('verifyCode', null); //手机验证码
  82. $type = $request->input('type', null); //验证码类型
  83. if ($mobile==null || $verifyCode==null || $type==null)
  84. {
  85. return ReturnData::create(ReturnData::PARAMS_ERROR);
  86. }
  87. if (!Helper::isValidMobile($mobile))
  88. {
  89. return ReturnData::create(ReturnData::MOBILE_FORMAT_FAIL);
  90. }
  91. $verifyCode = VerifyCode::isVerify($mobile, $verifyCode, $type);
  92. if(!$verifyCode)
  93. {
  94. return ReturnData::create(ReturnData::INVALID_VERIFYCODE);
  95. }
  96. return ReturnData::create(ReturnData::SUCCESS);
  97. }
  98. }