Login.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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\Mail;
  14. use app\web\model\Orders;
  15. use app\web\model\Send;
  16. use app\web\model\Team;
  17. use app\web\model\Tripartite;
  18. use Ramsey\Uuid\Uuid;
  19. class Login
  20. {
  21. // todo 登录注册
  22. // 登录
  23. public function in_login()
  24. {
  25. $phone = trim(input("phone"));
  26. if (!$phone) json_result(400, "请输入账号");
  27. $pwd = trim(input("pwd"));
  28. if (!$pwd) json_result(400, "请输入登录密码");
  29. $where["name"] = $phone;
  30. $user = User::where($where)->find();
  31. if (!$user) {
  32. json_result(400, "账号不存在");
  33. }
  34. if (!password_verify($pwd, $user->pwd)) {
  35. json_result(400, "密码错误");
  36. }
  37. if ($user->status == 1) {// 禁止登录
  38. if ($user->status_time > time()) {
  39. json_result(400, "该账号已经封号");
  40. } else {// 解除禁止登陸
  41. User::update(["status" => 0, "status_time" => ""], ["id" => $user->id]);
  42. }
  43. }
  44. // 给账号加活跃度
  45. $update["update_time"]=time();
  46. User::update($update,["id"=>$user->id]);
  47. json_result(200, "登录成功", $user);
  48. }
  49. // 获取验证码
  50. public function code()
  51. {
  52. $phone = trim(input("phone"));
  53. if (!$phone) json_result(400, "请输入手机号或者邮箱");
  54. $type = input("type") ?: 0;
  55. // 查询是否重复发送
  56. $where["phone"] = $phone;
  57. $where["add_time"] = ["<", time() - (1 * 60)];
  58. $phone_code = PhoneCode::where($where)->find();
  59. if ($phone_code) {
  60. json_result(400, "验证码已发送请稍后再发送");
  61. }
  62. $res = Tripartite::send_code($phone, $type);
  63. json_result(200, "验证码发送成功");
  64. }
  65. // 注册
  66. public function register()
  67. {
  68. $phone = trim(input("phone"));
  69. if (!$phone) json_result(400, "请输入手机号或者邮箱");
  70. $code = trim(input("code"));
  71. if (!$code) json_result(400, "请输入验证码");
  72. $name = trim(input("name"));
  73. if (!$name) json_result(400, "请输入账户");
  74. $type = input("type") ?: 0;
  75. $pwd = trim(input("pwd"));
  76. if (!$pwd) json_result(400, "请输入密码");
  77. $pid = trim(input("pid"));
  78. // 查看账号是存在
  79. $user_data= User::where(["name"=>$name])->find();
  80. if ($user_data){
  81. json_result(400,"账号已存在,请重新选一个名字吧");
  82. }
  83. $where["phone|mail"] = $phone;
  84. $user = User::where($where)->count();
  85. $phone_email= Orders::phone_email();
  86. // json_result(400, "验证码错误",$phone_email);
  87. if ($user>=$phone_email) {
  88. json_result(400, "账号手机号或邮箱已经注册超过".$phone_email);
  89. }
  90. // 验证码
  91. $phone_code = Tripartite::push_code($phone);
  92. if ($phone_code != $code) {
  93. json_result(400, "验证码错误");
  94. }
  95. if ($pid) {
  96. $wheres["code"] = $pid;
  97. $pid_user = User::where($wheres)->find();
  98. if (!$pid_user) {
  99. json_result(400, "上级账号不存在");
  100. }
  101. $add["pid"] = $pid_user->id;
  102. // Team::all_tem($pid_user->id);
  103. }
  104. $add["code"] = uniqid();
  105. if ($type == 0) {
  106. $add["phone"] = $phone;
  107. } else {
  108. $add["mail"] = $phone;
  109. }
  110. $add["name"] = $name;
  111. $add["uuid"] = uniqid();// 收款ID
  112. $uuid = Uuid::uuid1();
  113. $add["token"] = $uuid->getHex();;
  114. $add["add_time"] = time();
  115. $add["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
  116. // dump($add);die();
  117. User::create($add);
  118. json_result(200, "注册成功");
  119. }
  120. // 忘记密码 第一部
  121. public function forget_password()
  122. {
  123. $phone = trim(input("phone"));
  124. if (!$phone) json_result(400, "请输入手机号码或者邮箱");
  125. $type = input("type") ?: 0;
  126. $code = trim(input("code"));
  127. if (!$code) json_result(400, "请输入验证码");
  128. $name = trim(input("name"));
  129. // 查看账号是存在
  130. // $where["phone|mail"] = $phone;
  131. $where["name"] = $name;
  132. $user = User::where($where)->find();
  133. if (!$user) {
  134. json_result(400, "账号不存在");
  135. }
  136. // 验证码
  137. $phone_code = Tripartite::push_code($phone, $type);
  138. if ($phone_code != $code) {
  139. json_result(400, "验证码错误");
  140. }
  141. json_result(200, "验证码成功");
  142. }
  143. // 修改密码--第二步
  144. public function update_password()
  145. {
  146. $pwd = trim(input("pwd"));
  147. if (!$pwd) json_result(400, "请输入密码");
  148. $phone = trim(input("phone"));
  149. if (!$phone) json_result(400, "请输入手机号码或者邮箱");
  150. // 查看账号是存在
  151. $where["phone|mail"] = $phone;
  152. $user = User::where($where)->find();
  153. if (!$user) {
  154. json_result(400, "账号不存在");
  155. }
  156. $add["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
  157. User::where(["id" => $user->id])->update($add);
  158. json_result(200, "设置密码成功");
  159. }
  160. // 上传图片
  161. public function up_image()
  162. {
  163. // json_result(200,"eqweqw");
  164. // header('Control-type:image/*');
  165. // header('Origin:*');
  166. // header("Access-Control-Allow-Origin: *");
  167. // header("Accept:Application/json, text/plain, */*");
  168. // header("Access-Control-Allow-Methods:POST,GET");
  169. // header("Access-Control-Allow-Headers:x-requested-with,content-type");
  170. // header("Content-type:text/json;multipart/form-data;charset=utf-8");
  171. \app\web\model\Upfile::Uploadss();
  172. // json_result(200, "", $ret["url"]);
  173. }
  174. // 会员协议
  175. public function Membership()
  176. {
  177. $where["name"]="Membership";
  178. $data=System::where($where)->field("value")->find();
  179. json_result(200,"",$data->value?:"");
  180. }
  181. // 测试接口
  182. public function test()
  183. {
  184. // $eaml="www.794230322@outlook.com";
  185. // $eaml="3398530177@qq.com";
  186. // $data["user_email"]=$eaml;
  187. // $data["name"]=$eaml;
  188. // $data["content"]="【BTS】您的验证码是123456";
  189. // Mail::sendEmail($data);
  190. }
  191. }