server/app/Model/Dict.php

69 lines
1.8 KiB
PHP

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