| xqd
@@ -24,52 +24,101 @@ class IndexController extends Controller
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
|
|
*{
|
|
|
- *"status": true,
|
|
|
- *"status_code": 0,
|
|
|
- *"message": "",
|
|
|
- *"data": {
|
|
|
- * "banner": [], 轮播图
|
|
|
- * "users": [ 动态用户
|
|
|
- * 'news_num':2 新消息数目
|
|
|
- * ],
|
|
|
- * "dreams": {
|
|
|
- * "current_page": 1,
|
|
|
- * "data": [
|
|
|
- * {
|
|
|
- * "dream": "signture",
|
|
|
- * "about": "123568",
|
|
|
- * "video": "",
|
|
|
- * "money": 162,
|
|
|
- * "time": 2666,
|
|
|
- * "get_money": 0,
|
|
|
- * "status": 0,
|
|
|
- * "updated_at": "2017-06-21 10:51:20",
|
|
|
- * "dream_user":
|
|
|
- * {
|
|
|
- * "pic": "",
|
|
|
- * }
|
|
|
- * ,
|
|
|
- * "care_num": 1,
|
|
|
- * "dream_first_pic": null,
|
|
|
- * "dream_imgs_first": null 封面图片
|
|
|
- * "care_num": 2,
|
|
|
- * "dream_first_pic": null,
|
|
|
- * "dream_imgs_first": null
|
|
|
+ * "status": true,
|
|
|
+ * "status_code": 0,
|
|
|
+ * "message": "",
|
|
|
+ * "data": {
|
|
|
+ * "banner": [ 轮播图
|
|
|
+ * {
|
|
|
+ * "value": "http://w17.9026.com/img/banner/banner_2.png",
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "value": "http://w17.9026.com/img/banner/banner_3.png",
|
|
|
+ * },
|
|
|
+ * ],
|
|
|
+ * "users": [ 最新动态的关注用户
|
|
|
+ * {
|
|
|
+ * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg",
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * "dreams": { 梦想列表
|
|
|
+ * "current_page": 1,
|
|
|
+ * "data": [
|
|
|
+ * {
|
|
|
+ * "id": 1,
|
|
|
+ * "user_id": 1,
|
|
|
+ * "dream": "梦想标题",
|
|
|
+ * "about": "梦想烧",
|
|
|
+ * "video": "",
|
|
|
+ * "money": 10000,
|
|
|
+ * "time": 720000,
|
|
|
+ * "get_money": 0,
|
|
|
+ * "status": 0,
|
|
|
+ * "updated_at": "2017-06-22 09:42:41",
|
|
|
+ * "dream_user": { 梦想所有者
|
|
|
+ * "nickname": "ha",
|
|
|
+ * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg",
|
|
|
+ * "money": 123568,
|
|
|
+ * "sex": 1,
|
|
|
+ * "signture": "signture",
|
|
|
+ * "city": "",
|
|
|
+ * "birthday": "2017-06-21",
|
|
|
+ * "status": 1,
|
|
|
+ * },
|
|
|
+ * "care_num": 1, 关注人数
|
|
|
+ * "dream_imgs_first": { 梦想封面图片
|
|
|
+ * "title": "",
|
|
|
+ * "pic": "http://w17.9026.com/img/banner/banner_3.png"
|
|
|
+ * },
|
|
|
+ * "dream_detailed": { 点击进入梦想详情
|
|
|
+ * "dream_imgs": [
|
|
|
+ * {
|
|
|
+ * "title": "",
|
|
|
+ * "pic": "http://w17.9026.com/img/banner/banner_3.png"
|
|
|
* },
|
|
|
- * }
|
|
|
- * ],
|
|
|
- * "from": 1,
|
|
|
- * "last_page": 1,
|
|
|
- * "next_page_url": null,
|
|
|
- * "path": "http://www.miao.com/api/index/index",
|
|
|
- * "per_page": 20,
|
|
|
- * "prev_page_url": null,
|
|
|
- * "to": 3,
|
|
|
- * "total": 3
|
|
|
- * }
|
|
|
- * ]
|
|
|
+ * {
|
|
|
+ * "title": "",
|
|
|
+ * "pic": "http://w17.9026.com/img/banner/banner_3.png"
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * "comments": [
|
|
|
+ * {
|
|
|
+ * "user_id": 2,
|
|
|
+ * "level": 0,
|
|
|
+ * "content": "EST评论",
|
|
|
+ * "updated_at": null,
|
|
|
+ * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg", 评论者头像
|
|
|
+ * "replay": [
|
|
|
+ * {
|
|
|
+ * "user_id": 2,
|
|
|
+ * "level": 0,
|
|
|
+ * "content": "拉了",
|
|
|
+ * "updated_at": null,
|
|
|
+ * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg" 回复者头像
|
|
|
+ * },
|
|
|
+ * {
|
|
|
+ * "user_id": 3,
|
|
|
+ * "level": 0,
|
|
|
+ * "content": "userid3回复了你的消息",
|
|
|
+ * "updated_at": null,
|
|
|
+ * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg"
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
+ * },
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
+ * },
|
|
|
+ * "from": 1,
|
|
|
+ * "last_page": 1,
|
|
|
+ * "next_page_url": null,
|
|
|
+ * "path": "http://www.miao.com/api/index/index",
|
|
|
+ * "per_page": 20,
|
|
|
+ * "prev_page_url": null,
|
|
|
+ * "to": 8,
|
|
|
+ * "total": 8
|
|
|
* }
|
|
|
- * }
|
|
|
+ * }
|
|
|
+ *}
|
|
|
* @apiErrorExample {json} Error-Response:
|
|
|
* HTTP/1.1 400 Bad Request
|
|
|
* {
|
| xqd
@@ -116,7 +165,7 @@ class IndexController extends Controller
|
|
|
* @apiGroup Index
|
|
|
* @apiPermission none
|
|
|
* @apiVersion 0.1.0
|
|
|
- * @apiParam {string} keyword 关键字可选
|
|
|
+ * @apiParam {string} keyword 关键字可选 (ha)
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
|
|
* get
|
| xqd
@@ -161,13 +210,13 @@ class IndexController extends Controller
|
|
|
$keyword ='%'.$request->keyword.'%';
|
|
|
$data1 = UserInfoModel::where('nickname','like',$keyword)->paginate(20);
|
|
|
$data2 = DreamInfoModel::where('dream','like',$keyword)->
|
|
|
- orWhere('dream','like',$keyword)->paginate(20);
|
|
|
- $data3 = BaseSettingsModel::where('category','sign')->where('value','like',$keyword)->paginate(20);
|
|
|
+ orWhere('sign','like',$keyword)->paginate(20);
|
|
|
+ $data3 = BaseSettingsModel::where('category','sign')->where('value','like',$keyword)->get();
|
|
|
if (empty($request->keyword)) {
|
|
|
// 历史搜索
|
|
|
- $data1 = $user->search()->orderBy('id','desc')->limit(10)->paginate(20);
|
|
|
+ $data1 = $user->search()->orderBy('id','desc')->limit(10)->get();
|
|
|
// 热门搜索
|
|
|
- $data2 = SearchInfoModel::paginate(20);
|
|
|
+ $data2 = SearchInfoModel::get();
|
|
|
$arr = [];
|
|
|
foreach ($data2 as $k => $v) {
|
|
|
if (count($arr) == 8) {
|
| xqd
@@ -182,7 +231,8 @@ class IndexController extends Controller
|
|
|
arsort($arr);
|
|
|
return $this->api(compact('arr','data1'));
|
|
|
}
|
|
|
-
|
|
|
+// 写入搜索记录
|
|
|
+ $this->insertSearchTable($user->id,$request->keyword);
|
|
|
return $this->api(compact('data1','data2','data3'));
|
|
|
}
|
|
|
|
| xqd
@@ -212,12 +262,14 @@ class IndexController extends Controller
|
|
|
*/
|
|
|
public function userSearch(Request $request)
|
|
|
{
|
|
|
+ $user = $this->getUser();
|
|
|
if (empty($request->keyword)) {
|
|
|
return $this->api('');
|
|
|
}
|
|
|
$keyword ='%'.$request->keyword.'%';
|
|
|
$data1 = UserInfoModel::where('nickname','like',$keyword)->paginate(20);
|
|
|
- return $this->api(compact('data1'));
|
|
|
+ $this->insertSearchTable($user->id,$request->keyword);
|
|
|
+ return $this->api(compact('data1'));
|
|
|
}
|
|
|
|
|
|
/**
|
| xqd
@@ -252,16 +304,18 @@ class IndexController extends Controller
|
|
|
*/
|
|
|
public function dreamSearch(Request $request)
|
|
|
{
|
|
|
+ $user = $this->getUser();
|
|
|
if (empty($request->keyword)) {
|
|
|
return $this->api('');
|
|
|
}
|
|
|
$keyword ='%'.$request->keyword.'%';
|
|
|
$data = DreamInfoModel::where('dream','like',$keyword)->
|
|
|
- orWhere('dream','like',$keyword)->paginate(20);
|
|
|
+ orWhere('sign','like',$keyword)->paginate(20);
|
|
|
foreach ($data as $k => $value) {
|
|
|
$value->user_pic = $value->dreamFindUser;
|
|
|
$value->dream_img = $value->dreamImgsFirst->pic;
|
|
|
}
|
|
|
+ $this->insertSearchTable($user->id,$request->keyword);
|
|
|
return $this->api(compact('data'));
|
|
|
}
|
|
|
|
| xqd
@@ -279,14 +333,22 @@ class IndexController extends Controller
|
|
|
foreach ($dreams as $k => $dream) {
|
|
|
$dream->dream_user = $dream->dreamUser;
|
|
|
// 计算被关注总人数
|
|
|
- $dream->care_num = 0;
|
|
|
- $user = UserDream::where('dream_id',$dream->id)->first();
|
|
|
- if($user){
|
|
|
- $user_id = $user->user_id;
|
|
|
- $data = UserCareUser::where('other_user_id',$user_id)->paginate(20);
|
|
|
- $dream->care_num = count($data);
|
|
|
+ $user_id = $dream->user_id;
|
|
|
+ $data = UserCareUser::where('other_user_id',$user_id)->get();
|
|
|
+ $dream->care_num = count($data);
|
|
|
+ $dream->dream_imgs_first = $dream->dreamImgsFirst?$dream->dreamImgsFirst->pic:'';
|
|
|
+// 梦想详情 detailed 图片 ,评论 ,回复
|
|
|
+ $arr = [] ;
|
|
|
+ $arr['dream_imgs'] = $dream->dreamImgs;
|
|
|
+ $arr['comments'] = $dream->DreamInfo;
|
|
|
+ foreach ( $arr['comments'] as $k => $v){
|
|
|
+ $v->pic = UserInfoModel::find($v->user_id)->pic;
|
|
|
+ $v->replay = $v->replay;
|
|
|
+ foreach ($v->replay as $k1 => $v1){
|
|
|
+ $v1->pic = UserInfoModel::find($v1->user_id)->pic;
|
|
|
+ }
|
|
|
}
|
|
|
- $dream->dream_img = $dream->dreamImgsFirst?$dream->dreamImgsFirst->pic:'';
|
|
|
+ $dream->dream_detailed = $arr;
|
|
|
}
|
|
|
}
|
|
|
// 查看关注用户的最新动态
|
| xqd
@@ -301,43 +363,57 @@ class IndexController extends Controller
|
|
|
* HTTP/1.1 200 OK
|
|
|
*{
|
|
|
* "status": true,
|
|
|
- * "status_code": 0,
|
|
|
+ * "status_code": 0,
|
|
|
* "message": "",
|
|
|
- * "data": [
|
|
|
- * {
|
|
|
- * "dream": "1的梦想",
|
|
|
- * "about": "介绍",
|
|
|
+ * "data": [
|
|
|
+ * { 梦想信息
|
|
|
+ * "id": 7,
|
|
|
+ * "user_id": 2,
|
|
|
+ * "dream": "梦想标1123",
|
|
|
+ * "about": "梦想烧1111213",
|
|
|
* "video": "",
|
|
|
- * "time": 0,
|
|
|
+ * "money": 10000,
|
|
|
+ * "time": 720000,
|
|
|
+ * "get_money": 0,
|
|
|
* "status": 0,
|
|
|
- * "updated_at": null,
|
|
|
- * "dream_imgs": [
|
|
|
+ * "updated_at": "2017-06-22 09:47:03",
|
|
|
+ * "dream_imgs": [ 梦想的所有图片
|
|
|
* {
|
|
|
- * "title": "1", 梦想图片介绍
|
|
|
- * "pic": "111", 梦想图片
|
|
|
- * },
|
|
|
- * ],
|
|
|
- * "comments": [
|
|
|
+ * "title": "",
|
|
|
+ * "pic": "http://w17.9026.com/img/banner/banner_3.png"
|
|
|
+ * },
|
|
|
* {
|
|
|
- * "user_id": 2,
|
|
|
- * "level": 0,
|
|
|
- * "content": "评论内容", 评论内容
|
|
|
- * "updated_at": null,
|
|
|
- * "pic": "", 评论者头像
|
|
|
- * "replay": [
|
|
|
+ * "title": "",
|
|
|
+ * "pic": "http://w17.9026.com/img/banner/banner_3.png"
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * "comments": [ 评论内容
|
|
|
+ * {
|
|
|
+ * "user_id": 1,
|
|
|
+ * "level": 0,
|
|
|
+ * "content": "不错的梦想",
|
|
|
+ * "updated_at": null,
|
|
|
+ * "pic": "http://www.wsfjq.com/photos/bd119684755.jpg",
|
|
|
+ * "replay": [ 回复内容
|
|
|
* {
|
|
|
+ * "user_id": 1,
|
|
|
* "level": 0,
|
|
|
- * "content": "回复内容", 回复内容
|
|
|
+ * "content": "我也觉得不错",
|
|
|
* "updated_at": null,
|
|
|
- * "pic": "" 回复者头像
|
|
|
- * }
|
|
|
+ * "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"
|
|
|
+ * }
|
|
|
* ]
|
|
|
* }
|
|
|
* ],
|
|
|
- * }
|
|
|
- * ]
|
|
|
- * }
|
|
|
- * ]
|
|
|
+ * },
|
|
|
+ * ]
|
|
|
*}
|
|
|
* @apiErrorExample {json} Error-Response:
|
|
|
* HTTP/1.1 400 Bad Request
|
| xqd
@@ -349,8 +425,8 @@ class IndexController extends Controller
|
|
|
$other_id = $request->id;
|
|
|
if (empty($other_id)) return $this->error(ErrorCode::MEMBER_NOT_EXIST);
|
|
|
UserCareUser::where('user_id',$user->id)->where('other_user_id',$other_id)->update(['dream_num'=>0]);
|
|
|
- $data = UserInfoModel::find($other_id)->UserDream;
|
|
|
- foreach ($data as $item) {
|
|
|
+ $data = DreamInfoModel::where('user_id',$other_id)->orderBy('id','desc')->get();
|
|
|
+ foreach ($data as $item) {
|
|
|
$item->dream_imgs = $item->dreamImgs ;
|
|
|
$item->comments = $item->DreamInfo;
|
|
|
foreach ( $item->comments as $k => $v){
|
| xqd
@@ -363,4 +439,17 @@ class IndexController extends Controller
|
|
|
}
|
|
|
return $this->api($data);
|
|
|
}
|
|
|
+
|
|
|
+ public function insertSearchTable($id,$keyword)
|
|
|
+ {
|
|
|
+ $info = SearchInfoModel::where('user_id',$id)->
|
|
|
+ where('search',trim($keyword))->first();
|
|
|
+ if (count($info) == 0) {
|
|
|
+ SearchInfoModel::create(['user_id'=>$id,'search'=>trim($keyword),'times'=>1]);
|
|
|
+ }else{
|
|
|
+ $info->times += 1;
|
|
|
+ $info->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|