diff --git a/app/api/controller/TeacherScheduleTimeController.php b/app/api/controller/TeacherScheduleTimeController.php index dab1814..986871f 100644 --- a/app/api/controller/TeacherScheduleTimeController.php +++ b/app/api/controller/TeacherScheduleTimeController.php @@ -67,13 +67,15 @@ class TeacherScheduleTimeController extends BaseController foreach ($student_schedule as $k => &$v) { - if($v['studentSchedule']){ - $student = []; + + if ($v['studentSchedule']) { foreach ($v['studentSchedule'] as $k1 => $v1) { - if($v1['is_publish']){ + if ($v1['is_publish']) { $student[] = $v1['student_name']; } } + } else { + $student[] = ''; } $array[] = [ @@ -82,7 +84,7 @@ class TeacherScheduleTimeController extends BaseController 'time_on' => $v['time'], 'subject' => $v['english_name'], 'teacher_name' => $v['teacher_name'], - 'student_name' => implode(',', $student), + 'student_name' => implode(',', array_unique($student)), 'time_num' => $v['hour'] . '/h', ]; $stu_nmae = $v['teacher_name']; @@ -95,6 +97,8 @@ class TeacherScheduleTimeController extends BaseController 'table_time' => $month, 'data' => $array, ]; + + $file_path = '/files/images/teacher_schedule/' . $month . "/{$request->teacher->id}/"; $base = [ 'border' => 10,//图片外边框 @@ -107,7 +111,7 @@ class TeacherScheduleTimeController extends BaseController 'filed_id_width' => 60,//序号列的宽度 'filed_name_width' => 120,//玩家名称的宽度 'filed_data_width' => 120,//数据列的宽度 - 'table_header' => ['', 'Week', 'Date', 'Time', 'Subject', 'Teacher', 'Student','Duration'],//表头文字 + 'table_header' => ['', 'Week', 'Date', 'Time', 'Subject', 'Teacher', 'Student', 'Duration'],//表头文字 'column_text_offset_arr' => [45, 70, 70, 90, 55, 65, 65, 65],//表头文字左偏移量 'row_text_offset_arr' => [50, 110, 90, 110, 90, 90, 90, 90],//数据列文字左偏移量 ]; @@ -155,7 +159,7 @@ class TeacherScheduleTimeController extends BaseController $sub = 0; foreach ($item as $value) { $sub++; - imagettftext($img, $base['text_size'], 0, $base['column_x_arr'][$sub] - $base['row_text_offset_arr'][$sub], $border_top + $base['row_hight'] - 10, $text_coler, $base['font_ulr'], $value);//写入data数据 + imagettftext($img, $base['text_size'], 0, $base['column_x_arr'][$sub] - $base['row_text_offset_arr'][$sub], $border_top + $base['row_hight'] - 10, $text_coler, $base['font_ulr'], $value ?? '');//写入data数据 } } //计算标题写入起始位置 @@ -164,7 +168,7 @@ class TeacherScheduleTimeController extends BaseController $title_fout_width = $title_fout_box[2] - $title_fout_box[0];//右下角 X 位置 - 左下角 X 位置 为文字宽度 $title_fout_height = $title_fout_box[1] - $title_fout_box[7];//左下角 Y 位置- 左上角 Y 位置 为文字高度 //居中写入标题 - imagettftext($img, $base['title_font_size'], 0, ($base['img_width'] - $title_fout_width) / 2, $base['title_height'], $text_coler, $base['font_ulr'], $params['title']); + imagettftext($img, $base['title_font_size'], 0, round(($base['img_width'] - $title_fout_width) / 2), $base['title_height'], $text_coler, $base['font_ulr'], $params['title']); //写入制表时间 imagettftext($img, $base['text_size'], 0, $base['border'], $base['title_height'], $text_coler, $base['font_ulr'], 'Date:' . $params['table_time']); $save_path = $base['file_path'] . $params['file_name']; @@ -177,11 +181,11 @@ class TeacherScheduleTimeController extends BaseController $url = getenv('SERVER_DOMAIN') . $file_path . $params['file_name']; return $this->json([ - 'code'=>ResponseCode::SUCCESS, + 'code' => ResponseCode::SUCCESS, 'data' => $url, ]); - }catch (Exception $e){ + } catch (Exception $e) { return $this->json([ 'code' => ResponseCode::FAIL, 'msg' => $e->getMessage() @@ -191,7 +195,6 @@ class TeacherScheduleTimeController extends BaseController } - public function getWeek($date) { // $week_array = array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");