xiaogang 4 anos atrás
pai
commit
dd5d07d0cb

+ 2 - 2
app/Http/Controllers/Api/AuthorizationsController.php

xqd xqd
@@ -70,7 +70,7 @@ class AuthorizationsController extends Controller
         $token = Auth::guard('api')->fromUser($user);
         self::updateLastLogin($user, $token);
 
-        $resdata['token'] = $token;
+        $resdata['token'] = "Bearer ".$token;
         $resdata['sex'] = $user->sex;
         $resdata['password'] = $user->password?1:0;
         return response()->json($resdata);
@@ -126,7 +126,7 @@ class AuthorizationsController extends Controller
         $user->save();
         self::updateLastLogin($user, $token);
 
-        $resdata['token'] = $token;
+        $resdata['token'] ="Bearer ".$token;
         $resdata['sex'] = $user->sex;
         $resdata['password'] = $user->password?1:0;
         return response()->json($resdata);

+ 79 - 0
app/Http/Controllers/Api/NoticeController.php

xqd
@@ -0,0 +1,79 @@
+<?php
+
+
+namespace App\Http\Controllers\Api;
+
+
+use App\Models\DynamicModel;
+use App\Models\UserLikeModel;
+use App\Models\UserSystemMessageModel;
+use App\Services\NoticeService;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+
+class NoticeController extends Controller
+{
+    protected $noticeService;
+    public function __construct()
+    {
+        $this->noticeService = new NoticeService();
+    }
+
+    /**
+     * 获取消息列表
+     * @param Request $request
+     */
+    public function get_notice_list(Request $request){
+        try {
+            $user = auth('api')->user();
+            $res['notice_list'] = [];
+            //未读喜欢数量
+            $res['like_num'] = UserLikeModel::query()->where(["like_id"=>$user->id,'status'=>0])->count();
+            //未读点赞数量
+            $res['zan_num'] = DynamicModel::query()->with(["users"])->where('status','=',0)
+                ->whereHas("users",function($query)use($user){
+                    $query->where('id',$user->id)->select();
+                })->count();
+            //未读系统消息
+            $res['system_num'] = UserSystemMessageModel::query()->where(['user_id'=>$user->id,'status'=>0])->count();
+        }catch (\Exception $exception){
+            return $this->response->errorForbidden($exception->getMessage());
+        }
+        return response()->json($res);
+    }
+
+    /**
+     * 获取喜欢列表
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse|void
+     */
+    public function get_like_list(Request $request){
+        try {
+            $user = auth('api')->user();
+            $param['user_id'] = $user->id;
+            $param['type'] = $request->type;
+            $res = $this->noticeService->get_like_list($param);
+        } catch (\Exception $exception){
+            return $this->response->errorForbidden($exception->getMessage());
+        }
+        return response()->json($res);
+    }
+
+    /**
+     * 获取点赞列表
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse|void
+     */
+    public function get_zan_list(Request $request){
+        try {
+            $user = auth('api')->user();
+            $param['user_id'] = $user->id;
+            $param['type'] = $request->type;
+            $res = $this->noticeService->get_zan_list($param);
+        } catch (\Exception $exception){
+            return $this->response->errorForbidden($exception->getMessage());
+        }
+        return response()->json($res);
+
+    }
+}

+ 5 - 0
app/Models/DynamicZanModel.php

xqd
@@ -20,4 +20,9 @@ class DynamicZanModel extends BaseModel
     {
         return $this->belongsTo(UserInfoModel::class,'user_id','user_id');
     }
+
+    public function dynamic()
+    {
+        return $this->belongsTo(DynamicModel::class,'dynamic_id','id');
+    }
 }

+ 33 - 0
app/Models/UserLikeModel.php

xqd
@@ -0,0 +1,33 @@
+<?php
+
+
+namespace App\Models;
+
+
+class UserLikeModel extends BaseModel
+{
+    protected $table = 'users_like';
+    public $timestamps = false;
+    protected $fillable = ['user_id', 'like_id','status','atime'];
+
+
+    public function users()
+    {
+        return $this->belongsTo(User::class,'user_id','id');
+    }
+
+    public function users_info()
+    {
+        return $this->belongsTo(UserInfoModel::class,'user_id','user_id');
+    }
+
+    public function like_users()
+    {
+        return $this->belongsTo(User::class,'like_id','id');
+    }
+
+    public function like_users_info()
+    {
+        return $this->belongsTo(UserInfoModel::class,'like_id','user_id');
+    }
+}

+ 12 - 0
app/Models/UserSystemMessageModel.php

xqd
@@ -0,0 +1,12 @@
+<?php
+
+
+namespace App\Models;
+
+
+class UserSystemMessageModel extends BaseModel
+{
+    protected $table = 'users_system_message';
+    protected $fillable = ['user_id', 'content','status'];
+
+}

+ 15 - 9
app/Services/DynamicService.php

xqd xqd xqd
@@ -42,12 +42,15 @@ class DynamicService
                         "title"=>htmlspecialchars($v['title']),
                         "hot"=>1
                     ]);
-                    $tag_ins.=$id.',';
+                    $tag_ins.= $id.',';
                 }else{
                     DB::table('dynamic_tag')->where(['id'=>$v['id']])->increment('hot',1);
-                    $tag_ins.=$v['id'].',';
+                    $tag_ins.= $v['id'].',';
                 }
             }
