|
@@ -24,17 +24,16 @@ class Comment extends Api{
|
|
public function list(Model $Model, ArticleCommentModel $ArticleCommentModel){
|
|
public function list(Model $Model, ArticleCommentModel $ArticleCommentModel){
|
|
|
|
|
|
// 接受参数
|
|
// 接受参数
|
|
- $code = request('article_code','');
|
|
|
|
|
|
|
|
- $status = request('status');
|
|
|
|
|
|
+
|
|
|
|
+ $status = request('status', null);
|
|
$startTime = request('start_time','');
|
|
$startTime = request('start_time','');
|
|
$endTime = request('end_time','');
|
|
$endTime = request('end_time','');
|
|
- // 编码转ID
|
|
|
|
- $id = $code ? $Model->codeToId($code) : 0;
|
|
|
|
|
|
+
|
|
// 查询条件
|
|
// 查询条件
|
|
$map = [];
|
|
$map = [];
|
|
// 编码ID
|
|
// 编码ID
|
|
- if( $id ) $map[] = ['id','=',$id];
|
|
|
|
|
|
+
|
|
if( $startTime ) $map[] = ['start_time','>=',strtotime($startTime)];
|
|
if( $startTime ) $map[] = ['start_time','>=',strtotime($startTime)];
|
|
if( $endTime ) $map[] = ['end_time','<=',strtotime($endTime)];
|
|
if( $endTime ) $map[] = ['end_time','<=',strtotime($endTime)];
|
|
if( !is_null($status) ) $map[] = ['status','=',$status];
|
|
if( !is_null($status) ) $map[] = ['status','=',$status];
|
|
@@ -42,7 +41,7 @@ class Comment extends Api{
|
|
$list = $Model->query()->where($map);
|
|
$list = $Model->query()->where($map);
|
|
$list = $list->orderByDesc('id')->paginate(request('limit',config('page_num',10)))->appends(request()->all());
|
|
$list = $list->orderByDesc('id')->paginate(request('limit',config('page_num',10)))->appends(request()->all());
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
// 循环处理数据
|
|
// 循环处理数据
|
|
foreach ($list as $key => $value) {
|
|
foreach ($list as $key => $value) {
|
|
// id转编号
|
|
// id转编号
|
|
@@ -64,9 +63,6 @@ class Comment extends Api{
|
|
|
|
|
|
// 分配数据
|
|
// 分配数据
|
|
return json_send(['code'=>'success','msg'=>'列表数据','data'=>$list]);
|
|
return json_send(['code'=>'success','msg'=>'列表数据','data'=>$list]);
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -79,7 +75,7 @@ class Comment extends Api{
|
|
$tid = request('article_id',0);
|
|
$tid = request('article_id',0);
|
|
|
|
|
|
$uid = $this->checkLogin(); // custom_uid
|
|
$uid = $this->checkLogin(); // custom_uid
|
|
-
|
|
|
|
|
|
+
|
|
// 查询条件
|
|
// 查询条件
|
|
$map = [];
|
|
$map = [];
|
|
// 编码ID
|
|
// 编码ID
|
|
@@ -89,65 +85,63 @@ class Comment extends Api{
|
|
|
|
|
|
|
|
|
|
$data = $Model->query()->where($map)->find($tid,['id','title','poster','content']);
|
|
$data = $Model->query()->where($map)->find($tid,['id','title','poster','content']);
|
|
- $data['like_count'] = $ArticleCommentModel->query()
|
|
|
|
|
|
+ if ($data){
|
|
|
|
+ $data['like_count'] = $ArticleCommentModel->query()
|
|
->where(['article_id'=>$tid,'event_type'=>2])
|
|
->where(['article_id'=>$tid,'event_type'=>2])
|
|
->count();
|
|
->count();
|
|
|
|
|
|
- $data['read_count'] = $ArticleCommentModel->query()
|
|
|
|
- ->where(['article_id'=>$tid,'event_type'=>1])
|
|
|
|
- ->count();
|
|
|
|
-
|
|
|
|
- $data['share_count'] = $ArticleCommentModel->query()
|
|
|
|
- ->where(['article_id'=>$tid,'event_type'=>3])
|
|
|
|
- ->count();
|
|
|
|
-
|
|
|
|
- $data['recommend_count'] = $ArticleCommentModel->query()
|
|
|
|
- ->where(['article_id'=>$tid,'event_type'=>4])
|
|
|
|
- ->count();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //用户是否点赞和推荐
|
|
|
|
- if ($uid){
|
|
|
|
- $user_envent = $ArticleCommentModel->query()->where(['uid'=>$uid,'article_id'=>$tid])
|
|
|
|
- ->get();
|
|
|
|
- foreach ($user_envent as $value){
|
|
|
|
-
|
|
|
|
- if ($value['event_type'] == 2){
|
|
|
|
- $data['like_type'] = 2;
|
|
|
|
- }else{
|
|
|
|
- $data['like_type'] = 6;
|
|
|
|
|
|
+ $data['read_count'] = $ArticleCommentModel->query()
|
|
|
|
+ ->where(['article_id'=>$tid,'event_type'=>1])
|
|
|
|
+ ->count();
|
|
|
|
+
|
|
|
|
+ $data['share_count'] = $ArticleCommentModel->query()
|
|
|
|
+ ->where(['article_id'=>$tid,'event_type'=>3])
|
|
|
|
+ ->count();
|
|
|
|
+
|
|
|
|
+ $data['recommend_count'] = $ArticleCommentModel->query()
|
|
|
|
+ ->where(['article_id'=>$tid,'event_type'=>4])
|
|
|
|
+ ->count();
|
|
|
|
+ if ($uid){
|
|
|
|
+ $user_envent = $ArticleCommentModel->query()->where(['uid'=>$uid,'article_id'=>$tid])
|
|
|
|
+ ->get();
|
|
|
|
+ foreach ($user_envent as $value){
|
|
|
|
+
|
|
|
|
+ if ($value['event_type'] == 2){
|
|
|
|
+ $data['like_type'] = 2;
|
|
|
|
+ }else{
|
|
|
|
+ $data['like_type'] = 6;
|
|
|
|
+ }
|
|
|
|
+ if ($value['event_type'] == 4){
|
|
|
|
+ $data['recommend_type'] = 4;
|
|
|
|
+ }else{
|
|
|
|
+ $data['recommend_type'] = 5;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if ($value['event_type'] == 4){
|
|
|
|
- $data['recommend_type'] = 4;
|
|
|
|
- }else{
|
|
|
|
- $data['recommend_type'] = 5;
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //写入浏览记录
|
|
|
|
+ $read = [
|
|
|
|
+ 'article_id' => $tid,
|
|
|
|
+ 'event_type' => 1,
|
|
|
|
+ 'uid' => $uid,
|
|
|
|
+ 'insert_time' => time()
|
|
|
|
+ ];
|
|
|
|
+ //查询用户是否浏览过
|
|
|
|
+ $read_type = $ArticleCommentModel->query()->where(['uid'=>$uid,'article_id'=>$tid])->value('event_type');
|
|
|
|
+
|
|
|
|
+ if (!$read_type){
|
|
|
|
+ $comment_id = $ArticleCommentModel->add($read);
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //写入浏览记录
|
|
|
|
- $read = [
|
|
|
|
- 'article_id' => $tid,
|
|
|
|
- 'event_type' => 1,
|
|
|
|
- 'uid' => $uid,
|
|
|
|
- 'insert_time' => time()
|
|
|
|
- ];
|
|
|
|
- //查询用户是否浏览过
|
|
|
|
- $read_type = $ArticleCommentModel->query()->where(['uid'=>$uid,'article_id'=>$tid])->value('event_type');
|
|
|
|
|
|
+ }else{
|
|
|
|
|
|
- if (!$read_type){
|
|
|
|
- $comment_id = $ArticleCommentModel->add($read);
|
|
|
|
|
|
+ $read['event_type'] = 0;//禁止分享、推荐和点赞
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- }else{
|
|
|
|
-
|
|
|
|
- $read['event_type'] = 0;//禁止分享、推荐和点赞
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// 加载模板
|
|
// 加载模板
|
|
|
|
|
|
- if ($data){
|
|
|
|
|
|
+ if (!empty($data)){
|
|
return json_send(['code'=>'success','msg'=>'数据','data'=>$data]);
|
|
return json_send(['code'=>'success','msg'=>'数据','data'=>$data]);
|
|
}
|
|
}
|
|
return json_send(['code'=>'success','msg'=>'暂无','data'=>[]]);
|
|
return json_send(['code'=>'success','msg'=>'暂无','data'=>[]]);
|
|
@@ -168,7 +162,7 @@ class Comment extends Api{
|
|
$event = request('event_type',0);
|
|
$event = request('event_type',0);
|
|
$tid = request('article_id',0);
|
|
$tid = request('article_id',0);
|
|
$uid = $this->checkLogin(); // custom_uid
|
|
$uid = $this->checkLogin(); // custom_uid
|
|
-
|
|
|
|
|
|
+
|
|
// 查询条件
|
|
// 查询条件
|
|
$map = [];
|
|
$map = [];
|
|
$map[] = ['uid','=',$uid];
|
|
$map[] = ['uid','=',$uid];
|
|
@@ -193,12 +187,12 @@ class Comment extends Api{
|
|
return json_send(['code'=>'error','msg'=>'取消推荐','data'=>[]]);
|
|
return json_send(['code'=>'error','msg'=>'取消推荐','data'=>[]]);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
- case 6:
|
|
|
|
|
|
+ default:
|
|
$map[] = ['uid','=',$uid];
|
|
$map[] = ['uid','=',$uid];
|
|
$map[] = ['article_id','=',$tid];
|
|
$map[] = ['article_id','=',$tid];
|
|
$map[] = ['event_type','=',$event];
|
|
$map[] = ['event_type','=',$event];
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
$user_envent = $ArticleCommentModel->query()->where($map)->get();
|
|
$user_envent = $ArticleCommentModel->query()->where($map)->get();
|
|
if( $tid ) $map[] = ['id','=',$tid];
|
|
if( $tid ) $map[] = ['id','=',$tid];
|
|
// $orderRes = $Model::query()->where('article_id','=',$tid)->update(['status'=>'1']);
|
|
// $orderRes = $Model::query()->where('article_id','=',$tid)->update(['status'=>'1']);
|
|
@@ -207,7 +201,7 @@ class Comment extends Api{
|
|
|
|
|
|
return json_send(['code'=>'success','msg'=>'成功',
|
|
return json_send(['code'=>'success','msg'=>'成功',
|
|
'data'=>[
|
|
'data'=>[
|
|
- 'event_type'=>$event,'article_id'=>$tid,'uid'=>$uid]
|
|
|
|
|
|
+ 'event_type'=>$event,'article_id'=>$tid]
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
|