Пример #1
0
 /**
  * Create or update new page
  * @param boolean $new
  */
 public function actionUpdate($new = false)
 {
     if ($new === true) {
         $model = new Page();
     } else {
         $model = Page::model()->cache($this->cacheTime)->language(Yii::app()->language->active)->findByPk($_GET['id']);
     }
     $this->breadcrumbs = array(Yii::t('PagesModule.default', 'MODULE_NAME') => $this->createUrl('index'), $model->isNewRecord ? $model->t('PAGE_TITLE', 0) : CHtml::encode($model->title));
     $this->pageName = $model->isNewRecord ? $model->t('PAGE_TITLE', 0) : $model->t('PAGE_TITLE', 1);
     if (!$model) {
         throw new CHttpException(404);
     }
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = $_POST['Page'];
         if ($model->validate()) {
             $model->save();
             if ($model->in_menu == 1) {
                 $isset = MenuModel::model()->findByAttributes(array('url' => '/page/' . $model->seo_alias));
                 if (!isset($isset)) {
                     $menu = new MenuModel();
                     $menu->label = $model->title;
                     $menu->url = '/page/' . $model->seo_alias;
                     if ($menu->validate()) {
                         $menu->save(false, false);
                     }
                 }
             }
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }
Пример #2
0
 public function getTree($wechatId)
 {
     $sql = "select m.name,m.id,m.type,m.parentId,a.action,a.responseId,a.id as actionId from " . MenuModel::model()->tableName() . " m left join " . MenuactionModel::model()->tableName() . " a on m.id=a.menuId  where m.wechatId=" . $wechatId . " order by m.id desc";
     $command = Yii::app()->db->createCommand($sql);
     $data = $command->queryAll();
     $tree = new Tree($data);
     return $tree->get_tree_list();
 }
Пример #3
0
 public function init()
 {
     $model = MenuModel::model()->enabled()->findAll();
     $result = array();
     foreach ($model as $item) {
         $result[] = array('label' => $item->label, 'url' => $item->url, 'active' => $this->isActive($item->url));
     }
     $this->items = CMap::mergeArray($result, $this->items);
     parent::init();
 }
Пример #4
0
 public function run()
 {
     $menus = MenuModel::model()->enabled()->findAll();
     $req = Yii::app()->request->hostInfo . Yii::app()->request->requestUri;
     foreach ($menus as $item) {
         $url = Yii::app()->request->hostInfo . $item['url'];
         $active = $url == $req ? true : false;
         // $active = (preg_match('#'.$url.'#ui', $req))?true:false;
         $this->items[] = array('label' => $item['label'], 'active' => $active, 'url' => $item['url'], 'visible' => $this->checkVisible($item['switch']));
     }
     $this->renderMenu($this->items);
 }
Пример #5
0
 public function actionUpdate($new = false)
 {
     $model = $new === true ? new MenuModel() : MenuModel::model()->findByPk($_GET['id']);
     if (isset($model)) {
         $this->pageName = Yii::t('app', 'ENGINE_MENU');
         $this->breadcrumbs = array($this->pageName => Yii::app()->createUrl('admin/core/menu'), $new === true ? Yii::t('app', 'CREATE', 1) : Yii::t('app', 'UPDATE', 1));
         if (isset($_POST['MenuModel'])) {
             $model->attributes = $_POST['MenuModel'];
             if ($model->validate()) {
                 $model->save();
                 $this->redirect(array('index'));
             }
         }
         $this->render('update', array('model' => $model));
     } else {
         throw new CHttpException(404);
     }
 }
Пример #6
0
 public function actionReplayUpdate($id)
 {
     $menuList = array();
     $keyword = $common = '';
     $model = OpenReplayModel::model()->findByPk($id);
     if ($model->wechatId != $this->wechatInfo->id) {
         return;
     }
     $open = array('' => '请选择') + CHtml::listData(OpenPlatformModel::model()->findAll('wechatId=:wechatId and status=:status', array(':wechatId' => $this->wechatInfo->id, ':status' => 1)), 'id', 'name');
     switch ($model->type) {
         //获取关联表数据
         case GiftModel::TYPE_KEYWORDS:
             $keywords = KeywordsModel::model()->findAll('type=:type and responseId=:responseId', array(':type' => OpenReplayModel::OPEN_TYPE, ':responseId' => $id));
             foreach ($keywords as $k) {
                 $oldKeywords[] = $k->name;
                 $oldIsAccurate = $k->isAccurate;
                 $isAccurate = $k->isAccurate;
                 $keyword .= $common . $k->name;
                 $common = ',';
             }
             $model->keywords = $keyword;
             $model->isAccurate = $isAccurate;
             break;
         case GiftModel::TYPE_MENU:
             //取menu的下拉列表
             $menuList = MenuModel::model()->getMenuDropDownList($this->wechatInfo->id, Globals::TYPE_OPEN);
             $action = MenuactionModel::model()->with('action_menu')->find('action_menu.wechatId=:wechatId and responseId=:responseId', array(':wechatId' => $this->wechatInfo->id, ':responseId' => $id));
             $oldAction = $model->action = isset($action->menuId) ? $action->menuId : 0;
             break;
     }
     if (isset($_POST['OpenReplayModel'])) {
         $model->attributes = $_POST['OpenReplayModel'];
         if ($model->validate()) {
             switch ($model->type) {
                 //根据活动类型更新不同关联表
                 case GiftModel::TYPE_KEYWORDS:
                     $keywordsArray = explode(',', $_POST['OpenReplayModel']['keywords']);
                     $keywordsAdd = array_unique(array_merge($oldKeywords, $keywordsArray));
                     $arrayDel = array_diff($keywordsAdd, $keywordsArray);
                     //删除了的关键字
                     $arrayAdd = array_diff($keywordsAdd, $oldKeywords);
                     //添加的关键字
                     $arrayAlive = array_diff($oldKeywords, $arrayAdd);
                     //没改变的
                     $newIsAccurate = $_POST['OpenReplayModel']['isAccurate'];
                     if ($isAccurate != $newIsAccurate && $arrayAlive) {
                         //是否精准匹配改变了
                         foreach ($arrayAlive as $name) {
                             $keywordsModel = KeywordsModel::model()->find('name=:name', array(':name' => $name));
                             $keywordsModel->isAccurate = $newIsAccurate;
                             $keywordsModel->save();
                         }
                     }
                     foreach ($arrayAdd as $k) {
                         //新加关键词
                         $keywordsModel = new KeywordsModel();
                         $keywordsModel->responseId = $id;
                         $keywordsModel->name = $k;
                         $keywordsModel->isAccurate = $newIsAccurate;
                         $keywordsModel->wechatId = $this->wechatInfo->id;
                         $keywordsModel->type = OpenReplayModel::OPEN_TYPE;
                         $keywordsModel->save();
                     }
                     foreach ($arrayDel as $k) {
                         //删除的关键词
                         $keywordsModel = KeywordsModel::model()->find('responseId=:responseId and name=:name', array(':name' => $k, ':responseId' => $id));
                         $keywordsModel->delete();
                     }
                     if ($oldIsAccurate != $isAccurate) {
                         KeywordsModel::model()->updateAll(array('isAccurate' => $isAccurate), 'responseId=:responseId', array(':responseId' => $id));
                     }
                     //更新是否精准匹配字段
                     break;
                 case GiftModel::TYPE_MENU:
                     $newAction = $_POST['OpenReplayModel']['action'];
                     if ($oldAction != $newAction) {
                         //                            //检测menu action是否被其他使用
                         //                            $actionExist = MenuactionModel::model()->find('wechatId=:wechatId and action=:action', array(':wechatId' => $this->wechatInfo->id, ':action' => $newAction));
                         //                            if ($actionExist) {
                         //                                ShowMessage::error('此菜单动作已经被使用了');
                         //                            }
                         //                            $actionModel = MenuactionModel::model()->find('type=:type and action=:action', array(':type' => OpenReplayModel::OPEN_TYPE, ':action' => $oldAction));
                         //                            $actionModel->action = $newAction;
                         //                            $actionModel->save();
                         if ($oldAction) {
                             $actionModel = MenuactionModel::model()->find('menuId=:menuId', array(':menuId' => $oldAction));
                             $actionModel->responseId = 0;
                             $actionModel->save();
                             //原来菜单responseId置为0
                         }
                         $newActionModel = MenuactionModel::model()->find('menuId=:menuId', array(':menuId' => $newAction));
                         $newActionModel->responseId = $model->id;
                         $newActionModel->save();
                     }
                     break;
             }
             $model->save();
             ShowMessage::success('编辑成功', Yii::app()->createUrl('open/replay', array('type' => $model->type)));
         }
     }
     Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     $this->render('replayUpdate', array('model' => $model, 'type' => $model->type, 'wechatId' => $this->wechatInfo->id, 'responseId' => $id, 'open' => $open, 'menuList' => $menuList));
 }
Пример #7
0
 public function actionCreate()
 {
     $menuList = array();
     $type = Yii::app()->request->getParam('type');
     $type = $type ? $type : Globals::TYPE_KEYWORDS;
     if ($type == Globals::TYPE_MENU) {
         //取menu的下拉列表
         $menuList = MenuModel::model()->getMenuDropDownList($this->wechatInfo->id, Globals::TYPE_GIFT);
     }
     $model = new WheelModel();
     if (isset($_POST['WheelModel'])) {
         $model->type = $type;
         $model->attributes = $_POST['WheelModel'];
         $model->wechatId = $this->wechatInfo->id;
         if ($_FILES) {
             $file = array('name' => $_FILES['WheelModel']['name']['backgroundPic'], 'type' => $_FILES['WheelModel']['type']['backgroundPic'], 'tmp_name' => $_FILES['WheelModel']['tmp_name']['backgroundPic'], 'error' => $_FILES['WheelModel']['error']['backgroundPic'], 'size' => $_FILES['WheelModel']['size']['backgroundPic']);
             $uploadPath = Yii::app()->params['scratchPath'] . "/" . $this->wechatInfo->id . '/';
             $fileUpload = new FileUpload($uploadPath, $file);
             $fileUpload->move();
             $result = $fileUpload->getMessages();
             if (isset($result['name'])) {
                 $backgroundPic = $result['name'];
             } else {
                 ShowMessage::Error(current($result));
             }
             $file = array('name' => $_FILES['WheelModel']['name']['button'], 'type' => $_FILES['WheelModel']['type']['button'], 'tmp_name' => $_FILES['WheelModel']['tmp_name']['button'], 'error' => $_FILES['WheelModel']['error']['button'], 'size' => $_FILES['WheelModel']['size']['button']);
             $uploadPath = Yii::app()->params['scratchPath'] . "/" . $this->wechatInfo->id . '/';
             $fileUpload = new FileUpload($uploadPath, $file);
             $fileUpload->move();
             $result = $fileUpload->getMessages();
             if (isset($result['name'])) {
                 $button = $result['name'];
             } else {
                 ShowMessage::Error(current($result));
             }
         }
         //奖项处理
         for ($i = 1; $i <= 4; $i++) {
             ${'award' . $i} = $_POST['award' . $i];
             ${'isentity' . $i} = $_POST['isentity' . $i] ? $_POST['isentity' . $i] : 0;
             $awards[$i] = array('name' => ${'award' . $i}, 'isentity' => ${'isentity' . $i});
         }
         $model->awards = serialize($awards);
         $model->backgroundPic = $backgroundPic;
         $model->button = $button;
         $model->created_at = date('Y-m-d H:i:s');
         //$model->ispaward = '';//$_POST['WheelModel']['ispaward'];
         if ($model->validate()) {
             $model->save();
             switch ($type) {
                 case Globals::TYPE_KEYWORDS:
                     $keywords = $_POST['WheelModel']['keywords'];
                     $isAccurate = $_POST['WheelModel']['isAccurate'];
                     $keywordsArray = explode(',', $keywords);
                     foreach ($keywordsArray as $k) {
                         $keywordsModel = new KeywordsModel();
                         $keywordsModel->responseId = $model->id;
                         $keywordsModel->type = Globals::TYPE_SCRATCH;
                         $keywordsModel->isAccurate = $isAccurate;
                         $keywordsModel->name = $k;
                         $keywordsModel->wechatId = $this->wechatInfo->id;
                         $keywordsModel->save();
                     }
                     break;
                 case Globals::TYPE_MENU:
                     $menuId = $_POST['WheelModel']['action'];
                     $menuActionModel = MenuactionModel::model()->find('menuId=:menuId', array(':menuId' => $menuId));
                     $menuActionModel->responseId = $model->id;
                     $menuActionModel->save();
                     break;
             }
             ShowMessage::success('添加成功', Yii::app()->createUrl('scratch', array('type' => $type)));
         }
     }
     Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     $this->render('create', array('model' => $model, 'type' => $type ? $type : GiftModel::TYPE_KEYWORDS, 'wechatId' => $this->wechatInfo->id, 'responseId' => 0, 'menuList' => $menuList));
 }
Пример #8
0
 public function actionUpdate($id)
 {
     $model = MenuModel::model()->with('menu_action')->findByPk($id);
     if ($_POST) {
         $status = 1;
         $msg = '更新成功';
         $model->name = $_POST['name'];
         $model->type = $_POST['type'];
         if (!$model->parentId && $_POST['parentId']) {
             $status = -1;
             $msg = '此菜单含有子菜单,不能做此修改';
         } else {
             $model->parentId = $_POST['parentId'] ? $_POST['parentId'] : 0;
             $modelAction = MenuactionModel::model()->findByPk($model->menu_action->id);
             $modelAction->action = $_POST['type'] == Globals::TYPE_URL ? $_POST['url'] : $_POST['action'];
             //responseId 响应ID
             if ($_POST['type'] == Globals::TYPE_KEYWORDS || $_POST['type'] == Globals::TYPE_GIFT) {
                 //如果是关键词则需要找到对应的responseId
                 $keyword = KeywordsModel::model()->find("wechatId=:wechatId and name like concat('%',:name,'%') order by id desc", array(':wechatId' => $this->wechatInfo->id, ':name' => $_POST['action']));
                 if (!empty($keyword)) {
                     $modelAction->responseId = $keyword->responseId;
                 } else {
                     $msg = '不存在该关键词';
                 }
             }
             if ($model->validate() && $modelAction->validate()) {
                 $modelAction->save();
                 $model->save();
             } else {
                 $status = -1;
                 $error = $model->getErrors();
                 if ($error) {
                     foreach ($error as $e) {
                         $msg .= $e[0];
                     }
                 }
             }
         }
         echo json_encode(array('status' => $status, 'msg' => $msg));
     } else {
         $result['name'] = $model->name;
         $result['type'] = $model->type;
         $result['url'] = $result['action'] = isset($model->menu_action->action) ? $model->menu_action->action : '';
         $result['actionId'] = isset($model->menu_action->id) ? $model->menu_action->id : 0;
         echo json_encode($result);
     }
 }
Пример #9
0
 public function actionGiftUpdate($id)
 {
     $menuList = array();
     $keyword = $common = '';
     $model = GiftModel::model()->findByPk($id);
     switch ($model->type) {
         //获取关联表数据
         case GiftModel::TYPE_KEYWORDS:
             $keywords = KeywordsModel::model()->findAll('type=:type and responseId=:responseId', array(':type' => GiftModel::GIFT_TYPE, ':responseId' => $id));
             foreach ($keywords as $k) {
                 $oldKeywords[] = $k->name;
                 $oldIsAccurate = $k->isAccurate;
                 $isAccurate = $k->isAccurate;
                 $keyword .= $common . $k->name;
                 $common = ',';
             }
             $model->keywords = $keyword;
             $model->isAccurate = $isAccurate;
             break;
         case GiftModel::TYPE_MENU:
             $action = MenuactionModel::model()->with('action_menu')->find('action_menu.wechatId=:wechatId and responseId=:responseId', array(':wechatId' => $this->wechatInfo->id, ':responseId' => $id));
             $oldAction = $model->action = isset($action->menuId) ? $action->menuId : 0;
             //取menu的下拉列表
             $menuList = MenuModel::model()->getMenuDropDownList($this->wechatInfo->id, Globals::TYPE_GIFT);
             break;
     }
     if (isset($_POST['GiftModel'])) {
         $model->attributes = $_POST['GiftModel'];
         if ($model->validate()) {
             switch ($model->type) {
                 //根据活动类型更新不同关联表
                 case GiftModel::TYPE_KEYWORDS:
                     $keywordsArray = explode(',', $_POST['GiftModel']['keywords']);
                     $keywordsAdd = array_unique(array_merge($oldKeywords, $keywordsArray));
                     $arrayDel = array_diff($keywordsAdd, $keywordsArray);
                     //删除了的关键字
                     $arrayAdd = array_diff($keywordsAdd, $oldKeywords);
                     //添加的关键字
                     $arrayAlive = array_diff($oldKeywords, $arrayAdd);
                     //没改变的
                     $newIsAccurate = $_POST['GiftModel']['isAccurate'];
                     if ($isAccurate != $newIsAccurate && $arrayAlive) {
                         //是否精准匹配改变了
                         foreach ($arrayAlive as $name) {
                             $keywordsModel = KeywordsModel::model()->find('name=:name', array(':name' => $name));
                             $keywordsModel->isAccurate = $newIsAccurate;
                             $keywordsModel->save();
                         }
                     }
                     foreach ($arrayAdd as $k) {
                         //新加关键词
                         $keywordsModel = new KeywordsModel();
                         $keywordsModel->responseId = $id;
                         $keywordsModel->name = $k;
                         $keywordsModel->isAccurate = $newIsAccurate;
                         $keywordsModel->wechatId = $this->wechatInfo->id;
                         $keywordsModel->type = GiftModel::GIFT_TYPE;
                         $keywordsModel->save();
                     }
                     foreach ($arrayDel as $k) {
                         //删除的关键词
                         $keywordsModel = KeywordsModel::model()->find('responseId=:responseId and name=:name', array(':name' => $k, ':responseId' => $id));
                         $keywordsModel->delete();
                     }
                     if ($oldIsAccurate != $isAccurate) {
                         KeywordsModel::model()->updateAll(array('isAccurate' => $isAccurate), 'responseId=:responseId', array(':responseId' => $id));
                     }
                     //更新是否精准匹配字段
                     break;
                 case GiftModel::TYPE_MENU:
                     $newAction = $_POST['GiftModel']['action'];
                     if ($oldAction != $newAction) {
                         //检测menu action是否被其他使用
                         //                            $actionExist = MenuactionModel::model()->find('wechatId=:wechatId and action=:action', array(':wechatId' => $this->wechatInfo->id, ':action' => $newAction));
                         //                            if ($actionExist) {
                         //                                ShowMessage::error('此菜单动作已经被使用了');
                         //                            }
                         if ($oldAction) {
                             $actionModel = MenuactionModel::model()->find('menuId=:menuId', array(':menuId' => $oldAction));
                             $actionModel->responseId = 0;
                             $actionModel->save();
                             //原来菜单responseId置为0
                         }
                         $newActionModel = MenuactionModel::model()->find('menuId=:menuId', array(':menuId' => $newAction));
                         $newActionModel->responseId = $model->id;
                         $newActionModel->save();
                     }
                     break;
             }
             $model->save();
             //更新code表,防止礼包时礼包码表未创建成功问题
             $result = GiftModel::model()->createCodeTable($this->wechatInfo->id);
             if ($result == GiftModel::TABLE_CREATE_FAILED) {
                 ShowMessage::error('数据异常,请再次编辑一下');
             } else {
                 ShowMessage::success('编辑成功', Yii::app()->createUrl('market/gift', array('type' => $model->type)));
             }
         }
     }
     Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     $this->render('giftUpdate', array('model' => $model, 'type' => $model->type, 'wechatId' => $this->wechatInfo->id, 'responseId' => $id, 'menuList' => $menuList));
 }