63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace plugin\produce\app\dao;
|
||
|
|
|
||
|
|
use core\base\BaseDao;
|
||
|
|
use plugin\produce\app\model\ProduceConfig;
|
||
|
|
|
||
|
|
class ProduceConfigDao extends BaseDao
|
||
|
|
{
|
||
|
|
protected function setModel(): string
|
||
|
|
{
|
||
|
|
return ProduceConfig::class;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function getKeywordFields(): array
|
||
|
|
{
|
||
|
|
return ['group_code', 'code', 'name', 'remark'];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getByGroupCode(string $groupCode): array
|
||
|
|
{
|
||
|
|
$items = $this->getModel()::query()
|
||
|
|
->where('group_code', $groupCode)
|
||
|
|
->orderBy('sort')
|
||
|
|
->orderBy('id')
|
||
|
|
->get();
|
||
|
|
|
||
|
|
$result = [];
|
||
|
|
foreach ($items as $item) {
|
||
|
|
$result[$item->code] = $item->content;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $result;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function batchSave(string $groupCode, array $configs): bool
|
||
|
|
{
|
||
|
|
$timestamp = time();
|
||
|
|
|
||
|
|
foreach ($configs as $config) {
|
||
|
|
$this->getModel()::query()->updateOrCreate(
|
||
|
|
[
|
||
|
|
'group_code' => $groupCode,
|
||
|
|
'code' => (string) ($config['code'] ?? ''),
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'name' => (string) ($config['name'] ?? ''),
|
||
|
|
'content' => is_scalar($config['content'] ?? null) || $config['content'] === null
|
||
|
|
? ($config['content'] ?? null)
|
||
|
|
: json_encode($config['content'], JSON_UNESCAPED_UNICODE),
|
||
|
|
'sort' => (int) ($config['sort'] ?? 0),
|
||
|
|
'remark' => (string) ($config['remark'] ?? ''),
|
||
|
|
'updated_at' => $timestamp,
|
||
|
|
]
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|