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 %} - -