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(); } }