test

与时俱进 测试技术 2020-06-06
<?php
/**
*作者:王统
* 开发时间:2020-6-1
* 功能:预约模块类文件
* BUG
*/
namespace app\edus\controller\kiryapi;
use app\edus\model\AssistantModel;
use app\edus\model\ClassificationModel;
use app\edus\model\CourseModel;
use app\edus\model\EducationsModel;
use app\edus\model\GiveAnAlarmModel;
use app\edus\model\GradeModel;
use app\edus\model\NoticeModel;
use app\edus\model\StudentsModel;
use app\edus\model\TeacheresModel;
use app\edus\model\TeacherModel;
use app\edus\model\Teachers;
use app\edus\model\UserModel;
use app\edus\validate\CheckGiveAnAlarm;
use app\edus\validate\CheckNotice;
use think\exception\ValidateException;
use app\edus\validate\CheckAppointment;
use think\Request;
use Flc\Dysms\Client;
use Flc\Dysms\Request\SendSms;

class Appointment extends Common {
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
$this->requestMethod($this->request);
}



/**
* 作者: 王统
* 开发时间: 2020/6/1
* 功能:中断消息
*/
protected function json_exit($code, $msg = null)
{
$arr["code"] = $code;
if ($msg == null) {
$arr["msg"] = config('code.' . $code);
} else {
$arr["msg"] = $msg;
}
json($arr)->send();
exit;
}
/**
* 作者: 王统
* 开发时间: 2020/6/1
* 功能:返回API JSON数据
*/
function json_result($code, $msg = '', $data = [])
{
if ($msg == '') {
$msg = config('code.' . $code);
}
$ret = ["code" => $code, "msg" => $msg, "data" => $data];
json($ret)->send();
exit;
}
#请求方式验证
function requestMethod(Request $request){
#判断请求方式
if (!$request->isPost()){
$this->json_exit(401,"请求方式有误!");
}
}
#---------------------------------------API分割下--------------------------------------#
/**
* 作者: 王统
* 开发时间: 2020/6/1
* 功能:根据学生选择阶段、年级、科目、地址等信息匹配最佳教师
*/
public function seeTeacher(Request $request){
$teacher = new TeacherModel();
$education_id = $request->post('education_id');#学历阶段id
$grades = $request->post('grades_id');#所在年级ID
$classifications = $request->post('classifications_id');#预约的科目id
$address = $request->post('address');#地址
$where = [];
if(isset($education_id)){
array_push($where,['classifications_id','=',$education_id]);
}
if(isset($subjects)){
array_push($where,['classifications_id','=',$classifications]);
}
if(isset($grades)){
array_push($where,['grade_id','=',$grades]);
}
if(isset($address)){
array_push($where,['address', 'like', $address. '%']);
}
$teacherInfo = $teacher->where($where)->select();
if (!$teacherInfo){
$this->json_exit(404,"查询教师失败!");
}
$this->json_result(200,"查询教师成功!",$teacherInfo);
}
/**
* 作者: 王统
* 开发时间: 2020/6/2
* 功能:预约信息保存
*/
public function appointment(Request $request){
#获取参数
$data=array(
"method" => $request->post('method'),
"curriculums_id" => $request->post('curriculums_id'),
"teachers_id" => $request->post('teachers_id'),
"students_id" => $request->post('students_id'),
);
#验证参数
try {
validate(CheckAppointment::class)->check($data);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return $this->json_exit(422, $e->getError());
}
#数据入库
$appointment = new \app\edus\model\Appointment();
$appointmentResulet = $appointment->save($data);
if ($appointmentResulet===false){
return $this->json_exit('400',"预约失败!");
}else{
return $this->json_result('201',"预约成功!",$appointmentResulet);
}
}

