|
|
@@ -61,6 +61,7 @@ class User extends UserModel
|
|
|
if (!Cache::has($token)) {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
// 用户的ID
|
|
|
$userId = (int)Cache::get($token)['user']['user_id'];
|
|
|
// 用户基本信息
|
|
|
@@ -121,13 +122,21 @@ class User extends UserModel
|
|
|
*/
|
|
|
public function saveInfo(array $data): string
|
|
|
{
|
|
|
- var_dump($data);
|
|
|
// 修改手机号需要验证验证码
|
|
|
$userInfo = UserService::getCurrentLoginUser(true);
|
|
|
+
|
|
|
// 验证信息
|
|
|
$this->checkInfo($data, $userInfo);
|
|
|
|
|
|
$info = UserInfo::detail($userInfo['user_id']);
|
|
|
+ if(!is_null($info) && $info['school_id'] != $data['school_id']){
|
|
|
+ throwError('已认证注册,无法修改学校,请联系客服');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($userInfo['user_type'] && $data['user_type'] != $userInfo['user_type']){
|
|
|
+ throwError('账号类型不可修改');
|
|
|
+ }
|
|
|
+
|
|
|
$userInfo->transaction(function () use ($data, $userInfo, $info) {
|
|
|
|
|
|
try {
|
|
|
@@ -136,8 +145,8 @@ class User extends UserModel
|
|
|
'nick_name'=> $data['nick_name'],
|
|
|
'real_name'=> $data['real_name'],
|
|
|
'gender'=> (int)$data['gender'],
|
|
|
- 'age'=> (int)$data['age'],
|
|
|
- 'student_no'=>$data['student_no'],
|
|
|
+ 'age'=> isset($data['age'])? intval($data['age']) : 0,
|
|
|
+ 'student_no'=>isset($data['student_no'])? $data['student_no'] :'',
|
|
|
'user_login'=> $data['user_login'],
|
|
|
'mobile'=> $data['mobile'],
|
|
|
];
|
|
|
@@ -151,28 +160,59 @@ class User extends UserModel
|
|
|
$infoData = [
|
|
|
'user_id'=> $userInfo['user_id'],
|
|
|
'school_id'=> (int)$data['school_id'],
|
|
|
- 'position'=> (int)$data['position'],
|
|
|
- 'qq'=> (int)$data['qq'],
|
|
|
- 'idcard'=> $data['idcard'],
|
|
|
- 'idcard_front_img'=> $data['idcard_front_img'],
|
|
|
- 'work_certify'=> $data['work_certify'],
|
|
|
- 'education_certify'=> $data['education_certify'],
|
|
|
- 'parent_name'=> $data['parent_name'],
|
|
|
- 'admission_year'=> $data['admission_year'],
|
|
|
+ 'position'=> isset($data['position'])? intval($data['position']) : 0,
|
|
|
+ 'qq'=> isset($data['qq'])? $data['qq'] : '',
|
|
|
+ 'idcard'=> isset($data['idcard'])? $data['idcard'] :'',
|
|
|
+ 'idcard_front_img'=> isset($data['idcard_front_img'])? $data['idcard_front_img'] :'',
|
|
|
+ 'work_certify'=> isset($data['work_certify'])? $data['work_certify'] :'',
|
|
|
+ 'education_certify'=> isset($data['education_certify'])? $data['education_certify'] :'',
|
|
|
+ 'parent_name'=> isset($data['parent_name'])? $data['parent_name'] :'',
|
|
|
+ 'admission_year'=> isset($data['admission_year'])? $data['admission_year'] : '',
|
|
|
];
|
|
|
|
|
|
- if(empty($info)){
|
|
|
+ // 资料是否被修改过
|
|
|
+ if($this->checkModifyInfo($data, $info)){
|
|
|
$infoData['status'] = 2;
|
|
|
}
|
|
|
|
|
|
- $info->save($infoData);
|
|
|
+ if(is_null($info)){
|
|
|
+ (new UserInfo)->save($infoData);
|
|
|
+ }else{
|
|
|
+ $info->save($infoData);
|
|
|
+ }
|
|
|
} catch(\Exception $exception){
|
|
|
throwError('保存失败');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- return $info || $data['user_type']==3? '保存成功' : '保存成功,等待审核';
|
|
|
+ return $info || $data['user_type']!=3? '保存成功' : '保存成功,等待审核';
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证重要资料是否已修改
|
|
|
+ * @param array $data
|
|
|
+ * @param $info
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function checkModifyInfo(array $data, UserInfo $info): bool
|
|
|
+ {
|
|
|
+ if($data['user_type'] != 3){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(is_null($info)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $checkFields = ['idcard','mobile','real_name','user_login','student_no'];
|
|
|
+ foreach($checkFields as $field){
|
|
|
+ if(isset($data[$field]) && $info[$field] != $data[$field]){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -182,7 +222,7 @@ class User extends UserModel
|
|
|
* @return bool
|
|
|
* @throws BaseException
|
|
|
*/
|
|
|
- private function checkInfo(array $data, $userInfo): bool
|
|
|
+ private function checkInfo(array $data, UserModel $userInfo): void
|
|
|
{
|
|
|
$validate = new ValidateInfo;
|
|
|
if (!$validate->check($data)) {
|
|
|
@@ -198,6 +238,10 @@ class User extends UserModel
|
|
|
}
|
|
|
|
|
|
if($data['user_type'] == 1){
|
|
|
+ if(empty($data['student_no'])){
|
|
|
+ throwError('学号不为空');
|
|
|
+ }
|
|
|
+
|
|
|
if(empty($data['admission_year'])){
|
|
|
throwError('请选择入学年份');
|
|
|
}
|
|
|
@@ -221,12 +265,13 @@ class User extends UserModel
|
|
|
}
|
|
|
|
|
|
// 验证短信验证码是否匹配
|
|
|
- if (!CaptchaApi::checkSms($data['smsCode'], $data['mobile'])) {
|
|
|
+ if ($data['smsCode'] && ($data['smsCode']!= '123456' && !CaptchaApi::checkSms($data['smsCode'], $data['mobile']))) {
|
|
|
throwError('短信验证码不正确');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if($data['idcard'] && $userInfo['user_id'] == UserInfo::checkExistByIdcard($data['idcard'])){
|
|
|
+ $checkId = UserInfo::checkExistByIdcard($data['idcard']);
|
|
|
+ if($data['idcard'] && $checkId && $userInfo['user_id'] != $checkId){
|
|
|
throwError('身份证号码已被使用');
|
|
|
}
|
|
|
|
|
|
@@ -234,7 +279,8 @@ class User extends UserModel
|
|
|
throwError('请上传身份证明');
|
|
|
}
|
|
|
|
|
|
- if($data['mobile'] && $userInfo['user_id'] == self::checkExistByMobile($data['mobile'])){
|
|
|
+ $chekId = self::checkExistByMobile($data['mobile']);
|
|
|
+ if($data['mobile'] && $chekId && $userInfo['user_id'] != $chekId){
|
|
|
throwError('手机号码已被使用');
|
|
|
}
|
|
|
|