108 lines
2.4 KiB
PHP
108 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use Hyperf\Collection\Collection;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
use function Hyperf\Config\config;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $url
|
|
* @property int $size
|
|
* @property int $height
|
|
* @property int $width
|
|
* @property int $audio_second
|
|
* @property int $video_duration
|
|
* @property int $is_enabled
|
|
* @property string $create_time
|
|
* @property int $type
|
|
*/
|
|
class OssObject extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'oss_object';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
protected array $guarded = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['id' => 'integer', 'size' => 'integer','height' => 'integer', 'width' => 'integer', 'audio_second' => 'integer', 'video_duration' => 'integer', 'is_enabled' => 'integer', 'type' => 'integer'];
|
|
|
|
const CREATED_AT = 'create_time';
|
|
|
|
const UPDATED_AT = null;
|
|
|
|
/**
|
|
* url访问器
|
|
* @param $value
|
|
* @return string
|
|
*/
|
|
public function getUrlAttribute($value)
|
|
{
|
|
return config('ali.oss_url').$value;
|
|
}
|
|
|
|
/**
|
|
* 根据ids获取资源id列表
|
|
* @param array $ids
|
|
* @return Collection
|
|
*/
|
|
public function getIdListByIds(array $ids): Collection
|
|
{
|
|
return $this->whereIn('id', $ids)->pluck('id');
|
|
}
|
|
|
|
|
|
/**
|
|
* 根据ids更新oss Enable状态
|
|
*/
|
|
public function updateEnabledByIds(array $ids): int
|
|
{
|
|
return $this->whereIn('id', $ids)->update(['is_enabled' => 1]);
|
|
}
|
|
|
|
/**
|
|
* 根据ids 更新oss Disable状态
|
|
* @param array $ids
|
|
* @return int
|
|
*/
|
|
public function updateDisableByIds(array $ids): int
|
|
{
|
|
return $this->whereIn('id', $ids)->update(['is_enabled' => 0]);
|
|
}
|
|
|
|
/**
|
|
* 根据id获取信息
|
|
* @param array $ids
|
|
* @return Collection
|
|
*/
|
|
public function getInfoByOssIds(array $ids): Collection
|
|
{
|
|
return $this->whereIn('id', $ids)->get();
|
|
}
|
|
|
|
/**
|
|
* 根据is_enabled获取传入时间前无效资源id
|
|
* @param $time
|
|
* @return Collection|false
|
|
*/
|
|
public function getOssIdListByIsEnabled($time): Collection|false
|
|
{
|
|
return $this->where([
|
|
['is_enabled', '=', 0],
|
|
['create_time', '<',$time]
|
|
])->pluck('id') ?? false;
|
|
}
|
|
}
|