app/Customize/Entity/Auction.php line 24

Open in your IDE?
  1. <?php
  2. namespace Customize\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Eccube\Entity\Member;
  6. use Eccube\Entity\Tag;
  7. if (! class_exists('\Customize\Entity\Auction')) {
  8.     /**
  9.      * オークションテーブル
  10.      *
  11.      * @ORM\Table(name="dtb_auction")
  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\AuctionRepository")
  20.      */
  21.     class Auction 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 string|null
  39.          *
  40.          * @ORM\Column(name="name", type="string", length=255, nullable=true)
  41.          */
  42.         private $name;
  43.         /**
  44.          * 下見開始日時
  45.          *
  46.          * @var \DateTime|null
  47.          *
  48.          * @ORM\Column(name="preview_start_date", type="datetimetz", nullable=true)
  49.          */
  50.         private $preview_start_date;
  51.         /**
  52.          * オークション開始予定日時
  53.          *
  54.          * @var \DateTime|null
  55.          *
  56.          * @ORM\Column(name="schedule_start_date", type="datetimetz", nullable=true)
  57.          */
  58.         private $schedule_start_date;
  59.         /**
  60.          * @var int
  61.          *
  62.          * @ORM\Column(name="negotiation_period_hour", type="datetimetz", nullable=true)
  63.          */
  64.         private $negotiation_period_date;
  65.         /**
  66.          * オークション説明
  67.          *
  68.          * @var string|null
  69.          *
  70.          * @ORM\Column(name="description", type="text", nullable=true)
  71.          */
  72.         private $description;
  73.         /**
  74.          * 競り開始日時
  75.          *
  76.          * @var \DateTime|null
  77.          *
  78.          * @ORM\Column(name="start_date", type="datetimetz", nullable=true)
  79.          */
  80.         private $start_date;
  81.         /**
  82.          * 競り終了日時
  83.          *
  84.          * @var \DateTime|null
  85.          *
  86.          * @ORM\Column(name="end_date", type="datetimetz", nullable=true)
  87.          */
  88.         private $end_date;
  89.         /**
  90.          * 作成日時
  91.          *
  92.          * @var \DateTime|null
  93.          *
  94.          * @ORM\Column(name="create_date", type="datetimetz", nullable=true)
  95.          */
  96.         private $create_date;
  97.         /**
  98.          * 終了日時
  99.          *
  100.          * @var \DateTime|null
  101.          *
  102.          * @ORM\Column(name="update_date", type="datetimetz", nullable=true)
  103.          */
  104.         private $update_date;
  105.         /**
  106.          * 公開日時
  107.          *
  108.          * @var \DateTime|null
  109.          *
  110.          * @ORM\Column(name="publish_date", type="datetimetz", nullable=true)
  111.          */
  112.         private $publish_date;
  113.         /**
  114.          * @var \Doctrine\Common\Collections\Collection
  115.          *
  116.          * @ORM\OneToMany(targetEntity="Customize\Entity\AuctionImage", mappedBy="Auction", cascade={"remove"})
  117.          *
  118.          * @ORM\OrderBy({
  119.          *     "sort_no"="ASC"
  120.          * })
  121.          */
  122.         private $AuctionImage;
  123.         /**
  124.          * @var \Customize\Entity\Master\AuctionStatus
  125.          *
  126.          * @ORM\ManyToOne(targetEntity="Customize\Entity\Master\AuctionStatus")
  127.          *
  128.          * @ORM\JoinColumns({
  129.          *
  130.          * @ORM\JoinColumn(name="auction_status_id", referencedColumnName="id", nullable=true)
  131.          * })
  132.          */
  133.         private $Status;
  134.         /**
  135.          * @var \Doctrine\Common\Collections\Collection
  136.          *
  137.          * @ORM\OneToMany(targetEntity="Customize\Entity\AuctionCategory", mappedBy="Auction", cascade={"persist","remove"})
  138.          */
  139.         private $AuctionCategories;
  140.         /**
  141.          * @var \Doctrine\Common\Collections\Collection
  142.          *
  143.          * @ORM\OneToMany(targetEntity="Customize\Entity\AuctionTag", mappedBy="Auction", cascade={"remove"})
  144.          */
  145.         private $AuctionTags;
  146.         /**
  147.          * @var \Doctrine\Common\Collections\Collection
  148.          *
  149.          * @ORM\OneToMany(targetEntity="Customize\Entity\CustomerFavoriteAuction", mappedBy="Auction")
  150.          */
  151.         private $CustomerFavoriteAuctions;
  152.         /**
  153.          * @var \Doctrine\Common\Collections\Collection
  154.          *
  155.          * @ORM\OneToMany(targetEntity="Eccube\Entity\Product", mappedBy="Auction")
  156.          */
  157.         private $Products;
  158.         /**
  159.          * @var \Eccube\Entity\Member
  160.          *
  161.          * @ORM\ManyToOne(targetEntity="Eccube\Entity\Member")
  162.          *
  163.          * @ORM\JoinColumns({
  164.          *
  165.          *   @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
  166.          * })
  167.          */
  168.         private $Creator;
  169.         /**
  170.          * 準備中説明文言
  171.          *
  172.          * @var string|null
  173.          *
  174.          * @ORM\Column(name="ready_message", type="text", nullable=true)
  175.          */
  176.         private $ready_message;
  177.         /**
  178.          * 管理者用フラグ
  179.          *
  180.          * @var \DateTime|null
  181.          *
  182.          * @ORM\Column(name="is_admin", type="boolean", options={"default":false})
  183.          */
  184.         private $is_admin false;
  185.         /**
  186.          * Constructor
  187.          */
  188.         public function __construct()
  189.         {
  190.             $this->AuctionCategories = new \Doctrine\Common\Collections\ArrayCollection();
  191.             $this->AuctionImage = new \Doctrine\Common\Collections\ArrayCollection();
  192.             $this->AuctionTags = new \Doctrine\Common\Collections\ArrayCollection();
  193.         }
  194.         public function copy()
  195.         {
  196.             $Categories $this->getAuctionCategories();
  197.             $this->AuctionCategories = new ArrayCollection();
  198.             foreach ($Categories as $Category) {
  199.                 $CopyCategory = clone $Category;
  200.                 $this->addAuctionCategory($CopyCategory);
  201.                 $CopyCategory->setAuction($this);
  202.             }
  203.             $Images $this->getAuctionImage();
  204.             $this->AuctionImage = new ArrayCollection();
  205.             foreach ($Images as $Image) {
  206.                 $CloneImage = clone $Image;
  207.                 $this->addAuctionImage($CloneImage);
  208.                 $CloneImage->setAuction($this);
  209.             }
  210.             $Tags $this->getAuctionTags();
  211.             $this->AuctionTags = new ArrayCollection();
  212.             foreach ($Tags as $Tag) {
  213.                 $CloneTag = clone $Tag;
  214.                 $this->addAuctionTag($CloneTag);
  215.                 $CloneTag->setAuction($this);
  216.             }
  217.             return $this;
  218.         }
  219.         /**
  220.          * @return int
  221.          */
  222.         public function getId()
  223.         {
  224.             return $this->id;
  225.         }
  226.         /**
  227.          * @return string
  228.          */
  229.         public function getName()
  230.         {
  231.             return $this->name;
  232.         }
  233.         /**
  234.          * @param  string  $name
  235.          * @return Auction
  236.          */
  237.         public function setName($name)
  238.         {
  239.             $this->name $name;
  240.             return $this;
  241.         }
  242.         /**
  243.          * @return \DateTime
  244.          */
  245.         public function getPreviewStartDate()
  246.         {
  247.             return $this->preview_start_date;
  248.         }
  249.         /**
  250.          * @param  string  $previewStartDate
  251.          * @return Auction
  252.          */
  253.         public function setPreviewStartDate($previewStartDate)
  254.         {
  255.             $this->preview_start_date $previewStartDate;
  256.             return $this;
  257.         }
  258.         /**
  259.          * @return \DateTime
  260.          */
  261.         public function getScheduleStartDate()
  262.         {
  263.             return $this->schedule_start_date;
  264.         }
  265.         /**
  266.          * @param  \Datetime  $scheduleStartDate
  267.          * @return Auction
  268.          */
  269.         public function setScheduleStartDate($scheduleStartDate)
  270.         {
  271.             $this->schedule_start_date $scheduleStartDate;
  272.             return $this;
  273.         }
  274.         /**
  275.          * @return string
  276.          */
  277.         public function getDescription()
  278.         {
  279.             return $this->description;
  280.         }
  281.         /**
  282.          * @param  string  $description
  283.          * @return Auction
  284.          */
  285.         public function setDescription($description)
  286.         {
  287.             $this->description $description;
  288.             return $this;
  289.         }
  290.         /**
  291.          * @return string
  292.          */
  293.         public function getReadyMessage()
  294.         {
  295.             return $this->ready_message;
  296.         }
  297.         /**
  298.          * @param  string  $readyMessage
  299.          * @return Auction
  300.          */
  301.         public function setReadyMessage($readyMessage)
  302.         {
  303.             $this->ready_message $readyMessage;
  304.             return $this;
  305.         }
  306.         /**
  307.          * @return \DateTime
  308.          */
  309.         public function getStartDate()
  310.         {
  311.             return $this->start_date;
  312.         }
  313.         /**
  314.          * @param  \Datetime  $startDate
  315.          * @return Auction
  316.          */
  317.         public function setStartDate($startDate)
  318.         {
  319.             $this->start_date $startDate;
  320.             return $this;
  321.         }
  322.         /**
  323.          * @return \DateTime
  324.          */
  325.         public function getEndDate()
  326.         {
  327.             return $this->end_date;
  328.         }
  329.         /**
  330.          * @param  \Datetime  $endDate
  331.          * @return Auction
  332.          */
  333.         public function setEndDate($endDate)
  334.         {
  335.             $this->end_date $endDate;
  336.             return $this;
  337.         }
  338.         /**
  339.          * Set createDate.
  340.          *
  341.          * @param  \DateTime  $createDate
  342.          * @return Auction
  343.          */
  344.         public function setCreateDate($createDate)
  345.         {
  346.             $this->create_date $createDate;
  347.             return $this;
  348.         }
  349.         /**
  350.          * Get createDate.
  351.          *
  352.          * @return \DateTime
  353.          */
  354.         public function getCreateDate()
  355.         {
  356.             return $this->create_date;
  357.         }
  358.         /**
  359.          * Set updateDate.
  360.          *
  361.          * @param  \DateTime  $updateDate
  362.          * @return Auction
  363.          */
  364.         public function setUpdateDate($updateDate)
  365.         {
  366.             $this->update_date $updateDate;
  367.             return $this;
  368.         }
  369.         /**
  370.          * Get updateDate.
  371.          *
  372.          * @return \DateTime
  373.          */
  374.         public function getUpdateDate()
  375.         {
  376.             return $this->update_date;
  377.         }
  378.         /**
  379.          * Set negotiationPeriodDate.
  380.          *
  381.          * @param  \DateTime  $negotiationPeriodDate
  382.          * @return Auction
  383.          */
  384.         public function setNegotiationPeriodDate($negotiationPeriodDate)
  385.         {
  386.             $this->negotiation_period_date $negotiationPeriodDate;
  387.             return $this;
  388.         }
  389.         /**
  390.          * Get negotiationPeriodDate.
  391.          *
  392.          * @return \DateTime|null
  393.          */
  394.         public function getNegotiationPeriodDate()
  395.         {
  396.             return $this->negotiation_period_date;
  397.         }
  398.         /**
  399.          * Set updateDate.
  400.          *
  401.          * @param  \DateTime  $publishDate
  402.          * @return Auction
  403.          */
  404.         public function setPublishDate($publishDate)
  405.         {
  406.             $this->publish_date $publishDate;
  407.             return $this;
  408.         }
  409.         /**
  410.          * Get updateDate.
  411.          *
  412.          * @return \DateTime|null
  413.          */
  414.         public function getPublishDate()
  415.         {
  416.             return $this->publish_date;
  417.         }
  418.         /**
  419.          * Add productImage.
  420.          *
  421.          *
  422.          * @return Auction
  423.          */
  424.         public function addAuctionImage(AuctionImage $auctionImage)
  425.         {
  426.             $this->AuctionImage[] = $auctionImage;
  427.             return $this;
  428.         }
  429.         /**
  430.          * Remove auctionImage.
  431.          *
  432.          *
  433.          * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  434.          */
  435.         public function removeAuctionImage(AuctionImage $auctionImage)
  436.         {
  437.             return $this->AuctionImage->removeElement($auctionImage);
  438.         }
  439.         /**
  440.          * Get auctionImage.
  441.          *
  442.          * @return \Doctrine\Common\Collections\Collection
  443.          */
  444.         public function getAuctionImage()
  445.         {
  446.             return $this->AuctionImage;
  447.         }
  448.         public function getMainListImage()
  449.         {
  450.             $AuctionImages $this->getAuctionImage();
  451.             return $AuctionImages->isEmpty() ? null $AuctionImages[0];
  452.         }
  453.         public function getMainFileName()
  454.         {
  455.             if (count($this->AuctionImage) > 0) {
  456.                 return $this->AuctionImage[0];
  457.             } else {
  458.                 return null;
  459.             }
  460.         }
  461.         /**
  462.          * Set status.
  463.          *
  464.          *
  465.          * @return Auction
  466.          */
  467.         public function setStatus(?Master\AuctionStatus $status null)
  468.         {
  469.             $this->Status $status;
  470.             return $this;
  471.         }
  472.         /**
  473.          * Get status.
  474.          *
  475.          * @return \Customize\Entity\Master\AuctionStatus|null
  476.          */
  477.         public function getStatus()
  478.         {
  479.             return $this->Status;
  480.         }
  481.         /**
  482.          *
  483.          * @param boolean $isAdmin
  484.          *
  485.          * @return Auction
  486.          */
  487.         public function setIsAdmin($isAdmin)
  488.         {
  489.             $this->is_admin $isAdmin;
  490.             return $this;
  491.         }
  492.         /**
  493.          *
  494.          * @return boolean
  495.          */
  496.         public function getIsAdmin()
  497.         {
  498.             return $this->is_admin;
  499.         }
  500.         /**
  501.          * Add auctionCategory.
  502.          *
  503.          *
  504.          * @return Auction
  505.          */
  506.         public function addAuctionCategory(AuctionCategory $auctionCategory)
  507.         {
  508.             $this->AuctionCategories[] = $auctionCategory;
  509.             return $this;
  510.         }
  511.         /**
  512.          * Remove auctionCategory.
  513.          *
  514.          *
  515.          * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  516.          */
  517.         public function removeAuctionCategory(AuctionCategory $auctionCategory)
  518.         {
  519.             return $this->AuctionCategories->removeElement($auctionCategory);
  520.         }
  521.         /**
  522.          * Get auctionCategories.
  523.          *
  524.          * @return \Doctrine\Common\Collections\Collection
  525.          */
  526.         public function getAuctionCategories()
  527.         {
  528.             return $this->AuctionCategories;
  529.         }
  530.         /**
  531.          * Get auctionTags.
  532.          *
  533.          * @return \Doctrine\Common\Collections\Collection
  534.          */
  535.         public function getAuctionTags()
  536.         {
  537.             return $this->AuctionTags;
  538.         }
  539.         /**
  540.          * Add auctionTag.
  541.          *
  542.          *
  543.          * @return Auction
  544.          */
  545.         public function addAuctionTag(AuctionTag $auctionTag)
  546.         {
  547.             $this->AuctionTags[] = $auctionTag;
  548.             return $this;
  549.         }
  550.         /**
  551.          * Remove productTag.
  552.          *
  553.          *
  554.          * @return bool TRUE if this collection contained the specified element, FALSE otherwise.
  555.          */
  556.         public function removeAuctionTag(AuctionTag $auctionTag)
  557.         {
  558.             return $this->AuctionTags->removeElement($auctionTag);
  559.         }
  560.         /**
  561.          * Get Tag
  562.          * フロント側タグsort_no順の配列を作成する
  563.          *
  564.          * @return []Tag
  565.          */
  566.         public function getTags()
  567.         {
  568.             $tags = [];
  569.             if (! is_null($this->getAuctionTags())) {
  570.                 foreach ($this->getAuctionTags() as $auctionTag) {
  571.                     $tags[] = $auctionTag->getTag();
  572.                 }
  573.             }
  574.             usort($tags, function (Tag $tag1Tag $tag2) {
  575.                 return $tag1->getSortNo() < $tag2->getSortNo();
  576.             });
  577.             return $tags;
  578.         }
  579.         /**
  580.          * Set creator.
  581.          *
  582.          *
  583.          * @return Product
  584.          */
  585.         public function setCreator(?Member $creator null)
  586.         {
  587.             $this->Creator $creator;
  588.             return $this;
  589.         }
  590.         /**
  591.          * Get creator.
  592.          *
  593.          * @return \Eccube\Entity\Member|null
  594.          */
  595.         public function getCreator()
  596.         {
  597.             return $this->Creator;
  598.         }
  599.         /**
  600.          * Get customerFavoriteAuctions.
  601.          *
  602.          * @return \Doctrine\Common\Collections\Collection
  603.          */
  604.         public function getCustomerFavoriteAuctions()
  605.         {
  606.             return $this->CustomerFavoriteAuctions;
  607.         }
  608.         /**
  609.          * Get products.
  610.          *
  611.          * @return \Doctrine\Common\Collections\Collection
  612.          */
  613.         public function getProducts()
  614.         {
  615.             $Products = [];
  616.             foreach ($this->Products as $product) {
  617.                 if ($product->getStatus()->getName() == '公開') {
  618.                     $Products[] = $product;
  619.                 }
  620.             }
  621.             return new ArrayCollection($Products);
  622.         }
  623.         /**
  624.          * Get products.
  625.          *
  626.          * @return \Doctrine\Common\Collections\Collection
  627.          */
  628.         public function getProductsSortAuctionNo()
  629.         {
  630.             $Products = [];
  631.             foreach ($this->Products as $product) {
  632.                 if ($product->getStatus()->getName() == '公開') {
  633.                     $Products[] = $product;
  634.                 }
  635.             }
  636.             // auction_noで昇順ソート
  637.             usort($Products, function($a$b) {
  638.                 return $a->getAuctionNo() <=> $b->getAuctionNo();
  639.             });
  640.             return new ArrayCollection($Products);
  641.         }
  642.         public function hasAuctionCategories()
  643.         {
  644.             foreach ($this->AuctionCategories as $AuctionCategory) {
  645.                 if (! is_null($AuctionCategory)) {
  646.                     return true;
  647.                 }
  648.             }
  649.             return false;
  650.         }
  651.         public function getAuctionCategoryNames()
  652.         {
  653.             $categoryNames = [];
  654.             foreach ($this->AuctionCategories as $AuctionCategory) {
  655.                 if (is_null($AuctionCategory)) {
  656.                     break;
  657.                 }
  658.                 $categoryNames[] = $AuctionCategory->Category->getName();
  659.             }
  660.             return $categoryNames;
  661.         }
  662.         public function hasAuctionTags()
  663.         {
  664.             foreach ($this->AuctionTags as $AuctionTag) {
  665.                 if (! is_null($AuctionTag)) {
  666.                     return true;
  667.                 }
  668.             }
  669.             return false;
  670.         }
  671.         public function getAuctionTagNames()
  672.         {
  673.             $tagNames = [];
  674.             foreach ($this->AuctionTags as $AuctionTag) {
  675.                 if (is_null($AuctionTag)) {
  676.                     break;
  677.                 }
  678.                 $tagNames[] = $AuctionTag->Tag->getName();
  679.             }
  680.             return $tagNames;
  681.         }
  682.         public function countCustomerFavoriteAuctions()
  683.         {
  684.             return count($this->CustomerFavoriteAuctions);
  685.         }
  686.         public function isFavorite($Customer)
  687.         {
  688.             $is_favorite false;
  689.             if (is_null($Customer)) {
  690.                 return $is_favorite;
  691.             }
  692.             foreach ($this->CustomerFavoriteAuctions as $favoriteAuction) {
  693.                 $is_favorite $favoriteAuction->checkFavoriteFromAuction($Customer);
  694.                 if ($is_favorite) {
  695.                     return $is_favorite;
  696.                 }
  697.             }
  698.             return $is_favorite;
  699.         }
  700.         public function getDetailPath()
  701.         {
  702.             $detailPath 'auction_detail';
  703.             $isStarting $this->isStarting();
  704.             if ($isStarting) {
  705.                 $detailPath 'starting_auction_detail';
  706.             }
  707.             return $detailPath;
  708.         }
  709.         public function isBefore()
  710.         {
  711.             $now = new \DateTime();
  712.             return $this->preview_start_date $now;
  713.         }
  714.         public function isPreview()
  715.         {
  716.             $now = new \DateTime();
  717.             return $this->preview_start_date <= $now && is_null($this->start_date);
  718.         }
  719.         public function isStarting()
  720.         {
  721.             if ($this->getStatus() == '非公開') {
  722.                 return false;
  723.             }
  724.             $now = new \DateTime();
  725.             $after30min $now->modify('+30 minutes');
  726.             
  727.             return $this->schedule_start_date <= $after30min && is_null($this->end_date);
  728.         }
  729.         public function isStartingForAdmin()
  730.         {
  731.             if ($this->getStatus() == '非公開') {
  732.                 return false;
  733.             }
  734.             return is_null($this->end_date);
  735.         }
  736.         public function isEnding()
  737.         {
  738.             if (is_null($this->start_date) || is_null($this->end_date)) {
  739.                 return false;
  740.             }
  741.             return true;
  742.         }
  743.         /*
  744.         * 総落札数
  745.         */
  746.         public function countTotalSuccessFulBid(): int
  747.         {
  748.             $countTotalSuccessFulBid 0;
  749.             $products $this->Products;
  750.             // priceがnullの商品は落札されていないため除外
  751.             foreach ($products as $product) {
  752.                 $auctionResult $product->getAuctionResult();
  753.                 if (!$auctionResult) {
  754.                     continue;
  755.                 }
  756.                 if (
  757.                     $auctionResult->getStatusName() == '成約済み' ||
  758.                     $auctionResult->getStatusName() == '交渉中' ||
  759.                     $auctionResult->getStatusName() == '保留' && $auctionResult->getPrice() != null
  760.                 ) {
  761.                     $countTotalSuccessFulBid++;
  762.                 }
  763.             }
  764.             return $countTotalSuccessFulBid;
  765.         }
  766.         /*
  767.         * 成約数
  768.         */
  769.         public function countNumberOfDeal()
  770.         {
  771.             $countNumberOfDeals 0;
  772.             $products $this->Products;
  773.             foreach ($products as $product) {
  774.                 $auctionResult $product->getAuctionResult();
  775.                 if (!$auctionResult) {
  776.                     continue;
  777.                 }
  778.                 if ($auctionResult->getStatusName() == '成約済み') {
  779.                     $countNumberOfDeals++;
  780.                 }
  781.             }
  782.             return $countNumberOfDeals;
  783.         }
  784.         /*
  785.         * 保留数
  786.         */
  787.         public function countHold()
  788.         {
  789.             $countHold 0;
  790.             $products $this->Products;
  791.             foreach ($products as $product) {
  792.                 $auctionResult $product->getAuctionResult();
  793.                 if (!$auctionResult) {
  794.                     continue;
  795.                 }
  796.                 if ($auctionResult->getStatusName() == '保留') {
  797.                     $countHold++;
  798.                 }
  799.             }
  800.             return $countHold;
  801.         }
  802.         /*
  803.         * 不成約数
  804.         */
  805.         public function countNotContract()
  806.         {
  807.             $countNoContract 0;
  808.             $products $this->Products;
  809.             foreach ($products as $product) {
  810.                 $auctionResult $product->getAuctionResult();
  811.                 if (!$auctionResult) {
  812.                     continue;
  813.                 }
  814.                 if ($auctionResult->getStatusName() == '次回出品' || $auctionResult->getStatusName() == '返品') {
  815.                     $countNoContract++;
  816.                 }
  817.             }
  818.             return $countNoContract;
  819.         }
  820.         /*
  821.         * 交渉中数
  822.         */
  823.         public function countNowNegotiation()
  824.         {
  825.             $countNowNegotiation 0;
  826.             $products $this->Products;
  827.             foreach ($products as $product) {
  828.                 $auctionResult $product->getAuctionResult();
  829.                 if (!$auctionResult) {
  830.                     continue;
  831.                 }
  832.                 if ($auctionResult->getStatusName() == '交渉中') {
  833.                     $countNowNegotiation++;
  834.                 }
  835.             }
  836.             return $countNowNegotiation;
  837.         }
  838.         /*
  839.         * 次回出品数
  840.         */
  841.         public function countNextSell()
  842.         {
  843.             $countNextSell 0;
  844.             $products $this->Products;
  845.             foreach ($products as $product) {
  846.                 $auctionResult $product->getAuctionResult();
  847.                 if (!$auctionResult) {
  848.                     continue;
  849.                 }
  850.                 if ($auctionResult->getStatusName() == '次回出品') {
  851.                     $countNextSell++;
  852.                 }
  853.             }
  854.             return $countNextSell;
  855.         }
  856.         public function isClosed()
  857.         {
  858.             return !is_null($this->start_date) && !is_null($this->end_date);
  859.         }
  860.         public function countProducts()
  861.         {
  862.             $displayProducts = [];
  863.             foreach ($this->Products as $Product) {
  864.                 if ($Product->isEnable()) {
  865.                     $displayProducts[] = $Product;
  866.                 }
  867.             }
  868.             return count($displayProducts);
  869.         }
  870.         public function getCorrectionListProducts()
  871.         {
  872.             $correctionListProducts = [];
  873.             foreach ($this->Products as $product) {
  874.                 if (is_null($product->getCorrectionList())) {
  875.                     continue;
  876.                 }
  877.                 $correctionListProducts[] = $product;
  878.             }
  879.             return $correctionListProducts;
  880.         }
  881.         /**
  882.          * @return array
  883.          */
  884.         public function getCanMakeOrderProductsByCustomer(AuctionResult $AuctionResult)
  885.         {
  886.             $productsByCustomer = [];
  887.             $excludedCustomers = [];
  888.             $products $this->getProducts();
  889.             $beforeFlushProduct $AuctionResult->getProduct();
  890.             // 落札確定APIで、最後の商品のオークション結果はDBにまだcommitされないためSET
  891.             foreach ($products as $product) {
  892.                 if ($product->getId() == $beforeFlushProduct->getId()) {
  893.                     $product->setAuctionResult($AuctionResult);
  894.                 }
  895.             }
  896.             // 最初のループで保留商品がある顧客を特定
  897.             foreach ($products as $product) {
  898.                 $auctionResult $product->getAuctionResult();
  899.                 if (!$auctionResult) {
  900.                     continue;
  901.                 }
  902.                 $customer $auctionResult->getCustomer();
  903.                 $productCustomer $product->getCustomer();
  904.                 if ($customer !== null && $productCustomer && $auctionResult->getStatusName() == '保留') {
  905.                     $excludedCustomers[$customer->getId()] = true;
  906.                     $excludedCustomers[$productCustomer->getId()] = true;
  907.                 }
  908.             }
  909.             // 売りと買いでどちらも保留商品がない顧客の商品を配列に追加
  910.             foreach ($products as $product) {
  911.                 $auctionResult $product->getAuctionResult();
  912.                 if (!$auctionResult) {
  913.                     continue;
  914.                 }
  915.                 if (
  916.                     $auctionResult->getStatusName() == '返品' ||
  917.                     $auctionResult->getStatusName() == '次回出品'
  918.                 ) {
  919.                     continue;
  920.                 }
  921.                 if ($auctionResult->getCustomer() == null) {
  922.                     continue;
  923.                 }
  924.                 $successfulBidder $auctionResult->getCustomer();
  925.                 $seller $product->getCustomer();
  926.                 // 落札商品
  927.                 if ($successfulBidder !== null && !isset($excludedCustomers[$successfulBidder->getId()])) {
  928.                     $successfulBidderId $successfulBidder->getId();
  929.                     if (!isset($productsByCustomer[$successfulBidderId])) {
  930.                         $productsByCustomer[$successfulBidderId] = [];
  931.                     }
  932.                     $productsByCustomer[$successfulBidderId]['successful_bid'][] = $product;
  933.                 }
  934.                 // 出品商品
  935.                 if ($seller !== null && !isset($excludedCustomers[$seller->getId()])) {
  936.                     $sellerId $seller->getId();
  937.                     if (!isset($productsByCustomer[$sellerId])) {
  938.                         $productsByCustomer[$sellerId] = [];
  939.                     }
  940.                     $productsByCustomer[$sellerId]['sell'][] = $product;
  941.                 }
  942.             }
  943.             return $productsByCustomer;
  944.         }
  945.         public function getOrderBySuccessfulBidCustomer(AuctionResult $auctionResult): array
  946.         {
  947.             $productsByCustomer = [];
  948.             $customer $auctionResult->getCustomer();
  949.             $products $this->getProducts();
  950.             foreach ($products as $product) {
  951.                 $auctionResult $product->getAuctionResult();
  952.                 if (!$auctionResult) {
  953.                     continue;
  954.                 }
  955.                 if ($auctionResult->getStatusName() == '返品' || $auctionResult->getStatusName() == '次回出品') {
  956.                     continue;
  957.                 }
  958.                 $bidder $auctionResult->getCustomer();
  959.                 $seller $product->getCustomer();
  960.                 if ($bidder == null) {
  961.                     continue;
  962.                 }
  963.                 // 落札商品
  964.                 if ($bidder->getId() ==  $customer->getId()) {
  965.                     $bidderId $bidder->getId();
  966.                     if (!isset($productsByCustomer[$bidderId])) {
  967.                         $productsByCustomer[$bidderId] = [];
  968.                     }
  969.                     $productsByCustomer[$bidderId]['successful_bid'][] = $product;
  970.                 }
  971.                 // 出品商品
  972.                 if ($seller->getId() == $customer->getId()) {
  973.                     $sellerId $seller->getId();
  974.                     if (!isset($productsByCustomer[$sellerId])) {
  975.                         $productsByCustomer[$sellerId] = [];
  976.                     }
  977.                     $productsByCustomer[$sellerId]['sell'][] = $product;
  978.                 }
  979.             }
  980.             return $productsByCustomer;
  981.         }
  982.         public function getOrderBySellerCustomer(AuctionResult $auctionResult): array
  983.         {
  984.             $productsByCustomer = [];
  985.             $product $auctionResult->getProduct();
  986.             $customer $product->getCustomer();
  987.             $products $this->getProducts();
  988.             foreach ($products as $product) {
  989.                 $auctionResult $product->getAuctionResult();
  990.                 if (!$auctionResult) {
  991.                     continue;
  992.                 }
  993.                 if ($auctionResult->getStatusName() == '返品' || $auctionResult->getStatusName() == '次回出品') {
  994.                     continue;
  995.                 }
  996.                 $bidder $auctionResult->getCustomer();
  997.                 $seller $product->getCustomer();
  998.                 if ($bidder == null) {
  999.                     continue;
  1000.                 }
  1001.                 // 落札商品
  1002.                 if ($bidder->getId() ==  $customer->getId()) {
  1003.                     $bidderId $bidder->getId();
  1004.                     if (!isset($productsByCustomer[$bidderId])) {
  1005.                         $productsByCustomer[$bidderId] = [];
  1006.                     }
  1007.                     $productsByCustomer[$bidderId]['successful_bid'][] = $product;
  1008.                 }
  1009.                 // 出品商品
  1010.                 if ($seller->getId() == $customer->getId()) {
  1011.                     $sellerId $seller->getId();
  1012.                     if (!isset($productsByCustomer[$sellerId])) {
  1013.                         $productsByCustomer[$sellerId] = [];
  1014.                     }
  1015.                     $productsByCustomer[$sellerId]['sell'][] = $product;
  1016.                 }
  1017.             }
  1018.             return $productsByCustomer;
  1019.         }
  1020.         public function sumAgreementProductPrice(): int
  1021.         {
  1022.             $sum 0;
  1023.             foreach ($this->Products as $Product) {
  1024.                 $auctionResult $Product->getAuctionResult();
  1025.                 if (!$auctionResult) {
  1026.                     continue;
  1027.                 }
  1028.                 if ($auctionResult->getStatusName() == '成約済み') {
  1029.                     $sum += $auctionResult->getPrice();
  1030.                 }
  1031.             }
  1032.             return $sum;
  1033.         }
  1034.     }
  1035. }