gq 8 rokov pred
rodič
commit
53cff0e8a4

+ 22 - 122
server/app/Http/Controllers/Api/V1/IndexController.php

xqd xqd xqd
@@ -12,10 +12,12 @@ use Illuminate\Http\Request;
 use App\Services\Base\ErrorCode;
 class IndexController extends Controller
 {
+
     /**
-     * @api {get} /api/index/hot 热门(hot)
-     * @apiDescription 热门(hot)
+     * @api {get} /api/index/index 首页
+     * @apiDescription 首页
      * @apiGroup Index
+          * @apiParam {string}  type   (热门)hot/(潮流)trend/(最新)news
      * @apiPermission none
      * @apiVersion 0.1.0
      * @apiSuccessExample {json} Success-Response:
@@ -52,12 +54,10 @@ class IndexController extends Controller
      *     "data": null or []
      * }
      */
-    public function hot(Request $request)
+    public function index(Request $request)
     {
         $user = $this->getUser();
-//获取轮播图
-        $banner = $this->getBanner();
-//        关注的用户
+        //        关注的用户
         $arr =  $user->UserCareUser;
         $users = [] ;
         foreach ($arr as $k => $v){
@@ -66,126 +66,26 @@ class IndexController extends Controller
                 $users[] = $v;
             }
         }
+        $type = $request->type;
+        if ($type == 'hot') {
+            $banner = $this->getBanner();
 //        获取其他用户信息 及梦想
-        $dreams = DreamInfoModel::orderBy('score','desc')->limit(20)->paginate(20);
-        $this->dreams($dreams);
-        return $this->api(compact('banner','users','dreams'));
-    }
-
-    /**
-     * @api {get} /api/index/trend 潮流(trend)
-     * @apiDescription 潮流(trend)
-     * @apiGroup Index
-     * @apiPermission none
-     * @apiVersion 0.1.0
-     * @apiSuccessExample {json} Success-Response:
-     * HTTP/1.1 200 OK
-     *{
-     *"status": true,
-     *"status_code": 0,
-     *"message": "",
-     *"data": {
-     *      "users": [   动态用户
-     *               'news_num':2    新消息数目
-     * ],
-     *      "dreams": [
-     *         "care_num": 0,   关注人数
-     *         "time": 1222222,   梦想倒计时
-     *         "dream_imgs_first": {
-     *               "pic": "",  梦想封面图片
-     *          }
-     *        "dream_find_user": [
-     *             {
-     *                  ...       发布梦想的用户信息
-     *            }
-     *         ],
-     *    ]
-     *     }
-     * }
-     * @apiErrorExample {json} Error-Response:
-     * HTTP/1.1 400 Bad Request
-     * {
-     *     "state": false,
-     *     "code": 1000,
-     *     "message": "传入参数不正确",
-     *     "data": null or []
-     * }
-     */
-    public function trend(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;
-                $users[] = $v;
-            }
+            $dreams = DreamInfoModel::orderBy('score','desc')->limit(20)->paginate(20);
+            $this->dreams($dreams);
+            return $this->api(compact('banner','users','dreams'));
+        } elseif ($type == 'trend') {
+            $dreams = DreamInfoModel::orderBy('score','desc')->offset(20)->limit(100)->paginate(20);
+            $this->dreams($dreams);
+            return $this->api(compact('users','dreams'));
+        } elseif ($type == 'news') {
+            $dreams = DreamInfoModel::orderBy('score','desc')->offset(100)->limit(500)->paginate(20);
+            $this->dreams($dreams);
+            return $this->api(compact('users','dreams'));
+        }else{
+            return $this->error(ErrorCode::KEY_ERROR);
         }
-//        获取其他用户信息 及梦想
-        $dreams = DreamInfoModel::orderBy('score','desc')->offset(20)->limit(100)->paginate(20);
-        $this->dreams($dreams);
-        return $this->api(compact('users','dreams'));
     }
 
