| xqd
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Api\V1;
|
|
|
use App\Models\BaseSettingsModel;
|
|
|
use App\Models\DreamInfoModel;
|
|
|
use App\Models\SearchInfoModel;
|
|
|
+use App\Models\UserCareUser;
|
|
|
+use App\Models\UserDream;
|
|
|
use App\Models\UserInfoModel;
|
|
|
use Illuminate\Http\Request;
|
|
|
use App\Services\Base\ErrorCode;
|
| xqd
@@ -12,19 +14,31 @@ class IndexController extends Controller
|
|
|
{
|
|
|
/**
|
|
|
* @api {get} /api/index/hot 热门(hot)
|
|
|
- * @apiDescription 登陆(hot)
|
|
|
+ * @apiDescription 热门(hot)
|
|
|
* @apiGroup Index
|
|
|
* @apiPermission none
|
|
|
* @apiVersion 0.1.0
|
|
|
- * @apiParam {string} phone 手机号码
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
|
|
- * {
|
|
|
- * "state": true,
|
|
|
- * "code": 0,
|
|
|
- * "message": "",
|
|
|
- * "data": {
|
|
|
- * "verify_code": "1234"//该值调试时使用,sms调通后取消
|
|
|
+ *{
|
|
|
+ *"status": true,
|
|
|
+ *"status_code": 0,
|
|
|
+ *"message": "",
|
|
|
+ *"data": {
|
|
|
+ * "banner": [], 轮播图
|
|
|
+ * "other_user": [], 动态用户
|
|
|
+ * "dreams": [
|
|
|
+ * "care_num": 0, 关注人数
|
|
|
+ * "time": 1222222, 梦想倒计时
|
|
|
+ * "dream_imgs_first": {
|
|
|
+ * "pic": "", 梦想封面图片
|
|
|
+ * }
|
|
|
+ * dream_find_user": [
|
|
|
+ * {
|
|
|
+ * ... 发布梦想的用户信息
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * ]
|
|
|
* }
|
|
|
* }
|
|
|
* @apiErrorExample {json} Error-Response:
|
| xqd
@@ -35,8 +49,6 @@ class IndexController extends Controller
|
|
|
* "message": "传入参数不正确",
|
|
|
* "data": null or []
|
|
|
* }
|
|
|
- * 可能出现的错误代码:
|
|
|
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
|
|
|
*/
|
|
|
public function hot(Request $request)
|
|
|
{
|
| xqd
@@ -44,13 +56,16 @@ class IndexController extends Controller
|
|
|
//获取轮播图
|
|
|
$banner = $this->getBanner();
|
|
|
// 关注的用户
|
|
|
- $other_user = $user->UserCareUser;
|
|
|
+ $arr = $user->UserCareUser;
|
|
|
+ $other_user = [] ;
|
|
|
+ foreach ($arr as $k => $v){
|
|
|
+ if ($v->pivot->dream_num > 0) {
|
|
|
+ $other_user[] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
// 获取其他用户信息 及梦想
|
|
|
$dreams = DreamInfoModel::orderBy('score','desc')->limit(20)->get();
|
|
|
- foreach ($dreams as $k => $dream) {
|
|
|
- $dream->dream_find_user = $dream->dreamFindUser;
|
|
|
- $dream->dream_first_pic = $dream->dreamImgsFirst;
|
|
|
- }
|
|
|
+ $this->dreams($dreams);
|
|
|
return $this->api(compact('banner','other_user','dreams'));
|
|
|
}
|
|
|
|
| xqd
@@ -60,15 +75,26 @@ class IndexController extends Controller
|
|
|
* @apiGroup Index
|
|
|
* @apiPermission none
|
|
|
* @apiVersion 0.1.0
|
|
|
- * @apiParam {string} phone 手机号码
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
|
|
- * {
|
|
|
- * "state": true,
|
|
|
- * "code": 0,
|
|
|
- * "message": "",
|
|
|
- * "data": {
|
|
|
- * "verify_code": "1234"//该值调试时使用,sms调通后取消
|
|
|
+ *{
|
|
|
+ *"status": true,
|
|
|
+ *"status_code": 0,
|
|
|
+ *"message": "",
|
|
|
+ *"data": {
|
|
|
+ * "other_user": [], 动态用户
|
|
|
+ * "dreams": [
|
|
|
+ * "care_num": 0, 关注人数
|
|
|
+ * "time": 1222222, 梦想倒计时
|
|
|
+ * "dream_imgs_first": {
|
|
|
+ * "pic": "", 梦想封面图片
|
|
|
+ * }
|
|
|
+ * dream_find_user": [
|
|
|
+ * {
|
|
|
+ * ... 发布梦想的用户信息
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * ]
|
|
|
* }
|
|
|
* }
|
|
|
* @apiErrorExample {json} Error-Response:
|
| xqd
@@ -79,20 +105,21 @@ class IndexController extends Controller
|
|
|
* "message": "传入参数不正确",
|
|
|
* "data": null or []
|
|
|
* }
|
|
|
- * 可能出现的错误代码:
|
|
|
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
|
|
|
*/
|
|
|
public function trend(Request $request)
|
|
|
{
|
|
|
$user = $this->getUser();
|
|
|
// 关注的用户
|
|
|
- $other_user = $user->UserCareUser;
|
|
|
+ $arr = $user->UserCareUser;
|
|
|
+ $other_user = [] ;
|
|
|
+ foreach ($arr as $k => $v){
|
|
|
+ if ($v->pivot->dream_num > 0) {
|
|
|
+ $other_user[] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
// 获取其他用户信息 及梦想
|
|
|
$dreams = DreamInfoModel::orderBy('score','desc')->offset(20)->limit(100)->get();
|
|
|
- foreach ($dreams as $k => $dream) {
|
|
|
- $dream->dream_find_user = $dream->dreamFindUser;
|
|
|
- $dream->dream_first_pic = $dream->dreamImgsFirst;
|
|
|
- }
|
|
|
+ $this->dreams($dreams);
|
|
|
return $this->api(compact('other_user','dreams'));
|
|
|
}
|
|
|
|
| xqd
@@ -102,15 +129,26 @@ class IndexController extends Controller
|
|
|
* @apiGroup Index
|
|
|
* @apiPermission none
|
|
|
* @apiVersion 0.1.0
|
|
|
- * @apiParam {string} phone 手机号码
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
|
|
- * {
|
|
|
- * "state": true,
|
|
|
- * "code": 0,
|
|
|
- * "message": "",
|
|
|
- * "data": {
|
|
|
- * "verify_code": "1234"//该值调试时使用,sms调通后取消
|
|
|
+ *{
|
|
|
+ *"status": true,
|
|
|
+ *"status_code": 0,
|
|
|
+ *"message": "",
|
|
|
+ *"data": {
|
|
|
+ * "other_user": [], 动态用户
|
|
|
+ * "dreams": [
|
|
|
+ * "care_num": 0, 关注人数
|
|
|
+ * "time": 1222222, 梦想倒计时
|
|
|
+ * "dream_imgs_first": {
|
|
|
+ * "pic": "", 梦想封面图片
|
|
|
+ * }
|
|
|
+ * dream_find_user": [
|
|
|
+ * {
|
|
|
+ * ... 发布梦想的用户信息
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * ]
|
|
|
* }
|
|
|
* }
|
|
|
* @apiErrorExample {json} Error-Response:
|
| xqd
@@ -121,20 +159,21 @@ class IndexController extends Controller
|
|
|
* "message": "传入参数不正确",
|
|
|
* "data": null or []
|
|
|
* }
|
|
|
- * 可能出现的错误代码:
|
|
|
- * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
|
|
|
*/
|
|
|
public function news(Request $request)
|
|
|
{
|
|
|
$user = $this->getUser();
|
|
|
// 关注的用户
|
|
|
- $other_user = $user->UserCareUser;
|
|
|
+ $arr = $user->UserCareUser;
|
|
|
+ $other_user = [] ;
|
|
|
+ foreach ($arr as $k => $v){
|
|
|
+ if ($v->pivot->dream_num > 0) {
|
|
|
+ $other_user[] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
// 获取其他用户信息 及梦想
|
|
|
$dreams = DreamInfoModel::orderBy('score','desc')->offset(100)->limit(500)->get();
|
|
|
- foreach ($dreams as $k => $dream) {
|
|
|
- $dream->dream_find_user = $dream->dreamFindUser;
|
|
|
- $dream->dream_first_pic = $dream->dreamImgsFirst;
|
|
|
- }
|
|
|
+ $this->dreams($dreams);
|
|
|
return $this->api(compact('other_user','dreams'));
|
|
|
}
|
|
|
|
| xqd
@@ -190,7 +229,7 @@ class IndexController extends Controller
|
|
|
$data1 = UserInfoModel::where('nickname','like',$keyword)->get();
|
|
|
$data2 = DreamInfoModel::where('dream','like',$keyword)->
|
|
|
orWhere('dream','like',$keyword)->get();
|
|
|
- $data3 = BaseSettingsModel::where('category','sign')->get();
|
|
|
+ $data3 = BaseSettingsModel::where('category','sign')->where('value','like',$keyword)->get();
|
|
|
if (empty($request->keyword)) {
|
|
|
// 历史搜索
|
|
|
$data1 = $user->search()->orderBy('id','desc')->limit(10)->get();
|
| xqd
@@ -214,6 +253,85 @@ class IndexController extends Controller
|
|
|
return $this->api(compact('data1','data2','data3'));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @api {get} /api/index/user_search 用户搜索(search)
|
|
|
+ * @apiDescription 用户搜索(search)
|
|
|
+ * @apiGroup Index
|
|
|
+ * @apiPermission none
|
|
|
+ * @apiVersion 0.1.0
|
|
|
+ * @apiParam {string} keyword 关键字
|
|
|
+ * @apiSuccessExample {json} Success-Response:
|
|
|
+ * HTTP/1.1 200 OK
|
|
|
+ *{
|
|
|
+ * "status": true,
|
|
|
+ * "status_code": 0,
|
|
|
+ * "message": "",
|
|
|
+ * "data": {
|
|
|
+ * "data1": [
|
|
|
+ * "nickname": "ha", 昵称
|
|
|
+ * "pic": "", 头像
|
|
|
+ * ...
|
|
|
+ * ]
|
|
|
+ * }
|
|
|
+ *}
|
|
|
+ * @apiErrorExample {json} Error-Response:
|
|
|
+ * HTTP/1.1 400 Bad Request
|
|
|
+ */
|
|
|
+ public function userSearch(Request $request)
|
|
|
+ {
|
|
|
+ if (empty($request->keyword)) {
|
|
|
+ return $this->api('');
|
|
|
+ }
|
|
|
+ $keyword ='%'.$request->keyword.'%';
|
|
|
+ $data1 = UserInfoModel::where('nickname','like',$keyword)->get();
|
|
|
+ return $this->api(compact('data1'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @api {get} /api/index/dream_search 梦想搜索(search)
|
|
|
+ * @apiDescription 梦想搜索(search)
|
|
|
+ * @apiGroup Index
|
|
|
+ * @apiPermission none
|
|
|
+ * @apiVersion 0.1.0
|
|
|
+ * @apiParam {string} keyword 关键字
|
|
|
+ * @apiSuccessExample {json} Success-Response:
|
|
|
+ * HTTP/1.1 200 OK
|
|
|
+ {
|
|
|
+ "status": true,
|
|
|
+ "status_code": 0,
|
|
|
+ "message": "",
|
|
|
+ "data": {
|
|
|
+ "data": [
|
|
|
+ {
|
|
|
+ "dream": "haha", 梦想名
|
|
|
+ "user_pic": [
|
|
|
+ {
|
|
|
+ "pic": "", 用户头像
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "dream_img": "", 梦想图片
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ * @apiErrorExample {json} Error-Response:
|
|
|
+ * HTTP/1.1 400 Bad Request
|
|
|
+ */
|
|
|
+ public function dreamSearch(Request $request)
|
|
|
+ {
|
|
|
+ if (empty($request->keyword)) {
|
|
|
+ return $this->api('');
|
|
|
+ }
|
|
|
+ $keyword ='%'.$request->keyword.'%';
|
|
|
+ $data = DreamInfoModel::where('dream','like',$keyword)->
|
|
|
+ orWhere('dream','like',$keyword)->get();
|
|
|
+ foreach ($data as $k => $value) {
|
|
|
+ $value->user_pic = $value->dreamFindUser;
|
|
|
+ $value->dream_img = $value->dreamImgsFirst->pic;
|
|
|
+ }
|
|
|
+ return $this->api(compact('data'));
|
|
|
+ }
|
|
|
+
|
|
|
//获取轮播图
|
|
|
public function getBanner()
|
|
|
{
|
| xqd
@@ -221,4 +339,17 @@ class IndexController extends Controller
|
|
|
->orderBy('sort')->limit('3')->get()->toArray();
|
|
|
return $banner;
|
|
|
}
|
|
|
+
|
|
|
+// 完善梦想信息
|
|
|
+ public function dreams($dreams)
|
|
|
+ {
|
|
|
+ foreach ($dreams as $k => $dream) {
|
|
|
+ $dream->dream_find_user = $dream->dreamFindUser;
|
|
|
+// 计算被关注总人数
|
|
|
+ $user_id = UserDream::where('dream_id',$dream->id)->first()->user_id;
|
|
|
+ $data = UserCareUser::where('other_user_id',$user_id)->get();
|
|
|
+ $dream->care_num = count($data);
|
|
|
+ $dream->dream_first_pic = $dream->dreamImgsFirst;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|