Пример #1
0
 public function actionNavigation_group_category_edit()
 {
     $this->setauth();
     //检查有无权限
     $p_db = Yii::app()->p_db;
     $id = $_GET['id'];
     $navigation_group_category = VcosNavigationGroupCategory::model()->findByPk($id);
     if ($_POST) {
         $navigation_group = isset($_POST['navigation_group']) ? $_POST['navigation_group'] : 0;
         $name = isset($_POST['name']) ? $_POST['name'] : '';
         $sort = isset($_POST['sort']) ? $_POST['sort'] : '0';
         $highlight = isset($_POST['highlight']) ? $_POST['highlight'] : 0;
         $type = isset($_POST['type']) ? $_POST['type'] : '0';
         if ($type == 1) {
             $mapping = isset($_POST['mapping']) ? $_POST['mapping'] : '';
             $mapping = trim($mapping, ',');
         } else {
             $mapping = isset($_POST['one_sel']) ? $_POST['one_sel'] : '';
         }
         //$mapping = isset($_POST['mapping'])?$_POST['mapping']:'';
         $state = isset($_POST['state']) ? $_POST['state'] : '0';
         //事务处理
         $transaction = $p_db->beginTransaction();
         try {
             $navigation_group_category->navigation_group_id = $navigation_group;
             $navigation_group_category->navigation_category_name = $name;
             $navigation_group_category->sort_order = $sort;
             $navigation_group_category->is_highlight = $highlight;
             $navigation_group_category->category_type = $type;
             $navigation_group_category->mapping_id = $mapping;
             $navigation_group_category->status = $state;
             $navigation_group_category->save();
             $transaction->commit();
             Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Navigation/navigation_group_category_list"));
         } catch (Exception $e) {
             $transaction->rollBack();
             Helper::show_message(yii::t('vcos', '修改失败。'));
         }
     }
     $sql = "SELECT * FROM `vcos_navigation_group` WHERE status=1";
     $navigation_group = Yii::app()->p_db->createCommand($sql)->queryAll();
     $sql = "SELECT category_code,name FROM `vcos_category` WHERE parent_cid=0";
     $cat_1 = Yii::app()->p_db->createCommand($sql)->queryAll();
     $this_type_val = $navigation_group_category['category_type'];
     $type_cat = '';
     $cat2_val = '';
     $cat1_val = '';
     $cat2_name = '';
     $checked_sel = '';
     if ($this_type_val == 2) {
         $sql = "SELECT brand_id as val1,brand_cn_name as val2 FROM `vcos_brand` WHERE brand_status=1";
         $type_cat = Yii::app()->p_db->createCommand($sql)->queryAll();
     } elseif ($this_type_val == 3) {
         $sql = "SELECT shop_id as val1,shop_title as val2 FROM `vcos_shop`";
         $type_cat = Yii::app()->p_db->createCommand($sql)->queryAll();
     } else {
         if ($this_type_val == 1) {
             $this_code = $navigation_group_category['mapping_id'];
             $this_code = trim($this_code, ',');
             $sql = "SELECT category_code,name from `vcos_category` WHERE category_code in ({$this_code})";
             $checked_sel = Yii::app()->p_db->createCommand($sql)->queryAll();
             $this_code = explode(",", $this_code);
             $this_code = $this_code[0];
             $this_code_length = strlen($this_code);
             if ($this_code_length == 7) {
                 //三级
                 $sql = "SELECT parent_cid FROM `vcos_category` WHERE category_code=" . $this_code;
                 $cat2_res = Yii::app()->p_db->createCommand($sql)->queryRow();
                 $sql = "SELECT parent_cid,name FROM `vcos_category` WHERE category_code=" . $cat2_res['parent_cid'];
                 $cat1_res = Yii::app()->p_db->createCommand($sql)->queryRow();
                 $cat1_val = $cat1_res['parent_cid'];
                 $cat2_name = $cat1_res['name'];
                 $cat2_val = $cat2_res['parent_cid'];
             } else {
                 //二级
                 $sql = "SELECT parent_cid,name FROM `vcos_category` WHERE category_code=" . $this_code;
                 $cat1_res = Yii::app()->p_db->createCommand($sql)->queryRow();
                 $cat2_name = $cat1_res['name'];
                 $cat1_val = $cat1_res['parent_cid'];
                 $cat2_val = $this_code;
             }
             $sql = "SELECT * from `vcos_category` WHERE parent_cid=0";
             $cat1_sel = Yii::app()->p_db->createCommand($sql)->queryAll();
             $sql = "SELECT * from `vcos_category` WHERE parent_cid=" . $cat1_val;
             $cat2_sel = Yii::app()->p_db->createCommand($sql)->queryAll();
             $sql = "SELECT * from `vcos_category` WHERE parent_cid=" . $cat2_val;
             $cat3_sel = Yii::app()->p_db->createCommand($sql)->queryAll();
         }
     }
     $this->render('navigation_group_category_edit', array('checked_sel' => $checked_sel, 'cat2_name' => $cat2_name, 'type_cat' => $type_cat, 'cat1_val' => $cat1_val, 'cat2_val' => $cat2_val, 'cat1_sel' => $cat1_sel, 'cat2_sel' => $cat2_sel, 'cat3_sel' => $cat3_sel, 'navigation_group' => $navigation_group, 'navigation_group_category' => $navigation_group_category));
 }