Commit 2f5c3d49 2f5c3d49606f6638e9befeb0292cc75763f66707 by lemon

拆账

1 parent 6957ea96
......@@ -21,6 +21,8 @@ class ErrorCode
const WITHDRAW_HANDLE_ERROR = 40052;
const WITHDRAW_CONFIRM_BILLS_FAIL = 40053;
const WITHDRAW_APPLY_FAIL = 40054;
const WITHDRAW_FAIL = 40055;
......@@ -42,6 +44,7 @@ class ErrorCode
self::WITHDRAW_HANDLE_ERROR => '提现操作失败',
self::WITHDRAW_CONFIRM_BILLS_FAIL => '确认账单失败',
self::WITHDRAW_APPLY_FAIL => '提现申请失败',
self::WITHDRAW_FAIL => '提现失败',
];
......
......@@ -66,6 +66,40 @@ class WithdrawService extends Service implements WithdrawInterface
public function success(StakeholderIncomeSyncApp $app)
{
$condition = $this->compose($app);
DB::beginTransaction();
try {
//修改状态-》提现中 -> 提现完成
StakeholderIncomeSyncApp::query()->where(['serial_no'=>$app->serial_no, 'identifier'=>$this->identifier->identifier, 'sync_status'=>1, 'withdraw_status'=>2])->update([
'withdraw_status'=>3
]);
//修改资金账户
StakeholderBalanceByPayer::query()->where(['condition'=>$condition])->where('freeze', '>=', $app->total_money)->update([
'freeze' => DB::raw("freeze - {$app->total_money}"),
'pay_out'=> DB::raw("pay_out + {$app->total_money}"),
]);
//提现申请日志
StakeholderWithdrawAppLogs::query()->create([
'serial_no' => $app->serial_no,
'identifier' => $this->identifier->identifier,
'type' => __FUNCTION__,
'withdraw_money' => $app->total_money,
]);
DB::commit();
return Response::success();
} catch (\Exception $e) {
DB::rollBack();
Log::channel('api')->error(__METHOD__, ['msg'=>$e->getMessage()]);
return Response::error(ErrorCode::WITHDRAW_APPLY_FAIL);
}
}
/**
......@@ -75,6 +109,38 @@ class WithdrawService extends Service implements WithdrawInterface
public function fail(StakeholderIncomeSyncApp $app)
{
$condition = $this->compose($app);
DB::beginTransaction();
try {
//修改状态-》提现中 -》 已确认
StakeholderIncomeSyncApp::query()->where(['serial_no'=>$app->serial_no, 'identifier'=>$this->identifier->identifier, 'sync_status'=>1, 'withdraw_status'=>2])->update([
'withdraw_status'=>1
]);
//修改资金账户
StakeholderBalanceByPayer::query()->where(['condition'=>$condition])->where('freeze', '>=', $app->total_money)->update([
'freeze' => DB::raw("freeze - {$app->total_money}"),
'balance'=> DB::raw("balance + {$app->total_money}"),
]);
//提现申请日志
StakeholderWithdrawAppLogs::query()->create([
'serial_no' => $app->serial_no,
'identifier' => $this->identifier->identifier,
'type' => __FUNCTION__,
'withdraw_money' => $app->total_money,
]);
DB::commit();
return Response::success();
} catch (\Exception $e) {
DB::rollBack();
Log::channel('api')->error(__METHOD__, ['msg'=>$e->getMessage()]);
return Response::error();
}
}
/**
......