gq 7 years ago
parent
commit
1b13585db5

+ 0 - 1
server/app/Http/Controllers/Api/V1/DreamController.php

xqd
@@ -488,7 +488,6 @@ class DreamController extends Controller
             $info->times += 1;
             $info->save();
         }
-
     }
 
     /**

+ 101 - 3
server/app/Http/Controllers/Api/V1/MyController.php

xqd xqd xqd xqd
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api\V1;
 use App\Models\AccountLog;
 use App\Models\BaseDictionaryOptionModel;
 use App\Models\BaseSettingsModel;
+use App\Models\CommentInfoModel;
 use App\Models\DreamInfoModel;
 use App\Models\SearchInfoModel;
 use App\Models\Suggest;
@@ -247,6 +248,103 @@ class MyController extends Controller
         return $this->api(compact('data'));
     }
 
+    /**
+     * @api {get} /api/my/info 消息中心
+     * @apiDescription 消息中心
+     * @apiGroup My
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     *{
+     *  "status": true,
+     *  "status_code": 0,
+     *  "message": "",
+     *  "data": {
+     *      "systemInfo": {
+     *          "number": 3,
+     *          "is_read": 3
+     *      },
+     *      "letter": {
+     *          "number": 0,
+     *          "is_read": 0
+     *      },
+     *      "reply": {
+     *          "number": 3,
+     *          "is_read": 3
+     *      }
+     *  }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function info()
+    {
+        $user = $this->getUser();
+        $systemInfo1 =  SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
+        $systemInfo2 =  SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
+            ->whereNull('to_user_id')->orderBy('id','desc')->get();
+        $letter1 =  SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
+        $letter2 =  SystemInfoModel::where('user_id',$user->id)->where('is_read','0')
+            ->whereNotNull('to_user_id')->orderBy('id','desc')->get();
+        $comments1 = CommentInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get();
+        $comments2 = CommentInfoModel::where('user_id',$user->id)->where('is_read','0')->orderBy('id','desc')->get();
+        $arr = [];
+        $arr['systemInfo']['number'] = count($systemInfo1) ;
+        $arr['systemInfo']['is_read'] = count($systemInfo2) ;
+        $arr['letter']['number'] = count($letter1) ;
+        $arr['letter']['is_read'] = count($letter2) ;
+        $arr['reply']['number'] = count($comments1) ;
+        $arr['reply']['is_read'] = count($comments2) ;
+        return $this->api($arr);
+    }
+
+    /**
+     * @api {get} /api/my/read 设为已读
+     * @apiDescription 设为已读
+     * @apiGroup My
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     *{
+     *  "status": true,
+     *  "status_code": 0,
+     *  "message": "",
+     *  "data": ""
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *   "status": false,
+     *  "status_code": 700,
+     *   "message": "操作失败",
+     *  "data": null
+     *}
+     */
+    public function read()
+    {
+        $user = $this->getUser();
+        $id = $user->id;
+        $system_infos = SystemInfoModel::where(function ($query) use($id){
+            $query->where('user_id',$id)->where('is_read','0');
+        })->orWhere(function ($query) use($id){
+            $query->where('to_user_id',$id)->where('is_read','0');
+        })->orderBy('id','desc')->get();
+        $comments = CommentInfoModel::where('user_id',$user->id)->where('is_read','0')->orderBy('id','desc')->get();
+        foreach ($system_infos as $system_info){
+            $system_info->update(['is_read'=>1]);
+        }
+        foreach ($comments as $comment){
+            $comment->update(['is_read'=>1]);
+        }
+        if (count($system_infos) > 0 || count($comments) > 0) {
+            return $this->api('');
+        }else{
+            return $this->error(ErrorCode::OPERATION_FAILED);
+        }
+    }
+
 
 
     /**
@@ -591,8 +689,8 @@ class MyController extends Controller
     }
 
     /**
-     * @api {get} /api/my/setting 设置
-     * @apiDescription 设置
+     * @api {get} /api/my/miao 关于喵喵
+     * @apiDescription 关于喵喵
      * @apiGroup My
      * @apiPermission Passport
      * @apiVersion 0.1.0
@@ -610,7 +708,7 @@ class MyController extends Controller
      * @apiErrorExample {json} Error-Response:
      * HTTP/1.1 400 Bad Request
      */
-    public function setting()
+    public function aboutMiao()
     {
         $data = BaseSettingsModel::where('category','miaomiao')->select('key','value')->first();
         return $this->api($data);

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

xqd
@@ -12,6 +12,7 @@ class CommentInfoModel extends Model
         'user_id',
         'level',
         'content',
+        'is_read',
     ];
     protected $hidden = ['dream_id','created_at','deleted_at','id'];
 

+ 3 - 1
server/app/Models/SystemInfoModel.php

xqd
@@ -32,7 +32,9 @@ class SystemInfoModel extends BaseModel
      */
     protected $fillable = [
                            'user_id',
-                           'message'
+                           'message',
+                           'to_user_id',
+                           'is_read',
                           ];
 
     public function user()

+ 32 - 0
server/database/migrations/2017_08_16_152034_add_is_read_to_comments_info.php

xqd
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddIsReadToCommentsInfo extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('comments_info', function (Blueprint $table) {
+            $table->tinyInteger('is_read')->default(0)->after('content')->comment('0未读');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('comments_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 32 - 0
server/database/migrations/2017_08_16_152120_add_is_read_to_system_info.php

xqd
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddIsReadToSystemInfo extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('system_info', function (Blueprint $table) {
+            $table->tinyInteger('is_read')->default(0)->after('to_user_id')->comment('0未读');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('system_info', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 12 - 3
server/routes/api.php

xqd
@@ -146,9 +146,18 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'uses' => 'MyController@collection',
     ]);
 //    关于喵喵
-    $api->get('my/setting', [
-        'as' => 'my.setting',
-        'uses' => 'MyController@setting',
+    $api->get('my/miao', [
+        'as' => 'my.miao',
+        'uses' => 'MyController@aboutMiao',
+    ]);
+//    消息中心
+    $api->get('my/info', [
+        'as' => 'my.info',
+        'uses' => 'MyController@info',
+    ]);
+    $api->get('my/read', [
+        'as' => 'my.read',
+        'uses' => 'MyController@read',
     ]);
     //    联系客服
     $api->post('my/suggest', [