/**
* 作者: 王统
* 开发时间: 2020/6/2
* 功能:学生预约名单显示
* BUG
*/
public function appointmentList(Request $request){
$page=$request->param('page');
#获取预约表学生id
$appointment = new \app\edus\model\Appointment();
$studentsIdArr = $appointment->select()->toarray();
#判断从预约表查询出来的学生id是否是大于1
$data = [];
if (count($studentsIdArr)!==1){
foreach ($studentsIdArr as $k => $v){
$data[] = $v['id'];
}
$studentsModel = new StudentsModel();
#数组查询,根据不定数id进行查询
$studentsData = $studentsModel
->where('id','in',$data)
->paginate(['list_rows'=>$page,false,'query' => request()->param()]);
$data = [];
$data['lastPage'] = $studentsData->lastPage();
$data['data'] = $studentsData->getCollection();
if (count($studentsData)!==0){
return $this->json_result(200,"预约名单查看成功!",$data);
}else{
return $this->json_exit(404,"预约学生名单查询失败!");
}
}
}

/**
* 作者: 王统
* 开发时间: 2020/6/2
* 功能:上课名单显示
*/
public function courseList(){
#获取前端teacher_id参数
$teacherId=$this->request->param('teacher_id',0,'intval');
#判断参数是否是数字
if ($teacherId==0){
return $this->json_exit(422,"请检查参数正确性");
}
$course = new CourseModel();
$courseArr = $course->where('teacher_id',$teacherId)->where('status',0)->select()->toarray();
if (count($courseArr)!==0){
return $this->json_result(200,"教师端上课名单查询成功!",$courseArr);
}else{
return $this->json_exit(404,"教师端上课名单查询失败!");
}
}
/**
* 作者:王统
* 开发时间:2020-6-4
* 功能:后台一键警报
* BUGkiry_give_an_alarm
*/
public function giveAnAlarm(Request $request){
#获取参数组:报警人id、报警人标题、报警人内容
$parameter=array(
'people_id' => $request->param('people_id'),
'title' => $request->param('title'),
'content' => $request->param('content')
);
#验证参数
$giveAnAlarmValidate = new CheckGiveAnAlarm();
try {
validate(CheckGiveAnAlarm::class)->check($parameter);
}catch (ValidateException $e){
return $this->json_exit(422, $e->getError());
}
$giveAnAlarm = new GiveAnAlarmModel();
$giveAnAlarmResult = $giveAnAlarm->save($parameter);

if ($giveAnAlarmResult===false){
return $this->json_exit('400',"报警提交失败!");
}else{
return $this->json_result('201',"报警提交成功!",$giveAnAlarmResult);
}
}

/**
* 作者: 王统
* 开发时间: 2020/6/4
* 功能:教师上课通知发送(短信端)
*/
public function teacherNotice(){
#获取前端teacher_id参数
$teacherId = $this->request->param('teacher_id',0,'intval');
#判断参数是否是数字
if ($teacherId==0){
return $this->json_exit(422,"请检查参数正确性");
}
$noticeDate = NoticeModel::where('teacher_id',$teacherId)->select();
if ($noticeDate->isEmpty()){
return $this->json_exit(404,"无数据");
}
#获取$courseArr中的数据
$courseData = [];
$courseResult = CourseModel::where('teacher_id',$teacherId)->select()->toarray();
$teacherName = TeacherModel::where('id',$teacherId)->select()->toarray();
$phone=[];
foreach ($teacherName as $k=>$v){
$courseData['teacher_name'] = $v['name'];//教师名字
$phone['phone'] = $v['phone'];//教师电话
}
foreach ($courseResult as $k=>$v){
$courseData['class_time'] = $v['class_time'];//上课时间
$courseData['title'] = $v['title'];//课程
}
/**
* 1、设置模板变量内容:
尊敬的${teacher_name}老师,您上课时间为:${class_time},课程为:${title},请按时授课!
* 2、调用阿里云短信发送接口sendSms()方法
* 3、成功
*/
$sendSMSArr = array(
'teacher_name' => $courseData['teacher_name'],
'class_time' => $courseData['class_time'],
'title' => $courseData['title']
);
$signName='一咻教育科技';
$templateCode='SMS_192540912';
#电话、签名、模板变量、模板code
$sendSMS = $this->sendCode($phone,$signName,$sendSMSArr,$templateCode);
if($sendSMS && $sendSMS->Code == 'OK') {
return $this->json_result(200,"上课通知发送成功!",$sendSMS);
}else {
return $this->json_exit(404,"上课通知发送失败!");
}
}

