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; }); }
public function success($money = 0) { $userRecharge = $this; return DB::transaction(function () use($userRecharge, $money) { $user = User::find($userRecharge->user_id); if (!$user) { throw new Exception("用户不存在", 1000); } $userRecharge->status = 1; if (!$userRecharge->save()) { throw new Exception("确认失败", 1002); } $cashFlow = CashFlow::add($user, $userRecharge, $money, $type = 1); if (!$cashFlow) { throw new Exception("写入流水失败", 1001); } $r = $user->addCash($money); if (!$r) { throw new Exception("用户增加余额失败", 1003); } return true; }); }