getDbConnection()->createCommand($sql)->queryAll(); return $result; } /** * @param $psId * @param $classIdArr * @param $currSemester * @param $setType * @return string * 新增班级与产品关联 */ public function insertClassRelation($psId,$classIdArr,$currSemester,$setType){ if(is_array($classIdArr)){ $value = array(); //一个班级只能关联产品中的一个 foreach ($classIdArr as $k=>$v){ $value[] = "({$psId},{$v},{$currSemester},{$setType})"; } //开始事务 $transaction = $this->getDbConnection()->beginTransaction(); try{ //有则删除 $criteria = new CDbCriteria(); $criteria->addInCondition('class_id',$classIdArr); $criteria->addCondition("ps_id='{$psId}'"); $this->deleteAll($criteria); $sql = 'INSERT INTO `product_class_relation` (`ps_id`,`class_id`,`semester_id`,`set_type`) VALUES '.implode(',',$value); $this->getDbConnection()->createCommand($sql)->execute(); $transaction->commit(); return '1'; }catch (Exception $exception){ $transaction->rollback(); return '0'; } }else{ return '0'; } } public function batchInsert($data){ foreach ($data as $k=>$v){ $value[] = "({$v['ps_id']},{$v['class_id']},{$v['semester_id']},{$v['set_type']})"; } $sql = 'INSERT INTO `product_class_relation` (`ps_id`,`class_id`,`semester_id`,`set_type`) VALUES '.implode(',',$value); $this->getDbConnection()->createCommand($sql)->execute(); } /** * @param $classId * @param $setType * @return array|null * 是否存在同一类型同一班级 */ public function findRelationByClassId($classId,$setType){ $criteria = new CDbCriteria(); $criteria->select = 'ps_id,set_type'; $criteria->addCondition("class_id={$classId} AND set_type={$setType}"); $result = $this->findAll($criteria); if($result){ $info = getAttributes($result); }else{ $info = array(); } return $info; } /** * @param $psIdArr * @param $classId * @param $currSemester * @return string * 回归到默认设置 */ public function insertDefaultClass($psIdArr,$classId,$currSemester){ if(is_array($psIdArr)){ $value = "({$psIdArr['ps_id']},{$classId},{$currSemester},{$psIdArr['product_type']})"; $sql = 'INSERT INTO `product_class_relation` (`ps_id`,`class_id`,`semester_id`,`set_type`) VALUES '.$value; $bool = $this->getDbConnection()->createCommand($sql)->execute(); if($bool>0){ return '1'; }else{ return '0'; } }else{ return '0'; } } /** * @param $psIdArr * @param $classId * @param $currSemester * @return string * 添加新班级时关联默认产品设置 */ public function insertDefaultPsClass($psIdArr,$classId,$currSemester){ $value = array(); if(is_array($psIdArr)){ foreach ($psIdArr as $k=>$v){ $value[] = "({$v['ps_id']},{$classId},{$currSemester},{$v['product_type']})"; } $sql = 'INSERT INTO `product_class_relation` (`ps_id`,`class_id`,`semester_id`,`set_type`) VALUES '.implode(',',$value); $bool = $this->getDbConnection()->createCommand($sql)->execute(); if($bool>0){ return '1'; }else{ return '0'; } }else{ return '0'; } } /** * @param $psIdArr * @param $classId * @param $currSemester * @return string * 查询班级 */ public function getPsClass($psIdArr,$classId){ $value = array(); if(is_array($psIdArr)){ $sql = "select ps_id,class_id from `product_class_relation` where ps_id in(".implode(',',$psIdArr).") and class_id in(".implode(',',$classId).")"; $bool = $this->getDbConnection()->createCommand($sql)->queryAll(); return $bool; }else{ return false; } } }