80 lines
2.4 KiB
PHP
80 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
/**
|
|
* @property int $asset_id
|
|
* @property int $account_type
|
|
* @property int $belong_id
|
|
* @property int $account_id
|
|
* @property int $category_id
|
|
* @property string $file_name
|
|
* @property string $ori_name
|
|
* @property string $url
|
|
* @property string $type
|
|
* @property string $mime
|
|
* @property string $size
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
* @property string $deleted_at
|
|
*/
|
|
class Asset extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'asset';
|
|
|
|
protected string $primaryKey = 'asset_id';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['asset_id' => 'integer', 'account_type' => 'integer', 'belong_id' => 'integer', 'account_id' => 'integer', 'category_id' => 'integer'];
|
|
|
|
public static function list(array $param)
|
|
{
|
|
$model = (new self());
|
|
if (isset($param['account_type']) && $param['account_type'] != '') {
|
|
$model = $model->where('account_type', $param['account_type']);
|
|
}
|
|
if (isset($param['belong_id']) && $param['belong_id'] != '') {
|
|
$model = $model->where('belong_id', $param['belong_id']);
|
|
}
|
|
if (isset($param['account_id']) && $param['account_id'] != '') {
|
|
$model = $model->where('account_id', $param['account_id']);
|
|
}
|
|
if (isset($param['category_id']) && $param['category_id'] != '') {
|
|
$model = $model->where('category_id', $param['category_id']);
|
|
}
|
|
|
|
if (isset($param['ori_name']) && $param['ori_name'] != '') {
|
|
$model = $model->where('ori_name', "like", "%{$param['ori_name']}%");
|
|
}
|
|
if (isset($param['type']) && $param['type'] != '') {
|
|
$model = $model->where('type', $param['type']);
|
|
}
|
|
return $model->orderByDesc("asset_id")
|
|
->select(["asset_id", "file_name", "ori_name", "url", "type", "mime", "size", "create_time"])
|
|
->paginate((int)$param['limit']);
|
|
|
|
}
|
|
|
|
public static function move(array $data)
|
|
{
|
|
if (!isset($data['ids']) || count($data['ids']) == 0) {
|
|
return false;
|
|
}
|
|
return self::whereIn('asset_id', $data['ids'])->update([
|
|
'category_id' => $data['category_id']
|
|
]);
|
|
}
|
|
}
|