where(array('mer_id'=> $this->merchantId,'type' => 2))->value('result'); $menus = $menus ?: '[]'; $this->assign('menus', $menus); return $this->fetch(); } public function save(Request $request) { $buttons = $request->post('button/a', []); if (!count($buttons)) return $this->failed('请添加至少一个按钮'); try { $menus = Db::name('cache_merchant')->where(array('mer_id'=> $this->merchantId,'type' => 2))->find(); if($menus){ WechatAgentService::menuService($this->merchantId)->add($buttons); Db::name('cache_merchant')->where('mer_id',$this->merchantId)->update(['key' => 'wechat_menus', 'result' => json_encode($buttons), 'add_time' => time()], true); }else{ Db::name('cache_merchant')->insert(['mer_id'=>$this->merchantId,'type' => 2,'key' => 'wechat_menus', 'result' => json_encode($buttons), 'add_time' => time()], true); } return $this->successful('修改成功!'); } catch (\Exception $e) { return $this->failed($e->getMessage()); } } }