|
@@ -0,0 +1,78 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\api\model\UsersModel;
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 登录接口
|
|
|
+ */
|
|
|
+class Login extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = '*';
|
|
|
+ protected $noNeedRight = '*';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 会员登录
|
|
|
+ *
|
|
|
+ * @param string $user_tel 账号
|
|
|
+ * @param string $user_pwd 密码
|
|
|
+ * @param string $user_openid qq或者微信openID
|
|
|
+ */
|
|
|
+ public function Login()
|
|
|
+ {
|
|
|
+ $data = $this->request->post();
|
|
|
+ $rules = [
|
|
|
+ 'user_tel' => 'require|max:11|number|min:11',
|
|
|
+ 'user_pwd' => 'require|max:25|min:6'
|
|
|
+ ];
|
|
|
+ $msg = [
|
|
|
+ 'user_tel.require' => '手机号不能为空',
|
|
|
+ 'user_tel.max' => '手机号长度不正确',
|
|
|
+ 'user_tel.min' => '手机号长度不正确',
|
|
|
+ 'user_tel.number' => '手机号必须为数字',
|
|
|
+ 'user_pwd.require' => '密码不能为空',
|
|
|
+ 'user_pwd.max' => '密码长度过长',
|
|
|
+ 'user_pwd.min' => '密码长度不足',
|
|
|
+ ];
|
|
|
+ if (isset($data['user_tel']) && isset($data['user_pwd'])) {
|
|
|
+ $validata = $this->validate($data, $rules, $msg); //验证数据规则
|
|
|
+ if (is_string($validata)) {
|
|
|
+ return $this->result($validata, [], 100);
|
|
|
+ }
|
|
|
+ $valdatatel = UsersModel::where('user_tel', $data['user_tel'])->find(); //判断手机号是否存在
|
|
|
+ if ($valdatatel) {
|
|
|
+ $data['user_pwd'] = sha1(md5($data['user_pwd'])); //加密验证密码
|
|
|
+ $validatapwd = UsersModel::where('user_pwd', $data['user_pwd'])->where('user_tel', $data['user_tel'])->find(); //判断密码是否正确
|
|
|
+ if ($validatapwd) {
|
|
|
+ return $this->result('登录成功,欢迎回来', $validatapwd, 200);
|
|
|
+ } else {
|
|
|
+ return $this->result('密码错误', [], 100);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return $this->result('手机号不存在', [], 100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isset($data['openid'])) {
|
|
|
+ $validataopenid = UsersModel::where('user_openid', $data['openid'])->find(); //判断QQ或者微信登录的openid是否正确
|
|
|
+ if ($validataopenid) {
|
|
|
+ return $this->result('登陆成功,欢迎回来', $validataopenid, 200);
|
|
|
+ } else {
|
|
|
+ return $this->result('暂无该用户', [], 100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //验证手机号是否已存在
|
|
|
+ public function validatatel($tel)
|
|
|
+ {
|
|
|
+ $tel = UsersModel::where('user_tel', $tel)->find();
|
|
|
+ $num = count($tel);
|
|
|
+ if ($num > 0) {
|
|
|
+ return $this->result('手机号已存在', [], 100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|