| xqd
@@ -7,6 +7,7 @@ use App\Models\BaseSettingsModel;
|
|
|
use App\Models\DreamImages;
|
|
|
use App\Models\DreamInfoModel;
|
|
|
use App\Models\InteractionInfo;
|
|
|
+use App\Models\SearchInfoModel;
|
|
|
use App\Models\SupportDreamModel;
|
|
|
use App\Models\SystemInfoModel;
|
|
|
use App\Models\UserCareDream;
|
| xqd
@@ -22,7 +23,7 @@ class DreamController extends Controller
|
|
|
* @apiGroup Dream
|
|
|
* @apiPermission Passport
|
|
|
* @apiVersion 0.1.0
|
|
|
- * @apiParam {int} type index interaction paihang 默认all
|
|
|
+ * @apiParam {int} type home interaction paihang 默认all
|
|
|
* @apiParam {int} id 梦想ID
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
| xqd
@@ -139,11 +140,11 @@ class DreamController extends Controller
|
|
|
$id = $request->id; //梦想ID
|
|
|
if (empty($id)) return $this->error(ErrorCode::KEY_ERROR);
|
|
|
|
|
|
- $info = SupportDreamModel::where('dream_id',$id)->get();
|
|
|
+ $support_dream = SupportDreamModel::where('dream_id',$id)->get();
|
|
|
$top = [] ;
|
|
|
- $topuser = [];
|
|
|
- $top3user = [];
|
|
|
- foreach ($info as $item) {
|
|
|
+ $topuser = []; //所有支持用户排行
|
|
|
+ $top3user = []; // 支持用户排行前三
|
|
|
+ foreach ($support_dream as $item) {
|
|
|
if (!array_key_exists($item->user_id,$top)) {
|
|
|
$top[$item->user_id] = $item->score;
|
|
|
}else{
|
| xqd
@@ -155,14 +156,14 @@ class DreamController extends Controller
|
|
|
$user = UserInfoModel::find($user_id);
|
|
|
$user->score = $score;
|
|
|
$topuser[] = $user;
|
|
|
- if(count($top3user)<=2)$top3user[] = $user;
|
|
|
+ if(count($top3user)<=2) $top3user[] = $user;
|
|
|
}
|
|
|
if ($type == 'paihang') return $this->api($topuser);
|
|
|
|
|
|
$interactios = InteractionInfo::where('dream_id',$id)->orderBy('id','desc')->get();
|
|
|
foreach ($interactios as $item) {
|
|
|
dd($item->comments);
|
|
|
- $item->with(['comments']);
|
|
|
+// $item->with(['comments']);
|
|
|
foreach ($item->comments as $comment) {
|
|
|
$comment->pic = UserInfoModel::find($comment->user_id)->pic;
|
|
|
$comment->replay = $comment->replay;
|
| xqd
@@ -416,4 +417,63 @@ class DreamController extends Controller
|
|
|
return $this->error(ErrorCode::SAVE_USER_FAILED);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @api {get} /api/dream/search 梦想搜索
|
|
|
+ * @apiDescription 梦想搜索)
|
|
|
+ * @apiGroup Dream
|
|
|
+ * @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 search(Request $request)
|
|
|
+ {
|
|
|
+ $user = $this->getUser();
|
|
|
+ if (empty($request->keyword)) {
|
|
|
+ return $this->api('');
|
|
|
+ }
|
|
|
+ $keyword ='%'.$request->keyword.'%';
|
|
|
+ $data = DreamInfoModel::where('dream','like',$keyword)->
|
|
|
+ orWhere('sign','like',$keyword)->get();
|
|
|
+ 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'));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|