123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * 产品设置.
- * User: chenye
- * Date: 2017/11/22
- * Time: 11:10
- */
- class SProductTemplate extends MyActiveRecord {
- public static function model($className = __CLASS__)
- {
- return parent::model($className);
- }
- public function tableName()
- {
- return 'product_template';
- }
- /**
- * @return array|null
- * 获取所有默认设置数据
- */
- public function getDefaultPro(){
- $criteria = new CDbCriteria();
- $criteria->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';
- }
- }
- }
- }
|