调整运费service
parent
af83424a01
commit
2973e703d5
|
|
@ -11,16 +11,19 @@ class ShippingService
|
||||||
* 运费模板根据地址,重量, 商品金额 计算运费; 重量传g,金额传分
|
* 运费模板根据地址,重量, 商品金额 计算运费; 重量传g,金额传分
|
||||||
*
|
*
|
||||||
* @param integer $weight
|
* @param integer $weight
|
||||||
|
* @param integer $totalAmount
|
||||||
* @param integer $templateId
|
* @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;
|
$shipping_amount = 0;
|
||||||
$canShipping = true;//是否支持寄送
|
$canShipping = true;//是否支持寄送
|
||||||
|
|
||||||
//如果该模板下无运费规则,则直接包邮
|
//如果该模板下无运费规则,则直接包邮
|
||||||
if (ShippingRule::where('template_id', $templateId)->count() > 0) {
|
if (ShippingRule::where('template_id', $templateId)->count() > 0) {
|
||||||
|
$canShipping = false;
|
||||||
//只拿有这个地区配置的模板规则,减少sql查询市区数量
|
//只拿有这个地区配置的模板规则,减少sql查询市区数量
|
||||||
$rules = ShippingRule::with('zones')->where('template_id', $templateId)->whereHas('zones', function ($q) use ($zoneId) {
|
$rules = ShippingRule::with('zones')->where('template_id', $templateId)->whereHas('zones', function ($q) use ($zoneId) {
|
||||||
return $q->where('zones.id', $zoneId);
|
return $q->where('zones.id', $zoneId);
|
||||||
|
|
@ -28,10 +31,7 @@ class ShippingService
|
||||||
//按包邮/计重
|
//按包邮/计重
|
||||||
$rules = $rules->sortBy('type');//优先计算包邮
|
$rules = $rules->sortBy('type');//优先计算包邮
|
||||||
foreach ($rules as $rule) {
|
foreach ($rules as $rule) {
|
||||||
$canShipping = false;
|
|
||||||
$_ruleInfo = json_decode($rule->info, true);
|
$_ruleInfo = json_decode($rule->info, true);
|
||||||
|
|
||||||
// if (in_array($zoneId, $rule->zones->pluck('id')->toArray())) {
|
|
||||||
$canShipping = true;
|
$canShipping = true;
|
||||||
if ($rule->type == ShippingRule::TYPE_FREE) {
|
if ($rule->type == ShippingRule::TYPE_FREE) {
|
||||||
if ($totalAmount >= bcmul($_ruleInfo['threshold'], 100)) {//在包邮价格范围内
|
if ($totalAmount >= bcmul($_ruleInfo['threshold'], 100)) {//在包邮价格范围内
|
||||||
|
|
@ -51,25 +51,12 @@ class ShippingService
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$canShipping) {
|
if (!$canShipping) {
|
||||||
throw new BizException('当前选择的地址有部分商品不支持配送');
|
throw new BizException('当前选择的地址有部分商品不支持配送');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->returnAmount($shipping_amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 统一返回运费格式
|
|
||||||
*
|
|
||||||
* @param [type] $shipping_amount
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function returnAmount($shipping_amount)
|
|
||||||
{
|
|
||||||
return $shipping_amount;
|
return $shipping_amount;
|
||||||
// return bcdiv($shipping_amount, 100, 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue