LiveBarrage.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. /**
  13. * 直播间评论表
  14. */
  15. use app\admin\model\system\SystemGroupData;
  16. use basic\ModelBasic;
  17. use service\SystemConfigService;
  18. use traits\ModelTrait;
  19. use app\wap\model\user\User;
  20. use app\admin\model\live\LiveGift;
  21. class LiveBarrage extends ModelBasic
  22. {
  23. use ModelTrait;
  24. public static function getCommentList($uids,$live_id,$page = 0,$limit = 10)
  25. {
  26. $model = self::where('live_id',$live_id)->where('is_show',1);
  27. if($uids) $model = $model->where('uid','in',$uids);
  28. $list = $model->field('type,barrage as content,uid,live_id,id')->order('add_time desc')->page($page,$limit)->select();
  29. $list = count($list) ? $list->toArray() : [];
  30. $commentList=[];
  31. foreach ($list as &$item){
  32. $userinfo = User::where('uid',$item['uid'])->field(['nickname','avatar'])->find();
  33. if($userinfo){
  34. $item['nickname'] =$userinfo['nickname'];
  35. $item['avatar'] =$userinfo['avatar'];
  36. }else{
  37. $item['nickname'] ='';
  38. $item['avatar'] ='';
  39. }
  40. $type = LiveHonouredGuest::where(['uid'=>$item['uid'],'live_id'=>$item['live_id']])->value('type');
  41. if(is_null($type))
  42. $item['user_type'] = 2;
  43. else
  44. $item['user_type'] = $type;
  45. if ($item['type'] == 4) {
  46. $live_reward_list = LiveReward::where(['id' => $item['content']])->find();
  47. if ($live_reward_list ? $live_reward_list = $live_reward_list->toArray(): []){
  48. $live_gift = LiveGift::liveGiftOne($live_reward_list['gift_id']);
  49. if($live_gift){
  50. $item['content'] = "赠送给主播";
  51. $item['gift_num'] = $live_reward_list['gift_num'];
  52. $item['gift_image'] = $live_gift ? $live_gift['live_gift_show_img'] : "";
  53. $item['gift_name'] = $live_reward_list['gift_name'];
  54. array_push($commentList,$item);
  55. }
  56. }
  57. }else{
  58. array_push($commentList,$item);
  59. }
  60. }
  61. $page--;
  62. if(count($commentList) == 0 || count($commentList) < $limit){
  63. $ystemConfig = SystemConfigService::more(['site_name','site_logo']);
  64. $data = [
  65. 'nickname' => $ystemConfig['site_name'],
  66. 'avatar' => $ystemConfig['site_logo'],
  67. 'user_type' => 2,
  68. 'content'=>LiveStudio::where('id',$live_id)->value('auto_phrase'),
  69. 'id' => 0,
  70. 'type'=>1,
  71. 'uid'=>0
  72. ];
  73. array_push($commentList,$data);
  74. }
  75. return ['list'=>$commentList,'page'=> $page];
  76. }
  77. }