Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Cong.Zhao
/
musician-api.hikoon.com
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
c28dab40
...
c28dab40729c8d8903d413ea2e9a6775bb6f232a
authored
2021-08-21 19:22:42 +0800
by
lemon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
*
1 parent
cb6ed517
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
178 additions
and
148 deletions
app/Helper/Response.php
app/Http/Controllers/Musician/MusicianWithdrawController.php
app/Http/Requests/Musician/MusicianWithdrawReceiptRequest.php
app/Http/Requests/Musician/MusicianWithdrawStatusRequest.php
app/Models/Legal/StakeholderIncomeByPayer.php
app/Services/MusicianWithdrawService.php
routes/api.php
app/Helper/Response.php
View file @
c28dab4
...
...
@@ -21,7 +21,7 @@ class Response
{
return
response
()
->
json
([
'code'
=>
ErrorCode
::
SERVER_OK
,
'data'
=>
$data
instanceof
LengthAwarePaginator
?
self
::
paginator
(
$data
)
:
$data
'data'
=>
$data
instanceof
LengthAwarePaginator
?
self
::
paginator
(
$data
)
:
$data
]);
}
...
...
app/Http/Controllers/Musician/MusicianWithdrawController.php
View file @
c28dab4
...
...
@@ -3,9 +3,15 @@
namespace
App\Http\Controllers\Musician
;
use
App\Http\Controllers\Controller
;
use
App\Http\Requests\Musician\MusicianWithdrawReceiptRequest
;
use
App\Http\Requests\Musician\MusicianWithdrawRequest
;
use
App\Http\Requests\Musician\MusicianWithdrawStatusRequest
;
use
App\Services\MusicianWithdrawService
;
/**
* Class MusicianWithdrawController
* @package App\Http\Controllers\Musician
*/
class
MusicianWithdrawController
extends
Controller
{
/**
...
...
@@ -23,12 +29,20 @@ class MusicianWithdrawController extends Controller
}
/**
*
冻结资金
*
发票信息
* @return \Illuminate\Http\JsonResponse
*/
public
function
prepare
(
MusicianWithdrawRequest
$musicianWithdrawR
equest
)
public
function
receipt
(
MusicianWithdrawReceiptRequest
$r
equest
)
{
return
$this
->
musicianWithdrawService
->
prepare
();
return
$this
->
musicianWithdrawService
->
receiptInfo
();
}
/**
* 提现修改状态
* @return \Illuminate\Http\JsonResponse
*/
public
function
status
(
MusicianWithdrawStatusRequest
$request
)
{
return
$this
->
musicianWithdrawService
->
changeStatus
();
}
}
...
...
app/Http/Requests/Musician/MusicianWithdrawReceiptRequest.php
0 → 100644
View file @
c28dab4
<?php
namespace
App\Http\Requests\Musician
;
use
Illuminate\Foundation\Http\FormRequest
;
class
MusicianWithdrawReceiptRequest
extends
FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
'serial_no'
=>
[
'required'
,
'bail'
,
'array'
,
'filled'
],
];
}
/**
* @return string[]
*/
public
function
messages
()
:
array
{
return
[
'serial_no.required'
=>
'请提供流水号'
,
];
}
}
app/Http/Requests/Musician/MusicianWithdrawStatusRequest.php
0 → 100644
View file @
c28dab4
<?php
namespace
App\Http\Requests\Musician
;
use
Illuminate\Foundation\Http\FormRequest
;
/**
* Class MusicianWithdrawStatusRequest
* @package App\Http\Requests\Musician
*/
class
MusicianWithdrawStatusRequest
extends
FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public
function
authorize
()
{
return
true
;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public
function
rules
()
{
return
[
'serial_no'
=>
[
'required'
,
'bail'
,
'array'
,
'filled'
],
'type'
=>
[
'required'
,
'bail'
,
'in:success,fail,advance'
],
];
}
/**
* @return string[]
*/
public
function
messages
()
:
array
{
return
[
'serial_no.required'
=>
'请提供流水号'
,
'type.required'
=>
'请提供有效的提现状态变更'
,
];
}
}
app/Models/Legal/StakeholderIncomeByPayer.php
0 → 100644
View file @
c28dab4
<?php
namespace
App\Models\Legal
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
use
Illuminate\Database\Eloquent\Model
;
/**
* 进账收益流水
* Class StakeholderIncomeByPayer
* @package App\Models\Legal
*/
class
StakeholderIncomeByPayer
extends
Model
{
use
HasFactory
;
public
$table
=
'stakeholder_income_by_payer'
;
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public
function
company
()
{
return
$this
->
belongsTo
(
Company
::
class
,
'company_id'
,
'company_id'
);
}
}
app/Services/MusicianWithdrawService.php
View file @
c28dab4
...
...
@@ -3,13 +3,8 @@
namespace
App\Services
;
use
App\Helper\ErrorCode
;
use
App\Helper\RedisClient
;
use
App\Helper\Response
;
use
App\Models\Legal\StakeholderBalance
;
use
App\Models\Legal\StakeholderBalanceByPayer
;
use
App\Models\Musician\CashOutOrder
;
use
Illuminate\Support\Facades\DB
;
use
App\Models\Legal\StakeholderIncomeByPayer
;
/**
* Class MusicianAgreementService
...
...
@@ -18,154 +13,60 @@ use Illuminate\Support\Facades\DB;
class
MusicianWithdrawService
extends
Service
{
/**
*
冻结资金
*
发票信息
* @return \Illuminate\Http\JsonResponse
*/
public
function
prepare
()
public
function
receiptInfo
()
{
$order_id
=
$this
->
request
->
input
(
'order_id'
);
if
(
!
RedisClient
::
instance
()
->
set
(
str_replace
(
'#order#'
,
$order_id
,
config
(
'cachekey.withdraw.prepare'
)),
true
,
"nx"
,
"ex"
,
3
))
{
return
Response
::
error
(
ErrorCode
::
REPEAT_SUBMIT
);
}
$order
=
CashOutOrder
::
query
()
->
where
([
'order_id'
=>
$order_id
,
'withdraw_state'
=>
CashOutOrder
::
WITHDRAW_STATE_DEFAULT
,
'status'
=>
CashOutOrder
::
STATUS_WAIT
])
->
first
();
//订单非法
if
(
empty
(
$order
))
return
Response
::
error
(
ErrorCode
::
ORDER_ILLEGAl
);
if
(
empty
(
$order
->
balance_detail
))
return
Response
::
error
(
ErrorCode
::
ORDER_WITHDRAW_ERROR
);
if
(
empty
(
$order
->
cash_out_money
))
return
Response
::
error
(
ErrorCode
::
ORDER_MONEY_ERROR
);
Db
::
beginTransaction
();
try
{
//付款方集合
foreach
(
$order
->
balance_detail
[
'detail'
]
as
$item
)
{
//付款方账户
StakeholderBalanceByPayer
::
query
()
->
where
([
'stakeholder_id'
=>
$item
[
'stakeholderId'
],
'subject_no'
=>
$item
[
'no'
]])
->
where
(
'balance'
,
'>='
,
$item
[
'balance'
])
->
update
([
'balance'
=>
Db
::
raw
(
"balance -
{
$item
[
'balance'
]
}
"
),
'freeze'
=>
Db
::
raw
(
"freeze +
{
$item
[
'balance'
]
}
"
),
]);
//总账户
StakeholderBalance
::
query
()
->
where
([
'stakeholder_id'
=>
$item
[
'stakeholderId'
]])
->
where
(
'balance'
,
'>='
,
$item
[
'balance'
])
->
update
([
'balance'
=>
Db
::
raw
(
"balance -
{
$item
[
'balance'
]
}
"
),
'freeze'
=>
Db
::
raw
(
"freeze +
{
$item
[
'balance'
]
}
"
),
]);
}
CashOutOrder
::
query
()
->
where
([
'order_id'
=>
$order_id
,
'withdraw_state'
=>
CashOutOrder
::
WITHDRAW_STATE_DEFAULT
,
'status'
=>
CashOutOrder
::
STATUS_WAIT
])
->
update
([
'withdraw_state'
=>
CashOutOrder
::
WITHDRAW_STATE_WAIT
,
]);
DB
::
commit
();
return
Response
::
success
([
'order_id'
=>
$order
->
order_id
]);
}
catch
(
\Exception
$e
)
{
DB
::
rollBack
();
return
Response
::
error
();
}
$receipt
=
[];
StakeholderIncomeByPayer
::
query
()
->
with
(
'company:company_id,receipt_name,receipt_no,receipt_tel,receipt_address,receipt_bank,receipt_bank_no'
)
->
whereIn
(
'serial_no'
,
$this
->
request
->
input
(
'serial_no'
))
->
get
()
->
map
(
function
(
$item
)
use
(
&
$receipt
)
{
if
(
!
empty
(
$item
->
company
))
{
$receipt
[
$item
->
company_id
]
=
[
'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
(
$receipt
);
}
/**
*
后台提现
* @return \Illuminate\Http\JsonResponse
*
修改提现状态
* @return \Illuminate\Http\JsonResponse
|mixed
*/
public
function
withdraw
()
public
function
changeStatus
()
{
$order_id
=
$this
->
request
->
input
(
'order_id'
);
if
(
!
RedisClient
::
instance
()
->
set
(
str_replace
(
'#order#'
,
$order_id
,
config
(
'cachekey.withdraw.audit'
)),
true
,
"nx"
,
"ex"
,
3
))
{
return
Response
::
error
(
ErrorCode
::
REPEAT_SUBMIT
);
$withdraw_status
=
''
;
switch
(
$this
->
request
->
input
(
'type'
))
{
case
'fail'
:
$withdraw_status
=
0
;
break
;
case
'advance'
:
$withdraw_status
=
1
;
break
;
case
'success'
:
$withdraw_status
=
2
;
break
;
}
$order
=
CashOutOrder
::
query
()
->
where
([
'order_id'
=>
$order_id
,
'withdraw_state'
=>
CashOutOrder
::
WITHDRAW_STATE_WAIT
,
'status'
=>
$this
->
request
->
input
(
'status'
)])
->
first
();
//订单非法
if
(
empty
(
$order
))
return
Response
::
error
(
ErrorCode
::
ORDER_ILLEGAl
);
if
(
empty
(
$order
->
balance_detail
))
return
Response
::
error
(
ErrorCode
::
ORDER_WITHDRAW_ERROR
);
Db
::
beginTransaction
();
try
{
switch
(
intval
(
$this
->
request
->
input
(
'status'
)))
{
case
1
:
//审核通过
$this
->
withdrawAuditSuccess
(
$order
);
break
;
case
2
:
//审核失败
$this
->
withdrawAuditFail
(
$order
);
break
;
}
CashOutOrder
::
query
()
->
where
([
'order_id'
=>
$order_id
,
'withdraw_state'
=>
CashOutOrder
::
WITHDRAW_STATE_WAIT
,
'status'
=>
$this
->
request
->
input
(
'status'
)])
->
update
([
'withdraw_state'
=>
$this
->
request
->
input
(
'status'
)
]);
Db
::
commit
();
if
(
StakeholderIncomeByPayer
::
query
()
->
whereIn
(
'serial_no'
,
$this
->
request
->
input
(
'serial_no'
))
->
update
([
'withdraw_status'
=>
$withdraw_status
,
]))
{
return
Response
::
success
();
}
catch
(
\Exception
$e
)
{
Db
::
rollBack
();
return
Response
::
error
(
ErrorCode
::
WITHDRAW_HANDLE_ERROR
);
}
}
/**
* 提现审核成功
* @param CashOutOrder $order
*/
private
function
withdrawAuditSuccess
(
CashOutOrder
$order
)
{
foreach
(
$order
->
balance_detail
[
'detail'
]
as
$item
)
{
//付款方维度
StakeholderBalanceByPayer
::
query
()
->
where
([
'stakeholder_id'
=>
$item
[
'stakeholderId'
],
'subject_no'
=>
$item
[
'no'
]])
->
where
(
'freeze'
,
'>='
,
$item
[
'balance'
])
->
update
([
'freeze'
=>
Db
::
raw
(
"freeze -
{
$item
[
'balance'
]
}
"
),
'pay_out'
=>
Db
::
raw
(
"pay_out +
{
$item
[
'balance'
]
}
"
),
]);
//修改总的资金账户
StakeholderBalance
::
query
()
->
where
([
'stakeholder_id'
=>
$item
[
'stakeholderId'
]])
->
where
(
'freeze'
,
'>='
,
$item
[
'balance'
])
->
update
([
'freeze'
=>
Db
::
raw
(
"freeze -
{
$item
[
'balance'
]
}
"
),
'pay_out'
=>
Db
::
raw
(
"pay_out +
{
$item
[
'balance'
]
}
"
),
]);
}
}
/**
* 提现审核失败
* @param CashOutOrder $order
*/
private
function
withdrawAuditFail
(
CashOutOrder
$order
)
{
foreach
(
$order
->
balance_detail
[
'detail'
]
as
$item
)
{
StakeholderBalanceByPayer
::
query
()
->
where
([
'stakeholder_id'
=>
$item
[
'stakeholderId'
],
'subject_no'
=>
$item
[
'no'
]])
->
where
(
'freeze'
,
'>='
,
$item
[
'balance'
])
->
update
([
'freeze'
=>
Db
::
raw
(
"freeze -
{
$item
[
'balance'
]
}
"
),
'balance'
=>
Db
::
raw
(
"balance +
{
$item
[
'balance'
]
}
"
),
]);
StakeholderBalance
::
query
()
->
where
([
'stakeholder_id'
=>
$item
[
'stakeholderId'
]])
->
where
(
'freeze'
,
'>='
,
$item
[
'balance'
])
->
update
([
'freeze'
=>
Db
::
raw
(
"freeze -
{
$item
[
'balance'
]
}
"
),
'balance'
=>
Db
::
raw
(
"balance +
{
$item
[
'balance'
]
}
"
),
]);
}
else
{
return
Response
::
error
();
}
}
}
...
...
routes/api.php
View file @
c28dab4
...
...
@@ -34,7 +34,10 @@ Route::group([], function (){
Route
::
get
(
'musician_balance/account'
,
'MusicianBalanceController@account'
);
//钱包-账户详情
Route
::
get
(
'musician_balance/account_detail'
,
'MusicianBalanceController@accountDetail'
);
//提现请求
Route
::
post
(
'musician/withdraw_prepare'
,
'MusicianWithdrawController@prepare'
);
//提现发票抬头
Route
::
post
(
'/withdraw/receipt'
,
'MusicianWithdrawController@receipt'
);
//账单状态修改
Route
::
post
(
'/withdraw/status'
,
'MusicianWithdrawController@status'
);
});
...
...
Please
register
or
sign in
to post a comment