VideoController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * 短视频
  4. */
  5. namespace app\appapi\controller;
  6. use cmf\controller\HomeBaseController;
  7. use think\facade\Db;
  8. use think\db\Query;
  9. class VideoController extends HomebaseController {
  10. public function index(){
  11. $videoid = $this->request->param('videoid',0,'intval');
  12. if( !$videoid ){
  13. $this->assign("reason",lang('信息错误'));
  14. return $this->fetch(':error');
  15. }
  16. $Video=Db::name("user_video");
  17. $map['id']=$videoid;
  18. $videoinfo=$Video->where($map)->find();
  19. if(!$videoinfo){
  20. $this->assign("reason",lang('视频丢失啦,看看其他视频吧'));
  21. return $this->fetch(':error');
  22. }
  23. if($videoinfo['status']==0){
  24. $this->assign("reason",lang('视频审核中,先看看其他视频吧'));
  25. return $this->fetch(':error');
  26. }
  27. if($videoinfo['status']==2){
  28. $this->assign("reason",lang('视频已下架,看看其他视频吧'));
  29. return $this->fetch(':error');
  30. }
  31. if($videoinfo['isdel']==1){
  32. $this->assign("reason",lang('视频已下架,看看其他视频吧'));
  33. return $this->fetch(':error');
  34. }
  35. if($videoinfo['coin']>0){
  36. $this->assign("reason",lang('该视频为付费视频,请登录APP观看'));
  37. return $this->fetch(':error');
  38. }
  39. $videoinfo['thumb']=get_upload_path($videoinfo['thumb']);
  40. if($videoinfo['uid']==0){
  41. $liveinfo=[
  42. 'avatar_thumb'=>get_upload_path("/default_thumb.png"),
  43. 'user_nickname'=>lang('系统平台'),
  44. 'id'=>0
  45. ];
  46. }else{
  47. $liveinfo=getUserInfo($videoinfo['uid']);
  48. }
  49. $this->assign("hls",get_upload_path($videoinfo['href_w']));
  50. $this->assign("videoinfo",$videoinfo);
  51. $this->assign("liveinfo",$liveinfo);
  52. return $this->fetch();
  53. }
  54. /*更新曝光值(一小时请求一次)*/
  55. public function updateshowval(){
  56. $lastid = $this->request->param('lastid',0,'intval');
  57. if(!$lastid){
  58. $lastid=0;
  59. }
  60. $limit=1000;
  61. $now=time();
  62. $effective_time=$now-1*60*60; //当前时间往前推一小时
  63. $Video=Db::name("user_video");
  64. //获取后台配置的每小时减去的曝光值
  65. $configPri=getConfigPri();
  66. $hour_minus_val=$configPri['hour_minus_val'];
  67. //获取视频列表中可被扣除曝光值的视频列表
  68. $video_list=$Video->where("isdel=0 and status=1 and show_val>={$hour_minus_val} and id>{$lastid} and addtime<={$effective_time}")->order("id asc")->limit($limit)->select()->toArray();
  69. $list_nums=count($video_list);
  70. foreach ($video_list as $k => $v) {
  71. Db::name("user_video")->where("id={$v['id']}")->dec('show_val',$hour_minus_val)->update();//曝光值减
  72. $lastid=$v['id'];
  73. }
  74. if($list_nums<$limit){
  75. echo "NO";
  76. return;
  77. }
  78. echo 'OK-'.$lastid;
  79. }
  80. //更新上热门不到指定播放量的退款
  81. public function updatePopular(){
  82. $lastid=$this->request->param('lastid',0,'intval');
  83. if(!$lastid){
  84. $lastid=0;
  85. }
  86. $limit=1000;
  87. $now=time();
  88. $popular_list=Db::name("user_video")->field("id,p_nums")->where("isdel=0 and status=1 and id>{$lastid} and p_nums>0 and p_expire<{$now}")->order("id asc")->limit($limit)->select()->toArray();
  89. foreach ($popular_list as $k => $v) {
  90. $popinfo=Db::name("popular_orders")->where("videoid={$v['id']} and refund_status=0")->field("id,uid,money,nums")->find();
  91. if($popinfo['nums']){
  92. $coin=$v['p_nums']/$popinfo['nums']*$popinfo['money'];
  93. $coin=floor($coin);
  94. if($coin>=1){
  95. $isok=changeUserCoin($popinfo['uid'],$coin,1);
  96. if($isok){
  97. $data=array(
  98. 'type'=>'income',
  99. 'action'=>'pop_refund',
  100. 'uid'=>$popinfo['uid'],
  101. 'touid'=>$popinfo['uid'],
  102. 'totalcoin'=>$coin,
  103. 'videoid'=>$v['id'],
  104. 'addtime'=>$now
  105. );
  106. //写入钻石消费记录
  107. setCoinRecord($data);
  108. //更新视频的热门信息
  109. $data1=array(
  110. 'p_expire'=>0,
  111. 'p_nums'=>0,
  112. 'p_add'=>0
  113. );
  114. Db::name("user_video")->where("id={$v['id']}")->update($data1);
  115. }
  116. }
  117. //将上热门记录的退款状态修改一下
  118. Db::name("popular_orders")->where("id={$popinfo['id']}")->update(["refund_status"=>1,"end_nums"=>$v['p_nums']]);
  119. $lastid=$v['id'];
  120. }
  121. }
  122. $list_nums=count($popular_list);
  123. if($list_nums<$limit){
  124. echo "NO";
  125. return;
  126. }
  127. echo 'OK-'.$lastid;
  128. }
  129. }