Commit 0a0bbb6f 0a0bbb6fb6f0fef265da156622f803f862c62bc1 by lemon

同步分贝

1 parent 8db02e59
...@@ -3,13 +3,17 @@ ...@@ -3,13 +3,17 @@
3 namespace App\Console\Commands; 3 namespace App\Console\Commands;
4 4
5 use App\Helper\CacheKeyTools; 5 use App\Helper\CacheKeyTools;
6 use App\Helper\ErrorCode;
6 use App\Helper\RedisClient; 7 use App\Helper\RedisClient;
8 use App\Helper\Response;
7 use App\Models\Legal\Bills; 9 use App\Models\Legal\Bills;
8 use App\Models\Legal\Company; 10 use App\Models\Legal\Company;
9 use App\Models\Legal\StakeholderIncomeSyncApp; 11 use App\Models\Legal\StakeholderIncomeSyncApp;
10 use App\Models\Legal\StakeholderIncomeSyncAppDetails; 12 use App\Models\Legal\StakeholderIncomeSyncAppDetails;
13 use App\Models\Legal\StakeholderIncomeSyncAppLogs;
11 use App\Services\ApiService; 14 use App\Services\ApiService;
12 use Illuminate\Console\Command; 15 use Illuminate\Console\Command;
16 use Illuminate\Support\Facades\DB;
13 use Illuminate\Support\Facades\Log; 17 use Illuminate\Support\Facades\Log;
14 18
15 /** 19 /**
...@@ -40,7 +44,6 @@ class StakeholderIncomeSyncCommand extends Command ...@@ -40,7 +44,6 @@ class StakeholderIncomeSyncCommand extends Command
40 const BLOCK_TIME = 1000; 44 const BLOCK_TIME = 1000;
41 45
42 const TYPE_BILLS = "1001601"; //账单分成 46 const TYPE_BILLS = "1001601"; //账单分成
43 const TYPE_ROYALTY = "1001602"; //合作伙伴打款 type = 1 版税分成
44 47
45 /** 48 /**
46 * Create a new command instance. 49 * Create a new command instance.
...@@ -79,24 +82,55 @@ class StakeholderIncomeSyncCommand extends Command ...@@ -79,24 +82,55 @@ class StakeholderIncomeSyncCommand extends Command
79 //http 82 //http
80 $http_res = ApiService::walletAddIncome($http_data); 83 $http_res = ApiService::walletAddIncome($http_data);
81 84
82 if (empty($http_res)) { 85 Log::channel('api')->info(__METHOD__."同步反馈", ['stream-id'=>$id, 'serial_no'=>$serial_no, 'request'=>$http_data, 'response'=>$http_res]);
83 //重试 401/403/403
84 Log::channel('api')->warning(__METHOD__."streamid:{$id}-api请求失败", ['income_item'=>$income_item, 'http_data'=>$http_data]);
85 } else {
86 //成功
87 86
88 } 87 //处理返回体
88 $this->dealResponse($serial_no, $http_data, $http_res);
89 89
90 } else { 90 } else {
91 Log::channel('api')->info(__METHOD__, ['msg'=>'找不到需要同步的对应的收益记录', 'serial_no'=>$serial_no]); 91 Log::channel('api')->info(__METHOD__, ['msg'=>'找不到需要同步的对应的收益记录', 'serial_no'=>$serial_no]);
92 $this->consumeTask($redis, $key, $id);
93 } 92 }
94 93
94 $this->consumeTask($redis, $key, $id);
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99 /** 99 /**
100 * 处理返回体
101 * @param $serial_no
102 * @param $http_res
103 */
104 private function dealResponse($serial_no, $request, $response)
105 {
106 DB::beginTransaction();
107
108 try {
109
110 StakeholderIncomeSyncAppLogs::query()->create([
111 'serial_no' => $serial_no,
112 'request_log' => $request,
113 'response_log' => $response
114 ]);
115
116 if (!empty($response) && ($response['code'] == 0)) {
117 StakeholderIncomeSyncApp::query()->where(['serial_no'=>$serial_no])->update([
118 'busi_id' => $response['id'],
119 'sync_status' => 1,
120 ]);
121 }
122
123 DB::commit();
124
125 } catch (\Exception $e) {
126 DB::rollBack();
127 Log::channel('api')->error(__METHOD__, ['msg'=>$e->getMessage(), 'request'=>$request, 'response'=>$response]);
128 }
129
130
131 }
132
133 /**
100 * 消费任务 134 * 消费任务
101 * @param $redis 135 * @param $redis
102 * @param $key 136 * @param $key
...@@ -153,7 +187,7 @@ class StakeholderIncomeSyncCommand extends Command ...@@ -153,7 +187,7 @@ class StakeholderIncomeSyncCommand extends Command
153 187
154 foreach ($income_detail as $item) { 188 foreach ($income_detail as $item) {
155 $body['addLevelTwoIncomeRequests'][] = [ 189 $body['addLevelTwoIncomeRequests'][] = [
156 'actualTime' => (string)$item->created_at, 190 'actualTime' => $item->created_at,
157 'busiId' => $item->serial_no, 191 'busiId' => $item->serial_no,
158 'faxMoney' => $item->fax_money, 192 'faxMoney' => $item->fax_money,
159 'money' => $item->money, 193 'money' => $item->money,
......
1 <?php
2
3 namespace App\Models\Legal;
4
5 use App\Models\BaseModel;
6 use Illuminate\Support\Facades\DB;
7
8 /**
9 * Class stakeholderIncomeSyncApp
10 * @package App\Models
11 */
12 class StakeholderIncomeSyncAppLogs extends BaseModel
13 {
14
15 /**
16 * @var string
17 */
18 protected $table = 'stakeholder_income_sync_app_logs';
19
20 /**
21 * @var array
22 */
23 protected $guarded = [];
24
25 protected $casts = [
26 'request_log' => 'json',
27 'response_log' => 'json',
28 ];
29
30 }