diff --git a/app/api/controller/TestController.php b/app/api/controller/TestController.php index 75a4a5e..8ffadb1 100644 --- a/app/api/controller/TestController.php +++ b/app/api/controller/TestController.php @@ -4,11 +4,15 @@ namespace app\api\controller; use app\BaseController; use app\common\model\TimeZone; +use app\common\service\SendMsgCronJobService; use app\common\service\UploadService; use app\constant\ResponseCode; use app\utils\QiniuUtils; +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; +use PhpOffice\PhpSpreadsheet\IOFactory; use support\Redis; use support\Request; +use think\Exception; use Tinywan\Jwt\JwtToken; class TestController extends BaseController @@ -21,36 +25,40 @@ class TestController extends BaseController try { - phpinfo(); - $res = Redis::setEx('test', 60, 10); + (new SendMsgCronJobService())->classBeginMsgToTeacherBeforeDay(); - print '
'; - print_r($res); - die; +// // 使用示例 +// $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 ''; +// print_r($timePeriods); +// die; +// +// if (is_time_cross(...$timePeriods)) { +// echo "时间段没有交集"; +// } else { +// echo "时间段有交集"; +// } +// print ''; +// 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 ''; +// 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 ''; - print_r('success'); - die; $token_data = [ - 'id' => 7 + 'id' => 37, + 'role' => 'parent' ]; $token = JwtToken::generateToken($token_data); print ''; @@ -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) { $service = new UploadService(); diff --git a/app/common/service/SendMsgCronJobService.php b/app/common/service/SendMsgCronJobService.php index 2c0ce00..0b88bca 100644 --- a/app/common/service/SendMsgCronJobService.php +++ b/app/common/service/SendMsgCronJobService.php @@ -338,8 +338,8 @@ class SendMsgCronJobService { try { $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 23:59:59', 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('+0 day'))) ->with(['teacherAttr', 'subject', 'studentSchedule']) ->select(); @@ -378,7 +378,8 @@ class SendMsgCronJobService } $student_name = implode(',', array_column($student_info, 'student_name')); - if (!empty($student_name)) { + + if (empty($student_name)) { CronJob::create([ 'msg_type' => self::CLASS_BEGIN_NOTIFY_TEACHER, 'teacher_id' => $item->teacher_id, @@ -401,7 +402,7 @@ class SendMsgCronJobService } $send_teacher_data = [ - 'touser' => $item['teacherArr']['openid'], + 'touser' => $item['teacherAttr']['openid'], 'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI', 'data' => [ 'thing8' => [//课程名称 @@ -409,11 +410,11 @@ class SendMsgCronJobService 'color' => '#000000' ], 'time5' => [//上课时间 - 'value' => $item->end_time, + 'value' => $item->en_start_time, 'color' => '#000000' ], 'thing4' => [//任课教师 - 'value' => $item->teacherAttr->teacher_name, + 'value' => $item['teacherAttr']['account'], 'color' => '#000000' ], 'thing7' => [//学员姓名 @@ -453,7 +454,7 @@ class SendMsgCronJobService foreach ($student_info as $student) { //通知学生 $send_teacher_data = [ - 'touser' => $student['openid']->openid, + 'touser' => $student['openid'], 'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI', 'data' => [ 'thing8' => [//课程名称 @@ -461,15 +462,15 @@ class SendMsgCronJobService 'color' => '#000000' ], 'time5' => [//上课时间 - 'value' => $item->end_time, + 'value' => $item->start_time, 'color' => '#000000' ], 'thing4' => [//任课教师 - 'value' => $item->teacherAttr->teacher_name, + 'value' => $item->teacherAttr->account, 'color' => '#000000' ], 'thing7' => [//学员姓名 - 'value' => $student_name, + 'value' => $student['student_name'], 'color' => '#000000' ] ], @@ -514,7 +515,7 @@ class SendMsgCronJobService 'color' => '#000000' ], 'time5' => [//上课时间 - 'value' => $item->end_time, + 'value' => $item->start_time, 'color' => '#000000' ], 'thing4' => [//任课教师 @@ -575,8 +576,7 @@ class SendMsgCronJobService { try { $teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1]) - ->whereTime('start_time', '>=', date('Y-m-d 00:00:00', strtotime('+10 minute'))) - ->whereTime('start_time', '<=', date('Y-m-d 00:00:00', strtotime('+11 minute'))) + ->whereBetweenTime('start_time', date('Y-m-d H:i:00', strtotime('+10 minute')), date('Y-m-d H:i:00', strtotime('+11 minute'))) ->with(['teacherAttr', 'subject', 'studentSchedule']) ->select(); diff --git a/plugin/admin/app/model/Test.php b/plugin/admin/app/model/Test.php index 7eb6a03..a32187e 100644 --- a/plugin/admin/app/model/Test.php +++ b/plugin/admin/app/model/Test.php @@ -5,12 +5,9 @@ namespace plugin\admin\app\model; use plugin\admin\app\model\Base; /** - * @property integer $id 主键(主键) - * @property string $service_type 服务类型 - * @property string $created_at 创建时间 - * @property string $updated_at 更新时间 - * @property string $deleted_at - * @property integer $user_type 用户类型 + * @property integer $id (主键) + * @property integer $user_id 用户 + * @property integer $role_id 角色 */ class Test extends Base { @@ -27,7 +24,13 @@ class Test extends Base * @var string */ protected $primaryKey = 'id'; - + /** + * Indicates if the model should be timestamped. + * + * @var bool + */ + public $timestamps = false; + }