|
|
@@ -18,7 +18,7 @@ class GzcAddByBillCommand extends Command
|
|
18
|
18
|
protected function execute(Input $input, Output $output)
|
|
19
|
19
|
{
|
|
20
|
20
|
$output->writeln('定时任务执行中...');
|
|
21
|
|
- // $this->billGzcAdd();
|
|
|
21
|
+ $this->billGzcAdd();
|
|
22
|
22
|
|
|
23
|
23
|
/** 修复 历史数据脚本 */
|
|
24
|
24
|
// $gzcLogList = Db::name("gzc_logs")
|
|
|
@@ -111,125 +111,125 @@ class GzcAddByBillCommand extends Command
|
|
111
|
111
|
// // 定时任务执行完成
|
|
112
|
112
|
|
|
113
|
113
|
/** 将之前多跑出来的佣金和 */
|
|
114
|
|
- $userBillLinkIdMap = Db::query('SELECT link_id FROM `rrx_user_bill` WHERE link_id != 0 GROUP BY link_id, type_shop, uid, number, commission_type HAVING COUNT(*) > 1');
|
|
115
|
|
- $linkIdList = array_column($userBillLinkIdMap, 'link_id');
|
|
116
|
|
-
|
|
117
|
|
- $userBillList = Db::name("user_bill")
|
|
118
|
|
- ->whereIn('link_id', $linkIdList)
|
|
119
|
|
- ->field('bill_id, gzc, link_id, type_shop, uid, number, commission_type, order_sn, status')
|
|
120
|
|
- ->order('bill_id ASC')
|
|
121
|
|
- ->select()
|
|
122
|
|
- ->toArray();
|
|
123
|
|
-
|
|
124
|
|
- $userBillMap = [];
|
|
125
|
|
- $userBillIdList = [];
|
|
126
|
|
- foreach ($userBillList as $item) {
|
|
127
|
|
- $userBillIdList[] = $item['bill_id'];
|
|
128
|
|
- $userBillMap[$item['link_id'] . '_' . $item['type_shop'] . '_' . $item['uid'] . '_' . $item['commission_type'] . '_' . $item['number']][] = $item;
|
|
129
|
|
- }
|
|
130
|
|
-
|
|
131
|
|
- $gzcLogList = Db::name("gzc_logs")
|
|
132
|
|
- ->whereIn('link_id', $userBillIdList)
|
|
133
|
|
- ->field('id, gzc, success, link_id')
|
|
134
|
|
- ->order('id ASC')
|
|
135
|
|
- ->select()
|
|
136
|
|
- ->toArray();
|
|
137
|
|
- // 提前查询过了,按正常来说 就是一对一,上边数据修复过后,没有重复数据
|
|
138
|
|
- $gzcLogMap = array_column($gzcLogList, null, 'link_id');
|
|
139
|
|
-
|
|
140
|
|
- $delAllIdList = [];
|
|
141
|
|
- $delYongJin = [];
|
|
142
|
|
- $yjNum = 0.00;
|
|
143
|
|
- $yongjinKouchu = [];
|
|
144
|
|
- $yongjinKouchuDelBillIdList = [];
|
|
145
|
|
- foreach ($userBillMap as $userBillArr) {
|
|
146
|
|
- $allIds = [];
|
|
147
|
|
- $baoLiuIds = [];
|
|
148
|
|
- $yjDataList = [];
|
|
149
|
|
- // 单次遍历同时收集所有ID和需要保留的ID
|
|
150
|
|
- foreach ($userBillArr as $userBill) {
|
|
151
|
|
- $allIds[] = $userBill['bill_id'];
|
|
152
|
|
- // 如果该条记录是养老金记录 则根据 养老金公证处记录表 内的条件 来决定是否删除该条记录
|
|
153
|
|
- if ($userBill['commission_type'] == 5) {
|
|
154
|
|
- if (!empty($gzcLogMap[$userBill['bill_id']] ?? []) && $gzcLogMap[$userBill['bill_id']]['success'] == 1) {
|
|
155
|
|
- // 如果该条 养老金记录 推送到了公证处明细记录表
|
|
156
|
|
- $baoLiuIds[] = $userBill['bill_id'];
|
|
157
|
|
- }
|
|
158
|
|
- }
|
|
159
|
|
-
|
|
160
|
|
- if ($userBill['commission_type'] == 3) {
|
|
161
|
|
- if ($userBill['status'] == 1) {
|
|
162
|
|
- $yjDataList[] = $userBill;
|
|
163
|
|
- }
|
|
164
|
|
- }
|
|
165
|
|
- }
|
|
166
|
|
- // 确定需要删除的ID列表
|
|
167
|
|
- if (!empty($billIdList)) {
|
|
168
|
|
- // 保留有gzc标志的记录,删除其他
|
|
169
|
|
- $delIdList = array_diff($allIds, $billIdList);
|
|
170
|
|
- } else if (!empty($yjDataList)) {
|
|
171
|
|
- // 保留第一条 已生效 的佣金,其余的,需要从用户身上扣减 并删除
|
|
172
|
|
- $yjDataOne = array_shift($yjDataList);
|
|
173
|
|
- if (!empty($yjDataList)) {
|
|
174
|
|
- // 如果移除掉第一个 还有已经发放的 佣金 需要从用户身上扣除
|
|
175
|
|
- foreach ($yjDataList as $billData) {
|
|
176
|
|
- $delYongJin[] = $billData['bill_id'];
|
|
177
|
|
- $yjNum += $billData['number'];
|
|
178
|
|
- if (!isset($yongjinKouchu[$billData['uid']])) {
|
|
179
|
|
- $yongjinKouchu[$billData['uid']] = 0.00;
|
|
180
|
|
- }
|
|
181
|
|
- $yongjinKouchu[$billData['uid']] += $billData['number'];
|
|
182
|
|
- $yongjinKouchuDelBillIdList[$billData['uid']][] = $billData['bill_id'];
|
|
183
|
|
- }
|
|
184
|
|
- }
|
|
185
|
|
- $delIdList = array_values(array_diff($allIds, [$yjDataOne['bill_id']]));
|
|
186
|
|
- } else {
|
|
187
|
|
- // 保留第一条记录,删除其他
|
|
188
|
|
- $delIdList = array_slice($allIds, 1);
|
|
189
|
|
- }
|
|
190
|
|
- $delAllIdList = array_merge($delAllIdList, $delIdList);
|
|
191
|
|
- }
|
|
192
|
|
-
|
|
193
|
|
- echo '应删除的Bill记录' . implode(',', $delAllIdList) . "\n";
|
|
194
|
|
- echo '应删除的佣金记录' . implode(',', $delYongJin) . "\n";
|
|
195
|
|
- echo '应删除的佣金金额' . $yjNum . "\n";
|
|
196
|
|
-
|
|
197
|
|
- $successDecYongjin = 0.00;
|
|
198
|
|
- $fallDelBillIdList = [];
|
|
199
|
|
- if (!empty($yongjinKouchu)) {
|
|
200
|
|
- foreach ($yongjinKouchu as $uid => $number) {
|
|
201
|
|
- $user = Db::name('user')->where('uid', '=', $uid)->find();
|
|
202
|
|
- if ($user) {
|
|
203
|
|
- if ($user['brokerage_price'] >= $number) {
|
|
204
|
|
- $updateNum = Db::name('user')->where('uid', '=', $uid)->dec('brokerage_price', $number)->update();
|
|
205
|
|
- if ($updateNum) {
|
|
206
|
|
- $successDecYongjin += $number;
|
|
207
|
|
- echo "用户佣金扣除成功(uid:$uid ,账号:{$user['account']} ,用户佣金余额:{$user['brokerage_price']},应扣除佣金:$number )\n";
|
|
208
|
|
- continue;
|
|
209
|
|
- } else {
|
|
210
|
|
- echo "用户佣金余额不足(uid:$uid ,账号:{$user['account']} ,用户佣金余额:{$user['brokerage_price']},应扣除佣金:$number )\n";
|
|
211
|
|
- }
|
|
212
|
|
- } else {
|
|
213
|
|
- echo "用户佣金余额不足(uid:$uid ,账号:{$user['account']} ,用户佣金余额:{$user['brokerage_price']},应扣除佣金:$number )\n";
|
|
214
|
|
- }
|
|
215
|
|
- } else {
|
|
216
|
|
- echo "未查询到用户信息(uid:$uid ,应扣除佣金:$number )\n";
|
|
217
|
|
- }
|
|
218
|
|
- $fallDelBillIdList = array_values(array_merge($fallDelBillIdList, $yongjinKouchuDelBillIdList[$uid]));
|
|
219
|
|
- }
|
|
220
|
|
- }
|
|
221
|
|
- echo '因佣金扣减失败而不能删除的佣金记录:' . implode(',', $fallDelBillIdList) . "\n";
|
|
222
|
|
- echo '成功扣减佣金总额:' . $successDecYongjin . "\n";
|
|
223
|
|
- $delAllIdList = array_values(array_diff($delAllIdList, $fallDelBillIdList));
|
|
224
|
|
- echo '实际删除的Bill记录' . implode(',', $delAllIdList) . "\n";
|
|
225
|
|
- Db::name("user_bill")
|
|
226
|
|
- ->whereIn('bill_id', $delAllIdList)
|
|
227
|
|
- ->delete();
|
|
228
|
|
- Db::name("gzc_logs")
|
|
229
|
|
- ->whereIn('link_id', $delAllIdList)
|
|
230
|
|
- ->delete();
|
|
231
|
|
- $delYongJin = array_values(array_diff($delYongJin, $fallDelBillIdList));
|
|
232
|
|
- echo '实际应删除的佣金记录' . implode(',', $delYongJin) . "\n";
|
|
|
114
|
+ // $userBillLinkIdMap = Db::query('SELECT link_id FROM `rrx_user_bill` WHERE link_id != 0 GROUP BY link_id, type_shop, uid, number, commission_type HAVING COUNT(*) > 1');
|
|
|
115
|
+ // $linkIdList = array_column($userBillLinkIdMap, 'link_id');
|
|
|
116
|
+ //
|
|
|
117
|
+ // $userBillList = Db::name("user_bill")
|
|
|
118
|
+ // ->whereIn('link_id', $linkIdList)
|
|
|
119
|
+ // ->field('bill_id, gzc, link_id, type_shop, uid, number, commission_type, order_sn, status')
|
|
|
120
|
+ // ->order('bill_id ASC')
|
|
|
121
|
+ // ->select()
|
|
|
122
|
+ // ->toArray();
|
|
|
123
|
+ //
|
|
|
124
|
+ // $userBillMap = [];
|
|
|
125
|
+ // $userBillIdList = [];
|
|
|
126
|
+ // foreach ($userBillList as $item) {
|
|
|
127
|
+ // $userBillIdList[] = $item['bill_id'];
|
|
|
128
|
+ // $userBillMap[$item['link_id'] . '_' . $item['type_shop'] . '_' . $item['uid'] . '_' . $item['commission_type'] . '_' . $item['number']][] = $item;
|
|
|
129
|
+ // }
|
|
|
130
|
+ //
|
|
|
131
|
+ // $gzcLogList = Db::name("gzc_logs")
|
|
|
132
|
+ // ->whereIn('link_id', $userBillIdList)
|
|
|
133
|
+ // ->field('id, gzc, success, link_id')
|
|
|
134
|
+ // ->order('id ASC')
|
|
|
135
|
+ // ->select()
|
|
|
136
|
+ // ->toArray();
|
|
|
137
|
+ // // 提前查询过了,按正常来说 就是一对一,上边数据修复过后,没有重复数据
|
|
|
138
|
+ // $gzcLogMap = array_column($gzcLogList, null, 'link_id');
|
|
|
139
|
+ //
|
|
|
140
|
+ // $delAllIdList = [];
|
|
|
141
|
+ // $delYongJin = [];
|
|
|
142
|
+ // $yjNum = 0.00;
|
|
|
143
|
+ // $yongjinKouchu = [];
|
|
|
144
|
+ // $yongjinKouchuDelBillIdList = [];
|
|
|
145
|
+ // foreach ($userBillMap as $userBillArr) {
|
|
|
146
|
+ // $allIds = [];
|
|
|
147
|
+ // $baoLiuIds = [];
|
|
|
148
|
+ // $yjDataList = [];
|
|
|
149
|
+ // // 单次遍历同时收集所有ID和需要保留的ID
|
|
|
150
|
+ // foreach ($userBillArr as $userBill) {
|
|
|
151
|
+ // $allIds[] = $userBill['bill_id'];
|
|
|
152
|
+ // // 如果该条记录是养老金记录 则根据 养老金公证处记录表 内的条件 来决定是否删除该条记录
|
|
|
153
|
+ // if ($userBill['commission_type'] == 5) {
|
|
|
154
|
+ // if (!empty($gzcLogMap[$userBill['bill_id']] ?? []) && $gzcLogMap[$userBill['bill_id']]['success'] == 1) {
|
|
|
155
|
+ // // 如果该条 养老金记录 推送到了公证处明细记录表
|
|
|
156
|
+ // $baoLiuIds[] = $userBill['bill_id'];
|
|
|
157
|
+ // }
|
|
|
158
|
+ // }
|
|
|
159
|
+ //
|
|
|
160
|
+ // if ($userBill['commission_type'] == 3) {
|
|
|
161
|
+ // if ($userBill['status'] == 1) {
|
|
|
162
|
+ // $yjDataList[] = $userBill;
|
|
|
163
|
+ // }
|
|
|
164
|
+ // }
|
|
|
165
|
+ // }
|
|
|
166
|
+ // // 确定需要删除的ID列表
|
|
|
167
|
+ // if (!empty($billIdList)) {
|
|
|
168
|
+ // // 保留有gzc标志的记录,删除其他
|
|
|
169
|
+ // $delIdList = array_diff($allIds, $billIdList);
|
|
|
170
|
+ // } else if (!empty($yjDataList)) {
|
|
|
171
|
+ // // 保留第一条 已生效 的佣金,其余的,需要从用户身上扣减 并删除
|
|
|
172
|
+ // $yjDataOne = array_shift($yjDataList);
|
|
|
173
|
+ // if (!empty($yjDataList)) {
|
|
|
174
|
+ // // 如果移除掉第一个 还有已经发放的 佣金 需要从用户身上扣除
|
|
|
175
|
+ // foreach ($yjDataList as $billData) {
|
|
|
176
|
+ // $delYongJin[] = $billData['bill_id'];
|
|
|
177
|
+ // $yjNum += $billData['number'];
|
|
|
178
|
+ // if (!isset($yongjinKouchu[$billData['uid']])) {
|
|
|
179
|
+ // $yongjinKouchu[$billData['uid']] = 0.00;
|
|
|
180
|
+ // }
|
|
|
181
|
+ // $yongjinKouchu[$billData['uid']] += $billData['number'];
|
|
|
182
|
+ // $yongjinKouchuDelBillIdList[$billData['uid']][] = $billData['bill_id'];
|
|
|
183
|
+ // }
|
|
|
184
|
+ // }
|
|
|
185
|
+ // $delIdList = array_values(array_diff($allIds, [$yjDataOne['bill_id']]));
|
|
|
186
|
+ // } else {
|
|
|
187
|
+ // // 保留第一条记录,删除其他
|
|
|
188
|
+ // $delIdList = array_slice($allIds, 1);
|
|
|
189
|
+ // }
|
|
|
190
|
+ // $delAllIdList = array_merge($delAllIdList, $delIdList);
|
|
|
191
|
+ // }
|
|
|
192
|
+ //
|
|
|
193
|
+ // echo '应删除的Bill记录' . implode(',', $delAllIdList) . "\n";
|
|
|
194
|
+ // echo '应删除的佣金记录' . implode(',', $delYongJin) . "\n";
|
|
|
195
|
+ // echo '应删除的佣金金额' . $yjNum . "\n";
|
|
|
196
|
+ //
|
|
|
197
|
+ // $successDecYongjin = 0.00;
|
|
|
198
|
+ // $fallDelBillIdList = [];
|
|
|
199
|
+ // if (!empty($yongjinKouchu)) {
|
|
|
200
|
+ // foreach ($yongjinKouchu as $uid => $number) {
|
|
|
201
|
+ // $user = Db::name('user')->where('uid', '=', $uid)->find();
|
|
|
202
|
+ // if ($user) {
|
|
|
203
|
+ // if ($user['brokerage_price'] >= $number) {
|
|
|
204
|
+ // $updateNum = Db::name('user')->where('uid', '=', $uid)->dec('brokerage_price', $number)->update();
|
|
|
205
|
+ // if ($updateNum) {
|
|
|
206
|
+ // $successDecYongjin += $number;
|
|
|
207
|
+ // echo "用户佣金扣除成功(uid:$uid ,账号:{$user['account']} ,用户佣金余额:{$user['brokerage_price']},应扣除佣金:$number )\n";
|
|
|
208
|
+ // continue;
|
|
|
209
|
+ // } else {
|
|
|
210
|
+ // echo "用户佣金余额不足(uid:$uid ,账号:{$user['account']} ,用户佣金余额:{$user['brokerage_price']},应扣除佣金:$number )\n";
|
|
|
211
|
+ // }
|
|
|
212
|
+ // } else {
|
|
|
213
|
+ // echo "用户佣金余额不足(uid:$uid ,账号:{$user['account']} ,用户佣金余额:{$user['brokerage_price']},应扣除佣金:$number )\n";
|
|
|
214
|
+ // }
|
|
|
215
|
+ // } else {
|
|
|
216
|
+ // echo "未查询到用户信息(uid:$uid ,应扣除佣金:$number )\n";
|
|
|
217
|
+ // }
|
|
|
218
|
+ // $fallDelBillIdList = array_values(array_merge($fallDelBillIdList, $yongjinKouchuDelBillIdList[$uid]));
|
|
|
219
|
+ // }
|
|
|
220
|
+ // }
|
|
|
221
|
+ // echo '因佣金扣减失败而不能删除的佣金记录:' . implode(',', $fallDelBillIdList) . "\n";
|
|
|
222
|
+ // echo '成功扣减佣金总额:' . $successDecYongjin . "\n";
|
|
|
223
|
+ // $delAllIdList = array_values(array_diff($delAllIdList, $fallDelBillIdList));
|
|
|
224
|
+ // echo '实际删除的Bill记录' . implode(',', $delAllIdList) . "\n";
|
|
|
225
|
+ // Db::name("user_bill")
|
|
|
226
|
+ // ->whereIn('bill_id', $delAllIdList)
|
|
|
227
|
+ // ->delete();
|
|
|
228
|
+ // Db::name("gzc_logs")
|
|
|
229
|
+ // ->whereIn('link_id', $delAllIdList)
|
|
|
230
|
+ // ->delete();
|
|
|
231
|
+ // $delYongJin = array_values(array_diff($delYongJin, $fallDelBillIdList));
|
|
|
232
|
+ // echo '实际应删除的佣金记录' . implode(',', $delYongJin) . "\n";
|
|
233
|
233
|
|
|
234
|
234
|
$output->writeln('定时任务执行完成');
|
|
235
|
235
|
}
|