master
cody 3 months ago
parent fd46bce8af
commit 200fdb5c5b

@ -178,12 +178,13 @@ class OrderItems extends SoftDeletesModel
} }
$this->factor_texts = $factor_texts; $this->factor_texts = $factor_texts;
// 标志变量:是否成功计算了管理费
$feeCalculated = false;
if (!$this->product) { if (!$this->product) {
// 没有 product 时设置默认值 // 没有 product 时设置默认值(不扣除管理费)
if (!isset($this->paramedic_total) || $this->paramedic_total === null) { $this->paramedic_total = $this->total ?? 0;
$this->paramedic_total = $this->total ?? 0; $this->fee = 0;
$this->fee = $this->fee ?? 0;
}
return $this; return $this;
} }
@ -205,21 +206,17 @@ class OrderItems extends SoftDeletesModel
} }
if (!$factor) { if (!$factor) {
// 找不到因子时设置默认值 // 找不到因子时设置默认值(不扣除管理费)
if (!isset($this->paramedic_total) || $this->paramedic_total === null) { $this->paramedic_total = $this->total ?? 0;
$this->paramedic_total = $this->total ?? 0; $this->fee = 0;
$this->fee = $this->fee ?? 0;
}
return $this; return $this;
} }
//todo:考虑不同项目的情况,目前是全部统一 //todo:考虑不同项目的情况,目前是全部统一
if (!$this->order) { if (!$this->order) {
// 没有 order 时设置默认值 // 没有 order 时设置默认值(不扣除管理费)
if (!isset($this->paramedic_total) || $this->paramedic_total === null) { $this->paramedic_total = $this->total ?? 0;
$this->paramedic_total = $this->total ?? 0; $this->fee = 0;
$this->fee = $this->fee ?? 0;
}
return $this; return $this;
} }
@ -237,16 +234,16 @@ class OrderItems extends SoftDeletesModel
$paramedic_total = $this->total - $fee; $paramedic_total = $this->total - $fee;
$this->paramedic_total = $paramedic_total; $this->paramedic_total = $paramedic_total;
$this->fee = $fee; $this->fee = $fee;
$feeCalculated = true;
break; break;
} }
// 兜底逻辑:如果 paramedic_total 没有被设置,使用默认值 // 兜底逻辑:如果管理费没有被计算(通常是 fee_type 不是 "factor" 的情况),使用默认值
// 这通常发生在没有 product、fee_type 不是 "factor"、找不到因子或没有 order 的情况下 if (!$feeCalculated) {
if (!isset($this->paramedic_total) || $this->paramedic_total === null) {
$this->paramedic_total = $this->total ?? 0; $this->paramedic_total = $this->total ?? 0;
$this->fee = $this->fee ?? 0; $this->fee = 0;
} }
return $this; return $this;
} }

Loading…
Cancel
Save