| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shenyang
- * Date: 2017/10/15
- * Time: 下午9:03
- */
- namespace app\frontend\modules\deduction;
- use Illuminate\Database\Eloquent\Collection;
- /**
- * 抵扣设置集合
- * Class DeductionSettingCollection
- * @package app\frontend\modules\deduction
- */
- abstract class DeductionSettingCollection extends Collection
- {
- /**
- * @return float
- */
- public function getImportantAndValidMaxFixedAmount()
- {
- // 获取抵扣设置集合中设置了抵扣金额的,权重最高的设置项
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- $priceProportion = 0;
- foreach ($this as $deductionSetting){
- if($deductionSetting->isMaxDisable()){
- $priceProportion = 0;
- break;
- }
- if($deductionSetting->getMaxFixedAmount() !== false){
- $priceProportion = $deductionSetting->getMaxFixedAmount();
- break;
- }
- }
- return $priceProportion;
- }
- /**
- * @return float
- */
- public function getImportantAndValidMaxPriceProportion()
- {
- // 找到抵扣设置集合中设置了价格比例的,权重最高的设置项
- $priceProportion = 0;
- foreach ($this as $deductionSetting){
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- if($deductionSetting->isMaxDisable()){
- $priceProportion = 0;
- break;
- }
- if($deductionSetting->getMaxPriceProportion() !== false){
- $priceProportion = $deductionSetting->getMaxPriceProportion();
- break;
- }
- }
- return $priceProportion;
- }
- public function getImportantAndValidMaxCalculationType(){
- $type = '';
- foreach ($this as $deductionSetting){
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- if($deductionSetting->isMaxDisable()){
- trace_log()->deduction("订单抵扣", "最大抵扣类型设置".get_class($deductionSetting)."禁用");
- break;
- }
- if($deductionSetting->getMaxDeductionType() !== false){
- trace_log()->deduction("订单抵扣", "最大抵扣类型设置".get_class($deductionSetting)."启用");
- $type = $deductionSetting->getMaxDeductionType();
- break;
- }
- }
- return $type;
- }
- /**
- * @return float
- */
- public function getImportantAndValidMinFixedAmount()
- {
- // 获取抵扣设置集合中设置了抵扣金额的,权重最高的设置项
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- $priceProportion = 0;
- foreach ($this as $deductionSetting){
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- if($deductionSetting->isMinDisable()){
- $priceProportion = 0;
- break;
- }
- if($deductionSetting->getMinFixedAmount() !== false){
- $priceProportion = $deductionSetting->getMinFixedAmount();
- break;
- }
- }
- return $priceProportion;
- }
- /**
- * @return float
- */
- public function getImportantAndValidMinPriceProportion()
- {
- // 找到抵扣设置集合中设置了价格比例的,权重最高的设置项
- $priceProportion = 0;
- foreach ($this as $deductionSetting){
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- if($deductionSetting->isMinDisable()){
- $priceProportion = 0;
- break;
- }
- if($deductionSetting->getMinPriceProportion() !== false){
- $priceProportion = $deductionSetting->getMinPriceProportion();
- break;
- }
- }
- return $priceProportion;
- }
- public function getImportantAndValidMinCalculationType(){
- $type = '';
- foreach ($this as $deductionSetting){
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- if($deductionSetting->isMinDisable()){
- break;
- }
- if($deductionSetting->getMinDeductionType() !== false){
- $type = $deductionSetting->getMinDeductionType();
- trace_log()->deduction("订单抵扣",'抵扣设置使用'.get_class($deductionSetting));
- break;
- }
- }
- return $type;
- }
- public function getDeductionAmountType(){
- $type = '';
- foreach ($this as $deductionSetting){
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- if($deductionSetting->getDeductionAmountType() !== false){
- $type = $deductionSetting->getDeductionAmountType();
- break;
- }
- }
- return $type;
- }
- /**
- * todo 运费抵扣应该单独提取出去
- * @return bool|string
- */
- public function isEnableDeductDispatchPrice(){
- $type = '';
- foreach ($this as $deductionSetting){
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- if($deductionSetting->isDispatchDisable()){
- break;
- }
- if($deductionSetting->isEnableDeductDispatchPrice() !== false){
- $type = $deductionSetting->isEnableDeductDispatchPrice();
- break;
- }
- }
- return $type;
- }
- public function getAffectDeductionAmount()
- {
- $type = '';
- foreach ($this as $deductionSetting){
- /**
- * @var DeductionSettingInterface $deductionSetting
- */
- if($deductionSetting->getAffectDeductionAmount() !== false){
- $type = $deductionSetting->getAffectDeductionAmount();
- break;
- }
- }
- return $type;
- }
- }
|