生成课表
This commit is contained in:
parent
7b88f72965
commit
35cc2eb023
@ -65,54 +65,60 @@ class StudentController extends BaseController
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @desc 学生课表
|
||||
* @param Request $request
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function studentSchedule(Request $request)
|
||||
{
|
||||
$data = StudentSchedule::where(['student_id'])
|
||||
->with(['teacher','user'])
|
||||
->where('courserecord.user_id',$this->user_id)
|
||||
->where('courserecord.date','like',"$date%")
|
||||
->order('courserecord.date asc')
|
||||
->select();
|
||||
|
||||
$request_data = $request->post();
|
||||
$student_schedule = StudentSchedule::where(['student_id' => $request->student->id])
|
||||
->where(['month' => '2024-07'])
|
||||
->with(['teacher', 'subject'])
|
||||
->order('start_time asc')
|
||||
->select()->toArray();
|
||||
|
||||
|
||||
$array = [];
|
||||
|
||||
|
||||
$stu_nmae = '';
|
||||
|
||||
foreach($data as $k =>&$v){
|
||||
foreach ($student_schedule as $k => &$v) {
|
||||
$array[] = [
|
||||
'week'=>$this->getWeek(strtotime($v['date'])),
|
||||
'date'=>$v['date'],
|
||||
'time_on'=>$v['time_on'],
|
||||
'subject'=>$v['subject'],
|
||||
'teacher_name'=>$v['teacher']['name'],
|
||||
// 'stu_nmae'=>$v['user']['nickname'],
|
||||
|
||||
'time_num'=>$v['time_num'],
|
||||
'week' => $this->getWeek(strtotime($v['date'])),
|
||||
'date' => $v['date'],
|
||||
'time_on' => $v['time'],
|
||||
'subject' => $v['subject_name'],
|
||||
'teacher_name' => $v['teacher_name'],
|
||||
'time_num' => $v['hour'],
|
||||
];
|
||||
$stu_nmae = $v['user']['nickname'];
|
||||
$stu_nmae = $v['student_name'];
|
||||
}
|
||||
|
||||
$date = '2024-07';
|
||||
$params = [
|
||||
'row' => count($data)+1,//数据的行数
|
||||
'file_name' => time().'.png',
|
||||
'row' => count($student_schedule) + 1,//数据的行数
|
||||
'file_name' => time() . '.png',
|
||||
'title' => $stu_nmae,
|
||||
'table_time' => $date,
|
||||
'data' => $array,
|
||||
];
|
||||
$base = [
|
||||
'border' => 10,//图片外边框
|
||||
'file_path' => 'public/create_image/check/12/',//图片保存路径
|
||||
'file_path' => public_path('/files/images/'),//图片保存路径
|
||||
'title_height' => 30,//报表名称高度
|
||||
'title_font_size' =>16,//报表名称字体大小
|
||||
'font_ulr' => realpath('./uploads/111.ttf'),//字体文件路径
|
||||
'title_font_size' => 16,//报表名称字体大小
|
||||
'font_ulr' => public_path('/111.ttf'),//字体文件路径
|
||||
'text_size' => 12,//正文字体大小
|
||||
'row_hight' => 30,//每行数据行高
|
||||
'filed_id_width' => 60,//序号列的宽度
|
||||
'filed_name_width' => 120,//玩家名称的宽度
|
||||
'filed_data_width' => 100,//数据列的宽度
|
||||
'table_header' => ['','星期', '日期','上课时间', '学科', '教师', '课时'],//表头文字
|
||||
'table_header' => ['', '星期', '日期', '上课时间', '学科', '教师', '课时'],//表头文字
|
||||
'column_text_offset_arr' => [45, 70, 70, 80, 55, 65, 65],//表头文字左偏移量
|
||||
'row_text_offset_arr' => [50, 110, 90, 90, 90, 90, 90],//数据列文字左偏移量
|
||||
];
|
||||
@ -144,19 +150,19 @@ class StudentController extends BaseController
|
||||
//画表格纵线 及 写入表头文字
|
||||
foreach ($base['column_x_arr'] as $key => $x) {
|
||||
imageline($img, $x, $border_top, $x, $border_bottom, $border_coler);//画纵线
|
||||
$x = $x - $base['column_text_offset_arr'][$key] + 1;
|
||||
$x = $x - $base['column_text_offset_arr'][$key] + 1;
|
||||
// echo $x;echo "<br>";
|
||||
$y = $border_top + $base['row_hight'] - 8;
|
||||
$text = $base['table_header'][$key];
|
||||
imagettftext($img, $base['text_size'], 0, $x,$y , $text_coler, $base['font_ulr'],$text );//写入表头文字
|
||||
imagettftext($img, $base['text_size'], 0, $x, $y, $text_coler, $base['font_ulr'], $text);//写入表头文字
|
||||
}
|
||||
//画表格横线
|
||||
foreach ($params['data'] as $key => $item) {
|
||||
$border_top += $base['row_hight'];
|
||||
imageline($img, $base['border'], $border_top, $base['img_width'] - $base['border'], $border_top, $border_coler);
|
||||
$x = $base['column_x_arr'][0] - $base['row_text_offset_arr'][0];
|
||||
$x = $base['column_x_arr'][0] - $base['row_text_offset_arr'][0];
|
||||
$y = $border_top + $base['row_hight'] - 10;
|
||||
$text = $key + 1;
|
||||
$text = $key + 1;
|
||||
imagettftext($img, $base['text_size'], 0, $x, $y, $text_coler, $base['font_ulr'], $text);//写入序号
|
||||
$sub = 0;
|
||||
foreach ($item as $value) {
|
||||
@ -181,4 +187,12 @@ class StudentController extends BaseController
|
||||
imagepng($img, $save_path);//输出图片,输出png使用imagepng方法,输出gif使用imagegif方法
|
||||
}
|
||||
|
||||
|
||||
public function getWeek($date)
|
||||
{
|
||||
$week_array = array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
|
||||
$week = date("w", $date);
|
||||
return $week_array[$week];
|
||||
}
|
||||
|
||||
}
|
BIN
public/111.ttf
Normal file
BIN
public/111.ttf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user