public function setFailure($user) { $withdraw = $this; return DB::transaction(function () use($withdraw, $user) { $cashflow = CashFlow::userCashesIn($user, $withdraw, $withdraw->money, 2, '提现失败'); if (!$cashflow) { throw new Exception("写入流水失败", 1); } if (!$user->addCash($withdraw->money)) { throw new Exception("增加余额失败", 1); } $withdraw->status = 4; if (!$withdraw->save()) { throw new Exception("状态错误", 1); } return true; }); }