From 21c4390a8e48625e5a8080d055f85ce2838b85dc Mon Sep 17 00:00:00 2001 From: li kesong Date: Mon, 18 Apr 2022 23:53:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=95=86=E5=93=81=E6=AF=9B?= =?UTF-8?q?=E9=87=8D=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/v3/GoodsController.php | 1 + app/Models/v3/Goods.php | 24 +++++++++++++++++++- resources/lang/zh-CN/goods.php | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Admin/Controllers/v3/GoodsController.php b/app/Admin/Controllers/v3/GoodsController.php index aae6d3f..ec24b2a 100644 --- a/app/Admin/Controllers/v3/GoodsController.php +++ b/app/Admin/Controllers/v3/GoodsController.php @@ -232,6 +232,7 @@ class GoodsController extends AdminController $form->currency('vip_price')->required()->symbol('¥'); $form->currency('origin_shop_price')->required()->symbol('¥'); $form->text('goods_unit')->help('如:50克,100克,250克,500克,1000克,1500克等'); + $form->number('weight')->help('单位:克。商品毛重是指商品带包装的重量,主要用于计算快递配送费计算')->min(0)->rules('int|min:1', ['int' => '商品毛重必填'])->required(); $form->radio('is_infinite')->options(['关闭','开启'])->default(1); $form->number('inventory')->required()->attribute('min', 0)->default(1); $form->number('restrict_num')->attribute('min', 0)->default(0)->help('0表示不限购'); diff --git a/app/Models/v3/Goods.php b/app/Models/v3/Goods.php index f9c98be..b5e37f0 100644 --- a/app/Models/v3/Goods.php +++ b/app/Models/v3/Goods.php @@ -67,4 +67,26 @@ class Goods extends Model return $value; } } -} + + /** + * add:2022-04-11,获取产品毛重,主要用于计算顺丰运费 + */ + public function getWeightAttribute($value): int + { + if (empty($value) && !empty($this->attributes['goods_unit'])) { + $goods_unit = $this->attributes['goods_unit']; + switch (true) { + case preg_match('/(\d{2,})\D*±(\d{2,})/', $goods_unit, $matches): + array_shift($matches); + $value = (int)max($matches); + break; + case preg_match_all('/(\d{2,})[g|克]/', $goods_unit, $matches): + $value = (int)max($matches[1]); + break; + default: + $value = 0; + } + } + return $value ?: 0; + } +} \ No newline at end of file diff --git a/resources/lang/zh-CN/goods.php b/resources/lang/zh-CN/goods.php index 7954386..a724abd 100644 --- a/resources/lang/zh-CN/goods.php +++ b/resources/lang/zh-CN/goods.php @@ -27,6 +27,7 @@ return [ 'is_infinite' => '开启无限库存', 'is_infinite_text' => '开启无限库存', 'goods_unit' => '商品单位', + 'weight' => '商品毛重', 'tags' => '标签', 'details_imgs' => '详情图片', 'spec' => '规格',