66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace app\process;
|
|
|
|
use app\common\model\UsedCar;
|
|
use app\common\model\WordpressSite;
|
|
use app\common\model\WordpressUsedCar;
|
|
use app\common\service\WordpressSiteService;
|
|
use support\Db;
|
|
use support\Log;
|
|
use Workerman\Crontab\Crontab;
|
|
|
|
class Task
|
|
{
|
|
|
|
public function onWorkerStart()
|
|
{
|
|
// 每天三点删除pdf
|
|
new Crontab('0 0 3 * * *', function(){
|
|
// echo date('Y-m-d H:i:s') . "\n";
|
|
Log::info('send follow start',[time()]);
|
|
|
|
Db::table('used_car')
|
|
->update(['pdf_src' => '']);
|
|
|
|
array_map('unlink', glob(runtime_path('pdf/*.pdf')));
|
|
array_map('unlink', glob(public_path('pdf/*.pdf')));
|
|
|
|
Log::info('send follow end',[time()]);
|
|
});
|
|
|
|
// 每三个小时自动归档
|
|
new Crontab('0 25 */3 * * *', function(){
|
|
|
|
Db::table('used_car')
|
|
->where('status', 1)
|
|
->where('created_at', '<', time() - (86400*15))
|
|
->update(['status' => 3]);
|
|
|
|
});
|
|
|
|
if (getenv('ENVIRONMENT') === 'master') {
|
|
// 每三个小时自动归档
|
|
new Crontab('0 0 3 * * *', function(){
|
|
|
|
$sites = WordpressSite::where('status', 1)
|
|
->get();
|
|
foreach ($sites as $site) {
|
|
$used_car_id = WordpressUsedCar::where('wp_site_id', $site['id'])
|
|
->where('status', 1)
|
|
->max('used_car_id');
|
|
$used_cars = Db::table('used_car')
|
|
->where('id', '>', $used_car_id)
|
|
->get();
|
|
foreach ($used_cars as $car) {
|
|
WordpressSiteService::createProduct($site['site_url'], $car['id']);
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
} |