gq 7 년 전
부모
커밋
5ed42017f0

+ 26 - 6
server/app/Http/Controllers/Api/V1/DreamController.php

xqd xqd xqd
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api\V1;
 use App\Helper\JpushHelper;
 use App\Models\AccountLog;
 use App\Models\BaseSettingsModel;
+use App\Models\CommentInfoModel;
 use App\Models\DreamImages;
 use App\Models\DreamInfoModel;
 use App\Models\InteractionInfo;
@@ -232,9 +233,19 @@ class DreamController extends Controller
             }
         }
         if ($type == 'paihang') return $this->api($topuser);
-        $interactions = InteractionInfo::where('dream_id',$id)->with(['comments' => function ($query) {
-            $query->orderBy('created_at');
-        }])->orderBy('id','desc')->get();
+        $interactions = InteractionInfo::where('dream_id',$id)->orderBy('id','desc')->get();
+        foreach ($interactions as $interaction) {
+//            被屏蔽的人
+            $arr = array_filter(explode(',',$interaction->black_list));
+           if(!empty($arr)){
+               $interaction->comments = CommentInfoModel::where('interaction_id',$interaction->id)->where(function ($query) use ($arr) {
+                   $query->whereNotIn('user_id',$arr);
+               })->orderBy('created_at')->get()->toArray();
+           }else{
+               $interaction->comments = CommentInfoModel::where('interaction_id',$interaction->id)->orderBy('created_at')->get()->toArray();
+           }
+        }
+
         /*dd($interactions);
         foreach ($interactions as $item) {
             $item->comments;
@@ -289,9 +300,18 @@ class DreamController extends Controller
 //        梦想互动
         $interaction_id = $request->input('interaction_id');
 
-        $interactions = InteractionInfo::where('dream_id',$id)->with(['comments' => function ($query) {
-            $query->orderBy('created_at');
-        }])->orderBy('created_at','desc')->get();
+        $interactions = InteractionInfo::where('dream_id',$id)->orderBy('created_at','desc')->get();
+        foreach ($interactions as $interaction) {
+//            被屏蔽的人
+            $arr = array_filter(explode(',',$interaction->black_list));
+            if(!empty($arr)){
+                $interaction->comments = CommentInfoModel::where('interaction_id',$interaction->id)->where(function ($query) use ($arr) {
+                    $query->whereNotIn('user_id',$arr);
+                })->orderBy('created_at')->get()->toArray();
+            }else{
+                $interaction->comments = CommentInfoModel::where('interaction_id',$interaction->id)->orderBy('created_at')->get()->toArray();
+            }
+        }
         if (!empty($interaction_id)) {
             $data = InteractionInfo::with(['comments' => function ($query) {
                 $query->orderBy('created_at');

+ 44 - 0
server/app/Http/Controllers/Api/V1/InteractionController.php

xqd
@@ -421,4 +421,48 @@ class InteractionController extends Controller
             SystemInfoModel::firstOrCreate($info2);
         }
     }
+
+    /**
+     * @api {get} /api/interaction/add_comment_blackList 加入黑名单
+     * @apiDescription 隐藏某个人的评论
+     * @apiGroup Interaction
+     * @apiParam {int} dream_id       梦想id
+     * @apiParam {int} interaction_id       动态id
+     * @apiParam {int} user_id      加入黑名单用户id
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * {
+     *  "status": true,
+     *   "status_code": 0,
+     *   "message": "",
+     *   "data": ""
+     *}
+     * HTTP/1.1 200 OK
+     * @apiErrorExample {json} Error-Response:
+     * {
+     *   "status": false,
+     *   "status_code": 700,
+     *   "message": "操作失败",
+     *  "data": null
+     *}
+     * HTTP/1.1 400 Bad Request
+     */
+    public function addCommentBlackList(Request $request)
+    {
+        $user = $this->getUser();
+        $user_id = $request->input('user_id');
+        $interaction_id = $request->input('interaction_id');
+        $dream_id = $request->input('dream_id');
+        $login_user_id = $user->id;
+        $dream = DreamInfoModel::find($dream_id);
+       if (empty($dream)) return $this->error(ErrorCode::DREAM_NOT_EXIST);
+        if ($dream->user_id != $login_user_id) return $this->error(ErrorCode::OPERATION_FAILED);
+        $interaction = InteractionInfo::find($interaction_id);
+        if (empty($interaction)) return $this->error(ErrorCode::INTERACTION_NOT_EXIST);
+        $interaction->black_list = $user_id.',';
+        $ok = $interaction->save();
+        if ($ok) return $this->api();
+        return $this->error(ErrorCode::OPERATION_FAILED);
+    }
 }

+ 1 - 0
server/app/Models/InteractionInfo.php

xqd
@@ -20,6 +20,7 @@ class InteractionInfo extends Model
         'pic8',
         'pic9',
         'video',
+        'black_list',
     ];
     public function comments()
     {

+ 2 - 0
server/app/Services/Base/ErrorCode.php

xqd
@@ -73,10 +73,12 @@ final class ErrorCode {
     const DREAM_STATUS = 1412;
     const verify = 1413;
     const OPERATION_SUCCESS = 200;
+    const INTERACTION_NOT_EXIST = 2001;
 
     //错误常量枚举
     private static $_msg = [
         self::DREAM_NOT_EXIST => '梦想不存在',
+        self::INTERACTION_NOT_EXIST => '动态不存在',
         self::DREAM_STATUS => '梦想暂未实现',
         self::SUP_ERROR => '你不是最大支持者',
         self::SUP_TOP => '支持已达上限',

+ 32 - 0
server/database/migrations/2018_01_31_160618_add_black_list_to_interaction_table.php

xqd
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddBlackListToInteractionTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('interaction_info', function (Blueprint $table) {
+           $table->string('black_list')->comment('黑名单列表')->nullable()->after('status');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('interaction_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 1 - 1
server/resources/views/admin/share1.blade.php

xqd
@@ -277,7 +277,7 @@
 </head>
 <body>
 <div style="height: 50px">
-    <a href="https://fir.im/jt4h" style="height: 50px; background: #00c3da; position: fixed; z-index: 99; width: 100%">
+    <a href="      " style="height: 50px; background: #00c3da; position: fixed; z-index: 99; width: 100%">
         <div style="float: left;color: #fff;line-height: 50px;padding-left: 5px">支持({{empty($dream->user) ? '' : $dream->user->nickname}})的梦想!现在就下载瞄喵</div>
         <div style="float: right;padding: 5px">
             <img style="width: 40px;height: 40px;" src="http://firicon.fir.im/396004d5e7b572efbefdfee976338331a457282b" alt="">

+ 4 - 0
server/routes/api.php

xqd
@@ -296,6 +296,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'interaction.delete',
         'uses' => 'InteractionController@delete',
     ]);
+    $api->get('/interaction/add_comment_blackList', [  //加入黑名单
+        'as' => 'interaction.add_comment_blackList',
+        'uses' => 'InteractionController@addCommentBlackList',
+    ]);
     $api->get('/interaction/destroy', [  //删除动态
         'as' => 'interaction.destroy',
         'uses' => 'InteractionController@destroy',