Menus.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\wechat;
  12. use app\admin\controller\AuthController;
  13. use service\WechatService;
  14. use think\Cache;
  15. use think\Db;
  16. use think\Request;
  17. /**
  18. * 微信菜单 控制器
  19. * Class Menus
  20. * @package app\admin\controller\wechat
  21. */
  22. class Menus extends AuthController
  23. {
  24. public function index()
  25. {
  26. $menus = Db::name('cache')->where('key', 'wechat_menus')->value('result');
  27. $menus = $menus ?: '[]';
  28. $this->assign('menus', $menus);
  29. return $this->fetch();
  30. }
  31. public function save(Request $request)
  32. {
  33. $buttons = $request->post('button/a', []);
  34. if (!count($buttons)) return $this->failed('请添加至少一个按钮');
  35. try {
  36. WechatService::menuService()->add($buttons);
  37. Db::name('cache')->insert(['key' => 'wechat_menus', 'result' => json_encode($buttons), 'add_time' => time()], true);
  38. return $this->successful('修改成功!');
  39. } catch (\Exception $e) {
  40. return $this->failed($e->getMessage());
  41. }
  42. }
  43. }