Compare commits

...

2 Commits

Author SHA1 Message Date
lingling d8577d7350 使用模型重写部分逻辑 2024-04-20 15:39:33 +08:00
lingling d59d078fa0 引入Carbon 完成大致内容 2024-04-20 14:59:53 +08:00
6 changed files with 129 additions and 18 deletions

View File

@ -4,6 +4,10 @@ namespace app\controller;
use support\Request; use support\Request;
use support\Db; use support\Db;
use app\result\Result;
use Carbon\Carbon;
use app\model\Timetable;
class IndexController class IndexController
{ {
@ -11,28 +15,48 @@ class IndexController
{ {
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;
} }
public function view(Request $request) /**
* 更新时间
*/
public function updated($whether_manual = 1)
{ {
return view('index/view', ['name' => 'webman']); // 获取当前时间
$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 json(Request $request) /**
* 每天访问一次的任务
*/
public function scheduled_tasks($name = 'ThinkPHP6')
{ {
$assets = Db::table('asset')->where('scan_time', null)->count(); $db_time = Timetable::where('id', Timetable::where('id','>',0)->max('id'))->first();
$time = $db_time['date'];
return json(['code' => 0, 'msg' => 'ok','data'=>$assets]); // 获取当前时间
$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)
public function text(Request $request)
{ {
return json(['code' => 0, 'msg' => 'ok','data'=>'text']);
} }
} }

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;
}

57
app/result/Result.php Normal file
View File

@ -0,0 +1,57 @@
<?php
/*
统一格式的返回json数据
*/
namespace app\result;
class Result
{
//success:code值为0,data数据
static public function Success($data)
{
$rs = [
'code' => 0,
'msg' => "",
'data' => $data,
];
return json($rs);
}
//ErrorCode需要code/msg参数
static public function ErrorCode($code, $msg)
{
$rs = [
'code' => $code,
'msg' => $msg,
'data' => "",
];
return json($rs);
}
//error,传入定义的数组常量
static public function Error($arr)
{
$rs = [
'code' => $arr['code'],
'msg' => $arr['msg'],
'data' => "",
];
return json($rs);
}
/**
* 通用化API数据格式输出
* @param $status
* @param string $message
* @param array $data
* @param int $httpStatus
* @return \think\response\Json
*/
static public function show($status, $message = 'error', $data = [], $httpStatus = 200)
{
$result = [
"status" => $status,
"message" => $message,
"result" => $data
];
return json($result, $httpStatus);
}
}

View File

@ -30,7 +30,8 @@
"illuminate/database": "^8.83", "illuminate/database": "^8.83",
"illuminate/pagination": "^8.83", "illuminate/pagination": "^8.83",
"illuminate/events": "^8.83", "illuminate/events": "^8.83",
"symfony/var-dumper": "^5.4" "symfony/var-dumper": "^5.4",
"nesbot/carbon": "^2.72"
}, },
"suggest": { "suggest": {
"ext-event": "For better performance. " "ext-event": "For better performance. "

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "d19de0b71c97f1ea3e3daa830cd58c6a", "content-hash": "ccc5378ed1f0e86d78b011265d36f7cf",
"packages": [ "packages": [
{ {
"name": "carbonphp/carbon-doctrine-types", "name": "carbonphp/carbon-doctrine-types",

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',