course/app/api/controller/TestController.php

119 lines
3.5 KiB
PHP
Raw Normal View History

<?php
namespace app\api\controller;
use app\BaseController;
use app\common\model\TimeZone;
2024-11-06 21:14:36 +08:00
use app\common\service\SendMsgCronJobService;
use app\common\service\UploadService;
use app\constant\ResponseCode;
use app\utils\QiniuUtils;
2024-11-06 21:14:36 +08:00
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\IOFactory;
use support\Redis;
use support\Request;
2024-11-06 21:14:36 +08:00
use think\Exception;
use Tinywan\Jwt\JwtToken;
class TestController extends BaseController
{
protected $noNeedLogin = ['*'];
public function test(Request $request)
{
try {
2024-11-06 21:14:36 +08:00
(new SendMsgCronJobService())->classBeginMsgToTeacherBeforeDay();
// // 使用示例
// $timePeriods = [
// ['beginTime' => '2024-05-01 08:00', 'endTime' => '2024-05-01 11:00'],
// ['beginTime' => '2024-05-01 11:00', 'endTime' => '2024-05-01 12:30'],
// ['beginTime' => '2024-05-01 12:00', 'endTime' => '2024-05-01 15:00']
// ];
//
// print '<pre>';
// print_r($timePeriods);
// die;
//
// if (is_time_cross(...$timePeriods)) {
// echo "时间段没有交集";
// } else {
// echo "时间段有交集";
// }
// print '<pre>';
// print_r(111);
// die;
//
// $startTime1 = '2024-10-20 7:00:00';
// $endTime1 = '2024-10-20 8:00:00';
// $startTime2 = '2024-10-20 6:00:00';
// $endTime2 = '2024-10-20 7:30:00';
//
// print '<pre>';
// print_r(is_time_cross($startTime1, $endTime1, $startTime2, $endTime2));
// die;
$token_data = [
2024-11-06 21:14:36 +08:00
'id' => 37,
'role' => 'parent'
];
$token = JwtToken::generateToken($token_data);
print '<pre>';
print_r($token);
die;
// throw new \Exception('显示是错误测试');
} catch (\Exception $e) {
return $this->json([
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
]);
}
// return $this->json([
// 'code' => ResponseCode::SUCCESS,
// 'data'=>[1,2,3],
// 'msg' => '变更成功',
// ]);
}
2024-11-06 21:14:36 +08:00
function is_time_cross1231(...$timePeriods) {
// 将时间字符串转换为时间戳
$timePeriods = array_map(function ($period) {
extract($period);
return [
'begin' => strtotime($beginTime),
'end' => strtotime($endTime)
];
}, $timePeriods);
// 递归函数来检查时间段是否有交集
$checkCross = function ($index, $timePeriods) use (&$checkCross) {
if ($index === count($timePeriods) - 1) {
return true; // 最后一个时间段,没有交集
}
for ($i = $index + 1; $i < count($timePeriods); $i++) {
if ($timePeriods[$index]['end'] > $timePeriods[$i]['begin'] && $timePeriods[$i]['end'] > $timePeriods[$index]['begin']) {
return false; // 有交集
}
}
return $checkCross($index + 1, $timePeriods); // 递归检查下一个时间段
};
return $checkCross(0, $timePeriods); // 从第一个时间段开始检查
}
public function upload(Request $request)
{
$service = new UploadService();
$res = $service->uploadImg($request);
return $this->json($res);
}
}