MusicianWithdrawService.php
4.74 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace App\Services;
use App\Helper\ErrorCode;
use App\Helper\Response;
use App\Models\Legal\Company;
use App\Models\Legal\Contract;
use App\Models\Legal\StakeholderIncomeByPayer;
use App\Models\Legal\StakeholderSongCollate;
/**
* Class MusicianAgreementService
* @package App\Services
*/
class MusicianWithdrawService extends Service
{
/**
* 返回账单详情
* @return \Illuminate\Http\JsonResponse
*/
public function walletDetail()
{
$income_by_payer = StakeholderIncomeByPayer::query()->where(['busi_id'=>$this->request->input('busi_id'), 'sync_status'=>1])->first();
if (empty($income_by_payer)) return Response::error(ErrorCode::ORDER_NO_FOUND);
$collate = StakeholderSongCollate::query()->with('song:id,name,singer')->where([
'bills_id'=>$income_by_payer->related_id, 'subject_no'=>$income_by_payer->subject_no])
->select(['song_id', 'role', 'cost_amount', 'deduct_amount', 'real_share_amount'])->paginate($this->pageSize);
foreach ($collate as &$item) {
$item->setAttribute('role', Contract::transformRole($item->role));
}
return Response::success($collate);
}
/**
* 发票信息 - 通过名字
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function receiptInfoByName()
{
/*
if (!StakeholderIncomeByPayer::query()->where(['sync_status'=>1, 'withdraw_status'=>0, 'identifier'=>$this->identifier->identifier])->count()) {
return Response::error(ErrorCode::WITHDRAW_NO_RECORD);
}
*/
if ($receipt = Company::query()->where(['receipt_name'=>$this->request->input('name')])->first()) {
return Response::success([
'receipt_type'=>$receipt->receipt_type,
'receipt_consignee'=>$receipt->receipt_consignee,
'receipt_name'=>$receipt->receipt_name,
'receipt_no' =>$receipt->receipt_no,
'receipt_tel' =>$receipt->receipt_tel,
'receipt_address'=>$receipt->receipt_address,
'receipt_bank'=>$receipt->receipt_bank,
'receipt_bank_no'=>$receipt->receipt_bank_no,
]);
} else {
return Response::error();
}
}
/**
* 发票信息 - 通过流水号
* @return \Illuminate\Http\JsonResponse
*/
public function receiptInfo()
{
$receipt = [];
StakeholderIncomeByPayer::query()->with('company:company_id,receipt_type,receipt_name,receipt_no,receipt_tel,receipt_address,receipt_bank,receipt_bank_no')
->where(['identifier'=>$this->identifier->identifier, 'sync_status'=>1])->whereIn('serial_no', $this->request->input('serial_no'))->select(['id', 'company_id', 'serial_no', 'busi_id'])->get()->map(function ($item) use (&$receipt) {
if (!empty($item->company->company_id)) {
$receipt[$item->company->company_id] = [
'receipt_type'=>$item->company->receipt_type,
'receipt_name'=>$item->company->receipt_name,
'receipt_no' =>$item->company->receipt_no,
'receipt_tel' =>$item->company->receipt_tel,
'receipt_address'=>$item->company->receipt_address,
'receipt_bank'=>$item->company->receipt_bank,
'receipt_bank_no'=>$item->company->receipt_bank_no,
];
}
return $receipt;
});
return Response::success(array_values($receipt));
}
/**
* 修改提现状态
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function changeStatus()
{
$withdraw_status = '';
$query = StakeholderIncomeByPayer::query()->where(['sync_status'=>1, 'identifier'=>$this->identifier->identifier])
->whereIn('serial_no', $this->request->input('serial_no'));
switch ($this->request->input('type')) {
case 'fail':
$withdraw_status = 0;
$query = $query->where(['withdraw_status'=>1]);
break;
case 'advance':
$withdraw_status = 1;
$query = $query->where(['withdraw_status'=>0]);
break;
case 'success':
$withdraw_status = 2;
$query = $query->where(['withdraw_status'=>1]);
break;
}
if ($query->update(['withdraw_status'=>$withdraw_status])) {
return Response::success();
} else {
return Response::error();
}
}
}