src/Entity/Otpusk/PriceIndex.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Otpusk;
  3. use Doctrine\ORM\EntityNotFoundException;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Twig\Error\RuntimeError;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\Otpusk\PriceIndexRepository")
  8.  *
  9.  * @ORM\Table(
  10.  *     name="priceIndex",
  11.  *     indexes={
  12.  *         @ORM\Index(name="id", columns={"rec_id", "price", "offerId"}),
  13.  *         @ORM\Index(name="best", columns={"best"}),
  14.  *         @ORM\Index(name="id_date", columns={"rec_id", "date"}),
  15.  *         @ORM\Index(name="type_price", columns={"type", "price"}),
  16.  *         @ORM\Index(name="countryId", columns={"countryId", "date"}),
  17.  *         @ORM\Index(name="cityId", columns={"cityId", "date"}),
  18.  *         @ORM\Index(name="offerId", columns={"offerId"}),
  19.  *         @ORM\Index(name="rec_id", columns={"rec_id", "type", "from"}),
  20.  *         @ORM\Index(name="transport", columns={"rec_id", "fromCityId", "transport"}),
  21.  *         @ORM\Index(name="operatorId", columns={"operatorId", "countryId", "date"}),
  22.  *         @ORM\Index(name="vrein_testible_combined_1", columns={"countryId", "price", "date", "transport", "fromCityId", "priceUah"}),
  23.  *         @ORM\Index(name="vrein_testible_combined_2", columns={"cityId", "rec_id", "date"})
  24.  *     },
  25.  * )
  26.  */
  27. class PriceIndex
  28. {
  29.     /**
  30.      * @var int
  31.      *
  32.      * @ORM\Column(name="num", type="integer", nullable=false, options={"unsigned"=true})
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue(strategy="IDENTITY")
  35.      */
  36.     private $num;
  37.     /**
  38.      * @ORM\Column (name="rec_id", type="integer", options={"unsigned":true, "comment":"Страна-Курорт-Отель"}, nullable=false)
  39.      */
  40.     private $idCostil;
  41.     //@ORM\JoinColumn(name="rec_id", referencedColumnName="id", columnDefinition="INT UNSIGNED NOT NULL COMMENT 'Страна-Курорт-Отель'")
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\HotelsRCache")
  44.      * @ORM\JoinColumn(name="rec_id", referencedColumnName="id")
  45.      */
  46.     private $id;
  47.     /**
  48.      * Virtual field to connect priceIndex with tHotels
  49.      * @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\Hotel", inversedBy="priceIndex")
  50.      * @ORM\JoinColumn(name="rec_id", referencedColumnName="rec_id")
  51.      */
  52.     private $hotel;
  53.     /**
  54.      * @ORM\Column(name="type", type="priceIndexType", nullable=false, options={"default"="hotel"})
  55.      */
  56.     private $type;
  57.     /**
  58.      * @ORM\Column (name="countryId", type="integer", options={"unsigned":true}, nullable=false)
  59.      */
  60.     private $countryCostil;
  61.     //@ORM\JoinColumn(name="countryId", referencedColumnName="rec_id", nullable=false, columnDefinition="INT UNSIGNED NOT NULL")
  62.     /**
  63.      * @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\Country", cascade={"persist"})
  64.      * @ORM\JoinColumn(name="countryId", referencedColumnName="rec_id", nullable=false)
  65.      */
  66.     private $country;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\City", inversedBy="priceIndex", cascade={"persist"})
  69.      * @ORM\JoinColumn(name="cityId", referencedColumnName="rec_id", nullable=false, columnDefinition="INT UNSIGNED NOT NULL")
  70.      */
  71.     private $city;
  72. //    /**
  73. //     * @ORM\Id()
  74. //     * @ORM\GeneratedValue(strategy="NONE")
  75. //     * @ORM\Column(name="offerId")
  76. //     */
  77. //    private $offerId;
  78.     /**
  79.      * @var string
  80.      *
  81.      * @ORM\Column(name="offerId", type="string", length=25, nullable=false, options={"comment"="номер цены"})
  82.      */
  83.     private $offerId;
  84.     /**
  85.      * @ORM\Column(name="from", type="smallint", nullable=false, options={"unsigned"=true,"comment"="страна отправления"})
  86.      */
  87.     private $fromCountry;
  88.     /**
  89.      * @ORM\Column(type="decimal", precision=14, scale=2, nullable=false, options={"comment"="минимальная, с длительностью 6-10"})
  90.      */
  91.     private $price;
  92.     /**
  93.      * @ORM\Column(type="string", type="priceIndexCurrency")
  94.      */
  95.     private $currency;
  96.     /**
  97.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в грн. по курсу оператора"})
  98.      */
  99.     private $priceUah;
  100.     /**
  101.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в usd по курсу оператора"})
  102.      */
  103.     private $priceUsd;
  104.     /**
  105.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в eur по курсу оператора"})
  106.      */
  107.     private $priceEur;
  108.     /**
  109.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в mdl по курсу оператора"})
  110.      */
  111.     private $priceMdl;
  112.     /**
  113.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в uzs по курсу оператора"})
  114.      */
  115.     private $priceUzs;
  116.     /**
  117.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в pln по курсу оператора"})
  118.      */
  119.     private $pricePln;
  120.     /**
  121.      * @ORM\Column(type="date", nullable=false, options={"comment"="дата цены"})
  122.      */
  123.     private $date;
  124.     /**
  125.      * @ORM\Column(type="integer", nullable=false, options={"comment"="минимальная длительность !=0"})
  126.      */
  127.     private $length;
  128.     /**
  129.      * @ORM\Column(type="string", length=8, nullable=false, options={"comment"="необходим для установления приоритетов по цене"})
  130.      */
  131.     private $transport;
  132.     /**
  133.      * @ORM\Column(type="string", length=3, nullable=false, options={"comment"="питание"})
  134.      */
  135.     private $food;
  136.     /**
  137.      * @ORM\Column(type="string", length=32, nullable=false, options={"comment"="номер"})
  138.      */
  139.     private $room;
  140.     /**
  141.      * @ORM\Column(name="best", type="integer", nullable=true, options={"comment"="Лучшая-цена качество"})
  142.      */
  143.     private $best;
  144.     /**
  145.      * @ORM\Column(type="datetime", nullable=false, options={"comment"="дата последнего обновления"})
  146.      */
  147.     private $last;
  148.     /**
  149.      * @ORM\Column (name="fromCityId", type="integer", options={"unsigned":true,"default":1544,"comment":"город отправления"}, nullable=false)
  150.      */
  151.     private $fromCityCostil;
  152.     //@ORM\JoinColumn(name="fromCityId", referencedColumnName="rec_id", nullable=false, columnDefinition="INT UNSIGNED DEFAULT 1544 NOT NULL COMMENT 'город отправления'")
  153.     /**
  154.      * @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\City", cascade={"persist"})
  155.      * @ORM\JoinColumn(name="fromCityId", referencedColumnName="rec_id", nullable=false)
  156.      */
  157.     private $fromCity;
  158.     /**
  159.      * @ORM\ManyToOne(targetEntity="App\Entity\Otpusk\ExchangeRate", cascade={"persist"})
  160.      * @ORM\JoinColumn(name="currency", referencedColumnName="id")
  161.      */
  162.     private $exchange;
  163.     /**
  164.      * @var int
  165.      *
  166.      * @ORM\Column(name="operatorId", type="integer", nullable=false, options={"unsigned"=true})
  167.      */
  168.     private $operatorid;
  169.     /**
  170.      * @var string
  171.      *
  172.      * @ORM\Column(name="inf", type="text", length=65535, nullable=true, options={"comment"="формула"})
  173.      */
  174.     private $inf;
  175.     /**
  176.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в kzt по курсу оператора"})
  177.      */
  178.     private $priceKzt;
  179.     /**
  180.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в czk по курсу оператора"})
  181.      */
  182.     private $priceCzk;
  183.     /**
  184.      * @ORM\Column(type="decimal", precision=12, scale=2, nullable=false, options={"comment"="цена в huf по курсу оператора"})
  185.      */
  186.     private $priceHuf;
  187.     public function __toString()
  188.     {
  189.         return 'Предложение ' $this->getOfferId();
  190.     }
  191.     public function getId()
  192.     {
  193.         try{
  194.             return $this->id;
  195.         } catch (EntityNotFoundException $e){
  196.             return '';
  197.         } catch (RuntimeError $e){
  198.             return '';
  199.         }
  200.     }
  201.     public function getType(): ?string
  202.     {
  203.         return $this->type;
  204.     }
  205.     public function setType(string $type): self
  206.     {
  207.         $this->type $type;
  208.         return $this;
  209.     }
  210.     public function getCountry(): ?Country
  211.     {
  212.         return $this->country;
  213.     }
  214.     public function setCountry(?Country $country): self
  215.     {
  216.         $this->country $country;
  217.         return $this;
  218.     }
  219.     public function getCity(): ?City
  220.     {
  221.         return $this->city;
  222.     }
  223.     public function setCity(?City $city): self
  224.     {
  225.         $this->city $city;
  226.         return $this;
  227.     }
  228.     public function getOfferId(): ?int
  229.     {
  230.         return $this->offerId;
  231.     }
  232.     public function setOfferId(int $offerId): self
  233.     {
  234.         $this->offerId $offerId;
  235.         return $this;
  236.     }
  237.     public function getFromCountry(): ?Country
  238.     {
  239.         return $this->fromCountry;
  240.     }
  241.     public function setFromCountry(?Country $fromCountry): self
  242.     {
  243.         $this->fromCountry $fromCountry;
  244.         return $this;
  245.     }
  246.     public function getPrice(): ?float
  247.     {
  248.         return $this->price;
  249.     }
  250.     public function setPrice(float $price): self
  251.     {
  252.         $this->price $price;
  253.         return $this;
  254.     }
  255.     public function getCurrency(): ?string
  256.     {
  257.         return $this->currency;
  258.     }
  259.     public function setCurrency(string $currency): self
  260.     {
  261.         $this->currency $currency;
  262.         return $this;
  263.     }
  264.     public function getPriceUah(): ?float
  265.     {
  266.         return $this->priceUah;
  267.     }
  268.     public function setPriceUah(float $priceUah): self
  269.     {
  270.         $this->priceUah $priceUah;
  271.         return $this;
  272.     }
  273.     public function getPriceUsd(): ?float
  274.     {
  275.         return $this->priceUsd;
  276.     }
  277.     public function setPriceUsd(float $priceUsd): self
  278.     {
  279.         $this->priceUsd $priceUsd;
  280.         return $this;
  281.     }
  282.     public function getPriceEur(): ?float
  283.     {
  284.         return $this->priceEur;
  285.     }
  286.     public function setPriceEur(float $priceEur): self
  287.     {
  288.         $this->priceEur $priceEur;
  289.         return $this;
  290.     }
  291.     public function getPriceMdl(): ?float
  292.     {
  293.         return $this->priceMdl;
  294.     }
  295.     public function setPriceMdl(float $priceMdl): self
  296.     {
  297.         $this->priceMdl $priceMdl;
  298.         return $this;
  299.     }
  300.     public function getPriceUzs(): ?float
  301.     {
  302.         return $this->priceUzs;
  303.     }
  304.     public function setPriceUzs(float $priceUzs): self
  305.     {
  306.         $this->priceUzs $priceUzs;
  307.         return $this;
  308.     }
  309.     public function getPricePln(): ?float
  310.     {
  311.         return $this->pricePln;
  312.     }
  313.     public function setPricePln(float $pricePln): self
  314.     {
  315.         $this->pricePln $pricePln;
  316.         return $this;
  317.     }
  318.     public function getDate(): ?\DateTimeInterface
  319.     {
  320.         return $this->date;
  321.     }
  322.     public function setDate(\DateTimeInterface $date): self
  323.     {
  324.         $this->date $date;
  325.         return $this;
  326.     }
  327.     public function getLength(): ?int
  328.     {
  329.         return $this->length;
  330.     }
  331.     public function setLength(int $length): self
  332.     {
  333.         $this->length $length;
  334.         return $this;
  335.     }
  336.     public function getTransport(): ?string
  337.     {
  338.         return $this->transport;
  339.     }
  340.     public function setTransport(string $transport): self
  341.     {
  342.         $this->transport $transport;
  343.         return $this;
  344.     }
  345.     public function getFood(): ?string
  346.     {
  347.         switch ($this->food){
  348.             case 'ro':
  349.             case 'ob':
  350.             case 'ao':
  351.                 return 'Без питания';
  352.             case 'bb':
  353.                 return 'Завтраки';
  354.             case 'hb':
  355.                 return 'Полупансион (завтрак + ужин)';
  356.             case 'hb+':
  357.                 return 'Полупансион +';
  358.             case 'fb':
  359.                 return 'Полный пансион';
  360.             case 'fb+':
  361.                 return 'Полный пансион +';
  362.             case 'ai':
  363.                 return 'Всё включено';
  364.             case 'uai':
  365.                 return 'Ультра всё включено';
  366.             default:
  367.                 return 'Питание не определено';
  368.         }
  369.     }
  370.     public function setFood(string $food): self
  371.     {
  372.         $this->food $food;
  373.         return $this;
  374.     }
  375.     public function getRoom(): ?string
  376.     {
  377.         return $this->room;
  378.     }
  379.     public function setRoom(string $room): self
  380.     {
  381.         $this->room $room;
  382.         return $this;
  383.     }
  384.     public function getBest(): ?int
  385.     {
  386.         return $this->best;
  387.     }
  388.     public function setBest(int $best): self
  389.     {
  390.         $this->best $best;
  391.         return $this;
  392.     }
  393.     public function getLast(): ?\DateTimeInterface
  394.     {
  395.         return $this->last;
  396.     }
  397.     public function setLast(\DateTimeInterface $last): self
  398.     {
  399.         $this->last $last;
  400.         return $this;
  401.     }
  402.     public function getFromCity(): ?City
  403.     {
  404.         return $this->fromCity;
  405.     }
  406.     public function setFromCity(?City $fromCity): self
  407.     {
  408.         $this->fromCity $fromCity;
  409.         return $this;
  410.     }
  411.     public function getExchange(): ?ExchangeRate
  412.     {
  413.         return $this->exchange;
  414.     }
  415.     public function setExchange($exchange): self
  416.     {
  417.         $this->exchange $exchange;
  418.         return $this;
  419.     }
  420.     public function getDateString(): ?string
  421.     {
  422.         return $this->date->format('d.m.Y');
  423.     }
  424. //    public function getPriceUah()
  425. //    {
  426. //        return number_format(round($this->getPrice() * $this->exchange->getAsk(), 2), 2, ',', ' ');
  427. //    }
  428.     public function getOtpuskUrl()
  429.     {
  430.         return '<a href="https://www.otpusk.com/hotel/' $this->id->getId() . '-' $this->id->getHrefName() . '/' $this->offerId '" target="_blank">Отпуск URL</a>';
  431.     }
  432.     public function getCityWeightCurrent(): string
  433.     {
  434.         $month $this->date->format('n');
  435.         if($weights $this->city->getCitiesWeights()){
  436.             if(!is_null($weights->get($month 1)) && $weights->get($month 1)->getMonth() == $month)
  437.                 return $weights->get($month 1)->getWeight();
  438.             else{
  439.                 foreach ($weights as $index => $weight) {
  440.                     if($weight->getMonth() == $month)
  441.                         return $weight->getWeight();
  442.                 }
  443.             }
  444.         }
  445.         return '';
  446.     }
  447.     /**
  448.      *
  449.      * Get data for price-quality coefficient calculation
  450.      *
  451.      */
  452.     public function getCityWeightCurrentCoeff()
  453.     {
  454.         $weight $this->getCityWeightCurrent();
  455.         switch ($weight){
  456.             case 1:
  457.                 return 0.7;
  458.             case 2:
  459.                 return 1;
  460.             case 3:
  461.                 return 1.3;
  462.             case 0:
  463.             case "":
  464.             default:
  465.                 return 0.1;
  466.         }
  467.     }
  468.     public function getFoodCoeff()
  469.     {
  470.         switch ($this->getFood()){
  471.             case 'ro':
  472.             case 'ob':
  473.             case 'ao':
  474.                 return 0.6;
  475.             case 'bb':
  476.                 return 0.8;
  477.             case 'hb':
  478.                 return 1;
  479.             //case 'hb+':return 1.35;
  480.             case 'fb':
  481.                 return 1.2;
  482.             //case 'fb+': return 1.45;
  483.             case 'ai':
  484.                 return 1.5;
  485.             case 'uai':
  486.                 return 1.6;
  487.         }
  488.     }
  489.     public function getStarsCoeff()
  490.     {
  491.         switch ($this->id->getStars()){
  492.             case '1':
  493.                 return 1;
  494.             case '2':
  495.                 return 1.1;
  496.             case '3':
  497.                 return 1.2;
  498.             case '4':
  499.                 return 1.5;
  500.             case '4+':
  501.                 return 1.75;
  502.             case '5':
  503.                 return 2;
  504.             case '5+':
  505.                 return 2.15;
  506.         }
  507.     }
  508.     public function getLengthCoeff()
  509.     {
  510.         return $this->getLength();
  511.         return round($this->getLength() / 1503);
  512.     }
  513.     public function getRatingavgCoeff()
  514.     {
  515.         if (empty($this->id->getRatingAvg()) || (int)$this->id->getRatingAvg()<=0) return 0;
  516.         return $this->id->getRatingAvg();
  517.     }
  518.     public function getTransportCoeff()
  519.     {
  520.         switch ($this->transport){
  521.             case 'air':
  522.                 return 1.5;
  523.             case 'bus':
  524.                 return 1.2;
  525.             default:
  526.                 return 0.5;
  527.         }
  528.     }
  529.     public function getServicesLineText()
  530.     {
  531.         $services $this->id->getServices();
  532.         if(strpos($services'one_line_beach'))
  533.             return '1я линия пляжа';
  534.         elseif(strpos($services'two_line_beach'))
  535.             return '2я линия пляжа';
  536.         else
  537.             return '3я и далее линия пляжа';
  538.     }
  539.     public function getServicesLineTextCoeff()
  540.     {
  541.         $services $this->id->getServices();
  542.         if(strpos($services'one_line_beach'))
  543.             return 1.5;
  544.         elseif(strpos($services,'two_line_beach'))
  545.             return 1.2;
  546.         else
  547.             return 0.75;
  548.     }
  549.     public function getPriceCurr()
  550.     {
  551.         return $this->price ' ' strtoupper($this->currency);
  552.     }
  553.     public function bestFormula()
  554.     {
  555.         $food       $this->getFoodCoeff();
  556.         $stars      $this->getStarsCoeff();
  557.         $rating     $this->getRatingavgCoeff();
  558.         $weight     $this->getCityWeightCurrentCoeff();
  559.         $transport  $this->getTransportCoeff();
  560.         $line       $this->getServicesLineTextCoeff();
  561.         $uah        = (double) str_replace(',''.'str_replace(' '''$this->getPriceUah()));
  562.         return '( ( (1*'.$food.'/1.6*10) + (1*'.$transport.'/1.5*10) + (1.1*('.$rating.'*'.$rating.')/10) + (0.8*'.$weight.'/1.3*10) ) * '.$this->length.' * (1.2*'.$stars.'/2*10) * (0.9*'.$line.'/1.5*10) / '.$this->getPriceUah().' ) * 10 000 = '.round(( ( (1*($food/1.6)*10) + (1*($transport/1.5)*10) + (1.1*($rating*$rating/10)) + (0.8*($weight/1.3)*10) ) * $this->length * (1.2*($stars/2)*10) * (0.9*($line/1.5)*10) / $this->getPriceUah() ) * 10000);
  563.         return '(' $food ' * ' $stars ' * ' round(1+$this->length/1503)  . ' * ' $weight ' * ' $transport ' * ' $line' * (' . ($rating) . '/4) ) / ' $this->getPriceUah() . ' * 1 000 000 000 = ' round(($food $stars * (1+$this->length/150) * $weight $transport $line round($rating/4,3)) / $uah 10000000000);
  564.     }
  565.     public function getStarsImg()
  566.     {
  567.         try{
  568.             return str_repeat('☆', (int)$this->id->getStars());
  569.         } catch (EntityNotFoundException $e){
  570.             return '';
  571.         }catch (RuntimeError $e){
  572.             return '';
  573.         }
  574.     }
  575.     public function getRatingAvg()
  576.     {
  577.         try{
  578.             return $this->id->getRatingAvg();
  579.         } catch (EntityNotFoundException $e){
  580.              return '';
  581.         }catch (RuntimeError $e){
  582.             return '';
  583.         }
  584.     }
  585.     public function getPriceKzt(): ?string
  586.     {
  587.         return $this->priceKzt;
  588.     }
  589.     public function setPriceKzt(string $priceKzt): self
  590.     {
  591.         $this->priceKzt $priceKzt;
  592.         return $this;
  593.     }
  594.     public function getPriceCzk(): ?string
  595.     {
  596.         return $this->priceCzk;
  597.     }
  598.     public function setPriceCzk(string $priceCzk): self
  599.     {
  600.         $this->priceCzk $priceCzk;
  601.         return $this;
  602.     }
  603.     public function getPriceHuf(): ?string
  604.     {
  605.         return $this->priceHuf;
  606.     }
  607.     public function setPriceHuf(string $priceHuf): self
  608.     {
  609.         $this->priceHuf $priceHuf;
  610.         return $this;
  611.     }
  612. }