LivePlayback.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\merchant\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. {
  26. if (!self::be(['RecordId' => $item['RecordId'], 'stream_name' => $item['StreamName']])) {
  27. $data = [
  28. 'stream_name' => $item['StreamName'],
  29. 'playback_url' => $item['RecordUrl'],
  30. 'start_time' => strtotime($item['StartTime']),
  31. 'end_time' => strtotime($item['EndTime']),
  32. 'RecordId' => $item['RecordId'],
  33. 'add_time' => time(),
  34. ];
  35. return self::set($data);
  36. } else {
  37. return true;
  38. }
  39. }
  40. /**
  41. * 设置查询条件
  42. */
  43. public static function setUserWhere($where, $model = null, $alias = 'a', $jsonField = 'u.nickname')
  44. {
  45. $model = is_null($model) ? new self() : $model;
  46. if ($alias) {
  47. $model = $model->alias($alias);
  48. $alias .= '.';
  49. }
  50. if ($where['start_time'] && $where['end_time']) $model = $model->where("{$alias}add_time", 'between', [strtotime($where['start_time']), strtotime($where['end_time'])]);
  51. return $model->order("{$alias}sort desc,{$alias}add_time desc")->where("{$alias}stream_name", $where['stream_name'])->where("{$alias}is_del", 0);
  52. }
  53. /**
  54. * 查询直播间用户列表
  55. * @param array $where
  56. */
  57. public static function getLivePlaybackList($where)
  58. {
  59. $data = self::setUserWhere($where)->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. }