Live.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\admin\controller\shopro\app;
  3. use app\common\controller\Backend;
  4. /**
  5. *
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Live extends Backend
  10. {
  11. /**
  12. * Live模型对象
  13. * @var \app\admin\model\shopro\app\Live
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\shopro\app\Live;
  20. $this->view->assign("liveStatusList", $this->model->getLiveStatusList());
  21. }
  22. /**
  23. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  24. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  25. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  26. */
  27. /**
  28. * 查看
  29. */
  30. public function index()
  31. {
  32. //当前是否为关联查询
  33. $this->relationSearch = false;
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags', 'trim']);
  36. if ($this->request->isAjax())
  37. {
  38. //如果发送的来源是Selectpage,则转发到Selectpage
  39. if ($this->request->request('keyField'))
  40. {
  41. return $this->selectpage();
  42. }
  43. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  44. $total = $this->model
  45. ->where($where)
  46. ->order($sort, $order)
  47. ->count();
  48. $list = $this->model
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->limit($offset, $limit)
  52. ->select();
  53. foreach ($list as $row) {
  54. $row->visible(['id','name','room_id','live_status','starttime','endtime','anchor_name','share_img','createtime','updatetime']);
  55. }
  56. $list = collection($list)->toArray();
  57. $result = array("total" => $total, "rows" => $list);
  58. return json($result);
  59. }
  60. // 自动同步直播间
  61. \app\admin\model\shopro\app\Live::autoSyncLive();
  62. return $this->view->fetch();
  63. }
  64. /**
  65. * 直播详情
  66. */
  67. public function detail($ids = null)
  68. {
  69. $row = $this->model->get($ids);
  70. if (!$row) {
  71. $this->error(__('No Results were found'));
  72. }
  73. $adminIds = $this->getDataLimitAdminIds();
  74. if (is_array($adminIds)) {
  75. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  76. $this->error(__('You have no permission'));
  77. }
  78. }
  79. $this->view->assign("row", $row);
  80. $this->view->assign("goods", $row->goods);
  81. $liveLink = [];
  82. if ($row['live_status'] == \app\admin\model\shopro\app\Live::STATUS_LIVED) {
  83. // 直播已结束,显示 直播回放地址
  84. // 自动同步回放地址
  85. \app\admin\model\shopro\app\Live::autoSyncLiveLink($row);
  86. // 获取回放地址
  87. $liveLink = $row->links;
  88. }
  89. $this->view->assign("links", $liveLink);
  90. return $this->view->fetch();
  91. }
  92. public function select()
  93. {
  94. if ($this->request->isAjax()) {
  95. return $this->index();
  96. }
  97. return $this->view->fetch();
  98. }
  99. // 手动同步直播间
  100. public function syncLive () {
  101. // 手动同步直播间
  102. \app\admin\model\shopro\app\Live::syncLive();
  103. $this->success('同步成功');
  104. }
  105. }