public function actionGiftCreate() { $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 GiftModel(); if (isset($_POST['GiftModel'])) { $model->type = $type; $model->attributes = $_POST['GiftModel']; $model->wechatId = $this->wechatInfo->id; if ($model->validate()) { $model->save(); //创建礼包码表 $result = GiftModel::model()->createCodeTable($this->wechatInfo->id); switch ($type) { case Globals::TYPE_KEYWORDS: $keywords = $_POST['GiftModel']['keywords']; $isAccurate = $_POST['GiftModel']['isAccurate']; $keywordsArray = explode(',', $keywords); foreach ($keywordsArray as $k) { $keywordsModel = new KeywordsModel(); $keywordsModel->responseId = $model->id; $keywordsModel->type = GiftModel::GIFT_TYPE; $keywordsModel->isAccurate = $isAccurate; $keywordsModel->name = $k; $keywordsModel->wechatId = $this->wechatInfo->id; $keywordsModel->save(); } break; case Globals::TYPE_MENU: $menuId = $_POST['GiftModel']['action']; $menuActionModel = MenuactionModel::model()->find('menuId=:menuId', array(':menuId' => $menuId)); $menuActionModel->responseId = $model->id; $menuActionModel->save(); break; } if ($result == GiftModel::TABLE_CREATE_FAILED) { ShowMessage::error('创建异常,请重新编辑此信息', Yii::app()->createUrl('market/gift', array('type' => $type))); } else { ShowMessage::success('添加成功', Yii::app()->createUrl('market/gift', array('type' => $type))); } } } Yii::app()->clientScript->scriptMap['jquery.js'] = false; $this->render('giftCreate', array('model' => $model, 'type' => $type ? $type : GiftModel::TYPE_KEYWORDS, 'wechatId' => $this->wechatInfo->id, 'responseId' => 0, 'menuList' => $menuList)); }
}); $app->post($basePath . '/lanterns/create', function (Request $request) use($app, $LanternsController, $LanternModel) { $params = $request->query->all(); $errorMessage = $LanternModel->validate($params, "create"); if ($errorMessage) { return Utils::formatErrorMessage(ERROR_BAD_MODEL, $errorMessage); } else { return $LanternsController->create($params); } }); /* * Gifts */ $app->get($basePath . '/gifts', function (Request $request) use($app, $GiftsController, $GiftModel) { $params = $request->query->all(); $errorMessage = $GiftModel->validate($params, "index"); if ($errorMessage) { return Utils::formatErrorMessage(ERROR_BAD_MODEL, $errorMessage); } else { return $GiftsController->index($params); } }); $app->post($basePath . '/gifts/create', function (Request $request) use($app, $GiftsController, $GiftModel) { $params = $request->query->all(); $errorMessage = $GiftModel->validate($params, "create"); if ($errorMessage) { return Utils::formatErrorMessage(ERROR_BAD_MODEL, $errorMessage); } else { return $GiftsController->create($params); } });