wechat = WechatModel::detail(); View::assign('wechat', $this->wechat); } /** * 公众号信息 */ public function index() { $wechat = $this->wechat; $url = ''; if(!$wechat or $wechat['status']['value'] == 0){ $wx = new Driver; $url = $wx->authUrl(0,1); } return View::fetch('index', compact('url')); } /** * 被关注回复设置 */ public function subscribe() { return $this->updateEvent('subscribe'); } /** * 公众号菜单设置 */ public function menus() { return $this->updateEvent('menus'); } /** * 更新设置事件 */ private function updateEvent($key) { if (!$this->request->isAjax()) { $model = SettingModel::getItem($key,0); if($key == 'menus'){ $model = json_encode($model); } return View::fetch($key, compact('model')); } $model = new SettingModel; if ($model->edit($key,$this->postData('data'))){ return $this->renderSuccess('更新成功'); } $error = $model->getError() ?: '更新失败'; return $this->renderError($error); } }