LivePlayback.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 LivePlayback extends ModelBasic
  18. {
  19. use ModelTrait;
  20. /**储存直播回放
  21. * @param $item
  22. * @param $record_id
  23. */
  24. public static function livePlaybackAdd($item){
  25. if(!self::be(['RecordId'=>$item['RecordId'],'stream_name'=>$item['StreamName']])){
  26. $data=[
  27. 'stream_name'=>$item['StreamName'],
  28. 'playback_url'=>$item['RecordUrl'],
  29. 'start_time'=>strtotime($item['StartTime']),
  30. 'end_time'=>strtotime($item['EndTime']),
  31. 'RecordId'=>$item['RecordId'],
  32. 'add_time'=>time(),
  33. ];
  34. return self::set($data);
  35. }else{
  36. return true;
  37. }
  38. }
  39. /**
  40. * 设置查询条件
  41. */
  42. public static function setUserWhere($where,$model = null,$alias='a',$jsonField='u.nickname')
  43. {
  44. $model = is_null($model) ? new self() : $model ;
  45. if($alias){
  46. $model = $model->alias($alias);
  47. $alias.='.';
  48. }
  49. if($where['start_time'] && $where['end_time']) $model = $model->where("{$alias}add_time",'between',[strtotime($where['start_time']),strtotime($where['end_time'])]);
  50. return $model->order("{$alias}sort desc,{$alias}add_time desc")->where("{$alias}stream_name",$where['stream_name'])->where("{$alias}is_del",0);
  51. }
  52. /**
  53. * 查询直播间用户列表
  54. * @param array $where
  55. */
  56. public static function getLivePlaybackList($where)
  57. {
  58. $data = self::setUserWhere($where)
  59. ->page((int)$where['page'],(int)$where['limit'])->select();
  60. $data = count($data) ? $data->toArray() : [];
  61. foreach ($data as &$item){
  62. $item['_add_time'] = date('Y-m-d H:i:s',$item['add_time']);
  63. $item['StartTime'] = date('Y-m-d H:i:s',$item['start_time']);
  64. $item['EndTime'] = date('Y-m-d H:i:s',$item['end_time']);
  65. }
  66. $count = self::setUserWhere($where)->count();
  67. return compact('data','count');
  68. }
  69. }