|
|
@@ -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,49 +62,54 @@ class GzcAddByBillCommand extends Command
|
|
62
|
62
|
// // 定时任务执行完成
|
|
63
|
63
|
|
|
64
|
64
|
|
|
65
|
|
- /** 删除重复数据脚本 */
|
|
66
|
|
- $gzcLogList = Db::query('SELECT link_id FROM rrx_gzc_logs WHERE link_id != 0 GROUP BY link_id HAVING COUNT(*) > 1');
|
|
67
|
|
- $linkIdList = array_column($gzcLogList, 'link_id');
|
|
68
|
|
- $gzcLogList = Db::name("gzc_logs")
|
|
69
|
|
- ->whereIn('link_id', $linkIdList)
|
|
70
|
|
- ->field('id, gzc, success, link_id')
|
|
71
|
|
- ->order('id ASC')
|
|
72
|
|
- ->select()
|
|
73
|
|
- ->toArray();
|
|
74
|
|
- $gzcLogMap = [];
|
|
75
|
|
- foreach ($gzcLogList as $item) {
|
|
76
|
|
- $gzcLogMap[$item['link_id']][] = $item;
|
|
77
|
|
- }
|
|
78
|
|
-
|
|
79
|
|
- $delAllIdList = [];
|
|
80
|
|
- foreach ($gzcLogMap as $gzcLogArr) {
|
|
81
|
|
- $gzcIdList = [];
|
|
82
|
|
- $allIds = [];
|
|
83
|
|
- // 单次遍历同时收集所有ID和需要保留的ID
|
|
84
|
|
- foreach ($gzcLogArr as $gzcLog) {
|
|
85
|
|
- $allIds[] = $gzcLog['id'];
|
|
86
|
|
- if ($gzcLog['gzc'] != 0) {
|
|
87
|
|
- $gzcIdList[] = $gzcLog['id'];
|
|
88
|
|
- }
|
|
89
|
|
- }
|
|
90
|
|
- // 确定需要删除的ID列表
|
|
91
|
|
- if (!empty($gzcIdList)) {
|
|
92
|
|
- // 保留有gzc标志的记录,删除其他
|
|
93
|
|
- $delIdList = array_diff($allIds, $gzcIdList);
|
|
94
|
|
- } else {
|
|
95
|
|
- // 保留第一条记录,删除其他
|
|
96
|
|
- $delIdList = array_slice($allIds, 1);
|
|
97
|
|
- }
|
|
98
|
|
- $delAllIdList = array_merge($delAllIdList, $delIdList);
|
|
99
|
|
- }
|
|
|
65
|
+ // /** 删除重复数据脚本 */
|
|
|
66
|
+ // $gzcLogList = Db::query('SELECT link_id FROM rrx_gzc_logs WHERE link_id != 0 GROUP BY link_id HAVING COUNT(*) > 1');
|
|
|
67
|
+ // $linkIdList = array_column($gzcLogList, 'link_id');
|
|
|
68
|
+ // $gzcLogList = Db::name("gzc_logs")
|
|
|
69
|
+ // ->whereIn('link_id', $linkIdList)
|
|
|
70
|
+ // ->field('id, gzc, success, link_id')
|
|
|
71
|
+ // ->order('id ASC')
|
|
|
72
|
+ // ->select()
|
|
|
73
|
+ // ->toArray();
|
|
|
74
|
+ // $gzcLogMap = [];
|
|
|
75
|
+ // foreach ($gzcLogList as $item) {
|
|
|
76
|
+ // $gzcLogMap[$item['link_id']][] = $item;
|
|
|
77
|
+ // }
|
|
|
78
|
+ //
|
|
|
79
|
+ // $delAllIdList = [];
|
|
|
80
|
+ // foreach ($gzcLogMap as $gzcLogArr) {
|
|
|
81
|
+ // $gzcIdList = [];
|
|
|
82
|
+ // $allIds = [];
|
|
|
83
|
+ // // 单次遍历同时收集所有ID和需要保留的ID
|
|
|
84
|
+ // foreach ($gzcLogArr as $gzcLog) {
|
|
|
85
|
+ // $allIds[] = $gzcLog['id'];
|
|
|
86
|
+ // if ($gzcLog['gzc'] != 0) {
|
|
|
87
|
+ // $gzcIdList[] = $gzcLog['id'];
|
|
|
88
|
+ // }
|
|
|
89
|
+ // }
|
|
|
90
|
+ // // 确定需要删除的ID列表
|
|
|
91
|
+ // if (!empty($gzcIdList)) {
|
|
|
92
|
+ // // 保留有gzc标志的记录,删除其他
|
|
|
93
|
+ // $delIdList = array_diff($allIds, $gzcIdList);
|
|
|
94
|
+ // } else {
|
|
|
95
|
+ // // 保留第一条记录,删除其他
|
|
|
96
|
+ // $delIdList = array_slice($allIds, 1);
|
|
|
97
|
+ // }
|
|
|
98
|
+ // $delAllIdList = array_merge($delAllIdList, $delIdList);
|
|
|
99
|
+ // }
|
|
|
100
|
+ //
|
|
|
101
|
+ // // 如果后续需要索引连续
|
|
|
102
|
+ // $delAllIdList = array_values($delAllIdList);
|
|
|
103
|
+ // $res = Db::name("gzc_logs")
|
|
|
104
|
+ // ->whereIn('id', $delAllIdList)
|
|
|
105
|
+ // ->delete();
|
|
|
106
|
+ // echo implode('、', $delAllIdList);
|
|
|
107
|
+ // echo 'deleteNum' . $res;
|
|
|
108
|
+ // // 定时任务执行中...
|
|
|
109
|
+ // // 2327、2362、2375、2413、2414、2487、2536、2550、2564、320、2576、2578、2579、2580、2581、2588、2589、2599、2601、2602、2603、2604、2605、2606、2607、2608、2614、2638、2666、2680、2706、2707、2721、2729、2736、2739、2744、2748、2811、2859、2860、2861、2897、2928、2933、3264、3277、3279、3571、3572、3573、357、1590、3673、3675、1631、3678、3679、3680、3681、2106、3683、2107、3684、2112、3685、2113、3686
|
|
|
110
|
+ // // deleteNum78
|
|
|
111
|
+ // // 定时任务执行完成
|
|
100
|
112
|
|
|
101
|
|
- // 如果后续需要索引连续
|
|
102
|
|
- $delAllIdList = array_values($delAllIdList);
|
|
103
|
|
- $res = Db::name("gzc_logs")
|
|
104
|
|
- ->whereIn('id', $delAllIdList)
|
|
105
|
|
- ->delete();
|
|
106
|
|
- echo implode('、', $delAllIdList);
|
|
107
|
|
- echo 'deleteNum' . $res;
|
|
108
|
113
|
|
|
109
|
114
|
$output->writeln('定时任务执行完成');
|
|
110
|
115
|
}
|