app/Plugin/np42/Entity/OrderNp.php line 19

Open in your IDE?
  1. <?php
  2. namespace Plugin\np42\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Eccube\Entity\Master\OrderStatus;
  5. use Eccube\Entity\Order;
  6. use Plugin\np42\Service\PaymentApi\Cancel;
  7. use Plugin\np42\Service\PaymentApi\Capture;
  8. use Plugin\np42\Service\PaymentApi\Change;
  9. use Plugin\np42\Service\PaymentApi\Register;
  10. /**
  11.  * OrderNp
  12.  *
  13.  * @ORM\Table(name="plg_np42_order_np")
  14.  * @ORM\Entity(repositoryClass="Plugin\np42\Repository\OrderNpRepository")
  15.  */
  16. class OrderNp
  17. {
  18.     /**
  19.      * NP後払いステータス
  20.      */
  21.     const NP_STATUS_OK     '00';
  22.     const NP_STATUS_HOLD   '10';
  23.     const NP_STATUS_NG     '20';
  24.     const NP_STATUS_BEFORE '40';
  25.     const NP_STATUS_REVIEW '550'// すでに、出荷報告済み:50で使用しているため別の番号を割り振る
  26.     const NP_STATUS_SEND   '50';
  27.     const NP_STATUS_CANCEL '60';
  28.     const NP_STATUS_NONE '01';
  29.     const NP_STATUS_OK_NAME     "審査OK";
  30.     const NP_STATUS_HOLD_NAME   "保留";
  31.     const NP_STATUS_NG_NAME     "審査NG";
  32.     const NP_STATUS_BEFORE_NAME "審査前";
  33.     const NP_STATUS_REVIEW_NAME "審査中";
  34.     const NP_STATUS_SEND_NAME   "出荷報告済";
  35.     const NP_STATUS_CANCEL_NAME "キャンセル済";
  36.     const NP_STATUS_NONE_NAME '取引未完了';
  37.     const NP_STATUS_LIST = [
  38.         self::NP_STATUS_OK => self::NP_STATUS_OK_NAME,
  39.         self::NP_STATUS_HOLD => self::NP_STATUS_HOLD_NAME,
  40.         self::NP_STATUS_NG => self::NP_STATUS_NG_NAME,
  41.         self::NP_STATUS_BEFORE => self::NP_STATUS_BEFORE_NAME,
  42.         self::NP_STATUS_REVIEW => self::NP_STATUS_REVIEW_NAME,
  43.         self::NP_STATUS_SEND => self::NP_STATUS_SEND_NAME,
  44.         self::NP_STATUS_CANCEL => self::NP_STATUS_CANCEL_NAME,
  45.         self::NP_STATUS_NONE => self::NP_STATUS_NONE_NAME,
  46.     ];
  47.     /**
  48.      * @var int
  49.      *
  50.      * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  51.      * @ORM\Id
  52.      * @ORM\GeneratedValue(strategy="IDENTITY")
  53.      */
  54.     private $id;
  55.     /**
  56.      * @var Eccube\Entity\Order
  57.      * @ORM\ManyToOne(targetEntity="Eccube\Entity\Order", inversedBy="OrderNp")
  58.      * @ORM\JoinColumns({
  59.      *   @ORM\JoinColumn(name="order_id", referencedColumnName="id")
  60.      * })
  61.      */
  62.     private $Order;
  63.     /**
  64.      * @var int $np_status_id NP後払いステータスID
  65.      * @ORM\Column(name="np_status_id", type="text", options={"default":"00", "comment":"NP後払いステータスID"})
  66.      */
  67.     private $np_status_id '';
  68.     /**
  69.      * @var string
  70.      * @ORM\Column(name="shop_code", type="text", options={"default":"", "comment": "加盟店コード"})
  71.      */
  72.     private $shop_code '';
  73.     /**
  74.      * @var string
  75.      * @ORM\Column(name="shop_transaction_no", type="text", options={"default":"", "comment": "加盟店取引ID 半角英数字"})
  76.      */
  77.     private $shop_transaction_no '';
  78.     /**
  79.      * @var string
  80.      * @ORM\Column(name="transaction_id", type="text", options={"default":"", "comment": "取引ID format:YYMMDDXXXXX"})
  81.      */
  82.     private $transaction_id '';
  83.     /**
  84.      * @var string $authorization_result 与信結果
  85.      * @ORM\Column(name="authorization_result", type="text", options={"default":"", "comment": "与信結果"})
  86.      */
  87.     private $authorization_result '';
  88.     /**
  89.      * @var string $authorization_result_ng_reason 与信NG事由
  90.      * @ORM\Column(name="authorization_result_ng_reason", type="text", options={"default":"", "comment": "与信NG事由"})
  91.      */
  92.     private $authorization_result_ng_reason '';
  93.     /**
  94.      * @var string
  95.      * @ORM\Column(name="authori_hold", type="text", options={"default":"", "comment": "与信保留事由"})
  96.      */
  97.     private $authori_hold '';
  98.     /**
  99.      * @var string $amount atone顧客請求金額
  100.      * @ORM\Column(name="amount", type="integer", options={"default":0, "comment": "顧客請求金額"})
  101.      */
  102.     private $amount;
  103.     /**
  104.      * @var string $np_settlement_type 請求書区分
  105.      * @ORM\Column(name="np_settlement_type", type="text", options={"default":"", "comment": "請求書区分"})
  106.      */
  107.     private $np_settlement_type '';
  108.     /**
  109.      * md5でハッシュ化された受注情報
  110.      *
  111.      * @var string $order_np_detail_md5
  112.      *
  113.      * @ORM\Column(name="order_np_detail_md5", type="text", length=65532, nullable=true, options={"default":"", "comment": "NP後払い md5でハッシュ化された受注情報"})
  114.      */
  115.     private $order_np_detail_md5 '';
  116.     /**
  117.      * @var string $order_diff
  118.      *
  119.      * @ORM\Column(name="order_diff", type="text", nullable=true, options={"default":"", "comment": "NP後払い 差分情報"})
  120.      */
  121.     private $order_diff '';
  122.     /**
  123.      * @var \DateTime
  124.      *
  125.      * @ORM\Column(name="create_date", type="datetimetz", options={"comment": "作成日時"})
  126.      */
  127.     private $create_date;
  128.     /**
  129.      * @var \DateTime
  130.      *
  131.      * @ORM\Column(name="update_date", type="datetimetz", options={"comment": "更新日時"})
  132.      */
  133.     private $update_date;
  134.     public function getOrder(): ?Order
  135.     {
  136.         return $this->Order;
  137.     }
  138.     public function setOrder(Order $Order)
  139.     {
  140.         $this->Order $Order;
  141.         return $this;
  142.     }
  143.     public function getId(): ?int
  144.     {
  145.         return $this->id;
  146.     }
  147.     public function getShopCode(): ?string
  148.     {
  149.         return $this->shop_code;
  150.     }
  151.     public function setShopCode(string $shop_code): self
  152.     {
  153.         $this->shop_code $shop_code;
  154.         return $this;
  155.     }
  156.     public function getShopTransactionNo(): ?string
  157.     {
  158.         return $this->shop_transaction_no;
  159.     }
  160.     public function setShopTransactionNo(string $shop_transaction_no): self
  161.     {
  162.         $this->shop_transaction_no $shop_transaction_no;
  163.         return $this;
  164.     }
  165.     public function getTransactionId(): ?string
  166.     {
  167.         return $this->transaction_id;
  168.     }
  169.     public function setTransactionId(string $transaction_id): self
  170.     {
  171.         $this->transaction_id $transaction_id;
  172.         return $this;
  173.     }
  174.     public function getAuthorizationResult(): ?string
  175.     {
  176.         return $this->authorization_result;
  177.     }
  178.     public function setAuthorizationResult(string $authorization_result): self
  179.     {
  180.         $this->authorization_result $authorization_result;
  181.         return $this;
  182.     }
  183.     public function getAuthorizationResultNgReason(): ?string
  184.     {
  185.         return $this->authorization_result_ng_reason;
  186.     }
  187.     public function setAuthorizationResultNgReason(string $authorization_result_ng_reason): self
  188.     {
  189.         $this->authorization_result_ng_reason $authorization_result_ng_reason;
  190.         return $this;
  191.     }
  192.     public function getAuthoriHoldToArray(): array
  193.     {
  194.         if (empty($this->authori_hold)) {
  195.             return [];
  196.         }
  197.         return json_decode($this->authori_holdJSON_UNESCAPED_UNICODE);
  198.     }
  199.     public function getAuthoriHold(): ?string
  200.     {
  201.         return $this->authori_hold;
  202.     }
  203.     public function setAuthoriHold(string $authori_hold): self
  204.     {
  205.         $this->authori_hold $authori_hold;
  206.         return $this;
  207.     }
  208.     /**
  209.      * @return string
  210.      */
  211.     public function getNpStatusId(): string
  212.     {
  213.         return $this->np_status_id;
  214.     }
  215.     /**
  216.      * @param string $np_status_id
  217.      */
  218.     public function setNpStatusId(string $np_status_id): self
  219.     {
  220.         $this->np_status_id $np_status_id;
  221.         return $this;
  222.     }
  223.     /**
  224.      * @return string
  225.      */
  226.     public function getAmount(): string
  227.     {
  228.         return $this->amount;
  229.     }
  230.     /**
  231.      * @param string $amount
  232.      */
  233.     public function setAmount(string $amount): self
  234.     {
  235.         $this->amount $amount;
  236.         return $this;
  237.     }
  238.     /**
  239.      * @return string
  240.      */
  241.     public function getNpSettlementType(): string
  242.     {
  243.         return $this->np_settlement_type;
  244.     }
  245.     /**
  246.      * @param string $np_settlement_type
  247.      */
  248.     public function setNpSettlementType(string $np_settlement_type): self
  249.     {
  250.         $this->np_settlement_type $np_settlement_type;
  251.         return $this;
  252.     }
  253.     /**
  254.      * Set createDate.
  255.      *
  256.      * @param \DateTime $createDate
  257.      *
  258.      * @return $this
  259.      */
  260.     public function setCreateDate($createDate): self
  261.     {
  262.         $this->create_date $createDate;
  263.         return $this;
  264.     }
  265.     /**
  266.      * Get createDate.
  267.      *
  268.      * @return \DateTime
  269.      */
  270.     public function getCreateDate()
  271.     {
  272.         return $this->create_date;
  273.     }
  274.     /**
  275.      * Set updateDate.
  276.      *
  277.      * @param \DateTime $updateDate
  278.      *
  279.      * @return $this
  280.      */
  281.     public function setUpdateDate($updateDate): self
  282.     {
  283.         $this->update_date $updateDate;
  284.         return $this;
  285.     }
  286.     /**
  287.      * Get updateDate.
  288.      *
  289.      * @return \DateTime
  290.      */
  291.     public function getUpdateDate()
  292.     {
  293.         return $this->update_date;
  294.     }
  295.     /**
  296.      * @return string
  297.      */
  298.     public function getOrderNpDetailMd5(): string
  299.     {
  300.         return $this->order_np_detail_md5;
  301.     }
  302.     /**
  303.      * @param string $order_np_detail_md5
  304.      */
  305.     public function setOrderNpDetailMd5(string $order_np_detail_md5): self
  306.     {
  307.         $this->order_np_detail_md5 $order_np_detail_md5;
  308.         return $this;
  309.     }
  310.     /**
  311.      * @return string|null
  312.      */
  313.     public function getOrderDiff(): ?string
  314.     {
  315.         return $this->order_diff;
  316.     }
  317.     /**
  318.      * @param string|null $order_diff
  319.      */
  320.     public function setOrderDiff(?string $order_diff): self
  321.     {
  322.         $this->order_diff $order_diff;
  323.         return $this;
  324.     }
  325.     public function getCancelRequestAction(): string
  326.     {
  327.         // 取引キャンセル
  328.         if ($this->getNpStatusId() != self::NP_STATUS_CANCEL
  329.             && $this->getNpStatusId() != self::NP_STATUS_NONE) {
  330.             return Cancel::__REQUEST_ACTION;
  331.         }
  332.         return '';
  333.     }
  334.     public function getSubmitRequestAction(): string
  335.     {
  336.         /** * @var \Eccube\Entity\Order $Order */
  337.         $Order $this->getOrder();
  338.         // 発送伝票番号があるか
  339.         $is_tracking_number true;
  340.         /** @var \Eccube\Entity\Shipping $Shipping */
  341.         foreach ($Order->getShippings() as $Shipping) {
  342.             if (is_null($Shipping->getTrackingNumber()) || $Shipping->getTrackingNumber() === '') {
  343.                 $is_tracking_number false;
  344.             }
  345.         }
  346.         // 取引登録
  347.         if (self::NP_STATUS_NONE === $this->getNpStatusId()
  348.             && $Order->getOrderStatus()->getId() != OrderStatus::CANCEL
  349.         ) {
  350.             return Register::__REQUEST_ACTION;
  351.         }
  352.         // 売上確定 トラッキングナンバーがある。差分がない。発送済み。出荷報告済・キャンセル済以外。
  353.         if ($is_tracking_number
  354.             && $this->getOrderNpDetailMd5() === $Order->getOrderNpDetailMd5()
  355.             && $Order->getOrderStatus()->getId() == OrderStatus::DELIVERED
  356.             && $this->getNpStatusId() != self::NP_STATUS_SEND
  357.             && $this->getNpStatusId() != self::NP_STATUS_CANCEL
  358.         ) {
  359.             return Capture::__REQUEST_ACTION;
  360.         }
  361.         // 取引更新
  362.         if ($this->getOrderNpDetailMd5() != $Order->getOrderNpDetailMd5()
  363.             && $Order->getOrderStatus()->getId() != OrderStatus::CANCEL
  364.             && $this->getNpStatusId() != self::NP_STATUS_NONE
  365.             && $this->getNpStatusId() != self::NP_STATUS_SEND
  366.             && $this->getNpStatusId() != self::NP_STATUS_CANCEL
  367.         ) {
  368.             return Change::__REQUEST_ACTION;
  369.         }
  370.         return '';
  371.     }
  372. }