Menu.php
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace app\admin\controller\wechat;
use app\common\controller\Backend;
use app\common\model\Configvalue;
use app\common\model\WechatResponse;
use EasyWeChat\Foundation\Application;
use think\Exception;
/**
* 菜单管理
*
* @icon fa fa-list-alt
*/
class Menu extends Backend
{
protected $wechatcfg = NULL;
public function _initialize()
{
parent::_initialize();
$this->wechatcfg = Configvalue::get('wechat');
}
/**
* 查看
*/
public function index()
{
$responselist = array();
$all = WechatResponse::all();
foreach ($all as $k => $v)
{
$responselist[$v['eventkey']] = $v['title'];
}
$this->view->assign('responselist', $responselist);
$this->view->assign('menu', $this->wechatcfg->content['menu']);
return $this->view->fetch();
}
/**
* 修改
*/
public function edit($ids = NULL)
{
$menu = $this->request->post("menu");
$menu = (array) json_decode($menu, TRUE);
$content = $this->wechatcfg->content;
$content['menu'] = $menu;
$this->wechatcfg->content = $content;
$this->wechatcfg->save();
$this->code = 1;
return;
}
/**
* 同步
*/
public function sync($ids = NULL)
{
$this->code = -1;
$app = new Application(Config::get('wechat')->toArray());
try
{
$ret = $app->menu->add($this->wechatcfg->content['menu']);
if ($ret->errcode == 0)
{
$this->code = 1;
}
else
{
$this->content = $ret->errmsg;
}
}
catch (Exception $e)
{
$this->content = $e->getMessage();
}
return;
}
}