WithdrawService.php
2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace App\Services;
use App\ApiInterface\WithdrawInterface;
use App\Helper\ErrorCode;
use App\Helper\Response;
use App\Models\Legal\StakeholderBalanceByPayer;
use App\Models\Legal\StakeholderIncomeSyncApp;
use App\Models\Legal\StakeholderWithdrawAppLogs;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
/**
* Class MusicianAgreementService
* @package App\Services
*/
class WithdrawService extends Service implements WithdrawInterface
{
/**
* 提现申请
* @param StakeholderIncomeSyncApp $app
*/
public function advance(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'=>1])->update([
'withdraw_status'=>2
]);
//修改资金账户
StakeholderBalanceByPayer::query()->where(['condition'=>$condition])->where('balance', '>=', $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(ErrorCode::WITHDRAW_APPLY_FAIL);
}
}
/**
* 提现成功
* @param StakeholderIncomeSyncApp $app
*/
public function success(StakeholderIncomeSyncApp $app)
{
$condition = $this->compose($app);
}
/**
* 提现失败
* @param StakeholderIncomeSyncApp $app
*/
public function fail(StakeholderIncomeSyncApp $app)
{
$condition = $this->compose($app);
}
/**
* @param StakeholderIncomeSyncApp $app
* @return string
*/
private function compose(StakeholderIncomeSyncApp $app)
{
return $app->stakeholder_id .'|'. $app->subject_no;
}
}