+            if(strlen($tag_ins)>0){
+                $tag_ins = substr($tag_ins,0,-1);
+            }
         }
         $data = [
           "content"=>$dynamicParam->content,
@@ -80,13 +83,11 @@ class DynamicService
 
         }
 
-        //男,女,全部
+        //性别
         if($where['look_type']!=3){
-          //  $dynamic = $dynamic->where('users.sex','=',$where['look_type']);
-        }
-        //标签
-        if($where['tag_id']!=0){
-            $dynamic = $dynamic->where('tag','=',$where['user_id']);
+            $dynamic = $dynamic->whereHas('users',function($query)use($where){
+                $query->where('sex',$where['look_type'])->select();
+            });
         }
 
         //用户id
@@ -94,12 +95,17 @@ class DynamicService
             $dynamic = $dynamic->where('user_id','=',$where['user_id']);
         }
 
+        //标签
+        if($where['tag_id']!=0){
+            $dynamic = $dynamic->whereRaw('FIND_IN_SET(?,tag)',[$where['tag_id']]);
+        }
+
         $dynamic = $dynamic->orderByDesc('id')
             ->paginate(request('perPage',10));
         $dynamic = $dynamic->toArray();
         foreach ($dynamic['data'] as $k=>$v){
             $dynamic['data'][$k]['img_url'] = json_decode($v['img_url'],true);
-            $dynamic['data'][$k]['tag'] = json_decode($v['tag'],true);
+            //$dynamic['data'][$k]['tag'] = json_decode($v['tag'],true);
             if(!empty($v['site'])){
                 $dynamic['data'][$k]['site'] = json_decode($v['site'],true);
                 $site = json_decode($v['site'],true);

+ 84 - 0
app/Services/NoticeService.php

xqd
@@ -0,0 +1,84 @@
+<?php
+
+
+namespace App\Services;
+
+
+use App\Models\DynamicZanModel;
+use App\Models\UserLikeModel;
+
+class NoticeService
+{
+    /**
+     * 获取消息列表
+     */
+    public function get_notice_list(){
+
+    }
+
+    /**
+     * 获取喜欢列表
+     */
+    public function get_like_list($param){
+        $query = UserLikeModel::query();
+        if($param['type']==1){
+            //我喜欢
+            $query = $query->with(['like_users'=>function($query){
+                $query->select('id','sex','is_vip');
+            },'like_users_info'])->where('user_id',$param['user_id']);
+        }else{
+            //喜欢我
+            $query = $query->with(['users'=>function($query){
+                $query->select('id','sex','is_vip');
+            },'users_info'])->where('like_id',$param['user_id']);
+
+            //清除喜欢我未读状态
+            UserLikeModel::query()->where(['like_id'=>$param['user_id'],'status'=>0])->update(['status'=>1]);
+        }
+        $query = $query->orderByDesc('id')
+            ->paginate(request('perPage',20));
+
+        $query = $query->toArray();
+        foreach ($query['data'] as $k=>$v){
+            $query['data'][$k]['distance'] = 0;  //计算距离
+        }
+        return $query;
+    }
+
+
+    /**
+     * 获取点赞列表
+     */
+    public function get_zan_list($param){
+        $query = DynamicZanModel::query();
+        if($param['type']==1){
+            //我赞了他
+            $query = $query->with(['dynamic'=>function($query){
+                $query->select('id','content','img_url');
+            },'dynamic.users'=>function($querty){
+                $querty->select('id','sex','is_vip');
+            },'dynamic.users_info'])
+            ->where('user_id',$param['user_id']);
+        }else{
+            //他赞了我
+            $query = $query->with(['dynamic'])->whereHas('dynamic',function ($query)use($param){
+                $query->where('user_id',$param['user_id'])->select();
+            });
+
+            //清除他赞了我未读状态
+            DynamicZanModel::query()->with(['dynamic'])->where('status','=',0)->whereHas('dynamic',function ($query)use($param){
+                $query->where('user_id',$param['user_id'])->select('id','user_id','content','img_url');
+            })->update(['status'=>1]);
+        }
+        $query = $query->orderByDesc('id')
+            ->paginate(request('perPage',20));
+
+        $query = $query->toArray();
+        foreach ($query['data'] as $k=>$v){
+            $query['data'][$k]['dynamic']['img_url'] = json_decode($v['dynamic']['img_url'],true);
+        }
+        return $query;
+    }
+
+
+}

+ 11 - 0
routes/api.php

xqd
@@ -94,6 +94,17 @@ $api->version('v1', [
         });
 
 
+        /*
+        |--------------------------------------------------------------
+        |  消息相关
+        |--------------------------------------------------------------
+        */
+        $api->group(['prefix' => 'notice'], function ($api) {
+            $api->post('/get_notice_list', 'NoticeController@get_notice_list')->name('notice.get_notice_list');
+            $api->post('/get_like_list', 'NoticeController@get_like_list')->name('notice.get_like_list');
+            $api->post('/get_zan_list', 'NoticeController@get_zan_list')->name('notice.get_zan_list');
+        });
+
         /*
         |--------------------------------------------------------------
         |  退出登录