DeductionSettingCollection.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2017/10/15
  6. * Time: 下午9:03
  7. */
  8. namespace app\frontend\modules\deduction;
  9. use Illuminate\Database\Eloquent\Collection;
  10. /**
  11. * 抵扣设置集合
  12. * Class DeductionSettingCollection
  13. * @package app\frontend\modules\deduction
  14. */
  15. abstract class DeductionSettingCollection extends Collection
  16. {
  17. /**
  18. * @return float
  19. */
  20. public function getImportantAndValidMaxFixedAmount()
  21. {
  22. // 获取抵扣设置集合中设置了抵扣金额的,权重最高的设置项
  23. /**
  24. * @var DeductionSettingInterface $deductionSetting
  25. */
  26. $priceProportion = 0;
  27. foreach ($this as $deductionSetting){
  28. if($deductionSetting->isMaxDisable()){
  29. $priceProportion = 0;
  30. break;
  31. }
  32. if($deductionSetting->getMaxFixedAmount() !== false){
  33. $priceProportion = $deductionSetting->getMaxFixedAmount();
  34. break;
  35. }
  36. }
  37. return $priceProportion;
  38. }
  39. /**
  40. * @return float
  41. */
  42. public function getImportantAndValidMaxPriceProportion()
  43. {
  44. // 找到抵扣设置集合中设置了价格比例的,权重最高的设置项
  45. $priceProportion = 0;
  46. foreach ($this as $deductionSetting){
  47. /**
  48. * @var DeductionSettingInterface $deductionSetting
  49. */
  50. if($deductionSetting->isMaxDisable()){
  51. $priceProportion = 0;
  52. break;
  53. }
  54. if($deductionSetting->getMaxPriceProportion() !== false){
  55. $priceProportion = $deductionSetting->getMaxPriceProportion();
  56. break;
  57. }
  58. }
  59. return $priceProportion;
  60. }
  61. public function getImportantAndValidMaxCalculationType(){
  62. $type = '';
  63. foreach ($this as $deductionSetting){
  64. /**
  65. * @var DeductionSettingInterface $deductionSetting
  66. */
  67. if($deductionSetting->isMaxDisable()){
  68. trace_log()->deduction("订单抵扣", "最大抵扣类型设置".get_class($deductionSetting)."禁用");
  69. break;
  70. }
  71. if($deductionSetting->getMaxDeductionType() !== false){
  72. trace_log()->deduction("订单抵扣", "最大抵扣类型设置".get_class($deductionSetting)."启用");
  73. $type = $deductionSetting->getMaxDeductionType();
  74. break;
  75. }
  76. }
  77. return $type;
  78. }
  79. /**
  80. * @return float
  81. */
  82. public function getImportantAndValidMinFixedAmount()
  83. {
  84. // 获取抵扣设置集合中设置了抵扣金额的,权重最高的设置项
  85. /**
  86. * @var DeductionSettingInterface $deductionSetting
  87. */
  88. $priceProportion = 0;
  89. foreach ($this as $deductionSetting){
  90. /**
  91. * @var DeductionSettingInterface $deductionSetting
  92. */
  93. if($deductionSetting->isMinDisable()){
  94. $priceProportion = 0;
  95. break;
  96. }
  97. if($deductionSetting->getMinFixedAmount() !== false){
  98. $priceProportion = $deductionSetting->getMinFixedAmount();
  99. break;
  100. }
  101. }
  102. return $priceProportion;
  103. }
  104. /**
  105. * @return float
  106. */
  107. public function getImportantAndValidMinPriceProportion()
  108. {
  109. // 找到抵扣设置集合中设置了价格比例的,权重最高的设置项
  110. $priceProportion = 0;
  111. foreach ($this as $deductionSetting){
  112. /**
  113. * @var DeductionSettingInterface $deductionSetting
  114. */
  115. if($deductionSetting->isMinDisable()){
  116. $priceProportion = 0;
  117. break;
  118. }
  119. if($deductionSetting->getMinPriceProportion() !== false){
  120. $priceProportion = $deductionSetting->getMinPriceProportion();
  121. break;
  122. }
  123. }
  124. return $priceProportion;
  125. }
  126. public function getImportantAndValidMinCalculationType(){
  127. $type = '';
  128. foreach ($this as $deductionSetting){
  129. /**
  130. * @var DeductionSettingInterface $deductionSetting
  131. */
  132. if($deductionSetting->isMinDisable()){
  133. break;
  134. }
  135. if($deductionSetting->getMinDeductionType() !== false){
  136. $type = $deductionSetting->getMinDeductionType();
  137. trace_log()->deduction("订单抵扣",'抵扣设置使用'.get_class($deductionSetting));
  138. break;
  139. }
  140. }
  141. return $type;
  142. }
  143. public function getDeductionAmountType(){
  144. $type = '';
  145. foreach ($this as $deductionSetting){
  146. /**
  147. * @var DeductionSettingInterface $deductionSetting
  148. */
  149. if($deductionSetting->getDeductionAmountType() !== false){
  150. $type = $deductionSetting->getDeductionAmountType();
  151. break;
  152. }
  153. }
  154. return $type;
  155. }
  156. /**
  157. * todo 运费抵扣应该单独提取出去
  158. * @return bool|string
  159. */
  160. public function isEnableDeductDispatchPrice(){
  161. $type = '';
  162. foreach ($this as $deductionSetting){
  163. /**
  164. * @var DeductionSettingInterface $deductionSetting
  165. */
  166. if($deductionSetting->isDispatchDisable()){
  167. break;
  168. }
  169. if($deductionSetting->isEnableDeductDispatchPrice() !== false){
  170. $type = $deductionSetting->isEnableDeductDispatchPrice();
  171. break;
  172. }
  173. }
  174. return $type;
  175. }
  176. public function getAffectDeductionAmount()
  177. {
  178. $type = '';
  179. foreach ($this as $deductionSetting){
  180. /**
  181. * @var DeductionSettingInterface $deductionSetting
  182. */
  183. if($deductionSetting->getAffectDeductionAmount() !== false){
  184. $type = $deductionSetting->getAffectDeductionAmount();
  185. break;
  186. }
  187. }
  188. return $type;
  189. }
  190. }