LiveBarrage.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\admin\model\live;
  12. /**
  13. * 直播间评论表
  14. */
  15. use basic\ModelBasic;
  16. use traits\ModelTrait;
  17. class LiveBarrage extends ModelBasic
  18. {
  19. use ModelTrait;
  20. /*
  21. * 设置where条件
  22. * @param array $where 查询条件
  23. * @param object $model 模型实例化对象
  24. * @param string $alias 表别名
  25. * @param string $jsonField json 模糊查询字段
  26. * @return object
  27. * */
  28. public static function setWhere($where,$model =null ,$alias ='',$jsonField='')
  29. {
  30. $model = is_null($model) ? new self() : $model;
  31. if($alias){
  32. $model = $model->alias($alias);
  33. $alias.='.';
  34. }
  35. if($where['nickname']) $model = $model->where("{$alias}barrage".($jsonField ? '|'.$jsonField : ""),'like',"%$where[nickname]%");
  36. if($where['live_id']) $model = $model->where("{$alias}live_id",$where['live_id']);
  37. if($where['start_time'] && $where['end_time']) $model = $model->where("{$alias}add_time",'between',[strtotime($where['start_time']),strtotime($where['end_time'])]);
  38. return $model;
  39. }
  40. /*
  41. * 查询评论列表
  42. * @param array $where 查询条件
  43. * @return array
  44. * */
  45. public static function getLiveCommentList($where)
  46. {
  47. $data = self::setWhere($where,null,'a','u.nickname')->join('user u','u.uid=a.uid')->field(['a.*','u.avatar','u.nickname'])
  48. ->page((int)$where['page'],(int)$where['limit'])->order('id','desc')->select();
  49. $data = count($data) ? $data->toArray() : [];
  50. foreach ($data as &$item){
  51. $type = LiveHonouredGuest::where(['uid'=>$item['uid'],'live_id'=>$where['live_id']])->value('type');
  52. if($type === null)
  53. $item['type_name'] = '听众';
  54. else if($type === 1)
  55. $item['type_name'] = '讲师';
  56. else if($type === 0)
  57. $item['type_name'] = '助教';
  58. $item['add_time'] = date('Y-m-d H:i:s',$item['add_time']);
  59. }
  60. $count = self::setWhere($where,null,'a','u.nickname')->join('user u','u.uid=a.uid')->count();
  61. return compact('data','count');
  62. }
  63. }