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.
40 lines
1.0 KiB
40 lines
1.0 KiB
<?php
|
|
|
|
namespace app\enterprise\model;
|
|
|
|
use think\Model;
|
|
|
|
class PostsFile extends Model
|
|
{
|
|
|
|
public static function getPostsFile($posts_id)
|
|
{
|
|
$fileWhere = [
|
|
'posts_id' => $posts_id,
|
|
'delete_time' => 0
|
|
];
|
|
$files = self::where($fileWhere)
|
|
->field('file_id,type')
|
|
->order('sort asc')
|
|
->select()
|
|
->toArray();
|
|
$videoFile = [];
|
|
$privacyFile = [];
|
|
$is_video = 0;
|
|
foreach ($files as &$fileValue) {
|
|
$filesWhere = ['file_id' => $fileValue['file_id'], 'delete_time' => 0];
|
|
$fileValue['src'] = File::where($filesWhere)->value('src');
|
|
if ($fileValue['type'] == 2) {
|
|
$is_video = 1;
|
|
$videoFile = $fileValue;
|
|
}
|
|
$privacyFile = $fileValue;
|
|
}
|
|
if ($is_video) {
|
|
$newFiles = $videoFile;
|
|
$newFiles['privacy'] = $privacyFile['src'];
|
|
$files = [$newFiles];
|
|
}
|
|
return $files;
|
|
}
|
|
}
|