feat : cycle

This commit is contained in:
2024-12-23 11:24:33 +08:00
parent 6cd9f70e6a
commit b2ec16a50a
2 changed files with 42 additions and 1 deletions

View File

@@ -10,14 +10,24 @@ declare(strict_types=1);
namespace App\Cron\Good; namespace App\Cron\Good;
use App\Model\Cycle;
use Hyperf\Crontab\Annotation\Crontab; use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;
#[Crontab(rule: "0 5 * * *", name: "CycleCreateTask", singleton: true , callback: "execute", memo: "这是一个示例的定时任务")] #[Crontab(rule: "0 5 * * *", name: "CycleCreateTask", singleton: true , callback: "execute", memo: "创建新的周期任务")]
class CycleCreateTask class CycleCreateTask
{ {
/**
* @var Cycle $cycleModel
*/
#[Inject]
protected Cycle $cycleModel;
public function execute() public function execute()
{ {
//todo Write logic //todo Write logic
var_dump(date('Y-m-d H:i:s', time())); var_dump(date('Y-m-d H:i:s', time()));
$maxDate = $this->cycleModel->max('date');
} }
} }

31
app/Model/Cycle.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property string $dates
* @property int $is_use
* @property string $create_time
*/
class Cycle extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'cycle';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'is_use' => 'integer'];
}