Ejemplo n.º 1
0
 public function actionLscategoryadd()
 {
     if ($this->auth[0] == '0') {
     } else {
         $error = Yii::app()->createUrl('error/index');
         $this->redirect($error);
     }
     $lc = new VcosLifeserviceCategory();
     $lc_language = new VcosLifeserviceCategoryLanguage();
     if ($_POST) {
         $photo = '';
         if ($_FILES['photo']['error'] != 4) {
             $result = Helper::upload_file('photo', Yii::app()->params['img_save_url'] . 'lifeservice_images/' . Yii::app()->params['month'], 'image', 3);
             $photo = $result['filename'];
         }
         $state = isset($_POST['state']) ? $_POST['state'] : '0';
         $lc->bg_color = $_POST['bgcolor'];
         $lc->lc_state = $state;
         $lc->lc_img_url = 'lifeservice_images/' . Yii::app()->params['month'] . '/' . $photo;
         //处理事务
         $db = Yii::app()->m_db;
         $transaction = $db->beginTransaction();
         try {
             $lc->save();
             if (isset($_POST['language']) && $_POST['language'] != '') {
                 //判读是否同时添加系统语言和外语
                 $sql = "INSERT INTO `vcos_lifeservice_category_language` (`lc_id`, `iso`, `lc_name`) VALUES ('{$lc->primaryKey}', '" . Yii::app()->params['language'] . "', '{$_POST['title']}'), ('{$lc->primaryKey}', '{$_POST['language']}', '{$_POST['title_iso']}')";
                 $db->createCommand($sql)->execute();
                 $transaction->commit();
                 Helper::show_message(yii::t('vcos', '添加成功。'), Yii::app()->createUrl("Lifeservice/Service_category"));
             } else {
                 //只添加系统语言时
                 $lc_language->lc_id = $lc->primaryKey;
                 $lc_language->iso = Yii::app()->params['language'];
                 $lc_language->lc_name = $_POST['title'];
                 $lc_language->save();
                 $transaction->commit();
                 Helper::show_message(yii::t('vcos', '添加成功。'), Yii::app()->createUrl("Lifeservice/Service_category"));
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Helper::show_message(yii::t('vcos', '添加失败。'), '#');
         }
     }
     $this->render('lscategoryadd', array('lc' => $lc, 'lc_language' => $lc_language));
 }
Ejemplo n.º 2
0
 public function actionService_categoryedit()
 {
     $this->setauth();
     //检查有无权限
     $id = $_GET['id'];
     $lc = VcosLifeserviceCategory::model()->findByPk($id);
     $sql = "SELECT b.id FROM vcos_lifeservice_category a LEFT JOIN vcos_lifeservice_category_language b ON a.lc_id = b.lc_id WHERE a.lc_id = {$id} AND b.iso ='" . Yii::app()->params['language'] . "'";
     $id2 = Yii::app()->m_db->createCommand($sql)->queryRow();
     $lc_language = VcosLifeserviceCategoryLanguage::model()->findByPk($id2['id']);
     if ($_POST) {
         $photo = '';
         if ($_FILES['photo']['error'] != 4) {
             $result = Helper::upload_file('photo', Yii::app()->params['img_save_url'] . 'lifeservice_images/' . Yii::app()->params['month'], 'image', 3);
             $photo = $result['filename'];
         }
         $state = isset($_POST['state']) ? $_POST['state'] : '0';
         if ($state == '0') {
             //$result = VcosLifeservice::model()->count('ls_category=:id',array(':id'=>$id));
             $sql = "SELECT count(*) count FROM vcos_lifeservice WHERE ls_state = 1 AND ls_category =" . $id;
             $count = Yii::app()->m_db->createCommand($sql)->queryRow();
             if ($count['count'] > 0) {
                 die(Helper::show_message(yii::t('vcos', '此分类正在使用,不能禁用。')));
             }
         }
         //事务处理
         $db = Yii::app()->m_db;
         $transaction = $db->beginTransaction();
         try {
             if (isset($_POST['language']) && $_POST['language'] != '') {
                 //编辑系统语言和外语状态下
                 //编辑主表
                 $columns = array('lc_state' => $state, 'bg_color' => $_POST['bgcolor']);
                 if ($photo) {
                     //判断有无上传图片
                     $columns['lc_img_url'] = 'lifeservice_images/' . Yii::app()->params['month'] . '/' . $photo;
                 }
                 $db->createCommand()->update('vcos_lifeservice_category', $columns, 'lc_id = :id', array(':id' => $id));
                 //编辑系统语言
                 $db->createCommand()->update('vcos_lifeservice_category_language', array('lc_name' => $_POST['title']), 'id=:id', array(':id' => $id2['id']));
                 //判断外语是新增OR编辑
                 if ($_POST['judge'] == 'add') {
                     //新增外语
                     $db->createCommand()->insert('vcos_lifeservice_category_language', array('lc_id' => $id, 'iso' => $_POST['language'], 'lc_name' => $_POST['title_iso']));
                 } else {
                     //编辑外语
                     $db->createCommand()->update('vcos_lifeservice_category_language', array('lc_name' => $_POST['title_iso']), 'id=:id', array(':id' => $_POST['judge']));
                 }
                 //事务提交
                 $transaction->commit();
                 Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Lifeservice/Service_category"));
             } else {
                 //只编辑系统语言
                 $lc->lc_id = $id;
                 $lc->bg_color = $_POST['bgcolor'];
                 $lc->lc_state = $state;
                 if ($photo) {
                     $lc->lc_img_url = 'lifeservice_images/' . Yii::app()->params['month'] . '/' . $photo;
                 }
                 $lc->save();
                 $lc_language->id = $id2['id'];
                 $lc_language->lc_name = $_POST['title'];
                 $lc_language->save();
                 $transaction->commit();
                 Helper::show_message(yii::t('vcos', '修改成功。'), Yii::app()->createUrl("Lifeservice/Service_category"));
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Helper::show_message(yii::t('vcos', '修改失败。'));
         }
     }
     $this->render('categoryedit', array('lifeservice_category' => $lc, 'lc_language' => $lc_language));
 }