From 5c233f1bc5cab5684d4b90819e03085a18528e3c Mon Sep 17 00:00:00 2001 From: TL Date: Tue, 30 Aug 2022 16:26:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=9B=BD=E5=AE=B6=E7=9C=81?= =?UTF-8?q?=E4=BB=BD=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Installer/Lang/en/installer_messages.php | 4 ++-- beike/Models/Zone.php | 2 +- beike/Repositories/CountryRepo.php | 16 +++++++++++++++ beike/Repositories/ZoneRepo.php | 20 +++++++++++++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/beike/Installer/Lang/en/installer_messages.php b/beike/Installer/Lang/en/installer_messages.php index d5481ad2..71c9e6ef 100644 --- a/beike/Installer/Lang/en/installer_messages.php +++ b/beike/Installer/Lang/en/installer_messages.php @@ -23,8 +23,8 @@ return [ * */ 'welcome' => [ - 'templateTitle' => 'Welcome', - 'title' => 'Laravel Installer', + 'title' => 'Welcome', + 'describe' => 'Welcome to install BeikeShop. Easy Installation and Setup Wizard.', 'message' => 'Easy Installation and Setup Wizard.', 'next' => 'Check Requirements', ], diff --git a/beike/Models/Zone.php b/beike/Models/Zone.php index bea84a75..21aa9641 100644 --- a/beike/Models/Zone.php +++ b/beike/Models/Zone.php @@ -17,6 +17,6 @@ class Zone extends Base { use HasFactory; - protected $fillable = ['name', 'code', 'sort_order', 'status']; + protected $fillable = ['country_id', 'name', 'code', 'sort_order', 'status']; } diff --git a/beike/Repositories/CountryRepo.php b/beike/Repositories/CountryRepo.php index c7693230..9d9e7929 100644 --- a/beike/Repositories/CountryRepo.php +++ b/beike/Repositories/CountryRepo.php @@ -16,6 +16,20 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator; class CountryRepo { + /** + * @param $data + * @return array + */ + private static function handleParams($data) + { + return [ + 'name' => $data['name'] ?? '', + 'code' => $data['code'] ?? '', + 'sort_order' => (int)$data['sort_order'] ?? 0, + 'status' => (bool)$data['status'] ?? 0, + ]; + } + /** * 创建一个country记录 * @param $data @@ -23,6 +37,7 @@ class CountryRepo */ public static function create($data) { + $data = self::handleParams($data); return Country::query()->create($data); } @@ -34,6 +49,7 @@ class CountryRepo */ public static function update($id, $data) { + $data = self::handleParams($data); $country = Country::query()->find($id); if (!$country) { throw new \Exception("国家id {$id} 不存在"); diff --git a/beike/Repositories/ZoneRepo.php b/beike/Repositories/ZoneRepo.php index d90cfc29..156b3ace 100644 --- a/beike/Repositories/ZoneRepo.php +++ b/beike/Repositories/ZoneRepo.php @@ -15,6 +15,21 @@ use Beike\Models\Zone; class ZoneRepo { + /** + * @param $data + * @return array + */ + private static function handleParams($data) + { + return [ + 'country_id' => $data['country_id'] ?? 0, + 'name' => $data['name'] ?? '', + 'code' => $data['code'] ?? '', + 'sort_order' => (int)$data['sort_order'] ?? 0, + 'status' => (bool)$data['status'] ?? 0, + ]; + } + /** * 创建一个zone记录 * @param $data @@ -22,8 +37,8 @@ class ZoneRepo */ public static function create($data) { - $id = Zone::query()->insertGetId($data); - return self::find($id); + $data = self::handleParams($data); + return Zone::query()->create($data); } /** @@ -38,6 +53,7 @@ class ZoneRepo if (!$zone) { throw new \Exception("省份/地区id {$id} 不存在"); } + $data = self::handleParams($data); $zone->update($data); return $zone; }