BusinessStudent.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * 业务后台学生模型类
  4. * @author jiangfei
  5. * @date 2015-07-20 19:30:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class BusinessStudent extends BusinessActiveRecord{
  9. public static function model($className = __CLASS__){
  10. return parent::model($className);
  11. }
  12. public function tableName(){
  13. return "student";
  14. }
  15. public function primaryKey()
  16. {
  17. return array('student_id');
  18. }
  19. //根据uuid获取学生信息
  20. public function getStudentById($id){
  21. $info = $this->find('student_id=:stid',array(':stid'=>$id));
  22. if (empty($info)) {
  23. return null;
  24. } else {
  25. return $info->username;
  26. }
  27. }
  28. public function getStudentByUsernames($userNames)
  29. {
  30. $criteria = new CDbCriteria();
  31. $criteria->addInCondition('username',$userNames);
  32. $info = $this->findAll($criteria);
  33. if (empty($info)) {
  34. return false;
  35. } else {
  36. return $info;
  37. }
  38. }
  39. public function getStudentByUsernamesAndSchoolId($userNames,$school_id)
  40. {
  41. $criteria = new CDbCriteria();
  42. $criteria->addInCondition('username',$userNames);
  43. $criteria->addCondition('school_id=:school_id');
  44. $criteria->params[':school_id']=$school_id;
  45. $info = $this->findAll($criteria);
  46. if (empty($info)) {
  47. return false;
  48. } else {
  49. return $info;
  50. }
  51. }
  52. public function getStatus1ByStudentIds($studentIds,$school_id)//获取有效学生
  53. {
  54. $student_id=array();
  55. if ($studentIds && is_array($studentIds)) {
  56. $criteria = new CDbCriteria();
  57. $criteria->addCondition('school_id=:school_id');
  58. $criteria->params[':school_id']=$school_id;
  59. $criteria->addCondition('status=0');
  60. $criteria->addInCondition('student_id', $studentIds);
  61. $students = getAttributes($this->findAll($criteria));
  62. if ($students) {
  63. foreach ($students as $student) {
  64. $student_id[]=$student['student_id'];
  65. }
  66. }
  67. }
  68. return $student_id;
  69. }
  70. public function getCardsByStudentIds($studentIds)
  71. {
  72. $result = array();
  73. if ($studentIds && is_array($studentIds)) {
  74. $criteria = new CDbCriteria();
  75. $criteria->select = 'student_id, student_card, school_student_card';
  76. $criteria->addInCondition('student_id', $studentIds);
  77. $students = getAttributes($this->findAll($criteria));
  78. if ($students) {
  79. $result[0] = array();
  80. $result[1] = array();
  81. foreach ($students as $student) {
  82. $result[0][$student['student_id']] = $student['student_card'];
  83. $result[1][$student['student_id']] = $student['school_student_card'];
  84. }
  85. }
  86. }
  87. return $result;
  88. }
  89. //过滤无效学生
  90. public function keepStudentsStatus_0($studentIds){
  91. $result = array();
  92. if ($studentIds && is_array($studentIds)) {
  93. $criteria = new CDbCriteria();
  94. $criteria->select = 'student_id,status';
  95. $criteria->addInCondition('student_id',$studentIds);
  96. $students = getAttributes($this->findAll($criteria));
  97. if($students){
  98. foreach($students as $student){
  99. if($student['status'] == 0){
  100. $result[] = $student['student_id'];
  101. }
  102. }
  103. }
  104. }
  105. return $result;
  106. }
  107. //分页获取学生数据
  108. public function getStudentsByPages($schoolId){
  109. $result = array();
  110. $sql = "select count(0) as count from student where school_id = '{$schoolId}' order by student_id desc";
  111. $countArr = Yii::app()->businessDb->createCommand($sql)->queryRow();
  112. if($countArr && $countArr['count']){
  113. $count = $countArr['count'];
  114. $limit = 10000;
  115. $page = ceil($count/$limit);
  116. $_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";
  117. for($a = 1;$a <= $page;$a++){
  118. $offset = ($a - 1)*$limit;
  119. $_sqls = $_sql." limit {$offset},{$limit}";
  120. $data = Yii::app()->businessDb->createCommand($_sqls)->queryAll();
  121. foreach($data as $k=>$v){
  122. $result['b_student'][$v['student_id']] = $v;
  123. $result['b_student_ids'][$v['student_id']] = $v['student_id'];
  124. $result['b_id_student_cards'][$v['student_id']] = $v['student_card'];
  125. $result['b_id_school_student_cards'][$v['student_id']] = $v['school_student_card'];
  126. $result['b_id_zhixue_student_cards'][$v['student_id']] = $v['zhixue_student_card'];
  127. if($v['student_card'])
  128. {
  129. $result['b_student_cards'][$v['student_card']] = $v['student_id'];
  130. }
  131. if($v['school_student_card'])
  132. {
  133. $result['b_school_student_cards'][$v['school_student_card']] = $v['student_id'];
  134. }
  135. }
  136. unset($data);
  137. }
  138. }
  139. return $result;
  140. }
  141. //获取学生数据(schoolId,zhixue_student_card)
  142. public function getStudentsBySchoolIdAndZhixuecard($schoolId,$zhixue_student_card){
  143. $result = array();
  144. if(!$zhixue_student_card){
  145. $zhixue_student_card = array();
  146. }
  147. $sql = "select student_id,zhixue_student_card from student where school_id = '{$schoolId}' and zhixue_student_card in (".implode(',',$zhixue_student_card).")";
  148. $data = Yii::app()->businessDb->createCommand($sql)->queryAll();
  149. if($data){
  150. return $data;
  151. }else{
  152. return $result;
  153. }
  154. }
  155. }