正在显示
2 个修改的文件
包含
37 行增加
和
14 行删除
| @@ -59,22 +59,12 @@ class AutoMail { | @@ -59,22 +59,12 @@ class AutoMail { | ||
| 59 | if(redis()->add('auto_mail_sync2',1,60)){ | 59 | if(redis()->add('auto_mail_sync2',1,60)){ |
| 60 | _echo('正在计算数据'); | 60 | _echo('正在计算数据'); |
| 61 | $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1"); | 61 | $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1"); |
| 62 | - $id = 0; | ||
| 63 | - while (1){ | ||
| 64 | - $ids = []; | ||
| 65 | - for ($i=0;$i<1000;$i++){ | ||
| 66 | - $ids[] = $i+$id; | ||
| 67 | - } | ||
| 68 | - $id = end($ids); | ||
| 69 | - if($id<($maxId-10000)){ | ||
| 70 | - continue; | ||
| 71 | - } | ||
| 72 | - redis()->rPush('auto_check_ids',implode(',',$ids)); | 62 | + $startId = $maxId-10000; |
| 73 | 63 | ||
| 74 | - if($id>$maxId){ | ||
| 75 | - break; | ||
| 76 | - } | 64 | + foreach (minMaxToArray($startId,$maxId) as $ids){ |
| 65 | + redis()->rPush('auto_check_ids',implode(',',$ids)); | ||
| 77 | } | 66 | } |
| 67 | + | ||
| 78 | _echo('计算完成'); | 68 | _echo('计算完成'); |
| 79 | } | 69 | } |
| 80 | 70 |
| @@ -595,4 +595,37 @@ function base64_de_md5(string $str){ | @@ -595,4 +595,37 @@ function base64_de_md5(string $str){ | ||
| 595 | 595 | ||
| 596 | return base64_decode(implode('',$strs).'=='); | 596 | return base64_decode(implode('',$strs).'=='); |
| 597 | 597 | ||
| 598 | +} | ||
| 599 | + | ||
| 600 | + | ||
| 601 | +/** | ||
| 602 | + * 把最大最小之间的数生成 二维数组 | ||
| 603 | + * [[2,3,4],[5,6,7],....] | ||
| 604 | + * @param $min | ||
| 605 | + * @param $max | ||
| 606 | + * @param int $len | ||
| 607 | + * @return array | ||
| 608 | + * @author:dc | ||
| 609 | + * @time 2025/3/7 0:06 | ||
| 610 | + */ | ||
| 611 | +function minMaxToArray($min, $max,$len=1000) { | ||
| 612 | + $result = []; | ||
| 613 | + $currentGroup = []; | ||
| 614 | + | ||
| 615 | + for ($i = $min; $i <= $max; $i++) { | ||
| 616 | + $currentGroup[] = $i; | ||
| 617 | + | ||
| 618 | + // 每1000个数就创建一个新组 | ||
| 619 | + if (count($currentGroup) == $len) { | ||
| 620 | + $result[] = $currentGroup; | ||
| 621 | + $currentGroup = []; // 重置当前组 | ||
| 622 | + } | ||
| 623 | + } | ||
| 624 | + | ||
| 625 | + // 如果还有剩余的数,添加到结果中 | ||
| 626 | + if (!empty($currentGroup)) { | ||
| 627 | + $result[] = $currentGroup; | ||
| 628 | + } | ||
| 629 | + | ||
| 630 | + return $result; | ||
| 598 | } | 631 | } |
-
请 注册 或 登录 后发表评论