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