<?php
namespace Lm\Entity;
use Lm\Entity\Common\DbEntity;
use Lm\Service\Db\SqlService;
class Jancode extends DbEntity
{
/**
* @inheritDoc
*/
const TABLE_NAME = 'jancode_table';
/**
* @inheritDoc
*/
const COLUMNS = [
[
'name' => 'jan_id',
'type' => DbEntity::COLUMN_TYPE_INT, // { required: true }
'nullable' => false, // { required: false, default: true }
'default' => null, // { required: false, default: null }
'required' => true, // { required: false, default: true }
],
];
/**
* @inheritDoc
*/
const CONSTRAINTS = [
[
'type' => self::CONSTRAINT_TYPE_PRIMARY_KEY,
'columns' => [
'jan_id',
],
],
];
const STOCK_TYPE_BASE_STOCK = 'jan_stock';
const STOCK_TYPE_LM_BICHIKU_STOCK = 'jan_stock3';
const STOCK_TYPE_KEEP_STOCK = 'jan_stock4';
const STOCK_TYPE_SECRET_STOCK = 'jan_stock5';
const STOCK_TYPE_CHITOSE_LM_STOCK = 'jan_stock6';
const STOCK_TYPE_CHITOSE_KAITORI_STOCK = 'jan_stock7';
const STOCK_TYPE_CHITOSE_LM_BICHIKU_STOCK = 'jan_stock8';
const STOCK_TYPE_CHITOSE_EXTERNAL_STOCK = 'jan_stock9';
/**
* 返品不可フラグ - 返品不可でない
*/
const IS_RETURN_UNAVAILABLE_NO = 0;
/**
* 返品不可フラグ - 返品不可
*/
const IS_RETURN_UNAVAILABLE_YES = 1;
const STOCK_TYPE_LIST = [
[
'field' => self::STOCK_TYPE_LM_BICHIKU_STOCK,
'alias' => 'lm_stock',
'is_actual_stock' => true,
'is_base_stock' => false,
],
[
'field' => self::STOCK_TYPE_KEEP_STOCK,
'alias' => 'keep_stock',
'is_actual_stock' => false,
'is_base_stock' => false,
],
[
'field' => self::STOCK_TYPE_CHITOSE_LM_BICHIKU_STOCK,
'alias' => 'secret_stock4',
'is_actual_stock' => true,
'is_base_stock' => false,
],
[
'field' => self::STOCK_TYPE_CHITOSE_LM_STOCK,
'alias' => 'secret_stock2',
'is_actual_stock' => true,
'is_base_stock' => false,
],
[
'field' => self::STOCK_TYPE_CHITOSE_KAITORI_STOCK,
'alias' => 'secret_stock3',
'is_actual_stock' => true,
'is_base_stock' => false,
],
[
'field' => self::STOCK_TYPE_BASE_STOCK,
'alias' => 'base_stock',
'is_actual_stock' => true,
'is_base_stock' => true,
],
[
'field' => self::STOCK_TYPE_SECRET_STOCK,
'alias' => 'secret_stock',
'is_actual_stock' => false,
'is_base_stock' => false,
],
[
'field' => self::STOCK_TYPE_CHITOSE_EXTERNAL_STOCK,
'alias' => 'secret_stock5',
'is_actual_stock' => false,
'is_base_stock' => false,
],
];
/**
* @var int
*/
protected $janId;
/**
* @var string
*/
protected $janJancode;
/**
* @var string
*/
protected $janJancode2;
/**
* @var string
*/
protected $janJancode3;
/**
* @var string
*/
protected $janGoods;
/**
* @var string
*/
protected $janColor;
/**
* @var string
*/
protected $janPrice;
/**
* @var string
*/
protected $janDdate;
/**
* @var string
*/
protected $janShiireNo;
/**
* @var int
*/
protected $janStock;
/**
* @var int
*/
protected $janStock2;
/**
* @var int
*/
protected $janStock3;
/**
* @var int
*/
protected $janStock4;
/**
* @var int
*/
protected $janStock5;
/**
* @var int
*/
protected $janStock6;
/**
* @var int
*/
protected $janStock7;
/**
* @var int
*/
protected $janStock8;
/**
* @var int
*/
protected $janStock9;
/**
* @var string
*/
protected $janUdate;
/**
* @var int
*/
protected $janSpecialPrice;
/**
* @var string
*/
protected $janShiireColor;
/**
* @var string
*/
protected $janUniform1ColorNumber;
/**
* @var int
*/
protected $janNodisplay;
/**
* @var string
*/
protected $janShinmen;
/**
* @var string
*/
protected $janShiireSize;
/**
* @var string
*/
protected $janStock3NyukaDate;
/**
* @var int
*/
protected $janStock3NyukaSouko;
/**
* @var int
*/
protected $janReplicationFlg;
/**
* @var string
*/
protected $janReplicationSynchronizedAt;
/**
* @var int
*/
protected $janReturnUnavailableFlg;
/**
* @var Goods
*/
protected $goods;
/**
* @var GoodsColor
*/
protected $goodsColor;
/**
* @var GoodsPrice
*/
protected $goodsPrice;
/**
* @return int
*/
public function getJanId()
{
return self::intNullable($this->janId);
}
/**
* @return string
*/
public function getJanJancode()
{
return $this->janJancode;
}
/**
* @return string
*/
public function getJanJancode2()
{
return $this->janJancode2;
}
/**
* @return string
*/
public function getJanJancode3()
{
return $this->janJancode3;
}
/**
* @return int
*/
public function getJanGoods()
{
return self::intNullable($this->janGoods);
}
/**
* @return int
*/
public function getJanColor()
{
return self::intNullable($this->janColor);
}
/**
* @return int
*/
public function getJanPrice()
{
return self::intNullable($this->janPrice);
}
/**
* @return string
*/
public function getJanDdate()
{
return $this->janDdate;
}
/**
* @return string
*/
public function getJanShiireNo()
{
return $this->janShiireNo;
}
/**
* @return int
*/
public function getJanStock()
{
return self::intNullable($this->janStock);
}
/**
* @param int jJanStock $
* @return $this
*/
public function decrementJanStock($janStock)
{
//
if ($this->janStock === null) {
// no operation.
} else if ($this->janStock >= $janStock) {
$this->janStock -= $janStock;
} else {
$this->janStock = 0;
}
//
return $this;
}
/**
* @return int
*/
public function getJanStock2()
{
return self::intNullable($this->janStock2);
}
/**
* @param int $janStock2
* @return $this
*/
public function decrementJanStock2($janStock2)
{
//
if ($this->janStock2 === null) {
// no operation.
} else if ($this->janStock2 >= $janStock2) {
$this->janStock2 -= $janStock2;
} else {
$this->janStock2 = null;
}
//
return $this;
}
/**
* @return int
*/
public function getJanStock3()
{
return self::intNullable($this->janStock3);
}
/**
* @param int $janStock3
* @return $this
*/
public function decrementJanStock3($janStock3)
{
//
if ($this->janStock3 === null) {
// no operation.
} else if ($this->janStock3 >= $janStock3) {
$this->janStock3 -= $janStock3;
} else {
$this->janStock3 = null;
}
//
return $this;
}
/**
* @return int
*/
public function getJanStock4()
{
return self::intNullable($this->janStock4);
}
/**
* @param int $janStock4
* @return $this
*/
public function decrementJanStock4($janStock4)
{
//
if ($this->janStock4 === null) {
// no operation.
} else if ($this->janStock4 >= $janStock4) {
$this->janStock4 -= $janStock4;
} else {
$this->janStock4 = null;
}
//
return $this;
}
/**
* @return int
*/
public function getJanStock5()
{
return self::intNullable($this->janStock5);
}
/**
* @param int $janStock5
* @return $this
*/
public function decrementJanStock5($janStock5)
{
//
if ($this->janStock5 === null) {
// no operation.
} else if ($this->janStock5 >= $janStock5) {
$this->janStock5 -= $janStock5;
} else {
$this->janStock5 = null;
}
//
return $this;
}
/**
* @return int
*/
public function getJanStock6()
{
return self::intNullable($this->janStock6);
}
/**
* @param int $janStock6
* @return $this
*/
public function decrementJanStock6($janStock6)
{
//
if ($this->janStock6 === null) {
// no operation.
} else if ($this->janStock6 >= $janStock6) {
$this->janStock6 -= $janStock6;
} else {
$this->janStock6 = null;
}
//
return $this;
}
/**
* @return int
*/
public function getJanStock7()
{
return self::intNullable($this->janStock7);
}
/**
* @param int $janStock7
* @return $this
*/
public function decrementJanStock7($janStock7)
{
//
if ($this->janStock7 === null) {
// no operation.
} else if ($this->janStock7 >= $janStock7) {
$this->janStock7 -= $janStock7;
} else {
$this->janStock7 = null;
}
//
return $this;
}
/**
* @return int
*/
public function getJanStock8()
{
return self::intNullable($this->janStock8);
}
/**
* @param int $janStock8
* @return $this
*/
public function decrementJanStock8($janStock8)
{
//
if ($this->janStock8 === null) {
// no operation.
} else if ($this->janStock8 >= $janStock8) {
$this->janStock8 -= $janStock8;
} else {
$this->janStock8 = null;
}
//
return $this;
}
/**
* @return int
*/
public function getJanStock9()
{
return self::intNullable($this->janStock9);
}
/**
* @param int $janStock9
* @return $this
*/
public function decrementJanStock9($janStock9)
{
//
if ($this->janStock9 === null) {
// no operation.
} else if ($this->janStock9 >= $janStock9) {
$this->janStock9 -= $janStock9;
} else {
$this->janStock9 = null;
}
//
return $this;
}
/**
* @return string
*/
public function getJanUdate()
{
return $this->janUdate;
}
/**
* @return int
*/
public function getJanSpecialPrice()
{
return self::intNullable($this->janSpecialPrice);
}
/**
* @return string
*/
public function getJanShiireColor()
{
return $this->janShiireColor;
}
/**
* @return string
*/
public function getJanUniform1ColorNumber()
{
return $this->janUniform1ColorNumber;
}
/**
* @return int
*/
public function getJanNodisplay()
{
return self::intNullable($this->janNodisplay);
}
/**
* @return string
*/
public function getJanShinmen()
{
return $this->janShinmen;
}
/**
* @return string
*/
public function getJanShiireSize()
{
return $this->janShiireSize;
}
/**
* @return string
*/
public function getJanStock3NyukaDate()
{
return $this->janStock3NyukaDate;
}
/**
* @return int
*/
public function getJanStock3NyukaSouko()
{
return self::intNullable($this->janStock3NyukaSouko);
}
/**
* @return int
*/
public function getJanReplicationFlg()
{
return self::intNullable($this->janReplicationFlg);
}
/**
* @return string
*/
public function getJanReplicationSynchronizedAt()
{
return $this->janReplicationSynchronizedAt;
}
/**
* @return int
*/
public function getJanReturnUnavailableFlg()
{
return self::intNullable($this->janReturnUnavailableFlg);
}
/**
* @param int $janReturnUnavailableFlg
* @return $this
*/
public function setJanReturnUnavailableFlg($janReturnUnavailableFlg)
{
$this->janReturnUnavailableFlg = $janReturnUnavailableFlg;
return $this;
}
/**
* @return bool
*/
public function isReturnUnavailable()
{
return $this->getJanReturnUnavailableFlg() == Jancode::IS_RETURN_UNAVAILABLE_YES;
}
/**
* @param int $goodsId
* @return Jancode[]
*/
public static function findByGoodsId($goodsId)
{
$result = (new SqlService())
->Table(self::TABLE_NAME)
->Set('jan_goods', $goodsId)
->Finds();
$jancodes = [];
foreach ($result as $data) {
$jancodes[] = new Jancode($data);
}
return $jancodes;
}
/**
* @return Goods
*/
public function getGoods()
{
return self::compute($this->goods, function () {
return new Goods($this->getJanGoods());
});
}
/**
* @return GoodsColor
*/
public function getGoodsColor()
{
return self::compute($this->goodsColor, function () {
return new GoodsColor($this->getJanColor());
});
}
/**
* @return GoodsPrice
*/
public function getGoodsPrice()
{
return self::compute($this->goodsPrice, function () {
return new GoodsPrice($this->getJanPrice());
});
}
protected function update()
{
// FIXME: Set actually data.
$values = [
'jan_stock' => $this->getJanStock(),
'jan_stock2' => $this->getJanStock2(),
'jan_stock3' => $this->getJanStock3(),
'jan_stock4' => $this->getJanStock4(),
'jan_stock5' => $this->getJanStock5(),
'jan_stock6' => $this->getJanStock6(),
'jan_stock7' => $this->getJanStock7(),
'jan_stock8' => $this->getJanStock8(),
'jan_stock9' => $this->getJanStock9(),
'jan_return_unavailable_flg' => $this->getJanReturnUnavailableFlg(),
];
//
(new SqlService())
->Table(self::TABLE_NAME)
->Set('jan_id', $this->getJanId())
->Update(false, $values);
}
/**
* @param $goodsId
* @param $gclId
* @param $gpId
* @return Jancode|null
* @throws \Exception
*/
public static function getByIdentifiers($goodsId, $gclId, $gpId)
{
if (empty($goodsId) || empty($gclId) || empty($gpId)) {
return null;
}
$janCode = (new SqlService())
->Table(Jancode::TABLE_NAME)
->Set('jan_goods', $goodsId)
->Set('jan_color', $gclId)
->Set('jan_price', $gpId)
->Find();
return new Jancode($janCode);
}
}