57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace app\common\service;
|
|
|
|
use app\common\validate\VehDictMappingValidate;
|
|
use app\common\traits\crud\CrudServiceTrait;
|
|
use app\common\model\VehDictMapping;
|
|
|
|
class VehDictMappingService
|
|
{
|
|
|
|
use CrudServiceTrait;
|
|
|
|
/**
|
|
* 指定当前要操作的模型
|
|
*/
|
|
protected string $modelClass = VehDictMapping::class;
|
|
|
|
/**
|
|
* 验证器
|
|
*/
|
|
protected $validator = VehDictMappingValidate::class;
|
|
|
|
/**
|
|
* 获取验证器
|
|
*/
|
|
public function getValidator()
|
|
{
|
|
return new $this->validator;
|
|
}
|
|
|
|
|
|
public static function all(): array
|
|
{
|
|
$rows = VehDictMapping::where('status', 1)->orderBy('sort')->orderBy('id')->get()->toArray();
|
|
$out = [];
|
|
foreach ($rows as $r) {
|
|
$out[$r['dict']] = [
|
|
'field' => $r['field'],
|
|
'dict' => $r['dict'],
|
|
'required' => (int)$r['required'] === 1,
|
|
];
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
public static function requiredDicts(): array
|
|
{
|
|
return array_keys(array_filter(self::all(), fn($x)=>$x['required']===true));
|
|
}
|
|
|
|
public static function enabled(string $dict): bool
|
|
{
|
|
$all = self::all();
|
|
return isset($all[$dict]);
|
|
}
|
|
} |