xiaogang 4 роки тому
батько
коміт
f1538f17a7

+ 42 - 41
app/Http/Controllers/Api/AuthorizationsController.php

xqd xqd xqd
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
 use App\Exceptions\SmsException;
 use App\Models\AdminRole;
 use App\Models\User;
+use App\Models\UserInviteLog;
 use App\Services\SmsService;
 use App\Services\TencentImAccountService;
 use App\Transformers\UserTransformer;
@@ -14,6 +15,7 @@ use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Validator;
+use PHPUnit\Util\Exception;
 
 
 class AuthorizationsController extends Controller
@@ -213,54 +215,53 @@ class AuthorizationsController extends Controller
                 'message'=>$validator->messages()->first()
             ]);
         }
-//        try {
-//            //验证短信验证码
-//            SmsService::checkSmsCodeByVerifyKey($request->verifyKey, $request->smsCode);
-//        } catch (SmsException $e) {
-//            return response()->json([
-//                'code'=>0,
-//                'message'=>$e->getMessage()
-//            ]);
-//        } catch (\Exception $e) {
-//            return response()->json([
-//                'code'=>0,
-//                'message'=>'短信校验失败'
-//            ]);
-//        }
-        if(User::where(['mobile'=>$request->mobile])->first()){
-            return response()->json([
-                'code'=>0,
-                'message'=>'该手机号码已使用'
-            ]);
-        }
-        //邀请码设置
-        $pid = 0;
-        if(isset($request->ycode) && $request->ycode!=""){
-            if(!$puser = User::where(['ycode'=>$request->ycode])->first()){
-                return response()->json([
-                    'code'=>0,
-                    'message'=>'邀请码不存在'
-                ]);
-            }
-            $pid = $puser->id;
-        }
 
-        $ins = array();
-        $ins['mobile'] = $request->mobile;
-        $ins['password'] = $request->password;
-        $ins['pid'] = $pid;
-        if(User::create($ins)){
+
+
+        try {
+            //验证短信验证码
+            SmsService::checkSmsCodeByVerifyKey($request->verifyKey, $request->smsCode);
+
+            if(User::where(['mobile'=>$request->mobile])->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;
+            }
+            $ins = array();
+            $ins['mobile'] = $request->mobile;
+            $ins['password'] = $request->password;
+            $ins['pid'] = $pid;
+            $ins['created_at'] = date('Y-m-d H:i:s');
+            $ins['updated_at'] = date('Y-m-d H:i:s');
+            $insid = User::query()->insertGetId($ins);
+            //赠送会员天数
+            UserInviteLog::query()->create([
+                'user_id'=>$pid,
+                'invite_id'=>$insid,
+                'day'=>1,
+                'status'=>0,
+            ]);
+        } catch (SmsException $e) {
             return response()->json([
-                'code'=>1,
-                'message'=>'注册成功'
+                'code'=>0,
+                'message'=>$e->getMessage()
             ]);
-        }else{
+        } catch (\Exception $e) {
             return response()->json([
                 'code'=>0,
-                'message'=>'注册失败'
+                'message'=>'短信校验失败'
             ]);
         }
-
+        return response()->json([
+            'code'=>1,
+            'message'=>'注册成功'
+        ]);
     }
 
 

+ 1 - 0
app/Services/HomeService.php

xqd
@@ -75,6 +75,7 @@ class HomeService
             ->where('users.id',$user_id)
             ->select(['users.id','users.sex','users.is_auth','users.is_vip','users.tencent_im_user_id','users.online','users_info.*'])
             ->first();
+        $userinfo->age = birthday($userinfo->birthday);
         $userinfo->hobby = !empty($userinfo->hobby)?explode(',',$userinfo->hobby):array();
         $userinfo->photo = !empty($userinfo->photo)?json_decode($userinfo->photo,true):array();
         $userinfo->video = !empty($userinfo->video)?json_decode($userinfo->video,true):array();