sql/app/controller/Index.php

85 lines
3.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\controller;
use app\BaseController;
use think\Facade\Db;
use Carbon\Carbon;
class Index extends BaseController
{
public function index()
{
return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">16载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
}
public function hello($name = 'ThinkPHP6')
{
return 'hello,' . $name;
}
/**
* 更新时间
*/
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 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'))->find();;
//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 show(200, 'ok', ['time' => $current->toDateString(),'time2'=>$time]);
}
}
}
/**
* 更新时间
*/
public function send_msg($title,$body)
{
// 添加 30 天到当前时间
// 1.当前任务将由哪个类来负责处理。
// 当轮到该任务时,系统将生成一个该类的实例,并调用其 fire 方法
$jobHandlerClassName = 'app\job\Hello';
// 2.当前任务归属的队列名称,如果为新队列,会自动创建
$jobQueueName = "helloJobQueue";
// 3.当前任务所需的业务数据 . 不能为 resource 类型其他类型最终将转化为json形式的字符串
// ( jobData 为对象时存储其public属性的键值对 )
$jobData = ['ts' => time(), 'bizId' => uniqid(), 'a' => 1,'title'=>$title,'body'=>$body];
// 4.将该任务推送到消息队列,等待对应的消费者去执行
$isPushed = Queue::push($jobHandlerClassName, $jobData, $jobQueueName);
// database 驱动时,返回值为 1|false ; redis 驱动时,返回值为 随机字符串|false
if ($isPushed !== false) {
Log::info(date('Y-m-d H:i:s')."消息已经推送");
} else {
Log::error(date('Y-m-d H:i:s')."消息推送失败请检查队列驱动");
}
}
}