134 lines
4.0 KiB
PHP
134 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace plugin\admin\app\controller;
|
|
|
|
use app\common\model\Student;
|
|
use app\common\model\Subject;
|
|
use app\common\model\Teacher;
|
|
use app\constant\ResponseCode;
|
|
use support\Request;
|
|
use support\Response;
|
|
use plugin\admin\app\model\StudentFeedback;
|
|
use plugin\admin\app\controller\Crud;
|
|
use support\exception\BusinessException;
|
|
use think\Exception;
|
|
|
|
/**
|
|
* 学生反馈
|
|
*/
|
|
class StudentFeedbackController extends Crud
|
|
{
|
|
|
|
/**
|
|
* @var StudentFeedback
|
|
*/
|
|
protected $model = null;
|
|
|
|
/**
|
|
* 构造函数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->model = new StudentFeedback;
|
|
}
|
|
|
|
|
|
public function select(Request $request): Response
|
|
{
|
|
try {
|
|
$feedback = \app\common\model\StudentFeedback::order('id asc');
|
|
$data = $request->all();
|
|
|
|
if(isset($data['student_name']) && !empty($data['student_name'])){
|
|
$feedback->where('student_name','like','%'.$data['student_name'].'%');
|
|
}
|
|
if(isset($data['feedback']) && !empty($data['feedback'])){
|
|
$feedback->where('feedback','like','%'.$data['feedback'].'%');
|
|
}
|
|
if(isset($data['student_id']) && !empty($data['student_id'])){
|
|
$feedback->where('student_id',$data['student_id']);
|
|
}
|
|
if(isset($data['teacher_id']) && !empty($data['teacher_id'])){
|
|
$feedback->where('teacher_id',$data['teacher_id']);
|
|
}
|
|
if(isset($data['subject_id']) && !empty($data['subject_id'])){
|
|
$feedback->where('subject_id',$data['subject_id']);
|
|
}
|
|
if(isset($data['date']) && !empty($data['date'])){
|
|
if($data['date'][0] && $data['date'][1]){
|
|
$feedback->whereBetweenTime('created_at', $data['date'][0] . ' 00:00:00', $data['date'][1] . ' 23:59:59');
|
|
}
|
|
}
|
|
|
|
|
|
$limit = (int)$request->get('limit', 10);
|
|
$limit = $limit <= 0 ? 10 : $limit;
|
|
$page = (int)$request->get('page');
|
|
$page = $page > 0 ? $page : 1;
|
|
|
|
$total = $feedback->count();
|
|
$list = $feedback->with(['student', 'teacher', 'subject'])
|
|
->page($page, $limit)->select();
|
|
|
|
return json([
|
|
'code' => ResponseCode::WEB_API_SUCCESS,
|
|
'data' => $list,
|
|
'count' => $total,
|
|
'msg' => 'success'
|
|
]);
|
|
}catch (Exception $e){
|
|
|
|
return json([
|
|
'code' => ResponseCode::WEB_API_FAIL,
|
|
'data' => [],
|
|
'msg' => $e->getMessage()
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 浏览
|
|
* @return Response
|
|
*/
|
|
public function index(): Response
|
|
{
|
|
//获取所有老师
|
|
$teacher = Teacher::order('id asc')->field('id,teacher_name,account')->select()->toArray();
|
|
//所有课程
|
|
$subject = Subject::order('sort desc,id asc')->field('id,subject_name,english_name')->select()->toArray();
|
|
//学生
|
|
$student = Student::order('id asc')->field('id,student_name,account')->select()->toArray();
|
|
return view('student-feedback/index', compact('teacher', 'subject', 'student'));
|
|
}
|
|
|
|
/**
|
|
* 插入
|
|
* @param Request $request
|
|
* @return Response
|
|
* @throws BusinessException
|
|
*/
|
|
public function insert(Request $request): Response
|
|
{
|
|
if ($request->method() === 'POST') {
|
|
return parent::insert($request);
|
|
}
|
|
return view('student-feedback/insert');
|
|
}
|
|
|
|
/**
|
|
* 更新
|
|
* @param Request $request
|
|
* @return Response
|
|
* @throws BusinessException
|
|
*/
|
|
public function update(Request $request): Response
|
|
{
|
|
|
|
$feedback = \app\common\model\StudentFeedback::where(['id'=>$request->get('id')])->with(['teacher', 'student', 'subject'])->findOrEmpty()->toArray();
|
|
|
|
return view('student-feedback/update', ['feedback' => $feedback]);
|
|
}
|
|
|
|
}
|