workerman/app/controller/IndexController.php

72 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2024-04-16 10:41:39 +08:00
<?php
namespace app\controller;
use support\Request;
2024-04-20 14:59:53 +08:00
use app\result\Result;
use Carbon\Carbon;
2024-04-16 10:41:39 +08:00
2024-04-20 15:39:33 +08:00
use app\model\Timetable;
2024-04-20 15:49:57 +08:00
use support\Log;
2024-04-20 16:03:56 +08:00
use Curl\Curl;
2024-04-16 10:41:39 +08:00
class IndexController
{
public function index(Request $request)
{
static $readme;
if (!$readme) {
2024-04-20 15:39:33 +08:00
$readme = '700';
2024-04-20 11:04:06 +08:00
// $readme = file_get_contents(base_path('README.md'));
2024-04-16 10:41:39 +08:00
}
2024-04-20 16:03:56 +08:00
Log::info('log test');
2024-04-16 10:41:39 +08:00
return $readme;
}
2024-04-20 14:59:53 +08:00
/**
* 更新时间
*/
2024-04-20 15:39:33 +08:00
public function updated($whether_manual = 1)
2024-04-16 10:41:39 +08:00
{
2024-04-20 14:59:53 +08:00
// 获取当前时间
$current = Carbon::now();
// 添加 21 天到当前时间
$trialExpires = $current->addDays(21);
2024-04-20 15:39:33 +08:00
$timetable=new Timetable;
$timetable->date=$trialExpires->toDateString();
$timetable->tip=$whether_manual==0?'自动提交':'手动提交';
$timetable->save();
return Result::show(200, 'ok', ['time' => $timetable]);
2024-04-16 10:41:39 +08:00
}
2024-04-20 11:04:06 +08:00
2024-04-20 14:59:53 +08:00
/**
* 每天访问一次的任务
*/
public function scheduled_tasks($name = 'ThinkPHP6')
{
2024-04-20 15:39:33 +08:00
$db_time = Timetable::where('id', Timetable::where('id','>',0)->max('id'))->first();
2024-04-20 14:59:53 +08:00
$time = $db_time['date'];
// 获取当前时间
$current = Carbon::now();
for ($i = 0; $i < 8; $i++) {
$current->subDay($i);
if (strcmp($current->toDateString(), $time) == 0) {
2024-04-20 15:39:33 +08:00
$i == 7 ? $this->updated(0) : '';
2024-04-20 14:59:53 +08:00
return Result::show(200, 'ok', ['time' => $current->toDateString(), 'time2' => $time]);
}
}
2024-04-20 15:39:33 +08:00
return Result::show(200,'ok','');
2024-04-16 10:41:39 +08:00
}
2024-04-20 16:03:56 +08:00
public function send_msg($title='', $body='')
2024-04-20 11:09:02 +08:00
{
2024-04-20 16:29:05 +08:00
$brak_key='3vrp4DbTGmSWxVbzHnUnPB';
2024-04-20 16:03:56 +08:00
$curl = new Curl();
2024-04-20 16:29:05 +08:00
$curl->get('https://api.day.app/3vrp4DbTGmSWxVbzHnUnPB/'.$title.'/'.$body);
2024-04-20 16:03:56 +08:00
if ($curl->error) {
$curl->diagnose();
Log::info('消息发送失败', $curl->errorMessage);
}
return Result::show(200,'ok','');
2024-04-20 11:09:02 +08:00
}
2024-04-16 10:41:39 +08:00
}