学生绑定opendi、生成课程表

This commit is contained in:
Dai 2024-07-24 22:37:22 +08:00
parent 18fea029f8
commit 40f339e5af
8 changed files with 177 additions and 13 deletions

View File

@ -3,6 +3,7 @@
namespace app\api\controller;
use app\BaseController;
use app\common\model\StudentSchedule;
use app\common\service\StudentService;
use app\constant\ResponseCode;
use support\Request;
@ -59,7 +60,125 @@ class StudentController extends BaseController
public function updateOpenid(Request $request)
{
$service = new StudentService();
$res = $service->updateOpenid($request);
return $this->json($res);
}
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();
$array = [];
$stu_nmae = '';
foreach($data 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'],
];
$stu_nmae = $v['user']['nickname'];
}
$params = [
'row' => count($data)+1,//数据的行数
'file_name' => time().'.png',
'title' => $stu_nmae,
'table_time' => $date,
'data' => $array,
];
$base = [
'border' => 10,//图片外边框
'file_path' => 'public/create_image/check/12/',//图片保存路径
'title_height' => 30,//报表名称高度
'title_font_size' =>16,//报表名称字体大小
'font_ulr' => realpath('./uploads/111.ttf'),//字体文件路径
'text_size' => 12,//正文字体大小
'row_hight' => 30,//每行数据行高
'filed_id_width' => 60,//序号列的宽度
'filed_name_width' => 120,//玩家名称的宽度
'filed_data_width' => 100,//数据列的宽度
'table_header' => ['','星期', '日期','上课时间', '学科', '教师', '课时'],//表头文字
'column_text_offset_arr' => [45, 70, 70, 80, 55, 65, 65],//表头文字左偏移量
'row_text_offset_arr' => [50, 110, 90, 90, 90, 90, 90],//数据列文字左偏移量
];
$base['img_width'] = $base['filed_id_width'] + $base['filed_name_width'] + $base['filed_data_width'] * 5 + $base['border'] * 2;//图片宽度
$base['img_height'] = $params['row'] * $base['row_hight'] + $base['border'] * 2 + $base['title_height'];//图片高度
$border_top = $base['border'] + $base['title_height'];//表格顶部高度
$border_bottom = $base['img_height'] - $base['border'];//表格底部高度
$base['column_x_arr'] = [
$base['border'] + $base['filed_id_width'],//第一列边框线x轴像素 70/2+10
$base['border'] + $base['filed_id_width'] + $base['filed_name_width'],//第二列边框线x轴像素 190
$base['border'] + $base['filed_id_width'] + $base['filed_name_width'] + $base['filed_data_width'] * 1,//第三列边框线x轴像素
$base['border'] + $base['filed_id_width'] + $base['filed_name_width'] + $base['filed_data_width'] * 2,//第四列边框线x轴像素
$base['border'] + $base['filed_id_width'] + $base['filed_name_width'] + $base['filed_data_width'] * 3,//第五列边框线x轴像素
$base['border'] + $base['filed_id_width'] + $base['filed_name_width'] + $base['filed_data_width'] * 4,//第五列边框线x轴像素
$base['border'] + $base['filed_id_width'] + $base['filed_name_width'] + $base['filed_data_width'] * 5,//第五列边框线x轴像素
];
// var_dump( $base['column_x_arr']);
$img = imagecreatetruecolor($base['img_width'], $base['img_height']);//创建指定尺寸图片
$bg_color = imagecolorallocate($img, 255, 255, 255);//设定图片背景色
$text_coler = imagecolorallocate($img, 0, 0, 0);//设定文字颜色
$border_coler = imagecolorallocate($img, 0, 0, 0);//设定边框颜色
// $white_coler = imagecolorallocate($img, 255, 255, 255);//设定边框颜色
imagefill($img, 0, 0, $bg_color);//填充图片背景色
//先填充一个黑色的大块背景
imagefilledrectangle($img, $base['border'], $base['border'] + $base['title_height'], $base['img_width'] - $base['border'], $base['img_height'] - $base['border'], $border_coler);//画矩形
//再填充一个小两个像素的 背景色区域,形成一个两个像素的外边框
imagefilledrectangle($img, $base['border'] + 2, $base['border'] + $base['title_height'] + 2, $base['img_width'] - $base['border'] - 2, $base['img_height'] - $base['border'] - 2, $bg_color);//画矩形
//画表格纵线 及 写入表头文字
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;
// 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 );//写入表头文字
}
//画表格横线
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];
$y = $border_top + $base['row_hight'] - 10;
$text = $key + 1;
imagettftext($img, $base['text_size'], 0, $x, $y, $text_coler, $base['font_ulr'], $text);//写入序号
$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数据
}
}
//计算标题写入起始位置
$title_fout_box = imagettfbbox($base['title_font_size'], 0, $base['font_ulr'], $params['title']);//imagettfbbox() 返回一个含有 8 个单元的数组表示了文本外框的四个角:
$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['text_size'], 0, $base['border'], $base['title_height'], $text_coler, $base['font_ulr'], '时间:' . $params['table_time']);
$save_path = $base['file_path'] . $params['file_name'];
if (!is_dir($base['file_path']))//判断存储路径是否存在,不存在则创建
{
mkdir($base['file_path'], 0777, true);//可创建多级目录
}
imagepng($img, $save_path);//输出图片输出png使用imagepng方法输出gif使用imagegif方法
}
}

