public function cancel($msg = null)
{
$this->beforeCancel();
$transaction = Yii::$app->db->beginTransaction();
try {
$this->status = self::STATUS_CANCELLED;
$this->cancelled_msg = $msg;
if (!$this->save(false)) {
throw new \Exception('订单错误!');
}
foreach ($this->goods as $goods) {
if (!$goods->goods->moveSurplus(+$goods->count, "取消订单:{$this->order_sn}。")) {
throw new \Exception('订单商品错误!');
}
}
$transaction->commit();
$this->afterCancel();
return true;
} catch (\Exception $e) {
$transaction->rollBack();
return false;
}
}