WxliveController.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * lionfish 小程序直播插件
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author J_da
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class WxliveController extends CommonController
  16. {
  17. protected function _initialize()
  18. {
  19. parent::_initialize();
  20. }
  21. public function index()
  22. {
  23. $gpc = I('request.');
  24. $pindex = max(1, intval($gpc['page']));
  25. $psize = 10;
  26. $condition = '1';
  27. $offset = ($pindex - 1) * $psize;
  28. $keywords = addslashes(trim($gpc['keywords']));
  29. $keyword2 = stripslashes($keywords);
  30. $this->keywords = $keyword2;
  31. if ($keywords !== '') {
  32. $condition .= " and name like '%". $keywords ."%' or anchor_name like '%". $keywords ."%'";
  33. }
  34. $list = M("lionfish_comshop_wxlive")
  35. ->where($condition)
  36. ->order('is_top desc,start_time asc')
  37. ->limit($offset, $psize)
  38. ->select();
  39. $total = M('lionfish_comshop_wxlive')->where($condition)->count();
  40. $pager = pagination2($total, $pindex, $psize);
  41. $this->list = $list;
  42. $this->pager = $pager;
  43. $this->display();
  44. }
  45. public function setting()
  46. {
  47. if (IS_POST) {
  48. $data = I('request.parameter');
  49. $data['live_share_image'] = save_media($data['live_share_image']);
  50. $data['live_nav_name'] = trim($data['live_nav_name']);
  51. $data['live_share_title'] = trim($data['live_share_title']);
  52. D('Seller/Config')->update($data);
  53. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  54. }
  55. $data = D('Seller/Config')->get_all_config();
  56. $this->data = $data;
  57. $this->display();
  58. }
  59. /**
  60. * 同步直播间
  61. */
  62. public function sync()
  63. {
  64. $ret = D('Home/Livevideo')->syncRoomList();
  65. if (isset($ret['errcode'])) {
  66. show_json(0, $ret['msg']);
  67. }
  68. show_json(1);
  69. }
  70. /**
  71. * 同步直播间回放
  72. */
  73. public function syncreplay()
  74. {
  75. $live_id = I('request.live_id');
  76. $roomid = I('request.roomid');
  77. $list = D('Home/Livevideo')->syncLiveReplayNew($roomid);
  78. if ($list["errcode"] != 0 || $list["errmsg"] != "ok") {
  79. return show_json(0, $list["errmsg"]);
  80. }
  81. if (0 < $list["total"]) {
  82. M('lionfish_comshop_wxlive_replay')->where(array('roomid'=>$roomid))->delete();
  83. $result = $list["live_replay"];
  84. foreach ($result as $item) {
  85. $item["expire_time"] = strtotime($item["expire_time"]);
  86. $item["create_time"] = strtotime($item["create_time"]);
  87. $item["add_time"] = time();
  88. $item["live_id"] = $live_id;
  89. $item["roomid"] = $roomid;
  90. M('lionfish_comshop_wxlive_replay')->add($item);
  91. }
  92. }
  93. return show_json(1, "获取回放成功");
  94. }
  95. /**
  96. * 获取回放
  97. */
  98. public function replay()
  99. {
  100. $live_id = I('request.id');
  101. $roomid = I('request.roomid');
  102. $list = M("lionfish_comshop_wxlive_replay")
  103. ->where(array('roomid'=>$roomid))
  104. ->select();
  105. $this->live_id = $live_id;
  106. $this->roomid = $roomid;
  107. $this->list = $list;
  108. $this->display();
  109. }
  110. /**
  111. * 显示隐藏直播间
  112. * @return [type] [Boolean]
  113. */
  114. public function change()
  115. {
  116. $id = I('request.id');
  117. //ids
  118. if (empty($id)) {
  119. $ids = I('request.ids');
  120. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  121. }
  122. if (empty($id)) {
  123. show_json(0, array('message' => '参数错误'));
  124. }
  125. $type = I('request.type');
  126. $value = I('request.value');
  127. if (!(in_array($type, array('is_show', 'displayorder')))) {
  128. show_json(0, array('message' => '参数错误'));
  129. }
  130. $items = M('lionfish_comshop_wxlive')->where( array('id' => array('in', $id)) )->select();
  131. foreach ($items as $item) {
  132. M('lionfish_comshop_wxlive')->where( array('id' => $item['id']) )->save( array($type => $value) );
  133. }
  134. show_json(1 , array('url' => $_SERVER['HTTP_REFERER']));
  135. }
  136. }