workerman/app/controller/IndexController.php

64 lines
1.6 KiB
PHP

<?php
namespace app\controller;
use support\Request;
use support\Db;
use app\result\Result;
use Carbon\Carbon;
class IndexController
{
public function index(Request $request)
{
static $readme;
if (!$readme) {
$readme = '70';
// $readme = file_get_contents(base_path('README.md'));
}
return $readme;
}
/**
* 更新时间
*/
public function updated($name = 'ThinkPHP6')
{
// 获取当前时间
$current = Carbon::now();
// 添加 21 天到当前时间
$trialExpires = $current->addDays(21);
$data = ['date' => $trialExpires->toDateString(), 'tip' => ' '];
// $result = Db::table("demo")->where("id",1)->find();
// dump($result);
Db::table('time_log')->insert($data);
return Result::show(200, 'ok', ['time' => $trialExpires]);
}
/**
* 每天访问一次的任务
*/
public function scheduled_tasks($name = 'ThinkPHP6')
{
$db_time = Db::table('time_log')->where('id', Db::table('time_log')->max('id'))->first();
//dump($db_time);
$time = $db_time['date'];
// 获取当前时间
$current = Carbon::now();
for ($i = 0; $i < 8; $i++) {
$current->subDay($i);
if (strcmp($current->toDateString(), $time) == 0) {
echo "to do ";
//$this->updated("");
$i == 7 ? $this->updated("") : '';
return Result::show(200, 'ok', ['time' => $current->toDateString(), 'time2' => $time]);
}
}
}
public function send_msg($title, $body)
{
}
}