123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- /**
- * 业务后台学生模型类
- * @author jiangfei
- * @date 2015-07-20 19:30:00
- * @company 上海风车教育有限公司.
- */
- class BusinessStudent extends BusinessActiveRecord{
-
- public static function model($className = __CLASS__){
- return parent::model($className);
- }
- public function tableName(){
- return "student";
- }
- public function primaryKey()
- {
- return array('student_id');
- }
- //根据uuid获取学生信息
- public function getStudentById($id){
- $info = $this->find('student_id=:stid',array(':stid'=>$id));
- if (empty($info)) {
- return null;
- } else {
- return $info->username;
- }
- }
- public function getStudentByUsernames($userNames)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('username',$userNames);
- $info = $this->findAll($criteria);
- if (empty($info)) {
- return false;
- } else {
- return $info;
- }
- }
- public function getStudentByUsernamesAndSchoolId($userNames,$school_id)
- {
- $criteria = new CDbCriteria();
- $criteria->addInCondition('username',$userNames);
- $criteria->addCondition('school_id=:school_id');
- $criteria->params[':school_id']=$school_id;
- $info = $this->findAll($criteria);
- if (empty($info)) {
- return false;
- } else {
- return $info;
- }
- }
-
- public function getStatus1ByStudentIds($studentIds,$school_id)//获取有效学生
- {
- $student_id=array();
-
- if ($studentIds && is_array($studentIds)) {
- $criteria = new CDbCriteria();
- $criteria->addCondition('school_id=:school_id');
- $criteria->params[':school_id']=$school_id;
- $criteria->addCondition('status=0');
- $criteria->addInCondition('student_id', $studentIds);
-
- $students = getAttributes($this->findAll($criteria));
-
- if ($students) {
- foreach ($students as $student) {
- $student_id[]=$student['student_id'];
- }
- }
- }
-
- return $student_id;
- }
-
- public function getCardsByStudentIds($studentIds)
- {
- $result = array();
-
- if ($studentIds && is_array($studentIds)) {
- $criteria = new CDbCriteria();
- $criteria->select = 'student_id, student_card, school_student_card';
- $criteria->addInCondition('student_id', $studentIds);
-
- $students = getAttributes($this->findAll($criteria));
-
- if ($students) {
- $result[0] = array();
- $result[1] = array();
-
- foreach ($students as $student) {
- $result[0][$student['student_id']] = $student['student_card'];
- $result[1][$student['student_id']] = $student['school_student_card'];
- }
- }
- }
-
- return $result;
- }
-
-
- //过滤无效学生
- public function keepStudentsStatus_0($studentIds){
- $result = array();
- if ($studentIds && is_array($studentIds)) {
- $criteria = new CDbCriteria();
- $criteria->select = 'student_id,status';
- $criteria->addInCondition('student_id',$studentIds);
-
- $students = getAttributes($this->findAll($criteria));
- if($students){
- foreach($students as $student){
- if($student['status'] == 0){
- $result[] = $student['student_id'];
- }
- }
- }
-
- }
- return $result;
-
- }
-
-
- //分页获取学生数据
- public function getStudentsByPages($schoolId){
- $result = array();
-
- $sql = "select count(0) as count from student where school_id = '{$schoolId}' order by student_id desc";
- $countArr = Yii::app()->businessDb->createCommand($sql)->queryRow();
- if($countArr && $countArr['count']){
- $count = $countArr['count'];
- $limit = 10000;
- $page = ceil($count/$limit);
-
- $_sql = "select `student_id`,`username`,`student_card`,`school_student_card`,`zhixue_student_card`,`password`,`school_id`,`register_time` from student where school_id = '{$schoolId}' order by student_id desc";
- for($a = 1;$a <= $page;$a++){
- $offset = ($a - 1)*$limit;
- $_sqls = $_sql." limit {$offset},{$limit}";
- $data = Yii::app()->businessDb->createCommand($_sqls)->queryAll();
- foreach($data as $k=>$v){
- $result['b_student'][$v['student_id']] = $v;
- $result['b_student_ids'][$v['student_id']] = $v['student_id'];
- $result['b_id_student_cards'][$v['student_id']] = $v['student_card'];
- $result['b_id_school_student_cards'][$v['student_id']] = $v['school_student_card'];
- $result['b_id_zhixue_student_cards'][$v['student_id']] = $v['zhixue_student_card'];
- if($v['student_card'])
- {
- $result['b_student_cards'][$v['student_card']] = $v['student_id'];
- }
- if($v['school_student_card'])
- {
- $result['b_school_student_cards'][$v['school_student_card']] = $v['student_id'];
- }
- }
- unset($data);
- }
- }
- return $result;
- }
-
- //获取学生数据(schoolId,zhixue_student_card)
- public function getStudentsBySchoolIdAndZhixuecard($schoolId,$zhixue_student_card){
- $result = array();
- if(!$zhixue_student_card){
- $zhixue_student_card = array();
- }
- $sql = "select student_id,zhixue_student_card from student where school_id = '{$schoolId}' and zhixue_student_card in (".implode(',',$zhixue_student_card).")";
- $data = Yii::app()->businessDb->createCommand($sql)->queryAll();
- if($data){
- return $data;
- }else{
- return $result;
- }
-
- }
-
- }
|