您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

133 行
3.6KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use App\Entity\OrderPayment;
  4. use App\Entity\OrderRefund;
  5. use App\Entity\UserMerchant;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Lc\ShopBundle\Context\OrderPaymentInterface;
  8. use Lc\ShopBundle\Context\OrderRefundInterface;
  9. use Lc\ShopBundle\Context\PayoffInterface;
  10. use Lc\ShopBundle\Context\UserMerchantInterface;
  11. /**
  12. * @ORM\MappedSuperclass()
  13. */
  14. abstract class CreditHistory extends AbstractEntity implements PayoffInterface
  15. {
  16. use PayoffTrait;
  17. const TYPE_CREDIT = 'credit';
  18. const TYPE_DEBIT = 'debit';
  19. /**
  20. * @ORM\Column(type="float", nullable=true)
  21. */
  22. protected $amount;
  23. /**
  24. * @ORM\Column(type="string", length=31)
  25. */
  26. protected $type;
  27. /**
  28. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserMerchantInterface", inversedBy="creditHistories")
  29. * @ORM\JoinColumn(nullable=false)
  30. */
  31. protected $userMerchant;
  32. /**
  33. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\OrderPaymentInterface", cascade={"persist", "remove"})
  34. */
  35. protected $orderPayment;
  36. /**
  37. * @ORM\OneToOne(targetEntity="Lc\ShopBundle\Context\OrderRefundInterface", cascade={"persist", "remove"})
  38. */
  39. protected $orderRefund;
  40. public function getAmount(): ?float
  41. {
  42. return $this->amount;
  43. }
  44. public function setAmount(?float $amount): self
  45. {
  46. $this->amount = $amount;
  47. return $this;
  48. }
  49. public function getAmountInherited(): float
  50. {
  51. if ($this->getOrderPayment() !== null) {
  52. return $this->getOrderPayment()->getAmount();
  53. } else if ($this->getOrderRefund() !== null) {
  54. return $this->getOrderRefund()->getAmount();
  55. } else {
  56. return $this->getAmount();
  57. }
  58. }
  59. public function getMeanPaymentInherited(): string
  60. {
  61. if ($this->getOrderPayment() !== null) {
  62. return $this->getOrderPayment()->getMeanPayment();
  63. } else if ($this->getOrderRefund() !== null) {
  64. return $this->getOrderRefund()->getMeanPayment();
  65. } else {
  66. return $this->getMeanPayment();
  67. }
  68. }
  69. public function getType(): ?string
  70. {
  71. return $this->type;
  72. }
  73. public function setType(string $type): self
  74. {
  75. $this->type = $type;
  76. return $this;
  77. }
  78. public function getUserMerchant(): ?UserMerchantInterface
  79. {
  80. return $this->userMerchant;
  81. }
  82. public function setUserMerchant(?UserMerchantInterface $userMerchant): self
  83. {
  84. $this->userMerchant = $userMerchant;
  85. return $this;
  86. }
  87. public function getOrderPayment(): ?OrderPaymentInterface
  88. {
  89. return $this->orderPayment;
  90. }
  91. public function setOrderPayment(?OrderPaymentInterface $orderPayment): self
  92. {
  93. $this->orderPayment = $orderPayment;
  94. return $this;
  95. }
  96. public function getOrderRefund(): ?OrderRefundInterface
  97. {
  98. return $this->orderRefund;
  99. }
  100. public function setOrderRefund(?OrderRefundInterface $orderRefund): self
  101. {
  102. $this->orderRefund = $orderRefund;
  103. return $this;
  104. }
  105. }