From c9c63eeb85291930f14c87ac6842bc2ac4c731db Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Tue, 6 Sep 2016 14:41:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E4=BF=AE=E6=94=B9=E8=B5=84?= =?UTF-8?q?=E6=96=99=E5=90=8E=E5=8F=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/new_comment.rb | 1 + app/api/mobile/apis/users.rb | 93 +++++++++++++++++++ app/services/users_service.rb | 7 ++ app/services/wechat_service.rb | 37 ++++++++ config/wechat.yml.template | 1 + config/wechat.yml.test | 1 + public/assets/wechat/blog_detail.html | 12 +-- public/assets/wechat/course_discussion.html | 12 +-- public/assets/wechat/course_notice.html | 12 +-- public/assets/wechat/homework_detail.html | 12 +-- public/assets/wechat/issue_detail.html | 12 +-- public/assets/wechat/jour_message_detail.html | 12 +-- public/assets/wechat/project_discussion.html | 12 +-- .../wechat/directives/input_on_change.js | 25 +++++ public/javascripts/wechat/others/factory.js | 22 +++-- 15 files changed, 220 insertions(+), 51 deletions(-) create mode 100644 public/javascripts/wechat/directives/input_on_change.js diff --git a/app/api/mobile/apis/new_comment.rb b/app/api/mobile/apis/new_comment.rb index 22b654e1b..d98977661 100644 --- a/app/api/mobile/apis/new_comment.rb +++ b/app/api/mobile/apis/new_comment.rb @@ -313,6 +313,7 @@ module Mobile end present :result, result present :status, status + present :act_id, update_id present :tip, tip present :subscribe,subscribe end diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index 764dc957f..ed9115382 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -221,6 +221,99 @@ module Mobile present :data,my_jours,with:Mobile::Entities::Jours present :status,0 end + + desc "我的资料" + + params do + requires :token, type: String + end + + get 'my_userinfo' do + authenticate! + present :data, current_user, with: Mobile::Entities::User + present :status, 0 + end + + desc "我的资料" + + params do + requires :token, type: String + requires :nickname, type: String + requires :sex, type: Integer + requires :mail, type: String + end + + post 'edit_userinfo' do + authenticate! + user = current_user + status = 0 + message = "" + + #昵称 不能超过30个字符 + if params[:nickname].length > 30 then + message = "姓名不能超过30个字符!" + status = -1 + end + + if params[:mail].length > 60 then + message = "邮箱地址不能超过60个字符!" + status = -1 + end + + if !(params[:mail].match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i)) + message = "请输入正确的邮箱地址!" + status = -1 + end + + if status == 0 + # 修改邮箱的时候同步修改到gitlab + if user.mail != params[:mail] + g = Gitlab.client + begin + g.edit_user(user.gid, :email => params[:mail]) + rescue + logger.error "sync user's email of gitlab failed!" + end + end + + user.lastname = params[:nickname] + + se = user.extensions + + se.gender = params[:sex] + + if user.save && se.save + status = 0 + else + message = "保存数据失败!" + status = -1 + end + end + + if status == 0 + present :data, current_user, with: Mobile::Entities::User + present :status, 0 + else + present :status, -1 + present :message, message + end + end + + desc "解除绑定" + + params do + requires :token, type: String + end + + post 'unbind' do + authenticate! + + us = UsersService.new + us.wechat_unbind uw + + present :status, 0 + end + end end end diff --git a/app/services/users_service.rb b/app/services/users_service.rb index abc0d513a..c275e20dd 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -320,8 +320,15 @@ class UsersService end def wechat_unbind uw + user = uw.user + + #发重新绑定的微信模版消息 + ws = WechatService.new + ws.rebind_notice user.id, "login", user.id, "尊敬的用户,您已解除绑定。", "个人原因",format_time(Time.now), "点击进入重新绑定" + uw.user_id = nil uw.delete + end end diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 8adc1392f..c11826896 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -445,4 +445,41 @@ class WechatService end end + def rebind_notice(user_id, type, id, first, key1, key2,remark="") + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = { + touser:uw.openid, + template_id:Wechat.config.rebind_notice, + url:Wechat.config.auto_openid_url_1+Wechat.config.auto_openid_url_2+"login"+Wechat.config.auto_openid_url_3, + topcolor:"#FF0000", + data:{ + first: { + value:first, + color:"#707070" + }, + keyword1:{ + value:key1, + color:"#707070" + }, + keyword2:{ + value:key2, + color:"#707070" + }, + remark:{ + value:remark, + color:"#707070" + } + } + } + #data = three_keys_template uw.openid,Wechat.config.create_class_notice, type, id, first, key1, key2, key3, remark + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[rebind_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + end \ No newline at end of file diff --git a/config/wechat.yml.template b/config/wechat.yml.template index 8ca6ac237..734ed0e51 100644 --- a/config/wechat.yml.template +++ b/config/wechat.yml.template @@ -26,6 +26,7 @@ default: &default join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg" project_issue_notice: "HP8JejOnkzmvFopTarc0l1Tp4bU9qnxzdH27x3186lI" at_notice: "U3kqzgriCaqkPI9qX0NDQOInJ5hiwHCz6wgTsPysSx4" + rebind_notice: "OYsiECfqUlHKlzF_X-pz_xsGh_vAAUunX0jYRdHlyFU" auto_openid_url_1: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities" auto_openid_url_2: "&response_type=code&scope=snsapi_base&state=" diff --git a/config/wechat.yml.test b/config/wechat.yml.test index 12cee4751..28c9d974e 100644 --- a/config/wechat.yml.test +++ b/config/wechat.yml.test @@ -26,6 +26,7 @@ default: &default join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M" project_issue_notice: "HAF2aCta7BtnaOd_cotGvU4tErGWwCd9I9aiClFN7w8" at_notice: "p4HfyZQuF8O5bP_44RbbJS30SGojLJAuZEqp34iB4JU" + rebind_notice: "B97nOiW9cscB_d078I3k0jaPLHeJThTKUuxMoUnWZ2U" auto_openid_url_1: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities" auto_openid_url_2: "&response_type=code&scope=snsapi_base&state=" diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index 3b97e7df4..9b9141481 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -79,9 +79,9 @@
- - - + + +
@@ -96,9 +96,9 @@
- - - + + +
diff --git a/public/assets/wechat/course_discussion.html b/public/assets/wechat/course_discussion.html index b574deff7..ab5c91a5b 100644 --- a/public/assets/wechat/course_discussion.html +++ b/public/assets/wechat/course_discussion.html @@ -77,9 +77,9 @@
- - - + + +
@@ -93,9 +93,9 @@
- - - + + +
diff --git a/public/assets/wechat/course_notice.html b/public/assets/wechat/course_notice.html index c7ffbd3d5..b3d16ec26 100644 --- a/public/assets/wechat/course_notice.html +++ b/public/assets/wechat/course_notice.html @@ -92,9 +92,9 @@
- - - + + +
@@ -108,9 +108,9 @@
- - - + + +
diff --git a/public/assets/wechat/homework_detail.html b/public/assets/wechat/homework_detail.html index c33090554..ad63d29f3 100644 --- a/public/assets/wechat/homework_detail.html +++ b/public/assets/wechat/homework_detail.html @@ -81,9 +81,9 @@
- - - + + +
@@ -97,9 +97,9 @@
- - - + + +
diff --git a/public/assets/wechat/issue_detail.html b/public/assets/wechat/issue_detail.html index 69e3138d6..4adc4ca66 100644 --- a/public/assets/wechat/issue_detail.html +++ b/public/assets/wechat/issue_detail.html @@ -98,9 +98,9 @@
- - - + + +
@@ -114,9 +114,9 @@
- - - + + +
diff --git a/public/assets/wechat/jour_message_detail.html b/public/assets/wechat/jour_message_detail.html index 05fb4c6e9..721a62727 100644 --- a/public/assets/wechat/jour_message_detail.html +++ b/public/assets/wechat/jour_message_detail.html @@ -76,9 +76,9 @@
- - - + + +
@@ -92,9 +92,9 @@
- - - + + +
diff --git a/public/assets/wechat/project_discussion.html b/public/assets/wechat/project_discussion.html index 1ae009927..e2ebc2231 100644 --- a/public/assets/wechat/project_discussion.html +++ b/public/assets/wechat/project_discussion.html @@ -77,9 +77,9 @@
- - - + + +
@@ -92,9 +92,9 @@
- - - + + +
diff --git a/public/javascripts/wechat/directives/input_on_change.js b/public/javascripts/wechat/directives/input_on_change.js new file mode 100644 index 000000000..43baa3828 --- /dev/null +++ b/public/javascripts/wechat/directives/input_on_change.js @@ -0,0 +1,25 @@ +app.directive('inputOnChange', function(){ + return{ + restrict: 'A', + scope: {}, + link: function (scope, element, attrs) { + var onChangeFunc = scope.$eval(attrs.inputOnChange); + element.bind('change', onChangeFunc); + + scope.uploadDown = function () { + var file = event.target.files[0]; + //判断类型是不是图片 + if (!/image\/\w+/.test(file.type)) { + alert("非图片"); + return; + } + var reader = new FileReader(); + reader.readAsDataURL(file); + reader.onload = function (e) { + alert(this.result);//base64 + } + } + + } + } +}); \ No newline at end of file diff --git a/public/javascripts/wechat/others/factory.js b/public/javascripts/wechat/others/factory.js index d4e365321..37ca00114 100644 --- a/public/javascripts/wechat/others/factory.js +++ b/public/javascripts/wechat/others/factory.js @@ -94,7 +94,7 @@ app.factory('rms', function(){ }); app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$location', function($http, auth, $routeParams,rms,config,wx,$location){ - var addCommonReply = function(id, type, data,args, cb){ + var addCommonReply = function(id, type, data,args,reply_type, cb){ //先判断有没有绑定 // $http.post( // '/wechat/is_bind', @@ -116,7 +116,8 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc var userInfo = { type: type, content: temp, - token: auth.token() + token: auth.token(), + reply_type:reply_type }; //回复按钮禁用 data.disabled = true; @@ -146,24 +147,26 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc cb(response.data.subscribe); } + var act_id = response.data.act_id; + //保证内外回复数一致 activities = rms.get("activities") || []; course_activities = rms.get("course_activities") || []; project_activities = rms.get("project_activities") || []; for(var i in activities){ - if(activities[i].act_id == id){ + if(activities[i].act_id == act_id){ activities[i].reply_count += 1; break; } } for(var i in course_activities){ - if(course_activities[i].act_id == id){ + if(course_activities[i].act_id == act_id){ course_activities[i].reply_count += 1; break; } } for(var i in project_activities){ - if(project_activities[i].act_id == id){ + if(project_activities[i].act_id == act_id){ project_activities[i].reply_count += 1; break; } @@ -222,7 +225,7 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc var init = function(args){ args.scope.replytip = "输入回复内容~"; - args.scope.formData = {comment: ''}; +// args.scope.formData = {comment: ''}; var loadData = function(id,replytype,page){ loadCommonData(id, args.type,replytype,page).then(function successCallback(response) { console.log(response.data); @@ -304,10 +307,10 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc }; loadData(args.id,0,0); - args.scope.addReply = function(data){ + args.scope.addReply = function(data,reply_type){ console.log(data.comment); - addCommonReply(args.id, args.replyType, data,args, function(subscribe){ - args.scope.formData = {comment: ''}; + addCommonReply(data.act_id, args.replyType, data,args,reply_type, function(subscribe){ +// args.scope.formData = {comment: ''}; if(subscribe == 0){ $location.path("/login_tip"); return; @@ -322,6 +325,7 @@ app.factory('common', ['$http', 'auth', '$routeParams','rms','config','wx','$loc }); }; + // 动态详情界面点赞与动态界面的数据要同步 保证进入详情点赞后出来显示一致 args.scope.addPraise = function(act){ activities = rms.get("activities") || [];