您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProducerPriceRangeRepository.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace common\logic\Producer\ProducerPriceRange\Repository;
  3. use common\helpers\Price;
  4. use common\logic\AbstractRepository;
  5. use common\logic\Producer\ProducerPriceRange\Model\ProducerPriceRange;
  6. class ProducerPriceRangeRepository extends AbstractRepository
  7. {
  8. protected ProducerPriceRangeRepositoryQuery $query;
  9. public function loadDependencies(): void
  10. {
  11. $this->query = $this->loadService(ProducerPriceRangeRepositoryQuery::class);
  12. }
  13. /**
  14. * Retourne les options de base nécessaires à la fonction de recherche.
  15. *
  16. */
  17. public function getDefaultOptionsSearch(): array
  18. {
  19. return [
  20. 'with' => [],
  21. 'join_with' => [],
  22. 'orderby' => '',
  23. 'attribute_id_producer' => ''
  24. ];
  25. }
  26. public function findOneProducerPriceRangeById(int $id)
  27. {
  28. return ProducerPriceRange::searchOne([
  29. 'id' => $id
  30. ]);
  31. }
  32. public function queryProducerPriceRanges()
  33. {
  34. return ProducerPriceRange::find()->orderBy('range_begin ASC');
  35. }
  36. public function findProducerPriceRanges()
  37. {
  38. return $this->queryProducerPriceRanges()->all();
  39. }
  40. public function getAmountToBeBilledByTurnover(float $turnover = null, $format = false)
  41. {
  42. $amountToBeBilled = 0;
  43. $producerPriceRangeArray = $this->findProducerPriceRanges();
  44. foreach ($producerPriceRangeArray as $priceRange) {
  45. if ($turnover >= $priceRange->range_begin && $turnover < $priceRange->range_end) {
  46. $amountToBeBilled = $priceRange->price;
  47. }
  48. }
  49. if ($format) {
  50. return Price::format($amountToBeBilled, 0);
  51. } else {
  52. return $amountToBeBilled;
  53. }
  54. }
  55. }