You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
/**
|
|
* This is the model class for table "uc_dictionary_t".
|
|
*
|
|
* @property $id bigint
|
|
* @property $pid bigint
|
|
* @property $name varchar
|
|
* @property $title varchar
|
|
* @property $status tinyint
|
|
* @property $created_at timestamp
|
|
* @property $updated_at timestamp
|
|
*/
|
|
class DictionaryT extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'uc_dictionary_t';
|
|
|
|
public $attrs = [
|
|
'pid' => ['name' => 'pid', 'title' => '父ID', 'type' => 'bigint', 'is_must' => '0'],
|
|
'name' => ['name' => 'name', 'title' => '字典值', 'type' => 'varchar', 'is_must' => '1'],
|
|
'title' => ['name' => 'title', 'title' => '字典名', 'type' => 'varchar', 'is_must' => '1'],
|
|
'status' => ['name' => 'status', 'title' => '状态:1 启用 2 关闭', 'type' => 'tinyint', 'is_must' => '0'],
|
|
];
|
|
|
|
public function child()
|
|
{
|
|
return $this->hasMany(get_class($this), 'pid', $this->getKeyName());
|
|
}
|
|
|
|
public function parent()
|
|
{
|
|
return $this->hasOne(get_class($this), $this->getKeyName(), 'pid');
|
|
}
|
|
|
|
public static function getDictValue($name, $value = '')
|
|
{
|
|
$list = Cache::get('dict_list_'.$name);
|
|
if(!$list) {
|
|
$parent = self::where('pid', 0)->where('name', $name)->first();
|
|
$list = $parent->child()->pluck('title', 'name')->toArray();
|
|
Cache::put('dict_list_' . $name, $list, 60 * 60);
|
|
}
|
|
if($value !== ''){
|
|
return $list[$value];
|
|
}
|
|
return $list;
|
|
}
|
|
}
|
|
|