feat(process): 添加任务处理功能

This commit is contained in:
mkm 2024-06-17 20:08:38 +08:00
parent 4c1a07e598
commit d43d26163f
2 changed files with 25 additions and 0 deletions

View File

@ -40,4 +40,7 @@ return [
]
]
],
'task' => [
'handler' => process\Task::class
],
];

22
process/Task.php Normal file
View File

@ -0,0 +1,22 @@
<?php
namespace process;
use app\common\model\store_order\StoreOrder;
use Workerman\Crontab\Crontab;
class Task
{
public function onWorkerStart()
{
// 每5分钟执行一次
new Crontab('0 */10 * * * *', function(){
$where=['paid'=>0];
$where[]=['create_time','<',time() - 600];// 10分钟前创建的订单
// 删除10分钟未支付的订单
StoreOrder::where($where)->update(['delete_time'=>time()]); // 删除时间设置为当前时间,即删除
});
}
}