| xqd
@@ -3,9 +3,11 @@
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
use App\Models\BaseSettingsModel;
|
|
|
+use App\Models\CommentInfoModel;
|
|
|
use App\Models\DreamInfoModel;
|
|
|
use App\Models\SearchInfoModel;
|
|
|
use App\Models\UserCareDream;
|
|
|
+use App\Models\UserCareUser;
|
|
|
use App\Models\UserInfoModel;
|
|
|
use Illuminate\Http\Request;
|
|
|
class IndexController extends Controller
|
| xqd
@@ -22,59 +24,81 @@ class IndexController extends Controller
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
|
|
*{
|
|
|
- * "status": true,
|
|
|
- * "status_code": 0,
|
|
|
- * "message": "",
|
|
|
- * "data": {
|
|
|
- * "banners": [ 轮播图
|
|
|
- * {
|
|
|
- * "id": 34,
|
|
|
- * "key": "4",
|
|
|
- * "value": "http://w17.9026.com/img/banner/banner_4.png",
|
|
|
- * "sort": 0,
|
|
|
- * "category": "banner",
|
|
|
- * "pid": 0,
|
|
|
- * "status": 1,
|
|
|
- * "created_at": null,
|
|
|
- * "updated_at": null,
|
|
|
- * "deleted_at": null
|
|
|
- * }
|
|
|
- * ],
|
|
|
- * "users": [], 动态用户
|
|
|
- * "dreams": { 梦想列表
|
|
|
- * "current_page": 1,
|
|
|
- * "data": [
|
|
|
- * {
|
|
|
- * "id": 5,
|
|
|
- * "user_id": 1,
|
|
|
- * "name": "梦想标题1",
|
|
|
- * "about": "梦想介绍",
|
|
|
- * "coin": 2500,
|
|
|
- * "time": 21, 实现时间
|
|
|
- * "get_coin": 0,
|
|
|
- * "status": 0,
|
|
|
- * "video": null,
|
|
|
- * "score": 100079365,
|
|
|
- * "sign": "",
|
|
|
- * "created_at": "2017-06-25 12:45:22",
|
|
|
- * "updated_at": "2017-06-25 12:45:22",
|
|
|
- * "care_num": 0, 关注人数
|
|
|
- * "img": {
|
|
|
- * "title": "",
|
|
|
- * "pic": "https://timgsa.baidu.com/timg?ica852e6e9c6ec46b7b14f12f.jpg" 梦想封面图片
|
|
|
- * }
|
|
|
- * },
|
|
|
- * ],
|
|
|
- * "from": 1,
|
|
|
- * "last_page": 1,
|
|
|
- * "next_page_url": null,
|
|
|
- * "path": "http://www.miao.com/api/index/home",
|
|
|
- * "per_page": 20,
|
|
|
- * "prev_page_url": null,
|
|
|
- * "to": 5,
|
|
|
- * "total": 5
|
|
|
- * }
|
|
|
- * }
|
|
|
+ * "status": true,
|
|
|
+ * "status_code": 0,
|
|
|
+ * "message": "",
|
|
|
+ * "data": {
|
|
|
+ * "banners": [
|
|
|
+ * {
|
|
|
+ * "id": 32,
|
|
|
+ * "key": "2",
|
|
|
+ * "value": "http://w17.9026.com/img/banner/banner_2.png",
|
|
|
+ * "sort": 2,
|
|
|
+ * "category": "banner",
|
|
|
+ * "pid": 0,
|
|
|
+ * "status": 1,
|
|
|
+ * "created_at": null,
|
|
|
+ * "updated_at": "2017-06-26 09:21:36",
|
|
|
+ * "deleted_at": null
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * "dtusers": [ 动态用户
|
|
|
+ * {
|
|
|
+ * "id": 3,
|
|
|
+ * "user_id": 1,
|
|
|
+ * "other_user_id": 2,
|
|
|
+ * "dream_number": 1,
|
|
|
+ * "created_at": null,
|
|
|
+ * "updated_at": null,
|
|
|
+ * "other_user": { 动态用户 头像和id
|
|
|
+ * "id": 2,
|
|
|
+ * "avatar": "http://www.miao.com/upload/user/20170630/08e235d7211944e9b6482965b4d7c42e.jpg",
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * "hdusers": [], 互动用户
|
|
|
+ * "dreams": {
|
|
|
+ * "current_page": 1,
|
|
|
+ * "data": [
|
|
|
+ * {
|
|
|
+ * "id": 5,
|
|
|
+ * "user_id": 1,
|
|
|
+ * "name": "梦想标题1",
|
|
|
+ * "about": "梦想介绍",
|
|
|
+ * "coin": 2500,
|
|
|
+ * "end_time": "2017-05-11 17:00:00",
|
|
|
+ * "get_coin": 0,
|
|
|
+ * "mark": 0,
|
|
|
+ * "status": 2,
|
|
|
+ * "video": "url",
|
|
|
+ * "score": 100079365,
|
|
|
+ * "sign": "梦想达人",
|
|
|
+ * "code": "",
|
|
|
+ * "parameter": 100,
|
|
|
+ * "created_at": "2017-06-25 12:45:22",
|
|
|
+ * "updated_at": "2017-07-03 12:23:37",
|
|
|
+ * "care_num": 1,
|
|
|
+ * "img": {
|
|
|
+ * "title": "",
|
|
|
+ * "pic": "http://www.miao.com/upload/dream/20170629/a18cadd1560f21453a08fdd81fb8fb2d.jpg"
|
|
|
+ * },
|
|
|
+ * "user": {
|
|
|
+ * "id": 1,
|
|
|
+ * "avatar": "/upload/user/20170629/e77068cc14c82086fb6b16e5bb7c3dd1.jpg",
|
|
|
+ * }
|
|
|
+ * },
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * "from": 1,
|
|
|
+ * "last_page": 1,
|
|
|
+ * "next_page_url": null,
|
|
|
+ * "path": "http://www.miao.com/api/index/home",
|
|
|
+ * "per_page": 20,
|
|
|
+ * "prev_page_url": null,
|
|
|
+ * "to": 11,
|
|
|
+ * "total": 11
|
|
|
+ * }
|
|
|
+ * }
|
|
|
*}
|
|
|
* @apiErrorExample {json} Error-Response:
|
|
|
* HTTP/1.1 400 Bad Request
|
| xqd
@@ -87,25 +111,32 @@ class IndexController extends Controller
|
|
|
*/
|
|
|
public function home(Request $request)
|
|
|
{
|
|
|
+ $login_user = $this->getUser();
|
|
|
+ $id = $login_user->id;
|
|
|
$arr1 =DreamInfoModel::orderBy('score','desc')->limit(20)->select('id')->get()->toArray();
|
|
|
$id_arr1 = array_column($arr1,'id');
|
|
|
$arr2 =DreamInfoModel::orderBy('score','desc')->limit(120)->select('id')->get()->toArray();
|
|
|
$id_arr2 = array_column($arr2,'id');
|
|
|
- $users = UserInfoModel::all()->toArray();
|
|
|
+ $dtusers =UserCareUser::where('user_id',$id)->with('other_user')->
|
|
|
+ where('dream_number','>',0)->orderBy('created_at')->get()->toArray();
|
|
|
+
|
|
|
+ $hdusers = CommentInfoModel::where(function ($query) use ($id) {
|
|
|
+ $query->where('user_id',$id)->orWhere('to_user_id',$id);
|
|
|
+ })->where('is_read',0)->with('to_user')->orderBy('created_at')->get()->toArray();
|
|
|
$type = $request->type;
|
|
|
if ($type == 'trend') {
|
|
|
$dreams = DreamInfoModel::orderBy('score','desc')->with('user')->whereNotIn('id', $id_arr1)->limit(100)->paginate(20);
|
|
|
$this->dreams($dreams);
|
|
|
- return $this->api(compact('users','dreams'));
|
|
|
+ return $this->api(compact('dtusers','hdusers','dreams'));
|
|
|
} elseif ($type == 'news') {
|
|
|
$dreams = DreamInfoModel::orderBy('score','desc')->orderBy('created_at','desc')->with('user')->whereNotIn('id', $id_arr2)->limit(500)->paginate(20);
|
|
|
$this->dreams($dreams);
|
|
|
- return $this->api(compact('users','dreams'));
|
|
|
+ return $this->api(compact('dtusers','hdusers','dreams'));
|
|
|
} else{
|
|
|
$banners = $this->getBanner();
|
|
|
$dreams = DreamInfoModel::orderBy('score','desc')->with('user')->limit(20)->paginate(20);
|
|
|
$this->dreams($dreams);
|
|
|
- return $this->api(compact('banners','users','dreams'));
|
|
|
+ return $this->api(compact('banners','dtusers','hdusers','dreams'));
|
|
|
}
|
|
|
}
|
|
|
|