workerman/app/controller/IndexController.php

72 lines
1.9 KiB
PHP

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