瀏覽代碼

Merge branch 'gq' of http://git.9026.com/roobe/miao

Mike 7 年之前
父節點
當前提交
83737b9a1c

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

xqd xqd
@@ -469,6 +469,11 @@ class DreamController extends Controller
         $keyword ='%'.$request->keyword.'%';
         $data = DreamInfoModel::where('name','like',$keyword)->
         orWhere('sign','like',$keyword)->with(['user','img'])->get();
+        foreach ($data as $k => $dream) {
+            $info = UserCareDream::where('dream_id',$dream->id)->get();
+            $dream->care_num = count($info);
+            $dream->img = $dream->img?$dream->img->pic:'';
+        }
         $this->insertSearchTable($user->id,$request->keyword);
         return $this->api($data);
     }
@@ -483,7 +488,6 @@ class DreamController extends Controller
             $info->times += 1;
             $info->save();
         }
-
     }
 
     /**

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

xqd
@@ -157,6 +157,7 @@ class IndexController extends Controller
             $query->where('sign','like',$keyword)
                 ->where('end_time','>=',time());
         })->with(['user','img'])->get();
+        $this->dreams($dream_infos);
         $signs  = BaseSettingsModel::where('category','sign')->where('value','like',$keyword)->get();
         if (empty($request->keyword)) {
 //            历史搜索

+ 167 - 9
server/app/Http/Controllers/Api/V1/MyController.php

xqd 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;
@@ -221,6 +222,63 @@ class MyController extends Controller
     }
 
     /**
+     * @api {get} /api/my/reply 回复我的
+     * @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
+     */
+    public function reply()
+    {
+        $user = $this->getUser();
+        $data = CommentInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get();
+
+        foreach ($data as $item){   //访问接口  标记已读
+            $item->update(['is_read'=>1]);
+        }
+        return $this->api($data);
+    } /**
+     * @api {get} /api/my/letter 私信
+     * @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
+     */
+    public function letter()
+    {
+        $user = $this->getUser();
+        $data  =  SystemInfoModel::where('user_id',$user->id)->whereNotNull('to_user_id')->orderBy('id','desc')->get();
+        foreach ($data as $item){   //访问接口  标记已读
+            $item->update(['is_read'=>1]);
+        }
+        return $this->api($data);
+    } /**
      * @api {get} /api/my/system_info 系统消息
      * @apiDescription 系统消息
      * @apiGroup My
@@ -232,19 +290,119 @@ class MyController extends Controller
      *  "status": true,
      *  "status_code": 0,
      *  "message": "",
+     *  "data": [
+     *      {
+     *         ....
+     *      }
+     *   ]
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function systemInfo()
+    {
+        $user = $this->getUser();
+        $data =  SystemInfoModel::where('user_id',$user->id)->whereNull('to_user_id')->orderBy('id','desc')->get();
+        foreach ($data as $item){   //访问接口  标记已读
+            $item->update(['is_read'=>1]);
+        }
+        return $this->api($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": {
-     *     "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 systemInfo()
+    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();
-        $data = SystemInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get();
-        return $this->api(compact('data'));
+        $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 +749,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 +768,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) {
+            //
+        });
+    }
+}

+ 19 - 6
server/routes/api.php

xqd xqd
@@ -128,9 +128,13 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'my.system_info',
         'uses' => 'MyController@systemInfo',
     ]);
-    $api->get('my/reply_my', [
-        'as' => 'my.reply_my',
-        'uses' => 'MyController@replyMy',
+    $api->get('my/reply', [
+        'as' => 'my.reply',
+        'uses' => 'MyController@reply',
+    ]);
+    $api->get('my/letter', [
+        'as' => 'my.letter',
+        'uses' => 'MyController@letter',
     ]);
     $api->get('my/dream', [
         'as' => 'my.dream',
@@ -146,9 +150,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', [