1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 03:50:56 +08:00
2023-05-12 18:52:11 +08:00

34 lines
829 B
PHP

<?php
/**
* @copyright Copyright (c) 2022 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
trait SettingTrait
{
protected function insertSettings(array $rows)
{
foreach ($rows as $key => $row) {
$exists = $this->settingExists($row['section'], $row['item_key']);
if ($exists) unset($rows[$key]);
}
if (count($rows) == 0) return;
$this->table('kg_setting')->insert($rows)->save();
}
protected function settingExists($section, $itemKey)
{
$row = $this->getQueryBuilder()
->select('*')
->from('kg_setting')
->where(['section' => $section, 'item_key' => $itemKey])
->execute()->fetch();
return (bool)$row;
}
}