app/Customize/Entity/AuctionResult.php line 10

Open in your IDE?
  1. <?php
  2. namespace Customize\Entity;
  3. use Customize\Entity\Master\AuctionResultStatus;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Eccube\Entity\Customer;
  6. use Eccube\Entity\Product;
  7. if (! class_exists('\Customize\Entity\AuctionResult')) {
  8.     /**
  9.      * 競り結果テーブル
  10.      *
  11.      * @ORM\Table(name="dtb_auction_result")
  12.      *
  13.      * @ORM\InheritanceType("SINGLE_TABLE")
  14.      *
  15.      * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  16.      *
  17.      * @ORM\HasLifecycleCallbacks()
  18.      *
  19.      * @ORM\Entity(repositoryClass="Customize\Repository\AuctionResultRepository")
  20.      */
  21.     class AuctionResult extends \Eccube\Entity\AbstractEntity
  22.     {
  23.         /**
  24.          * id
  25.          *
  26.          * @var int
  27.          *
  28.          * @ORM\Column(name="id", type="integer", options={"unsigned":true, "comment":"ID"})
  29.          *
  30.          * @ORM\Id
  31.          *
  32.          * @ORM\GeneratedValue(strategy="IDENTITY")
  33.          */
  34.         private $id;
  35.         /**
  36.          * 金額
  37.          *
  38.          * @var int|null
  39.          *
  40.          * @ORM\Column(name="price", type="integer", nullable=true, options={"unsigned":true })
  41.          */
  42.         private $price;
  43.         /**
  44.          * 商品ID
  45.          *
  46.          * @var \Eccube\Entity\Product
  47.          *
  48.          * @ORM\OneToOne(targetEntity="Eccube\Entity\Product", inversedBy="AuctionResult")
  49.          *
  50.          * @ORM\JoinColumns({
  51.          *
  52.          * @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false)
  53.          * })
  54.          */
  55.         private $Product;
  56.         /**
  57.          * 顧客ID
  58.          *
  59.          * @var \Eccube\Entity\Customer
  60.          *
  61.          * @ORM\ManyToOne(targetEntity="Eccube\Entity\Customer")
  62.          *
  63.          * @ORM\JoinColumns({
  64.          *
  65.          * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", nullable=true)
  66.          * })
  67.          */
  68.         private $Customer;
  69.         /**
  70.          * @var \Customize\Entity\Master\AuctionResultStatus
  71.          *
  72.          * @ORM\ManyToOne(targetEntity="Customize\Entity\Master\AuctionResultStatus")
  73.          *
  74.          * @ORM\JoinColumns({
  75.          *
  76.          * @ORM\JoinColumn(name="auction_result_status_id", referencedColumnName="id", nullable=false)
  77.          * })
  78.          */
  79.         private $Status;
  80.         /**
  81.          * @var \Customize\Entity\Master\CommentType
  82.          *
  83.          * @ORM\ManyToOne(targetEntity="Customize\Entity\Master\CommentType")
  84.          *
  85.          * @ORM\JoinColumns({
  86.          *
  87.          * @ORM\JoinColumn(name="comment_type_id", referencedColumnName="id", nullable=true)
  88.          * })
  89.          */
  90.         private $CommentType;
  91.         /**
  92.          * 作成日時
  93.          *
  94.          * @var \DateTime|null
  95.          *
  96.          * @ORM\Column(name="create_date", type="datetimetz", nullable=true)
  97.          */
  98.         private $create_date;
  99.         /**
  100.          * 更新日時
  101.          *
  102.          * @var \DateTime|null
  103.          *
  104.          * @ORM\Column(name="update_date", type="datetimetz", nullable=true)
  105.          */
  106.         private $update_date;
  107.         /**
  108.          * 金額
  109.          *
  110.          * @var int
  111.          *
  112.          * @ORM\Column(name="negotiation_price", type="integer", nullable=true, options={"unsigned":true })
  113.          */
  114.         private $negotiation_price;
  115.         /**
  116.          * Constructor
  117.          */
  118.         public function __construct() {}
  119.         /**
  120.          * @return int
  121.          */
  122.         public function getId()
  123.         {
  124.             return $this->id;
  125.         }
  126.         /**
  127.          * @param Product
  128.          * @return AuctionResult
  129.          */
  130.         public function setProduct($product)
  131.         {
  132.             $this->Product $product;
  133.             return $this;
  134.         }
  135.         /**
  136.          * @return Product
  137.          */
  138.         public function getProduct()
  139.         {
  140.             return $this->Product;
  141.         }
  142.         /**
  143.          * @param Customer|null $customer
  144.          * @return AuctionResult
  145.          */
  146.         public function setCustomer($customer)
  147.         {
  148.             $this->Customer $customer;
  149.             return $this;
  150.         }
  151.         /**
  152.          * @return Customer|null
  153.          */
  154.         public function getCustomer()
  155.         {
  156.             return $this->Customer;
  157.         }
  158.         /**
  159.          * @return int|null
  160.          */
  161.         public function getPrice()
  162.         {
  163.             return $this->price;
  164.         }
  165.         /**
  166.          * @param int|null $price
  167.          * @return AuctionResult
  168.          */
  169.         public function setPrice($price)
  170.         {
  171.             $this->price $price;
  172.             return $this;
  173.         }
  174.         /**
  175.          * @return int|null
  176.          */
  177.         public function getNegotiationPrice()
  178.         {
  179.             return $this->negotiation_price;
  180.         }
  181.         /**
  182.          * @return AuctionResult
  183.          */
  184.         public function setNegotiationPrice(?int $negotiationPrice)
  185.         {
  186.             $this->negotiation_price $negotiationPrice;
  187.             return $this;
  188.         }
  189.         /**
  190.          * Set status.
  191.          *
  192.          * @param  AuctionResultStatus  $status
  193.          * @return AuctionResult
  194.          */
  195.         public function setStatus($status)
  196.         {
  197.             $this->Status $status;
  198.             return $this;
  199.         }
  200.         /**
  201.          * Get status.
  202.          *
  203.          * @return AuctionResultStatus
  204.          */
  205.         public function getStatus()
  206.         {
  207.             return $this->Status;
  208.         }
  209.         /**
  210.          * Get status.
  211.          *
  212.          * @return string|null
  213.          */
  214.         public function getStatusName()
  215.         {
  216.             return $this->Status->getName();
  217.         }
  218.         /**
  219.          * Set status.
  220.          *
  221.          * @param  CommentType  $commentType
  222.          * @return AuctionResult
  223.          */
  224.         public function setCommentType($commentType)
  225.         {
  226.             $this->CommentType $commentType;
  227.             return $this;
  228.         }
  229.         /**
  230.          * Get status.
  231.          *
  232.          * @return CommentType
  233.          */
  234.         public function getCommentType()
  235.         {
  236.             return $this->CommentType;
  237.         }
  238.         /**
  239.          * Set createDate.
  240.          *
  241.          * @param  \DateTime  $createDate
  242.          * @return AuctionResult
  243.          */
  244.         public function setCreateDate($createDate)
  245.         {
  246.             $this->create_date $createDate;
  247.             return $this;
  248.         }
  249.         /**
  250.          * Get createDate.
  251.          *
  252.          * @return \DateTime
  253.          */
  254.         public function getCreateDate()
  255.         {
  256.             return $this->create_date;
  257.         }
  258.         /**
  259.          * Set updateDate.
  260.          *
  261.          * @param  \DateTime  $updateDate
  262.          * @return AuctionResult
  263.          */
  264.         public function setUpdateDate($updateDate)
  265.         {
  266.             $this->update_date $updateDate;
  267.             return $this;
  268.         }
  269.         /**
  270.          * Get updateDate.
  271.          *
  272.          * @return \DateTime
  273.          */
  274.         public function getUpdateDate()
  275.         {
  276.             return $this->update_date;
  277.         }
  278.         /**
  279.          * @return string
  280.          */
  281.         public function getStatusColor()
  282.         {
  283.             $status $this->Status->getName();
  284.             if ($status == '出品中' || $status == '成約済み') {
  285.                 return '#25B877';
  286.             }
  287.             if ($status == '保留' || $status == '交渉中') {
  288.                 return '#EEB128';
  289.             }
  290.             if ($status == '次回出品' || $status == '返品') {
  291.                 return '#C04949';
  292.             }
  293.             return '#437ec4';
  294.         }
  295.         /**
  296.          * @return string
  297.          */
  298.         public function getAuctionName()
  299.         {
  300.             $Auction $this->Product->getAuction();
  301.             return $Auction->getName();
  302.         }
  303.         /**
  304.          * 現在の交渉で次に返答すべき側を返す.
  305.          *
  306.          * 最後の返答が出品者なら買主、落札者なら売主を返す。
  307.          *
  308.          * @return string
  309.          */
  310.         public function getCurrentNegotiationBallOwner(): string
  311.         {
  312.             $lastCommentTypeName $this->getLastNegotiationCommentTypeName();
  313.             if ($lastCommentTypeName === '出品者' || $lastCommentTypeName === '売主') {
  314.                 return '落札者';
  315.             }
  316.             if ($lastCommentTypeName === '落札者' || $lastCommentTypeName === '買主') {
  317.                 return '出品者';
  318.             }
  319.             return '-';
  320.         }
  321.         /**
  322.          * 交渉履歴の最後の返答者(CommentType名)を返す.
  323.          *
  324.          * @return string|null
  325.          */
  326.         private function getLastNegotiationCommentTypeName(): ?string
  327.         {
  328.             if ($this->Product === null) {
  329.                 return null;
  330.             }
  331.             $latestNegotiation null;
  332.             foreach ($this->Product->getProductNegotiations() as $productNegotiation) {
  333.                 if ($productNegotiation === null || $productNegotiation->getCommentType() === null) {
  334.                     continue;
  335.                 }
  336.                 if ($latestNegotiation === null || $latestNegotiation->getId() < $productNegotiation->getId()) {
  337.                     $latestNegotiation $productNegotiation;
  338.                 }
  339.             }
  340.             if ($latestNegotiation !== null) {
  341.                 return $latestNegotiation->getCommentType()->getName();
  342.             }
  343.             if ($this->CommentType !== null) {
  344.                 return $this->CommentType->getName();
  345.             }
  346.             return null;
  347.         }
  348.     }
  349. }