MusicianBalanceService.php
3.27 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
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace App\Services;
use App\Helper\Response;
use App\Models\Legal\StakeholderBalance;
use App\Models\Legal\StakeholderBalanceByPayer;
use App\Models\Musician\CashOutOrder;
use App\Traits\TaxReckon;
/**
* Class MusicianAgreementService
* @package App\Services
*/
class MusicianBalanceService extends Service
{
use TaxReckon;
/**
* 账户详情
* @return \Illuminate\Http\JsonResponse
*/
public function account()
{
//数据初始化
$account = [
'cash_total' => '0.00',
'balance' => '0.00',
'advance_out' => '0.00',
'remain_prepaid'=> '0.00',
];
//累计提现
$account['cash_total'] = CashOutOrder::query()->where(['cash_out_uid'=>$this->request->input('cash_out_uid'), 'status'=>1, 'withdraw_state'=>1])->sum('cash_out_money');
//预付
$advance = StakeholderBalance::query()->identify()->select(['advance_out', 'remain_prepaid'])->get();
foreach ($advance as $item) {
$account['advance_out'] = bcadd($account['advance_out'], $item->advance_out, self::DECIMAL);
$account['remain_prepaid'] = bcadd($account['remain_prepaid'], $item->remain_prepaid, self::DECIMAL);
}
//计算可提现收益
$payer = StakeholderBalanceByPayer::query()->identify()->get();
foreach ($payer as $item) {
//计算个人所得税
$tax = ($this->identifier->type == 1) ? (string)$this->reckonPersonTax($item['balance']) : (string)0;
//税后余额
$balance = bcsub($item['balance'], $tax, Service::DECIMAL);
$account['balance'] = bcadd($balance, $account['balance'], Service::DECIMAL);
}
return Response::success($account);
}
/**
* 提现详情
* @return \Illuminate\Http\JsonResponse
*/
public function accountDetail()
{
//数据初始化
$account = [
'detail' => [],
'tax'=> '0.00',
'amount'=> '0.00',
];
$payer = StakeholderBalanceByPayer::query()->with('subject:no,name')->identify()->get();
foreach ($payer as $item) {
$tax = ($this->identifier->type == 1) ? (string)$this->reckonPersonTax($item['balance']) : (string)0;
//税后余额
$amount = (string)bcsub($item['balance'], $tax, Service::DECIMAL);
if ($amount > 0) {
//明细
$account['detail'][] = [
'payer' => $item->subject->name, //付款方
'balance' => $item['balance'], //税前提现金额
'no' => $item->subject->no, //付款方唯一标识
'tax' => $tax, //所得税
'amount' => $amount, //税后提现金额
'stakeholder_id' => $item['stakeholder_id'],
];
}
//个人所得税总和
$account['tax'] = bcadd($account['tax'], $tax, Service::DECIMAL);
//提现金额(税后)
$account['amount'] = bcadd($account['amount'], $amount, Service::DECIMAL);
}
return Response::success($account);
}
}