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:
parent
83a39e5648
commit
b5ceb155f3
@ -274,6 +274,7 @@ class Course extends Service
|
|||||||
$allCategories = $categoryRepo->findAll([
|
$allCategories = $categoryRepo->findAll([
|
||||||
'type' => CategoryModel::TYPE_COURSE,
|
'type' => CategoryModel::TYPE_COURSE,
|
||||||
'published' => 1,
|
'published' => 1,
|
||||||
|
'deleted' => 0,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($allCategories->count() == 0) return [];
|
if ($allCategories->count() == 0) return [];
|
||||||
|
@ -50,7 +50,11 @@ class FlashSale extends Service
|
|||||||
{
|
{
|
||||||
$courseRepo = new CourseRepo();
|
$courseRepo = new CourseRepo();
|
||||||
|
|
||||||
$items = $courseRepo->findAll(['free' => 0, 'published' => 1]);
|
$items = $courseRepo->findAll([
|
||||||
|
'free' => 0,
|
||||||
|
'published' => 1,
|
||||||
|
'deleted' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
if ($items->count() == 0) return [];
|
if ($items->count() == 0) return [];
|
||||||
|
|
||||||
|
@ -215,7 +215,6 @@ class PointGift extends Service
|
|||||||
return $gift;
|
return $gift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function createVipPointGift($post)
|
protected function createVipPointGift($post)
|
||||||
{
|
{
|
||||||
$validator = new PointGiftValidator();
|
$validator = new PointGiftValidator();
|
||||||
|
@ -1,10 +1,19 @@
|
|||||||
<?php
|
<?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;
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
final class V20220607014823 extends AbstractMigration
|
final class V20220607014823 extends AbstractMigration
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use SettingTrait;
|
||||||
|
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
$this->handleSiteSettings();
|
$this->handleSiteSettings();
|
||||||
@ -12,7 +21,7 @@ final class V20220607014823 extends AbstractMigration
|
|||||||
|
|
||||||
protected function handleSiteSettings()
|
protected function handleSiteSettings()
|
||||||
{
|
{
|
||||||
$row =
|
$rows =
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
'section' => 'site',
|
'section' => 'site',
|
||||||
@ -36,7 +45,7 @@ final class V20220607014823 extends AbstractMigration
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->table('kg_setting')->insert($row)->save();
|
$this->insertSettings($rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
34
db/migrations/SettingTrait.php
Normal file
34
db/migrations/SettingTrait.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user