params['hdDomain']; self::menuGenerate($style, $merchant, $url); } elseif ($style == dict::getDict('ptStyle', 'ghs')) { $merchant = WxOpenClass::getGhsWxInfo(); $url = Yii::$app->params['ghsDomain']; self::menuGenerate($style, $merchant, $url); } elseif ($style == dict::getDict('ptStyle', 'mall')) { $merchant = WxOpenClass::getMallWxInfo(); $url = Yii::$app->params['mallDomain']; self::menuGenerate($style, $merchant, $url); } } } public static function menuGenerate($style, $merchant, $url) { if ($style == dict::getDict('ptStyle', 'mall')) { $button = [ ["type" => 'miniprogram', "name" => "最近访问", "appid" => $merchant['miniAppId'], "pagepath" => "pages/home/recent", "url" => $url,], ]; } else { $button = [ ["type" => 'miniprogram', "name" => "官网", "appid" => $merchant['miniAppId'], "pagepath" => "pagesClient/official/index", "url" => $url,], ["type" => 'miniprogram', "name" => "后台", "appid" => $merchant['miniAppId'], "pagepath" => "admin/home/workbench", "url" => $url,], ]; } foreach ($button as $key => $val) { unset($button[$key]['keyName']); } $menu['button'] = $button; $info = wxUtil::userMenuToWeiXin($menu, $merchant, $style); $info = json_decode($info, true); print_r($info); } public static function getByMenuKey($menuKey) { return xhWxMenu::find()->where(['menuKey' => $menuKey])->asArray()->one(); } public static function getMenuList($sjId) { $list = self::getAllMenu($sjId); return $list; } /** * 取出商家所有菜单 */ public static function getAllMenu($sjId, $getKeyName = false) { $list = self::getMenuById(0, $sjId, $getKeyName); return $list; } /** * 根据菜单id取子菜单 * $getKeyName false 默认不带键名 true 返回带键名的 */ public static function getMenuById($parentId, $sjId, $getKeyName = false) { $condition = ['parentId' => $parentId, 'sjId' => $sjId]; $wxMenu = xhWxMenu::getAllByCondition($condition, 'menuOrder asc'); $data = []; if (empty($wxMenu)) { return $data; } foreach ($wxMenu as $k => $v) { $id = $v['id']; $cate = [ 'id' => $id, 'name' => $v['name'], 'menuKey' => $v['menuKey'], 'menuOption' => $v['menuOption'], 'parentId' => $v['parentId'], 'sjId' => $v['sjId'], 'replyType' => $v['replyType'], 'replyUrl' => $v['replyUrl'], 'replyText' => $v['replyText'], 'replyNews' => $v['replyNews'], 'replyMultiNews' => $v['replyMultiNews'], 'hasSonMenu' => $v['hasSonMenu'], 'menuOrder' => $v['menuOrder'], 'createTime' => $v['createTime'], 'updateTime' => $v['updateTime'], 'child' => self::getMenuById($id, $sjId, $getKeyName), ]; if ($getKeyName) { $data[$id] = $cate; } else { $data[] = $cate; } } return $data; } public static function delMenuList($sjId) { xhWxMenu::deleteByCondition(['sjId' => $sjId]); } public static function add($data) { return xhWxMenu::add($data); } public static function getFormatData($wxMenuContent, $wxMenuOption, $merchant) { $addData = []; $wxMenuOptionList = dict::getDict('wxMenuOption'); $commonUseUrl = dict::getDict('commonUseUrl'); switch ($wxMenuOption) { case $wxMenuOptionList['redirectToCommonUseUrl']://跳转到常用链接 foreach ($commonUseUrl as $comKey => $comVal) { if ($comKey == $wxMenuContent) { $addData['replyUrl'] = Yii::$app->params['frontUrl'] . $comVal['url'] . '?account=' . $merchant['id']; $addData['targetId'] = $wxMenuContent; } } break; case $wxMenuOptionList['redirectToCustomUrl']://跳转到自定义网址 $addData['replyUrl'] = urldecode($wxMenuContent); break; case $wxMenuOptionList['showText']://回复文字 $addData['replyText'] = $wxMenuContent; break; default: } return $addData; } }