74 lines
1.5 KiB
PHP
74 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property int $pid
|
|
* @property string $key
|
|
* @property string $value
|
|
* @property string $desc
|
|
* @property int $input_type
|
|
* @property int $sort
|
|
* @property string $param
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class Config extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'config';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
protected array $guarded = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['id' => 'integer', 'pid' => 'integer', 'status' => 'integer', 'input_type' => 'integer', 'sort' => 'integer'];
|
|
|
|
const CREATED_AT = 'create_time';
|
|
|
|
const UPDATED_AT = 'update_time';
|
|
|
|
/**
|
|
* 获取
|
|
* @return array
|
|
*/
|
|
public function getTopConfigModule(): array
|
|
{
|
|
$res = $this->where('pid', 0)->get(['id', 'name']);
|
|
|
|
if (empty($res)) return [];
|
|
|
|
return $res->toArray();
|
|
}
|
|
|
|
/**
|
|
* @param int $pid
|
|
* @return array
|
|
*/
|
|
public function getConfigByPid(int $pid): array
|
|
{
|
|
$res = $this
|
|
->where('pid', $pid)
|
|
->orderBy('sort','desc')
|
|
->get(['id', 'pid', 'name', 'value','param','desc','input_type','sort','key']);
|
|
|
|
if (empty($res)) return [];
|
|
|
|
return $res->toArray();
|
|
}
|
|
}
|