拆账
Showing
2 changed files
with
69 additions
and
0 deletions
| ... | @@ -21,6 +21,8 @@ class ErrorCode | ... | @@ -21,6 +21,8 @@ class ErrorCode |
| 21 | const WITHDRAW_HANDLE_ERROR = 40052; | 21 | const WITHDRAW_HANDLE_ERROR = 40052; |
| 22 | const WITHDRAW_CONFIRM_BILLS_FAIL = 40053; | 22 | const WITHDRAW_CONFIRM_BILLS_FAIL = 40053; |
| 23 | const WITHDRAW_APPLY_FAIL = 40054; | 23 | const WITHDRAW_APPLY_FAIL = 40054; |
| 24 | const WITHDRAW_FAIL = 40055; | ||
| 25 | |||
| 24 | 26 | ||
| 25 | 27 | ||
| 26 | 28 | ||
| ... | @@ -42,6 +44,7 @@ class ErrorCode | ... | @@ -42,6 +44,7 @@ class ErrorCode |
| 42 | self::WITHDRAW_HANDLE_ERROR => '提现操作失败', | 44 | self::WITHDRAW_HANDLE_ERROR => '提现操作失败', |
| 43 | self::WITHDRAW_CONFIRM_BILLS_FAIL => '确认账单失败', | 45 | self::WITHDRAW_CONFIRM_BILLS_FAIL => '确认账单失败', |
| 44 | self::WITHDRAW_APPLY_FAIL => '提现申请失败', | 46 | self::WITHDRAW_APPLY_FAIL => '提现申请失败', |
| 47 | self::WITHDRAW_FAIL => '提现失败', | ||
| 45 | ]; | 48 | ]; |
| 46 | 49 | ||
| 47 | 50 | ... | ... |
| ... | @@ -66,6 +66,40 @@ class WithdrawService extends Service implements WithdrawInterface | ... | @@ -66,6 +66,40 @@ class WithdrawService extends Service implements WithdrawInterface |
| 66 | public function success(StakeholderIncomeSyncApp $app) | 66 | public function success(StakeholderIncomeSyncApp $app) |
| 67 | { | 67 | { |
| 68 | $condition = $this->compose($app); | 68 | $condition = $this->compose($app); |
| 69 | |||
| 70 | DB::beginTransaction(); | ||
| 71 | |||
| 72 | try { | ||
| 73 | |||
| 74 | //修改状态-》提现中 -> 提现完成 | ||
| 75 | StakeholderIncomeSyncApp::query()->where(['serial_no'=>$app->serial_no, 'identifier'=>$this->identifier->identifier, 'sync_status'=>1, 'withdraw_status'=>2])->update([ | ||
| 76 | 'withdraw_status'=>3 | ||
| 77 | ]); | ||
| 78 | |||
| 79 | //修改资金账户 | ||
| 80 | StakeholderBalanceByPayer::query()->where(['condition'=>$condition])->where('freeze', '>=', $app->total_money)->update([ | ||
| 81 | 'freeze' => DB::raw("freeze - {$app->total_money}"), | ||
| 82 | 'pay_out'=> DB::raw("pay_out + {$app->total_money}"), | ||
| 83 | ]); | ||
| 84 | |||
| 85 | //提现申请日志 | ||
| 86 | StakeholderWithdrawAppLogs::query()->create([ | ||
| 87 | 'serial_no' => $app->serial_no, | ||
| 88 | 'identifier' => $this->identifier->identifier, | ||
| 89 | 'type' => __FUNCTION__, | ||
| 90 | 'withdraw_money' => $app->total_money, | ||
| 91 | ]); | ||
| 92 | |||
| 93 | DB::commit(); | ||
| 94 | return Response::success(); | ||
| 95 | |||
| 96 | } catch (\Exception $e) { | ||
| 97 | DB::rollBack(); | ||
| 98 | Log::channel('api')->error(__METHOD__, ['msg'=>$e->getMessage()]); | ||
| 99 | return Response::error(ErrorCode::WITHDRAW_APPLY_FAIL); | ||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 69 | } | 103 | } |
| 70 | 104 | ||
| 71 | /** | 105 | /** |
| ... | @@ -75,6 +109,38 @@ class WithdrawService extends Service implements WithdrawInterface | ... | @@ -75,6 +109,38 @@ class WithdrawService extends Service implements WithdrawInterface |
| 75 | public function fail(StakeholderIncomeSyncApp $app) | 109 | public function fail(StakeholderIncomeSyncApp $app) |
| 76 | { | 110 | { |
| 77 | $condition = $this->compose($app); | 111 | $condition = $this->compose($app); |
| 112 | |||
| 113 | DB::beginTransaction(); | ||
| 114 | |||
| 115 | try { | ||
| 116 | |||
| 117 | //修改状态-》提现中 -》 已确认 | ||
| 118 | StakeholderIncomeSyncApp::query()->where(['serial_no'=>$app->serial_no, 'identifier'=>$this->identifier->identifier, 'sync_status'=>1, 'withdraw_status'=>2])->update([ | ||
| 119 | 'withdraw_status'=>1 | ||
| 120 | ]); | ||
| 121 | |||
| 122 | //修改资金账户 | ||
| 123 | StakeholderBalanceByPayer::query()->where(['condition'=>$condition])->where('freeze', '>=', $app->total_money)->update([ | ||
| 124 | 'freeze' => DB::raw("freeze - {$app->total_money}"), | ||
| 125 | 'balance'=> DB::raw("balance + {$app->total_money}"), | ||
| 126 | ]); | ||
| 127 | |||
| 128 | //提现申请日志 | ||
| 129 | StakeholderWithdrawAppLogs::query()->create([ | ||
| 130 | 'serial_no' => $app->serial_no, | ||
| 131 | 'identifier' => $this->identifier->identifier, | ||
| 132 | 'type' => __FUNCTION__, | ||
| 133 | 'withdraw_money' => $app->total_money, | ||
| 134 | ]); | ||
| 135 | |||
| 136 | DB::commit(); | ||
| 137 | return Response::success(); | ||
| 138 | |||
| 139 | } catch (\Exception $e) { | ||
| 140 | DB::rollBack(); | ||
| 141 | Log::channel('api')->error(__METHOD__, ['msg'=>$e->getMessage()]); | ||
| 142 | return Response::error(); | ||
| 143 | } | ||
| 78 | } | 144 | } |
| 79 | 145 | ||
| 80 | /** | 146 | /** | ... | ... |
-
Please register or sign in to post a comment