diff --git a/beike/Admin/Http/Controllers/LogisticsController.php b/beike/Admin/Http/Controllers/LogisticsController.php index aeaea861..1b9eb3a3 100644 --- a/beike/Admin/Http/Controllers/LogisticsController.php +++ b/beike/Admin/Http/Controllers/LogisticsController.php @@ -9,8 +9,10 @@ use Beike\Admin\Repositories\TaxClassRepo; use Beike\Admin\Services\LogisticsService; use Beike\Admin\View\DesignBuilders\Product; use Beike\Libraries\Weight; +use Beike\Models\Country; use Beike\Models\Logistics; use Beike\Repositories\CategoryRepo; +use Beike\Repositories\CountryRepo; use Beike\Repositories\LanguageRepo; use Beike\Repositories\LogisticsRepo; use Illuminate\Http\Request; @@ -161,6 +163,10 @@ class LogisticsController extends Controller ['title' => 'num','name'=>trans('admin/logistics.type_num')], ['title' => 'free','name'=>trans('admin/logistics.type_free')], ]; + // 获取 + $countryIds = (array)explode(',',$logistics->country_ids); + $logistics->country_ids = CountryRepo::getInList($countryIds); + $data = [ 'logistics' => $logistics, 'types' => $types, diff --git a/beike/Admin/Services/LogisticsService.php b/beike/Admin/Services/LogisticsService.php index fdc0599e..30d035da 100644 --- a/beike/Admin/Services/LogisticsService.php +++ b/beike/Admin/Services/LogisticsService.php @@ -49,6 +49,7 @@ class LogisticsService try { DB::beginTransaction(); + $data['country_ids'] = (String) ($data['country_ids'] ? implode(',',$data['country_ids']) : ''); $data['country_id'] = (int) ($data['country_id'] ?? 0); $data['throwing_ratio'] = (int) ($data['throwing_ratio'] ?? 0); $data['day_min'] = (int) ($data['day_min'] ?? 0); @@ -60,12 +61,12 @@ class LogisticsService $data['continuation_weight_fee'] = (float) ($data['continuation_weight_fee'] ?? 0); $data['num_fee'] = (float) ($data['num_fee'] ?? 0); $data['variables'] = json_decode($data['variables'] ?? '[]'); + $logistics->fill($data); $logistics->updated_at = now(); $logistics->save(); - if ($isUpdating) { - } + if ($isUpdating) {} DB::commit(); diff --git a/beike/Models/Logistics.php b/beike/Models/Logistics.php index ea865714..9df21ee2 100644 --- a/beike/Models/Logistics.php +++ b/beike/Models/Logistics.php @@ -10,7 +10,23 @@ class Logistics extends Base use HasFactory; use SoftDeletes; - protected $fillable = ['name', 'warehouse_name', 'country_id', 'type', 'first_weight', 'first_weight_fee', 'continuation_weight_max', 'add_weight', 'continuation_weight_fee', 'throwing_ratio', 'num_fee', 'day_min', 'day_max','position']; + protected $fillable = [ + 'name', + 'warehouse_name', + 'country_id', + 'country_ids', + 'type', + 'first_weight', + 'first_weight_fee', + 'continuation_weight_max', + 'add_weight', + 'continuation_weight_fee', + 'throwing_ratio', + 'num_fee', + 'day_min', + 'day_max', + 'position' + ]; public function country() { diff --git a/beike/Repositories/CountryRepo.php b/beike/Repositories/CountryRepo.php index 18c96d44..a32540de 100644 --- a/beike/Repositories/CountryRepo.php +++ b/beike/Repositories/CountryRepo.php @@ -122,15 +122,50 @@ class CountryRepo return Country::query()->select('id', 'name')->get(); } - public static function autocomplete($name, $onlyActive = 1) - { + /** + * Common: 查询国家列表 + * Author: wu-hui + * Time: 2023/08/21 16:10 + * @param $name + * @param int $onlyActive + * @return Builder[]|Collection + */ + public static function autocomplete($name, $onlyActive = 1){ + // 参数获取 + $pageSize = request()->input('page_size',10); + // 列表获取 $builder = Country::query() ->where('name', 'like', "$name%") - ->select('id', 'name', 'status'); + ->select('id', 'name', 'status', 'code') + ->orderBy('sort_order','DESC') + ->orderBy('id','ASC'); // if ($onlyActive) { // $builder->where('status', 1); // } - - return $builder->limit(10)->get(); + if($pageSize == 'all') return $builder->get(); + else return $builder->limit($pageSize)->get(); } + /** + * Common: 根据国家ID 获取对应的列表 + * Author: wu-hui + * Time: 2023/08/21 16:13 + * @param array $ids + * @return array|mixed[] + */ + public static function getInList(array $ids){ + $list = Country::query() + ->whereIn('id', $ids) + ->select('id', 'name', 'code') + ->orderBy('sort_order','DESC') + ->orderBy('id','ASC') + ->get(); + if($list) { + $list = $list->toArray(); + + return array_column($list,null,'id'); + } + + return []; + } + } diff --git a/resources/beike/admin/views/pages/logistics/form/form.blade.php b/resources/beike/admin/views/pages/logistics/form/form.blade.php index a2e943ca..e97fd5c0 100644 --- a/resources/beike/admin/views/pages/logistics/form/form.blade.php +++ b/resources/beike/admin/views/pages/logistics/form/form.blade.php @@ -25,17 +25,79 @@ @endforeach @endif - + -
+
-
+ @csrf @method($logistics->id ? 'PUT' : 'POST') @@ -49,8 +111,25 @@ @hookwrapper('admin.logistics.edit.country') - - + {{--已选中地区列表--}} +
+
+
+
@{{ item.name }}
+
@{{ item.code }}
+ +
+
+ +
+
+
+ {{--添加按钮--}} + + {{----}} + {{----}}
@endhookwrapper @@ -110,17 +189,21 @@
+
- @hook('admin.logistics.form.footer') + + + @hook('admin.logistics.form.footer') @endsection @push('footer') + @include('shared.select-countries') - + +