token['root_org']]; $condition[] = ['publish', '=', 1]; $condition[] = ['delete_time', '=', 0]; empty($label) ?: $condition[] = ['label', '=', $label]; empty($type) ?: $condition[] = ['type', '=', $type]; empty($keyword) ?: $condition[] = ['title', 'like', '%' . $keyword . '%']; // 获取数据 $data = VideoModel::where($condition)->field('id,title,description,video_url,uploadtime,cover,shared_times,cover_share_img'); if ($order == 'clue_number') { $data = $data->select()->toArray(); } else { $data = $data->page($page, $limit)->order($order . ' ' . $desc)->select()->toArray(); } $count = VideoModel::where($condition)->count(); $user_id = $this->request->token['uid']; if (!empty($user_id)) { $video_id = array_column($data, 'id'); $video_id = implode(',', $video_id); $user_foot = UserCollect::where([['content_type','=','video'], ['content_id','in',$video_id], ['user_id','=',$user_id]])->column('user_id', 'content_id'); } foreach ($data as &$val) { $val['isCollection'] = false; if (!empty($user_id)) { $val['isCollection'] = isset($user_foot[$val['id']]) ? true : false; } $val['clue_number'] = CustomerClue::where([['pipe_type', '=', 'video'], ['pipe_id', '=', $val['id']]])->count(); /** -----乐尚企业演示,线索数量进行调整按照分享量的三分之一展示,正式使用系统时删除此代码 ------*/ if(request()->token['root_org'] == 1793) { $val['clue_number'] = floor($val['shared_times'] > 0 ? $val['shared_times']/3 : 0); } /*------------------------------------------------------------------------*/ } // 排序 if ($order == 'clue_number') { $sort = $desc == 'desc' ? SORT_DESC : SORT_ASC; array_multisort(array_column($data, $order), $sort, array_column($data, 'uploadtime'), SORT_DESC, $data); $data = array_slice($data, ($page-1) * $limit, $limit); } return json(['code' => 0, 'data' => $data, 'count' => $count, 'msg' => '获取成功']); } /** * 类型获取 */ public function type() { $type = VideoType::where(['pid' => 0, 'type' => 'video', 'root_id' => request()->token['root_org']])->select()->toArray(); $label = VideoType::where([['pid', '>', 0], ['type', '=', 'video'], ['root_id', '=', request()->token['root_org']]])->select()->toArray(); foreach ($type as &$val) { $val['sonLabel'] = []; foreach ($label as $typeVal) { if ($val['id'] == $typeVal['pid']) { $val['sonLabel'][] = $typeVal; } } } return json(['code' => 0, 'data' => $type, 'msg' => '获取成功']); } /** * 获取所有标签 */ public function get_all_label(){ $label = VideoType::field('id,pid,name')->where([['pid', '>', 0], ['type', '=', 'video'], ['root_id', '=', request()->token['root_org']]])->select()->toArray(); return json(['code' => 0, 'data' => $label, 'msg' => '获取成功']); } /** * 获取视频详情 */ public function info($video_id) { $video = VideoModel::where(['id' => $video_id, 'publish' => 1, 'delete_time' => 0])->find(); $user_id = $this->request->token['uid']; $collect = UserCollect::where(['user_id' => $user_id, 'content_type' => 'video', 'content_id' => $video_id])->count(); $video['collect'] = $collect > 0 ? true : false; return json(['code' => 0, 'msg' => '获取成功', 'data' => $video]); } /** * 收藏 */ public function collect($id) { $user_id = $this->request->token['uid']; $had = UserCollect::where(['user_id' => $user_id, 'content_type' => 'video', 'content_id' => $id])->count(); if ($had > 0) return json(['code' => 1, 'msg' => '您已收藏']); UserCollect::insert(['user_id' => $user_id, 'content_type' => 'video', 'content_id' => $id]); return json(['code' => 0, 'msg' => '收藏成功']); } /** * 取消收藏 */ public function collectCancel($id) { $user_id = $this->request->token['uid']; UserCollect::where(['user_id' => $user_id, 'content_type' => 'video', 'content_id' => $id])->delete(); return json(['code' => 0, 'msg' => '取消收藏']); } }