LiveBarrage.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\live;
  12. use basic\ModelBasic;
  13. use service\SystemConfigService;
  14. use traits\ModelTrait;
  15. use app\wap\model\user\User;
  16. use app\wap\model\live\LiveGift;
  17. /**直播间评论表
  18. * Class LiveBarrage
  19. * @package app\wap\model\live
  20. */
  21. class LiveBarrage extends ModelBasic
  22. {
  23. use ModelTrait;
  24. /**助教评论列表
  25. * @param $uids
  26. * @param $live_id
  27. * @param int $page
  28. * @param int $limit
  29. * @return array
  30. * @throws \think\Exception
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \think\exception\DbException
  34. */
  35. public static function getCommentList($uids, $live_id, $page = 0, $limit = 10)
  36. {
  37. $model = self::where('live_id', $live_id)->where('is_show', 1);
  38. if ($uids) $model = $model->where('uid', 'in', $uids);
  39. $list = $model->field('type,barrage as content,uid,live_id,id')->order('add_time desc')->page($page, $limit)->select();
  40. $list = count($list) ? $list->toArray() : [];
  41. $commentList = [];
  42. foreach ($list as &$item) {
  43. $userinfo = User::where('uid', $item['uid'])->field(['nickname', 'avatar'])->find();
  44. if ($userinfo) {
  45. $item['nickname'] = $userinfo['nickname'];
  46. $item['avatar'] = $userinfo['avatar'];
  47. } else {
  48. $item['nickname'] = '';
  49. $item['avatar'] = '';
  50. }
  51. $type = LiveHonouredGuest::where(['uid' => $item['uid'], 'live_id' => $item['live_id']])->value('type');
  52. if (is_null($type))
  53. $item['user_type'] = 2;
  54. else
  55. $item['user_type'] = $type;
  56. if ($item['type'] == 4) {
  57. $live_reward_list = LiveReward::where(['id' => $item['content']])->find();
  58. if ($live_reward_list ? $live_reward_list = $live_reward_list->toArray() : []) {
  59. $live_gift = LiveGift::liveGiftOne($live_reward_list['gift_id']);
  60. if ($live_gift) {
  61. $item['content'] = "赠送给主播";
  62. $item['gift_num'] = $live_reward_list['gift_num'];
  63. $item['gift_image'] = $live_gift ? $live_gift['live_gift_show_img'] : "";
  64. $item['gift_name'] = $live_reward_list['gift_name'];
  65. array_push($commentList, $item);
  66. }
  67. }
  68. } else {
  69. array_push($commentList, $item);
  70. }
  71. }
  72. $page--;
  73. if (count($commentList) == 0 || count($commentList) < $limit) {
  74. $ystemConfig = SystemConfigService::more(['site_name', 'home_logo']);
  75. $data = [
  76. 'nickname' => $ystemConfig['site_name'],
  77. 'avatar' => $ystemConfig['home_logo'],
  78. 'user_type' => 2,
  79. 'content' => LiveStudio::where('id', $live_id)->value('auto_phrase'),
  80. 'id' => 0,
  81. 'type' => 1,
  82. 'uid' => 0
  83. ];
  84. array_push($commentList, $data);
  85. }
  86. return ['list' => $commentList, 'page' => $page];
  87. }
  88. }