|
@@ -12,6 +12,7 @@ declare (strict_types=1);
|
|
|
|
|
|
|
|
namespace app\api\model;
|
|
namespace app\api\model;
|
|
|
|
|
|
|
|
|
|
+use app\api\validate\user\Info as ValidateInfo;
|
|
|
use think\facade\Cache;
|
|
use think\facade\Cache;
|
|
|
use app\api\service\User as UserService;
|
|
use app\api\service\User as UserService;
|
|
|
use app\api\model\UserOauth as UserOauthModel;
|
|
use app\api\model\UserOauth as UserOauthModel;
|
|
@@ -112,4 +113,129 @@ class User extends UserModel
|
|
|
throwError('很抱歉,该手机号已绑定其他账户');
|
|
throwError('很抱歉,该手机号已绑定其他账户');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param array $data
|
|
|
|
|
+ * @return string
|
|
|
|
|
+ * @throws BaseException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function saveInfo(array $data): string
|
|
|
|
|
+ {
|
|
|
|
|
+ // 修改手机号需要验证验证码
|
|
|
|
|
+ $userInfo = UserService::getCurrentLoginUser(true);
|
|
|
|
|
+ // 验证信息
|
|
|
|
|
+ $this->checkInfo($data, $userInfo);
|
|
|
|
|
+
|
|
|
|
|
+ $info = UserInfo::detail($userInfo['user_id']);
|
|
|
|
|
+ $userInfo->transaction(function () use ($data, $userInfo, $info) {
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ $userData = [
|
|
|
|
|
+ 'user_id'=> $userInfo['user_id'],
|
|
|
|
|
+ 'nick_name'=> $data['nick_name'],
|
|
|
|
|
+ 'real_name'=> $data['real_name'],
|
|
|
|
|
+ 'gender'=> (int)$data['gender'],
|
|
|
|
|
+ 'age'=> (int)$data['age'],
|
|
|
|
|
+ 'student_no'=>$data['student_no'],
|
|
|
|
|
+ 'user_login'=> $data['user_login'],
|
|
|
|
|
+ 'mobile'=> $data['mobile'],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if($userInfo['user_type']<=0){
|
|
|
|
|
+ $userData['user_type'] = (int)$data['user_type'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $userInfo->save($userData);
|
|
|
|
|
+
|
|
|
|
|
+ $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'],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ if(empty($info)){
|
|
|
|
|
+ $infoData['status'] = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $info->save($infoData);
|
|
|
|
|
+ } catch(\Exception $exception){
|
|
|
|
|
+ throwError('保存失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return $info || $data['user_type']==3? '保存成功' : '保存成功,等待审核';
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 验证用户信息
|
|
|
|
|
+ * @param array $data
|
|
|
|
|
+ * @param array $userInfo
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ * @throws BaseException
|
|
|
|
|
+ */
|
|
|
|
|
+ private function checkInfo(array $data, array $userInfo): bool
|
|
|
|
|
+ {
|
|
|
|
|
+ $validate = new ValidateInfo;
|
|
|
|
|
+ if (!$validate->check($data)) {
|
|
|
|
|
+ throwError($validate->getError());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($data['user_type'] == 2 && empty($data['parent_name'])){
|
|
|
|
|
+ throwError('家长姓名不为空');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(empty($data['school_id'])){
|
|
|
|
|
+ throwError('学校不为空');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($data['user_type'] == 1){
|
|
|
|
|
+ if(empty($data['admission_year'])){
|
|
|
|
|
+ throwError('请选择入学年份');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(empty($data['education_certify'])){
|
|
|
|
|
+ throwError('请上传教育证明');
|
|
|
|
|
+ }
|
|
|
|
|
+ }else if($data['user_type'] == 3){
|
|
|
|
|
+ if(empty($data['position'])){
|
|
|
|
|
+ throwError('请选择职务');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(empty($data['work_certify'])){
|
|
|
|
|
+ throwError('请上传职务证明');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($userInfo['mobile'] != $data['mobile']) {
|
|
|
|
|
+ if (empty($data['smsCode'])) {
|
|
|
|
|
+ throwError('短信验证码不为空');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 验证短信验证码是否匹配
|
|
|
|
|
+ if (!CaptchaApi::checkSms($data['smsCode'], $data['mobile'])) {
|
|
|
|
|
+ throwError('短信验证码不正确');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($data['idcard'] && $userInfo['user_id'] == UserInfo::checkExistByIdcard($data['idcard'])){
|
|
|
|
|
+ throwError('身份证号码已被使用');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(empty($data['idcard_front_img'])){
|
|
|
|
|
+ throwError('请上传身份证明');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($data['mobile'] && $userInfo['user_id'] == self::checkExistByMobile($data['mobile'])){
|
|
|
|
|
+ throwError('手机号码已被使用');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|