gq преди 8 години
родител
ревизия
75fc324db4

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

xqd xqd xqd xqd xqd xqd xqd
@@ -6,7 +6,9 @@ use App\Models\AccountLog;
 use App\Models\BaseSettingsModel;
 use App\Models\DreamImages;
 use App\Models\DreamInfoModel;
+use App\Models\InteractionInfo;
 use App\Models\SupportDreamModel;
+use App\Models\SystemInfoModel;
 use App\Models\UserCareDream;
 use App\Models\UserInfoModel;
 use Illuminate\Http\Request;
@@ -21,6 +23,7 @@ class DreamController extends Controller
      * @apiPermission Passport
      * @apiVersion 0.1.0
      * @apiParam {int} type interaction paihang  默认index
+     * @apiParam {int} id 梦想ID
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
      *               主页
@@ -75,7 +78,51 @@ class DreamController extends Controller
      *      },
      *  ]
      *}
-     *
+     *     互动
+     *{
+     *   "status": true,
+     *  "status_code": 0,
+     *  "message": "",
+     *  "data": {
+     *       "data": [
+     *           {
+     *          "id": 7,
+     *          "dream_id": 2,
+     *          "title": "梦想动态有力来了",
+     *          "pic1": "http\"//www.baidu.com",
+     *          "created_at": "2017-06-22 21:09:18",
+     *          "updated_at": "2017-06-22 21:09:18",
+     *          "deleted_at": null,
+     *          "comments": [                          评论
+     *              {
+     *                  "interaction_id": 7,
+     *                  "user_id": 1,
+     *                  "level": 0,
+     *                  "content": "不错的梦想",
+     *                  "updated_at": null,
+     *                 "pic": "http://www.wsfjq.com/photos/bd119684755.jpg",    评论者头像
+     *                 "replay": [                                     回复
+     *                  {
+     *                      "user_id": 1,
+     *                      "level": 0,
+     *                      "content": "我也觉得不错",
+     *                     "updated_at": null,
+     *                     "pic": "http://www.wsfjq.com/photos/bd119684755.jpg"       回复者头像
+     *                  },
+     *                  {
+     *                      "user_id": 6,
+     *                       "level": 0,
+     *                      "content": "祝你梦想成真",
+     *                      "updated_at": null,
+     *                      "pic": "http://www.wsfjq.com/photos/bd119684755.jpg"
+     *                  }
+     *              }
+     *          ]
+     *       ]
+     *  },
+     *  "times": 720000                    梦想实现倒计时(s)
+     *  }
+     *}
      * @apiErrorExample {json} Error-Response:
      *HTTP/1.1 400 Bad Request
      *{
@@ -112,7 +159,19 @@ class DreamController extends Controller
             return $this->api($data);
 
         } elseif ($type == 'interaction') {
-
+            $times = DreamInfoModel::find($id)->time;
+            $data = InteractionInfo::where('dream_id',$id)->orderBy('id','desc')->get();
+            foreach ($data as $item) {
+                $item->comments = $item->comments;
+                foreach ($item->comments as $comment) {
+                    $comment->pic = UserInfoModel::find($comment->user_id)->pic;
+                    $comment->replay = $comment->replay;
+                    foreach ($comment->replay as $k1 => $v1){
+                        $v1->pic =  UserInfoModel::find($v1->user_id)->pic;
+                    }
+                }
+            }
+            return $this->api(compact('data','times'));
         }else{
 //            梦想  图片  支持者前三    支持乘数参数    用户余额   梦想分数
             $score = 0 ;
@@ -219,7 +278,7 @@ class DreamController extends Controller
             if (!$ok) {
                 return $this->error(ErrorCode::MERCHANT_SERVICE_STATUS_INVALID);
             }
-            //                记录充值记录
+            //                记录充值记录     新增系统消息
             $data = [
                 'from_id' =>$user->id,
                 'to_id' => $user_id,
@@ -230,6 +289,13 @@ class DreamController extends Controller
                 'op' =>  AccountLog::OP_SUPPORT,
             ];
             AccountLog::create($data);
+            $message = UserInfoModel::find($user->id)->nickname.'为你的梦想捐赠'.$coin.'梦想币';
+            $info = [
+                'user_id' => $user_id,
+                'message' => $message,
+            ];
+            SystemInfoModel::create($info);
+
             return $this->api('');
         }
     }
@@ -277,4 +343,66 @@ class DreamController extends Controller
         return $this->api('');
 
     }
+
+//    发布关于梦想的动态
+    /**
+     * @api {post} /api/dream/add_info 新增动态
+     * @apiDescription 新增动态
+     * @apiGroup Dream
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiParam {int} id 梦想ID
+     * @apiParam {string} title 梦想标题
+     * @apiParam {array} pics[] 图片数组
+     * @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
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     *
+     */
+    public function addInfo(Request $request)
+    {
+        $validator = \Validator::make($request->all(),
+            [
+                'id'  => 'required',
+                'title'  => 'required',
+            ],
+            [
+                'title.required'  => '动态标题不能为空',
+                'dream_id.required'  => '梦想ID不能为空',
+            ]
+        );
+
+        if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
+        $pics = $request->pics;
+        if (empty($pics) || !is_array($pics)) {
+            return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST);
+        }
+        $data = [];
+        foreach ($pics as $k => $pic) {
+            $data['pic'.($k+1)] = $pic;
+        }
+        $dream_id = $request->id;
+        $title = $request->title;
+        $data['dream_id'] = $dream_id;
+        $data['title'] = $title;
+        $ok = InteractionInfo::create($data);
+        if ($ok) {
+            return $this->api('');
+        }else{
+            return $this->error(ErrorCode::SAVE_USER_FAILED);
+        }
+    }
 }

