From e6882598fe115a229c9a60d7c91b0b70aa7f7e57 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Mon, 28 Aug 2023 17:45:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E7=89=A9=E6=B5=81?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=AD=E9=87=8D=E8=8C=83=E5=9B=B4=E5=A1=AB?= =?UTF-8?q?=E5=86=99=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/LogisticsController.php | 5 +- beike/Admin/Services/LogisticsService.php | 18 +++++ beike/Models/LogisticsWeight.php | 37 +++++++++ .../views/pages/logistics/form/form.blade.php | 80 ++++++++++++++++--- 4 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 beike/Models/LogisticsWeight.php diff --git a/beike/Admin/Http/Controllers/LogisticsController.php b/beike/Admin/Http/Controllers/LogisticsController.php index eae69d60..dac7f921 100644 --- a/beike/Admin/Http/Controllers/LogisticsController.php +++ b/beike/Admin/Http/Controllers/LogisticsController.php @@ -11,6 +11,7 @@ use Beike\Admin\View\DesignBuilders\Product; use Beike\Libraries\Weight; use Beike\Models\Country; use Beike\Models\Logistics; +use Beike\Models\LogisticsWeight; use Beike\Repositories\CategoryRepo; use Beike\Repositories\CountryRepo; use Beike\Repositories\LanguageRepo; @@ -121,7 +122,7 @@ class LogisticsController extends Controller return redirect()->to($this->getRedirect())->with('success', trans('common.updated_success')); } catch (\Exception $e) { - return redirect(admin_route('products.edit', $product))->withErrors(['error' => $e->getMessage()]); + return redirect(admin_route('logistics.index'))->withErrors(['error' => $e->getMessage()]); } } @@ -171,6 +172,8 @@ class LogisticsController extends Controller // 获取 $countryIds = (array)explode(',',$logistics->country_ids); $logistics->country_ids = CountryRepo::getInList($countryIds); + $logistics->logistics_weights = LogisticsWeight::getList($logistics->id); + $data = [ 'logistics' => $logistics, 'types' => $types, diff --git a/beike/Admin/Services/LogisticsService.php b/beike/Admin/Services/LogisticsService.php index 30d035da..b44b0cfd 100644 --- a/beike/Admin/Services/LogisticsService.php +++ b/beike/Admin/Services/LogisticsService.php @@ -3,6 +3,7 @@ namespace Beike\Admin\Services; use Beike\Models\Logistics; +use Beike\Models\LogisticsWeight; use Beike\Models\Product; use Illuminate\Support\Facades\DB; @@ -67,6 +68,23 @@ class LogisticsService $logistics->save(); if ($isUpdating) {} + // 续重范围处理 + $continuationWeightList = (array) ($data['continuation_weight_list'] ? : []); + if(count($continuationWeightList)){ + $logisticsId = $logistics->id; + $newWeightList = array_filter(array_map(function($item) use ($logisticsId){ + if($item['max'] > 0){ + $item['logistics_id'] = $logisticsId; + + return $item; + } + return []; + },$continuationWeightList)); + // 删除旧数据 + LogisticsWeight::query()->where('logistics_id',$logisticsId)->delete(); + // 添加新数据 + LogisticsWeight::query()->insert($newWeightList); + } DB::commit(); diff --git a/beike/Models/LogisticsWeight.php b/beike/Models/LogisticsWeight.php new file mode 100644 index 00000000..9d85599f --- /dev/null +++ b/beike/Models/LogisticsWeight.php @@ -0,0 +1,37 @@ +where('logistics_id',$logisticsId)->orderBy('id','asc')->get(); + + return $list ? $list->toArray() : []; + } + + + + + + + + +} 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 cae8fd36..d4e10579 100644 --- a/resources/beike/admin/views/pages/logistics/form/form.blade.php +++ b/resources/beike/admin/views/pages/logistics/form/form.blade.php @@ -154,15 +154,44 @@ :value="old('add_weight', $logistics->add_weight ?? '')" step="any" required> {{ __('admin/logistics.unit',['unit'=>__('product.g')]) }} - - {{ __('admin/logistics.unit',['unit'=>'USD']) }} - - + + {{ __('admin/logistics.unit',['unit'=>'USD']) }} + {{-- 续重范围 START --------------------------------------------------------}} + + {{--续重范围列表--}} + + + - + + {{ __('product.g') }} + + + + + + + {{--续重范围添加--}} + + + + + {{-- 续重范围 END --------------------------------------------------------}} + + + {{-- --}} @@ -177,11 +206,11 @@ {{-- --}} - + - - - {{ __('admin/logistics.work_day') }} + - + {{ __('admin/logistics.work_day') }} @@ -272,6 +301,8 @@ rules: {}, // 已选择国家列表 country_list: @json($logistics->country_ids ?? []), + // 续重范围 + continuation_weight_list: @json($logistics->logistics_weights ?? []), }, computed: { // variant value 重复次数 @@ -688,7 +719,34 @@ // 国家信息改变 changeCountry(info){ this.country_list = info; + }, + // 续重范围 - 添加续重范围信息 + continuationWeightAdd(){ + let _this = this; + let weightList = Object.assign({}, _this.continuation_weight_list); + let length = Object.values(weightList).length || 0; + weightList[length] = { + min: 0, + max: 0 + }; + + _this.continuation_weight_list = Object.values(weightList); + }, + // 续重范围 - 续重范围改变 + continuationWeightChange(e,field = 'min',cwIndex = 0){ + let value = e.currentTarget.value || e.target.value; + this.continuation_weight_list[cwIndex][field] = value || 0; + }, + // 续重范围 - 删除续重范围 + continuationWeightRemove(cwIndex){ + let _this = this; + let weightList = Object.assign({}, _this.continuation_weight_list); + delete weightList[cwIndex]; + + _this.continuation_weight_list = Object.values(weightList); } + + } });