| xqd
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
|
|
|
use App\Http\Params\ProblemParam;
|
|
|
use App\Models\User;
|
|
|
use App\Models\UserInfoModel;
|
|
|
+use App\Models\UserInviteLog;
|
|
|
use App\Models\UserVipLogModel;
|
|
|
use App\Models\VipConfig;
|
|
|
use App\Models\VipModel;
|
| xqd
@@ -70,34 +71,42 @@ class UserController extends Controller
|
|
|
public function setinfo(Request $request){
|
|
|
$user = auth('api')->user();
|
|
|
|
|
|
- $validator = Validator::make($request->all(), [
|
|
|
- 'nickname' => 'required|between:2,10',
|
|
|
- 'birthday' => 'required',
|
|
|
- 'avatar' => 'required',
|
|
|
- ], [
|
|
|
- 'nickname.required'=>"昵称不能为空",
|
|
|
- 'nickname.between'=>"昵称长度必须在2~10之间",
|
|
|
- 'birthday.required'=>"生日不能为空",
|
|
|
- 'avatar.required'=>"头像不能为空",
|
|
|
- ]);
|
|
|
- if ($validator->fails()) {
|
|
|
- return $this->response()->errorForbidden($validator->messages()->first());
|
|
|
- }
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'nickname' => 'required|between:2,10',
|
|
|
+ 'birthday' => 'required',
|
|
|
+ 'avatar' => 'required',
|
|
|
+ ], [
|
|
|
+ 'nickname.required'=>"昵称不能为空",
|
|
|
+ 'nickname.between'=>"昵称长度必须在2~10之间",
|
|
|
+ 'birthday.required'=>"生日不能为空",
|
|
|
+ 'avatar.required'=>"头像不能为空",
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ throw new Exception($validator->messages()->first());
|
|
|
+ }
|
|
|
|
|
|
- if(UserInfoModel::where(['nickname'=>$request->nickname])->where('user_id', '!=' , $user->id)->first()){
|
|
|
- return $this->response->errorForbidden('昵称已被使用');
|
|
|
- }
|
|
|
- //邀请码设置
|
|
|
- $pid = 0;
|
|
|
- if(isset($request->ycode) && $request->ycode!=""){
|
|
|
- if(!$puser = User::where(['ycode'=>$request->ycode])->first()){
|
|
|
- return $this->response->errorForbidden("邀请码不存在");
|
|
|
+ if(UserInfoModel::where(['nickname'=>$request->nickname])->where('user_id', '!=' , $user->id)->first()){
|
|
|
+ throw new Exception("昵称已被使用");
|
|
|
+ }
|
|
|
+ //邀请码设置
|
|
|
+ $pid = 0;
|
|
|
+ if(isset($request->ycode) && $request->ycode!=""){
|
|
|
+ if(!$puser = User::where(['ycode'=>$request->ycode])->first()){
|
|
|
+ throw new Exception("邀请码不存在");
|
|
|
+ }
|
|
|
+ $pid = $puser->id;
|
|
|
+
|
|
|
+ //赠送会员天数
|
|
|
+ UserInviteLog::query()->create([
|
|
|
+ 'user_id'=>$pid,
|
|
|
+ 'invite_id'=>$user->id,
|
|
|
+ 'day'=>1,
|
|
|
+ 'status'=>0,
|
|
|
+ ]);
|
|
|
}
|
|
|
- $pid = $puser->id;
|
|
|
- }
|
|
|
|
|
|
- DB::beginTransaction();
|
|
|
- try {
|
|
|
UserInfoModel::firstOrCreate([
|
|
|
'user_id' => $user->id,
|
|
|
'avatar' =>$request->avatar,
|
| xqd
@@ -105,13 +114,13 @@ class UserController extends Controller
|
|
|
'birthday' =>$request->birthday,
|
|
|
]);
|
|
|
if($pid!=0){
|
|
|
- $user->pid = $pid;
|
|
|
- $user->save();
|
|
|
+ $user->pid = $pid;
|
|
|
+ $user->save();
|
|
|
}
|
|
|
DB::commit();
|
|
|
- } catch (\Exception $e) {
|
|
|
+ }catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
|
- return $this->response->errorForbidden($e->getMessage());
|
|
|
+ return $this->response()->errorForbidden($exception->getMessage());
|
|
|
}
|
|
|
return response()->json(['message'=>"设置成功"]);
|
|
|
}
|