From d99181673d31da85a23f4b9ffaf08a4288056880 Mon Sep 17 00:00:00 2001 From: gongfuxiang <2499232802@qq.com> Date: Sun, 26 May 2019 01:32:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/view/default/personal/index.html | 4 +- .../index/public/auth_text.html | 2 +- .../plugins/weixinwebauthorization/Hook.php | 49 +++++++++++++------ .../weixinwebauthorization/config.json | 2 +- .../weixinwebauthorization/index/Auth.php | 12 +++++ .../service/Service.php | 29 +++++++++++ .../weixinwebauthorization/uninstall.sql | 2 + application/service/NavigationService.php | 6 ++- application/tags.php | 5 +- 9 files changed, 90 insertions(+), 21 deletions(-) create mode 100644 application/plugins/weixinwebauthorization/uninstall.sql diff --git a/application/index/view/default/personal/index.html b/application/index/view/default/personal/index.html index 2ae00f43b..a4928aac4 100755 --- a/application/index/view/default/personal/index.html +++ b/application/index/view/default/personal/index.html @@ -32,7 +32,9 @@
{{$v.name}}
{{if isset($v['is_ext']) and $v['is_ext'] eq 1}} - {{$v.value}} + {{if isset($v['value'])}} + {{$v.value}} + {{/if}} {{else /}} {{if empty($user[$k])}} 未填写 diff --git a/application/plugins/view/weixinwebauthorization/index/public/auth_text.html b/application/plugins/view/weixinwebauthorization/index/public/auth_text.html index b84bf3370..c54a643b4 100644 --- a/application/plugins/view/weixinwebauthorization/index/public/auth_text.html +++ b/application/plugins/view/weixinwebauthorization/index/public/auth_text.html @@ -1 +1 @@ - {{if empty($plugins_data['login_name'])}}微信{{else /}}{{$plugins_data.login_name}}{{/if}} \ No newline at end of file + {{if empty($plugins_data['login_name'])}}微信{{else /}}{{$plugins_data.login_name}}{{/if}} \ No newline at end of file diff --git a/application/plugins/weixinwebauthorization/Hook.php b/application/plugins/weixinwebauthorization/Hook.php index f661c431d..5b80cc74e 100644 --- a/application/plugins/weixinwebauthorization/Hook.php +++ b/application/plugins/weixinwebauthorization/Hook.php @@ -11,6 +11,7 @@ namespace app\plugins\weixinwebauthorization; use think\Controller; +use app\service\UserService; use app\service\PluginsService; /** @@ -32,48 +33,64 @@ class Hook extends Controller */ public function run($params = []) { - // 目前微信登录只针对手机端 - if(!empty($params['hook_name']) && IsMobile()) + $ret = ''; + if(!empty($params['hook_name'])) { + // 获取登录用户 + $user = UserService::LoginUserInfo(); switch($params['hook_name']) { // 用户登录页面顶部钩子 // 用户注册页面钩子 case 'plugins_view_user_login_info_top' : case 'plugins_view_user_reg_info' : - $ret = $this->ButtonHtml($params); + if(empty($user) && IsMobile()) + { + $ret = $this->ButtonHtml($params); + } break; // 公共顶部小导航钩子-左侧 case 'plugins_view_header_navigation_top_left' : - $ret = $this->NavTextHtml($params); + if(empty($user) && IsMobile()) + { + $ret = $this->NavTextHtml($params); + } break; - // header代码 - case 'plugins_common_header' : - $ret = $this->Style($params); + // 用户中心-个人资料 + case 'plugins_service_users_personal_show_field_list_handle' : + $ret = $this->UserPersonalHtml($params, $user); break; - - default : - $ret = ''; } - return $ret; } + return $ret; } /** - * css + * 用户中心-个人资料 * @author Devil * @blog http://gong.gg/ * @version 1.0.0 * @datetime 2019-02-06T16:16:34+0800 * @param [array] $params [输入参数] + * @param [array] $user [用户登录信息] */ - public function Style($params = []) + public function UserPersonalHtml($params = [], $user = []) { - return ''; + if(empty($user['weixin_web_openid'])) + { + $tips = ' 绑定'; + } else { + $tips = ' 解绑'; + } + + $params['data']['weixin_web_openid'] = [ + 'is_ext' => 1, + 'name' => '微信绑定', + 'value' => empty($user['weixin_web_openid']) ? '未绑定' : $user['weixin_web_openid'], + 'tips' => $tips, + ]; } /** diff --git a/application/plugins/weixinwebauthorization/config.json b/application/plugins/weixinwebauthorization/config.json index 7418d0213..21b3cacc6 100644 --- a/application/plugins/weixinwebauthorization/config.json +++ b/application/plugins/weixinwebauthorization/config.json @@ -26,7 +26,7 @@ "plugins_view_header_navigation_top_left":[ "app\\plugins\\weixinwebauthorization\\Hook" ], - "plugins_common_header":[ + "plugins_service_users_personal_show_field_list_handle":[ "app\\plugins\\weixinwebauthorization\\Hook" ] } diff --git a/application/plugins/weixinwebauthorization/index/Auth.php b/application/plugins/weixinwebauthorization/index/Auth.php index c191f957a..6568b25d1 100644 --- a/application/plugins/weixinwebauthorization/index/Auth.php +++ b/application/plugins/weixinwebauthorization/index/Auth.php @@ -23,6 +23,18 @@ use app\plugins\weixinwebauthorization\service\Service; */ class Auth extends Controller { + /** + * 用户解绑 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-05-26T00:55:08+0800 + * @param array $params [description] + */ + public function Unbind($params = []) + { + return Service::WeixinUnbind($params); + } /** * 支付提示 * @author Devil diff --git a/application/plugins/weixinwebauthorization/service/Service.php b/application/plugins/weixinwebauthorization/service/Service.php index 855f0a648..c99984a28 100755 --- a/application/plugins/weixinwebauthorization/service/Service.php +++ b/application/plugins/weixinwebauthorization/service/Service.php @@ -23,6 +23,35 @@ use app\service\PluginsService; */ class Service { + /** + * 微信解绑 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-05-26T00:56:04+0800 + * @param [array] $params [输入参数] + */ + public static function WeixinUnbind($params = []) + { + $user = UserService::LoginUserInfo(); + if(!empty($user)) + { + $data = [ + 'weixin_web_openid' => '', + 'upd_time' => time(), + ]; + if(Db::name('User')->where(['id'=>$user['id']])->update($data)) + { + if(UserService::UserLoginRecord($user['id'])) + { + return DataReturn('解绑成功', 0); + } + } + return DataReturn('解绑失败', -100); + } + return DataReturn('未登录,不能操作', -1); + } + /** * 微信绑定 * @author Devil diff --git a/application/plugins/weixinwebauthorization/uninstall.sql b/application/plugins/weixinwebauthorization/uninstall.sql new file mode 100644 index 000000000..8bd8d6642 --- /dev/null +++ b/application/plugins/weixinwebauthorization/uninstall.sql @@ -0,0 +1,2 @@ +# 用户-微信web用户openid +ALTER TABLE `s_user` drop `weixin_web_openid`; \ No newline at end of file diff --git a/application/service/NavigationService.php b/application/service/NavigationService.php index 1ab5e9558..4eb16c600 100755 --- a/application/service/NavigationService.php +++ b/application/service/NavigationService.php @@ -581,6 +581,10 @@ class NavigationService */ public static function UsersPersonalShowFieldList($params = []) { + // is_ext 扩展数据 1, key不存在用户字段中可使用该扩展 + // name 显示名称 + // value 扩展自定义值 + // tips html提示操作内容 $data = [ 'avatar' => [ 'name' => '头像', @@ -607,7 +611,7 @@ class NavigationService 'name' => '注册时间' ], 'upd_time_text' => [ - 'name' => '最后更新时间' + 'name' => '更新时间' ], ]; diff --git a/application/tags.php b/application/tags.php index ab1a799db..eb975ead0 100755 --- a/application/tags.php +++ b/application/tags.php @@ -86,7 +86,6 @@ return array ( 0 => 'app\\plugins\\expressforkdn\\Hook', 1 => 'app\\plugins\\touristbuy\\Hook', 2 => 'app\\plugins\\homemiddleadv\\Hook', - 3 => 'app\\plugins\\weixinwebauthorization\\Hook', ), 'plugins_admin_common_header' => array ( @@ -151,5 +150,9 @@ return array ( array ( 0 => 'app\\plugins\\wallet\\Hook', ), + 'plugins_service_users_personal_show_field_list_handle' => + array ( + 0 => 'app\\plugins\\weixinwebauthorization\\Hook', + ), ); ?> \ No newline at end of file -- GitLab