*
Showing
3 changed files
with
22 additions
and
12 deletions
... | @@ -65,16 +65,18 @@ class StakeholderIncomeSyncCommand extends Command | ... | @@ -65,16 +65,18 @@ class StakeholderIncomeSyncCommand extends Command |
65 | while (true) { | 65 | while (true) { |
66 | 66 | ||
67 | $redis = RedisClient::instance('bills'); | 67 | $redis = RedisClient::instance('bills'); |
68 | $key = CacheKeyTools::billsSync(); | 68 | $key = CacheKeyTools::billsSettleByNo(); |
69 | 69 | ||
70 | //处理消息体 | 70 | //处理消息体 - 每次处理1个入账的数据 |
71 | if($msg = $redis->xread([$key=>$id], self::COUNT, self::BLOCK_TIME)) { | 71 | if($msg = $redis->xread([$key=>$id], self::COUNT, self::BLOCK_TIME)) { |
72 | 72 | ||
73 | $id = key($msg[$key]); | 73 | $id = key($msg[$key]); |
74 | $serial_no = $msg[$key][$id]['serial_no']; | 74 | $task = $msg[$key][$id]; |
75 | //$batch_no = $task['batch_no']; | ||
76 | $serial_no = $task['serial_no']; | ||
75 | $http_res = []; | 77 | $http_res = []; |
76 | 78 | ||
77 | Log::channel('api')->warning(__METHOD__."streamid:{$id}-即将处理任务", ['item'=>$msg[$key][$id]]); | 79 | Log::channel('api')->warning(__METHOD__."streamid:{$key}:{$id}-即将处理任务", ['task'=>$task]); |
78 | 80 | ||
79 | //获取记录 | 81 | //获取记录 |
80 | if ($http_data = $this->resolveSyncData($serial_no)) { | 82 | if ($http_data = $this->resolveSyncData($serial_no)) { |
... | @@ -86,12 +88,13 @@ class StakeholderIncomeSyncCommand extends Command | ... | @@ -86,12 +88,13 @@ class StakeholderIncomeSyncCommand extends Command |
86 | 88 | ||
87 | //处理返回体 | 89 | //处理返回体 |
88 | $this->dealResponse($serial_no, $http_data, $http_res); | 90 | $this->dealResponse($serial_no, $http_data, $http_res); |
89 | $this->consumeTask($http_res, $redis, $key, $id); | ||
90 | |||
91 | } else { | 91 | } else { |
92 | //此处需要加入 重试计数移除任务机制 | 92 | //此处需要加入 重试计数移除任务机制 |
93 | Log::channel('api')->info(__METHOD__, ['msg'=>'暂时找不到需要同步的对应的收益记录', 'serial_no'=>$serial_no]); | 93 | Log::channel('api')->info(__METHOD__, ['msg'=>'未找到同步记录', 'serial_no'=>$serial_no]); |
94 | } | 94 | } |
95 | |||
96 | //标记处理 | ||
97 | $this->consumeTask($redis, $http_res, $key, $id); | ||
95 | } | 98 | } |
96 | } | 99 | } |
97 | } | 100 | } |
... | @@ -115,7 +118,7 @@ class StakeholderIncomeSyncCommand extends Command | ... | @@ -115,7 +118,7 @@ class StakeholderIncomeSyncCommand extends Command |
115 | 118 | ||
116 | if (!empty($response)) { | 119 | if (!empty($response)) { |
117 | StakeholderIncomeSyncApp::query()->where(['serial_no'=>$serial_no])->update([ | 120 | StakeholderIncomeSyncApp::query()->where(['serial_no'=>$serial_no])->update([ |
118 | 'busi_id' => $response['id'], | 121 | 'busi_id' => ($response['code'] == 0 ) ? $response['id'] : null, |
119 | 'sync_status' => ($response['code'] == 0 ) ? 1 : 2, | 122 | 'sync_status' => ($response['code'] == 0 ) ? 1 : 2, |
120 | ]); | 123 | ]); |
121 | } | 124 | } |
... | @@ -130,16 +133,15 @@ class StakeholderIncomeSyncCommand extends Command | ... | @@ -130,16 +133,15 @@ class StakeholderIncomeSyncCommand extends Command |
130 | 133 | ||
131 | /** | 134 | /** |
132 | * 将任务id标记为删除 | 135 | * 将任务id标记为删除 |
133 | * @param $http_res | ||
134 | * @param $redis | 136 | * @param $redis |
137 | * @param $http_res | ||
135 | * @param $key | 138 | * @param $key |
136 | * @param $id | 139 | * @param $id |
137 | * @return mixed | ||
138 | */ | 140 | */ |
139 | private function consumeTask($http_res, $redis, $key, $id) | 141 | private function consumeTask($redis, $http_res, $key, $id) |
140 | { | 142 | { |
141 | if (empty($http_res)) { | 143 | if (empty($http_res)) { |
142 | return $redis->xdel($key, [$id]); | 144 | $redis->xdel($key, [$id]); |
143 | } else { | 145 | } else { |
144 | switch (intval($http_res['code'])) { | 146 | switch (intval($http_res['code'])) { |
145 | case 0: //同步成功 | 147 | case 0: //同步成功 | ... | ... |
... | @@ -34,4 +34,11 @@ class CacheKeyTools | ... | @@ -34,4 +34,11 @@ class CacheKeyTools |
34 | return str_replace('#serial_no#', $serial_no, config('cache.key')['bills_confirm']); | 34 | return str_replace('#serial_no#', $serial_no, config('cache.key')['bills_confirm']); |
35 | } | 35 | } |
36 | 36 | ||
37 | /** | ||
38 | * @return mixed | ||
39 | */ | ||
40 | public static function billsSettleByNo() | ||
41 | { | ||
42 | return config('cache.key')['bills_settle_no']; | ||
43 | } | ||
37 | } | 44 | } | ... | ... |
... | @@ -112,6 +112,7 @@ return [ | ... | @@ -112,6 +112,7 @@ return [ |
112 | 'bills_sync' => 'bills:sync', | 112 | 'bills_sync' => 'bills:sync', |
113 | 'channelname' => 'channelname', | 113 | 'channelname' => 'channelname', |
114 | 'bills_confirm' => 'serial:#serial_no#', | 114 | 'bills_confirm' => 'serial:#serial_no#', |
115 | 'bills_settle_no' => 'bills:settle:no' | ||
115 | ] | 116 | ] |
116 | 117 | ||
117 | ]; | 118 | ]; | ... | ... |
-
Please register or sign in to post a comment