<?php
namespace Customize\Entity;
use Customize\Entity\Master\AuctionResultStatus;
use Doctrine\ORM\Mapping as ORM;
use Eccube\Entity\Customer;
use Eccube\Entity\Product;
if (! class_exists('\Customize\Entity\AuctionResult')) {
/**
* 競り結果テーブル
*
* @ORM\Table(name="dtb_auction_result")
*
* @ORM\InheritanceType("SINGLE_TABLE")
*
* @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
*
* @ORM\HasLifecycleCallbacks()
*
* @ORM\Entity(repositoryClass="Customize\Repository\AuctionResultRepository")
*/
class AuctionResult extends \Eccube\Entity\AbstractEntity
{
/**
* id
*
* @var int
*
* @ORM\Column(name="id", type="integer", options={"unsigned":true, "comment":"ID"})
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* 金額
*
* @var int|null
*
* @ORM\Column(name="price", type="integer", nullable=true, options={"unsigned":true })
*/
private $price;
/**
* 商品ID
*
* @var \Eccube\Entity\Product
*
* @ORM\OneToOne(targetEntity="Eccube\Entity\Product", inversedBy="AuctionResult")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false)
* })
*/
private $Product;
/**
* 顧客ID
*
* @var \Eccube\Entity\Customer
*
* @ORM\ManyToOne(targetEntity="Eccube\Entity\Customer")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id", nullable=true)
* })
*/
private $Customer;
/**
* @var \Customize\Entity\Master\AuctionResultStatus
*
* @ORM\ManyToOne(targetEntity="Customize\Entity\Master\AuctionResultStatus")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="auction_result_status_id", referencedColumnName="id", nullable=false)
* })
*/
private $Status;
/**
* @var \Customize\Entity\Master\CommentType
*
* @ORM\ManyToOne(targetEntity="Customize\Entity\Master\CommentType")
*
* @ORM\JoinColumns({
*
* @ORM\JoinColumn(name="comment_type_id", referencedColumnName="id", nullable=true)
* })
*/
private $CommentType;
/**
* 作成日時
*
* @var \DateTime|null
*
* @ORM\Column(name="create_date", type="datetimetz", nullable=true)
*/
private $create_date;
/**
* 更新日時
*
* @var \DateTime|null
*
* @ORM\Column(name="update_date", type="datetimetz", nullable=true)
*/
private $update_date;
/**
* 金額
*
* @var int
*
* @ORM\Column(name="negotiation_price", type="integer", nullable=true, options={"unsigned":true })
*/
private $negotiation_price;
/**
* Constructor
*/
public function __construct() {}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param Product
* @return AuctionResult
*/
public function setProduct($product)
{
$this->Product = $product;
return $this;
}
/**
* @return Product
*/
public function getProduct()
{
return $this->Product;
}
/**
* @param Customer|null $customer
* @return AuctionResult
*/
public function setCustomer($customer)
{
$this->Customer = $customer;
return $this;
}
/**
* @return Customer|null
*/
public function getCustomer()
{
return $this->Customer;
}
/**
* @return int|null
*/
public function getPrice()
{
return $this->price;
}
/**
* @param int|null $price
* @return AuctionResult
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* @return int|null
*/
public function getNegotiationPrice()
{
return $this->negotiation_price;
}
/**
* @return AuctionResult
*/
public function setNegotiationPrice(?int $negotiationPrice)
{
$this->negotiation_price = $negotiationPrice;
return $this;
}
/**
* Set status.
*
* @param AuctionResultStatus $status
* @return AuctionResult
*/
public function setStatus($status)
{
$this->Status = $status;
return $this;
}
/**
* Get status.
*
* @return AuctionResultStatus
*/
public function getStatus()
{
return $this->Status;
}
/**
* Get status.
*
* @return string|null
*/
public function getStatusName()
{
return $this->Status->getName();
}
/**
* Set status.
*
* @param CommentType $commentType
* @return AuctionResult
*/
public function setCommentType($commentType)
{
$this->CommentType = $commentType;
return $this;
}
/**
* Get status.
*
* @return CommentType
*/
public function getCommentType()
{
return $this->CommentType;
}
/**
* Set createDate.
*
* @param \DateTime $createDate
* @return AuctionResult
*/
public function setCreateDate($createDate)
{
$this->create_date = $createDate;
return $this;
}
/**
* Get createDate.
*
* @return \DateTime
*/
public function getCreateDate()
{
return $this->create_date;
}
/**
* Set updateDate.
*
* @param \DateTime $updateDate
* @return AuctionResult
*/
public function setUpdateDate($updateDate)
{
$this->update_date = $updateDate;
return $this;
}
/**
* Get updateDate.
*
* @return \DateTime
*/
public function getUpdateDate()
{
return $this->update_date;
}
/**
* @return string
*/
public function getStatusColor()
{
$status = $this->Status->getName();
if ($status == '出品中' || $status == '成約済み') {
return '#25B877';
}
if ($status == '保留' || $status == '交渉中') {
return '#EEB128';
}
if ($status == '次回出品' || $status == '返品') {
return '#C04949';
}
return '#437ec4';
}
/**
* @return string
*/
public function getAuctionName()
{
$Auction = $this->Product->getAuction();
return $Auction->getName();
}
/**
* 現在の交渉で次に返答すべき側を返す.
*
* 最後の返答が出品者なら買主、落札者なら売主を返す。
*
* @return string
*/
public function getCurrentNegotiationBallOwner(): string
{
$lastCommentTypeName = $this->getLastNegotiationCommentTypeName();
if ($lastCommentTypeName === '出品者' || $lastCommentTypeName === '売主') {
return '落札者';
}
if ($lastCommentTypeName === '落札者' || $lastCommentTypeName === '買主') {
return '出品者';
}
return '-';
}
/**
* 交渉履歴の最後の返答者(CommentType名)を返す.
*
* @return string|null
*/
private function getLastNegotiationCommentTypeName(): ?string
{
if ($this->Product === null) {
return null;
}
$latestNegotiation = null;
foreach ($this->Product->getProductNegotiations() as $productNegotiation) {
if ($productNegotiation === null || $productNegotiation->getCommentType() === null) {
continue;
}
if ($latestNegotiation === null || $latestNegotiation->getId() < $productNegotiation->getId()) {
$latestNegotiation = $productNegotiation;
}
}
if ($latestNegotiation !== null) {
return $latestNegotiation->getCommentType()->getName();
}
if ($this->CommentType !== null) {
return $this->CommentType->getName();
}
return null;
}
}
}