后台国家省份管理

This commit is contained in:
TL 2022-08-30 16:26:11 +08:00
parent dcc1640b1c
commit 5c233f1bc5
4 changed files with 37 additions and 5 deletions

View File

@ -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',
],

View File

@ -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'];
}

View File

@ -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} 不存在");

View File

@ -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;
}