From 2973e703d5329b0e3d230a25eb729fe7c168a3cf Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 13 Dec 2021 17:52:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=BF=90=E8=B4=B9service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/ShippingService.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/app/Services/ShippingService.php b/app/Services/ShippingService.php index 3da9396c..f5adcc36 100644 --- a/app/Services/ShippingService.php +++ b/app/Services/ShippingService.php @@ -11,16 +11,19 @@ class ShippingService * 运费模板根据地址,重量, 商品金额 计算运费; 重量传g,金额传分 * * @param integer $weight + * @param integer $totalAmount * @param integer $templateId - * @return void + * @param integer $zoneId + * @return integer */ - public function countShippingAmount(int $weight, int $totalAmount, int $templateId, int $zoneId) + public function countShippingAmount(int $weight, int $totalAmount, int $templateId, int $zoneId): int { $shipping_amount = 0; $canShipping = true;//是否支持寄送 //如果该模板下无运费规则,则直接包邮 if (ShippingRule::where('template_id', $templateId)->count() > 0) { + $canShipping = false; //只拿有这个地区配置的模板规则,减少sql查询市区数量 $rules = ShippingRule::with('zones')->where('template_id', $templateId)->whereHas('zones', function ($q) use ($zoneId) { return $q->where('zones.id', $zoneId); @@ -28,10 +31,7 @@ class ShippingService //按包邮/计重 $rules = $rules->sortBy('type');//优先计算包邮 foreach ($rules as $rule) { - $canShipping = false; $_ruleInfo = json_decode($rule->info, true); - - // if (in_array($zoneId, $rule->zones->pluck('id')->toArray())) { $canShipping = true; if ($rule->type == ShippingRule::TYPE_FREE) { if ($totalAmount >= bcmul($_ruleInfo['threshold'], 100)) {//在包邮价格范围内 @@ -51,25 +51,12 @@ class ShippingService break; } } - // } } } if (!$canShipping) { throw new BizException('当前选择的地址有部分商品不支持配送'); } - return $this->returnAmount($shipping_amount); - } - - /** - * 统一返回运费格式 - * - * @param [type] $shipping_amount - * @return void - */ - protected function returnAmount($shipping_amount) - { return $shipping_amount; - // return bcdiv($shipping_amount, 100, 2); } }