<?php
namespace Lm\Engine\EC\Entity;
use Lm\Engine\SokujitsuHassou\SokujitsuHassou;
use Lm\Engine\Tax\TaxRule;
use Lm\Engine\Zaiko\Entity\SkuExtended;
use Lm\Service\Cache\CacheService;
class SkuWithPrice extends SkuExtended
{
/**
* @var int キャンペーン価格(税込)
*/
protected $cpPriceInTax;
/**
* @var int 通常価格(税抜)
*/
protected $gpPriceExTax;
/**
* @var int 定価(税込)
*/
protected $gpTeikaInTax;
/**
* @var int 売価(税抜)
*/
protected $priceExTax;
/**
* @var int 売価(税込)
*/
protected $priceInTax;
/**
* @var int 希望小売価格(税込)
*/
protected $teikaInTax;
/**
* @var int 希望小売価格(税抜)
*/
protected $teikaExTax;
/**
* @var bool 即日発送可否
*/
protected $isSokujitsuHassouAvailable;
/**
* キャンペーン価格(税込)
*
* @return int|null
*/
public function getCpPriceInTax()
{
return self::intNullable($this->cpPriceInTax);
}
/**
* 通常価格(税抜)
*
* @return int|null
*/
public function getGpPriceExTax()
{
return self::intNullable($this->gpPriceExTax);
}
/**
* 定価(税込)
*
* @return int|null
*/
public function getGpTeikaInTax()
{
return self::intNullable($this->gpTeikaInTax);
}
/**
* 売価(税込)
*
* @return int
*/
public function getPriceInTax($datetime = null)
{
return self::compute($this->priceInTax, function () use ($datetime) {
//
if ($priceInTax = $this->getCpPriceInTax()) {
//
return $priceInTax;
} else if ($priceExTax = $this->getGpPriceExTax()) {
//
return TaxRule::toInTax($priceExTax, $datetime);
} else {
//
throw new \Exception('価格が取得出来ませんでした');
}
});
}
/**
* 売価(税抜)
*
* @return int
*/
public function getPriceExTax($datetime = null)
{
return self::compute($this->priceExTax, function () use ($datetime) {
//
if ($priceInTax = $this->getCpPriceInTax()) {
//
return TaxRule::toExTax($priceInTax);
} else if ($priceExTax = $this->getGpPriceExTax()) {
//
return $priceExTax;
} else {
//
throw new \Exception('価格が取得出来ませんでした');
}
});
}
/**
* 希望小売価格(税込)
*
* @return int
*/
public function getTeikaInTax($datetime = null)
{
return self::compute($this->teikaInTax, function () use ($datetime) {
//
$teikaInTax = $this->getGpTeikaInTax();
//
return $teikaInTax;
});
}
/**
* 希望小売価格(税抜)
*
* @return int
*/
public function getTeikaExTax($datetime = null)
{
return self::compute($this->teikaExTax, function () use ($datetime) {
//
$teikaInTax = $this->getGpTeikaInTax();
//
return TaxRule::toExTax($teikaInTax, $datetime);
});
}
/**
* @return bool
* @throws \Exception
*/
public function isSokujitsuHassouAvailable()
{
return self::compute($this->isSokujitsuHassouAvailable, function () {
//
return self::retrieveSokujitauHassouFlgByIdentifiers($this->getGoodsId(), $this->getGclId(), $this->getGpId());
});
}
/**
* @param $goodsId
* @param $janId
* @param $gclId
* @param $gpId
* @param $datetime
* @return SkuWithPrice[]
* @throws \Exception
*/
public static function getInstanceList($goodsId, $janId = null, $gclId = null, $gpId = null, $datetime = null)
{
//
$result = [];
//
$skuList = SkuExtended::getInstanceList($goodsId, $janId, $gclId, $gpId, $datetime);
//
foreach ($skuList as $sku) {
//
$result[] = SkuWithPrice::factory($sku);
}
//
return $result;
}
/**
* @param $goodsId
* @param $janId
* @param $gclId
* @param $gpId
* @param $datetime
* @return SkuWithPrice
* @throws \Exception
*/
public static function getInstance($goodsId, $janId = null, $gclId = null, $gpId = null, $datetime = null)
{
//
$sku = SkuWithPrice::factory(SkuExtended::getInstance($goodsId, $janId, $gclId, $gpId, $datetime));
//
return $sku;
}
/**
* @param int $goodsId
* @param int $gclId
* @param int $gpId
* @return bool
* @throws \Exception
*/
protected static function retrieveSokujitauHassouFlgByIdentifiers($goodsId, $gclId, $gpId)
{
//
$sokujitsuHassouFlgCache = CacheService::getCached(function () use ($goodsId) {
//
return (new SokujitsuHassou())
->check($goodsId, true)
;
});
//
if (!empty($sokujitsuHassouFlgCache) && isset($sokujitsuHassouFlgCache[$gclId]) && isset($sokujitsuHassouFlgCache[$gclId][$gpId])) {
//
return $sokujitsuHassouFlgCache[$gclId][$gpId] > SokujitsuHassou::FLG_NONE;
} else {
//
return false;
}
}
}