VideoController.php 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-04-30
  10. // +—————————————————————————————————————————————————————————————————————
  11. /**
  12. * 短视频
  13. */
  14. namespace app\admin\controller;
  15. use cmf\controller\AdminBaseController;
  16. use think\Db;
  17. use think\db\Query;
  18. class VideoController extends AdminbaseController {
  19. protected function initialize(){
  20. parent::initialize();
  21. $site_info=cmf_get_option('site_info');
  22. $name_coin=$site_info['name_coin'];
  23. $this->name_coin=$name_coin;
  24. }
  25. /*待审核视频列表*/
  26. public function index(){
  27. $ordertype = $this->request->param('ordertype');
  28. $orderstr="";
  29. if($ordertype==1){//评论数排序
  30. $orderstr="comments DESC";
  31. }else if($ordertype==2){//票房数量排序(点赞)
  32. $orderstr="likes DESC";
  33. }else if($ordertype==3){//分享数量排序
  34. $orderstr="shares DESC";
  35. }else{
  36. $orderstr="addtime DESC";
  37. }
  38. $lists = Db::name('user_video')
  39. ->where(function (Query $query) {
  40. $data = $this->request->param();
  41. $query->where('isdel', 0);
  42. $query->where('status', 0);
  43. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  44. $keyword1=isset($data['keyword1']) ? $data['keyword1']: '';
  45. $keyword2=isset($data['keyword2']) ? $data['keyword2']: '';
  46. if (!empty($keyword)) {
  47. $query->where('uid|id', 'like', "%$keyword%");
  48. }
  49. if (!empty($keyword1)) {
  50. $query->where('title', 'like', "%$keyword1%");
  51. }
  52. if (!empty($keyword2)) {
  53. $userlist =Db::name("user")
  54. ->field("id")
  55. ->where("user_nicename like '%".$keyword2."%'")
  56. ->select();
  57. $strids="";
  58. $userlist->all();
  59. foreach ($userlist as $k => $vu) {
  60. if($strids==""){
  61. $strids=$vu['id'];
  62. }else{
  63. $strids.=",".$vu['id'];
  64. }
  65. }
  66. $query->where('uid', 'in', $strids);
  67. }
  68. })
  69. ->order($orderstr)
  70. ->paginate(20);
  71. $lists->each(function($v,$k){
  72. if($v['uid']==0){
  73. $userinfo=array(
  74. 'user_nicename'=>'系统管理员'
  75. );
  76. }else{
  77. $userinfo=getUserInfo($v['uid']);
  78. if(!$userinfo){
  79. $userinfo=array(
  80. 'user_nicename'=>'已删除'
  81. );
  82. }
  83. }
  84. $v['userinfo']=$userinfo;
  85. $v['thumb']=get_upload_path($v['thumb']);
  86. return $v;
  87. });
  88. //分页-->筛选条件参数
  89. $data = $this->request->param();
  90. $lists->appends($data);
  91. // 获取分页显示
  92. $page = $lists->render();
  93. $p= $this->request->param('page');
  94. if(!$p){
  95. $p=1;
  96. }
  97. $this->assign('lists', $lists);
  98. $this->assign("page", $page);
  99. $this->assign("p",$p);
  100. $this->assign("time",time());
  101. return $this->fetch();
  102. }
  103. /*未通过视频列表*/
  104. public function nopassindex(){
  105. $ordertype = $this->request->param('ordertype');
  106. $orderstr="";
  107. if($ordertype==1){//评论数排序
  108. $orderstr="comments DESC";
  109. }else if($ordertype==2){//票房数量排序(点赞)
  110. $orderstr="likes DESC";
  111. }else if($ordertype==3){//分享数量排序
  112. $orderstr="shares DESC";
  113. }else{
  114. $orderstr="addtime DESC";
  115. }
  116. $lists = Db::name('user_video')
  117. ->where(function (Query $query) {
  118. $data = $this->request->param();
  119. $query->where('isdel', 0);
  120. $query->where('status', 2);
  121. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  122. $keyword1=isset($data['keyword1']) ? $data['keyword1']: '';
  123. $keyword2=isset($data['keyword2']) ? $data['keyword2']: '';
  124. if (!empty($keyword)) {
  125. $query->where('uid|id', 'like', "%$keyword%");
  126. }
  127. if (!empty($keyword1)) {
  128. $query->where('title', 'like', "%$keyword1%");
  129. }
  130. if (!empty($keyword2)) {
  131. $userlist =Db::name("user")
  132. ->field("id")
  133. ->where("user_nicename like '%".$keyword2."%'")
  134. ->select();
  135. $strids="";
  136. $userlist->all();
  137. foreach ($userlist as $k => $vu) {
  138. if($strids==""){
  139. $strids=$vu['id'];
  140. }else{
  141. $strids.=",".$vu['id'];
  142. }
  143. }
  144. $query->where('uid', 'in', $strids);
  145. }
  146. })
  147. ->order($orderstr)
  148. ->paginate(20);
  149. $lists->each(function($v,$k){
  150. if($v['uid']==0){
  151. $userinfo=array(
  152. 'user_nicename'=>'系统管理员'
  153. );
  154. }else{
  155. $userinfo=getUserInfo($v['uid']);
  156. if(!$userinfo){
  157. $userinfo=array(
  158. 'user_nicename'=>'已删除'
  159. );
  160. }
  161. }
  162. $v['userinfo']=$userinfo;
  163. $v['thumb']=get_upload_path($v['thumb']);
  164. return $v;
  165. });
  166. //分页-->筛选条件参数
  167. $data = $this->request->param();
  168. $lists->appends($data);
  169. // 获取分页显示
  170. $page = $lists->render();
  171. $p= $this->request->param('page');
  172. if(!$p){
  173. $p=1;
  174. }
  175. $this->assign('lists', $lists);
  176. $this->assign("page", $page);
  177. $this->assign("p",$p);
  178. $this->assign("time",time());
  179. return $this->fetch();
  180. }
  181. /*审核通过视频列表*/
  182. public function passindex(){
  183. $ordertype = $this->request->param('ordertype');
  184. $orderstr="";
  185. if($ordertype==1){//评论数排序
  186. $orderstr="comments DESC";
  187. }else if($ordertype==2){//票房数量排序(点赞)
  188. $orderstr="likes DESC";
  189. }else if($ordertype==3){//分享数量排序
  190. $orderstr="shares DESC";
  191. }else{
  192. $orderstr="addtime DESC";
  193. }
  194. $lists = Db::name('user_video')
  195. ->where(function (Query $query) {
  196. $data = $this->request->param();
  197. $query->where('isdel', 0);
  198. $query->where('status', 1);
  199. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  200. $keyword1=isset($data['keyword1']) ? $data['keyword1']: '';
  201. $keyword2=isset($data['keyword2']) ? $data['keyword2']: '';
  202. if (!empty($keyword)) {
  203. $query->where('uid|id', 'like', "%$keyword%");
  204. }
  205. if (!empty($keyword1)) {
  206. $query->where('title', 'like', "%$keyword1%");
  207. }
  208. if (!empty($keyword2)) {
  209. $userlist =Db::name("user")
  210. ->field("id")
  211. ->where("user_nicename like '%".$keyword2."%'")
  212. ->select();
  213. $strids="";
  214. $userlist->all();
  215. foreach ($userlist as $k => $vu) {
  216. if($strids==""){
  217. $strids=$vu['id'];
  218. }else{
  219. $strids.=",".$vu['id'];
  220. }
  221. }
  222. $query->where('uid', 'in', $strids);
  223. }
  224. })
  225. ->order($orderstr)
  226. ->paginate(20);
  227. $lists->each(function($v,$k){
  228. if($v['uid']==0){
  229. $userinfo=array(
  230. 'user_nicename'=>'系统管理员'
  231. );
  232. }else{
  233. $userinfo=getUserInfo($v['uid']);
  234. if(!$userinfo){
  235. $userinfo=array(
  236. 'user_nicename'=>'已删除'
  237. );
  238. }
  239. }
  240. $v['userinfo']=$userinfo;
  241. $v['thumb']=get_upload_path($v['thumb']);
  242. return $v;
  243. });
  244. //分页-->筛选条件参数
  245. $data = $this->request->param();
  246. $lists->appends($data);
  247. // 获取分页显示
  248. $page = $lists->render();
  249. $p= $this->request->param('page');
  250. if(!$p){
  251. $p=1;
  252. }
  253. $this->assign('lists', $lists);
  254. $this->assign("page", $page);
  255. $this->assign("p",$p);
  256. $this->assign("time",time());
  257. return $this->fetch();
  258. }
  259. //删除视频
  260. public function del(){
  261. $res=array("code"=>0,"msg"=>"删除成功","info"=>array());
  262. $data = $this->request->param();
  263. $id=$data['id'];
  264. $reason=$data["reason"];
  265. if(!$id){
  266. $res['code']=1001;
  267. $res['msg']='视频信息加载失败';
  268. echo json_encode($res);
  269. exit;
  270. }
  271. //获取视频信息
  272. $videoInfo=Db::name("user_video")->where("id={$id}")->find();
  273. $result=Db::name("user_video")->where("id={$id}")->delete();
  274. if($result!==false){
  275. Db::name("user_video_comments_messages")->where("videoid={$id}")->delete(); //删除视频评论信息列表
  276. Db::name("user_video_comments")->where("videoid={$id}")->delete(); //删除视频评论
  277. Db::name("user_video_like")->where("videoid={$id}")->delete(); //删除视频喜欢
  278. Db::name("user_video_report")->where("videoid={$id}")->delete(); //删除视频举报
  279. Db::name("user_video_view")->where("videoid={$id}")->delete(); //删除视频观看
  280. Db::name("user_video_comments_like")->where("videoid={$id}")->delete();
  281. $res['msg']='视频删除成功';
  282. echo json_encode($res);
  283. exit;
  284. }else{
  285. $res['code']=1002;
  286. $res['msg']='视频删除失败';
  287. echo json_encode($res);
  288. exit;
  289. }
  290. }
  291. //排序
  292. public function listsorders() {
  293. $ids=$this->request->param('listsorders');
  294. foreach ($ids as $key => $r) {
  295. $data['orderno'] = $r;
  296. Db::name("user_video")->where(array('id' => $key))->save($data);
  297. }
  298. $status = true;
  299. if ($status) {
  300. $this->success("排序更新成功!");
  301. } else {
  302. $this->error("排序更新失败!");
  303. }
  304. }
  305. //添加
  306. public function add(){
  307. $this->assign("time",time());
  308. return $this->fetch();
  309. }
  310. public function add_post(){
  311. if($this->request->isPost()) {
  312. $data=$this->request->param();
  313. $video=Db::name("user_video");
  314. $data['addtime']=time();
  315. $data['uid']=0;
  316. $owner=$data['owner'];
  317. $owner_uid=$data['owner_uid'];
  318. if($owner==1){
  319. if($owner_uid==""||!is_numeric($owner_uid)){
  320. $this->error("请填写视频所有者id");
  321. return;
  322. }
  323. //判断用户是否存在
  324. $ownerInfo=Db::name("user")->where("user_type=2 and id={$owner_uid}")->find();
  325. if(!$ownerInfo){
  326. $this->error("视频所有者不存在");
  327. return;
  328. }
  329. $data['uid']=$owner_uid;
  330. }
  331. $url=$data['href'];
  332. $url_w=$data['href_w'];
  333. $title=$data['title'];
  334. $thumb=$data['thumb'];
  335. if($title==""){
  336. $this->error("请填写视频标题");
  337. }
  338. if($thumb==""){
  339. $this->error("请上传视频封面");
  340. }
  341. $data['thumb_s']=$thumb;
  342. $uploadSetting = cmf_get_upload_setting();
  343. $extensions=$uploadSetting['file_types']['video']['extensions'];
  344. $allow=explode(",",$extensions);
  345. if($url!=""){
  346. //判断链接地址的正确性
  347. if(strpos($url,'http')===false){
  348. $this->error("请填写正确的视频地址");
  349. }
  350. $video_type=substr(strrchr($url, '.'), 1);
  351. if(!in_array(strtolower($video_type), $allow)){
  352. $this->error("请填写正确后缀的视频地址");
  353. }
  354. $data['href']=$url;
  355. //判断链接地址的正确性
  356. if(strpos($url_w,'http')===false){
  357. $this->error("请填写正确的水印视频地址");
  358. }
  359. $video_type_w=substr(strrchr($url_w, '.'), 1);
  360. if(!in_array(strtolower($video_type_w), $allow)){
  361. $this->error("请填写正确后缀的水印视频地址");
  362. }
  363. $data['href_w']=$url_w;
  364. }else{
  365. if(!$_FILES["file"]){
  366. $this->error("请上传视频");
  367. }
  368. if(!$_FILES["file_w"]){
  369. $this->error("请上传水印视频");
  370. }
  371. $files["file"]=$_FILES["file"];
  372. $type='video';
  373. if (!get_file_suffix($files['file']['name'],$allow)){
  374. $this->error("请上传正确格式的视频文件或检查上传设置中视频文件设置的文件类型");
  375. }
  376. $rs=adminUploadFiles($files,$type);
  377. if($rs['code']!=0){
  378. $this->error($rs['msg']);
  379. }
  380. $files_w["file"]=$_FILES["file_w"];
  381. $type_w='video';
  382. if (!get_file_suffix($files_w['file']['name'],$allow)){
  383. $this->error("请上传正确格式的水印视频文件或检查上传设置中视频文件设置的文件类型");
  384. }
  385. $rs_w=adminUploadFiles($files_w,$type_w);
  386. if($rs_w['code']!=0){
  387. $this->error($rs_w['msg']);
  388. }
  389. $data['href']=$rs['filepath'];
  390. $data['href_w']=$rs_w['filepath'];
  391. }
  392. //计算封面尺寸比例
  393. $configpub=getConfigPub(); //获取公共配置信息
  394. $anyway='1.1';
  395. $thumb_url=get_upload_path($thumb);
  396. $refer=$configpub['site'];
  397. $option=array(
  398. 'http'=>array('header'=>"Referer: {$refer}"),
  399. "ssl" => [
  400. "verify_peer"=>false,
  401. "verify_peer_name"=>false,
  402. ]
  403. );
  404. $context=stream_context_create($option);//创建资源流上下文
  405. $file_contents = file_get_contents($thumb_url,false, $context);//将整个文件读入一个字符串
  406. $thumb_size = getimagesizefromstring($file_contents);//从字符串中获取图像尺寸信息
  407. if($thumb_size){
  408. $thumb_width=$thumb_size[0]; //封面-宽
  409. $thumb_height=$thumb_size[1]; //封面-高
  410. $anyway=round($thumb_height/$thumb_width);
  411. }
  412. $data['anyway']=$anyway;
  413. unset($data['file']);
  414. unset($data['file_w']);
  415. unset($data['owner']);
  416. unset($data['owner_uid']);
  417. unset($data['video_upload_type']);
  418. $result=$video->insert($data);
  419. if($result){
  420. $this->success('添加成功','admin/video/passindex',3);
  421. }else{
  422. $this->error('添加失败');
  423. }
  424. }
  425. }
  426. //编辑
  427. public function edit(){
  428. $data = $this->request->param();
  429. $id=intval($data['id']);
  430. $from=$data["from"];
  431. if($id){
  432. $video=Db::name("user_video")->where("id={$id}")->find();
  433. if($video['uid']==0){
  434. $userinfo=array(
  435. 'user_nicename'=>'系统管理员'
  436. );
  437. }else{
  438. $userinfo=getUserInfo($video['uid']);
  439. if(!$userinfo){
  440. $userinfo=array(
  441. 'user_nicename'=>'已删除'
  442. );
  443. }
  444. }
  445. $video['userinfo']=$userinfo;
  446. $video['thumb']=get_upload_path($video['thumb']);
  447. $video['href']=get_upload_path($video['href']);
  448. $video['href_w']=get_upload_path($video['href_w']);
  449. $this->assign('video', $video);
  450. }else{
  451. $this->error('数据传入失败!');
  452. }
  453. $this->assign("from",$from);
  454. return $this->fetch();
  455. }
  456. public function edit_post(){
  457. if($this->request->isPost()) {
  458. $data = $this->request->param();
  459. $video=Db::name("user_video");
  460. $id=$data['id'];
  461. $title=$data['title'];
  462. $thumb=$data['thumb'];
  463. $type=$data['video_upload_type'];
  464. $url=$data['href_e'];
  465. $url_w=$data['href_e_w'];
  466. $status=$data['status'];
  467. $isdel=$data['isdel'];
  468. if($thumb==""){
  469. $this->error("请上传视频封面");
  470. }
  471. $data['thumb_s']=$thumb;
  472. if($type!=''){
  473. $uploadSetting = cmf_get_upload_setting();
  474. $extensions=$uploadSetting['file_types']['video']['extensions'];
  475. $allow=explode(",",$extensions);
  476. if($type==0){ //视频链接型式
  477. if($url==''){
  478. $this->error("请填写视频链接地址");
  479. }
  480. if($url_w==''){
  481. $this->error("请填写水印视频链接地址");
  482. }
  483. //判断链接地址的正确性
  484. if(strpos($url,'http')===false){
  485. $this->error("请填写正确的视频地址");
  486. }
  487. $video_type=substr(strrchr($url, '.'), 1);
  488. if(!in_array(strtolower($video_type), $allow)){
  489. $this->error("请填写正确后缀的视频地址");
  490. }
  491. $data['href']=$url;
  492. //判断链接地址的正确性
  493. if(strpos($url_w,'http')===false){
  494. $this->error("请填写正确的水印视频地址");
  495. }
  496. $video_type_w=substr(strrchr($url_w, '.'), 1);
  497. if(!in_array(strtolower($video_type_w), $allow)){
  498. $this->error("请填写正确后缀的水印视频地址");
  499. }
  500. $data['href_w']=$url_w;
  501. }else if($type==1){ //文件上传型式
  502. if(!$_FILES["file"]){
  503. $this->error("请上传视频");
  504. }
  505. if(!$_FILES["file_w"]){
  506. $this->error("请上传水印视频");
  507. }
  508. $files["file"]=$_FILES["file"];
  509. $type='video';
  510. if (!get_file_suffix($files['file']['name'],$allow)){
  511. $this->error("请上传正确格式的水印视频文件或检查上传设置中视频文件设置的文件类型");
  512. }
  513. $rs=adminUploadFiles($files,$type);
  514. if($rs['code']!=0){
  515. $this->error($rs['msg']);
  516. }
  517. $file_w["file"]=$_FILES["file_w"];
  518. $type_w='video';
  519. if (!get_file_suffix($file_w['file']['name'],$allow)){
  520. $this->error("请上传正确格式的水印视频文件或检查上传设置中视频文件设置的文件类型");
  521. }
  522. $rs_w=adminUploadFiles($file_w,$type_w);
  523. if($rs_w['code']!=0){
  524. $this->error($rs_w['msg']);
  525. }
  526. $data['href']=$rs['filepath'];
  527. $data['href_w']=$rs_w['filepath'];
  528. }
  529. }
  530. //计算封面尺寸比例
  531. $configpub=getConfigPub(); //获取公共配置信息
  532. $anyway='1.1';
  533. $thumb_url=get_upload_path($thumb);
  534. $refer=$configpub['site'];
  535. $option=array(
  536. 'http'=>array('header'=>"Referer: {$refer}"),
  537. "ssl" => [
  538. "verify_peer"=>false,
  539. "verify_peer_name"=>false,
  540. ]
  541. );
  542. $context=stream_context_create($option);//创建资源流上下文
  543. $file_contents = file_get_contents($thumb_url,false, $context);//将整个文件读入一个字符串
  544. $thumb_size = getimagesizefromstring($file_contents);//从字符串中获取图像尺寸信息
  545. if($thumb_size){
  546. $thumb_width=$thumb_size[0]; //封面-宽
  547. $thumb_height=$thumb_size[1]; //封面-高
  548. $anyway=round($thumb_height/$thumb_width);
  549. }
  550. $data['anyway']=$anyway;
  551. unset($data['file']);
  552. unset($data['file_w']);
  553. unset($data['href_e']);
  554. unset($data['href_e_w']);
  555. unset($data['video_upload_type']);
  556. unset($data['owner_uid']);
  557. unset($data['ckplayer_playerzmblbkjP']);
  558. $result=$video->update($data);
  559. if($result!==false){
  560. if($status==2||$isdel==1){ //如果该视频下架或视频状态改为不通过,需要将视频喜欢列表的状态更改
  561. Db::name("user_video_like")->where("videoid={$id}")->setField('status',0);
  562. Db::name("user_video_view")->where("videoid={$id}")->setField('status',0);
  563. }
  564. $this->success('修改成功');
  565. }else{
  566. $this->error('修改失败');
  567. }
  568. }
  569. }
  570. public function reportlist(){
  571. $lists=Db::name("user_video_report")
  572. ->where(function (Query $query) {
  573. $data = $this->request->param();
  574. if ($data['status']!='') {
  575. $query->where('status', $data['status']);
  576. }
  577. if (!empty($data['start_time'])) {
  578. $query->where('addtime', 'gt' , strtotime($data['start_time']));
  579. }
  580. if (!empty($data['end_time'])) {
  581. $query->where('addtime', 'lt' ,strtotime($data['end_time']));
  582. }
  583. if (!empty($data['start_time']) && !empty($data['end_time'])) {
  584. $query->where('addtime', 'between' , [strtotime($data['start_time']),strtotime($data['end_time'])]);
  585. }
  586. if (!empty($data['keyword'])) {
  587. $keyword = $data['keyword'];
  588. $query->where('uid', 'like', "%$keyword%");
  589. }
  590. })
  591. ->order("addtime DESC")
  592. ->paginate(20);
  593. $lists->all();
  594. $lists->each(function($v,$k){
  595. $userinfo=Db::name("user")
  596. ->field("user_nicename")
  597. ->where("id='{$v['uid']}'")
  598. ->find();
  599. if(!$userinfo){
  600. $userinfo=array(
  601. 'user_nicename'=>'已删除'
  602. );
  603. }
  604. $v['userinfo']= $userinfo;
  605. $touserinfo=Db::name("user")
  606. ->field("user_nicename")
  607. ->where("id='{$v['touid']}'")
  608. ->find();
  609. if(!$touserinfo){
  610. $touserinfo=array(
  611. 'user_nicename'=>'已删除'
  612. );
  613. }
  614. $v['touserinfo']= $touserinfo;
  615. //判断视频是否下架
  616. $video_isdel=Db::name("user_video")->where("id={$v['videoid']}")->value("isdel");
  617. $v['video_isdel']=$video_isdel;
  618. return $v;
  619. });
  620. //分页-->筛选条件参数
  621. $data = $this->request->param();
  622. $lists->appends($data);
  623. // 获取分页显示
  624. $page = $lists->render();
  625. $p= $this->request->param('page');
  626. if(!$p){
  627. $p=1;
  628. }
  629. $this->assign('lists', $lists);
  630. $this->assign("page", $page);
  631. $this->assign("p",$p);
  632. return $this->fetch();
  633. }
  634. //视频举报标记
  635. public function setstatus(){
  636. $id=$this->request->param('id');
  637. if($id){
  638. $data['status']=1;
  639. $data['uptime']=time();
  640. $result=Db::name("user_video_report")->where("id='{$id}'")->update($data);
  641. if($result!==false){
  642. $this->success('标记成功');
  643. }else{
  644. $this->error('标记失败');
  645. }
  646. }else{
  647. $this->error('数据传入失败!');
  648. }
  649. }
  650. //删除用户举报列表
  651. public function report_del(){
  652. $id=$this->request->param("id");
  653. if($id){
  654. $result=Db::name("user_video_report")->delete($id);
  655. if($result){
  656. $this->success('删除成功');
  657. }else{
  658. $this->error('删除失败');
  659. }
  660. }else{
  661. $this->error('数据传入失败!');
  662. }
  663. }
  664. //举报内容设置**************start******************
  665. //举报类型列表
  666. public function reportset(){
  667. $lists = Db::name("user_video_report_classify")
  668. ->order("orderno ASC")
  669. ->select();
  670. $this->assign('lists', $lists);
  671. return $this->fetch();
  672. }
  673. //添加举报理由
  674. public function add_report(){
  675. return $this->fetch();
  676. }
  677. public function add_reportpost(){
  678. if($this->request->isPost()) {
  679. $data=$this->request->param();
  680. $report=Db::name("user_video_report_classify");
  681. $name=$data['name'];//举报类型名称
  682. if(!trim($name)){
  683. $this->error('举报类型名称不能为空');
  684. }
  685. $isexit=Db::name("user_video_report_classify")
  686. ->where("name='{$name}'")
  687. ->find();
  688. if($isexit){
  689. $this->error('该举报类型名称已存在');
  690. }
  691. $data['addtime']=time();
  692. $result=$report->insert($data);
  693. if($result){
  694. $this->success('添加成功');
  695. }else{
  696. $this->error('添加失败');
  697. }
  698. }
  699. }
  700. //编辑举报类型名称
  701. public function edit_report(){
  702. $id = $this->request->param('id', 0, 'intval');
  703. if($id){
  704. $reportinfo=Db::name("user_video_report_classify")
  705. ->where("id={$id}")
  706. ->find();
  707. $this->assign('reportinfo', $reportinfo);
  708. }else{
  709. $this->error('数据传入失败!');
  710. }
  711. return $this->fetch();
  712. }
  713. public function edit_reportpost(){
  714. if($this->request->isPost()) {
  715. $data=$this->request->param();
  716. $report=Db::name("user_video_report_classify");
  717. $id=$data['id'];
  718. $name=$data['name'];//举报类型名称
  719. if(!trim($name)){
  720. $this->error('举报类型名称不能为空');
  721. }
  722. $isexit=Db::name("user_video_report_classify")
  723. ->where("id!={$id} and name='{$name}'")
  724. ->find();
  725. if($isexit){
  726. $this->error('该举报类型名称已存在');
  727. }
  728. $result=$report->update($data);
  729. if($result!==false){
  730. $this->success('修改成功');
  731. }else{
  732. $this->error('修改失败');
  733. }
  734. }
  735. }
  736. //删除举报类型名称
  737. public function del_report(){
  738. $id = $this->request->param('id', 0, 'intval');
  739. if($id){
  740. $result=Db::name("user_video_report_classify")->where("id={$id}")->delete();
  741. if($result!==false){
  742. $this->success('删除成功');
  743. }else{
  744. $this->error('删除失败');
  745. }
  746. }else{
  747. $this->error('数据传入失败!');
  748. }
  749. return $this->fetch();
  750. }
  751. //举报内容排序
  752. public function listordersset() {
  753. $ids=$this->request->param('listorders');
  754. foreach ($ids as $key => $r) {
  755. $data['orderno'] = $r;
  756. Db::name("user_video_report_classify")
  757. ->where(array('id' => $key))
  758. ->update($data);
  759. }
  760. $status = true;
  761. if ($status) {
  762. $this->success("排序更新成功!");
  763. } else {
  764. $this->error("排序更新失败!");
  765. }
  766. }
  767. //举报内容设置**************end******************
  768. //设置下架
  769. public function setXiajia(){
  770. $res=array("code"=>0,"msg"=>"下架成功","info"=>array());
  771. $data = $this->request->param();
  772. $id=$data['id'];
  773. $reason=$data["reason"];
  774. if(!$id){
  775. $res['code']=1001;
  776. $res['msg']="请确认视频信息";
  777. echo json_encode($res);
  778. exit;
  779. }
  780. //判断此视频是否存在
  781. $videoInfo=Db::name("user_video")->where("id={$id}")->find();
  782. if(!$videoInfo){
  783. $res['code']=1001;
  784. $res['msg']="请确认视频信息";
  785. echo json_encode($res);
  786. exit;
  787. }
  788. //更新视频状态
  789. $data=array("isdel"=>1,"xiajia_reason"=>$reason);
  790. $result=Db::name("user_video")->where("id={$id}")->update($data);
  791. if($result!==false){
  792. //将视频喜欢列表的状态更改
  793. Db::name("user_video_like")->where("videoid={$id}")->setField('status',0);
  794. //将视频喜欢列表的状态更改
  795. Db::name("user_video_view")->where("videoid={$id}")->setField('status',0);
  796. //将评论信息列表的状态更改
  797. Db::name("user_video_comments_messages")->where("videoid={$id}")->setField('status',0);
  798. //更新此视频的举报信息
  799. $data1=array(
  800. 'status'=>1,
  801. 'uptime'=>time()
  802. );
  803. Db::name("user_video_report")->where("videoid={$id}")->update($data1);
  804. echo json_encode($res);
  805. exit;
  806. }else{
  807. $res['code']=1002;
  808. $res['msg']="下架失败";
  809. echo json_encode($res);
  810. exit;
  811. }
  812. }
  813. /*下架视频列表*/
  814. public function lowervideo(){
  815. $ordertype = $this->request->param('ordertype');
  816. $orderstr="";
  817. if($ordertype==1){//评论数排序
  818. $orderstr="comments DESC";
  819. }else if($ordertype==2){//票房数量排序(点赞)
  820. $orderstr="likes DESC";
  821. }else if($ordertype==3){//分享数量排序
  822. $orderstr="shares DESC";
  823. }else{
  824. $orderstr="addtime DESC";
  825. }
  826. $lists = Db::name('user_video')
  827. ->where(function (Query $query) {
  828. $data = $this->request->param();
  829. $query->where('isdel', 1);
  830. $classid=isset($data['classid']) ? $data['classid']: '';
  831. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  832. $keyword1=isset($data['keyword1']) ? $data['keyword1']: '';
  833. $keyword2=isset($data['keyword2']) ? $data['keyword2']: '';
  834. if (!empty($classid)) {
  835. $query->where('classid', 'eq', $classid);
  836. }
  837. if (!empty($keyword)) {
  838. $query->where('uid|id', 'like', "%$keyword%");
  839. }
  840. if (!empty($keyword1)) {
  841. $query->where('title', 'like', "%$keyword1%");
  842. }
  843. if (!empty($keyword2)) {
  844. $userlist =Db::name("user")
  845. ->field("id")
  846. ->where("user_nicename like '%".$keyword2."%'")
  847. ->select();
  848. $strids="";
  849. $userlist->all();
  850. foreach ($userlist as $k => $vu) {
  851. if($strids==""){
  852. $strids=$vu['id'];
  853. }else{
  854. $strids.=",".$vu['id'];
  855. }
  856. }
  857. $query->where('uid', 'in', $strids);
  858. }
  859. })
  860. ->order($orderstr)
  861. ->paginate(20);
  862. $lists->each(function($v,$k){
  863. if($v['uid']==0){
  864. $userinfo=array(
  865. 'user_nicename'=>'系统管理员'
  866. );
  867. }else{
  868. $userinfo=getUserInfo($v['uid']);
  869. if(!$userinfo){
  870. $userinfo=array(
  871. 'user_nicename'=>'已删除'
  872. );
  873. }
  874. }
  875. $v['userinfo']=$userinfo;
  876. $v['thumb']=get_upload_path($v['thumb']);
  877. return $v;
  878. });
  879. //分页-->筛选条件参数
  880. $data = $this->request->param();
  881. $lists->appends($data);
  882. // 获取分页显示
  883. $page = $lists->render();
  884. $p= $this->request->param('page');
  885. if(!$p){
  886. $p=1;
  887. }
  888. $this->assign('lists', $lists);
  889. $this->assign("page", $page);
  890. $this->assign("p",$p);
  891. $this->assign("time",time());
  892. return $this->fetch();
  893. }
  894. public function video_listen(){
  895. $id = $this->request->param('id', 0, 'intval');
  896. if(!$id||$id==""||!is_numeric($id)){
  897. $this->error("加载失败");
  898. }else{
  899. //获取音乐信息
  900. $info=Db::name("user_video")->where("id={$id}")->find();
  901. $info['thumb']=get_upload_path($info['thumb']);
  902. $info['href']=get_upload_path($info['href']);
  903. $this->assign("info",$info);
  904. }
  905. return $this->fetch();
  906. }
  907. /*视频上架*/
  908. public function set_shangjia(){
  909. $id = $this->request->param('id', 0, 'intval');
  910. if(!$id){
  911. $this->error("视频信息加载失败");
  912. }
  913. //获取视频信息
  914. $info=Db::name("user_video")->where("id={$id}")->find();
  915. if(!$info){
  916. $this->error("视频信息加载失败");
  917. }
  918. $data=array(
  919. 'xiajia_reason'=>'',
  920. 'isdel'=>0
  921. );
  922. $result=Db::name("user_video")->where("id={$id}")->update($data);
  923. if($result!==false){
  924. //将视频喜欢列表的状态更改
  925. Db::name("user_video_like")->where("videoid={$id}")->setField('status',1);
  926. //将视频观看列表的状态更改
  927. Db::name("user_video_view")->where("videoid={$id}")->setField('status',1);
  928. $this->success("上架成功");
  929. }
  930. return $this->fetch();
  931. }
  932. //评论列表
  933. public function commentlists(){
  934. $data = $this->request->param();
  935. $videoid=$data['videoid'];
  936. $lists = Db::name('user_video_comments')
  937. ->where("videoid={$videoid}")
  938. ->order("addtime DESC")
  939. ->paginate(20);
  940. $lists->each(function($v,$k){
  941. $userinfo=getUserInfo($v['uid']);
  942. if(!$userinfo){
  943. $userinfo=array(
  944. 'user_nicename'=>'已删除'
  945. );
  946. }
  947. $v['user_nicename']=$userinfo['user_nicename'];
  948. if($v['voice']){
  949. $v['voice']=get_upload_path($v['voice']);
  950. }
  951. return $v;
  952. });
  953. //分页-->筛选条件参数
  954. $lists->appends($data);
  955. // 获取分页显示
  956. $page = $lists->render();
  957. $this->assign("lists",$lists);
  958. $this->assign("page", $page);
  959. return $this->fetch();
  960. }
  961. //批量下架
  962. public function setBatchXiajia(){
  963. $data = $this->request->param();
  964. $status=$data['status'];
  965. $ids = $data['ids'];
  966. if(empty($ids)){
  967. $this->error("请选择列表");
  968. }
  969. foreach ($ids as $k => $v) {
  970. $id=$v;
  971. //获取视频详情
  972. $videoInfo=Db::name("user_video")->where("id={$id}")->find();
  973. if(!$videoInfo){
  974. continue;
  975. }
  976. $update_data=array(
  977. 'isdel'=>$status
  978. );
  979. $result=Db::name("user_video")->where("id={$id}")->update($update_data);
  980. if($result!==false){
  981. //将视频喜欢列表的状态更改
  982. Db::name("user_video_like")->where("videoid={$id}")->setField('status',0);
  983. //将视频喜欢列表的状态更改
  984. Db::name("user_video_view")->where("videoid={$id}")->setField('status',0);
  985. //更新此视频的举报信息
  986. $data1=array(
  987. 'status'=>1,
  988. 'uptime'=>time()
  989. );
  990. Db::name("user_video_report")->where("videoid={$id}")->update($data1);
  991. }
  992. }
  993. $this->success("操作成功!");
  994. }
  995. //批量删除
  996. public function setBatchDel(){
  997. $data = $this->request->param();
  998. $ids = $data['ids'];
  999. if(empty($ids)){
  1000. $this->error("请选择列表");
  1001. }
  1002. foreach ($ids as $k => $v) {
  1003. $id=$v;
  1004. //获取视频信息
  1005. $videoInfo=Db::name("user_video")->where("id={$id}")->find();
  1006. $result=Db::name("user_video")->where("id={$id}")->delete();
  1007. if($result!==false){
  1008. Db::name("user_video_comments_messages")->where("videoid={$id}")->delete(); //删除视频评论信息列表
  1009. Db::name("user_video_comments")->where("videoid={$id}")->delete(); //删除视频评论
  1010. Db::name("user_video_like")->where("videoid={$id}")->delete(); //删除视频喜欢
  1011. Db::name("user_video_report")->where("videoid={$id}")->delete(); //删除视频举报
  1012. Db::name("user_video_view")->where("videoid={$id}")->delete(); //删除视频观看
  1013. Db::name("user_video_comments_like")->where("videoid={$id}")->delete(); //删除视频评论喜欢
  1014. }
  1015. }
  1016. $this->success("操作成功!");
  1017. }
  1018. //批量审核 通过/不通过
  1019. public function setBatchStatus(){
  1020. $data=$this->request->param();
  1021. $status=$data['status'];
  1022. $ids=$data['ids'];
  1023. if(empty($ids)){
  1024. $this->error("请选择列表");
  1025. }
  1026. foreach ($ids as $k => $v) {
  1027. $post_data=array(
  1028. 'status'=>$status
  1029. );
  1030. if($status==2){
  1031. $post_data['nopass_time']=time();
  1032. }
  1033. $id=$v;
  1034. $videoInfo=Db::name("user_video")->where("id={$id}")->find();
  1035. $result=Db::name("user_video")->where("id={$id}")->update($post_data);
  1036. if($result!==false){
  1037. if($status==2){ //如果该视频状态改为不通过,需要将视频喜欢列表的状态更改
  1038. Db::name("user_video_like")->where("videoid={$id}")->setField('status',0);
  1039. Db::name("user_video_view")->where("videoid={$id}")->setField('status',0);
  1040. }
  1041. }
  1042. }
  1043. $this->success('修改成功');
  1044. }
  1045. }