gq 8 years ago
parent
commit
e740306f78

+ 3 - 2
server/app/Http/Controllers/Api/V1/DreamController.php

xqd xqd xqd
@@ -273,7 +273,6 @@ class DreamController extends Controller
                 'coin'=>$coin,
                 'score'=>$coin*$number,
             ];
-
             $ok =   SupportDreamModel::create($data);
             if (!$ok) {
                 return $this->error(ErrorCode::MERCHANT_SERVICE_STATUS_INVALID);
@@ -380,8 +379,8 @@ class DreamController extends Controller
                 'title'  => 'required',
             ],
             [
-                'title.required'  => '动态标题不能为空',
                 'dream_id.required'  => '梦想ID不能为空',
+                'title.required'  => '动态标题不能为空',
             ]
         );
 
@@ -400,6 +399,8 @@ class DreamController extends Controller
         $data['title'] = $title;
         $ok = InteractionInfo::create($data);
         if ($ok) {
+//            收藏梦想最新动态加一
+            UserCareDream::where('dream_id',$dream_id)->increment('interaction_number',1);
             return $this->api('');
         }else{
             return $this->error(ErrorCode::SAVE_USER_FAILED);

+ 57 - 9
server/app/Http/Controllers/Api/V1/IndexController.php

xqd xqd
@@ -36,11 +36,51 @@ class IndexController extends Controller
      *               "value": "http://w17.9026.com/img/banner/banner_3.png",
      *           },
      *      ],
-     *       "users": [                            最新动态的关注用户
-     *          {
-     *              "pic": "http://www.wsfjq.com/photos/bd119684755.jpg",
-     *          }
+     *   "users": {
+     *      "1": [               1用户ID
+     *          [
+     *              {                                   用户梦想互动
+     *                  "id": 8,
+     *                  "dream_id": 1,
+     *                  "title": "2",
+     *                  "pic1": "www.buniang.com",
+     *                 "pic2": "",
+     *                  "pic3": "",
+     *                 "pic4": "",
+     *                  "pic5": "",
+     *                 "pic6": "",
+     *                  "pic7": "",
+     *                   "pic8": "",
+     *                  "pic9": "",
+     *                  "status": 1,
+     *                  "created_at": "2017-06-23 08:13:39",
+     *                  "updated_at": "2017-06-23 08:13:39",
+     *                  "deleted_at": null,
+     *                  "user_id": 1
+     *              },
+     *              {
+     *                  "id": 9,
+     *                  "dream_id": 1,
+     *                  "title": "2haha",
+     *                  "pic1": "www.buniang.com",
+     *                  "pic2": "",
+     *                  "pic3": "",
+     *                  "pic4": "",
+     *                  "pic5": "",
+     *                  "pic6": "",
+     *                  "pic7": "",
+     *                  "pic8": "",
+     *                  "pic9": "",
+     *                  "status": 1,
+     *                  "created_at": "2017-06-23 08:15:01",
+     *                  "updated_at": "2017-06-23 08:15:01",
+     *                 "deleted_at": null,
+     *                  "user_id": 1
+     *              },
+     *          ],
+     *          "http://www.wsfjq.com/photos/bd119684755.jpg"            用户头像
      *      ],
+     *}
      *      "dreams": {                             梦想列表
      *      "current_page": 1,
      *      "data": [
@@ -132,15 +172,23 @@ class IndexController extends Controller
     {
         $user = $this->getUser();
         //        关注的梦想
-        $arr =  $user->UserCareUser;
+        $arr =  $user->UserCareDream;
+//        $arr = UserInfoModel::where('id',$user->id)->whereHas('UserCareDream', function ($query) {
+//            $query->where('interaction_number', '>', 0);
+//        })->get();
         $users = [] ;
+        $arr1 = [];
         foreach ($arr as $k => $v){
-            if ($v->pivot->interaction_number > 0) {
-                $v->news_num = $v->pivot->interaction_number;
-                $v->pic = $v->dreamUser->pic;
-                $users[] = $v;
+            if (!array_key_exists($v->pivot->dream_user_id,$arr1)) {
+                $arr1[$v->pivot->dream_user_id] = $v->pivot->interaction_number;
+            }else{
+                $arr1[$v->pivot->dream_user_id] += $v->pivot->interaction_number;
             }
         }
+        foreach ($arr1 as $k => $v){
+            $a = UserInfoModel::find($k);
+            $users[$k] =[$a->allInteraction,$a->pic] ;
+        }
         $type = $request->type;
         if ($type == 'trend') {
             $dreams = DreamInfoModel::orderBy('score','desc')->offset(20)->limit(100)->paginate(20);

+ 6 - 1
server/app/Models/UserInfoModel.php

xqd xqd
@@ -60,7 +60,7 @@ class UserInfoModel extends Authenticatable
     }
     public function UserCareDream()
     {
-        return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->withPivot('interaction_number');
+        return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->withPivot('interaction_number','dream_user_id');
     }
 
 
@@ -116,5 +116,10 @@ class UserInfoModel extends Authenticatable
     {
         return $this->hasManyThrough('App\Models\DreamImages', 'App\Models\DreamInfoModel','user_id','dream_id');
     }
+    //    获取所有梦想的互动
+    public function allInteraction()
+    {
+        return $this->hasManyThrough('App\Models\InteractionInfo', 'App\Models\DreamInfoModel','user_id','dream_id');
+    }
 
 }

+ 1 - 0
server/database/migrations/2017_06_03_035722_create_user_care_dream_table.php

xqd
@@ -17,6 +17,7 @@ class CreateUserCareDreamTable extends Migration
             $table->increments('id');
             $table->integer('user_id')->comment('用户ID');
             $table->integer('dream_id')->comment('关注梦想ID');
+            $table->integer('dream_user_id')->comment('梦想用户ID');
             $table->integer('interaction_number')->comment('最新动态数量');
             $table->timestamps();
         });