LiveUser.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 LiveUser extends ModelBasic
  18. {
  19. use ModelTrait;
  20. /*
  21. * 设置查询条件
  22. * */
  23. public static function setUserWhere($where,$model = null,$alias='a',$jsonField='u.nickname')
  24. {
  25. $model = is_null($model) ? new self() : $model ;
  26. if($alias){
  27. $model = $model->alias($alias);
  28. $alias.='.';
  29. }
  30. if($where['nickname']) $model = $model->where("{$alias}uid".($jsonField ? '|'.$jsonField : ''),'LIKE',"$where[nickname]");
  31. if($where['start_time'] && $where['end_time']) $model = $model->where("{$alias}add_time",'between',[strtotime($where['start_time']),strtotime($where['end_time'])]);
  32. return $model->order("{$alias}add_time desc")->where("{$alias}live_id",$where['live_id']);
  33. }
  34. /*
  35. * 查询直播间用户列表
  36. * @param array $where
  37. * */
  38. public static function getLiveUserList($where)
  39. {
  40. $data = self::setUserWhere($where)->join('user u','a.uid=u.uid')->field(['a.*','u.nickname','u.avatar'])
  41. ->page((int)$where['page'],(int)$where['limit'])->select();
  42. $data = count($data) ? $data->toArray() : [];
  43. foreach ($data as &$item){
  44. $item['_add_time'] = date('Y-m-d H:i:s',$item['add_time']);
  45. $item['_last_time'] = $item['last_time'] ? date('Y-m-d H:i:s',$item['last_time']) : '暂无';
  46. $item['ban_time']=$item['ban_time'] ? date('Y-m-d H:i:s',$item['ban_time']) : '0';
  47. $item['open_ben_time']=$item['open_ben_time'] ? date('Y-m-d H:i:s',$item['open_ben_time']) : '0';
  48. }
  49. $count = self::setUserWhere($where)->join('user u','a.uid=u.uid')->count();
  50. return compact('data','count');
  51. }
  52. }