+ 4 - 3
server/app/Http/Controllers/Api/V1/IndexController.php

xqd
@@ -131,12 +131,13 @@ class IndexController extends Controller
     public function index(Request $request)
     {
         $user = $this->getUser();
-        //        关注的用户
+        //        关注的梦想
         $arr =  $user->UserCareUser;
         $users = [] ;
         foreach ($arr as $k => $v){
-            if ($v->pivot->dream_num > 0) {
-                $v->news_num = $v->pivot->dream_num;
+            if ($v->pivot->interaction_number > 0) {
+                $v->news_num = $v->pivot->interaction_number;
+                $v->pic = $v->dreamUser->pic;
                 $users[] = $v;
             }
         }

+ 4 - 7
server/app/Http/Controllers/Api/V1/MyController.php

xqd xqd xqd
@@ -7,6 +7,7 @@ use App\Models\BaseSettingsModel;
 use App\Models\DreamImages;
 use App\Models\DreamInfoModel;
 use App\Models\ReplyCommentsInfo;
+use App\Models\SystemInfoModel;
 use App\Models\UserCareUser;
 use App\Models\UserDream;
 use App\Models\UserInfoModel;
@@ -251,12 +252,8 @@ class MyController extends Controller
      *  "message": "",
      *  "data": {
      *     "data": [
-     *           {
-     *              "nickname": "",充值人
-     *              "pivot": {
-     *                  "coin": 0  捐赠梦想币数量
-     *                }
-     *          }
+     *        ...
+     *      ]
      *}
      * @apiErrorExample {json} Error-Response:
      * HTTP/1.1 400 Bad Request
@@ -272,7 +269,7 @@ class MyController extends Controller
     public function systemInfo()
     {
         $user = $this->getUser();
-        $data = $user->SystemInfo;
+        $data = SystemInfoModel::where('user_id',$user->id)->orderBy('id','desc')->get();
         return $this->api(compact('data'));
     }
 

+ 1 - 4
server/app/Models/DreamInfoModel.php

xqd
@@ -53,10 +53,7 @@ class DreamInfoModel extends BaseModel
 //        return $this->belongsToMany('App\Models\UserInfoModel','user_dream','dream_id','user_id');
 //    }
 
-    public function DreamInfo()
-    {
-        return $this->hasMany('App\Models\CommentInfoModel','dream_id','id');
-    }
+
 
     public function dreamImgs()
     {

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

xqd
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class InteractionInfo extends Model
+{
+    protected $table = 'interaction_info';
+    protected $fillable = [
+        'dream_id',
+        'title',
+        'pic1',
+        'pic2',
+        'pic3',
+        'pic4',
+        'pic5',
+        'pic6',
+        'pic7',
+        'pic8',
+        'pic9',
+    ];
+    public function comments()
+    {
+        return $this->hasMany('App\Models\CommentInfoModel','interaction_id','id');
+    }
+}

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

xqd
@@ -9,7 +9,6 @@ class SystemInfoModel extends Model
     protected $table = 'system_info';
     protected $fillable = [
         'user_id',
-        'other_id',
-        'coin',
+        'message',
     ];
 }

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

xqd
@@ -58,11 +58,17 @@ class UserInfoModel extends Authenticatable
     {
         return $this->belongsToMany('App\Models\UserInfoModel','user_care_user','user_id','other_user_id')->withPivot('dream_num');
     }
+    public function UserCareDream()
+    {
+        return $this->belongsToMany('App\Models\DreamInfoModel','user_care_dream','user_id','dream_id')->withPivot('interaction_number');
+    }
+
+
 
 //    系统消息
     public function systemInfo()
     {
-        return $this->belongsToMany('App\Models\UserInfoModel','system_info','other_id','user_id')->withPivot('coin');
+        return $this->hasMany('App\Models\SystemInfoModel','user_id','id');
     }
 //用户梦想
     public function UserDream()

+ 1 - 1
server/database/migrations/2017_06_02_062004_create_comments_info_table.php

xqd
@@ -15,7 +15,7 @@ class CreateCommentsInfoTable extends Migration
     {
         Schema::create('comments_info', function (Blueprint $table) {
             $table->increments('id');
-            $table->integer('dream_id')->comment('梦想ID');
+            $table->integer('interaction_id')->comment('梦想动态ID');
             $table->integer('user_id')->comment('评价用户');
             $table->tinyInteger('level')->default(0)->comment('评论星级');
             $table->text('content')->comment('评论内容');

+ 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('interaction_number')->comment('最新动态数量');
             $table->timestamps();
         });
     }

+ 1 - 1
server/database/migrations/2017_06_22_175547_create_interaction_info_table.php

xqd
@@ -16,7 +16,7 @@ class CreateInteractionInfoTable extends Migration
         Schema::create('interaction_info', function (Blueprint $table) {
             $table->increments('id')->comment('id');
             $table->integer('dream_id')->comment('梦想ID');
-            $table->text('dream',20)->comment('互动标题');
+            $table->text('title')->comment('互动标题');
             $table->string('pic1')->default('')->comment('图片');
             $table->string('pic2')->default('')->comment('图片');
             $table->string('pic3')->default('')->comment('图片');

+ 4 - 0
server/routes/api.php

xqd
@@ -194,4 +194,8 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'dream.support',
         'uses' => 'DreamController@support',
     ]);
+    $api->post('dream/add_info', [
+        'as' => 'dream.add_info',
+        'uses' => 'DreamController@addInfo',
+    ]);
 });