Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MediaFile.php 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海口快推科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\home\model;
  14. use think\Db;
  15. use think\Model;
  16. /**
  17. * 视频文件
  18. */
  19. class MediaFile extends Model
  20. {
  21. //初始化
  22. protected function initialize()
  23. {
  24. // 需要调用`Model`的`initialize`方法
  25. parent::initialize();
  26. }
  27. /**
  28. * 获取指定下载文章的所有文件
  29. * @author 小虎哥 by 2018-4-3
  30. */
  31. public function getMediaFile($aid, $field = '*')
  32. {
  33. $request = request();
  34. $result = Db::name('media_file')->field($field)
  35. ->where('aid', $aid)
  36. ->order('file_id asc')
  37. ->select();
  38. foreach ($result as $key => $val) {
  39. if (!empty($val['file_url'])) {
  40. $result[$key]['file_url'] = handle_subdir_pic($val['file_url'], 'media');
  41. if (!is_http_url($result[$key]['file_url'])){
  42. $result[$key]['file_url'] = $request->domain() .$result[$key]['file_url'];
  43. }
  44. }
  45. if (!empty($val['file_time'])) {
  46. // 总秒数
  47. $time = intval($val['file_time']);
  48. // 可读时间
  49. $humanTime = '';
  50. if ($time > 3600) {// 判断小时
  51. $hours = intval(($time / 3600));
  52. $time = $time % 3600;
  53. if ($hours && $hours < 10) {
  54. $humanTime .= '0' . $hours . ':';
  55. } elseif ($hours && $hours > 10) {
  56. $humanTime .= $hours . ':';
  57. }
  58. } else {
  59. $humanTime .= '00:';
  60. }
  61. if ($time > 60) {// 判断分钟
  62. $minutes = intval(($time / 60));
  63. $time = $time % 60;
  64. if ($minutes && $minutes < 10) {
  65. $humanTime .= '0' . $minutes . ':';
  66. } elseif ($minutes && $minutes > 10) {
  67. $humanTime .= $minutes . ':';
  68. }
  69. } else {
  70. $humanTime .= '00:';
  71. }
  72. if ($time > 0) {// 判断秒钟
  73. $seconds = $time;
  74. if ($seconds && $seconds < 10) {
  75. $humanTime .= '0' . $seconds . '';
  76. } elseif ($seconds && $seconds >= 10) {
  77. $humanTime .= $seconds . '';
  78. }
  79. } else {
  80. $humanTime .= '00';
  81. }
  82. $result[$key]['file_time'] = $humanTime;
  83. }
  84. }
  85. return $result;
  86. }
  87. }