课程作业
This commit is contained in:
parent
3a367a5192
commit
300ead8895
@ -52,6 +52,7 @@ class StudentController extends BaseController
|
||||
*/
|
||||
public function userInfo(Request $request)
|
||||
{
|
||||
|
||||
$service = new StudentService();
|
||||
$res = $service->userInfo($request);
|
||||
return $this->json($res);
|
||||
|
@ -20,25 +20,37 @@ class StudentHomeworkService
|
||||
public function addStudentHomework($request)
|
||||
{
|
||||
try {
|
||||
if (empty($request->student)) {
|
||||
if (empty((array)$request->student) && empty((array)$request->parent)) {
|
||||
throw new Exception('请登陆后再查看');
|
||||
}
|
||||
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到用户信息');
|
||||
if (!empty((array)$request->student)) {
|
||||
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到用户信息');
|
||||
}
|
||||
}
|
||||
if (!empty((array)$request->parent)) {
|
||||
$student = Student::where(['parent_id' => $request->parent->id])->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到用户信息');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = $request->post();
|
||||
|
||||
$teacher_schedule_time = TeacherScheduleTime::where(['id' => $data['subject_homework_id']])->findOrEmpty();
|
||||
// $teacher_schedule_time = TeacherScheduleTime::where(['id' => $data['subject_homework_id']])->findOrEmpty();
|
||||
|
||||
print '<pre>';
|
||||
print_r($teacher_schedule_time->isEmpty());
|
||||
die;
|
||||
|
||||
$subject_homework = SubjectHomework::where(['id' => $data['subject_homework_id']])->findOrEmpty();
|
||||
$subject_homework = SubjectHomework::where(['teacher_schedule_time_id' => $data['subject_homework_id'], 'is_publish' => 1])->findOrEmpty();
|
||||
if ($subject_homework->isEmpty()) {
|
||||
throw new Exception('未找到课程作业');
|
||||
throw new Exception('老师还未布置课程作业');
|
||||
}
|
||||
$feedback_file_url = '';
|
||||
if(isset($data['feedback_file_url'])){
|
||||
if(!empty(json_decode($data['feedback_file_url'],true))){
|
||||
$feedback_file_url = $data['feedback_file_url'];
|
||||
}
|
||||
}
|
||||
|
||||
StudentHomework::create([
|
||||
@ -47,12 +59,7 @@ class StudentHomeworkService
|
||||
'teacher_id' => $subject_homework->teacher_id,
|
||||
'teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id,
|
||||
'subject_id' => $subject_homework->subject_id,
|
||||
'homework_file_url' => $subject_homework->homework_file_url,
|
||||
'homework_file_name' => $subject_homework->homework_file_name,
|
||||
'homework_version_file_url' => $subject_homework->homework_version_file_url,
|
||||
'homework_version_file_name' => $subject_homework->homework_version_file_name,
|
||||
'feedback_file_url' => $data['feedback_file_url'],
|
||||
'feedback_file_name' => $data['feedback_file_name'],
|
||||
'feedback_file_url' => $feedback_file_url,
|
||||
]);
|
||||
|
||||
return [
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Student;
|
||||
use app\common\model\StudentParent;
|
||||
use app\common\model\StudentSchedule;
|
||||
use app\constant\ResponseCode;
|
||||
use think\Exception;
|
||||
@ -18,12 +19,21 @@ class StudentScheduleService
|
||||
public function getScheduleTime($request)
|
||||
{
|
||||
try {
|
||||
if (empty($request->student)) {
|
||||
if (empty((array)$request->student) && empty((array)$request->parent)) {
|
||||
throw new Exception('请登陆后再查看');
|
||||
}
|
||||
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到用户信息');
|
||||
if(!empty((array)$request->student)){
|
||||
$student = Student::where(['id' => $request->student->id])->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到用户信息');
|
||||
}
|
||||
}
|
||||
if(!empty((array)$request->parent)){
|
||||
$student = Student::where(['parent_id' => $request->parent->id])->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到用户信息');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = $request->get();
|
||||
|
@ -4,6 +4,7 @@ namespace app\common\service;
|
||||
|
||||
use app\api\controller\WechatSubscriptController;
|
||||
use app\common\model\Student;
|
||||
use app\common\model\StudentParent;
|
||||
use app\constant\ResponseCode;
|
||||
use think\Exception;
|
||||
use Tinywan\Jwt\JwtToken;
|
||||
@ -20,28 +21,47 @@ class StudentService
|
||||
public function login($request)
|
||||
{
|
||||
try {
|
||||
$student = Student::where(['account' => $request['account']])->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('账号不存在');
|
||||
}
|
||||
if (empty($request['password'])) {
|
||||
throw new Exception('请填写密码');
|
||||
}
|
||||
$student = Student::where(['account' => $request['account']])->findOrEmpty();
|
||||
|
||||
if (!$student->isEmpty()) {
|
||||
if (md5($request['password'] . $student->salt) != $student->password) {
|
||||
throw new Exception('密码错误,请填写正确的密码');
|
||||
}
|
||||
|
||||
$token_data = [
|
||||
'id' => $student->id,
|
||||
'role' => 'student'
|
||||
];
|
||||
$token = JwtToken::generateToken($token_data);
|
||||
return [
|
||||
'code' => ResponseCode::SUCCESS,
|
||||
'data' => $token,
|
||||
'msg' => 'success'
|
||||
];
|
||||
}else{
|
||||
$parent = StudentParent::where(['account' => $request['account']])->findOrEmpty();
|
||||
if(!$parent->isEmpty()){
|
||||
if (md5($request['password'] . $parent->salt) != $parent->password) {
|
||||
throw new Exception('密码错误,请填写正确的密码');
|
||||
}
|
||||
|
||||
$token_data = [
|
||||
'id' => $parent->id,
|
||||
'role' => 'parent'
|
||||
];
|
||||
$token = JwtToken::generateToken($token_data);
|
||||
return [
|
||||
'code' => ResponseCode::SUCCESS,
|
||||
'data' => $token,
|
||||
'msg' => 'success'
|
||||
];
|
||||
}
|
||||
|
||||
if (md5($request['password'] . $student->salt) != $student->password) {
|
||||
throw new Exception('密码错误,请填写正确的密码');
|
||||
}
|
||||
|
||||
$token_data = [
|
||||
'id' => $student->id,
|
||||
'role' => 'student'
|
||||
];
|
||||
$token = JwtToken::generateToken($token_data);
|
||||
return [
|
||||
'code' => ResponseCode::SUCCESS,
|
||||
'data' => $token,
|
||||
'msg' => 'success'
|
||||
];
|
||||
throw new Exception('请检查账号信息,未匹配到任何学生或家长');
|
||||
|
||||
} catch (Exception $e) {
|
||||
return [
|
||||
@ -58,17 +78,28 @@ class StudentService
|
||||
public function userInfo($request)
|
||||
{
|
||||
try {
|
||||
if (empty($request->student)) {
|
||||
throw new Exception('请学生登陆后再查看');
|
||||
if (empty((array)$request->student) && empty((array)$request->parent)) {
|
||||
throw new Exception('请登陆后再查看');
|
||||
}
|
||||
$student = Student::where(['id' => $request->student->id])->field('id,student_name,account,openid')->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到学生信息');
|
||||
if(!empty((array)$request->student)){
|
||||
$student = Student::where(['id' => $request->student->id])->field('id,student_name,account,openid,avatar')->findOrEmpty();
|
||||
if ($student->isEmpty()) {
|
||||
throw new Exception('未找到学生信息');
|
||||
}
|
||||
$info = $student->toArray();
|
||||
$info['role'] = 'student';
|
||||
}elseif (!empty((array)$request->parent)){
|
||||
$parent = StudentParent::where(['id' => $request->parent->id])->field('id,parent_name,account,openid,avatar')->findOrEmpty();
|
||||
if ($parent->isEmpty()) {
|
||||
throw new Exception('未找到家长信息');
|
||||
}
|
||||
$info = $parent->toArray();
|
||||
$info['role'] = 'parent';
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => ResponseCode::SUCCESS,
|
||||
'data' => $student,
|
||||
'data' => $info,
|
||||
'msg' => 'success'
|
||||
];
|
||||
|
||||
|
@ -19,7 +19,7 @@ class SubjectHomeworkService
|
||||
public function publish($request)
|
||||
{
|
||||
try {
|
||||
if (empty($request->teacher)) {
|
||||
if (empty((array)$request->teacher)) {
|
||||
throw new Exception('请教师登陆后再设置');
|
||||
}
|
||||
$teacher = Teacher::where(['id' => $request->teacher->id])->findOrEmpty();
|
||||
|
@ -24,7 +24,7 @@ class ApiAuthCheckMiddleware implements MiddlewareInterface
|
||||
|
||||
$request->student = new \stdClass();
|
||||
$request->teacher = new \stdClass();
|
||||
$request->partent = new \stdClass();
|
||||
$request->parent = new \stdClass();
|
||||
|
||||
// 通过反射获取控制器哪些方法不需要登录和鉴权
|
||||
$controller = new ReflectionClass($request->controller);
|
||||
@ -36,21 +36,22 @@ class ApiAuthCheckMiddleware implements MiddlewareInterface
|
||||
$msg = '';
|
||||
try {
|
||||
$extend = JwtToken::getExtend();
|
||||
|
||||
if ($extend['role'] == 'student') {
|
||||
$request->student = \support\Db::table('student')
|
||||
->where('id', $extend['id'])
|
||||
->select('id','student_name','account','openid')
|
||||
->select('id', 'student_name', 'account', 'openid')
|
||||
->first();
|
||||
} elseif ($extend['role'] == 'teacher') {
|
||||
$request->teacher = \support\Db::table('teacher')
|
||||
->where('id', $extend['id'])
|
||||
->select('id','account','teacher_name','openid','time_zone_name','time_zone_abbr','time_zone_offset')
|
||||
->select('id', 'account', 'teacher_name', 'openid', 'time_zone_name', 'time_zone_abbr', 'time_zone_offset')
|
||||
->first();
|
||||
|
||||
} elseif ($extend['role'] == 'parents') {
|
||||
$request->partent = \support\Db::table('student_parent')
|
||||
} elseif ($extend['role'] == 'parent') {
|
||||
$request->parent = \support\Db::table('student_parent')
|
||||
->where('id', $extend['id'])
|
||||
->select('id','parent_name','account','openid')
|
||||
->select('id', 'parent_name', 'account', 'openid')
|
||||
->first();
|
||||
}
|
||||
|
||||
|
@ -143,6 +143,7 @@ class SubjectHomeworkController extends Crud
|
||||
|
||||
$subject_homework = \app\common\model\SubjectHomework::where(['id' => $data['id']])->findOrEmpty();
|
||||
$subject_homework->save([
|
||||
'is_publish' => $data['is_publish'],
|
||||
'homework_web_url' => $data['homework_web_url'],
|
||||
'homework_file_url' => empty($homework_file_url) ? '' : json_encode($homework_file_url, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||
'homework_version_file_url' => empty($homework_version_file_url) ? '' : json_encode($homework_version_file_url, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||
@ -181,4 +182,21 @@ class SubjectHomeworkController extends Crud
|
||||
return view('subject-homework/update', ['subject_homework' => $subject_homework]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc 更改发布状态
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function changePublishStatus(Request $request)
|
||||
{
|
||||
$subject_homework = \app\common\model\SubjectHomework::where('id', $request->post('id'))->findOrEmpty();
|
||||
$subject_homework->save([
|
||||
'is_publish' => $request->post('is_publish')
|
||||
]);
|
||||
return json([
|
||||
'code' => ResponseCode::WEB_API_SUCCESS,
|
||||
'msg' => 'success'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -273,7 +273,7 @@
|
||||
let postData = {};
|
||||
postData[field] = data.elem.checked ? 1 : 0;
|
||||
postData[PRIMARY_KEY] = this.value;
|
||||
$.post(UPDATE_API, postData, function (res) {
|
||||
$.post('/app/admin/subject-homework/changePublishStatus', postData, function (res) {
|
||||
layer.close(load);
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg, function () {
|
||||
|
@ -217,7 +217,7 @@
|
||||
<label class="layui-form-label">是否发布</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" id="is_publish" lay-filter="is_publish" lay-skin="switch"/>
|
||||
<input type="text" style="display:none" name="is_publish" value="0"/>
|
||||
<input type="text" style="display:none" name="is_publish" value="{$subject_homework['is_publish']}"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user