diff --git a/app/Http/Home/Controllers/ConnectController.php b/app/Http/Home/Controllers/ConnectController.php index 29c5d8a6..7479287a 100644 --- a/app/Http/Home/Controllers/ConnectController.php +++ b/app/Http/Home/Controllers/ConnectController.php @@ -121,17 +121,6 @@ class ConnectController extends Controller $openUser = $service->getOpenUserInfo($code, $state, $provider); - /** - * 微信扫码登录检查是否关注过公众号,关注过直接登录 - */ - if ($provider == ConnectModel::PROVIDER_WEIXIN && !empty($openUser['unionid'])) { - $subscribe = $service->getWeChatSubscribe($openUser['unionid']); - if ($subscribe && $subscribe->deleted == 0) { - $service->authSubscribeLogin($subscribe); - return $this->response->redirect(['for' => 'home.index']); - } - } - $connect = $service->getConnectRelation($openUser['id'], $openUser['provider']); if ($this->authUser->id > 0) { @@ -148,6 +137,8 @@ class ConnectController extends Controller $captcha = $service->getSettings('captcha'); + $this->seo->prependTitle('绑定帐号'); + $this->view->pick('connect/bind'); $this->view->setVar('captcha', $captcha); $this->view->setVar('provider', $provider); diff --git a/app/Http/Home/Controllers/UserConsoleController.php b/app/Http/Home/Controllers/UserConsoleController.php index 672b497e..64eb255a 100644 --- a/app/Http/Home/Controllers/UserConsoleController.php +++ b/app/Http/Home/Controllers/UserConsoleController.php @@ -7,7 +7,7 @@ namespace App\Http\Home\Controllers; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; +use App\Http\Home\Services\UserConsole as HomeUserConsoleService; use App\Services\Logic\Account\OAuthProvider as OAuthProviderService; use App\Services\Logic\User\Console\AccountInfo as AccountInfoService; use App\Services\Logic\User\Console\AnswerList as AnswerListService; @@ -117,6 +117,10 @@ class UserConsoleController extends Controller $connects = $service->handle(); + $service = new HomeUserConsoleService(); + + $wechatOAConnect = $service->getWeChatOAConnect(); + if ($type == 'info') { $this->view->pick('user/console/account_info'); } elseif ($type == 'phone') { @@ -127,6 +131,7 @@ class UserConsoleController extends Controller $this->view->pick('user/console/account_password'); } + $this->view->setVar('wechat_oa_connected', $wechatOAConnect ? 1 : 0); $this->view->setVar('oauth_provider', $oauthProvider); $this->view->setVar('connects', $connects); $this->view->setVar('captcha', $captcha); @@ -293,21 +298,6 @@ class UserConsoleController extends Controller $this->view->setVar('pager', $pager); } - /** - * @Get("/subscribe", name="home.uc.subscribe") - */ - public function subscribeAction() - { - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($this->authUser->id); - - $subscribed = $subscribe ? 1 : 0; - - $this->view->pick('user/console/subscribe'); - $this->view->setVar('subscribed', $subscribed); - } - /** * @Get("/notify/stats", name="home.uc.notify_stats") */ diff --git a/app/Http/Home/Services/Connect.php b/app/Http/Home/Services/Connect.php index 83ca171a..3345c6b0 100644 --- a/app/Http/Home/Services/Connect.php +++ b/app/Http/Home/Services/Connect.php @@ -9,12 +9,9 @@ namespace App\Http\Home\Services; use App\Models\Connect as ConnectModel; use App\Models\User as UserModel; -use App\Models\WeChatSubscribe as WeChatSubscribeModel; use App\Repos\Connect as ConnectRepo; use App\Repos\User as UserRepo; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\Auth\Home as AuthService; -use App\Services\Auth\Home as HomeAuthService; use App\Services\Logic\Account\Register as RegisterService; use App\Services\Logic\Notice\External\AccountLogin as AccountLoginNotice; use App\Services\OAuth\QQ as QQAuth; @@ -82,19 +79,6 @@ class Connect extends Service $this->handleConnectRelation($user, $openUser); } - public function authSubscribeLogin(WeChatSubscribeModel $subscribe) - { - $userRepo = new UserRepo(); - - $user = $userRepo->findById($subscribe->user_id); - - $this->handleLoginNotice($user); - - $auth = new HomeAuthService(); - - $auth->saveAuthInfo($user); - } - public function authConnectLogin(ConnectModel $connect) { $userRepo = new UserRepo(); @@ -132,13 +116,6 @@ class Connect extends Service return $auth->getUserInfo($token, $openId); } - public function getWeChatSubscribe($unionId) - { - $subscribeRepo = new WeChatSubscribeRepo(); - - return $subscribeRepo->findByUnionId($unionId); - } - public function getConnectRelation($openId, $provider) { $connectRepo = new ConnectRepo(); diff --git a/app/Http/Home/Services/UserConsole.php b/app/Http/Home/Services/UserConsole.php new file mode 100644 index 00000000..1693730c --- /dev/null +++ b/app/Http/Home/Services/UserConsole.php @@ -0,0 +1,25 @@ +getLoginUser(); + + $connectRepo = new ConnectRepo(); + + return $connectRepo->findByUserId($user->id, ConnectModel::PROVIDER_WECHAT_OA); + } + +} diff --git a/app/Http/Home/Views/user/console/account_info.volt b/app/Http/Home/Views/user/console/account_info.volt index 8ccd7cb5..f7c7d254 100644 --- a/app/Http/Home/Views/user/console/account_info.volt +++ b/app/Http/Home/Views/user/console/account_info.volt @@ -14,7 +14,7 @@ {%- macro connect_user(item) %} {% if item.open_avatar %} - + {{ item.open_name }} {% endif %} {{ item.open_name }} {%- endmacro %} @@ -27,89 +27,116 @@
{{ partial('user/console/menu') }}
-
- 账号安全 -
-
-
-
- - 登录密码 - 经常更改密码有助于保护您的帐号安全 + {% if oauth_provider.wechat.enabled == 1 %} +
+
+ 关注订阅
-
- 修改 -
-
-
-
- - 手机绑定 - {% if account.phone %} - 已绑定手机:{{ account.phone|anonymous }} +
+ {% if wechat_oa_connected == 0 %} +
+
关注官方公众号,订阅系统重要通知
{% else %} - 可用于登录和重置密码 +
你已经关注官方公众号
{% endif %}
-
- 绑定 -
-
-
-
- - 邮箱绑定 - {% if account.email %} - 已绑定邮箱:{{ account.email|anonymous }} - {% else %} - 可用于登录和重置密码 - {% endif %} -
-
- 绑定 -
-
-
-
- 开放登录 -
- {% if connects %} -
已经绑定的第三方帐号
-
- - - - - - - - {% for connect in connects %} - {% set url = url({'for':'home.uc.unconnect','id':connect.id}) %} - {% set time = connect.update_time > 0 ? connect.update_time : connect.create_time %} - - - - - - - {% endfor %} -
提供方用户信息更新日期操作
{{ connect_provider(connect) }}{{ connect_user(connect) }}{{ date('Y-m-d H:i',time) }}解绑
{% endif %} -
支持绑定的第三方帐号
-
- {% if oauth_provider.qq.enabled == 1 %} - - {% endif %} - {% if oauth_provider.weixin.enabled == 1 %} - - {% endif %} - {% if oauth_provider.weibo.enabled == 1 %} - +
+
+ 账号安全 +
+
+
+
+ + 登录密码 + 经常更改密码有助于保护您的帐号安全 +
+
+ 修改 +
+
+
+
+ + 手机绑定 + {% if account.phone %} + 已绑定手机:{{ account.phone|anonymous }} + {% else %} + 可用于登录和重置密码 + {% endif %} +
+
+ 绑定 +
+
+
+
+ + 邮箱绑定 + {% if account.email %} + 已绑定邮箱:{{ account.email|anonymous }} + {% else %} + 可用于登录和重置密码 + {% endif %} +
+
+ 绑定 +
+
+
+
+
+
+ 开放登录 +
+ {% if connects|length > 0 %} +
已经绑定的第三方帐号
+
+ + + + + + + + {% for connect in connects %} + {% set url = url({'for':'home.uc.unconnect','id':connect.id}) %} + {% set time = connect.update_time > 0 ? connect.update_time : connect.create_time %} + + + + + + + {% endfor %} +
提供方用户信息更新日期操作
{{ connect_provider(connect) }}{{ connect_user(connect) }}{{ date('Y-m-d H:i',time) }}解绑
+
{% endif %} +
支持绑定的第三方帐号
+
+ {% if oauth_provider.qq.enabled == 1 %} + + {% endif %} + {% if oauth_provider.weixin.enabled == 1 %} + + {% endif %} + {% if oauth_provider.weibo.enabled == 1 %} + + {% endif %} +
+{% endblock %} + +{% block include_js %} + + {% if oauth_provider.wechat.enabled == 1 and wechat_oa_connected == 0 %} + {{ js_include('home/js/wechat.oa.subscribe.js') }} + {% endif %} + {% endblock %} \ No newline at end of file diff --git a/app/Http/Home/Views/user/console/menu.volt b/app/Http/Home/Views/user/console/menu.volt index 8f80df14..c2f28d20 100644 --- a/app/Http/Home/Views/user/console/menu.volt +++ b/app/Http/Home/Views/user/console/menu.volt @@ -7,7 +7,6 @@ {% endif %} {%- endmacro %} -{% set wechat_oa_enabled = setting('wechat.oa','enabled') %} {% set point_enabled = setting('point','enabled') %}
@@ -70,9 +69,6 @@
  • 个人信息
  • 收货地址
  • 帐号安全
  • - {% if wechat_oa_enabled == 1 %} -
  • 关注订阅
  • - {% endif %}
    \ No newline at end of file diff --git a/app/Http/Home/Views/user/console/subscribe.volt b/app/Http/Home/Views/user/console/subscribe.volt index 196cf83e..fc2c1849 100644 --- a/app/Http/Home/Views/user/console/subscribe.volt +++ b/app/Http/Home/Views/user/console/subscribe.volt @@ -28,6 +28,6 @@ {% block include_js %} - {{ js_include('home/js/user.console.subscribe.js') }} + {{ js_include('home/js/wechat.oa.subscribe.js') }} {% endblock %} \ No newline at end of file diff --git a/app/Models/WeChatSubscribe.php b/app/Models/WeChatSubscribe.php deleted file mode 100644 index b6b0234a..00000000 --- a/app/Models/WeChatSubscribe.php +++ /dev/null @@ -1,70 +0,0 @@ -create_time = time(); - } - - public function beforeUpdate() - { - $this->update_time = time(); - } - -} diff --git a/app/Repos/WeChatSubscribe.php b/app/Repos/WeChatSubscribe.php deleted file mode 100644 index bec577d5..00000000 --- a/app/Repos/WeChatSubscribe.php +++ /dev/null @@ -1,77 +0,0 @@ - 'user_id= ?1 AND open_id = ?2', - 'bind' => [1 => $userId, 2 => $openId], - ]); - } - - /** - * @param int $id - * @return WeChatSubscribeModel|Model|bool - */ - public function findById($id) - { - return WeChatSubscribeModel::findFirst([ - 'conditions' => 'id = :id:', - 'bind' => ['id' => $id], - ]); - } - - /** - * @param int $userId - * @return WeChatSubscribeModel|Model|bool - */ - public function findByUserId($userId) - { - return WechatSubscribeModel::findFirst([ - 'conditions' => 'user_id = :user_id:', - 'bind' => ['user_id' => $userId], - ]); - } - - /** - * @param string $openId - * @return WeChatSubscribeModel|Model|bool - */ - public function findByOpenId($openId) - { - return WeChatSubscribeModel::findFirst([ - 'conditions' => 'open_id = :open_id:', - 'bind' => ['open_id' => $openId], - ]); - } - - /** - * @param string $unionId - * @return WeChatSubscribeModel|Model|bool - */ - public function findByUnionId($unionId) - { - return WeChatSubscribeModel::findFirst([ - 'conditions' => 'union_id = :union_id:', - 'bind' => ['union_id' => $unionId], - ]); - } - -} diff --git a/app/Services/Logic/Account/OAuthProvider.php b/app/Services/Logic/Account/OAuthProvider.php index 6b63763d..94ae5247 100644 --- a/app/Services/Logic/Account/OAuthProvider.php +++ b/app/Services/Logic/Account/OAuthProvider.php @@ -15,18 +15,20 @@ class OAuthProvider extends LogicService public function handle() { $local = $this->getSettings('oauth.local'); + $qq = $this->getSettings('oauth.qq'); $weixin = $this->getSettings('oauth.weixin'); $weibo = $this->getSettings('oauth.weibo'); - $qq = $this->getSettings('oauth.qq'); + $wechatOA = $this->getSettings('wechat.oa'); return [ 'local' => [ 'register_with_phone' => $local['register_with_phone'], 'register_with_email' => $local['register_with_email'], ], + 'qq' => ['enabled' => $qq['enabled']], 'weixin' => ['enabled' => $weixin['enabled']], 'weibo' => ['enabled' => $weibo['enabled']], - 'qq' => ['enabled' => $qq['enabled']], + 'wechat' => ['enabled' => $wechatOA['enabled']], ]; } diff --git a/app/Services/Logic/Notice/External/WeChat/AccountLogin.php b/app/Services/Logic/Notice/External/WeChat/AccountLogin.php index 6319492f..487c5c2c 100644 --- a/app/Services/Logic/Notice/External/WeChat/AccountLogin.php +++ b/app/Services/Logic/Notice/External/WeChat/AccountLogin.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class AccountLogin extends WeChatNotice @@ -21,9 +20,7 @@ class AccountLogin extends WeChatNotice */ public function handle(array $params) { - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + $subscribe = $this->getConnect($params['user']['id']); if (!$subscribe) return null; diff --git a/app/Services/Logic/Notice/External/WeChat/ConsultReply.php b/app/Services/Logic/Notice/External/WeChat/ConsultReply.php index 330dfbc2..a7d596dc 100644 --- a/app/Services/Logic/Notice/External/WeChat/ConsultReply.php +++ b/app/Services/Logic/Notice/External/WeChat/ConsultReply.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class ConsultReply extends WeChatNotice @@ -21,9 +20,7 @@ class ConsultReply extends WeChatNotice */ public function handle(array $params) { - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + $subscribe = $this->getConnect($params['user']['id']); if (!$subscribe) return null; diff --git a/app/Services/Logic/Notice/External/WeChat/GoodsDeliver.php b/app/Services/Logic/Notice/External/WeChat/GoodsDeliver.php index 6d336c33..e7b24460 100644 --- a/app/Services/Logic/Notice/External/WeChat/GoodsDeliver.php +++ b/app/Services/Logic/Notice/External/WeChat/GoodsDeliver.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class GoodsDeliver extends WeChatNotice @@ -21,9 +20,7 @@ class GoodsDeliver extends WeChatNotice */ public function handle($params) { - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + $subscribe = $this->getConnect($params['user']['id']); if (!$subscribe) return null; diff --git a/app/Services/Logic/Notice/External/WeChat/LiveBegin.php b/app/Services/Logic/Notice/External/WeChat/LiveBegin.php index 3db3d77f..8c03e22d 100644 --- a/app/Services/Logic/Notice/External/WeChat/LiveBegin.php +++ b/app/Services/Logic/Notice/External/WeChat/LiveBegin.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class LiveBegin extends WeChatNotice @@ -21,9 +20,7 @@ class LiveBegin extends WeChatNotice */ public function handle(array $params) { - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + $subscribe = $this->getConnect($params['user']['id']); if (!$subscribe) return null; diff --git a/app/Services/Logic/Notice/External/WeChat/OrderFinish.php b/app/Services/Logic/Notice/External/WeChat/OrderFinish.php index 2594bcd2..9563863c 100644 --- a/app/Services/Logic/Notice/External/WeChat/OrderFinish.php +++ b/app/Services/Logic/Notice/External/WeChat/OrderFinish.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class OrderFinish extends WeChatNotice @@ -21,9 +20,7 @@ class OrderFinish extends WeChatNotice */ public function handle($params) { - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + $subscribe = $this->getConnect($params['user']['id']); if (!$subscribe) return null; diff --git a/app/Services/Logic/Notice/External/WeChat/RefundFinish.php b/app/Services/Logic/Notice/External/WeChat/RefundFinish.php index f19d3c0c..0685311c 100644 --- a/app/Services/Logic/Notice/External/WeChat/RefundFinish.php +++ b/app/Services/Logic/Notice/External/WeChat/RefundFinish.php @@ -7,7 +7,6 @@ namespace App\Services\Logic\Notice\External\WeChat; -use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\WeChatNotice; class RefundFinish extends WeChatNotice @@ -21,9 +20,7 @@ class RefundFinish extends WeChatNotice */ public function handle(array $params) { - $subscribeRepo = new WeChatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($params['user']['id']); + $subscribe = $this->getConnect($params['user']['id']); if (!$subscribe) return null; diff --git a/app/Services/WeChatNotice.php b/app/Services/WeChatNotice.php index 7af1a140..30a9c88b 100644 --- a/app/Services/WeChatNotice.php +++ b/app/Services/WeChatNotice.php @@ -7,6 +7,8 @@ namespace App\Services; +use App\Models\Connect as ConnectModel; +use App\Repos\Connect as ConnectRepo; use App\Services\WeChat as WeChatService; use Phalcon\Logger\Adapter\File as FileLogger; @@ -105,4 +107,11 @@ abstract class WeChatNotice extends Service return $template[$code]['id'] ?? null; } + protected function getConnect($userId) + { + $connectRepo = new ConnectRepo(); + + return $connectRepo->findByUserId($userId, ConnectModel::PROVIDER_WECHAT_OA); + } + } diff --git a/db/migrations/20210324064239.php b/db/migrations/20210324064239.php index 4320717a..04aa1e42 100644 --- a/db/migrations/20210324064239.php +++ b/db/migrations/20210324064239.php @@ -81,7 +81,6 @@ final class V20210324064239 extends AbstractMigration $this->createUserSessionTable(); $this->createUserTokenTable(); $this->createVipTable(); - $this->createWechatSubscribeTable(); } protected function createAccountTable() @@ -7206,72 +7205,4 @@ final class V20210324064239 extends AbstractMigration ->create(); } - protected function createWechatSubscribeTable() - { - $tableName = 'kg_wechat_subscribe'; - - if ($this->table($tableName)->exists()) { - return; - } - - $this->table($tableName, [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->addColumn('id', 'integer', [ - 'null' => false, - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'identity' => 'enable', - 'comment' => '主键编号', - ]) - ->addColumn('user_id', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '用户编号', - 'after' => 'id', - ]) - ->addColumn('open_id', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 64, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '开放ID', - 'after' => 'user_id', - ]) - ->addColumn('create_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '创建时间', - 'after' => 'open_id', - ]) - ->addColumn('update_time', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '更新时间', - 'after' => 'create_time', - ]) - ->addIndex(['open_id'], [ - 'name' => 'open_id', - 'unique' => false, - ]) - ->addIndex(['user_id'], [ - 'name' => 'user_id', - 'unique' => false, - ]) - ->create(); - } - } diff --git a/db/migrations/20210917093354.php b/db/migrations/20210917093354.php index 0b68b55b..dcacacbf 100644 --- a/db/migrations/20210917093354.php +++ b/db/migrations/20210917093354.php @@ -17,7 +17,6 @@ class V20210917093354 extends Phinx\Migration\AbstractMigration public function up() { $this->alterConnectTable(); - $this->alterWechatSubscribeTable(); $this->handleLocalAuthSettings(); } @@ -50,52 +49,6 @@ class V20210917093354 extends Phinx\Migration\AbstractMigration $table->save(); } - protected function alterWechatSubscribeTable() - { - $table = $this->table('kg_wechat_subscribe'); - - if (!$table->hasColumn('union_id')) { - $table->addColumn('union_id', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 64, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '联合ID', - 'after' => 'open_id', - ]); - } - if (!$table->hasColumn('deleted')) { - $table->addColumn('deleted', 'integer', [ - 'null' => false, - 'default' => '0', - 'limit' => MysqlAdapter::INT_REGULAR, - 'signed' => false, - 'comment' => '删除标识', - 'after' => 'union_id', - ]); - } - if (!$table->hasIndexByName('user_id')) { - $table->addIndex(['user_id'], [ - 'name' => 'user_id', - 'unique' => false, - ]); - } - if (!$table->hasIndexByName('open_id')) { - $table->addIndex(['open_id'], [ - 'name' => 'open_id', - 'unique' => false, - ]); - } - if (!$table->hasIndexByName('union_id')) { - $table->addIndex(['union_id'], [ - 'name' => 'union_id', - 'unique' => false, - ]); - } - $table->save(); - } - protected function handleLocalAuthSettings() { $rows = [ diff --git a/public/static/home/css/common.css b/public/static/home/css/common.css index e8ca5767..f4e41425 100644 --- a/public/static/home/css/common.css +++ b/public/static/home/css/common.css @@ -1700,6 +1700,30 @@ color: red; } +.register-close-tips { + padding: 50px; + text-align: center; + color: #999; +} + +.wechat-scan-box { + padding: 20px; + text-align: center; +} + +.wechat-scan-box .qrcode { + margin-bottom: 20px; +} + +.wechat-scan-box .qrcode img { + border: 3px solid #999; + padding: 3px; +} + +.wechat-scan-box .tips { + color: #666; +} + .user-profile { display: flex; align-items: center; @@ -1934,6 +1958,10 @@ margin-right: 0; } +.my-content .section { + margin-bottom: 20px; +} + .profile-form { width: 95%; } diff --git a/public/static/home/js/user.console.subscribe.js b/public/static/home/js/user.console.subscribe.js deleted file mode 100644 index 14dc9fd2..00000000 --- a/public/static/home/js/user.console.subscribe.js +++ /dev/null @@ -1,29 +0,0 @@ -layui.use(['jquery'], function () { - - var $ = layui.jquery; - var subscribed = $('input[name=subscribed]').val(); - var interval = null; - - if (subscribed === '0') { - showQrCode(); - interval = setInterval(function () { - queryStatus(); - }, 5000); - } - - function showQrCode() { - $.get('/wechat/oa/subscribe/qrcode', function (res) { - $('#sub-qrcode').html('扫码关注'); - }); - } - - function queryStatus() { - $.get('/wechat/oa/subscribe/status', function (res) { - if (res.status === 1) { - clearInterval(interval); - $('#sub-tips').addClass('success').html('关注公众号成功'); - } - }); - } - -}); \ No newline at end of file diff --git a/public/static/home/js/wechat.oa.subscribe.js b/public/static/home/js/wechat.oa.subscribe.js new file mode 100644 index 00000000..a2f62122 --- /dev/null +++ b/public/static/home/js/wechat.oa.subscribe.js @@ -0,0 +1,34 @@ +layui.use(['jquery', 'layer'], function () { + + var $ = layui.jquery; + var layer = layui.layer; + var interval = null; + + var $qrcode = $('.wechat-scan-box > .qrcode'); + + if ($qrcode.length > 0) { + showQrCode(); + } + + function showQrCode() { + $.get('/wechat/oa/subscribe/qrcode', function (res) { + $qrcode.html('关注微信公众号'); + interval = setInterval(function () { + queryStatus(); + }, 1500); + }); + } + + function queryStatus() { + $.get('/wechat/oa/subscribe/status', function (res) { + if (res.status === 1) { + clearInterval(interval); + layer.msg('关注微信公众号成功', {icon: 1}); + setTimeout(function () { + window.location.reload(); + }, 1500); + } + }); + } + +});