使用模型重写部分逻辑

This commit is contained in:
lingling 2024-04-20 15:39:33 +08:00
parent d59d078fa0
commit d8577d7350
3 changed files with 44 additions and 16 deletions

View File

@ -7,13 +7,15 @@ use support\Db;
use app\result\Result; use app\result\Result;
use Carbon\Carbon; use Carbon\Carbon;
use app\model\Timetable;
class IndexController class IndexController
{ {
public function index(Request $request) public function index(Request $request)
{ {
static $readme; static $readme;
if (!$readme) { if (!$readme) {
$readme = '70'; $readme = '700';
// $readme = file_get_contents(base_path('README.md')); // $readme = file_get_contents(base_path('README.md'));
} }
return $readme; return $readme;
@ -22,18 +24,18 @@ class IndexController
/** /**
* 更新时间 * 更新时间
*/ */
public function updated($name = 'ThinkPHP6') public function updated($whether_manual = 1)
{ {
// 获取当前时间 // 获取当前时间
$current = Carbon::now(); $current = Carbon::now();
// 添加 21 天到当前时间 // 添加 21 天到当前时间
$trialExpires = $current->addDays(21); $trialExpires = $current->addDays(21);
$data = ['date' => $trialExpires->toDateString(), 'tip' => ' ']; $timetable=new Timetable;
// $result = Db::table("demo")->where("id",1)->find(); $timetable->date=$trialExpires->toDateString();
// dump($result); $timetable->tip=$whether_manual==0?'自动提交':'手动提交';
Db::table('time_log')->insert($data); $timetable->save();
return Result::show(200, 'ok', ['time' => $trialExpires]); return Result::show(200, 'ok', ['time' => $timetable]);
} }
/** /**
@ -41,21 +43,18 @@ class IndexController
*/ */
public function scheduled_tasks($name = 'ThinkPHP6') public function scheduled_tasks($name = 'ThinkPHP6')
{ {
$db_time = Db::table('time_log')->where('id', Db::table('time_log')->max('id'))->first(); $db_time = Timetable::where('id', Timetable::where('id','>',0)->max('id'))->first();
//dump($db_time);
$time = $db_time['date']; $time = $db_time['date'];
// 获取当前时间 // 获取当前时间
$current = Carbon::now(); $current = Carbon::now();
for ($i = 0; $i < 8; $i++) { for ($i = 0; $i < 8; $i++) {
$current->subDay($i); $current->subDay($i);
if (strcmp($current->toDateString(), $time) == 0) { if (strcmp($current->toDateString(), $time) == 0) {
$i == 7 ? $this->updated(0) : '';
echo "to do ";
//$this->updated("");
$i == 7 ? $this->updated("") : '';
return Result::show(200, 'ok', ['time' => $current->toDateString(), 'time2' => $time]); return Result::show(200, 'ok', ['time' => $current->toDateString(), 'time2' => $time]);
} }
} }
return Result::show(200,'ok','');
} }
public function send_msg($title, $body) public function send_msg($title, $body)
{ {

29
app/model/Timetable.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace app\model;
use support\Model;
class Timetable extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'timetable';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
}

View File

@ -22,9 +22,9 @@
'driver' => 'mysql', 'driver' => 'mysql',
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => 3306, 'port' => 3306,
'database' => 'kunkun_shagain_c', 'database' => 'sql',
'username' => 'kunkun_shagain_c', 'username' => 'sql',
'password' => 'JcAT8frcGfrrrJBN', 'password' => 'arxYBLyp3nMePn5C',
'unix_socket' => '', 'unix_socket' => '',
'charset' => 'utf8', 'charset' => 'utf8',
'collation' => 'utf8_unicode_ci', 'collation' => 'utf8_unicode_ci',