Login.php 5.4 KB

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