学生登录、学生课表接口
This commit is contained in:
parent
34f4f28512
commit
4fc8a53f06
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace app\api\controller;
|
|
||||||
|
|
||||||
use app\BaseController;
|
|
||||||
|
|
||||||
class ParentController extends BaseController
|
|
||||||
{
|
|
||||||
protected $noNeedLogin = ['login'];
|
|
||||||
|
|
||||||
public function login()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
20
app/api/controller/StudentParentController.php
Normal file
20
app/api/controller/StudentParentController.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\service\StudentParentService;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
|
class StudentParentController extends BaseController
|
||||||
|
{
|
||||||
|
protected $noNeedLogin = ['login'];
|
||||||
|
|
||||||
|
public function login(Request $request)
|
||||||
|
{
|
||||||
|
$service = new StudentParentService();
|
||||||
|
$res = $service->login($request->post());
|
||||||
|
return $this->json($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
app/api/controller/StudentScheduleController.php
Normal file
19
app/api/controller/StudentScheduleController.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\service\StudentScheduleService;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
|
class StudentScheduleController extends BaseController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getScheduleTime(Request $request)
|
||||||
|
{
|
||||||
|
$service = new StudentScheduleService();
|
||||||
|
$result = $service->getScheduleTime($request);
|
||||||
|
return $this->json($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
app/common/service/StudentParentService.php
Normal file
52
app/common/service/StudentParentService.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\service;
|
||||||
|
|
||||||
|
use app\common\model\StudentParent;
|
||||||
|
use app\constant\ResponseCode;
|
||||||
|
use think\Exception;
|
||||||
|
use Tinywan\Jwt\JwtToken;
|
||||||
|
|
||||||
|
class StudentParentService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @desc 登录
|
||||||
|
* @param $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function login($request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$student = StudentParent::where(['account' => $request['account']])->findOrEmpty();
|
||||||
|
if ($student->isEmpty()) {
|
||||||
|
throw new Exception('账号不存在');
|
||||||
|
}
|
||||||
|
if (empty($request['password'])) {
|
||||||
|
throw new Exception('请填写密码');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (md5($request['password'] . $student->salt) != $student->password) {
|
||||||
|
throw new Exception('密码错误,请填写正确的密码');
|
||||||
|
}
|
||||||
|
|
||||||
|
$token_data = [
|
||||||
|
'id' => $student->id,
|
||||||
|
'role' => 'parent'
|
||||||
|
];
|
||||||
|
$token = JwtToken::generateToken($token_data);
|
||||||
|
return [
|
||||||
|
'code' => ResponseCode::SUCCESS,
|
||||||
|
'data' => $token,
|
||||||
|
'msg' => 'success'
|
||||||
|
];
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return [
|
||||||
|
'code' => ResponseCode::FAIL,
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
53
app/common/service/StudentScheduleService.php
Normal file
53
app/common/service/StudentScheduleService.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\service;
|
||||||
|
|
||||||
|
use app\common\model\Student;
|
||||||
|
use app\common\model\StudentSchedule;
|
||||||
|
use app\constant\ResponseCode;
|
||||||
|
use think\Exception;
|
||||||
|
|
||||||
|
class StudentScheduleService
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc 获取课表
|
||||||
|
* @param $request
|
||||||
|
* @return array|void
|
||||||
|
*/
|
||||||
|
public function getScheduleTime($request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (empty($request->student)) {
|
||||||
|
throw new Exception('请登陆后再查看');
|
||||||
|
}
|
||||||
|
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
|
||||||
|
if ($student->isEmpty()) {
|
||||||
|
throw new Exception('未找到用户信息');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $request->get();
|
||||||
|
$schedule_time = StudentSchedule::where(['student_id' => $student->id, 'is_publish' => 1]);
|
||||||
|
if (isset($data['month']) && $data['month']) {
|
||||||
|
$schedule_time->where('month', $data['month']);
|
||||||
|
}
|
||||||
|
if (isset($data['date']) && $data['date']) {
|
||||||
|
$schedule_time->where('date', $data['date']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = $schedule_time->with(['teacher', 'subject'])->select()->toArray();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'code' => ResponseCode::SUCCESS,
|
||||||
|
'data' => $list,
|
||||||
|
'msg' => 'success'
|
||||||
|
];
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return [
|
||||||
|
'code' => ResponseCode::FAIL,
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -22,9 +22,9 @@ class ApiAuthCheckMiddleware implements MiddlewareInterface
|
|||||||
public function process(Request $request, callable $handler): Response
|
public function process(Request $request, callable $handler): Response
|
||||||
{
|
{
|
||||||
|
|
||||||
$request->user = new \stdClass();
|
$request->student = new \stdClass();
|
||||||
$request->teacher = new \stdClass();
|
$request->teacher = new \stdClass();
|
||||||
$request->partents = new \stdClass();
|
$request->partent = new \stdClass();
|
||||||
|
|
||||||
// 通过反射获取控制器哪些方法不需要登录和鉴权
|
// 通过反射获取控制器哪些方法不需要登录和鉴权
|
||||||
$controller = new ReflectionClass($request->controller);
|
$controller = new ReflectionClass($request->controller);
|
||||||
@ -37,7 +37,10 @@ class ApiAuthCheckMiddleware implements MiddlewareInterface
|
|||||||
try {
|
try {
|
||||||
$extend = JwtToken::getExtend();
|
$extend = JwtToken::getExtend();
|
||||||
if ($extend['role'] == 'student') {
|
if ($extend['role'] == 'student') {
|
||||||
|
$request->student = \support\Db::table('student')
|
||||||
|
->where('id', $extend['id'])
|
||||||
|
->select('id','student_name','account','openid')
|
||||||
|
->first();
|
||||||
} elseif ($extend['role'] == 'teacher') {
|
} elseif ($extend['role'] == 'teacher') {
|
||||||
$request->teacher = \support\Db::table('teacher')
|
$request->teacher = \support\Db::table('teacher')
|
||||||
->where('id', $extend['id'])
|
->where('id', $extend['id'])
|
||||||
@ -45,7 +48,10 @@ class ApiAuthCheckMiddleware implements MiddlewareInterface
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
} elseif ($extend['role'] == 'parents') {
|
} elseif ($extend['role'] == 'parents') {
|
||||||
|
$request->partent = \support\Db::table('student_parent')
|
||||||
|
->where('id', $extend['id'])
|
||||||
|
->select('id','parent_name','account','openid')
|
||||||
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
// $request->user = JwtToken::getUser();
|
// $request->user = JwtToken::getUser();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user