1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-29 22:01:38 +08:00

增加迁移SettingTrait

This commit is contained in:
koogua 2022-06-08 09:22:28 +08:00
parent 83a39e5648
commit b5ceb155f3
5 changed files with 51 additions and 4 deletions

View File

@ -274,6 +274,7 @@ class Course extends Service
$allCategories = $categoryRepo->findAll([
'type' => CategoryModel::TYPE_COURSE,
'published' => 1,
'deleted' => 0,
]);
if ($allCategories->count() == 0) return [];

View File

@ -50,7 +50,11 @@ class FlashSale extends Service
{
$courseRepo = new CourseRepo();
$items = $courseRepo->findAll(['free' => 0, 'published' => 1]);
$items = $courseRepo->findAll([
'free' => 0,
'published' => 1,
'deleted' => 0,
]);
if ($items->count() == 0) return [];

View File

@ -215,7 +215,6 @@ class PointGift extends Service
return $gift;
}
protected function createVipPointGift($post)
{
$validator = new PointGiftValidator();

View File

@ -1,10 +1,19 @@
<?php
/**
* @copyright Copyright (c) 2022 深圳市酷瓜软件有限公司
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* @link https://www.koogua.com
*/
require_once 'SettingTrait.php';
use Phinx\Migration\AbstractMigration;
final class V20220607014823 extends AbstractMigration
{
use SettingTrait;
public function up()
{
$this->handleSiteSettings();
@ -12,7 +21,7 @@ final class V20220607014823 extends AbstractMigration
protected function handleSiteSettings()
{
$row =
$rows =
[
[
'section' => 'site',
@ -36,7 +45,7 @@ final class V20220607014823 extends AbstractMigration
],
];
$this->table('kg_setting')->insert($row)->save();
$this->insertSettings($rows);
}
}

View File

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