LiveStudio.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 basic\ModelBasic;
  16. use traits\ModelTrait;
  17. use think\Db;
  18. class LiveStudio extends ModelBasic
  19. {
  20. use ModelTrait;
  21. public static function getLiveList($limit = 10)
  22. {
  23. return self::where(['l.is_del' => 0, 's.is_show' => 1, 's.is_del' => 0])->alias('l')
  24. ->join('special s', 's.id = l.special_id')
  25. ->field(['s.title', 's.image', 's.browse_count', 'l.is_play', 's.id', 'l.playback_record_id', 'l.start_play_time'])
  26. ->limit($limit)->order('s.sort DESC,l.sort DESC,l.add_time DESC')->select()->each(function ($item) {
  27. if ($item['playback_record_id'] && !$item['is_play']) {
  28. $item['status'] = 2;
  29. } else if ($item['is_play']) {
  30. $item['status'] = 1;
  31. } else if (!$item['playback_record_id'] && !$item['is_play'] && strtotime($item['start_play_time']) > time()) {
  32. $item['status'] = 3;
  33. }
  34. if ($item['start_play_time']) {
  35. $item['start_play_time'] = date('m-d H:i', strtotime($item['start_play_time']));
  36. }
  37. $uids=Db::name('learning_records')->where(['special_id'=>$item['id']])->column('uid');
  38. $uids=array_unique($uids);
  39. $item['records'] =count($uids);
  40. })->toArray();
  41. }
  42. public static function getLiveOne($live_one_id)
  43. {
  44. return self::where(['l.is_del' => 0, 's.is_show' => 1, 's.is_del' => 0])->alias('l')
  45. ->join('special s', 's.id = l.special_id')
  46. ->field(['s.title', 's.image','l.is_play', 's.id'])
  47. ->where('l.is_play',1)->where('s.id',$live_one_id)
  48. ->order('l.sort DESC,l.add_time DESC')->find();
  49. }
  50. public function getStartPlayTimeAttr($time)
  51. {
  52. return $time;//返回create_time原始数据,不进行时间戳转换。
  53. }
  54. }