BusinessSchool.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * 学校模型类
  4. * @author jiangfei
  5. * @date 2015-10-29 13:30:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class BusinessSchool extends BusinessActiveRecord{
  9. public static function model($className = __CLASS__){
  10. return parent::model($className);
  11. }
  12. public function tableName(){
  13. return "school";
  14. }
  15. //查询学校
  16. public function getSchoolIdByCondition($condition){
  17. $schoolIds=array();
  18. $sql="select school_id from school where ".implode(' and ',$condition);
  19. $schoolData=Yii::app()->businessDb->createCommand($sql)->queryAll();
  20. foreach ($schoolData as $val){
  21. $schoolIds[]=$val['school_id'];
  22. }
  23. return $schoolIds;
  24. }
  25. public function countSchool($condition){
  26. $sql="select count(*) as count from school ";
  27. if($condition){
  28. $sql.=" where ".implode(' and ',$condition);
  29. }
  30. $data=$this->getDbConnection()->createCommand($sql)->queryRow();
  31. if($data){
  32. return $data['count'];
  33. }
  34. }
  35. public function getList($condition,$page,$pageLimit){
  36. $sql="select school_id,school_name,province_id,city_id,area_id from school ";
  37. if($condition){
  38. $sql.=" where ".implode(' and ',$condition);
  39. }
  40. $sql.=" order by school_id asc ";
  41. $offset=($page-1)*$pageLimit;
  42. $sql.=" limit {$offset},{$pageLimit}";
  43. $data=$this->getDbConnection()->createCommand($sql)->queryAll();
  44. return $data;
  45. }
  46. //更新学校学生设备权限
  47. public function updateLoginPermission($schoolId,$permission){
  48. $result = 0;
  49. $sql="select school_id,is_login_permission from school where school_id = '{$schoolId}' and is_login_permission = '{$permission}'";
  50. $schoolData=$this->getDbConnection()->createCommand($sql)->queryRow();
  51. if(!$schoolData){
  52. $sql = "update school set is_login_permission='{$permission}' where school_id = {$schoolId}";
  53. $is_edit=$this->getDbConnection()->createCommand($sql)->execute();
  54. if($is_edit){
  55. $result = $permission;
  56. }else{
  57. $result = $schoolData['is_login_permission'];
  58. }
  59. }else{
  60. $result = $schoolData['is_login_permission'];
  61. }
  62. return $result;
  63. }
  64. }