wechat = WechatModel::detail($this->applet_id); 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($this->applet_id,1); } return View::fetch('../../admin/view/wechat/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,$this->applet_id); if($key == 'menus'){ $model = json_encode($model); } return View::fetch('../../admin/view/wechat/' . $key, compact('model')); } $model = new SettingModel; if ($model->edit($key,$this->postData('data'),$this->applet_id)){ return $this->renderSuccess('更新成功'); } $error = $model->getError() ?: '更新失败'; return $this->renderError($error); } }