123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- /**
- * 学校模型类
- * @author jiangfei
- * @date 2015-10-29 13:30:00
- * @company 上海风车教育有限公司.
- */
- class BusinessSchool extends BusinessActiveRecord{
-
- public static function model($className = __CLASS__){
- return parent::model($className);
- }
- public function tableName(){
- return "school";
- }
- //查询学校
- public function getSchoolIdByCondition($condition){
- $schoolIds=array();
- $sql="select school_id from school where ".implode(' and ',$condition);
- $schoolData=Yii::app()->businessDb->createCommand($sql)->queryAll();
- foreach ($schoolData as $val){
- $schoolIds[]=$val['school_id'];
- }
- return $schoolIds;
- }
- public function countSchool($condition){
- $sql="select count(*) as count from school ";
- if($condition){
- $sql.=" where ".implode(' and ',$condition);
- }
- $data=$this->getDbConnection()->createCommand($sql)->queryRow();
- if($data){
- return $data['count'];
- }
- }
- public function getList($condition,$page,$pageLimit){
- $sql="select school_id,school_name,province_id,city_id,area_id from school ";
- if($condition){
- $sql.=" where ".implode(' and ',$condition);
- }
- $sql.=" order by school_id asc ";
- $offset=($page-1)*$pageLimit;
- $sql.=" limit {$offset},{$pageLimit}";
- $data=$this->getDbConnection()->createCommand($sql)->queryAll();
- return $data;
- }
- //更新学校学生设备权限
- public function updateLoginPermission($schoolId,$permission){
- $result = 0;
- $sql="select school_id,is_login_permission from school where school_id = '{$schoolId}' and is_login_permission = '{$permission}'";
- $schoolData=$this->getDbConnection()->createCommand($sql)->queryRow();
- if(!$schoolData){
- $sql = "update school set is_login_permission='{$permission}' where school_id = {$schoolId}";
- $is_edit=$this->getDbConnection()->createCommand($sql)->execute();
- if($is_edit){
- $result = $permission;
- }else{
- $result = $schoolData['is_login_permission'];
- }
- }else{
- $result = $schoolData['is_login_permission'];
- }
- return $result;
- }
- }
|