| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020/8/21
- * Time: 9:50
- */
- namespace app\frontend\models\order;
- use app\common\models\order\OrderServiceFee;
- use app\frontend\modules\order\models\PreOrder;
- use app\frontend\modules\order\serviceFee\BaseOrderServiceFee;
- class PreOrderServiceFee extends OrderServiceFee
- {
- protected $appends = ['checked', 'show'];
- /**
- * @var PreOrder
- */
- public $order;
- /**
- * @var BaseOrderServiceFee
- */
- protected $serviceFee;
- public function init(BaseOrderServiceFee $serviceFee, PreOrder $order)
- {
- $this->serviceFee = $serviceFee;
- $this->setOrder($order);
- }
- public function setOrder(PreOrder $order)
- {
- $this->order = $order;
- $this->order->orderServiceFees->push($this);
- }
- public function getServiceFee()
- {
- return $this->serviceFee;
- }
- public function getUidAttribute()
- {
- return $this->order->uid;
- }
- public function getCodeAttribute()
- {
- return $this->getServiceFee()->getCode();
- }
- public function getNameAttribute()
- {
- return $this->getServiceFee()->getName();
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- public function getAmountAttribute()
- {
- return $this->getServiceFee()->getAmount();
- }
- /**
- * 调用当前类不存在方法时 查询 BaseOrderServiceFee 类存在代替处理
- * @param string $method
- * @param array $parameters
- * @return mixed
- */
- public function __call($method, $parameters)
- {
- if (method_exists($this->getServiceFee(), $method)) {
- return $this->getServiceFee()->$method($parameters);
- }
- return parent::__call($method, $parameters); // TODO: Change the autogenerated stub
- }
- /**
- * @return mixed
- * @throws \app\common\exceptions\AppException
- */
- // public function getAmount()
- // {
- //
- // return $this->getServiceFee()->getAmount();
- // }
- /**
- * @return bool
- */
- public function getCheckedAttribute()
- {
- return $this->getServiceFee()->isChecked();
- }
- /**
- * @return bool
- */
- public function getShowAttribute()
- {
- return $this->getServiceFee()->isShow();
- }
- /**
- * @return array
- */
- public function toArray()
- {
- $this->code = (string)$this->code;
- $this->name = (string)$this->name;
- $this->amount = sprintf('%.2f', $this->amount);
- return parent::toArray();
- }
- /**
- * @return bool
- */
- public function beforeSaving()
- {
- if (!$this->getServiceFee()->isChecked()) {
- return false;
- }
- $this->uid = (string)$this->uid;
- $this->code = (string)$this->code;
- $this->name = (string)$this->name;
- $this->amount = sprintf('%.2f', $this->amount);
- return parent::beforeSaving();
- }
- }
|