From 530a37421802781a82c7fab5276fe9e86a1ad264 Mon Sep 17 00:00:00 2001 From: Dai Date: Tue, 23 Jul 2024 21:12:35 +0800 Subject: [PATCH 1/8] =?UTF-8?q?fix=20=E8=B7=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/middleware/AccessControlMiddleware.php | 28 ++++++++++++++++++++++ config/middleware.php | 1 + 2 files changed, 29 insertions(+) create mode 100644 app/middleware/AccessControlMiddleware.php diff --git a/app/middleware/AccessControlMiddleware.php b/app/middleware/AccessControlMiddleware.php new file mode 100644 index 0000000..6f132a0 --- /dev/null +++ b/app/middleware/AccessControlMiddleware.php @@ -0,0 +1,28 @@ +method() == 'OPTIONS' ? response('') : $handler($request); + + // 给响应添加跨域相关的http头 + $response->withHeaders([ + 'Access-Control-Allow-Credentials' => 'true', + 'Access-Control-Allow-Origin' => $request->header('origin', '*'), + 'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'), + 'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'), + ]); + + return $response; + } + +} \ No newline at end of file diff --git a/config/middleware.php b/config/middleware.php index 4c4db21..6b31d8b 100644 --- a/config/middleware.php +++ b/config/middleware.php @@ -16,5 +16,6 @@ return [ // mch应用中间件 'api' => [ app\middleware\ApiAuthCheckMiddleware::class, + \app\middleware\AccessControlMiddleware::class ], ]; \ No newline at end of file From 21a53abd935ddd95858abe6b457b60672d42c7b7 Mon Sep 17 00:00:00 2001 From: Dai Date: Tue, 23 Jul 2024 21:38:28 +0800 Subject: [PATCH 2/8] h5 --- app/view/h5/index.html | 39 +++++++++++++++++++++++++++++++++++++++ config/route.php | 3 +++ 2 files changed, 42 insertions(+) create mode 100644 app/view/h5/index.html diff --git a/app/view/h5/index.html b/app/view/h5/index.html new file mode 100644 index 0000000..5bf0440 --- /dev/null +++ b/app/view/h5/index.html @@ -0,0 +1,39 @@ + + + + + 恭喜,站点创建成功! + + + +
+

恭喜, 站点创建成功 H5!

+

这是默认index.html,本页面由系统自动生成

+
    +
  • 本页面在FTP根目录下的index.html
  • +
  • 您可以修改、删除或覆盖本页面
  • +
  • FTP相关信息,请到“面板系统后台 > FTP” 查看
  • +
