|
@@ -18,10 +18,7 @@ class AdminIndexController extends PluginBaseController |
|
@@ -18,10 +18,7 @@ class AdminIndexController extends PluginBaseController |
18
|
function _initialize()
|
18
|
function _initialize()
|
19
|
{
|
19
|
{
|
20
|
parent::_initialize();
|
20
|
parent::_initialize();
|
21
|
- $this->options= [
|
|
|
22
|
- 'app_id' => config('wechat_config.app_id'),
|
|
|
23
|
- 'secret' => config('wechat_config.secret'),
|
|
|
24
|
- ];
|
21
|
+ $this->options= config('wechat_config');
|
25
|
}
|
22
|
}
|
26
|
|
23
|
|
27
|
/**
|
24
|
/**
|
|
@@ -41,17 +38,83 @@ class AdminIndexController extends PluginBaseController |
|
@@ -41,17 +38,83 @@ class AdminIndexController extends PluginBaseController |
41
|
|
38
|
|
42
|
public function index()
|
39
|
public function index()
|
43
|
{
|
40
|
{
|
44
|
-// $app = new Application($this->options);
|
|
|
45
|
-// $menu = $app->menu;
|
|
|
46
|
-// $menus = $menu->all();
|
|
|
47
|
-// var_dump($menus);
|
|
|
48
|
-
|
|
|
49
|
$list=Db::name('wechat_menu')->select()->toArray();
|
41
|
$list=Db::name('wechat_menu')->select()->toArray();
|
50
|
$list=$this->arr2tree($list, 'index', 'parent_id');
|
42
|
$list=$this->arr2tree($list, 'index', 'parent_id');
|
51
|
$this->assign('list',$list);
|
43
|
$this->assign('list',$list);
|
|
|
44
|
+
|
52
|
return $this->fetch('/admin_index');
|
45
|
return $this->fetch('/admin_index');
|
53
|
}
|
46
|
}
|
54
|
|
47
|
|
|
|
48
|
+ public function sync(){
|
|
|
49
|
+ $app = new Application($this->options);
|
|
|
50
|
+ $menu = $app->menu;
|
|
|
51
|
+ $menus = $menu->current();
|
|
|
52
|
+ if($menus->is_menu_open==1){
|
|
|
53
|
+ $selfmenu_info=$menus->selfmenu_info;
|
|
|
54
|
+ if(isset($selfmenu_info['button'])){
|
|
|
55
|
+ $data=[];
|
|
|
56
|
+ $i=1;
|
|
|
57
|
+ foreach ($selfmenu_info['button'] as $k=>$v){
|
|
|
58
|
+ if(isset($v['type'])&&$v['type']=='click' && isset($v['key'])){
|
|
|
59
|
+ $type='keys';
|
|
|
60
|
+ }elseif (isset($v['type'])&&$v['type']=='click' && isset($v['value'])){
|
|
|
61
|
+ $type='text';
|
|
|
62
|
+ }elseif(isset($v['type'])){
|
|
|
63
|
+ $type=$v['type'];
|
|
|
64
|
+ }else{
|
|
|
65
|
+ $type='text';
|
|
|
66
|
+ }
|
|
|
67
|
+ if(!empty($v['view'])){
|
|
|
68
|
+ $content=$v['view'];
|
|
|
69
|
+ }elseif (!empty($v['key'])){
|
|
|
70
|
+ $content=$v['key'];
|
|
|
71
|
+ }elseif (!empty($v['value'])){
|
|
|
72
|
+ $content=$v['value'];
|
|
|
73
|
+ }else{
|
|
|
74
|
+ $content='';
|
|
|
75
|
+ }
|
|
|
76
|
+ $data[]=['index'=>$i,'parent_id'=>0,'type'=>$type,'content'=>$content,'name'=>$v['name']];
|
|
|
77
|
+
|
|
|
78
|
+ if(!empty($v['sub_button']['list'])){
|
|
|
79
|
+ $j=1;
|
|
|
80
|
+ foreach ($v['sub_button']['list'] as $k1=>$v1){
|
|
|
81
|
+ if($v1['type']=='click' && isset($v1['key'])){
|
|
|
82
|
+ $type1='keys';
|
|
|
83
|
+ }elseif ($v1['type']=='click' && isset($v1['value'])){
|
|
|
84
|
+ $type1='text';
|
|
|
85
|
+ }else{
|
|
|
86
|
+ $type1=$v1['type'];
|
|
|
87
|
+ }
|
|
|
88
|
+ if(!empty($v1['url'])){
|
|
|
89
|
+ $content1=$v1['url'];
|
|
|
90
|
+ }elseif (!empty($v1['key'])){
|
|
|
91
|
+ $content1=$v1['key'];
|
|
|
92
|
+ }elseif (!empty($v1['value'])){
|
|
|
93
|
+ $content1=$v1['value'];
|
|
|
94
|
+ }else{
|
|
|
95
|
+ $content1='';
|
|
|
96
|
+ }
|
|
|
97
|
+ $data[]=['index'=>$i.$j,'parent_id'=>$i,'type'=>$type1,'content'=>$content1,'name'=>$v1['name']];
|
|
|
98
|
+ $j++;
|
|
|
99
|
+ }
|
|
|
100
|
+ }
|
|
|
101
|
+ $i++;
|
|
|
102
|
+ }
|
|
|
103
|
+ try {
|
|
|
104
|
+ Db::transaction(function () use ($data) {
|
|
|
105
|
+ Db::name('wechat_menu')->where('1=1')->delete();
|
|
|
106
|
+ Db::name('wechat_menu')->insertAll($data);
|
|
|
107
|
+ });
|
|
|
108
|
+ $this->_push();
|
|
|
109
|
+ } catch (\Exception $e) {
|
|
|
110
|
+ $this->error('微信菜单发布失败,请稍候再试!' . $e->getMessage());
|
|
|
111
|
+ }
|
|
|
112
|
+ $this->success('保存发布菜单成功!', '');
|
|
|
113
|
+ }
|
|
|
114
|
+ }
|
|
|
115
|
+ $this->error('微信菜单尚未启用!');
|
|
|
116
|
+ }
|
|
|
117
|
+
|
55
|
/**
|
118
|
/**
|
56
|
* 微信菜单编辑
|
119
|
* 微信菜单编辑
|
57
|
*/
|
120
|
*/
|
|
@@ -113,7 +176,7 @@ class AdminIndexController extends PluginBaseController |
|
@@ -113,7 +176,7 @@ class AdminIndexController extends PluginBaseController |
113
|
private function _push()
|
176
|
private function _push()
|
114
|
{
|
177
|
{
|
115
|
list($map, $field) = [['status' => '1'], 'id,index,parent_id,name,type,content'];
|
178
|
list($map, $field) = [['status' => '1'], 'id,index,parent_id,name,type,content'];
|
116
|
- $result = (array)Db::name('wechat_menu')->field($field)->where($map)->order('sort ASC,id ASC')->select();
|
179
|
+ $result =Db::name('wechat_menu')->field($field)->where($map)->order('sort ASC,id ASC')->select()->toArray();
|
117
|
foreach ($result as &$row) {
|
180
|
foreach ($result as &$row) {
|
118
|
empty($row['content']) && $row['content'] = uniqid();
|
181
|
empty($row['content']) && $row['content'] = uniqid();
|
119
|
if ($row['type'] === 'miniprogram') {
|
182
|
if ($row['type'] === 'miniprogram') {
|
|
@@ -124,35 +187,34 @@ class AdminIndexController extends PluginBaseController |
|
@@ -124,35 +187,34 @@ class AdminIndexController extends PluginBaseController |
124
|
} else {
|
187
|
} else {
|
125
|
$row['url'] = url($row['content'], '', true, true);
|
188
|
$row['url'] = url($row['content'], '', true, true);
|
126
|
}
|
189
|
}
|
127
|
- } elseif
|
|
|
128
|
- ($row['type'] === 'event') {
|
190
|
+ } elseif ($row['type'] === 'event') {
|
129
|
if (isset($this->menuType[$row['content']])) {
|
191
|
if (isset($this->menuType[$row['content']])) {
|
130
|
list($row['type'], $row['key']) = [$row['content'], "wechat_menu#id#{$row['id']}"];
|
192
|
list($row['type'], $row['key']) = [$row['content'], "wechat_menu#id#{$row['id']}"];
|
131
|
}
|
193
|
}
|
132
|
} elseif ($row['type'] === 'media_id') {
|
194
|
} elseif ($row['type'] === 'media_id') {
|
133
|
$row['media_id'] = $row['content'];
|
195
|
$row['media_id'] = $row['content'];
|
134
|
} else {
|
196
|
} else {
|
135
|
- $row['key'] = "wechat_menu#id#{$row['id']}";
|
197
|
+ $row['key'] = $row['content'];
|
136
|
!in_array($row['type'], $this->menuType) && $row['type'] = 'click';
|
198
|
!in_array($row['type'], $this->menuType) && $row['type'] = 'click';
|
137
|
}
|
199
|
}
|
138
|
unset($row['content']);
|
200
|
unset($row['content']);
|
139
|
}
|
201
|
}
|
140
|
$menus = $this->arr2tree($result, 'index', 'parent_id', 'sub_button');
|
202
|
$menus = $this->arr2tree($result, 'index', 'parent_id', 'sub_button');
|
141
|
//去除无效的字段
|
203
|
//去除无效的字段
|
142
|
- foreach ($menus as &$menu) {
|
|
|
143
|
- unset($menu['index'], $menu['parent_id'], $menu['id']);
|
|
|
144
|
- if (empty($menu['sub_button'])) {
|
204
|
+ foreach ($menus as &$item) {
|
|
|
205
|
+ unset($item['index'], $item['parent_id'], $item['id']);
|
|
|
206
|
+ if (empty($item['sub_button'])) {
|
145
|
continue;
|
207
|
continue;
|
|
|
208
|
+ }else{
|
|
|
209
|
+ unset($item['key']);
|
146
|
}
|
210
|
}
|
147
|
- foreach ($menu['sub_button'] as &$submenu) {
|
211
|
+ foreach ($item['sub_button'] as &$submenu) {
|
148
|
unset($submenu['index'], $submenu['parent_id'], $submenu['id']);
|
212
|
unset($submenu['index'], $submenu['parent_id'], $submenu['id']);
|
149
|
}
|
213
|
}
|
150
|
- unset($menu['type']);
|
214
|
+ unset($item['type']);
|
151
|
}
|
215
|
}
|
152
|
-
|
|
|
153
|
$app = new Application($this->options);
|
216
|
$app = new Application($this->options);
|
154
|
- $menu = $app->menu;
|
|
|
155
|
- $menu->add($menus);
|
217
|
+ $app->menu->add($menus);
|
156
|
}
|
218
|
}
|
157
|
|
219
|
|
158
|
/**
|
220
|
/**
|