Login.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. *
  4. * User: anyluck
  5. * Date: 2020/6/3
  6. * Time: 9:46
  7. */
  8. namespace app\web\controller;
  9. use app\common\controller\Upfile;
  10. use app\common\model\PhoneCode;
  11. use app\common\model\System;
  12. use app\common\model\User;
  13. use app\web\model\Send;
  14. use app\web\model\Team;
  15. use app\web\model\Tripartite;
  16. use Ramsey\Uuid\Uuid;
  17. class Login
  18. {
  19. // todo 登录注册
  20. // 登录
  21. public function in_login()
  22. {
  23. $phone = input("phone");
  24. if (!$phone) json_result(400, "请输入手机号码或者邮箱账号");
  25. $pwd = input("pwd");
  26. if (!$pwd) json_result(400, "请输入登录密码");
  27. $where["phone|mail"] = $phone;
  28. $user = User::where($where)->find();
  29. if (!$user) {
  30. json_result(400, "账号不存在");
  31. }
  32. if (!password_verify($pwd, $user->pwd)) {
  33. json_result(400, "密码错误");
  34. }
  35. if ($user->status == 1) {// 禁止登录
  36. if ($user->status_time > time()) {
  37. json_result(400, "该账号已经封号");
  38. } else {// 解除禁止登陸
  39. User::update(["status" => 0, "status_time" => ""], ["id" => $user->id]);
  40. }
  41. }
  42. // 给账号加活跃度
  43. $update["update_time"]=time();
  44. User::update($update,["id"=>$user->id]);
  45. json_result(200, "登录成功", $user);
  46. }
  47. // 获取验证码
  48. public function code()
  49. {
  50. $phone = input("phone");
  51. if (!$phone) json_result(400, "请输入手机号或者邮箱");
  52. $type = input("type") ?: 0;
  53. // 查询是否重复发送
  54. $where["phone"] = $phone;
  55. $where["add_time"] = ["<", time() - (1 * 60)];
  56. $phone_code = PhoneCode::where($where)->find();
  57. if ($phone_code) {
  58. json_result(400, "验证码已发送请稍后再发送");
  59. }
  60. $res = Tripartite::send_code($phone, $type);
  61. json_result(200, "验证码发送成功", $res);
  62. }
  63. // 注册
  64. public function register()
  65. {
  66. $phone = input("phone");
  67. if (!$phone) json_result(400, "请输入手机号或者邮箱");
  68. $code = input("code");
  69. if (!$code) json_result(400, "请输入验证码");
  70. $name = input("name");
  71. if (!$name) json_result(400, "请输入账户呢称");
  72. $type = input("type") ?: 0;
  73. $pwd = input("pwd");
  74. if (!$pwd) json_result(400, "请输入密码");
  75. $pid = input("pid");
  76. // 查看账号是存在
  77. $where["phone|mail"] = $phone;
  78. $user = User::where($where)->find();
  79. if ($user) {
  80. json_result(400, "账号已注册,请前去登录");
  81. }
  82. // 验证码
  83. $phone_code = Tripartite::push_code($phone);
  84. if ($phone_code != $code) {
  85. json_result(400, "验证码错误");
  86. }
  87. if ($pid) {
  88. $wheres["code"] = $pid;
  89. $pid_user = User::where($wheres)->find();
  90. if (!$pid_user) {
  91. json_result(400, "上级账号不存在");
  92. }
  93. $add["pid"] = $pid_user->id;
  94. // Team::all_tem($pid_user->id);
  95. }
  96. $add["code"] = uniqid();
  97. if ($type == 0) {
  98. $add["phone"] = $phone;
  99. } else {
  100. $add["mail"] = $phone;
  101. }
  102. $add["name"] = $name;
  103. $add["uuid"] = uniqid();// 收款ID
  104. $uuid = Uuid::uuid1();
  105. $add["token"] = $uuid->getHex();;
  106. $add["add_time"] = time();
  107. $add["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
  108. // dump($add);die();
  109. User::create($add);
  110. json_result(200, "注册成功");
  111. }
  112. // 忘记密码 第一部
  113. public function forget_password()
  114. {
  115. $phone = input("phone");
  116. if (!$phone) json_result(400, "请输入手机号码或者邮箱");
  117. $type = input("type") ?: 0;
  118. $code = input("code");
  119. if (!$code) json_result(400, "请输入验证码");
  120. $name = input("name");
  121. // 查看账号是存在
  122. $where["phone|mail"] = $phone;
  123. $user = User::where($where)->find();
  124. if (!$user) {
  125. json_result(400, "账号不存在");
  126. }
  127. // 验证码
  128. $phone_code = Tripartite::push_code($phone, $type);
  129. if ($phone_code != $code) {
  130. json_result(400, "验证码错误");
  131. }
  132. json_result(200, "验证码成功");
  133. }
  134. // 修改密码--第二步
  135. public function update_password()
  136. {
  137. $pwd = input("pwd");
  138. if (!$pwd) json_result(400, "请输入密码");
  139. $phone = input("phone");
  140. if (!$phone) json_result(400, "请输入手机号码或者邮箱");
  141. // 查看账号是存在
  142. $where["phone|mail"] = $phone;
  143. $user = User::where($where)->find();
  144. if (!$user) {
  145. json_result(400, "账号不存在");
  146. }
  147. $add["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
  148. User::where(["id" => $user->id])->update($add);
  149. json_result(200, "设置密码成功");
  150. }
  151. // 上传图片
  152. public function up_image()
  153. {
  154. $upfile = new Upfile();
  155. $ret = $upfile->Uploads();
  156. json_result(200, "", $ret["url"]);
  157. }
  158. // 会员协议
  159. public function Membership()
  160. {
  161. $where["name"]="Membership";
  162. $data=System::where($where)->field("value")->find();
  163. json_result(200,"",$data->value?:"");
  164. }
  165. // 测试接口
  166. public function test()
  167. {
  168. Send::login_code("13323821192","123456");
  169. }
  170. }