|
|
@@ -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")
|
|
|
@@ -62,7 +62,7 @@ class GzcAddByBillCommand extends Command
|
|
62
|
62
|
// // 定时任务执行完成
|
|
63
|
63
|
|
|
64
|
64
|
|
|
65
|
|
- // /** 删除重复数据脚本 */
|
|
|
65
|
+ /** 删除重复数据脚本 */
|
|
66
|
66
|
// $gzcLogList = Db::query('SELECT link_id FROM rrx_gzc_logs WHERE link_id != 0 GROUP BY link_id HAVING COUNT(*) > 1');
|
|
67
|
67
|
// $linkIdList = array_column($gzcLogList, 'link_id');
|
|
68
|
68
|
// $gzcLogList = Db::name("gzc_logs")
|
|
|
@@ -110,6 +110,82 @@ class GzcAddByBillCommand extends Command
|
|
110
|
110
|
// // deleteNum78
|
|
111
|
111
|
// // 定时任务执行完成
|
|
112
|
112
|
|
|
|
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
|
+ foreach ($userBillMap as $userBillArr) {
|
|
|
144
|
+ $allIds = [];
|
|
|
145
|
+ $baoLiuIds = [];
|
|
|
146
|
+ $yjDataList = [];
|
|
|
147
|
+ // 单次遍历同时收集所有ID和需要保留的ID
|
|
|
148
|
+ foreach ($userBillArr as $userBill) {
|
|
|
149
|
+ $allIds[] = $userBill['bill_id'];
|
|
|
150
|
+ // 如果该条记录是养老金记录 则根据 养老金公证处记录表 内的条件 来决定是否删除该条记录
|
|
|
151
|
+ if ($userBill['commission_type'] == 5) {
|
|
|
152
|
+ if (!empty($gzcLogMap[$userBill['bill_id']] ?? []) && $gzcLogMap[$userBill['bill_id']]['success'] == 1) {
|
|
|
153
|
+ // 如果该条 养老金记录 推送到了公证处明细记录表
|
|
|
154
|
+ $baoLiuIds[] = $userBill['bill_id'];
|
|
|
155
|
+ }
|
|
|
156
|
+ }
|
|
|
157
|
+
|
|
|
158
|
+ if ($userBill['commission_type'] == 3) {
|
|
|
159
|
+ if ($userBill['status'] == 1) {
|
|
|
160
|
+ $yjDataList[] = $userBill;
|
|
|
161
|
+ }
|
|
|
162
|
+ }
|
|
|
163
|
+ }
|
|
|
164
|
+ // 确定需要删除的ID列表
|
|
|
165
|
+ if (!empty($billIdList)) {
|
|
|
166
|
+ // 保留有gzc标志的记录,删除其他
|
|
|
167
|
+ $delIdList = array_diff($allIds, $billIdList);
|
|
|
168
|
+ } else if (!empty($yjDataList)) {
|
|
|
169
|
+ // 保留第一条 已生效 的佣金,其余的,需要从用户身上扣减 并删除
|
|
|
170
|
+ $yjDataOne = array_shift($yjDataList);
|
|
|
171
|
+ if (!empty($yjDataList)) {
|
|
|
172
|
+ // 如果移除掉第一个 还有已经发放的 佣金 需要从用户身上扣除
|
|
|
173
|
+ foreach ($yjDataList as $billData) {
|
|
|
174
|
+ $delYongJin[] = $billData['bill_id'];
|
|
|
175
|
+ $yjNum += $billData['number'];
|
|
|
176
|
+ }
|
|
|
177
|
+ }
|
|
|
178
|
+ $delIdList = array_values(array_diff($allIds, [$yjDataOne['bill_id']]));
|
|
|
179
|
+ } else {
|
|
|
180
|
+ // 保留第一条记录,删除其他
|
|
|
181
|
+ $delIdList = array_slice($allIds, 1);
|
|
|
182
|
+ }
|
|
|
183
|
+ $delAllIdList = array_merge($delAllIdList, $delIdList);
|
|
|
184
|
+ }
|
|
|
185
|
+
|
|
|
186
|
+ echo '删除的Bill记录' . implode(',', $delAllIdList) . "\n";
|
|
|
187
|
+ echo '删除的佣金记录' . implode(',', $delYongJin) . "\n";
|
|
|
188
|
+ echo '删除的佣金金额' . $yjNum . "\n";
|
|
113
|
189
|
|
|
114
|
190
|
$output->writeln('定时任务执行完成');
|
|
115
|
191
|
}
|