select = 'template_id,product_type'; $criteria->addCondition('is_default=1'); $result = $this->findAll($criteria); if($result){ $info = getAttributes($result); }else{ $info = array(); } return $info; } /** * @return array|null * 获取产品设置列表 */ public function getProductList($subjectId=3){ $criteria = new CDbCriteria(); $criteria->select = 'template_id,template_name,product_type,target_type,is_default,subject_id'; $criteria->addCondition('subject_id='.$subjectId); $criteria->order = 'product_type,template_id ASC'; $result = getAttributes($this->findAll($criteria)); return $result; } /** * @param int $id * @return static * 获取设置详情 */ public function getSetInfo($id=0,$subjectId=3){ if($id>0 && $id!='NULL'){ $result = $this->findByPk($id); }else{ $criteria = new CDbCriteria(); $criteria->addCondition('product_type=1 AND is_default=1 AND subject_id='.$subjectId); $result = $this->find($criteria); } return $result; } /** * @param $psType * @param $name * @return array * 添加新的产品 */ public function addNew($psType,$name,$subjectId=3){ $criteria = new CDbCriteria(); $criteria->select = 'ps_id'; $criteria->addCondition("product_type={$psType} AND name='{$name}' AND subject_id='{$subjectId}'"); $result = $this->find($criteria); if($result){ //重名 return array('status'=>0,'msg'=>"重名"); }else{ $criteria = new CDbCriteria(); $criteria->addCondition("product_type={$psType} AND is_default=1"); $oldResult = $this->find($criteria); $new = $oldResult->getAttributes(); $ps = new SProductSetting(); $ps->name = $name; $ps->product_type = $new['product_type']; $ps->show_map = $new['show_map']; $ps->show_kp = $new['show_kp']; $ps->show_top = $new['show_top']; $ps->show_wrg_origin = $new['show_wrg_origin']; $ps->show_wrg_analyze = $new['show_wrg_analyze']; $ps->show_guide = $new['show_guide']; $ps->st_tuozhan = $new['st_tuozhan']; $ps->st_wrong = $new['st_wrong']; $ps->st_reduce = $new['st_reduce']; $ps->show_level = $new['show_level']; $ps->create_time = time(); $ps->is_default = 0; $ps->subject_id=$subjectId; $bool = $ps->save(); if($bool){ return array('status'=>1,'msg'=>$ps->primaryKey); }else{ return array('status'=>0,'msg'=>"保存失败"); } } } /** * @param $psType * @param $name * @return string * 重命名 */ public function rename($psType,$name){ $ti = explode('_',$psType); $criteria = new CDbCriteria(); $criteria->select = 'ps_id'; $criteria->addCondition("product_type={$ti[0]} AND ps_id!={$ti[1]} AND name='{$name}'"); $result = $this->find($criteria); if($result){ //重名 return '2'; }else{ //更新 $bool = $this->updateByPk($ti[1],array('name'=>$name)); if($bool!==false){ return '1'; }else{ return '0'; } } } }