+
+ + \ No newline at end of file diff --git a/config/route.php b/config/route.php index 0ea8822..46f4e83 100644 --- a/config/route.php +++ b/config/route.php @@ -23,6 +23,9 @@ Route::any('/h5/student', function (){ Route::any('/h5/teacher', function (){ return view('teacher/index'); }); +Route::any('/h5', function (){ + return view('h5/index'); +}); From b0ad73fe2ba5d9d7dd6ffb76e850d4e998c1d211 Mon Sep 17 00:00:00 2001 From: Dai Date: Tue, 23 Jul 2024 21:59:15 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0openid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/StudentController.php | 22 ++++++- app/api/controller/TeacherController.php | 24 +++++++- .../controller/WechatSubscriptController.php | 57 +++++++++++++++++-- app/common/service/StudentService.php | 42 ++++++++++++++ app/common/service/TeacherService.php | 41 +++++++++++++ 5 files changed, 179 insertions(+), 7 deletions(-) diff --git a/app/api/controller/StudentController.php b/app/api/controller/StudentController.php index 371d4f3..28f8c82 100644 --- a/app/api/controller/StudentController.php +++ b/app/api/controller/StudentController.php @@ -8,7 +8,7 @@ use support\Request; class StudentController extends BaseController { - protected $noNeedLogin = ['login']; + protected $noNeedLogin = ['login', 'getCode']; /** * @desc 登录 @@ -22,6 +22,20 @@ class StudentController extends BaseController return $this->json($res); } + /** + * @desc 获取code + * @param Request $request + * @return \support\Response + */ + public function getCode(Request $request) + { + $appid = getenv('WECHAT_APPID'); + $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5/teacher#/pages/index/index");//重定向地址 + + $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; + return redirect($url); + } + /** * @desc 学生信息 * @param Request $request @@ -34,4 +48,10 @@ class StudentController extends BaseController return $this->json($res); } + public function updateOpenid(Request $request) + { + $service = new StudentService(); + + } + } \ No newline at end of file diff --git a/app/api/controller/TeacherController.php b/app/api/controller/TeacherController.php index 87e3c6c..100be8b 100644 --- a/app/api/controller/TeacherController.php +++ b/app/api/controller/TeacherController.php @@ -9,7 +9,7 @@ use support\Request; class TeacherController extends BaseController { - protected $noNeedLogin = ['login']; + protected $noNeedLogin = ['login', 'getCode']; public function login(Request $request) { @@ -19,6 +19,20 @@ class TeacherController extends BaseController } + /** + * @desc 获取code + * @param Request $request + * @return \support\Response + */ + public function getCode(Request $request) + { + $appid = getenv('WECHAT_APPID'); + $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5/teacher#/pages/login/login");//重定向地址 + + $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; + return redirect($url); + } + /** * @desc 设置时区 * @param Request $request @@ -43,5 +57,13 @@ class TeacherController extends BaseController return $this->json($res); } + public function updateOpenid(Request $request) + { + $service = new TeacherService(); + $res = $service->updateOpenid($request); + return $this->json($res); + + } + } \ No newline at end of file diff --git a/app/api/controller/WechatSubscriptController.php b/app/api/controller/WechatSubscriptController.php index d8b445f..a747634 100644 --- a/app/api/controller/WechatSubscriptController.php +++ b/app/api/controller/WechatSubscriptController.php @@ -4,22 +4,69 @@ namespace app\api\controller; use app\BaseController; use app\constant\ResponseCode; +use GuzzleHttp\Client; use support\Request; +use think\Exception; class WechatSubscriptController extends BaseController { protected $noNeedLogin = ['*']; + const GENERAL_ACCESS_TOKEN = 'general_access_token'; + const CODE_ACCESS_TOKEN = 'code_access_token'; + const BASE_URI = 'https://api.weixin.qq.com'; public function getCode(Request $request) { $appid = getenv('WECHAT_APPID'); - $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/index.html#/pages/login/login ");//重定向地址 + if($request->all('client') == 'student'){ + $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5/student#/pages/login/login");//重定向地址 + }else{ + $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5/teacher#/pages/login/login");//重定向地址 + } + $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; - return $this->json([ - 'code' => ResponseCode::SUCCESS, - 'data' => $url - ]); + return redirect($url); + } + + + + /** + * @desc 获取网页授权code的access_token + * @param $code + * @return array|void + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public static function getCodeAccessToken($code) + { + try { + $client = new Client(['base_uri'=>self::BASE_URI]); + $response = $client->request('get', 'sns/oauth2/access_token', [ + 'query' => [ + 'appid' => getenv('APPID'), + 'secret' => getenv('APPSECRET'), + 'code'=>$code, + 'grant_type'=>'authorization_code' + ] + ]); + + $response_contents = $response->getBody()->getContents(); + raw_log('wechat/code_access_token', ['result' => $response_contents]); + if ($response->getStatusCode() == 200) { + $result = json_decode($response_contents, true); + raw_log('wechat/code_access_token', ['result' => $result]); + if (isset($result['errcode'])) { + throw new Exception($result['errmsg']); + } + return $result; + } + + }catch (Exception $e){ + return [ + 'code'=>ResponseCode::FAIL, + 'msg'=>$e->getMessage() + ]; + } } } \ No newline at end of file diff --git a/app/common/service/StudentService.php b/app/common/service/StudentService.php index 74534dc..51520d0 100644 --- a/app/common/service/StudentService.php +++ b/app/common/service/StudentService.php @@ -2,6 +2,7 @@ namespace app\common\service; +use app\api\controller\WechatSubscriptController; use app\common\model\Student; use app\constant\ResponseCode; use think\Exception; @@ -79,4 +80,45 @@ class StudentService } } + + /** + * @desc 更新code + * @param $request + * @return array|void + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function updateOpenid($request) + { + try { + if(empty($request->teacher)){ + throw new Exception('请先教师登陆'); + } + $teacher = Student::where(['id' => $request->teacher->id])->findOrEmpty(); + if($teacher->isEmpty()){ + throw new Exception('未找到教师信息'); + } + + $data = $request->post('code'); + $user_info = WechatSubscriptController::getCodeAccessToken($data['code']); + if (isset($result['code'])) { + $message = '获取信息失败'; + } + $openid = $user_info['openid']; + $teacher = Student::where(['id'=>$request->teacher->id])->findOrEmpty(); + $teacher->save([ + 'openid' => $openid, + ]); + + return [ + 'code' => ResponseCode::SUCCESS, + 'msg' => 'success' + ]; + }catch (Exception $e){ + return [ + 'code' => ResponseCode::FAIL, + 'msg' => $e->getMessage() + ]; + } + } + } \ No newline at end of file diff --git a/app/common/service/TeacherService.php b/app/common/service/TeacherService.php index 56fc93c..baf3e3c 100644 --- a/app/common/service/TeacherService.php +++ b/app/common/service/TeacherService.php @@ -2,6 +2,7 @@ namespace app\common\service; +use app\api\controller\WechatSubscriptController; use app\common\model\Teacher; use app\common\model\TimeZone; use app\constant\ResponseCode; @@ -115,4 +116,44 @@ class TeacherService } } + /** + * @desc 更新code + * @param $request + * @return array|void + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function updateOpenid($request) + { + try { + if(empty($request->teacher)){ + throw new Exception('请先教师登陆'); + } + $teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty(); + if($teacher->isEmpty()){ + throw new Exception('未找到教师信息'); + } + + $data = $request->post('code'); + $user_info = WechatSubscriptController::getCodeAccessToken($data['code']); + if (isset($result['code'])) { + $message = '获取信息失败'; + } + $openid = $user_info['openid']; + $teacher = Teacher::where(['id'=>$request->teacher->id])->findOrEmpty(); + $teacher->save([ + 'openid' => $openid, + ]); + + return [ + 'code' => ResponseCode::SUCCESS, + 'msg' => 'success' + ]; + }catch (Exception $e){ + return [ + 'code' => ResponseCode::FAIL, + 'msg' => $e->getMessage() + ]; + } + } + } \ No newline at end of file From 7de8f65d53cb771bb1e18dadddd2a71888813566 Mon Sep 17 00:00:00 2001 From: Dai Date: Tue, 23 Jul 2024 22:01:31 +0800 Subject: [PATCH 4/8] h5 --- app/api/controller/StudentController.php | 2 +- app/api/controller/TeacherController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/api/controller/StudentController.php b/app/api/controller/StudentController.php index 28f8c82..ac6e6fc 100644 --- a/app/api/controller/StudentController.php +++ b/app/api/controller/StudentController.php @@ -30,7 +30,7 @@ class StudentController extends BaseController public function getCode(Request $request) { $appid = getenv('WECHAT_APPID'); - $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5/teacher#/pages/index/index");//重定向地址 + $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5#/pages/index/index");//重定向地址 $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; return redirect($url); diff --git a/app/api/controller/TeacherController.php b/app/api/controller/TeacherController.php index 100be8b..4c67c59 100644 --- a/app/api/controller/TeacherController.php +++ b/app/api/controller/TeacherController.php @@ -27,7 +27,7 @@ class TeacherController extends BaseController public function getCode(Request $request) { $appid = getenv('WECHAT_APPID'); - $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5/teacher#/pages/login/login");//重定向地址 + $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5#/pages/login/login");//重定向地址 $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; return redirect($url); From 60f22db5760b727481cdb23818b00ade515644c8 Mon Sep 17 00:00:00 2001 From: Dai Date: Tue, 23 Jul 2024 22:16:04 +0800 Subject: [PATCH 5/8] =?UTF-8?q?h5=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/StudentController.php | 6 +++++- app/api/controller/TeacherController.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/api/controller/StudentController.php b/app/api/controller/StudentController.php index ac6e6fc..e3e0a1a 100644 --- a/app/api/controller/StudentController.php +++ b/app/api/controller/StudentController.php @@ -29,10 +29,14 @@ class StudentController extends BaseController */ public function getCode(Request $request) { - $appid = getenv('WECHAT_APPID'); + $appid = getenv('APP_ID'); $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5#/pages/index/index");//重定向地址 +// $redirect_uri = getenv('SERVER_DOMAIN') . "/h5#/pages/index/index";//重定向地址 + $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; +// $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; + return redirect($url); } diff --git a/app/api/controller/TeacherController.php b/app/api/controller/TeacherController.php index 4c67c59..c369373 100644 --- a/app/api/controller/TeacherController.php +++ b/app/api/controller/TeacherController.php @@ -26,7 +26,7 @@ class TeacherController extends BaseController */ public function getCode(Request $request) { - $appid = getenv('WECHAT_APPID'); + $appid = getenv('APP_ID'); $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5#/pages/login/login");//重定向地址 $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; From f92658ffed06187f2e42fd91259055f1a2576d53 Mon Sep 17 00:00:00 2001 From: Dai Date: Tue, 23 Jul 2024 22:18:17 +0800 Subject: [PATCH 6/8] fix bug --- app/api/controller/StudentController.php | 7 ++++++- app/api/controller/TeacherController.php | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/api/controller/StudentController.php b/app/api/controller/StudentController.php index e3e0a1a..652bb0b 100644 --- a/app/api/controller/StudentController.php +++ b/app/api/controller/StudentController.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\BaseController; use app\common\service\StudentService; +use app\constant\ResponseCode; use support\Request; class StudentController extends BaseController @@ -37,7 +38,11 @@ class StudentController extends BaseController $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; // $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; - return redirect($url); + return $this->json([ + 'code' => ResponseCode::SUCCESS, + 'data' => $url + ]); +// return redirect($url); } /** diff --git a/app/api/controller/TeacherController.php b/app/api/controller/TeacherController.php index c369373..8d14418 100644 --- a/app/api/controller/TeacherController.php +++ b/app/api/controller/TeacherController.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\BaseController; use app\common\service\TeacherService; +use app\constant\ResponseCode; use support\Request; class TeacherController extends BaseController @@ -30,7 +31,11 @@ class TeacherController extends BaseController $redirect_uri = urlencode(getenv('SERVER_DOMAIN') . "/h5#/pages/login/login");//重定向地址 $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect"; - return redirect($url); + return $this->json([ + 'code' => ResponseCode::SUCCESS, + 'data' => $url + ]); +// return redirect($url); } /** From f6288dc9c6dcc2935f60dee5fefb0d3a4484e5e1 Mon Sep 17 00:00:00 2001 From: Dai Date: Tue, 23 Jul 2024 22:30:24 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E8=8E=B7=E5=8F=96openid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/WechatSubscriptController.php | 4 ++-- app/common/service/StudentService.php | 4 ++-- app/common/service/TeacherService.php | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/api/controller/WechatSubscriptController.php b/app/api/controller/WechatSubscriptController.php index a747634..5e91200 100644 --- a/app/api/controller/WechatSubscriptController.php +++ b/app/api/controller/WechatSubscriptController.php @@ -43,8 +43,8 @@ class WechatSubscriptController extends BaseController $client = new Client(['base_uri'=>self::BASE_URI]); $response = $client->request('get', 'sns/oauth2/access_token', [ 'query' => [ - 'appid' => getenv('APPID'), - 'secret' => getenv('APPSECRET'), + 'appid' => getenv('APP_ID'), + 'secret' => getenv('APP_SECRET'), 'code'=>$code, 'grant_type'=>'authorization_code' ] diff --git a/app/common/service/StudentService.php b/app/common/service/StudentService.php index 51520d0..b6a31dd 100644 --- a/app/common/service/StudentService.php +++ b/app/common/service/StudentService.php @@ -98,8 +98,8 @@ class StudentService throw new Exception('未找到教师信息'); } - $data = $request->post('code'); - $user_info = WechatSubscriptController::getCodeAccessToken($data['code']); + $code = $request->post('code'); + $user_info = WechatSubscriptController::getCodeAccessToken($code); if (isset($result['code'])) { $message = '获取信息失败'; } diff --git a/app/common/service/TeacherService.php b/app/common/service/TeacherService.php index baf3e3c..180d449 100644 --- a/app/common/service/TeacherService.php +++ b/app/common/service/TeacherService.php @@ -133,8 +133,9 @@ class TeacherService throw new Exception('未找到教师信息'); } - $data = $request->post('code'); - $user_info = WechatSubscriptController::getCodeAccessToken($data['code']); + $code = $request->post('code'); + $user_info = WechatSubscriptController::getCodeAccessToken($code); + if (isset($result['code'])) { $message = '获取信息失败'; } From cce32a420372625d5d52ac381bc014e8c30617bf Mon Sep 17 00:00:00 2001 From: Dai Date: Tue, 23 Jul 2024 23:29:56 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95?= =?UTF-8?q?=EF=BC=8C=E5=90=8E=E5=8F=B0=E5=AE=B6=E5=BA=AD=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/SubjectHomeworkService.php | 5 + app/common/service/TeacherFreeTimeService.php | 105 ++-- app/common/service/UploadService.php | 2 +- .../controller/SubjectHomeworkController.php | 99 ++++ .../admin/app/controller/UploadController.php | 21 + plugin/admin/app/model/SubjectHomework.php | 50 ++ .../app/view/subject-homework/index.html | 466 ++++++++++++++++++ .../app/view/subject-homework/insert.html | 330 +++++++++++++ .../app/view/subject-homework/update.html | 366 ++++++++++++++ .../app/view/teacher-free-time/index.html | 5 +- .../upload/files/20240723/669fc73dc9a1.txt | 0 .../upload/files/20240723/669fc751cf9b.txt | 1 + .../upload/files/20240723/669fc9378a28.txt | 1 + .../upload/files/20240723/669fc941abab.txt | 1 + 14 files changed, 1417 insertions(+), 35 deletions(-) create mode 100644 plugin/admin/app/controller/SubjectHomeworkController.php create mode 100644 plugin/admin/app/model/SubjectHomework.php create mode 100644 plugin/admin/app/view/subject-homework/index.html create mode 100644 plugin/admin/app/view/subject-homework/insert.html create mode 100644 plugin/admin/app/view/subject-homework/update.html create mode 100644 plugin/admin/public/upload/files/20240723/669fc73dc9a1.txt create mode 100644 plugin/admin/public/upload/files/20240723/669fc751cf9b.txt create mode 100644 plugin/admin/public/upload/files/20240723/669fc9378a28.txt create mode 100644 plugin/admin/public/upload/files/20240723/669fc941abab.txt diff --git a/app/common/service/SubjectHomeworkService.php b/app/common/service/SubjectHomeworkService.php index b550b68..4877bab 100644 --- a/app/common/service/SubjectHomeworkService.php +++ b/app/common/service/SubjectHomeworkService.php @@ -47,6 +47,11 @@ class SubjectHomeworkService $res = SubjectHomework::create([ 'teacher_id' => $teacher->id, 'teacher_schedule_time_id' => $data['teacher_schedule_time_id'], + 'date' => $teacher_schedule_time->date, + 'time' => $teacher_schedule_time->time, + 'start_time' => $teacher_schedule_time->start_time, + 'end_time' => $teacher_schedule_time->end_time, + 'month' => $teacher_schedule_time->month, 'subject_id' => $teacher_schedule_time->subject_id, 'homework_file_url' => $data['homework_file_url'], 'homework_file_name' => $data['homework_file_name'], diff --git a/app/common/service/TeacherFreeTimeService.php b/app/common/service/TeacherFreeTimeService.php index d17fe58..6e9ac46 100644 --- a/app/common/service/TeacherFreeTimeService.php +++ b/app/common/service/TeacherFreeTimeService.php @@ -31,50 +31,89 @@ class TeacherFreeTimeService } $data = $request->post(); + if(empty($data['free_time'])){ + throw new Exception('请选择时间后提交'); + } + $free_time = json_decode($data['free_time'], true); - - if (empty($free_time)) { - throw new Exception('请选择时间段之后再提交'); - } $total_count = 0; $exit_count = 0; $err_free_count = 0; - foreach ($free_time as $free_date => $times) { - if ($times) { - foreach ($times as $time) { - $time_period = explode(' - ', $time); - $firstDate = new DateTime($free_date . ' ' . trim($time_period[0])); - $secondDate = new DateTime($free_date . ' ' . trim($time_period[1])); - $diff = $secondDate->diff($firstDate); - $h = $diff->h; - $m = round($diff->i / 60, 2); - $hour = round($h + $m, 2); - $time = $time_period[0] . ' - ' . $time_period[1]; - $free_data = [ - 'teacher_id' => $request->teacher->id, - 'date' => $free_date, - 'time' => $time, - 'hour' => $hour, - 'start_time' => date('Y-m-d H:i:s', $firstDate->getTimestamp()), - 'end_time' => date('Y-m-d H:i:s', $secondDate->getTimestamp()), - 'month' => date('Y-m', strtotime($free_date)), - ]; + foreach ($free_time as $item) { + $free_date = $item['day']; + foreach ($item['times'] as $val){ + $time = $val['zh']; + $en_time = $val['en']; + $time_period = explode('-', $time); + $en_time_period = explode('-', $en_time); + $firstDate = new DateTime($free_date . ' ' . trim($time_period[0])); + $secondDate = new DateTime($free_date . ' ' . trim($time_period[1])); + $diff = $secondDate->diff($firstDate); + $h = $diff->h; + $m = round($diff->i / 60, 2); + $hour = round($h + $m, 2); + $time = $time_period[0] . ' - ' . $time_period[1]; + $free_data = [ + 'teacher_id' => $request->teacher->id, + 'date' => $free_date, + 'time' => $time, + 'en_time' => implode(' - ', $en_time_period), + 'hour' => $hour, + 'start_time' => date('Y-m-d H:i:s', $firstDate->getTimestamp()), + 'end_time' => date('Y-m-d H:i:s', $secondDate->getTimestamp()), + 'month' => date('Y-m', strtotime($free_date)), + ]; - //判断是否已经存在 - $exit = TeacherFreeTime::where($free_data)->findOrEmpty(); - if(!$exit->isEmpty()){ - continue; - } - $res = TeacherFreeTime::create($free_data); - if(!$res){ - throw new Exception('保存失败'); - } + //判断是否已经存在 + $exit = TeacherFreeTime::where($free_data)->findOrEmpty(); + if(!$exit->isEmpty()){ + continue; } + $res = TeacherFreeTime::create($free_data); + if(!$res){ + throw new Exception('保存失败'); + } + } } + +// foreach ($free_time as $free_date => $times) { +// if ($times) { +// foreach ($times as $time) { +// $time_period = explode(' - ', $time); +// $firstDate = new DateTime($free_date . ' ' . trim($time_period[0])); +// $secondDate = new DateTime($free_date . ' ' . trim($time_period[1])); +// $diff = $secondDate->diff($firstDate); +// $h = $diff->h; +// $m = round($diff->i / 60, 2); +// $hour = round($h + $m, 2); +// $time = $time_period[0] . ' - ' . $time_period[1]; +// $free_data = [ +// 'teacher_id' => $request->teacher->id, +// 'date' => $free_date, +// 'time' => $time, +// 'hour' => $hour, +// 'start_time' => date('Y-m-d H:i:s', $firstDate->getTimestamp()), +// 'end_time' => date('Y-m-d H:i:s', $secondDate->getTimestamp()), +// 'month' => date('Y-m', strtotime($free_date)), +// ]; +// +// //判断是否已经存在 +// $exit = TeacherFreeTime::where($free_data)->findOrEmpty(); +// if(!$exit->isEmpty()){ +// continue; +// } +// $res = TeacherFreeTime::create($free_data); +// if(!$res){ +// throw new Exception('保存失败'); +// } +// } +// } +// } + return [ 'code' => ResponseCode::SUCCESS, 'msg' => '保存成功' diff --git a/app/common/service/UploadService.php b/app/common/service/UploadService.php index 2cf7d57..71a29d7 100644 --- a/app/common/service/UploadService.php +++ b/app/common/service/UploadService.php @@ -67,7 +67,7 @@ class UploadService if ($file && $file->isValid()) { $ext = $file->getUploadExtension(); - if (in_array($ext, ['pdf', 'doc', 'docx', 'xlsx', 'xls', 'csv', 'pptx', 'ppt', 'zip', 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'JPG', 'JPEG', 'PBG'])) { + if (in_array($ext, ['pdf', 'doc', 'docx', 'xlsx', 'xls', 'csv', 'pptx', 'ppt', 'zip', 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'JPG', 'JPEG', 'PBG', 'txt'])) { $type = 'files'; } else { $type = 'other'; diff --git a/plugin/admin/app/controller/SubjectHomeworkController.php b/plugin/admin/app/controller/SubjectHomeworkController.php new file mode 100644 index 0000000..1d8dced --- /dev/null +++ b/plugin/admin/app/controller/SubjectHomeworkController.php @@ -0,0 +1,99 @@ +model = new SubjectHomework; + } + + /** + * 浏览 + * @return Response + */ + public function index(): Response + { + return view('subject-homework/index'); + } + + public function select(Request $request): Response + { + try { + $homework = \app\common\model\SubjectHomework::order('id desc'); + if(1){ + + } + $limit = (int)$request->get('limit', 10); + $limit = $limit <= 0 ? 10 : $limit; + $page = (int)$request->get('page'); + $page = $page > 0 ? $page : 1; + + $total = $homework->count(); + $list = $homework->page($page, $limit)->with(['teacher', 'subject'])->select(); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'data' => $list, + 'count' => $total + ]); + }catch (Exception $e){ + + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + } + + /** + * 插入 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function insert(Request $request): Response + { + if ($request->method() === 'POST') { + return parent::insert($request); + } + return view('subject-homework/insert'); + } + + /** + * 更新 + * @param Request $request + * @return Response + * @throws BusinessException + */ + public function update(Request $request): Response + { + if ($request->method() === 'POST') { + return parent::update($request); + } + return view('subject-homework/update'); + } + +} diff --git a/plugin/admin/app/controller/UploadController.php b/plugin/admin/app/controller/UploadController.php index e7105e1..166fe99 100644 --- a/plugin/admin/app/controller/UploadController.php +++ b/plugin/admin/app/controller/UploadController.php @@ -2,6 +2,7 @@ namespace plugin\admin\app\controller; +use app\common\service\UploadService; use app\constant\ResponseCode; use app\utils\QiniuUtils; use Exception; @@ -132,6 +133,26 @@ class UploadController extends Crud ]); } + + + /** + * @desc 上传图片 + * @param Request $request + * @return \support\Response + */ + public function uploadFile(Request $request) + { + $service = new UploadService(); + $res = $service->uploadFile($request->file('file')); + if($res['code'] == ResponseCode::SUCCESS){ + return $this->json(0, '上传成功', [ + 'url' => $res['data']['url'], + 'name' => $res['data']['origin_name'] + ]); + } + return $this->json($res); + } + /** * 上传文件 * @param Request $request diff --git a/plugin/admin/app/model/SubjectHomework.php b/plugin/admin/app/model/SubjectHomework.php new file mode 100644 index 0000000..f84b63c --- /dev/null +++ b/plugin/admin/app/model/SubjectHomework.php @@ -0,0 +1,50 @@ + + + + + 浏览页面 + + + + + + +
+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+ + +
+
+
+ +
+ +
+
+ + +
+
+
+ +
+ +
+
+
+
+ +
+ + + +
+
+ 展开 + 收起 +
+
+
+
+ + +
+
+
+
+
+ + + + + + + + + + + + + + + diff --git a/plugin/admin/app/view/subject-homework/insert.html b/plugin/admin/app/view/subject-homework/insert.html new file mode 100644 index 0000000..66fa198 --- /dev/null +++ b/plugin/admin/app/view/subject-homework/insert.html @@ -0,0 +1,330 @@ + + + + + 新增页面 + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + + + +
+
+ +
+ +
+ +
+
+ +
+ +
+ + + + +
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+ + +
+
+ +
+ + + + + + + + + + diff --git a/plugin/admin/app/view/subject-homework/update.html b/plugin/admin/app/view/subject-homework/update.html new file mode 100644 index 0000000..58239e4 --- /dev/null +++ b/plugin/admin/app/view/subject-homework/update.html @@ -0,0 +1,366 @@ + + + + + 更新页面 + + + + + + + +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + + + + + +
+
+ + + + + + + + +
+ +
+ + + + + + +
+
+ + + + + + + + +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+ + +
+
+ +
+ + + + + + + + + + + diff --git a/plugin/admin/app/view/teacher-free-time/index.html b/plugin/admin/app/view/teacher-free-time/index.html index 31537ea..f4dad50 100644 --- a/plugin/admin/app/view/teacher-free-time/index.html +++ b/plugin/admin/app/view/teacher-free-time/index.html @@ -153,8 +153,11 @@ title: "日期",align: "center", field: "date", },{ - title: "时间",align: "center", + title: "中国时间",align: "center", field: "time", + },{ + title: "当地时间",align: "center", + field: "en_time", },{ title: "课时/h",align: "center", field: "hour", diff --git a/plugin/admin/public/upload/files/20240723/669fc73dc9a1.txt b/plugin/admin/public/upload/files/20240723/669fc73dc9a1.txt new file mode 100644 index 0000000..e69de29 diff --git a/plugin/admin/public/upload/files/20240723/669fc751cf9b.txt b/plugin/admin/public/upload/files/20240723/669fc751cf9b.txt new file mode 100644 index 0000000..f6456b4 --- /dev/null +++ b/plugin/admin/public/upload/files/20240723/669fc751cf9b.txt @@ -0,0 +1 @@ +123123132 \ No newline at end of file diff --git a/plugin/admin/public/upload/files/20240723/669fc9378a28.txt b/plugin/admin/public/upload/files/20240723/669fc9378a28.txt new file mode 100644 index 0000000..f6456b4 --- /dev/null +++ b/plugin/admin/public/upload/files/20240723/669fc9378a28.txt @@ -0,0 +1 @@ +123123132 \ No newline at end of file diff --git a/plugin/admin/public/upload/files/20240723/669fc941abab.txt b/plugin/admin/public/upload/files/20240723/669fc941abab.txt new file mode 100644 index 0000000..f6456b4 --- /dev/null +++ b/plugin/admin/public/upload/files/20240723/669fc941abab.txt @@ -0,0 +1 @@ +123123132 \ No newline at end of file