69 lines
2.1 KiB
PHP
69 lines
2.1 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($param)
|
|
{
|
|
return (new self())->setTable("da")
|
|
->from("dict_data as da")
|
|
->join('dict as d', 'd.dict_id', '=', 'da.dict_id')
|
|
->where('d.dict_type', $param['key'])
|
|
->where('da.status', 1)
|
|
->select(["da.dict_value", "da.dict_label", "da.is_default"])
|
|
->orderByDesc("da.rank")
|
|
->get()
|
|
->toArray();
|
|
}
|
|
}
|