Room.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\live\shop\controller;
  11. use addon\live\model\Live;
  12. use app\model\upload\Upload;
  13. use app\shop\controller\BaseShop;
  14. use addon\live\model\Room as RoomModel;
  15. use addon\live\model\Goods as GoodsModel;
  16. /**
  17. * 直播间
  18. */
  19. class Room extends BaseShop
  20. {
  21. protected $replace = []; //视图输出字符串内容替换 相当于配置文件中的'view_replace_str'
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. $this->replace = [
  26. 'LIVE_IMG' => __ROOT__ . '/addon/live/shop/view/public/img',
  27. ];
  28. }
  29. /**
  30. * 直播间列表
  31. * @return array|mixed
  32. */
  33. public function index()
  34. {
  35. if (request()->isAjax()) {
  36. $room = new RoomModel();
  37. $page = input('page', 1);
  38. $page_size = input('page_size', PAGE_LIST_ROWS);
  39. $condition = [
  40. 'site_id' => $this->site_id
  41. ];
  42. $data = $room->getRoomPageList($condition, '*', 'roomid desc', $page, $page_size);
  43. return $data;
  44. } else {
  45. $this->forthMenu();
  46. return $this->fetch("room/index", [], $this->replace);
  47. }
  48. }
  49. /**
  50. * 同步直播间
  51. * @return array
  52. */
  53. public function sync()
  54. {
  55. if (request()->isAjax()) {
  56. $room = new RoomModel();
  57. $start = input('start', 0);
  58. $res = $room->syncLiveRoom($start, 20, $this->site_id);
  59. return $res;
  60. }
  61. }
  62. /**
  63. * 添加直播间
  64. */
  65. public function add()
  66. {
  67. if (request()->isAjax()) {
  68. $room = new RoomModel();
  69. $data = [
  70. 'name' => input('name', ''),
  71. 'coverImg' => input('coverImg', ''),
  72. 'startTime' => strtotime(input('startTime', '')),
  73. 'endTime' => strtotime(input('endTime', '')),
  74. 'anchorName' => input('anchorName', ''),
  75. 'anchorWechat' => input('anchorWechat', ''),
  76. 'shareImg' => input('shareImg', ''),
  77. 'feedsImg' => input('feedsImg', ''),
  78. 'type' => input('type', 0),
  79. 'screenType' => 0,
  80. 'closeLike' => input('closeLike', 1),
  81. 'closeGoods' => input('closeGoods', 1),
  82. 'closeComment' => input('closeComment', 1),
  83. 'closeReplay' => input('closeReplay', 1),
  84. 'closeKf' => input('closeKf', 1)
  85. ];
  86. $res = $room->createRoom($data, $this->site_id);
  87. return $res;
  88. }
  89. return $this->fetch("room/add");
  90. }
  91. /**
  92. * 添加图片素材
  93. */
  94. public function addImageMedia()
  95. {
  96. if (request()->isAjax()) {
  97. $upload_model = new Upload($this->site_id, $this->app_module);
  98. $thumb_type = input("thumb", "");
  99. $name = input("name", "");
  100. $param = array (
  101. "thumb_type" => "",
  102. "name" => "file",
  103. "watermark" => 0,
  104. "cloud" => 0
  105. );
  106. $path = "common/images/" . date("Ymd") . '/';
  107. $result = $upload_model->setPath($path)->image($param);
  108. if ($result[ 'code' ] < 0) return $result;
  109. $live = new Live($this->site_id);
  110. $media_result = $live->addImageMedia($result[ 'data' ][ 'pic_path' ]);
  111. if ($media_result[ 'code' ] < 0) return $media_result;
  112. return success(0, '上传成功', [ 'pic_info' => $result[ 'data' ], 'media_info' => $media_result[ 'data' ] ]);
  113. }
  114. }
  115. /**
  116. * 运营
  117. */
  118. public function operate()
  119. {
  120. $room = new RoomModel();
  121. if (request()->isAjax()) {
  122. $id = input('id', '');
  123. $anchor_img = input('anchor_img', '-1');
  124. $banner = input('banner', '-1');
  125. $data = [];
  126. if ($anchor_img != '-1') $data = [ 'anchor_img' => $anchor_img ];
  127. if ($banner != '-1') $data = [ 'banner' => $banner ];
  128. $res = $room->updateRoomInfo($data, [ [ 'site_id', '=', $this->site_id ], [ 'id', '=', $id ] ]);
  129. return $res;
  130. }
  131. $id = input('id', '');
  132. $room_info = $room->getRoomInfo([ [ 'site_id', '=', $this->site_id ], [ 'id', '=', $id ] ]);
  133. if (empty($room_info[ 'data' ])) $this->error('未获取到直播间信息');
  134. $this->assign('room_info', $room_info[ 'data' ]);
  135. return $this->fetch("room/operate");
  136. }
  137. /**
  138. * 查询商品
  139. */
  140. public function getGoodsPageList()
  141. {
  142. if (request()->isAjax()) {
  143. $goods = new GoodsModel();
  144. $page = input('page', 1);
  145. $page_size = input('page_size', PAGE_LIST_ROWS);
  146. $sku_id = input('sku_id', '');
  147. $condition = [
  148. [ 'site_id', '=', $this->site_id ],
  149. [ 'status', '=', 2 ]
  150. ];
  151. if (!empty($sku_id)) $condition[] = [ 'sku_id', 'not in', explode(',', $sku_id) ];
  152. $data = $goods->getGoodsPageList($condition, '*', 'id desc', $page, $page_size);
  153. return $data;
  154. }
  155. $ids = input('ids', '');
  156. $this->assign('ids', $ids);
  157. return $this->fetch("room/goods_select");
  158. }
  159. /**
  160. * 添加商品到直播间
  161. * @return array
  162. */
  163. public function addGoods()
  164. {
  165. if (request()->isAjax()) {
  166. $room = new RoomModel();
  167. $room_id = input('room_id', '');
  168. $data = input('data', '');
  169. $res = $room->addGoods($this->site_id, $room_id, $data);
  170. return $res;
  171. }
  172. }
  173. /**
  174. * 删除直播间
  175. * @return mixed
  176. */
  177. public function delete()
  178. {
  179. if (request()->isAjax()) {
  180. $room = new RoomModel();
  181. $room_ids = input('room_ids', '');
  182. $res = $room->deleteRoom($this->site_id, $room_ids);
  183. return $res;
  184. }
  185. }
  186. }