|
@@ -46,28 +46,29 @@ class Login extends Controller
|
|
|
if (isset($data['user_tel']) && isset($data['user_pwd'])) {
|
|
|
$validata = $this->validate($data, $rules, $msg); //验证数据规则
|
|
|
if (is_string($validata)) {
|
|
|
- return json(['code' => 100, 'msg' => '','data' => $validata]);
|
|
|
+ return json(['code' => 100, 'msg' => '', 'data' => $validata]);
|
|
|
}
|
|
|
$valdatatel = UsersModel::where('user_tel', $data['user_tel'])->find(); //判断手机号是否存在
|
|
|
if ($valdatatel) {
|
|
|
$data['user_pwd'] = sha1(md5($data['user_pwd'])); //加密验证密码
|
|
|
$where = array(
|
|
|
- 'user_tel' => $data['user_tel'],
|
|
|
- 'user_pwd' => $data['user_pwd'],
|
|
|
+ 'user_tel' => $data['user_tel'],
|
|
|
+ 'user_pwd' => $data['user_pwd'],
|
|
|
);
|
|
|
$validatapwd = Db::name('users')->where($data)->field('user_id')->find(); //判断密码是否正确
|
|
|
+ if ($valdatatel['status_switch'] == 0) {
|
|
|
+ return json(['code' => 100, 'msg' => '此账号已被禁用', 'data' => []]);
|
|
|
+ }
|
|
|
if ($validatapwd) {
|
|
|
$validatapwd['token'] = self::settoken($validatapwd['user_id']);
|
|
|
- return json(['code' => 200, 'msg' => '登陆成功,欢迎回来哦','data' => $validatapwd]);
|
|
|
+ return json(['code' => 200, 'msg' => '登陆成功,欢迎回来哦', 'data' => $validatapwd]);
|
|
|
} else {
|
|
|
- return json(['code' => 100, 'msg' => '密码错误','data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => '密码错误', 'data' => []]);
|
|
|
}
|
|
|
} else {
|
|
|
- return json(['code' => 100, 'msg' => '手机号不存在','data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => '手机号不存在', 'data' => []]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -92,28 +93,33 @@ class Login extends Controller
|
|
|
];
|
|
|
$validata = $this->validate($params, $rules, $msg);
|
|
|
if (is_string($validata)) {
|
|
|
- return json(['code' => 100, 'msg' => '','data' => $validata]);
|
|
|
+ return json(['code' => 100, 'msg' => '', 'data' => $validata]);
|
|
|
}
|
|
|
- $validataopenid = UsersModel::where('user_unionid', $params['user_unionid'])->field('user_id')->find(); //判断QQ或者微信登录的openid是否正确
|
|
|
+ $validataopenid = UsersModel::where('user_unionid', $params['user_unionid'])->field('user_id,user_tel')->find(); //判断QQ或者微信登录的openid是否正确
|
|
|
if ($validataopenid) {
|
|
|
+ if ($validataopenid['user_tel'] == "") {
|
|
|
+ return json(['code' => 10, 'msg' => '请先绑定手机号', 'data' => $validataopenid]);
|
|
|
+ }
|
|
|
$validataopenid['token'] = self::settoken($validataopenid['user_id']);
|
|
|
- return json(['code' => 200, 'msg' => '登陆成功,欢迎回来哦','data' => $validataopenid]);
|
|
|
+ return json(['code' => 200, 'msg' => '登陆成功,欢迎回来哦', 'data' => $validataopenid]);
|
|
|
} else {
|
|
|
- $data = array(
|
|
|
- 'user_nickname' => $params['user_nickname'],
|
|
|
- 'user_avatar' => $params['user_avatar'],
|
|
|
- 'create_time' => date('Y-m-d H:i:s', time()),
|
|
|
- 'user_unionid' => $params['user_unionid'],
|
|
|
- 'type' => 1,
|
|
|
- );
|
|
|
- $userId['user_id'] = Db::name('users')->insertGetId($data);
|
|
|
- if ($userId) {
|
|
|
- return json(['code' => 100, 'msg' => '请先绑定手机号','data' => []]);
|
|
|
- } else {
|
|
|
- return json(['code' => 100, 'msg' => '登录失败','data' => []]);
|
|
|
- }
|
|
|
+ return json(['code' => 10, 'msg' => '请先绑定手机号', 'data' => $params]);
|
|
|
+// $data = array(
|
|
|
+// 'user_nickname' => $params['user_nickname'],
|
|
|
+// 'user_avatar' => $params['user_avatar'],
|
|
|
+// 'create_time' => date('Y-m-d H:i:s', time()),
|
|
|
+// 'user_unionid' => $params['user_unionid'],
|
|
|
+// 'type' => 1,
|
|
|
+// );
|
|
|
+// $userId['user_id'] = Db::name('users')->insertGetId($data);
|
|
|
+// if ($userId) {
|
|
|
+// return json(['code' => 10, 'msg' => '请去绑定手机号', 'data' => []]);
|
|
|
+// } else {
|
|
|
+// return json(['code' => 100, 'msg' => '登录失败', 'data' => []]);
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* QQ登录
|
|
|
* @ApiMethod (POST)
|
|
@@ -136,92 +142,128 @@ class Login extends Controller
|
|
|
];
|
|
|
$validata = $this->validate($params, $rules, $msg);
|
|
|
if (is_string($validata)) {
|
|
|
- return json(['code' => 100, 'msg' => '','data' => $validata]);
|
|
|
+ return json(['code' => 100, 'msg' => '', 'data' => $validata]);
|
|
|
}
|
|
|
- $validataopenid = UsersModel::where('user_unionid', $params['user_unionid'])->field('user_id')->find(); //判断QQ或者微信登录的openid是否正确
|
|
|
+ $validataopenid = UsersModel::where('user_unionid', $params['user_unionid'])->field('user_id,user_tel')->find(); //判断QQ或者微信登录的openid是否正确
|
|
|
$validataopenid['token'] = self::settoken($validataopenid['user_id']);
|
|
|
if ($validataopenid) {
|
|
|
- return json(['code' => 200, 'msg' => '登陆成功,欢迎回来哦','data' => $validataopenid]);
|
|
|
- } else {
|
|
|
- $data = array(
|
|
|
- 'user_nickname' => $params['user_nickname'],
|
|
|
- 'user_avatar' => $params['user_avatar'],
|
|
|
- 'create_time' => $params('Y-m-d H:i:s', time()),
|
|
|
- 'user_tjtel' => $params['user_tjtel'],
|
|
|
- 'user_unionid' => $params['user_openid'],
|
|
|
- 'type' => $params['type'],
|
|
|
- );
|
|
|
- $userId['user_id'] = Db::name('users')->insertGetId($params);
|
|
|
- if ($userId) {
|
|
|
- return json(['code' => 100, 'msg' => '请先绑定手机号','data' => []]);
|
|
|
- } else {
|
|
|
- return json(['code' => 100, 'msg' => '登录失败','data' => []]);
|
|
|
+ if ($validataopenid['user_tel'] == "") {
|
|
|
+ return json(['code' => 10, 'msg' => '请先绑定手机号', 'data' => $validataopenid]);
|
|
|
}
|
|
|
+ return json(['code' => 200, 'msg' => '登陆成功,欢迎回来哦', 'data' => $validataopenid]);
|
|
|
+ } else {
|
|
|
+ return json(['code' => 10, 'msg' => '请先绑定手机号', 'data' => $params]);
|
|
|
+// $data = array(
|
|
|
+// 'user_nickname' => $params['user_nickname'],
|
|
|
+// 'user_avatar' => $params['user_avatar'],
|
|
|
+// 'create_time' => $params('Y-m-d H:i:s', time()),
|
|
|
+// 'user_tjtel' => $params['user_tjtel'],
|
|
|
+// 'user_unionid' => $params['user_openid'],
|
|
|
+// 'type' => 2,
|
|
|
+// );
|
|
|
+// $userId['user_id'] = Db::name('users')->insertGetId($params);
|
|
|
+// if ($userId) {
|
|
|
+//
|
|
|
+// return json(['code' => 10, 'msg' => '请先绑定手机号','data' => []]);
|
|
|
+// } else {
|
|
|
+// return json(['code' => 100, 'msg' => '登录失败','data' => []]);
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 添加登录手机号登录
|
|
|
* @ApiMethod (POST)
|
|
|
- * @param string $user_id 用户ID
|
|
|
* @param string $user_tel 用户手机号
|
|
|
* @param string $code 验证码
|
|
|
* @param string $user_tjtel 用户手机号
|
|
|
+ * @param string $user_nickname 昵称
|
|
|
+ * @param string $user_avatar 头像
|
|
|
+ * @param string $user_unionid unionID
|
|
|
+ * @param string $type 0手机号1微信2QQ
|
|
|
*/
|
|
|
public function addUserTel()
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$rules = [
|
|
|
- 'user_id' => 'require|number',
|
|
|
+ // 'user_id' => 'require|number',
|
|
|
'code' => 'require|number',
|
|
|
'user_tel' => 'require|number',
|
|
|
'user_tjtel' => 'require|number',
|
|
|
- 'token' => 'require',
|
|
|
+ //'token' => 'require',
|
|
|
];
|
|
|
$msg = [
|
|
|
- 'user_id.require' => '网络错误1',
|
|
|
+ //'user_id.require' => '网络错误1',
|
|
|
'code .require' => '网络错误2',
|
|
|
'user_tel.require' => '手机号不能为空',
|
|
|
'user_tjtel.require' => '推荐人手机号不能为空',
|
|
|
- 'token.require' => '网络错误3',
|
|
|
- 'user_id.number' => '网络错误4',
|
|
|
+ //'token.require' => '网络错误3',
|
|
|
+ // 'user_id.number' => '网络错误4',
|
|
|
'code.number' => '网络错误5',
|
|
|
'user_tel.number' => '网络错误6',
|
|
|
'user_tjtel.number' => '网络错误7',
|
|
|
];
|
|
|
$validate = $this->validate($params, $rules, $msg);
|
|
|
if (is_string($validate)) {
|
|
|
- return json(['code' => 100, 'msg' => $validate,'data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => $validate, 'data' => []]);
|
|
|
}
|
|
|
$check = '/^(1(([35789][0-9])|(47)))\d{8}$/';
|
|
|
if (!preg_match($check, $params['user_tel'])) {
|
|
|
- return json(['code' => 100, 'msg' => '手机号不合法','data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => '手机号不合法', 'data' => []]);
|
|
|
}
|
|
|
//检查数据库是否有此推荐人手机号
|
|
|
$user_tjtel = UsersModel::where('user_tel', $params['user_tjtel'])->find();
|
|
|
if (!$user_tjtel) {
|
|
|
- return json(['code' => 100, 'msg' => '无此推荐人','data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => '无此推荐人', 'data' => []]);
|
|
|
}
|
|
|
//判断验证码是否正确
|
|
|
if (!Cache::get($params['code'])) {
|
|
|
- return json(['code' => 100, 'msg' => '验证码不正确','data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => '验证码不正确', 'data' => []]);
|
|
|
+ }
|
|
|
+ //Cache::rm($params['code']);
|
|
|
+ // 判断是否有此手机号
|
|
|
+ $user_tel = UsersModel::where('user_tel', $params['user_tel'])->find();
|
|
|
+ if ($user_tel) {
|
|
|
+ $upddata = array(
|
|
|
+ 'user_tjtel' => $params['user_tjtel'],
|
|
|
+ 'type' => $params['type'],
|
|
|
+ 'create_time' => date('Y-m-d H:i:s', time()),
|
|
|
+ 'user_unionid' => $params['user_unionid'],
|
|
|
+ 'user_nickname' => $params['user_nickname'],
|
|
|
+ 'user_avatar' => $params['user_avatar'],
|
|
|
+ );
|
|
|
+ $addUserMember = Db::name('Users')->where('user_tel', $params['user_tjtel'])->setInc('user_member_count', 1); // 给上机的下级成员总数加1
|
|
|
+ $updUsertelAndwechat = Db::name('users')->where('user_id', $user_tel['user_id'])->update($upddata);
|
|
|
+ if ($updUsertelAndwechat) {
|
|
|
+ $token = self::settoken($user_tel['user_id']);
|
|
|
+ $res = array(
|
|
|
+ "user_id" => $user_tel['user_id'],
|
|
|
+ "token" => $token,
|
|
|
+ );
|
|
|
+ return json(['code' => 200, 'msg' => '绑定成功', 'data' => $res]);
|
|
|
+ } else {
|
|
|
+ return json(['code' => 100, 'msg' => '绑定失败', 'data' => []]);
|
|
|
+ }
|
|
|
}
|
|
|
- Cache::rm($params['code']);
|
|
|
- $upddata = array(
|
|
|
- 'user_tel' => $params['user_tel'],
|
|
|
- 'user_tjtel' => $params['user_tjtel'],
|
|
|
- 'type' => 1,
|
|
|
+ $data = array(
|
|
|
+ 'user_tel' => $params['user_tel'],
|
|
|
+ 'user_tjtel' => $params['user_tjtel'],
|
|
|
+ 'type' => $params['type'],
|
|
|
+ 'create_time' => date('Y-m-d H:i:s', time()),
|
|
|
+ 'user_unionid' => $params['user_unionid'],
|
|
|
+ 'user_nickname' => $params['user_nickname'],
|
|
|
+ 'user_avatar' => $params['user_avatar'],
|
|
|
);
|
|
|
- $updUser_tel = Db::name('users')->where('user_id', $params['user_id'])->update($upddata);
|
|
|
- if ($updUser_tel) {
|
|
|
- $token = self::settoken($params['user_id']);
|
|
|
+ $adduser = Db::name('users')->insertGetId($data);
|
|
|
+ if ($adduser) {
|
|
|
+ $token = self::settoken($adduser);
|
|
|
$res = array(
|
|
|
- "user_id" => $params['user_id'],
|
|
|
+ "user_id" => $adduser,
|
|
|
"token" => $token,
|
|
|
);
|
|
|
- return json(['code' => 200, 'msg' => '绑定成功','data' => []]);
|
|
|
+ return json(['code' => 200, 'msg' => '绑定成功', 'data' => $res]);
|
|
|
} else {
|
|
|
- Db::name('users')->where('user_id',$params['user_id'])->delete(); // 绑定失败删除此用户
|
|
|
- return json(['code' => 100, 'msg' => '绑定失败','data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => '绑定失败', 'data' => []]);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -236,7 +278,7 @@ class Login extends Controller
|
|
|
$tel = UsersModel::where('user_tel', $tel)->find();
|
|
|
$num = count($tel);
|
|
|
if ($num > 0) {
|
|
|
- return json(['code' => 100, 'msg' => '手机号已存在','data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => '手机号已存在', 'data' => []]);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -248,9 +290,9 @@ class Login extends Controller
|
|
|
{
|
|
|
$data = Db::name('agreement')->where('type', 0)->find();
|
|
|
if ($data) {
|
|
|
- return json(['code' => 200, 'msg' => '绑定成功','data' => $data]);
|
|
|
+ return json(['code' => 200, 'msg' => '绑定成功', 'data' => $data]);
|
|
|
} else {
|
|
|
- return json(['code' => 100, 'msg' => '网络错误','data' => []]);
|
|
|
+ return json(['code' => 100, 'msg' => '网络错误', 'data' => []]);
|
|
|
}
|
|
|
}
|
|
|
|