【发布时间】:2021-07-04 02:04:10
【问题描述】:
我正在尝试做的是一个附属计划,我希望当我调用一个范围时,它会返回我想要的所有值。将有一个计算平台、卖家和附属公司价值的逻辑。
我已经拥有的是:
public function scopeProfitPlatform($query) {
return $query->sum('price')*0.6;
}
public function scopeProfitAffiliate($query) {
return $query->sum('price')*0.05;
}
public function scopeProfitBuyer($query) {
return $query->sum('price')*0.35;
}
这可行,但我想让它更简单。因此,我不想调用 Order::profitplatform() and order::profitaffiliate, etc....,而是想调用 Order::profit(),它会一次性将所有这些值返回给我。
我尝试使用 Order::profitplatform()->profitaffiliate() 但它不起作用。
我正在考虑为此目的创建一个特定的服务,但我认为没有必要。我认为可以使用范围或其他类似的东西,但是我没有找到解决方案。
感谢任何简化此问题的建议、想法和解决方案。谢谢。
【问题讨论】:
-
这更像是一个代码审查问题。
标签: php mysql laravel model affiliate