Room.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace app\api\controller\plus\live;
  3. use app\api\controller\Controller;
  4. use app\api\model\plus\live\Room as RoomModel;
  5. use app\api\model\plus\live\Gift as GiftModel;
  6. use app\api\model\product\Product as ProductModel;
  7. use app\api\model\user\Favorite as FavoriteModel;
  8. use app\api\model\settings\Setting as SettingModel;
  9. use app\common\service\qrcode\RoomService;
  10. use app\common\model\plus\live\UserGift as UserGiftModel;
  11. /**
  12. * 房间控制器
  13. */
  14. class Room extends Controller
  15. {
  16. /**
  17. * 微信直播列表
  18. */
  19. public function lists()
  20. {
  21. $model = new RoomModel();
  22. $list = $model->getList($this->postData(),$this->getUser(false));
  23. $live = $model->getLive($this->postData());
  24. return $this->renderSuccess('', compact('list','live'));
  25. }
  26. /**
  27. * 礼物列表
  28. */
  29. public function gift()
  30. {
  31. $model = new GiftModel();
  32. $list = $model->getList();
  33. return $this->renderSuccess('', compact('list'));
  34. }
  35. /**
  36. * 发送礼物
  37. */
  38. public function send_gift($room_id, $gift_id)
  39. {
  40. $model = new GiftModel();
  41. if($model->sendGift($this->getUser(), $room_id, $gift_id)){
  42. // 重新获取用户礼物数量
  43. $gift_money = $this->getUser()['gift_money'];
  44. // 房间获取的总礼物数
  45. $gift_num = RoomModel::detail($room_id)['gift_num'];
  46. return $this->renderSuccess('发送成功',compact('gift_money', 'gift_num'));
  47. }
  48. return $this->renderError($model->getError()?:'发送失败');
  49. }
  50. /**
  51. * 点赞
  52. */
  53. public function digg($room_id,$num)
  54. {
  55. $model = RoomModel::detail($room_id);
  56. if($model->digg($num)){
  57. $digg_num = $model['digg_num'] + 1;
  58. return $this->renderSuccess('点赞成功', compact('digg_num'));
  59. }
  60. return $this->renderError($model->getError()?:'点赞失败');
  61. }
  62. /**
  63. * 当前房间详情
  64. */
  65. public function detail($room_id){
  66. $model = RoomModel::detail($room_id, ['cover', 'product.product.image.file', 'user', 'share', 'currentProduct.image.file','supplier.logo']);
  67. // 是否关注过
  68. $hasFollow = false;
  69. $fans = $this->getUser();
  70. if($fans && $fans['user_id'] != $model['user_id']){
  71. $hasFollow = FavoriteModel::isFollow($model['shop_supplier_id'], $fans['user_id'],10)?true:false;
  72. }
  73. $gift_name = SettingModel::getItem('live')['gift_name'];
  74. $user = [
  75. 'nickName' => $fans['nickName'],
  76. 'avatarUrl' => $fans['avatarUrl'],
  77. ];
  78. return $this->renderSuccess('', compact('model', 'hasFollow', 'gift_name', 'user'));
  79. }
  80. /**
  81. * 同步房间详情
  82. */
  83. public function syn_room($room_id){
  84. $detail = RoomModel::detail($room_id);
  85. $detail->updateEndTime();
  86. $model = [
  87. 'views' => $detail['show_views'],
  88. 'digg_num' => $detail['digg_num'],
  89. ];
  90. return $this->renderSuccess('', compact('model'));
  91. }
  92. /**
  93. * 设置商品
  94. */
  95. public function set_product($room_id, $product_id)
  96. {
  97. $user = $this->getUser();
  98. $model = RoomModel::detailByUser($user['user_id'], $room_id);
  99. if($model->setProduct($product_id)){
  100. return $this->renderSuccess('设置成功');
  101. }
  102. return $this->renderError($model->getError()?:'设置失败');
  103. }
  104. /**
  105. * 设置商品
  106. */
  107. public function product_detail($product_id)
  108. {
  109. $model = ProductModel::detail($product_id);
  110. return $this->renderSuccess('',compact('model'));
  111. }
  112. /**
  113. * 设置状态
  114. */
  115. public function set_status($room_id, $status)
  116. {
  117. $user = $this->getUser();
  118. $model = RoomModel::detailByUser($user['user_id'], $room_id);
  119. if($model->setStatus($status)){
  120. return $this->renderSuccess('修改成功');
  121. }
  122. return $this->renderError($model->getError()?:'修改失败');
  123. }
  124. /**
  125. * 生成直播海报
  126. */
  127. public function poster($room_id, $source)
  128. {
  129. // 商品详情
  130. $detail = RoomModel::detail($room_id, ['user', 'share']);
  131. $Qrcode = new RoomService($detail, $this->getUser(), $source);
  132. return $this->renderSuccess('', [
  133. 'qrcode' => $Qrcode->getImage(),
  134. ]);
  135. }
  136. /**
  137. * 礼物排行
  138. */
  139. public function user_gift()
  140. {
  141. $model = new UserGiftModel();
  142. $list = $model->getList($this->postData());
  143. return $this->renderSuccess('', compact('list'));
  144. }
  145. /**
  146. * 直播数据
  147. */
  148. public function livedata()
  149. {
  150. $user = $this->getUser();
  151. $model = new RoomModel();
  152. $data = $model->livedata($user['supplierUser']['shop_supplier_id']);
  153. return $this->renderSuccess('', compact('data'));
  154. }
  155. }