1
0

Broadcast.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\mobile\controller;
  4. use think\facade\Request;
  5. use app\model\Employee;
  6. use app\model\Broadcast as BroadcastModel;
  7. use xiaohongwu\Vr;
  8. class Broadcast extends Base
  9. {
  10. /**
  11. * 直播列表
  12. */
  13. public function lists()
  14. {
  15. $where = [
  16. ['broadcast_type','=',0],
  17. ['root_id','=',0],
  18. ['del','=',0]
  19. ];
  20. $list = BroadcastModel::with(['lecturer'=>function($query){
  21. $query->bind(['lecturer_name'=>'name']);
  22. }])->where($where)->order('id desc')->limit(2)->select()->toArray();
  23. if($list){
  24. foreach ($list as $key => $value) {
  25. $list[$key]['time'] = date('Y-m-d')==$value['start_date'] ? '今日:'.date('H:i') : date('m-d',strtotime($value['start_date']));
  26. $list[$key]['start_date'] = date('m月d日 H:i',strtotime($value['start_date']));
  27. $list[$key]['introduce'] = $value['introduce'] ?: '';
  28. }
  29. }
  30. return json(['code'=>0,'data'=>$list]);
  31. }
  32. /**
  33. * 威哥直播列表
  34. */
  35. public function list()
  36. {
  37. $where = [
  38. ['broadcast_type','=',1],
  39. ['root_id','=',0],
  40. ['del','=',0]
  41. ];
  42. $info = BroadcastModel::where($where)->order('id desc')->limit(2)->findOrEmpty();
  43. if(!$info->isEmpty()){
  44. //预约人数
  45. $info['number_count'] = 0;
  46. $info['time'] = date('Y-m-d')==$info['start_date'] ? '今日:'.date('H:i') : date('m-d',$info->getData('start_date'));
  47. $info['res'] = time()<$info['start_date'] ? '预告' : (time()<$info['end_date'] ? '直播中' : '直播已结束');
  48. $info['introduce'] = $info['introduce'] ?: '';
  49. }
  50. return json(['code'=>0,'data'=>$info]);
  51. }
  52. /**
  53. * 直播页面 列表
  54. * 直播中 直播列表 直播回放
  55. */
  56. public function getList()
  57. {
  58. $param = Request::only(['page'=>1,'limit'=>10,'keyword'=>'','type'=>0]);
  59. $where = [
  60. ['broadcast_type','=',0],
  61. ['root_id','=',0],
  62. ['del','=',0]
  63. ];
  64. if($param['keyword']) $where[] = ['name','like','%'.$param['keyword'].'%'];
  65. if ($param['type']==1) {
  66. //直播预告
  67. $where[] = ['start_date','>',time()];
  68. }elseif ($param['type']==2) {
  69. //直播中
  70. $where[] = ['start_date','<',time()];
  71. $where[] = ['end_date','>',time()];
  72. }elseif ($param['type']==3) {
  73. //直播回放
  74. $where[] = ['end_date','<',time()];
  75. }
  76. $res = BroadcastModel::with(['lecturer'=>function($query){
  77. $query->bind(['lecturer_name'=>'name']);
  78. }])->where($where)->order('start_date asc')->select()->toArray();
  79. foreach ($res as $key => $value) {
  80. $res[$key]['res'] = time()<strtotime($value['start_date']) ? '预告' : (time()<strtotime($value['end_date']) ? '直播中' : '直播已结束');
  81. $res[$key]['time'] = date('m月d日 H:i',strtotime($value['start_date']));
  82. }
  83. $count = BroadcastModel::where($where)->count();
  84. return json(['code'=>0,'data'=>$res,'count'=>$count]);
  85. }
  86. }