From 3bb613b2b3371db56cf894a4ee8eb41522ccd16d Mon Sep 17 00:00:00 2001 From: koogua Date: Sat, 20 Mar 2021 17:34:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=B0=81=E9=9D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +- app/Library/AppInfo.php | 2 +- app/Models/Course.php | 2 +- app/Models/Package.php | 2 +- app/Models/PointGift.php | 2 +- app/Models/User.php | 2 +- app/Services/Storage.php | 7 +-- .../20210314045908_schema_202103141300.php | 52 ++++++++++++------- 8 files changed, 46 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dfb940a..9dd4f0bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,10 @@ - 增加限时秒杀功能 - 更新phinx默认环境配置项 -- 重构轮播图数据结构 +- 优化存储相关命名以及逻辑 +- 重构轮播图表结构 +- 重构套餐数表结构 +- 重构会员表结构 - 重构xm-select插件选取内容方式 - 整理UI展现形式 diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index de45a4a2..10b5febd 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -11,7 +11,7 @@ class AppInfo protected $link = 'https://koogua.com'; - protected $version = '1.2.8'; + protected $version = '1.2.9'; public function __get($name) { diff --git a/app/Models/Course.php b/app/Models/Course.php index b1ef8060..0a076eeb 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -293,7 +293,7 @@ class Course extends Model } if (empty($this->cover)) { - $this->cover = kg_default_cover_path(); + $this->cover = kg_default_course_cover_path(); } elseif (Text::startsWith($this->cover, 'http')) { $this->cover = self::getCoverPath($this->cover); } diff --git a/app/Models/Package.php b/app/Models/Package.php index a93017ee..b9e27eb5 100644 --- a/app/Models/Package.php +++ b/app/Models/Package.php @@ -106,7 +106,7 @@ class Package extends Model public function beforeCreate() { if (empty($this->cover)) { - $this->cover = kg_default_cover_path(); + $this->cover = kg_default_package_cover_path(); } elseif (Text::startsWith($this->cover, 'http')) { $this->cover = self::getCoverPath($this->cover); } diff --git a/app/Models/PointGift.php b/app/Models/PointGift.php index 61f27896..0a1a5db1 100644 --- a/app/Models/PointGift.php +++ b/app/Models/PointGift.php @@ -167,7 +167,7 @@ class PointGift extends Model } if (empty($this->cover)) { - $this->cover = kg_default_cover_path(); + $this->cover = kg_default_gift_cover_path(); } elseif (Text::startsWith($this->cover, 'http')) { $this->cover = self::getCoverPath($this->cover); } diff --git a/app/Models/User.php b/app/Models/User.php index 60601a19..e4492560 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -179,7 +179,7 @@ class User extends Model public function beforeCreate() { if (empty($this->avatar)) { - $this->avatar = kg_default_avatar_path(); + $this->avatar = kg_default_user_avatar_path(); } elseif (Text::startsWith($this->avatar, 'http')) { $this->avatar = self::getAvatarPath($this->avatar); } diff --git a/app/Services/Storage.php b/app/Services/Storage.php index a7d2fca1..432a2f3b 100644 --- a/app/Services/Storage.php +++ b/app/Services/Storage.php @@ -248,10 +248,11 @@ class Storage extends Service */ protected function generateFileName($extension = '', $prefix = '') { - $randDir = date('Y') . '/' . date('m') . '/'; - $randName = date('YmdHis') . rand(100, 999) . rand(100, 999); + $dir = date('Y') . '/' . date('m') . '/'; - return $prefix . $randDir . $randName . '.' . $extension; + $name = uniqid(); + + return sprintf('%s%s%s.%s', $prefix, $dir, $name, $extension); } /** diff --git a/db/migrations/20210314045908_schema_202103141300.php b/db/migrations/20210314045908_schema_202103141300.php index d40a3dec..3ab18d89 100644 --- a/db/migrations/20210314045908_schema_202103141300.php +++ b/db/migrations/20210314045908_schema_202103141300.php @@ -143,6 +143,18 @@ class Schema202103141300 extends Phinx\Migration\AbstractMigration ]) ->save(); + $this->table('kg_package') + ->addColumn('cover', 'string', [ + 'null' => false, + 'default' => '', + 'limit' => 100, + 'collation' => 'utf8mb4_general_ci', + 'encoding' => 'utf8mb4', + 'comment' => '封面', + 'after' => 'title', + ]) + ->save(); + $this->table('kg_vip') ->addColumn('cover', 'string', [ 'null' => false, @@ -191,8 +203,9 @@ class Schema202103141300 extends Phinx\Migration\AbstractMigration $this->handleSlideTargetAttrs(); - $this->handleVipCover(); + $this->handlePackageCover(); + $this->handleVipCover(); } public function down() @@ -204,6 +217,10 @@ class Schema202103141300 extends Phinx\Migration\AbstractMigration ->removeColumn('target_attrs') ->save(); + $this->table('kg_package') + ->removeColumn('cover') + ->save(); + $this->table('kg_vip') ->removeColumn('cover') ->save(); @@ -282,18 +299,24 @@ class Schema202103141300 extends Phinx\Migration\AbstractMigration } } + protected function handlePackageCover() + { + $cover = '/img/default/package_cover.png'; + + $this->getQueryBuilder() + ->update('kg_package') + ->set('cover', $cover) + ->execute(); + } + protected function handleVipCover() { - $vips = $this->getQueryBuilder() - ->select('*') - ->from('kg_vip') + $cover = '/img/default/vip_cover.png'; + + $this->getQueryBuilder() + ->update('kg_vip') + ->set('cover', $cover) ->execute(); - - if ($vips->count() == 0) return; - - foreach ($vips as $vip) { - $this->updateVipCover($vip['id'], '/img/default/vip_cover.png'); - } } protected function findCourseById($id) @@ -325,13 +348,4 @@ class Schema202103141300 extends Phinx\Migration\AbstractMigration ->execute(); } - protected function updateVipCover($id, $cover) - { - $this->getQueryBuilder() - ->update('kg_vip') - ->set('cover', $cover) - ->where(['id' => $id]) - ->execute(); - } - }