Login.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\Config;
  4. use app\common\model\User;
  5. use app\common\controller\Api;
  6. use think\Db;
  7. use think\facade\Validate;
  8. /**
  9. * @title 登录注册
  10. * @controller Login
  11. * @group user
  12. */
  13. class Login extends Api
  14. {
  15. /**
  16. * @title 注册
  17. * @desc 注册
  18. * @url /api/Login/register
  19. * @method POST
  20. * @tag 基础
  21. * @header
  22. * @param name:phone type:string require:1 desc:手机号
  23. * @param name:password type:string require:1 desc:密码
  24. * @param name:ver_code type:string require:1 desc:验证码
  25. * @param name:invite_code type:string require:0 desc:邀请码
  26. */
  27. public function register(){
  28. $phone = input('phone'); //手机号
  29. $password = input('password'); //密码
  30. $ver_code = input('ver_code'); //验证码
  31. $invite_code = input('invite_code'); //邀请码
  32. if (!$phone || !$password){
  33. $this->error('参数错误');
  34. }
  35. if (!Validate::regex($phone, "^1\d{10}$")) {
  36. $this->error('手机号格式错误');
  37. }
  38. $us = User::register($phone,$password,$ver_code,$invite_code);
  39. if ($us['code']){
  40. $this->success($us['msg'],$us['data']);
  41. }else{
  42. $this->error($us['msg']);
  43. }
  44. }
  45. /**
  46. * @title 登录
  47. * @desc 登录
  48. * @url /api/Login/login
  49. * @method POST
  50. * @tag 基础
  51. * @header
  52. * @param name:phone type:string require:1 desc:手机号
  53. * @param name:type type:string require:1 desc:1:密码登录2:验证码登录
  54. * @param name:password type:string require:0 desc:密码(密码登录时传)
  55. * @param name:ver_code type:string require:0 desc:验证码(验证码登录时传)
  56. * @param name:come type:int require:0 desc:1:用户端2:设计师端(默认为1)
  57. *
  58. *
  59. * @return name:token type:string desc:token
  60. * @return name:type type:int desc:1:未申请2:待审核3:审核失败4:登录成功
  61. */
  62. public function login(){
  63. $phone = input('phone'); //手机号
  64. $type = input('type',1); //1:密码登录 2:验证码登录
  65. $password = input('password'); //密码
  66. $ver_code = input('ver_code'); //验证码
  67. $come = input('come',1); //1:用户端2:设计师端(默认为1)
  68. if (!$phone || !Validate::regex($phone, "^1\d{10}$")) {
  69. $this->error('手机号格式错误');
  70. }
  71. if (!in_array($type,['1','2'])){
  72. $this->error('非法操作');
  73. }
  74. if ($type==1){
  75. if (!$password){
  76. $this->error('密码为空');
  77. }
  78. }elseif ($type==2){
  79. if (!$ver_code){
  80. $this->error('短信验证码为空');
  81. }
  82. }
  83. $result = User::login($phone,$password,$type,$ver_code,$come);
  84. if ($result['code']){
  85. $this->success($result['msg'],$result['data']);
  86. }else{
  87. $this->error($result['msg']);
  88. }
  89. }
  90. /**
  91. * @title 忘记密码
  92. * @desc 忘记密码
  93. * @url /api/Login/forgot_password
  94. * @method POST
  95. * @tag 基础
  96. * @header
  97. * @param name:phone type:string require:1 desc:手机号
  98. * @param name:password type:string require:0 desc:密码
  99. * @param name:ver_code type:string require:0 desc:验证码
  100. *
  101. */
  102. public function forgot_password(){
  103. $phone = input('phone'); //手机号
  104. $password = input('password'); //密码
  105. $ver_code = input('ver_code'); //验证码
  106. if (!$phone || !$password){
  107. $this->error('参数错误');
  108. }
  109. if (!$phone || !Validate::regex($phone, "^1\d{10}$")) {
  110. $this->error('手机号格式错误');
  111. }
  112. $result = User::forgotPassword($phone,$password,$ver_code);
  113. if ($result['code']){
  114. $this->success($result['msg'],$result['data']);
  115. }else{
  116. $this->error($result['msg']);
  117. }
  118. }
  119. /**
  120. * @title 微信授权登录
  121. * @desc 微信授权登录
  122. * @url /api/Login/wechat_login
  123. * @method POST
  124. * @tag 基础
  125. * @header
  126. * @param name:code type:string require:1 desc:微信code
  127. *
  128. */
  129. public function wechat_login(){
  130. $code = input('code');
  131. if (!$code) $this->error('code为空');
  132. $result = User::wechatLogin($code);
  133. if ($result['code']){
  134. $this->success($result['msg'],$result['data']);
  135. }else{
  136. $this->error($result['msg']);
  137. }
  138. }
  139. /**
  140. * @title 微信授权绑定手机号信息
  141. * @desc 微信授权绑定手机号信息
  142. * @url /api/Login/wechat_login_bind_phone
  143. * @method POST
  144. * @tag 基础
  145. * @header
  146. * @param name:code type:string require:1 desc:微信code
  147. * @param name:rawData type:string require:1 desc:用户信息
  148. * @param name:phone type:string require:1 desc:手机号
  149. * @param name:ver_code type:string require:1 desc:验证码
  150. * @param name:password type:string require:1 desc:密码
  151. *
  152. */
  153. public function wechat_login_bind_phone(){
  154. $code = input('code');
  155. if (!$code) $this->error('code为空');
  156. $rawData = input('rawData'); //用户信息
  157. $phone = input('phone'); //手机号
  158. $ver_code = input('ver_code'); //验证码
  159. $password = input('password'); //密码
  160. if (!$phone || !Validate::regex($phone, "^1\d{10}$")) {
  161. $this->error('手机号格式错误');
  162. }
  163. if (!$ver_code){
  164. $this->error('短信验证码为空');
  165. }
  166. if (!$password){
  167. $this->error('密码为空');
  168. }
  169. $result = User::wechatLoginBindPhone($code,$rawData,$phone,$ver_code,$password);
  170. if ($result['code']){
  171. $this->success($result['msg'],$result['data']);
  172. }else{
  173. $this->error($result['msg']);
  174. }
  175. }
  176. /**
  177. * @title 设计师注册
  178. * @desc 设计师注册
  179. * @url /api/Login/designer_register
  180. * @method POST
  181. * @tag 基础
  182. * @header
  183. * @param name:type type:int require:1 desc:1:第一页验证手机号、验证码2:填写设计师信息
  184. * @param name:phone type:string require:1 desc:手机号
  185. * @param name:ver_code type:string require:1 desc:验证码
  186. * @param name:password type:string require:1 desc:密码
  187. *
  188. * @param name:name type:string require:1 desc:姓名
  189. * @param name:design_classifi type:string require:1 desc:设计分类
  190. * @param name:skills_label type:string require:1 desc:技能标签
  191. * @param name:good_type type:string require:1 desc:擅长类型
  192. * @param name:province type:string require:1 desc:省
  193. * @param name:city type:string require:1 desc:市
  194. * @param name:area type:string require:1 desc:区
  195. * @param name:work_year type:string require:1 desc:工作年限
  196. * @param name:identity_card_zheng type:string require:1 desc:身份证正面
  197. * @param name:identity_card_fan type:string require:1 desc:身份证反面
  198. * @param name:related_certificate type:string require:1 desc:相关证书,数组
  199. * @param name:works type:string require:1 desc:作品,数组
  200. * @param name:wd type:string require:1 desc:当前位置纬度
  201. * @param name:jd type:string require:1 desc:当前位置经度
  202. *
  203. *
  204. *
  205. *
  206. * @return name:type type:int desc:1:手机号未注册2:手机号已注册,未申请成为设计师或者正在审核中
  207. */
  208. public function designer_register(){
  209. $phone = input('phone'); //手机号
  210. $password = input('password'); //密码
  211. $ver_code = input('ver_code'); //验证码
  212. $type = input('type'); //1:第一页验证手机号、验证码 2:填写商家信息
  213. if (!$phone || !Validate::regex($phone, "^1\d{10}$")) {
  214. $this->error('手机号格式错误');
  215. }
  216. if (!in_array($type,['1','2'])){
  217. $this->error('非法操作');
  218. }
  219. if ($type==1){
  220. if (!$phone || !$password || !$password){
  221. $this->error('参数错误');
  222. }
  223. $result = User::designer_register_one($phone,$ver_code);
  224. }else{
  225. $data['phone'] = $phone;
  226. $data['name'] = input('name'); //姓名
  227. $data['design_classifi'] = input('design_classifi'); //设计分类
  228. $data['skills_label'] = input('skills_label'); //技能标签
  229. $data['good_type'] = input('good_type'); //擅长类型
  230. $data['province'] = input('province'); //省
  231. $data['city'] = input('city'); //市
  232. $data['area'] = input('area'); //区
  233. $data['work_year'] = input('work_year'); //工作年限
  234. $data['identity_card_zheng'] = input('identity_card_zheng'); //身份证正面
  235. $data['identity_card_fan'] = input('identity_card_fan'); //身份证反面
  236. $data['related_certificate'] = input('related_certificate'); //相关证书
  237. $data['works'] = input('works'); //作品
  238. $data['wd'] = input('wd'); //当前位置纬度
  239. $data['jd'] = input('jd'); //当前位置经度
  240. if (!$data['name'] || !$data['design_classifi'] || !$data['design_classifi'] || !$data['skills_label'] || !$data['good_type'] || !$data['identity_card_zheng'] || !$data['identity_card_fan'] || !$data['province']
  241. || !$data['city'] || !$data['area'] || !$data['work_year'] || !$data['works']){
  242. $this->error('参数错误');
  243. }
  244. $data['related_certificate'] = implode(',',$data['related_certificate']);
  245. $data['works'] = implode(',',$data['works']);
  246. $data['skills_label'] = implode(',',$data['skills_label']);
  247. $data['good_type'] = implode(',',$data['good_type']);
  248. $result = User::designer_register_two($data);
  249. }
  250. if ($result['code']){
  251. $this->success($result['msg'],$result['data']);
  252. }else{
  253. $this->error($result['msg']);
  254. }
  255. }
  256. }