-    /**
-     * @api {get} /api/index/new 最新(news)
-     * @apiDescription 最新(news)
-     * @apiGroup Index
-     * @apiPermission none
-     * @apiVersion 0.1.0
-     * @apiSuccessExample {json} Success-Response:
-     * HTTP/1.1 200 OK
-     *{
-     *"status": true,
-     *"status_code": 0,
-     *"message": "",
-     *"data": {
-     *      "users": [
-     *          'news_num':2    新消息数目
-     * ],  动态用户
-     *      "dreams": [
-     *         "care_num": 0,   关注人数
-     *         "time": 1222222,   梦想倒计时
-     *         "dream_imgs_first": {
-     *               "pic": "",  梦想封面图片
-     *          }
-     *        "dream_find_user": [
-     *             {
-     *                  ...       发布梦想的用户信息
-     *            }
-     *         ],
-     *    ]
-     *     }
-     * }
-     * @apiErrorExample {json} Error-Response:
-     * HTTP/1.1 400 Bad Request
-     * {
-     *     "state": false,
-     *     "code": 1000,
-     *     "message": "传入参数不正确",
-     *     "data": null or []
-     * }
-     */
-    public function news(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;
-                $users[] = $v;
-            }
-        }
-//        获取其他用户信息 及梦想
-        $dreams = DreamInfoModel::orderBy('score','desc')->offset(100)->limit(500)->paginate(20);
-        $this->dreams($dreams);
-        return $this->api(compact('$users','dreams'));
-    }
 
     /**
      * @api {get}  /api/index/search 搜索(search)

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

xqd xqd
@@ -320,11 +320,11 @@ class MyController extends Controller
 
         if (count($dreams) == 0)
             return $this->error(ErrorCode::DREAM_NOT_EXIST);
-
+        $comments_infos = [];
         foreach ($dreams as $dream){
-            $comments_infos = $dream->DreamInfo;
-            if (count($comments_infos) > 0) {
-                foreach ($comments_infos as $k => $value) {
+            $comments_info = $dream->DreamInfo;
+            if (count($comments_info) > 0) {
+                foreach ($comments_info as $k => $value) {
                     $value->dream_name = $dream->dream;
                     $value->dream_about = $dream->about;
                     $value->dream_pic = count($dream->dreamImgsFirst) > 0 ? $dream->dreamImgsFirst->pic : '';
@@ -332,6 +332,7 @@ class MyController extends Controller
                     $value->reviewer = $value->CommentUser->nickname;
                     $value->reviewer_pic = $value->CommentUser->pic;
                 }
+                $comments_infos[] = $comments_info;
             }
         }
 

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

xqd
@@ -40,7 +40,7 @@ class DreamInfoModel extends BaseModel
                            'status'
                           ];
 
-    protected $hidden = ['score','created_at','deleted_at','id','sign','money','mark','get_money'];
+    protected $hidden = ['score','created_at','deleted_at','id','sign','mark'];
 
 
     public function dreamUser()

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

xqd xqd
@@ -65,6 +65,7 @@ final class ErrorCode {
     const CLIENT_WRONG_PARAMS = 1000;
     const DREAM_NOT_EXIST = 1308;
     const LOCK_USER = 1309;
+    const KEY_ERROR = 1310;
 
     //错误常量枚举
     private static $_msg = [
@@ -119,6 +120,7 @@ final class ErrorCode {
         self::DELETE_OP_FAILED => '删除操作失败',
         self::CLIENT_WRONG_PARAMS => '输入不正确',
         self:: LOCK_USER=> '当前账号已被封号,请联系管理员',
+        self::KEY_ERROR => '参数错误',
     ];
 
     public static function message($code) {

+ 3 - 11
server/routes/api.php

xqd
@@ -84,17 +84,9 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
 
 
 //首页
-    $api->get('index/hot', [
-        'as' => 'index.hot',
-        'uses' => 'IndexController@hot',
-    ]);
-    $api->get('index/trend', [
-        'as' => 'index.trend',
-        'uses' => 'IndexController@trend',
-    ]);
-    $api->get('index/new', [
-        'as' => 'index.new',
-        'uses' => 'IndexController@news',
+    $api->get('index/index', [
+        'as' => 'index.index',
+        'uses' => 'IndexController@index',
     ]);
     $api->get('index/search', [
         'as' => 'index.search',