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
4b472f54
...
4b472f54100dd9a0f4d02d8957f65631e51dd77f
authored
2021-11-14 20:51:15 +0800
by
lemon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
发票
1 parent
bf612098
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
268 additions
and
99 deletions
app/Console/Commands/StakeholderIncomeSyncCommand.php
app/Helper/CacheKeyTools.php
app/Models/Legal/Channel.php
app/Models/Legal/StakeholderIncomeByPayer.php
app/Models/Legal/StakeholderIncomeSyncApp.php
app/Models/Legal/StakeholderIncomeSyncAppDetails.php
app/Models/Legal/StakeholderIncomeSyncLogs.php
app/Services/ApiService.php
app/Services/MusicianWithdrawService.php
app/Traits/Bills.php
config/cache.php
routes/api.php
app/Console/Commands/StakeholderIncomeSyncCommand.php
View file @
4b472f5
...
...
@@ -6,7 +6,8 @@ use App\Helper\CacheKeyTools;
use
App\Helper\RedisClient
;
use
App\Models\Legal\Bills
;
use
App\Models\Legal\Company
;
use
App\Models\Legal\StakeholderIncomeByPayer
;
use
App\Models\Legal\StakeholderIncomeSyncApp
;
use
App\Models\Legal\StakeholderIncomeSyncAppDetails
;
use
App\Services\ApiService
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -18,6 +19,8 @@ use Illuminate\Support\Facades\Log;
*/
class
StakeholderIncomeSyncCommand
extends
Command
{
use
\App\Traits\Bills
;
/**
* The name and signature of the console command.
*
...
...
@@ -36,8 +39,8 @@ class StakeholderIncomeSyncCommand extends Command
const
COUNT
=
1
;
const
BLOCK_TIME
=
1000
;
const
TYPE_BILLS
=
1001601
;
//账单分成
const
TYPE_ROYALTY
=
1001602
;
//合作伙伴打款 type = 1 版税分成
const
TYPE_BILLS
=
"1001601"
;
//账单分成
const
TYPE_ROYALTY
=
"1001602"
;
//合作伙伴打款 type = 1 版税分成
/**
* Create a new command instance.
...
...
@@ -67,59 +70,103 @@ class StakeholderIncomeSyncCommand extends Command
if
(
$msg
=
$redis
->
xread
([
$key
=>
$id
],
self
::
COUNT
,
self
::
BLOCK_TIME
))
{
$id
=
key
(
$msg
[
$key
]);
$income_item
=
$msg
[
$key
][
$id
];
Log
::
channel
(
'api'
)
->
warning
(
__METHOD__
.
"streamid:
{
$id
}
-即将处理任务"
,
[
'income_item'
=>
$income_item
]);
$company
=
Company
::
query
()
->
find
(
$income_item
[
'company_id'
]);
$bills
=
Bills
::
query
()
->
find
(
$income_item
[
'related_id'
]);
$channel
=
'TME'
;
$http_data
=
[
'busiId'
=>
$income_item
[
'serial_no'
],
'cardNo'
=>
$income_item
[
'identifier'
],
'faxMoney'
=>
$income_item
[
'fax_money'
],
'money'
=>
$income_item
[
'money'
],
'totalMoney'
=>
$income_item
[
'total_money'
],
'paymentCompany'
=>
$company
->
receipt_name
,
'type'
=>
self
::
TYPE_BILLS
,
'title'
=>
"
{
$bills
->
bill_section_start
}
-
{
$bills
->
bill_section_end
}
账单/
{
$channel
}
"
,
];
$serial_no
=
$msg
[
$key
][
$id
][
'serial_no'
];
if
(
$res
=
StakeholderIncomeByPayer
::
query
()
->
where
([
'serial_no'
=>
$income_item
[
'serial_no'
]])
->
first
())
{
Log
::
channel
(
'api'
)
->
warning
(
__METHOD__
.
"streamid:
{
$id
}
-即将处理任务"
,
[
'item'
=>
$msg
[
$key
][
$id
]]);
if
(
$res
[
'sync_status'
]
==
0
)
{
//直接未同步的数据才请求api
//获取记录
if
(
$http_data
=
$this
->
resolveSyncData
(
$serial_no
))
{
//http
$http_res
=
ApiService
::
walletAddIncome
(
$http_data
);
if
(
empty
(
$http_res
))
{
//重试 401/403/403
Log
::
channel
(
'api'
)
->
warning
(
__METHOD__
.
"streamid:
{
$id
}
-api请求失败"
,
[
'income_item'
=>
$income_item
,
'http_data'
=>
$http_data
]);
}
else
{
//成功
$update
=
[
'http_log'
=>
json_encode
(
$http_res
,
JSON_UNESCAPED_UNICODE
),
'busi_id'
=>
$http_res
[
'data'
][
'busiId'
],
];
}
if
(
$http_res
[
'code'
]
==
0
)
{
$update
[
'sync_status'
]
=
1
;
}
else
{
$update
[
'sync_status'
]
=
2
;
Log
::
channel
(
'api'
)
->
info
(
__METHOD__
,
[
'msg'
=>
'找不到需要同步的对应的收益记录'
,
'serial_no'
=>
$serial_no
]);
$this
->
consumeTask
(
$redis
,
$key
,
$id
);
}
//记录请求api返回体并修改状态
if
(
StakeholderIncomeByPayer
::
query
()
->
where
([
'serial_no'
=>
$income_item
[
'serial_no'
]])
->
update
(
$update
))
{
$redis
->
xdel
(
$key
,
[
$id
]);
}
}
}
}
else
{
$redis
->
xdel
(
$key
,
[
$id
]);
/**
* 消费任务
* @param $redis
* @param $key
* @param $id
* @return mixed
*/
private
function
consumeTask
(
$redis
,
$key
,
$id
)
{
return
$redis
->
xdel
(
$key
,
[
$id
]);
}
/**
* 生成http请求数据
* @param $serial_no
* @return array
*/
private
function
resolveSyncData
(
$serial_no
)
{
if
(
$income
=
StakeholderIncomeSyncApp
::
query
()
->
where
([
'serial_no'
=>
$serial_no
,
'sync_status'
=>
0
])
->
first
())
{
$income_detail
=
StakeholderIncomeSyncAppDetails
::
query
()
->
where
([
'track_serial_no'
=>
$serial_no
])
->
orderBy
(
'month'
)
->
get
();
if
(
$income_detail
->
isNotEmpty
())
{
return
$this
->
formatHttpBody
(
$income
,
$income_detail
);
}
}
return
[];
}
/**
* @param $income
* @param $income_detail
* @return array
*/
private
function
formatHttpBody
(
$income
,
$income_detail
)
{
$company
=
Company
::
query
()
->
find
(
$income
->
company_id
);
$bills
=
Bills
::
query
()
->
find
(
$income
->
related_id
);
$body
=
[
'busiId'
=>
$income
->
serial_no
,
'cardNo'
=>
$income
->
identifier
,
'cost'
=>
$income
->
cost_amount
,
'deductAmount'
=>
$income
->
deduct_prepaid
,
'faxMoney'
=>
$income
->
fax_money
,
'money'
=>
$income
->
money
,
'totalMoney'
=>
$income
->
total_money
,
'type'
=>
self
::
TYPE_BILLS
,
'title'
=>
$this
->
billsTitle
(
$bills
),
//账单标题
'paymentCompany'
=>
$company
->
receipt_name
,
//付款公司营业执照全称
'addLevelTwoIncomeRequests'
=>
[],
];
foreach
(
$income_detail
as
$item
)
{
$body
[
'addLevelTwoIncomeRequests'
][]
=
[
'actualTime'
=>
(
string
)
$item
->
created_at
,
'busiId'
=>
$item
->
serial_no
,
'faxMoney'
=>
$item
->
fax_money
,
'money'
=>
$item
->
money
,
'totalMoney'
=>
$item
->
total_money
,
'paymentCompany'
=>
$company
->
receipt_name
,
//付款公司营业执照全称
'songNum'
=>
$item
->
song_num
,
'title'
=>
$this
->
billsSubTitle
(
$item
->
month
),
'type'
=>
self
::
TYPE_BILLS
,
];
}
return
$body
;
}
}
...
...
app/Helper/CacheKeyTools.php
View file @
4b472f5
...
...
@@ -17,4 +17,13 @@ class CacheKeyTools
{
return
config
(
'cache.key'
)[
'bills_sync'
];
}
/**
* @return mixed
*/
public
static
function
channelname
()
{
return
config
(
'cache.key'
)[
'channelname'
];
}
}
...
...
app/Models/Legal/Channel.php
0 → 100644
View file @
4b472f5
<?php
namespace
App\Models\Legal
;
use
App\Helper\CacheKeyTools
;
use
App\Models\BaseModel
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Support\Facades\Cache
;
/**
* Class Channel
* @package App\Models
*/
class
Channel
extends
BaseModel
{
use
SoftDeletes
;
const
TIME
=
86400
;
/**
* @return mixed
*/
public
static
function
getChannelName
()
{
if
(
!
$res
=
Cache
::
get
(
CacheKeyTools
::
channelname
()))
{
$res
=
Channel
::
query
()
->
where
([
'pid'
=>
0
])
->
pluck
(
'name'
,
'id'
)
->
toArray
();
Cache
::
put
(
CacheKeyTools
::
channelname
(),
$res
,
self
::
TIME
);
}
return
$res
;
}
}
app/Models/Legal/StakeholderIncomeByPayer.php
deleted
100644 → 0
View file @
bf61209
<?php
namespace
App\Models\Legal
;
use
App\Models\BaseModel
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
/**
* 进账收益流水
* Class StakeholderIncomeByPayer
* @package App\Models\Legal
*/
class
StakeholderIncomeByPayer
extends
BaseModel
{
use
HasFactory
;
const
TYPE_INCOME
=
1
;
const
TYPE_PAY
=
2
;
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/Models/Legal/StakeholderIncomeSyncApp.php
0 → 100644
View file @
4b472f5
<?php
namespace
App\Models\Legal
;
use
App\Models\BaseModel
;
use
Illuminate\Support\Facades\DB
;
/**
* Class stakeholderIncomeSyncApp
* @package App\Models
*/
class
StakeholderIncomeSyncApp
extends
BaseModel
{
const
TYPE_INCOME
=
1
;
//收入
const
TYPE_PAY
=
2
;
//支出
/**
* @var string
*/
protected
$table
=
'stakeholder_income_sync_app'
;
/**
* @var array
*/
protected
$guarded
=
[];
/**
* 付款方
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public
function
subject
()
{
return
$this
->
belongsTo
(
Subject
::
class
,
'subject_no'
,
'no'
)
->
where
(
'attr'
,
'like'
,
'%1%'
);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public
function
stakeholder
()
{
return
$this
->
belongsTo
(
Stakeholder
::
class
,
'stakeholder_id'
);
}
}
app/Models/Legal/StakeholderIncomeSyncAppDetails.php
0 → 100644
View file @
4b472f5
<?php
namespace
App\Models\Legal
;
use
App\Models\BaseModel
;
use
Illuminate\Support\Facades\DB
;
/**
* Class stakeholderIncomeSyncApp
* @package App\Models
*/
class
StakeholderIncomeSyncAppDetails
extends
BaseModel
{
const
TYPE_INCOME
=
1
;
//收入
const
TYPE_PAY
=
2
;
//支出
/**
* @var string
*/
protected
$table
=
'stakeholder_income_sync_app_details'
;
/**
* @var array
*/
protected
$guarded
=
[];
/**
* 付款方
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public
function
subject
()
{
return
$this
->
belongsTo
(
Subject
::
class
,
'subject_no'
,
'no'
)
->
where
(
'attr'
,
'like'
,
'%1%'
);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public
function
stakeholder
()
{
return
$this
->
belongsTo
(
Stakeholder
::
class
,
'stakeholder_id'
);
}
}
app/Models/Legal/StakeholderIncomeSyncLogs.php
deleted
100644 → 0
View file @
bf61209
<?php
namespace
App\Models\Legal
;
use
App\Models\BaseModel
;
use
Illuminate\Database\Eloquent\Factories\HasFactory
;
/**
* Class StakeholderIncomeSyncLogs
* @package App\Models\Legal
*/
class
StakeholderIncomeSyncLogs
extends
BaseModel
{
public
$table
=
'stakeholder_income_sync_logs'
;
}
app/Services/ApiService.php
View file @
4b472f5
...
...
@@ -15,7 +15,7 @@ use App\Models\Legal\StakeholderIncomeByPayer;
class
ApiService
{
protected
static
$uri
=
[
'walletAddIncome'
=>
'/api/
wallet/addIncome
'
,
//外部系统入账-外部可调用
'walletAddIncome'
=>
'/api/
income/addIncomeAndDetail
'
,
//外部系统入账-外部可调用
];
/**
...
...
app/Services/MusicianWithdrawService.php
View file @
4b472f5
...
...
@@ -41,22 +41,18 @@ class MusicianWithdrawService extends Service
*/
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
,
'receipt_type'
=>
$receipt
->
receipt_type
,
'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
,
'receipt_consignee'
=>
$receipt
->
post_consignee
,
//收件人
'post_address'
=>
$receipt
->
post_address
,
//邮寄地址
'post_phone'
=>
$receipt
->
post_phone
,
//邮寄电话
]);
}
else
{
return
Response
::
error
();
...
...
app/Traits/Bills.php
0 → 100644
View file @
4b472f5
<?php
namespace
App\Traits
;
use
App\Models\Legal\Channel
;
/**
* 账单
* Class Bills
* @package App\Traits
*/
trait
Bills
{
/**
* 获取账单名字
* @param \App\Models\Legal\Bills $bills
*/
public
function
billsTitle
(
\App\Models\Legal\Bills
$bills
)
{
$start_month
=
date
(
'm'
,
strtotime
(
$bills
->
bill_section_start
));
$end_month
=
date
(
'm'
,
strtotime
(
$bills
->
bill_section_end
));
$channel
=
Channel
::
getChannelName
()[
$bills
->
channel
]
??
''
;
return
"
{
$start_month
}
-
{
$end_month
}
月
{
$channel
}
版税账单"
;
}
/**
* @param $month
* @return string
*/
public
function
billsSubTitle
(
$month
)
{
return
$month
.
"月账单"
;
}
}
config/cache.php
View file @
4b472f5
...
...
@@ -109,7 +109,8 @@ return [
//cache_key
'key'
=>
[
'bills_sync'
=>
"bills:sync"
,
'bills_sync'
=>
'bills:sync'
,
'channelname'
=>
'channelname'
,
]
];
...
...
routes/api.php
View file @
4b472f5
...
...
@@ -38,7 +38,7 @@ Route::group([], function (){
//提现发票抬头
Route
::
post
(
'withdraw/receipt'
,
'MusicianWithdrawController@receipt'
);
//提现发票抬头 - 通过公司中文
Route
::
pos
t
(
'withdraw/receipt_by_name'
,
'MusicianWithdrawController@receiptByName'
);
Route
::
ge
t
(
'withdraw/receipt_by_name'
,
'MusicianWithdrawController@receiptByName'
);
//账单状态修改
Route
::
post
(
'withdraw/status'
,
'MusicianWithdrawController@status'
);
...
...
Please
register
or
sign in
to post a comment