85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
namespace Modules\SystemTool\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* Class Setting
|
|
*/
|
|
class SysConfigItemsModel extends Model
|
|
{
|
|
protected $table = 'sys_config_items';
|
|
|
|
protected $casts = [
|
|
'group_id' => 'int',
|
|
'sort' => 'int',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'key',
|
|
'title',
|
|
'describe',
|
|
'values',
|
|
'type',
|
|
'options',
|
|
'props',
|
|
'group_id',
|
|
'sort',
|
|
];
|
|
|
|
protected $appends = ['options_json', 'props_json'];
|
|
|
|
/**
|
|
* 关联设置
|
|
* @return BelongsTo
|
|
*/
|
|
public function group(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SysConfigGroupModel::class, 'id', 'group_id');
|
|
}
|
|
|
|
public function getOptionsJsonAttribute(): string
|
|
{
|
|
if(empty($this->options)) {
|
|
return "{}";
|
|
}
|
|
$data = [];
|
|
$value = explode("\n", $this->options);
|
|
foreach ($value as $item) {
|
|
$item = explode('=',$item);
|
|
if(count($item) < 2) {
|
|
continue;
|
|
}
|
|
$data[] = [
|
|
'label' => $item[1],
|
|
'value' => $item[0]
|
|
];
|
|
}
|
|
return json_encode($data);
|
|
}
|
|
|
|
public function getPropsJsonAttribute(): string
|
|
{
|
|
if(empty($this->props)) {
|
|
return "{}";
|
|
}
|
|
$data = [];
|
|
$value = explode("\n",$this->props);
|
|
foreach ($value as $item) {
|
|
$item = explode('=',$item);
|
|
if(count($item) < 2) {
|
|
continue;
|
|
}
|
|
if($item[1] === 'false') {
|
|
$data[$item[0]] = false;
|
|
}elseif ($item[1] === 'true') {
|
|
$data[$item[0]] = true;
|
|
}else {
|
|
$data[$item[0]] = $item[1];
|
|
}
|
|
}
|
|
return json_encode($data);
|
|
}
|
|
}
|