server/app/Model/Attachment.php

65 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $attachment_id
* @property int $account_type
* @property int $belong_id
* @property int $account_id
* @property string $name
* @property string $module
* @property string $params
* @property string $type
* @property string $path
* @property int $status
* @property string $fail_reason
* @property string $deleted_at
* @property string $create_time
* @property string $update_time
*/
class Attachment extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'attachment';
protected string $primaryKey = 'attachment_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['attachment_id' => 'integer', 'account_id' => 'integer', 'status' => 'integer', 'account_type' => 'integer', 'belong_id' => 'integer'];
public static function list(array $param)
{
$model = self::query();
if (isset($param['account_id']) && $param['account_id'] != '') {
$model = $model->where('account_id', $param['account_id']);
}
if (isset($param['name']) && $param['name'] != '') {
$model = $model->where('name', "like", "%{$param['name']}%");
}
if (isset($param['module']) && $param['module'] != '') {
$model = $model->where('module', $param['module']);
}
if (isset($param['type']) && $param['type'] != '') {
$model = $model->where('type', $param['type']);
}
if (isset($param['status']) && $param['status'] != '') {
$model = $model->where('status', $param['status']);
}
return $model->orderByDesc("attachment_id")
->select(["attachment_id", "name", "type", "path", "status", "fail_reason", "create_time"])
->paginate((int)$param['limit']);
}
}