admin/app/frontend/models/order/PreOrderTaxFee.php

86 lines
2.1 KiB
PHP

<?php
namespace app\frontend\models\order;
use app\common\models\order\OrderTaxFee;
use app\frontend\models\Order;
use app\frontend\modules\order\models\PreOrder;
use app\frontend\modules\order\taxFee\BaseOrderTaxFee;
class PreOrderTaxFee extends OrderTaxFee
{
protected $appends = ['checked', 'show','show_name'];
/**
* @var Order
*/
public $order;
/**
* @var BaseOrderTaxFee
*/
protected $taxFee;
public function init(BaseOrderTaxFee $taxFee, PreOrder $order)
{
$this->taxFee = $taxFee;
$this->setOrder($order);
}
public function setOrder(PreOrder $order)
{
$this->order = $order;
$this->uniacid = \YunShop::app()->uniacid;
$this->uid = $order->uid;
$this->fee_code = $this->getTaxFee()->getCode();
$this->name = $this->getTaxFee()->getName();
$this->rate = $this->getTaxFee()->getRate();
$this->amount = sprintf('%.2f', $this->getTaxFee()->getAmount());
$order->orderTaxFees->push($this);
}
public function getTaxFee()
{
return $this->taxFee;
}
/**
* 调用当前类不存在方法时 查询 BaseOrderTaxFee 类存在代替处理
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
if (method_exists($this->getTaxFee(), $method)) {
return $this->getTaxFee()->$method($parameters);
}
return parent::__call($method, $parameters); // TODO: Change the autogenerated stub
}
public function getCheckedAttribute()
{
return $this->getTaxFee()->isChecked();
}
public function getShowAttribute()
{
return $this->getTaxFee()->isShow();
}
public function getShowNameAttribute()
{
return $this->getTaxFee()->getShowName();
}
/**
* @return bool
*/
public function beforeSaving()
{
if (!$this->getTaxFee()->isChecked()) {
return false;
}
return parent::beforeSaving();
}
}