/** * 提交任务签到接口: * 教师在App中提交学员课时签到信息 * @param $user_id * @param $lessonJson * @return bool|int */ public function postSign($user_id, $lessonJson) { $nowTime = date('Y-m-d H:m:i'); try { $con_task = Yii::app()->cnhutong; $table_name = 'ht_lesson_student'; // 按照课时ID进行签到,ht_lesson_student: status_id = 1(老师签到),step = 0 正常, step = 1 补课, step = 2 缺勤, step = 6 请假 foreach ($lessonJson as $row) { // 需要对$lessonJson里面的数值做判断 if... step = 0 增加一条消息记录,jPush推送学员用户; step = 2|6 增加一条补课机会记录 $result = $con_task->createCommand()->update($table_name, array('status_id' => 1, 'step' => $row['step']), 'id = :id', array(':id' => $row['lessonStudentId'])); if ($row['step'] == 2 || $row['step'] == 6) { // 判断 step = 2|6 添加补课机会记录 self::insertExtraChance($row['lessonStudentId'], $row['step']); } elseif ($row['step'] == 0) { // step = 0 增加一条消息记录,jPush推送学员用户发送销课通知 $acceptIdArr = self::getAcceptIdByLessonStudentId($row['lessonStudentId']); // $acceptArr = array(); 则表示为该学员未绑定任何user_id 只记录消息,不推送 if ($acceptIdArr && $acceptIdArr[0]['user_id']) { foreach ($acceptIdArr as $acceptId) { $lessonDetail = Common::model()->getLessonDetailById($row['lessonStudentId']); // 推送相关补课消息给相应老师 // 学员名称 $studentName = $lessonDetail['studentName']; // 时间 $dateTime = $lessonDetail['date'] . ' ' . $lessonDetail['time']; // 课程 $courseName = $lessonDetail['course']; // 课时 $lesson_cnt_charged = $lessonDetail['lesson_cnt_charged']; // 校区 $departmentName = $lessonDetail['department']; // 老师 $teacherName = Common::model()->getNameById($user_id); // 教室 $classroomName = $lessonDetail['classroom']; // 学员 $studentId = $lessonDetail['studentId']; // 理由 备注 $extraReason $msg_content = " 学员: {$studentName} &8424 时间: {$dateTime} &8424 课程: {$courseName} &8424 课时: {$lesson_cnt_charged} &8424 老师: {$teacherName} &8424 教室: {$departmentName}/{$classroomName} "; $msg_title = '销课通知'; $alert_content = $studentName . " 完成了 " . $courseName; $push = Push::model()->pushMsg(10, $acceptId['user_id'], '1', $msg_title, $alert_content); // if ($push) { // return true; // } else { // return false; // } } // 添加老师销课消息 Notice::model()->insertNotice($user_id, $studentId, 1, null, null, 1, $msg_title, $msg_content, $nowTime, 1, 0); } else { // 记录消息,不推送 $lessonDetail = Common::model()->getLessonDetailById($row['lessonStudentId']); // 推送相关补课消息给相应老师 // 学员名称 $studentName = $lessonDetail['studentName']; // 时间 $dateTime = $lessonDetail['date'] . ' ' . $lessonDetail['time']; // 课程 $courseName = $lessonDetail['course']; // 课时 $lesson_cnt_charged = $lessonDetail['lesson_cnt_charged']; // 校区 $departmentName = $lessonDetail['department']; // 老师 $teacherName = Common::model()->getNameById($user_id); // 教室 $classroomName = $lessonDetail['classroom']; // 学员 $studentId = $lessonDetail['studentId']; // 理由 备注 $extraReason $msg_content = " 学员: {$studentName} &8424 时间: {$dateTime} &8424 课程: {$courseName} &8424 课时: {$lesson_cnt_charged} &8424 老师: {$teacherName} &8424 教室: {$departmentName}/{$classroomName} "; $msg_title = '销课通知'; // 添加老师销课消息 Notice::model()->insertNotice($user_id, $studentId, 1, null, null, 1, $msg_title, $msg_content, $nowTime, 1, 0); } } else { return false; } // return true; // 不加会返回null } } catch (Exception $e) { error_log($e); return false; } }
/** * 教师提交补课信息 * @param $user_id * @param $departmentId * @param $courseId * @param $classroomId * @param $extraTime * @param $studentJson * @param $extraReason * @return array|bool */ public function postExtraLesson($user_id, $departmentId, $courseId, $classroomId, $extraTime, $studentJson, $extraReason) { $data = array(); $nowTime = date('Y-m-d H:i:s'); try { $con_user = Yii::app()->cnhutong; // 补课表添加数据 $result1 = $con_user->createCommand()->insert('com_extra', array('member_id' => $user_id, 'extra_time' => $extraTime, 'department_id' => $departmentId, 'course_id' => $courseId, 'classroom_id' => $classroomId, 'create_time' => $nowTime, 'update_time' => $nowTime, 'flag' => 1, 'status' => 1, 'type' => 2, 'reason' => $extraReason)); // 获取补课表id $extraId = Yii::app()->cnhutong->getLastInsertID(); $studentNameArr = array(); // 补课详情表添加数据 foreach ($studentJson as $row) { $result2 = $con_user->createCommand()->insert('com_extra_detail', array('extra_id' => $extraId, 'member_id' => $row['studentId'], 'status' => 0, 'create_time' => $nowTime, 'update_time' => $nowTime, 'create_user_id' => 0, 'update_user_id' => 0)); if (Common::model()->getNameById($row['studentId'])) { $studentNameArr[] = Common::model()->getNameById($row['studentId']); } } // 推送相关补课消息给相应老师 // 申请人名称 $userName = Common::model()->getNameById($user_id); // 学员名称 $studentNames = implode(' ', $studentNameArr); // 加课时间 $extraTime // 课程 $courseName = Common::model()->getCourseById($courseId); // 校区 $departmentName = Common::model()->getDepartmentById($departmentId); // 老师 $teacherName = Common::model()->getNameById($user_id); // 教室 $classroomName = Common::model()->getClassroomById($classroomId); // 理由 备注 $extraReason $msg_content = " 申请人: {$userName} &8424 学员: {$studentNames} &8424 时间: {$extraTime} &8424 课程: {$courseName} &8424 老师: {$teacherName} &8424 教室: {$departmentName}/{$classroomName} &8424 备注: {$extraReason} "; $msg_title = '老师补课申请'; $alert_content = $teacherName . " 提交了 " . $extraTime . " 的补课申请"; // 添加老师补课消息 Notice::model()->insertNotice($user_id, $user_id, 1, null, $extraId, 3, $msg_title, $msg_content, $nowTime, 1, 0); $push = Push::model()->pushMsg(11, $user_id, '3', $msg_title, $alert_content); if ($push) { return true; } else { return false; } } catch (Exception $e) { error_log($e); return false; } }
/** * 提交课时请假信息 * @param $memberId * @param $courseId * @param $lessonStudentId * @param $dateTime * @param $reason * @return bool */ public function lessonStudentLeave($memberId, $courseId, $lessonStudentId, $dateTime, $reason) { $nowTime = date('Y-m-d H:i:s'); try { $con_user = Yii::app()->cnhutong; $table_name = 'com_leave'; // 请假表记录请假详情 $data = $con_user->createCommand()->insert($table_name, array('member_id' => $memberId, 'course_id' => $courseId, 'lesson_student_id' => $lessonStudentId, 'leave_time' => $dateTime, 'create_time' => $nowTime, 'update_time' => $nowTime, 'flag' => 2, 'status' => 1, 'reason' => $reason)); $leaveId = Yii::app()->cnhutong->getLastInsertID(); // 学员请假直接修改课表课时状态 $dataLeave = $con_user->createCommand()->update('ht_lesson_student', array('step' => 6), 'id = :lessonStudentId', array(':lessonStudentId' => $lessonStudentId)); // 根据课时id获得学员id (ht_lesson_student),再根据学员id获得绑定的user_id(com_user_member) $lessonDetail = Common::model()->getLessonDetailById($lessonStudentId); // 推送相关请假消息给相应老师 // 学员名称 $studentName = $lessonDetail['studentName']; // 时间 $dateTime = $lessonDetail['date'] . ' ' . $lessonDetail['time']; // 课程 $courseName = $lessonDetail['course']; // 课时 $lesson_cnt_charged = $lessonDetail['lesson_cnt_charged']; // 校区 $departmentName = $lessonDetail['department']; // 老师 $teacherId = $lessonDetail['teacherId']; // 教室 $classroomName = $lessonDetail['classroom']; // 理由 备注 $extraReason $msg_content = " 学员: {$studentName} &8424 时间: {$dateTime} &8424 课程: {$courseName} &8424 课时: {$lesson_cnt_charged} &8424 教室: {$departmentName}/{$classroomName} &8424 备注: {$reason} "; $msg_title = '学员请假通知'; $alert_content = $dateTime . " 的 " . $courseName . " 有一位学员请假"; // 添加学员请假消息 // 教师 Notice::model()->insertNotice($memberId, $teacherId, 2, $leaveId, null, 2, $msg_title, $msg_content, $nowTime, 1, 0); // 学生 Notice::model()->insertNotice($memberId, $memberId, 2, $leaveId, null, 2, $msg_title, $msg_content, $nowTime, 1, 0); $push = Push::model()->pushMsg(11, $teacherId, '2', $msg_title, $alert_content); // if ($push) { // return true; // } else { // return false; // } } catch (Exception $e) { error_log($e); return false; } }