public function actionLv() { $model = new VipPaymentModel(); $_priceList = PriceList::returnPriceList(); foreach ($_priceList as $l => $p) { $priceList[$p] = $l; } for ($i = 1; $i <= 12; $i++) { $mouth[$i] = $i . '个月'; } if (isset($_POST['VipPaymentModel'])) { $dateTime = time(); $model->attributes = $_POST['VipPaymentModel']; $model->uid = Yii::app()->session['userInfo']['uid']; $model->username = Yii::app()->session['userInfo']['username']; $model->created_at = $dateTime; $model->orderId = $this->_createOrderSns(); if ($model->validate()) { //校验价格 $price = $model->payCode; $count = $model->count; $amount = $price * $count; if ($amount != $model->amount) { ShowMessage::error('数据有误!'); } $model->payCode = $priceList[$model->payCode]; $model->save(); //ShowMessage::success('添加成功!',Yii::app()->createUrl('vip/index')); } } $this->render('lv', array('model' => $model, 'priceList' => $priceList, 'mouth' => $mouth)); }
protected function _getWechatInfo($id) { $wechatInfo = WechatModel::model()->findByPk($id); if (!$wechatInfo || $wechatInfo->uid != Yii::app()->session['userInfo']['uid']) { ShowMessage::error('公众帐号不存在!'); } return $wechatInfo; }
public function actionDelete($id) { $model = OpenPlatformModel::model()->findByPk($id); if ($model->wechatId != $this->wechatInfo->id) { return; } //检查是否已接入关键字 $openReplayInfo = OpenReplayModel::model()->find('openId=:openId', array(':openId' => $model->id)); if ($openReplayInfo) { ShowMessage::error('请先删除转接回复'); } $model->delete(); ShowMessage::success('删除成功', Yii::app()->createUlr('open/idex')); }
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)); }