getUser();
$validator = \Validator::make($request->all(),
[
'id' => 'required',
'title' => 'required',
],
[
'id.required' => '梦想ID不能为空',
'title.required' => '动态标题不能为空',
]
);
if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
$data = [];
$pics = $request->pics;
if (empty($pics) || !is_array($pics)) {
// return $this->error(ErrorCode::ATTACHMENT_NOT_EXIST);
}else{
foreach ($pics as $k => $pic) {
$data['pic'.($k+1)] = $pic;
}
}
$dream_id = $request->id;
$dream_name = DreamInfoModel::find($dream_id)->name;
$title = $request->title;
$data['dream_id'] = $dream_id;
$data['title'] = $title;
$video = $request->video;
if (!empty($video)) $data['video'] =env('APP_URL').'/attachment/'. $request->video;
$ok = InteractionInfo::create($data);
if ($ok) {
// 新的互动应该有消息通知《支持者》
$support_user = SupportDreamModel::where('dream_id',$dream_id)->get();
if (!empty(count($support_user))) {
$user_ids = array_column($support_user->toArray(),'user_id');
foreach ($user_ids as $user_id) {
$arr['user_id']=$user->id;
$arr['to_user_id']=$user_id;
$arr['message']='您支持的梦想《'.$dream_name.'》又有新的动态啦';
$arr['interaction_id']=$ok->id;
$arr['dream_id']=$dream_id;
SystemInfoModel::create($arr);
// 长连接
$this->jPush($arr['message'],'',$user_id);
}
}
// 收藏梦想的最新动态加一
UserCareDream::where('dream_id',$dream_id)->increment('interaction_number',1);
$dream_user_id = DreamInfoModel::find($dream_id)->user_id;
UserCareUser::where('other_user_id',$dream_user_id)->update(['dream_id'=>$dream_id,'dream_number'=>'1']);
// UserCareUser::where('dream_id',$dream_id)->increment('interaction_number',1);
return $this->api('');
}else{
return $this->error(ErrorCode::SAVE_USER_FAILED);
}
}
// 评论互动
/**
* @api {post} /api/interaction/comment 评论动态
* @apiDescription 评论动态
* @apiGroup Interaction
* @apiPermission Passport
* @apiVersion 0.1.0
* @apiParam {int} id 动态ID不存在
* @apiParam {int} u_id @用户id
* @apiParam {int} to_user_id 发布动态的梦想者id
* @apiParam {int} [comment_user_id] //已经评论者id
* @apiParam {string} content 内容不能为空
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
*{
* "status": true,
* "status_code": 0,
* "message": "",
* "data": ""
*}
* @apiErrorExample {json} Error-Response:
*HTTP/1.1 400 Bad Request
* {
* "state": false,
* "code": 1000,
* "message": "传入参数不正确",
* "data": null or []
* }
*
*/
public function comment(Request $request)
{
$validator = \Validator::make($request->all(),
[
'id' => 'required',
'content' => 'required',
],
[
'id.required' => '动态ID不存在',
'content.required' => '内容不能为空',
]
);
if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
$user = $this->getUser();
/* $user_id = $user->id;
$user_avatar = $user->avatar;
$user_nickname = $user->nickname;
$interaction_id = $request->id;
$content = $request->content;
$is_read = 1;
$data = compact('user_id','user_avatar','user_nickname','interaction_id','content','is_read');*/
$toid = $request->input('to_user_id');
$dream_id = InteractionInfo::find($request->id)->dream_id;
// $data['to_user_avatar'] = InteractionInfo::find($request->id)->dream->user_avatar;
// $data['to_user_nickname'] = InteractionInfo::find($request->id)->dream->user_nickname;
if (!empty($request->input('comment_user_id'))) {
$to_user = UserInfoModel::find($request->input('comment_user_id'));
if (!empty($to_user)){
$data['to_user_id'] = $request->input('to_user_id');
$data['to_user_avatar'] = $to_user->avatar;
$data['to_user_nickname'] = $to_user->nickname;
//点击去看看
$message = ""."[$user->nickname] ".'在你的互动上留言啦!点击去看看';
$info = [
'to_user_id' => $data['to_user_id'],
'message' => $message,
'is_url' => 1,
'type_id' => 1,
'attr_id' => 3,
'dream_id' => $dream_id,
'interaction_id' => $request->input('id'),
];
SystemInfoModel::create($info);
}
}
$this->jPush($user->nickname."在你的互动上留言啦!点击去看看",'',$toid);
if (!empty($request->input('u_id'))) {
$message = ""."[$user->nickname] ".'提起了你哦~点击看看!';
$info = [
'to_user_id' => $request->input('u_id'),
'message' => $message,
'is_url' => 1,
'type_id' => 1,
'attr_id' => 8,
'dream_id' => $dream_id,
'interaction_id' => $request->input('id'),
];
SystemInfoModel::create($info);
}
$data['user_id'] = $user->id;
$data['user_avatar'] =$user->avatar;
$data['user_nickname'] = $user->nickname;
$data['interaction_id'] = $request->id;
$data['content'] = $request->content;
$data['is_read'] = 1;
$ok = CommentInfoModel::create($data);
if ($ok) {
// 评论动态也会出现在首页用户
UserCareDream::where('dream_id',$dream_id)->increment('interaction_number',1);
$this->autoCareDream($user->id,$user->nickname,$dream_id);
return $this->api('');
// 评论成功自动收藏梦想
}else{
return $this->error(ErrorCode::OPERATION_FAILED);
}
}
// 回复评论
/**
* @api {post} /api/interaction/reply 我的回复
* @apiDescription 我的回复
* @apiGroup Interaction
* @apiParam {text} content 回复内容
* @apiParam {int} comment_id 评论ID
* @apiParam {int} interaction_id 动态ID
* @apiPermission Passport
* @apiVersion 0.1.0
* @apiSuccessExample {json} Success-Response:
* {
* "status": true,
* "status_code": 0,
* "message": "",
* "data": ""
*}
* HTTP/1.1 200 OK
* @apiErrorExample {json} Error-Response:
* {
* "status": false,
* "status_code": 1000,
* "message": "输入不正确",
* "data": null
*}
* HTTP/1.1 400 Bad Request
*/
public function reply(Request $request)
{
$validator = \Validator::make($request->all(),
[
'id' => 'required',
'interaction_id' => 'required',
'content' => 'required',
],
[
'id.required' => '评论ID不存在',
'content.required' => '内容不能为空',
]
);
if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
$user = $this->getUser();
/* $data['to_user_id'] = $user->id;
$data['to_user_avatar'] = $user->avatar;
$data['to_user_nickname'] = $user->nickname; */
$data['to_user_id'] = CommentInfoModel::find($request->id)->user_id;
// $data['to_user_avatar'] = CommentInfoModel::find($request->id)->user_avatar;
$data['to_user_nickname'] = CommentInfoModel::find($request->id)->user_nickname;
$data['user_id'] = $user->id;
$data['user_avatar'] =$user->avatar;
$data['user_nickname'] = $user->nickname;
$data['interaction_id'] = $request->id;
$data['content'] = $request->content;
$data['is_read'] = 1;
if (!$request->content)
return $this->error(ErrorCode::CONNET_NOT_EXIST);
$ok = CommentInfoModel::create($data);
if ($ok) {
// 评论成功自动收藏梦想
$dream_id = InteractionInfo::find($request->id)->dream_id;
$this->autoCareDream($user->id,$user->nickname,$dream_id);
return $this->api('');
}else{
return $this->error(ErrorCode::OPERATION_FAILED);
}
}
/**
* @api {get} /api/comment/delete 删除评论
* @apiDescription 删除评论
* @apiGroup Interaction
* @apiParam {int} id 评论ID
* @apiPermission Passport
* @apiVersion 0.1.0
* @apiSuccessExample {json} Success-Response:
* {
* "status": true,
* "status_code": 0,
* "message": "",
* "data": ""
*}
* HTTP/1.1 200 OK
* @apiErrorExample {json} Error-Response:
* {
* "status": false,
* "status_code": 700,
* "message": "操作失败",
* "data": null
*}
* HTTP/1.1 400 Bad Request
*/
public function delete(Request $request)
{
$validator = \Validator::make($request->all(),
[
'id' => 'required',
],
[
'id.required' => '评论ID不存在',
]
);
if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
$user = $this->getUser();
$ok = CommentInfoModel::where('user_id',$user->id)->where('id',$request->id)->delete();
if ($ok) {
return $this->api('');
}else{
return $this->error(ErrorCode::OPERATION_FAILED);
}
}
/**
* @api {get} /api/interaction/destroy 删除动态
* @apiDescription 删除动态
* @apiGroup Interaction
* @apiParam {int} id 动态ID
* @apiPermission Passport
* @apiVersion 0.1.0
* @apiSuccessExample {json} Success-Response:
* {
* "status": true,
* "status_code": 0,
* "message": "",
* "data": ""
*}
* HTTP/1.1 200 OK
* @apiErrorExample {json} Error-Response:
* {
* "status": false,
* "status_code": 700,
* "message": "操作失败",
* "data": null
*}
* HTTP/1.1 400 Bad Request
*/
public function destroy(Request $request)
{
$validator = \Validator::make($request->all(),
[
'id' => 'required',
],
[
'id.required' => '动态ID不存在',
]
);
if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
// $user = $this->getUser();
$id = $request->input('id');
CommentInfoModel::where('interaction_id',$id)->delete();
$ok = InteractionInfo::destroy($id);
if ($ok) {
return $this->api('');
}else{
return $this->error(ErrorCode::OPERATION_FAILED);
}
}
public function autoCareDream($user_id,$nickname,$dream_id)
{
$user_care_dream = UserCareDream::where('user_id',$user_id)->where('dream_id',$dream_id)->first();
if (empty($user_care_dream)) {
$dream = DreamInfoModel::find($dream_id);
$data_info = [
'user_id' =>$user_id,
'dream_id' =>$dream_id,
'dream_user_id' =>$dream->user_id,
];
UserCareDream::create($data_info);
// 关注成功发送私信
$message = BaseSettingsModel::where('category','message')->first();
$message = empty($message) ? ""."[$nickname] 收藏了你的梦想《".$dream->name.'》' : $message->value;
$info2 = [
'to_user_id' => $dream->user_id,
'message' => $message,
'dream_id' => $dream_id,
'user_id' => $user_id,
'is_reply' => 1,
'type_id' => 1,
'attr_id' => 2,
];
SystemInfoModel::firstOrCreate($info2);
}
}
/**
* @api {get} /api/interaction/add_comment_blackList 加入黑名单
* @apiDescription 隐藏某个人的评论
* @apiGroup Interaction
* @apiParam {int} dream_id 梦想id
* @apiParam {int} interaction_id 动态id
* @apiParam {int} user_id 加入黑名单用户id
* @apiPermission Passport
* @apiVersion 0.1.0
* @apiSuccessExample {json} Success-Response:
* {
* "status": true,
* "status_code": 0,
* "message": "",
* "data": ""
*}
* HTTP/1.1 200 OK
* @apiErrorExample {json} Error-Response:
* {
* "status": false,
* "status_code": 700,
* "message": "操作失败",
* "data": null
*}
* HTTP/1.1 400 Bad Request
*/
public function addCommentBlackList(Request $request)
{
$user = $this->getUser();
$user_id = $request->input('user_id');
$interaction_id = $request->input('interaction_id');
$dream_id = $request->input('dream_id');
$login_user_id = $user->id;
$dream = DreamInfoModel::find($dream_id);
if (empty($dream)) return $this->error(ErrorCode::DREAM_NOT_EXIST);
if ($dream->user_id != $login_user_id) return $this->error(ErrorCode::OPERATION_FAILED);
$interaction = InteractionInfo::find($interaction_id);
if (empty($interaction)) return $this->error(ErrorCode::INTERACTION_NOT_EXIST);
$interaction->black_list = $user_id.',';
$ok = $interaction->save();
if ($ok) return $this->api();
return $this->error(ErrorCode::OPERATION_FAILED);
}
}