PreOrderTaxFee.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\frontend\models\order;
  3. use app\common\models\order\OrderTaxFee;
  4. use app\frontend\models\Order;
  5. use app\frontend\modules\order\models\PreOrder;
  6. use app\frontend\modules\order\taxFee\BaseOrderTaxFee;
  7. class PreOrderTaxFee extends OrderTaxFee
  8. {
  9. protected $appends = ['checked', 'show','show_name'];
  10. /**
  11. * @var Order
  12. */
  13. public $order;
  14. /**
  15. * @var BaseOrderTaxFee
  16. */
  17. protected $taxFee;
  18. public function init(BaseOrderTaxFee $taxFee, PreOrder $order)
  19. {
  20. $this->taxFee = $taxFee;
  21. $this->setOrder($order);
  22. }
  23. public function setOrder(PreOrder $order)
  24. {
  25. $this->order = $order;
  26. $this->uniacid = \YunShop::app()->uniacid;
  27. $this->uid = $order->uid;
  28. $this->fee_code = $this->getTaxFee()->getCode();
  29. $this->name = $this->getTaxFee()->getName();
  30. $this->rate = $this->getTaxFee()->getRate();
  31. $this->amount = sprintf('%.2f', $this->getTaxFee()->getAmount());
  32. $order->orderTaxFees->push($this);
  33. }
  34. public function getTaxFee()
  35. {
  36. return $this->taxFee;
  37. }
  38. /**
  39. * 调用当前类不存在方法时 查询 BaseOrderTaxFee 类存在代替处理
  40. * @param string $method
  41. * @param array $parameters
  42. * @return mixed
  43. */
  44. public function __call($method, $parameters)
  45. {
  46. if (method_exists($this->getTaxFee(), $method)) {
  47. return $this->getTaxFee()->$method($parameters);
  48. }
  49. return parent::__call($method, $parameters); // TODO: Change the autogenerated stub
  50. }
  51. public function getCheckedAttribute()
  52. {
  53. return $this->getTaxFee()->isChecked();
  54. }
  55. public function getShowAttribute()
  56. {
  57. return $this->getTaxFee()->isShow();
  58. }
  59. public function getShowNameAttribute()
  60. {
  61. return $this->getTaxFee()->getShowName();
  62. }
  63. /**
  64. * @return bool
  65. */
  66. public function beforeSaving()
  67. {
  68. if (!$this->getTaxFee()->isChecked()) {
  69. return false;
  70. }
  71. return parent::beforeSaving();
  72. }
  73. }