/** * 自定义菜单 * @return [type] */ public function menu() { if (IS_AJAX) { // 同步菜单 self::initWechat(); $res = Menu::get(); if ($res) { Db::query('TRUNCATE ' . Config::get('database.prefix') . 'wechat_menu'); $model = Db::name('WechatMenu'); foreach ($res as $key => $value) { $data = ['pid' => 0, 'sort' => $key, 'type' => isset($value['type']) ? $value['type'] : '', 'name' => $value['name'], 'keyword' => isset($value['key']) ? $value['key'] : '', 'url' => isset($value['url']) ? $value['url'] : '', 'media_id' => isset($value['media_id']) ? $value['media_id'] : '', 'create_time' => NOW_TIME, 'update_time' => 0]; $id = $model->insert($data, false, true); if (!empty($value['sub_button'])) { foreach ($value['sub_button'] as $subKey => $subValue) { $data = ['pid' => $id, 'sort' => $subKey, 'type' => $subValue['type'], 'name' => $subValue['name'], 'keyword' => isset($subValue['key']) ? $subValue['key'] : '', 'url' => isset($subValue['url']) ? $subValue['url'] : '', 'media_id' => isset($subValue['media_id']) ? $subValue['media_id'] : '', 'create_time' => NOW_TIME, 'update_time' => 0]; $model->insert($data, false, true); } } } return $this->success(); } else { return $this->error(Wechat::error()); } } else { $config = Config::get('wechat_config'); $this->assign('wechat', $config); $list = Db::name('WechatMenu')->order('sort asc,id asc')->select(); $list = list_to_tree($list); $this->assign('list', $list); // 获取首次关注时回复信息 $firstMsg = Db::name('WechatCommon')->where('type', 'first')->find(); $this->assign('firstMsg', $firstMsg); return $this->fetch(); } }