public function complete() { $this->beforeComplete(); $transaction = Yii::$app->db->beginTransaction(); try { $this->status = self::STATUS_COMPLETED; $this->clearCancelledMsg(); if (!$this->save(false)) { throw new \Exception('订单错误!'); } $orderVolume = new OrderVolume(); $orderVolume->volume = $this->real_fee; $orderVolume->cost = $this->cost; $orderVolume->profit = bcsub($this->real_fee, $this->cost, 4); $orderVolume->order_id = $this->id; $orderVolume->payment = $this->payment; $orderVolume->user_id = $this->user_id; $orderVolume->store_id = $this->store_id; if (!$orderVolume->save(false)) { throw new \Exception('记录交易错误!'); } $transaction->commit(); $this->afterComplete(); return true; } catch (\Exception $e) { $transaction->rollBack(); return false; } }