fix 定时任务通知
This commit is contained in:
parent
0b22f96c4a
commit
3c60610271
@ -4,11 +4,15 @@ namespace app\api\controller;
|
|||||||
|
|
||||||
use app\BaseController;
|
use app\BaseController;
|
||||||
use app\common\model\TimeZone;
|
use app\common\model\TimeZone;
|
||||||
|
use app\common\service\SendMsgCronJobService;
|
||||||
use app\common\service\UploadService;
|
use app\common\service\UploadService;
|
||||||
use app\constant\ResponseCode;
|
use app\constant\ResponseCode;
|
||||||
use app\utils\QiniuUtils;
|
use app\utils\QiniuUtils;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use support\Redis;
|
use support\Redis;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
use think\Exception;
|
||||||
use Tinywan\Jwt\JwtToken;
|
use Tinywan\Jwt\JwtToken;
|
||||||
|
|
||||||
class TestController extends BaseController
|
class TestController extends BaseController
|
||||||
@ -21,36 +25,40 @@ class TestController extends BaseController
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
phpinfo();
|
(new SendMsgCronJobService())->classBeginMsgToTeacherBeforeDay();
|
||||||
$res = Redis::setEx('test', 60, 10);
|
|
||||||
|
|
||||||
print '<pre>';
|
// // 使用示例
|
||||||
print_r($res);
|
// $timePeriods = [
|
||||||
die;
|
// ['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;
|
||||||
|
|
||||||
|
|
||||||
$time_zone = json_decode(file_get_contents(base_path('/timezones.json')), true);
|
|
||||||
|
|
||||||
foreach ($time_zone as $index => $item) {
|
|
||||||
$res = TimeZone::create([
|
|
||||||
'name' => $item['value'],
|
|
||||||
'abbr' => $item['abbr'],
|
|
||||||
'text' => $item['text'],
|
|
||||||
'offset' => $item['offset'],
|
|
||||||
'utc' => json_encode($item['utc'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
|
||||||
]);
|
|
||||||
if ($res) {
|
|
||||||
var_dump($index . '-成功');
|
|
||||||
} else {
|
|
||||||
var_dump($index . '-失败');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print '<pre>';
|
|
||||||
print_r('success');
|
|
||||||
die;
|
|
||||||
$token_data = [
|
$token_data = [
|
||||||
'id' => 7
|
'id' => 37,
|
||||||
|
'role' => 'parent'
|
||||||
];
|
];
|
||||||
$token = JwtToken::generateToken($token_data);
|
$token = JwtToken::generateToken($token_data);
|
||||||
print '<pre>';
|
print '<pre>';
|
||||||
@ -72,6 +80,35 @@ class TestController extends BaseController
|
|||||||
// ]);
|
// ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
public function upload(Request $request)
|
||||||
{
|
{
|
||||||
$service = new UploadService();
|
$service = new UploadService();
|
||||||
|
@ -338,8 +338,8 @@ class SendMsgCronJobService
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1])
|
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1])
|
||||||
->whereTime('start_time', '>=', date('Y-m-d 00:00:00', strtotime('+1 day')))
|
->whereTime('start_time', '>=', date('Y-m-d 00:00:00', strtotime('+0 day')))
|
||||||
->whereTime('start_time', '<=', date('Y-m-d 23:59:59', strtotime('+1 day')))
|
->whereTime('start_time', '<=', date('Y-m-d 23:59:59', strtotime('+0 day')))
|
||||||
->with(['teacherAttr', 'subject', 'studentSchedule'])
|
->with(['teacherAttr', 'subject', 'studentSchedule'])
|
||||||
->select();
|
->select();
|
||||||
|
|
||||||
@ -378,7 +378,8 @@ class SendMsgCronJobService
|
|||||||
}
|
}
|
||||||
$student_name = implode(',', array_column($student_info, 'student_name'));
|
$student_name = implode(',', array_column($student_info, 'student_name'));
|
||||||
|
|
||||||
if (!empty($student_name)) {
|
|
||||||
|
if (empty($student_name)) {
|
||||||
CronJob::create([
|
CronJob::create([
|
||||||
'msg_type' => self::CLASS_BEGIN_NOTIFY_TEACHER,
|
'msg_type' => self::CLASS_BEGIN_NOTIFY_TEACHER,
|
||||||
'teacher_id' => $item->teacher_id,
|
'teacher_id' => $item->teacher_id,
|
||||||
@ -401,7 +402,7 @@ class SendMsgCronJobService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$send_teacher_data = [
|
$send_teacher_data = [
|
||||||
'touser' => $item['teacherArr']['openid'],
|
'touser' => $item['teacherAttr']['openid'],
|
||||||
'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI',
|
'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI',
|
||||||
'data' => [
|
'data' => [
|
||||||
'thing8' => [//课程名称
|
'thing8' => [//课程名称
|
||||||
@ -409,11 +410,11 @@ class SendMsgCronJobService
|
|||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
],
|
],
|
||||||
'time5' => [//上课时间
|
'time5' => [//上课时间
|
||||||
'value' => $item->end_time,
|
'value' => $item->en_start_time,
|
||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
],
|
],
|
||||||
'thing4' => [//任课教师
|
'thing4' => [//任课教师
|
||||||
'value' => $item->teacherAttr->teacher_name,
|
'value' => $item['teacherAttr']['account'],
|
||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
],
|
],
|
||||||
'thing7' => [//学员姓名
|
'thing7' => [//学员姓名
|
||||||
@ -453,7 +454,7 @@ class SendMsgCronJobService
|
|||||||
foreach ($student_info as $student) {
|
foreach ($student_info as $student) {
|
||||||
//通知学生
|
//通知学生
|
||||||
$send_teacher_data = [
|
$send_teacher_data = [
|
||||||
'touser' => $student['openid']->openid,
|
'touser' => $student['openid'],
|
||||||
'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI',
|
'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI',
|
||||||
'data' => [
|
'data' => [
|
||||||
'thing8' => [//课程名称
|
'thing8' => [//课程名称
|
||||||
@ -461,15 +462,15 @@ class SendMsgCronJobService
|
|||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
],
|
],
|
||||||
'time5' => [//上课时间
|
'time5' => [//上课时间
|
||||||
'value' => $item->end_time,
|
'value' => $item->start_time,
|
||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
],
|
],
|
||||||
'thing4' => [//任课教师
|
'thing4' => [//任课教师
|
||||||
'value' => $item->teacherAttr->teacher_name,
|
'value' => $item->teacherAttr->account,
|
||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
],
|
],
|
||||||
'thing7' => [//学员姓名
|
'thing7' => [//学员姓名
|
||||||
'value' => $student_name,
|
'value' => $student['student_name'],
|
||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@ -514,7 +515,7 @@ class SendMsgCronJobService
|
|||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
],
|
],
|
||||||
'time5' => [//上课时间
|
'time5' => [//上课时间
|
||||||
'value' => $item->end_time,
|
'value' => $item->start_time,
|
||||||
'color' => '#000000'
|
'color' => '#000000'
|
||||||
],
|
],
|
||||||
'thing4' => [//任课教师
|
'thing4' => [//任课教师
|
||||||
@ -575,8 +576,7 @@ class SendMsgCronJobService
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1])
|
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1])
|
||||||
->whereTime('start_time', '>=', date('Y-m-d 00:00:00', strtotime('+10 minute')))
|
->whereBetweenTime('start_time', date('Y-m-d H:i:00', strtotime('+10 minute')), date('Y-m-d H:i:00', strtotime('+11 minute')))
|
||||||
->whereTime('start_time', '<=', date('Y-m-d 00:00:00', strtotime('+11 minute')))
|
|
||||||
->with(['teacherAttr', 'subject', 'studentSchedule'])
|
->with(['teacherAttr', 'subject', 'studentSchedule'])
|
||||||
->select();
|
->select();
|
||||||
|
|
||||||
|
@ -5,12 +5,9 @@ namespace plugin\admin\app\model;
|
|||||||
use plugin\admin\app\model\Base;
|
use plugin\admin\app\model\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property integer $id 主键(主键)
|
* @property integer $id (主键)
|
||||||
* @property string $service_type 服务类型
|
* @property integer $user_id 用户
|
||||||
* @property string $created_at 创建时间
|
* @property integer $role_id 角色
|
||||||
* @property string $updated_at 更新时间
|
|
||||||
* @property string $deleted_at
|
|
||||||
* @property integer $user_type 用户类型
|
|
||||||
*/
|
*/
|
||||||
class Test extends Base
|
class Test extends Base
|
||||||
{
|
{
|
||||||
@ -27,7 +24,13 @@ class Test extends Base
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $primaryKey = 'id';
|
protected $primaryKey = 'id';
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user