123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- <?php
- namespace App\Http\Controllers\Api\V1;
- use App\Models\CommentInfoModel;
- use App\Models\InteractionInfo;
- use App\Models\ReplyCommentsInfo;
- use App\Models\SystemInfoModel;
- use App\Models\UserCareDream;
- use Illuminate\Http\Request;
- use App\Services\Base\ErrorCode;
- use App\Helper\JpushHelper;
- class InteractionController extends Controller
- {
- use JpushHelper;
- // 发布关于梦想的动态
- /**
- * @api {post} /api/interaction/store 新增动态
- * @apiDescription 新增动态
- * @apiGroup Interaction
- * @apiPermission Passport
- * @apiVersion 0.1.0
- * @apiParam {int} id 梦想ID
- * @apiParam {string} title 互动标题
- * @apiParam {string} [video] 视频
- * @apiParam {array} pics[] 图片数组
- * @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 store(Request $request)
- {
- $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;
- $title = $request->title;
- $data['dream_id'] = $dream_id;
- $data['title'] = $title;
- $data['video'] = $request->video;
- $ok = InteractionInfo::create($data);
- if ($ok) {
- // 收藏梦想最新动态加一
- UserCareDream::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 {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');*/
- $data['to_user_id'] = InteractionInfo::find($request->id)->dream->user_id;
- $data['to_user_avatar'] = InteractionInfo::find($request->id)->dream->user_avatar;
- $data['to_user_nickname'] = InteractionInfo::find($request->id)->dream->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;
- $ok = CommentInfoModel::create($data);
- $message = $user->nickname.'在你的互动上留言啦!点击去看看!';
- $info = [
- 'user_id' => $data['to_user_id'],
- 'message' => $message,
- ];
- SystemInfoModel::create($info);
- // 长连接
- $this->jPush($message,'',$data['to_user_id']);
- if ($ok) {
- 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) {
- 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);
- }
- }
- }
|