public function actionNav_product_category_add() { $this->setauth(); //检查有无权限 $p_db = Yii::app()->p_db; $group = new VcosNavigationGroup(); $group_category = new VcosNavigationGroupCategory(); $nav = isset($_POST['nav']) ? $_POST['nav'] : 0; $val = isset($_POST['val']) ? $_POST['val'] : 0; $parent = isset($_POST['parent']) ? $_POST['parent'] : 0; $name = isset($_POST['name']) ? $_POST['name'] : ''; $sort = isset($_POST['sort']) ? $_POST['sort'] : ''; $img_name = isset($_POST['img_name']) ? $_POST['img_name'] : ''; $cat_name = isset($_POST['cat_name']) ? $_POST['cat_name'] : ''; $highlight = isset($_POST['highlight']) ? $_POST['highlight'] : 0; //var_dump($_POST);exit; if ($val == 0 || $val == '') { //新增 if ($parent == 0) { $photo = ''; if ($_FILES[$img_name]['error'] != 4) { $result = Helper::upload_file($img_name, Yii::app()->params['img_save_url'] . 'navigation_images/' . Yii::app()->params['month'], 'image', 3); $photo = $result['filename']; } $photo_url = 'navigation_images/' . Yii::app()->params['month'] . '/' . $photo; //事务处理 $transaction = $p_db->beginTransaction(); try { $group->navigation_id = $nav; $group->navigation_group_name = $name; $group->sort_order = $sort; $group->img_url = $photo_url; $group->save(); //$id = $group->attributes['navigation_group_id']; $transaction->commit(); Helper::show_message(yii::t('vcos', '添加成功。'), Yii::app()->createUrl("Navigation/nav_column_set", array('nav' => $nav, 'act' => 'category', 'op' => 1))); } catch (Exception $e) { $transaction->rollBack(); Helper::show_message(yii::t('vcos', '添加失败。'), Yii::app()->createUrl("Navigation/nav_column_set", array('nav' => $nav, 'act' => 'category', 'op' => 1))); } } else { //事务处理 $transaction = $p_db->beginTransaction(); try { $group_category->navigation_group_id = $parent; $group_category->navigation_category_name = $name; $group_category->sort_order = $sort; $group_category->is_highlight = $highlight; $group_category->category_type = 1; $group_category->mapping_id = $cat_name; $group_category->save(); //$id = $group->attributes['navigation_group_id']; $transaction->commit(); Helper::show_message(yii::t('vcos', '添加成功。'), Yii::app()->createUrl("Navigation/nav_column_set", array('nav' => $nav, 'act' => 'category', 'op' => 1))); } catch (Exception $e) { $transaction->rollBack(); Helper::show_message(yii::t('vcos', '添加失败。'), Yii::app()->createUrl("Navigation/nav_column_set", array('nav' => $nav, 'act' => 'category', 'op' => 1))); } } } else { //修改 if ($parent == 0) { $photo = ''; if ($_FILES[$img_name]['error'] != 4) { $result = Helper::upload_file($img_name, Yii::app()->params['img_save_url'] . 'navigation_images/' . Yii::app()->params['month'], 'image', 3); $photo = $result['filename']; } $photo_url = 'navigation_images/' . Yii::app()->params['month'] . '/' . $photo; //事务处理 $transaction = $p_db->beginTransaction(); try { if ($photo == '') { $sql = "UPDATE `vcos_navigation_group` SET navigation_group_name='{$name}' WHERE navigation_group_id='{$val}'"; } else { $sql = "UPDATE `vcos_navigation_group` SET navigation_group_name='{$name}',img_url='{$photo_url}' WHERE navigation_group_id='{$val}'"; } Yii::app()->p_db->createCommand($sql)->execute(); $transaction->commit(); Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Navigation/nav_column_set", array('nav' => $nav, 'act' => 'category', 'op' => 1))); } catch (Exception $e) { $transaction->rollBack(); Helper::show_message(yii::t('vcos', '修改失败。'), Yii::app()->createUrl("Navigation/nav_column_set", array('nav' => $nav, 'act' => 'category', 'op' => 1))); } } else { //事务处理 $transaction = $p_db->beginTransaction(); try { $sql = "UPDATE `vcos_navigation_group_category` SET navigation_category_name='{$name}',mapping_id='{$cat_name}',is_highlight='{$highlight}' WHERE navigation_group_cid='{$val}'"; Yii::app()->p_db->createCommand($sql)->execute(); $transaction->commit(); Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Navigation/nav_column_set", array('nav' => $nav, 'act' => 'category', 'op' => 1))); } catch (Exception $e) { $transaction->rollBack(); Helper::show_message(yii::t('vcos', '修改失败。'), Yii::app()->createUrl("Navigation/nav_column_set", array('nav' => $nav, 'act' => 'category', 'op' => 1))); } } } }
public function actionNavigation_group_edit() { $this->setauth(); //检查有无权限 $p_db = Yii::app()->p_db; $id = $_GET['id']; $navigation_group = VcosNavigationGroup::model()->findByPk($id); if ($_POST) { $name = isset($_POST['name']) ? $_POST['name'] : ''; $navigation = isset($_POST['navigation']) ? $_POST['navigation'] : 0; $activity = isset($_POST['activity']) ? $_POST['activity'] : 0; $sort = isset($_POST['sort']) ? $_POST['sort'] : '0'; $group_type = isset($_POST['group_type']) ? $_POST['group_type'] : '0'; $state = isset($_POST['state']) ? $_POST['state'] : '0'; $photo = ''; if ($_FILES['photo']['error'] != 4) { $result = Helper::upload_file('photo', Yii::app()->params['img_save_url'] . 'navigation_images/' . Yii::app()->params['month'], 'image', 3); $photo = $result['filename']; } $photo_url = 'navigation_images/' . Yii::app()->params['month'] . '/' . $photo; //事务处理 $transaction = $p_db->beginTransaction(); try { $navigation_group->navigation_group_name = $name; $navigation_group->navigation_id = $navigation; $navigation_group->activity_id = $activity; $navigation_group->img_url = $photo_url; $navigation_group->sort_order = $sort; $navigation_group->status = $state; $navigation_group->show_type = $group_type; $navigation_group->save(); $transaction->commit(); Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Navigation/navigation_group_list")); } catch (Exception $e) { $transaction->rollBack(); Helper::show_message(yii::t('vcos', '修改失败。')); } } $sql = "SELECT activity_id,activity_name FROM `vcos_activity` WHERE status=1"; $activity = Yii::app()->p_db->createCommand($sql)->queryAll(); $sql = "SELECT navigation_id,navigation_name FROM `vcos_navigation` WHERE is_category=1 AND status=1"; $navigation = Yii::app()->p_db->createCommand($sql)->queryAll(); $this->render('navigation_group_edit', array('activity' => $activity, 'navigation' => $navigation, 'navigation_group' => $navigation_group)); }