StakeholderIncomeSync.php
3.23 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
<?php
namespace App\Console\Commands\Test;
use App\Models\Legal\Bills;
use App\Models\Legal\Company;
use App\Models\Legal\StakeholderIncomeSyncApp;
use App\Models\Legal\StakeholderIncomeSyncAppDetails;
use App\Services\ApiService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
/**
* 合作伙同数据同步
* Class StakeholderIncomeSyncCommand
* @package App\Console\Commands
*/
class StakeholderIncomeSync extends Command
{
use \App\Traits\Bills;
const TYPE_BILLS = "1001601"; //账单分成
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:stakeholder:income:sync {serial_no?}';
/**
* The console command description.
*
* @var string
*/
protected $description = '测试:权益人收益同步';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$serial_no = $this->argument('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()) {
$res = $this->formatHttpBody($income, $income_detail);
print_r($res);
exit();
}
}
exit('xxx');
}
/**
* @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' => $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;
}
}