View File

@ -3,6 +3,7 @@
namespace app\api\controller;
use app\BaseController;
use app\common\model\StudentSchedule;
use app\common\service\TeacherService;
use app\constant\ResponseCode;
use support\Request;
@ -72,4 +73,6 @@ class TeacherController extends BaseController
}
}

View File

@ -90,10 +90,10 @@ class StudentService
public function updateOpenid($request)
{
try {
if(empty($request->teacher)){
if(empty($request->student)){
throw new Exception('请先教师登陆');
}
$teacher = Student::where(['id' => $request->teacher->id])->findOrEmpty();
$teacher = Student::where(['id' => $request->student->id])->findOrEmpty();
if($teacher->isEmpty()){
throw new Exception('未找到教师信息');
}
@ -104,7 +104,7 @@ class StudentService
$message = '获取信息失败';
}
$openid = $user_info['openid'];
$teacher = Student::where(['id'=>$request->teacher->id])->findOrEmpty();
$teacher = Student::where(['id'=>$request->student->id])->findOrEmpty();
$teacher->save([
'openid' => $openid,
]);

View File

@ -137,7 +137,7 @@ class TeacherService
$user_info = WechatSubscriptController::getCodeAccessToken($code);
if (isset($result['code'])) {
$message = '获取信息失败';
throw new Exception('获取信息失败');
}
$openid = $user_info['openid'];
$teacher = Teacher::where(['id'=>$request->teacher->id])->findOrEmpty();

View File

@ -40,7 +40,8 @@
"tinywan/jwt": "^1.10",
"webman/think-orm": "^1.1",
"illuminate/redis": "^8.83",
"illuminate/events": "^8.83"
"illuminate/events": "^8.83",
"topthink/think-template": "^3.0"
},
"suggest": {
"ext-event": "For better performance. "

43
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9dc426c41a2a58306c3239ca918e541f",
"content-hash": "5fe57755b8f3b4ef94f2aecec261675e",
"packages": [
{
"name": "carbonphp/carbon-doctrine-types",
@ -3572,6 +3572,47 @@
},
"time": "2023-04-20T14:27:51+00:00"
},
{
"name": "topthink/think-template",
"version": "v3.0.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-template.git",
"reference": "4352d2cf627abfb8b49f830686c25c02f59c23f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-template/zipball/4352d2cf627abfb8b49f830686c25c02f59c23f2",
"reference": "4352d2cf627abfb8b49f830686c25c02f59c23f2",
"shasum": ""
},
"require": {
"php": ">=8.0.0",
"psr/simple-cache": ">=1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"think\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"description": "the php template engine",
"support": {
"issues": "https://github.com/top-think/think-template/issues",
"source": "https://github.com/top-think/think-template/tree/v3.0.0"
},
"time": "2023-02-25T12:11:14+00:00"
},
{
"name": "topthink/think-validate",
"version": "v2.0.2",

View File

@ -74,9 +74,9 @@
<!-- 表格顶部工具栏 -->
<script type="text/html" id="table-toolbar">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.teacherfreetime.insert">
<i class="layui-icon layui-icon-add-1"></i>新增
</button>
<!-- <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.teacherfreetime.insert">-->
<!-- <i class="layui-icon layui-icon-add-1"></i>新增-->
<!-- </button>-->
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.teacherfreetime.delete">
<i class="layui-icon layui-icon-delete"></i>删除
</button>

View File

@ -104,10 +104,10 @@
<!-- 表格顶部工具栏 -->
<script type="text/html" id="table-toolbar">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add"
permission="app.admin.teacherscheduletime.insert">
<i class="layui-icon layui-icon-add-1"></i>新增
</button>
<!-- <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add"-->
<!-- permission="app.admin.teacherscheduletime.insert">-->
<!-- <i class="layui-icon layui-icon-add-1"></i>新增-->
<!-- </button>-->
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove"
permission="app.admin.teacherscheduletime.delete">
<i class="layui-icon layui-icon-delete"></i>删除