Menu.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\wechat\shop\controller;
  11. use addon\wechat\model\Menu as MenuModel;
  12. use addon\wechat\model\Wechat as WechatModel;
  13. /**
  14. * 微信菜单控制器
  15. */
  16. class Menu extends BaseWechat
  17. {
  18. /**
  19. * 微信自定义菜单配置
  20. */
  21. public function menu()
  22. {
  23. if (request()->isAjax()) {
  24. $menu_model = new MenuModel();
  25. $menu_info = $menu_model->getWechatMenuConfig($this->site_id);
  26. return $menu_info;
  27. } else {
  28. return $this->fetch('menu/menu', [], $this->replace);
  29. }
  30. }
  31. /**
  32. * 修改微信自定义菜单
  33. */
  34. public function edit()
  35. {
  36. if (request()->isAjax()) {
  37. $menu_value = input('value', '');
  38. $menu_json = input('json_data', '');
  39. $menu_model = new MenuModel();
  40. $data = json_decode($menu_value, true);
  41. $res = $menu_model->setWechatMenuConfig($data, $this->site_id);
  42. if ($res['code'] != 0) {
  43. return $res;
  44. }
  45. $res = $this->sendWeixinMenu($menu_json);
  46. return $res;
  47. }
  48. }
  49. /**
  50. * 公众号同步更新微信菜单
  51. */
  52. public function sendWeixinMenu($menu_json)
  53. {
  54. $wechat_model = new WechatModel($this->site_id);
  55. $menu_arr = json_decode($menu_json, true);
  56. $res = $wechat_model->menu($menu_arr['button']);
  57. return $res;
  58. }
  59. }