diff --git a/app/Console/Tasks/UpgradeTask.php b/app/Console/Tasks/UpgradeTask.php index 0dbfa0dc..cfd14aab 100644 --- a/app/Console/Tasks/UpgradeTask.php +++ b/app/Console/Tasks/UpgradeTask.php @@ -80,7 +80,7 @@ class UpgradeTask extends Task $redis->del($statsKey); } - echo "start reset metadata..." . PHP_EOL; + echo "end reset metadata..." . PHP_EOL; } /** diff --git a/app/Http/Admin/Controllers/SettingController.php b/app/Http/Admin/Controllers/SettingController.php index 309d6bd8..7d949a67 100644 --- a/app/Http/Admin/Controllers/SettingController.php +++ b/app/Http/Admin/Controllers/SettingController.php @@ -328,9 +328,9 @@ class SettingController extends Controller } /** - * @Route("/wechat", name="admin.setting.wechat") + * @Route("/wechat/oa", name="admin.setting.wechat_oa") */ - public function wechatAction() + public function wechatOaAction() { $settingService = new SettingService(); @@ -340,7 +340,7 @@ class SettingController extends Controller $data = $this->request->getPost(); - $settingService->updateWechatSettings($section, $data); + $settingService->updateWechatOASettings($section, $data); return $this->jsonSuccess(['msg' => '更新配置成功']); @@ -348,6 +348,7 @@ class SettingController extends Controller $oa = $settingService->getWechatOASettings(); + $this->view->pick('setting/wechat_oa'); $this->view->setVar('oa', $oa); } } diff --git a/app/Http/Admin/Controllers/TestController.php b/app/Http/Admin/Controllers/TestController.php index fb398d11..4db114d2 100644 --- a/app/Http/Admin/Controllers/TestController.php +++ b/app/Http/Admin/Controllers/TestController.php @@ -11,6 +11,7 @@ use App\Services\Mail\Test as TestMailService; use App\Services\MyStorage as StorageService; use App\Services\Sms\Test as TestSmsService; use App\Services\Vod as VodService; +use App\Services\Wechat as WechatService; /** * @RoutePrefix("/admin/test") @@ -54,6 +55,24 @@ class TestController extends Controller } } + /** + * @Post("/wechat/oa", name="admin.test.wechat_oa") + */ + public function wechatOaAction() + { + $wechatService = new WechatService(); + + $oa = $wechatService->getOfficialAccount(); + + $result = $oa->qrcode->temporary('foo', 86400); + + if (isset($result['ticket'])) { + return $this->jsonSuccess(['msg' => '接口返回成功']); + } else { + return $this->jsonError(['msg' => '接口返回失败,请检查相关配置']); + } + } + /** * @Get("/live/push", name="admin.test.live_push") */ diff --git a/app/Http/Admin/Services/AuthNode.php b/app/Http/Admin/Services/AuthNode.php index 89b75942..77104b1d 100644 --- a/app/Http/Admin/Services/AuthNode.php +++ b/app/Http/Admin/Services/AuthNode.php @@ -759,9 +759,9 @@ class AuthNode extends Service ], [ 'id' => '5-1-13', - 'title' => '微信平台', + 'title' => '微信公众号', 'type' => 'menu', - 'route' => 'admin.setting.wechat', + 'route' => 'admin.setting.wechat_oa', ], ], ], diff --git a/app/Http/Admin/Services/Setting.php b/app/Http/Admin/Services/Setting.php index 92ade54d..d592dc8e 100644 --- a/app/Http/Admin/Services/Setting.php +++ b/app/Http/Admin/Services/Setting.php @@ -5,6 +5,7 @@ namespace App\Http\Admin\Services; use App\Caches\Setting as SettingCache; use App\Repos\Setting as SettingRepo; use App\Repos\Vip as VipRepo; +use App\Services\Wechat as WechatService; class Setting extends Service { @@ -63,6 +64,26 @@ class Setting extends Service $oa['notify_url'] = $oa['notify_url'] ?: kg_full_url(['for' => 'home.wechat.oa.notify']); + $oa['menu'] = json_decode($oa['menu'], true); + + /** + * 构造一个3*5的二维树形菜单 + */ + for ($i = 0; $i < 3; $i++) { + if (!isset($oa['menu'][$i])) { + $oa['menu'][$i] = ['name' => sprintf('菜单%s', $i + 1)]; + } + for ($j = 0; $j < 5; $j++) { + if (!isset($oa['menu'][$i]['children'][$j])) { + $oa['menu'][$i]['children'][$j] = [ + 'type' => 'view', + 'name' => '', + 'url' => '', + ];; + } + } + } + return $oa; } @@ -171,15 +192,39 @@ class Setting extends Service } } - public function updateWechatSettings($section, $settings) + public function updateWechatOASettings($section, $settings) { - if ($section == 'wechat.oa') { - if (isset($settings['notice_template'])) { - $settings['notice_template'] = kg_json_encode($settings['notice_template']); + if (!empty($settings['notice_template'])) { + $settings['notice_template'] = kg_json_encode($settings['notice_template']); + } + + $buttons = []; + + if (!empty($settings['menu'])) { + foreach ($settings['menu'] as $i => $top) { + $buttons[$i]['name'] = !empty($top['name']) ? $top['name'] : sprintf('菜单%s', $i + 1); + if (!empty($top['url'])) { + $buttons[$i]['url'] = $top['url']; + $buttons[$i]['type'] = 'view'; + } + foreach ($top['children'] as $j => $sub) { + if (!empty($sub['name']) && !empty($sub['url'])) { + $buttons[$i]['sub_button'][$j]['name'] = $sub['name']; + $buttons[$i]['sub_button'][$j]['url'] = $sub['url']; + $buttons[$i]['sub_button'][$j]['type'] = 'view'; + } + } } + $settings['menu'] = kg_json_encode($settings['menu']); } $this->updateSettings($section, $settings); + + if (!empty($buttons)) { + $service = new WechatService(); + $oa = $service->getOfficialAccount(); + $oa->menu->create($buttons); + } } } diff --git a/app/Http/Admin/Views/setting/wechat.volt b/app/Http/Admin/Views/setting/wechat.volt deleted file mode 100644 index a37d7091..00000000 --- a/app/Http/Admin/Views/setting/wechat.volt +++ /dev/null @@ -1,16 +0,0 @@ -{% extends 'templates/main.volt' %} - -{% block content %} - -
- -
-
- {{ partial('setting/wechat_oa') }} -
-
-
- -{% endblock %} \ No newline at end of file diff --git a/app/Http/Admin/Views/setting/wechat_oa.volt b/app/Http/Admin/Views/setting/wechat_oa.volt index 97702aa3..faad9ad7 100644 --- a/app/Http/Admin/Views/setting/wechat_oa.volt +++ b/app/Http/Admin/Views/setting/wechat_oa.volt @@ -1,104 +1,24 @@ -{% set notice_template = oa.notice_template|json_decode %} +{% extends 'templates/main.volt' %} -
-
- -
- - +{% block content %} + +
+
    +
  • 基本设置
  • +
  • 模板消息
  • +
  • 自定义菜单
  • +
+
+
+ {{ partial('setting/wechat_oa_basic') }} +
+
+ {{ partial('setting/wechat_oa_notice') }} +
+
+ {{ partial('setting/wechat_oa_menu') }} +
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- - - -
-
- -
- 模板配置 -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
名称模板编号
登录成功通知
购买成功提醒
退款成功通知
课程直播提醒
咨询结果通知
-
-
- -
- - - -
-
-
\ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/app/Http/Admin/Views/setting/wechat_oa_basic.volt b/app/Http/Admin/Views/setting/wechat_oa_basic.volt new file mode 100644 index 00000000..84e952c5 --- /dev/null +++ b/app/Http/Admin/Views/setting/wechat_oa_basic.volt @@ -0,0 +1,66 @@ +
+
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + + +
+
+
+ +
+
+ 接口测试 +
+
+ +
+ +
+
+
+ +
+ + +
+
+
\ No newline at end of file diff --git a/app/Http/Admin/Views/setting/wechat_oa_menu.volt b/app/Http/Admin/Views/setting/wechat_oa_menu.volt new file mode 100644 index 00000000..0c34b148 --- /dev/null +++ b/app/Http/Admin/Views/setting/wechat_oa_menu.volt @@ -0,0 +1,42 @@ +
+ + + + + + + + + + + + + + + {% for i,top in oa.menu %} + + + + + + {% for j,sub in top.children %} + + + + + + {% endfor %} + {% endfor %} + +
层级名称链接
├──
├──
+
+
+ +
+ + + +
+
+
+ diff --git a/app/Http/Admin/Views/setting/wechat_oa_notice.volt b/app/Http/Admin/Views/setting/wechat_oa_notice.volt new file mode 100644 index 00000000..0b7eee16 --- /dev/null +++ b/app/Http/Admin/Views/setting/wechat_oa_notice.volt @@ -0,0 +1,47 @@ +{% set notice_template = oa.notice_template|json_decode %} + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
模板名称模板编号
登录成功通知
购买成功提醒
退款成功通知
课程直播提醒
咨询结果通知
+
+
+ +
+ + + +
+
+
\ No newline at end of file diff --git a/db/migrations/20210106112717_data_202101061830.php b/db/migrations/20210106112717_data_202101061830.php new file mode 100644 index 00000000..c11aee46 --- /dev/null +++ b/db/migrations/20210106112717_data_202101061830.php @@ -0,0 +1,68 @@ + '菜单1', + 'url' => '', + 'children' => [ + [ + 'type' => 'view', + 'name' => '菜单1-1', + 'url' => 'https://gitee.com/koogua' + ], + ], + ], + [ + 'name' => '菜单2', + 'url' => '', + 'children' => [ + [ + 'type' => 'view', + 'name' => '菜单2-1', + 'url' => 'https://gitee.com/koogua' + ], + ], + ], + [ + 'name' => '菜单3', + 'url' => '', + 'children' => [ + [ + 'type' => 'view', + 'name' => '菜单3-1', + 'url' => 'https://gitee.com/koogua' + ], + ], + ], + ]; + + $rows = [ + [ + 'section' => 'wechat.oa', + 'item_key' => 'menu', + 'item_value' => json_encode($menu), + ], + ]; + + $this->table('kg_setting')->insert($rows)->save(); + + } + + public function down() + { + $this->getQueryBuilder() + ->delete('kg_setting') + ->where(['section' => 'wechat.oa', 'item_key' => 'menu']) + ->execute(); + } + +} \ No newline at end of file diff --git a/public/static/admin/js/common.js b/public/static/admin/js/common.js index 9ad972a9..145c6887 100644 --- a/public/static/admin/js/common.js +++ b/public/static/admin/js/common.js @@ -30,8 +30,9 @@ layui.use(['jquery', 'form', 'element', 'layer', 'dropdown'], function () { 404: function () { layer.msg('资源不存在', {icon: 2, anim: 6}); }, - 500: function () { - layer.msg('服务器内部错误', {icon: 2, anim: 6}); + 500: function (xhr) { + var res = JSON.parse(xhr.responseText); + layer.msg(res.msg, {icon: 2, anim: 6}); } } });