SmsController.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * 短信
  4. * @author wesmiler
  5. */
  6. namespace app\api\controller;
  7. use app\weixin\model\Member;
  8. use app\weixin\service\Sms;
  9. use app\weixin\validate\MemberValidate;
  10. use cmf\controller\HomeBaseController;
  11. class SmsController extends HomeBaseController
  12. {
  13. /**
  14. * 发送短信验证码
  15. * @return mixed
  16. */
  17. public function sendCode()
  18. {
  19. // 参数验证
  20. $mobile = input('mobile', '');
  21. $scene = input('scene', 'code');
  22. $userId = input('id', 0);
  23. $validate = new MemberValidate();
  24. if(!$validate->scene('code')->check(input())){
  25. showJson(1004, $validate->getError());
  26. }
  27. // 场景验证
  28. switch ($scene) {
  29. case 'code': // 完善信息注册
  30. case 'reg': // 账号注册
  31. $id = Member::where(['mobile' => $mobile])
  32. ->where(function($query) {
  33. $query->where(['agent_type'=> 0])->whereOr(['agent_type'=> 1, 'is_reg_profile'=> 1]);
  34. })
  35. ->where('user_status','>=',0)
  36. ->value('id');
  37. if ($id && $id != $userId) {
  38. showJson(1004, 2001);
  39. }
  40. if($id && $id == $userId){
  41. showJson(1004, 2000);
  42. }
  43. break;
  44. case 'verify': // 验证换绑
  45. $id = Member::where(['mobile' => $mobile,'user_type'=>2])
  46. ->where(function($query) {
  47. $query->where(['agent_type'=> 0])->whereOr(['agent_type'=> 1, 'is_reg_profile'=> 1]);
  48. })
  49. ->where('user_status','>=',0)
  50. ->value('id');
  51. if ($id && $id != $userId) {
  52. showJson(1004, 2001);
  53. }
  54. break;
  55. case 'marketReg': // 分销账号注册
  56. $id = Member::where(['user_login' => $mobile,'agent_type'=> 1])->where('agent_status','in',[0,1,2])->value('id');
  57. if ($id && $id != $userId) {
  58. showJson(1004, 2001);
  59. }
  60. if($id && $id == $userId){
  61. showJson(1004, 2000);
  62. }
  63. break;
  64. case 'login': // 登录
  65. case 'fpwd': // 找回密码
  66. case 'mpwd': // 修改密码
  67. if (!Member::where(['mobile' => $mobile])->value('id')) {
  68. showJson(1004, 2013);
  69. }
  70. break;
  71. }
  72. // 发送处理
  73. $result = Sms::sendCode($mobile, ['tpName' => 'code'], $scene);
  74. if (!is_array($result)) {
  75. showJson(1004, $result ? $result : 2017);
  76. }
  77. showJson(1005, 2016);
  78. }
  79. }
  80. ?>