server/app/Model/DictData.php

61 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $data_id
* @property int $dict_id
* @property string $dict_label
* @property string $dict_value
* @property int $is_default
* @property int $rank
* @property int $status
* @property string $remark
* @property string $create_time
* @property string $update_time
* @property string $deleted_at
*/
class DictData extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'dict_data';
protected string $primaryKey = 'data_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['data_id' => 'integer', 'dict_id' => 'integer', 'is_default' => 'integer', 'rank' => 'integer', 'status' => 'integer'];
public static function list(array $param)
{
$model = self::query();
if (isset($param['dict_id']) && $param['dict_id'] != '') {
$model = $model->where('dict_id', $param['dict_id']);
}
if (isset($param['dict_label']) && $param['dict_label'] != '') {
$model = $model->where('dict_label', 'like', "%{$param['dict_label']}%");
}
if (isset($param['status']) && $param['status'] != '') {
$model = $model->where('status', $param['status']);
}
return $model->orderByDesc("rank")
->orderByDesc("dict_id")
->select(["data_id", "dict_id", "dict_label", "dict_value", "is_default", "rank", "status", "remark", "create_time", "update_time"])
->paginate((int)$param['limit']);
}
public static function options()
{
return self::select(["data_id", "data_name"])->get()->toArray();
}
}