|
@@ -62,15 +62,14 @@ class Comment extends Api{
|
|
|
if( !$articleData ) return json_send(['code'=>'error','msg'=>'文章不存在或者已下架']);
|
|
|
// 转数组
|
|
|
$articleData = $articleData->toArray();
|
|
|
- // 如果用户不存在
|
|
|
- $oldData = $uid ? $ArticleEvent->query()->where([['custom_uid','=',$uid],['article_id','=',$id],['type_id','=',1]])->value('id') : 0;
|
|
|
// 阅读数 + 1
|
|
|
$Model->query()->where([['id','=',$id]])->increment('read_count');
|
|
|
// 如果事件不存在,新增此次事件
|
|
|
- if( !$oldData && $uid ) $ArticleEvent->add(['custom_uid'=>$uid,'article_id'=>$id,'type_id'=>1,'status'=>0]);
|
|
|
+ $ArticleEvent->add(['custom_uid'=>$uid,'article_id'=>$id,'type_id'=>1,'status'=>0]);
|
|
|
// 用户是否点赞和推荐
|
|
|
$articleData['is_hand'] = $uid ? (int) $ArticleEvent->query()->where([['custom_uid','=',$uid],['article_id','=',$id],['type_id','=',2],['status','=',0]])->value('id') : 0;
|
|
|
$articleData['is_like'] = $uid ? (int) $ArticleEvent->query()->where([['custom_uid','=',$uid],['article_id','=',$id],['type_id','=',4],['status','=',0]])->value('id') : 0;
|
|
|
+ $articleData['insert_time'] = date('Y年m月d日 H:s',$articleData['insert_time']);
|
|
|
// 返回结果
|
|
|
return json_send(['code'=>'success','msg'=>'暂无','data'=>$articleData]);
|
|
|
|
|
@@ -90,22 +89,26 @@ class Comment extends Api{
|
|
|
$oldData = $uid ? $ArticleEvent->query()->where([['custom_uid','=',$uid],['article_id','=',$articleId],['type_id','=',$typeId]])->first(['id','status']) : [];
|
|
|
// 判断事件。
|
|
|
$oldData = $oldData ? $oldData->toArray() : [];
|
|
|
- // 更新状态
|
|
|
- if( $oldData ){
|
|
|
+ // 事件已存在,并且是点赞或者喜欢
|
|
|
+ if( $oldData && in_array($typeId,[2,4]) ){
|
|
|
+ // 更新事件状态
|
|
|
$ArticleEvent->edit($oldData['id'],['status'=>$oldData['status']?0:1]);
|
|
|
}else{
|
|
|
- // 如果事件不存在,新增此次事件
|
|
|
- if( $uid ) $ArticleEvent->add(['custom_uid'=>$uid,'article_id'=>$articleId,'type_id'=>$typeId,'status'=>0]);
|
|
|
+ // 新增事件
|
|
|
+ $ArticleEvent->add(['custom_uid'=>$uid,'article_id'=>$articleId,'type_id'=>$typeId,'status'=>0]);
|
|
|
}
|
|
|
// 判断数据类型,点赞
|
|
|
if( $typeId == 2 ) {
|
|
|
// 如果旧数据是未点赞或者取消点赞,继续点赞
|
|
|
- ( !$oldData || !empty($oldData['status']) ) ? $Model->query()->where([['id','=',$articleId]])->increment('hand_count') : $Model->query()->where([['id','=',$articleId],['hand_count','>=',1]])->decrement('hand_count');
|
|
|
+ ( !$oldData || !empty($oldData['status']) ) ? $Model->query()->where([['id','=',$articleId]])->increment('hand_count') : $Model->query()->where([['id','=',$articleId],['hand_count','>=',1]])->decrement('hand_count');
|
|
|
}
|
|
|
// 判断数据类型,分享
|
|
|
if( $typeId == 3 ) $Model->query()->where([['id','=',$articleId]])->increment('share_count');
|
|
|
// 判断数据类型,喜欢
|
|
|
- if( $typeId == 4 ) (!$oldData || !empty($oldData['status'])) ? $Model->query()->where([['id','=',$articleId]])->increment('like_count') : $Model->query()->where([['id','=',$articleId],['like_count','>=',1]])->decrement('like_count') ;
|
|
|
+ if( $typeId == 4 ) {
|
|
|
+ // 如果旧数据是未喜欢或者取消喜欢或,继续喜欢
|
|
|
+ ( !$oldData || !empty($oldData['status']) ) ? $Model->query()->where([['id','=',$articleId]])->increment('like_count') : $Model->query()->where([['id','=',$articleId],['like_count','>=',1]])->decrement('like_count') ;
|
|
|
+ }
|
|
|
// 返回结果
|
|
|
return json_send(['code'=>'success','msg'=>'操作成功','data'=>'']);
|
|
|
}
|