|
|
@@ -62,15 +62,14 @@ class VideoCommentService extends BaseService
|
|
|
public function getDataList($params, $pageSize = 15, $field='', $userId=0)
|
|
|
{
|
|
|
$where = ['a.mark' => 1,'a.status'=>1,'b.status'=>1,'b.mark'=>1];
|
|
|
- $field = $field? $field : 'lev_a.*,lev_b.id as cid,lev_b.user_id as collect_user_id,lev_a.type as collect_type';
|
|
|
+ $field = $field? $field : 'lev_a.*';
|
|
|
$sortType = isset($params['sort_type']) ? $params['sort_type'] : 1;
|
|
|
- $order = 'id desc';
|
|
|
+ $order = 'a.id desc';
|
|
|
if($sortType == 1){
|
|
|
$order = 'lev_b.create_time desc, lev_b.id desc';
|
|
|
}
|
|
|
$list = $this->model->with(['member'])
|
|
|
- ->from('video_comments as b')
|
|
|
- ->leftJoin('video as a', 'a.id', '=', 'b.collect_id')
|
|
|
+ ->from('video_comments as a')
|
|
|
->where($where)
|
|
|
->where(function ($query) use ($params) {
|
|
|
$userId = isset($params['user_id']) ? $params['user_id'] : 0;
|
|
|
@@ -78,9 +77,14 @@ class VideoCommentService extends BaseService
|
|
|
$query->where('a.user_id', $userId);
|
|
|
}
|
|
|
|
|
|
- $collectUserId = isset($params['collect_uid']) ? $params['collect_uid'] : 0;
|
|
|
- if ($collectUserId > 0) {
|
|
|
- $query->where('a.collect_uid', $collectUserId);
|
|
|
+ $videoId = isset($params['video_id']) ? $params['video_id'] : 0;
|
|
|
+ if ($videoId > 0) {
|
|
|
+ $query->where('a.video_id', $videoId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $replyId = isset($params['reply_id']) ? $params['reply_id'] : 0;
|
|
|
+ if ($replyId > 0) {
|
|
|
+ $query->where('a.reply_id', $replyId);
|
|
|
}
|
|
|
|
|
|
$isRead = isset($params['is_read'])? $params['is_read'] : 0;
|
|
|
@@ -89,19 +93,11 @@ class VideoCommentService extends BaseService
|
|
|
$query->where('a.is_read', $isRead);
|
|
|
}
|
|
|
|
|
|
- $type = isset($params['type'])? $params['type'] : 0;
|
|
|
- $type = $type>0? $type : 1;
|
|
|
- if ($type > 0) {
|
|
|
- $query->where('a.type', $type);
|
|
|
- }
|
|
|
-
|
|
|
})
|
|
|
->where(function ($query) use ($params) {
|
|
|
$keyword = isset($params['kw']) ? $params['kw'] : '';
|
|
|
if ($keyword) {
|
|
|
- $query->where('a.title', 'like', "%{$keyword}%")
|
|
|
- ->orWhere('a.tags','like',"%{$keyword}%")
|
|
|
- ->orWhere('a.description','like',"%{$keyword}%");
|
|
|
+ $query->where('a.content','like',"%{$keyword}%");
|
|
|
}
|
|
|
})
|
|
|
->selectRaw($field)
|
|
|
@@ -111,23 +107,10 @@ class VideoCommentService extends BaseService
|
|
|
if ($list) {
|
|
|
foreach ($list['data'] as &$item) {
|
|
|
$item['time_text'] = isset($item['create_time']) && $item['create_time']? dateFormat($item['create_time']) : '';
|
|
|
- $item['thumb'] = isset($item['thumb']) && $item['thumb'] ? get_image_url($item['thumb']) : '';
|
|
|
- $item['file_url'] = isset($item['file_url']) && $item['file_url'] ? get_image_url($item['file_url']) : '';
|
|
|
- if(isset($item['albums'])){
|
|
|
- $albums = $item['albums']? json_decode($item['albums'], true):[];
|
|
|
- $item['albums'] = $albums? get_images_preview($albums) : [];
|
|
|
- }
|
|
|
- if(isset($item['music_url'])){
|
|
|
- $item['music_url'] = $item['music_url']? get_image_url($item['music_url']) : '';
|
|
|
- }
|
|
|
$member = isset($item['member'])? $item['member'] : [];
|
|
|
if($member){
|
|
|
$member['avatar'] = isset($member['avatar'])? get_image_url($member['avatar']) : '';
|
|
|
}
|
|
|
- $item['tags'] = isset($item['tags']) && $item['tags']? explode(',', $item['tags']) : [];
|
|
|
- $item['like_num'] = isset($item['like_num']) && $item['like_num']? format_num($item['like_num']) : 0;
|
|
|
- $item['collect_num'] = isset($item['collect_num']) && $item['collect_num']? format_num($item['collect_num']) : 0;
|
|
|
- $item['views'] = isset($item['views']) && $item['views']? format_num($item['views']) : 0;
|
|
|
$item['member'] = $member;
|
|
|
}
|
|
|
}
|
|
|
@@ -139,32 +122,65 @@ class VideoCommentService extends BaseService
|
|
|
];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 取消
|
|
|
+ * 发布评论
|
|
|
* @param $userId
|
|
|
+ * @param $params
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public function cancel($userId)
|
|
|
+ public function publish($userId, $params)
|
|
|
{
|
|
|
- // 参数
|
|
|
- $ids = request()->post('ids','');
|
|
|
- $ids = $ids? explode(',', $ids) : [];
|
|
|
- $type = request()->post('type',0);
|
|
|
- if (empty($ids) && $type == 0) {
|
|
|
- $this->error = 1033;
|
|
|
- return false;
|
|
|
- }
|
|
|
+ $albums = isset($params['albums'])? get_format_images($params['albums']) : '';
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'reply_id'=> isset($params['reply_id'])? intval($params['reply_id']) : 0,
|
|
|
+ 'video_id'=> isset($params['video_id'])? intval($params['video_id']) : 0,
|
|
|
+ 'reply_to_uid'=> isset($params['reply_to_uid'])? intval($params['reply_to_uid']) : 0,
|
|
|
+ 'albums'=> $albums,
|
|
|
+ 'content'=> isset($params['content'])? trim($params['content']) : '',
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'update_time'=> time(),
|
|
|
+ 'status'=> 1,
|
|
|
+ 'mark'=> 1,
|
|
|
+ ];
|
|
|
|
|
|
- if($type){
|
|
|
- $this->model->where(['user_id'=> $userId,'status'=>1,'mark'=>1])->update(['status'=>2,'update_time'=>time()]);
|
|
|
- }else {
|
|
|
- $this->model->where(['user_id'=> $userId,'status'=>1,'mark'=>1])->whereIn('id', $ids)->update(['status'=>2,'update_time'=>time()]);
|
|
|
+ if($this->model->insertGetId($data)){
|
|
|
+ $this->error = 2942;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- $this->error = 1002;
|
|
|
+ $this->error = 2943;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 点赞
|
|
|
+ * @param $userId
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function like($userId, $params)
|
|
|
+ {
|
|
|
+ $id = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $status = isset($params['status'])? $params['status'] : 1;
|
|
|
+ $cacheKey = "caches:videos:comment_{$userId}_{$id}";
|
|
|
+ if(RedisService::get($cacheKey)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
+ if(!$info = $this->model->where(['id'=> $id,'mark'=>1])->select(['id','like_num'])->first()){
|
|
|
+ $this->error = 2941;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $updateData['like_num'] = ($status == 1 ? $info['like_num']+1 : max(0, $info['like_num']-1));
|
|
|
+ if ($this->model->where(['id' => $id, 'mark' => 1])->update($updateData)) {
|
|
|
+ $this->error = 1002;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->error = 1003;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|