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(); }
public function getMenuDropDownList($wechatId, $type) { $result = array(); $menu = MenuactionModel::model()->getTree($wechatId); foreach ($menu as $m) { if ($m['child']) { foreach ($m['child'] as $ch) { if ($ch['type'] == $type) { $result[$ch['id']] = $ch['name']; } } } elseif ($m['type'] == $type) { $result[$m['id']] = $m['name']; } } return $result; }
public function actionReplayDelete($id) { $model = OpenReplayModel::model()->findByPk($id); //删除关键字或者menu action switch ($model->type) { case GiftModel::TYPE_KEYWORDS: KeywordsModel::model()->deleteAll('responseId=:responseId and type=:type', array(':responseId' => $id, ':type' => OpenReplayModel::OPEN_TYPE)); break; case GiftModel::TYPE_MENU: MenuactionModel::model()->deleteAll('responseId=:responseId and type=:type', array(':responseId' => $id, ':type' => OpenReplayModel::OPEN_TYPE)); break; } $model->delete(); ShowMessage::success('删除成功', Yii::app()->createUrl('open/replay')); }
public function actionDelete($id) { $model = WheelModel::model()->findByPk($id); //删除关键字或者menu action switch ($model->type) { case GiftModel::TYPE_KEYWORDS: KeywordsModel::model()->deleteAll('responseId=:responseId and type=:type', array(':responseId' => $id, ':type' => Globals::TYPE_SCRATCH)); break; case GiftModel::TYPE_MENU: $menuactionModel = MenuactionModel::model()->find('responseId=:responseId', array('responseId' => $model->id)); $menuactionModel->responseId = 0; $menuactionModel->save(); break; } $model->delete(); ShowMessage::success('删除成功', Yii::app()->createUrl('scratch')); }
private function menuResponse($key, $request) { $menuInfo = MenuactionModel::model()->with('action_menu')->find('action=:action', array(':action' => $key)); if ($menuInfo) { $responseId = $menuInfo->responseId; switch ($menuInfo->action_menu->type) { case Globals::TYPE_TEXT: $response = $this->_getTextReplay($responseId, $request->from_user_name); break; case Globals::TYPE_IMAGE_TEXT: $response = $this->_getImageTextReplay($responseId, Globals::TYPE_MENU); break; case Globals::TYPE_GIFT: //礼包领取 $response = $this->_getGiftReplay($responseId, $request->from_user_name); break; case Globals::TYPE_OPEN: //转接 $response = $this->_getOpenReplay($responseId); return $response; break; case Globals::TYPE_SCRATCH: //刮刮乐 $response = $this->_getScratch($responseId, $request->from_user_name, 1); break; } } $xml = $response->_to_xml($request); return $xml; }
public function actionGetDropDownList() { $option = ''; $parentId = Yii::app()->request->getParam('parentId'); $menu = MenuactionModel::model()->getTree($this->wechatInfo->id); if (count($menu) < 3 || isset($_GET['parentId'])) { $option = '<option value="0">一级菜单</option>'; } if ($menu) { foreach ($menu as $m) { //如果子节点没有或者数量小于等于5则显示 if (!(isset($m['child']) && count($m['child']) >= 5)) { $select = $m['id'] == $parentId ? 'selected="selected"' : ''; $option .= '<option value="' . $m['id'] . '" ' . $select . '>' . $m['name'] . '</option>'; } } } echo $option; }
public function actionGiftDelete($id) { $model = GiftModel::model()->findByPk($id); /* $codeTable = sprintf(GiftModel::CREATE_CODE_TABLE_NAME, $this->wechatInfo->id); GiftCodeModel::model($codeTable)->deleteAll('giftId=:giftId', array(':giftId' => $id));*/ //删除关键字或者menu action switch ($model->type) { case GiftModel::TYPE_KEYWORDS: KeywordsModel::model()->deleteAll('responseId=:responseId and type=:type', array(':responseId' => $id, ':type' => GiftModel::GIFT_TYPE)); break; case GiftModel::TYPE_MENU: $menuactionModel = MenuactionModel::model()->find('responseId=:responseId', array('responseId' => $model->id)); $menuactionModel->responseId = 0; $menuactionModel->save(); break; } $model->delete(); ShowMessage::success('删除成功', Yii::app()->createUrl('market/gift')); }
/** * 更新菜单 */ public function actionUpdateMenu($wechatId) { $status = -1; $token = $this->_getToken($wechatId); $tokenValue = $token['tokenValue']; if ($tokenValue) { //更新菜单 $menu = MenuactionModel::model()->getTree($wechatId); if ($menu) { foreach ($menu as $m) { if (isset($m['child']) && $m['child']) { foreach ($m['child'] as $ch) { if ($ch['type'] == Globals::TYPE_URL) { $subV = array('type' => 'view', 'url' => $ch['action']); } else { $subV = array('type' => 'click', 'key' => $ch['action']); } $subV['name'] = urlencode($ch['name']); $sub[] = $subV; } $t = array('name' => urlencode($m['name']), 'sub_button' => $sub); unset($sub); } else { if ($m['type'] == Globals::TYPE_URL) { $urlInfo = UrlModel::model()->findByPk($m['responseId']); $t = array('type' => 'view', 'url' => $urlInfo->url); } else { $t = array('type' => 'click', 'key' => $m['action']); } $t['name'] = urlencode($m['name']); } $buttonValue['button'][] = $t; } $menuValue = stripslashes(urldecode(json_encode($buttonValue))); $url = sprintf(Globals::MENU_UPDATE_URL, $tokenValue); $result = HttpRequest::sendHttpRequest($url, $menuValue, 'POST'); $resultData = json_decode($result['content']); $status = $resultData->errcode == Globals::WECHAT_RESPONSE_OK ? 1 : -1; $msg = $resultData->errcode == Globals::WECHAT_RESPONSE_OK ? '' : Globals::$wechatErrorCode[$resultData->errcode]; if ($status == 1) { $settingMenuModel = SettingModel::model()->find("wechatId = :wechatId and `key`=:key", array(':wechatId' => $wechatId, ':key' => Globals::SETTING_KEY_MENU)); if (!$settingMenuModel) { $settingMenuModel = new SettingModel(); $settingMenuModel->key = Globals::SETTING_KEY_MENU; $settingMenuModel->wechatId = $wechatId; } $settingMenuModel->created_at = time(); $settingMenuModel->value = $menuValue; $settingMenuModel->save(); } } else { $msg = '菜单为空'; } } else { $msg = '获取token异常'; } echo json_encode(array('status' => $status, 'msg' => $msg)); }