vendor/lm/engine-zaiko/src/Yoyaku.php line 87

Open in your IDE?
  1. <?php
  2. namespace Lm\Engine\Zaiko;
  3. use Lm\Engine\Zaiko\Entity\SkuExtended;
  4. use Lm\Service\Db\SqlService;
  5. class Yoyaku
  6. {
  7.     /**
  8.      * 入荷予定日までの予約受付開始日数
  9.      */
  10.     const YOYAKU_AVAILABLE_SINCE_DAYS_AGO 180;
  11.     /**
  12.      * @param int $goodsId
  13.      * @param bool $isMatrix
  14.      * @param int $janId
  15.      * @param int $gpId
  16.      * @param int $gclId
  17.      * @param string $datetime
  18.      * @see Yoyaku::check()
  19.      * @deprecated use Yoyaku::check() instead.
  20.      * @return array|bool
  21.      */
  22.     public function check2($goodsId$isMatrix false$janId null$gpId null$gclId null$datetime null)
  23.     {
  24.         //
  25.         return self::check($goodsId$isMatrix$janId$gpId$gclId$datetime);
  26.     }
  27.     /**
  28.      * @param int $goodsId
  29.      * @param bool|false $isMatrix
  30.      * @param int|null $janId
  31.      * @param int|null $gpId
  32.      * @param int|null $gclId
  33.      * @param string|null $datetime
  34.      * @return array|false|mixed
  35.      */
  36.     public static function check($goodsId$isMatrix false$janId null$gpId null$gclId null$datetime null)
  37.     {
  38.         //
  39.         try {
  40.             //
  41.             $skuList SkuExtended::getInstanceList($goodsId$janId$gclId$gpId$datetime);
  42.         } catch (\Exception $e) {
  43.             //
  44.             return false;
  45.         }
  46.         //
  47.         $result = [];
  48.         $buffer = [];
  49.         //
  50.         foreach ($skuList as $sku) {
  51.             //
  52.             if (!isset($result[$sku->getGclId()])) {
  53.                 //
  54.                 $result[$sku->getGclId()] = [];
  55.             }
  56.             //
  57.             $result[$sku->getGclId()][$sku->getGpId()] = $buffer[] = $sku->getIsYoyakuAvailable() || $sku->getIsBichikuYoyakuAvailable();
  58.         }
  59.         //
  60.         if (!$isMatrix) {
  61.             //
  62.             $result = ($buffer array_filter($buffer, function ($_buffer) {
  63.                 //
  64.                 return !empty($_buffer);
  65.             })) ? max($buffer) : false;
  66.         }
  67.         //
  68.         return $result;
  69.     }
  70.     /**
  71.      * @param string $nyukaDate
  72.      * @param string|null $fromDate
  73.      * @param int|self::YOYAKU_AVAILABLE_SINCE_DAYS_AGO $yoyakuAvailableSinceDaysAgo
  74.      * @return bool
  75.      * @throws \Exception
  76.      */
  77.     public static function calculateIsYoyakuAvailable($nyukaDate$fromDate null$yoyakuAvailableSinceDaysAgo self::YOYAKU_AVAILABLE_SINCE_DAYS_AGO)
  78.     {
  79.         //
  80.         $date1 = new \DateTime($fromDate);
  81.         $date2 = new \DateTime($nyukaDate);
  82.         $diff $date1->diff($date2);
  83.         //
  84.         return $diff->days <= $yoyakuAvailableSinceDaysAgo;
  85.     }
  86. }