/**
* 作者: 王统
* 开发时间: 2020/6/6
* 功能:教师系统通知发送(短信端)
* BUG
*/
public function systemNotification(){
#获取前端teacher_id参数
$teacherId = $this->request->param('teacher_id',0,'intval');
#判断参数是否是数字
if ($teacherId==0){
return $this->json_exit(422,"请检查参数正确性");
}
#根据教师id查询教师电话
$teacherResult = TeacherModel::where('id',$teacherId)->select()->toarray();
$teacherArr=[];//教师姓名、电话
foreach ($teacherResult as $K=>$v){
$teacherArr['phone'] = $v['phone'];
$teacherArr['teacher_name'] = $v['name'];
}
$phone = $teacherArr['phone'];//电话
$teacherName = $teacherArr['teacher_name'];//教师姓名

$signName = '一咻教育科技';//签名
$templateCode = 'SMS_192540912';//模板code
$noticeResult = NoticeModel::where('id',$teacherId)->select();

$teacherArr = [];
foreach ($noticeResult as $K=>$v){
$teacherArr['title'] = $v['title'];//通知标题
$teacherArr['content'] = $v['content'];//通知内容
}

$sendSMSArr = array(
'teacher_name' => $teacherName,//教师名字
'title' => $teacherArr['title'],//通知标题
'content' => $teacherArr['content']//通知内容
);//模板变量
#模板变量内容:
#${teacher_name}您好!您有新通知了:${title},${content}
#将上面模板内容配置到阿里云短信模板中即可使用
$sendSMS = $this->sendCode($phone,$signName,$sendSMSArr,$templateCode);
var_dump($sendSMS);die();
if($sendSMS && $sendSMS->Code == 'OK') {
return $this->json_result(200,"教师系统通知发送至教务处成功!",$sendSMS);
}else {
return $this->json_exit(404,"教师系统通知发送至教务处失败!");
}
}

/**
* 作者: 王统
* 开发时间: 2020/6/5
* 功能:通知添加
*/
public function addNotice(){
#获取前端数据
$data=array(
'create_name' => $this->request->param('create_name'),//创建者
'teacher_id' => $this->request->param('teacher_id'),//教师ID
'student_id' => $this->request->param('student_id'),//教师ID
'title' => $this->request->param('title'),//通知标题
'content' => $this->request->param('content'),//通知内容
'send_time' => $this->request->param('send_time'),//通知发送时间
);
try {
validate(CheckNotice::class)->check($data);
} catch (ValidateException $e) {
$this->json_exit(422,$e->getError());
}
$noticeModel = new NoticeModel();
$noticeResult = $noticeModel->save($data);
if($noticeResult===false){
return $this->json_exit(400,"通知消息添加失败!");
}else{
return $this->json_result(201,"通知消息添加成功!",$noticeResult);
}
}
/**
* 作者: 王统
* 开发时间: 2020/6/5
* 功能:一键沟通获取助教电话给前端显示
*/
public function assistant(){
$assistantResult=AssistantModel::select();
#判断数据集是否为空
if ($assistantResult->isEmpty()){
return $this->json_exit(404,"查询助教电话失败!");
}else{
return $this->json_result(200,"查询助教电话成功!",$assistantResult);
}
}
public function test(){
$teacher = TeacherModel::where('id',0)->select();
if (!$teacher->isEmpty()){
echo "无数据";
}else{
echo $pp=$teacher['name'];
}
}
}
Apipost 私有化火热进行中

评论

苑儿飞雪

暂未填写介绍