发布推送

This commit is contained in:
ROmani
2024-02-26 00:41:25 +08:00
parent 70304f730b
commit 1a9008b318
33 changed files with 1515 additions and 216 deletions

View File

@ -0,0 +1,82 @@
<?php
namespace App\Tools;
class CollectOffsetLimit
{
private $offset = 0;
private $limit = 2000;
private $page = 0;
private $iTotalCount = null;
public $fCountFun;
function setCountFun(\Closure $fun)
{
$this->fCountFun = $fun();
return $this;
}
private function countPage()
{
if($this->iTotalCount === null && $this->fCountFun !== null){
$this->iTotalCount = $this->fCountFun;
}
if(empty($this->page) && !empty($this->iTotalCount)){
$this->page = ceil($this->iTotalCount / $this->limit);
}
}
function runWhile(\Closure $fun)
{
$this->countPage();
if($this->iTotalCount === null) $this->iTotalCount = $this->fCountFun;
if($this->iTotalCount === 0 | $this->page === 0) return [];
for( $iPage = 1; $iPage <= $this->page; $iPage++){
$this->offset = ($iPage - 1) * $this->limit;
$fun($this->offset,$this->limit);
}
$this->offset = 0;
}
public function getLimit(): int
{
return $this->limit;
}
public function setLimit(int $limit): void
{
$this->limit = $limit;
}
public function getOffset(): int
{
return $this->offset;
}
public function setOffset(int $offset): void
{
$this->offset = $offset;
}
/**
* @return null
*/
public function getITotalCount()
{
return $this->iTotalCount;
}
/**
* @param null $iTotalCount
*/
public function setITotalCount($iTotalCount): CollectOffsetLimit
{
$this->iTotalCount = $iTotalCount;
return $this;
}
}