diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index 95940c0c5..6f5a3db74 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -73,6 +73,12 @@ module Mobile elsif ac.container_type == "Blog" "发表博客" end + when :course_project_id + if ac.container_type == "Course" + ac.container_id + elsif ac.container_type == "Project" + ac.container_id + end when :activity_type_name if ac.container_type == "Course" case ac.act_type @@ -137,6 +143,7 @@ module Mobile act_expose :subject #标题 act_expose :description #描述 act_expose :latest_update #最新更新时间 + act_expose :course_project_id #课程/项目ID act_expose :course_project_name #课程/项目名字 act_expose :activity_type_name #课程问答区/项目缺陷等 expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index b0c83e869..8880a4f3e 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -589,19 +589,19 @@ class IssuesController < ApplicationController return false end end - @issue.safe_attributes = issue_attributes senduser = User.find(params[:issue][:assigned_to_id]) - if senduser.id != User.current.id + if senduser.id != User.current.id && @issue.assigned_to_id != params[:issue][:assigned_to_id] issue_id = @issue.id issue_title = params[:issue][:subject] priority_id = params[:issue][:priority_id] - ps = ProjectsService.new ps.send_wechat_project_issue_notice senduser,@issue.project,issue_id,issue_title,priority_id end + @issue.safe_attributes = issue_attributes + @priorities = IssuePriority.active @allowed_statuses = @issue.new_statuses_allowed_to(User.current) true diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0c0e0919e..aabacb6e0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3236,6 +3236,16 @@ def get_all_children result, jour result end +#获取该节点所在的帖子 +def get_root_parent comment + while comment.parent + comment = comment.parent + end + comment +end + + + #将有置顶属性的提到数组前面 def sort_by_sticky topics tmpTopics = [] diff --git a/app/models/at_message.rb b/app/models/at_message.rb index bca2c7ba4..702b16335 100644 --- a/app/models/at_message.rb +++ b/app/models/at_message.rb @@ -1,6 +1,7 @@ #coding=utf-8 class AtMessage < ActiveRecord::Base + include ApplicationHelper belongs_to :user belongs_to :sender, class_name: "User", foreign_key: "sender_id" attr_accessible :at_message, :container, :viewed, :user_id, :sender_id @@ -10,7 +11,7 @@ class AtMessage < ActiveRecord::Base has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy validates :user_id, :sender_id, :at_message_id, :at_message_type, presence: true - after_create :add_user_message + after_create :add_user_message, :send_wechat_message scope :unviewed, ->(type, id){ where(at_message_type: type, at_message_id:id, viewed: false) @@ -34,6 +35,88 @@ class AtMessage < ActiveRecord::Base end end + def send_wechat_message + shield_type = "" + container_id = 0 + status = 0 + type = "" + detail_id = 0 + detail_title = "" + + if defined? at_message.notes + detail_content = strip_html at_message.notes,30 + elsif defined? at_message.content + detail_content = strip_html at_message.content,30 + end + + user = self.user + + topic = get_root_parent at_message + + case at_message_type + when "Issue" + shield_type = "Project" + container_id = at_message.project.id + type = "issue" + detail_id = topic.id + detail_title = at_message.subject + when "Journal" + + topic = get_root_parent at_message.journalized + + shield_type = "Project" + container_id = at_message.journalized.project.id + type = "issue" + detail_id = topic.id + detail_title = at_message.journalized.subject + when 'Message' + if at_message.course + shield_type = "Course" + container_id = at_message.course.id + type = "course_discussion" + detail_id = topic.id + detail_title = at_message.subject + elsif at_message.project + shield_type = "Project" + container_id = at_message.project.id + type = "project_discussion" + detail_id = topic.id + detail_title = at_message.subject + else + status = -1 + end + when 'JournalsForMessage' + if at_message.jour && at_message.jour.course + shield_type = "Course" + container_id = at_message.jour.course.id + type = "homework" + + detail_id = at_message.jour.id + detail_title = at_message.jour.name + else + type = "journal_for_message" + detail_id = topic.id + detail_title = at_message.subject + end + else + status = -1 + end + + count = 0 + + detail_title = detail_title.gsub(/RE: /, '') + + if container_id != 0 + count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='#{shield_type}' and shield_id=#{container_id}").count + end + if count == 0 && status == 0 + message_title = self.sender.show_name+"@了您" + ws = WechatService.new + ws.at_notice user.id, type, detail_id, message_title, detail_title, format_time(Time.now), detail_content, "点击查看详情。",0 + end + + end + def subject case at_message_type when "Issue" diff --git a/app/services/wechat_service.rb b/app/services/wechat_service.rb index 423676983..8adc1392f 100644 --- a/app/services/wechat_service.rb +++ b/app/services/wechat_service.rb @@ -432,4 +432,17 @@ class WechatService end end + def at_notice(user_id, type, id, first, key1, key2,key3,remark="",uid=0) + uw = UserWechat.where(user_id: user_id).first + unless uw.nil? + data = three_keys_template uw.openid,Wechat.config.at_notice, type, id, first, key1, key2, key3, remark,uid + begin + req = Wechat.api.template_message_send Wechat::Message.to(uw.openid).template(data) + rescue Exception => e + Rails.logger.error "[at_notice] ===> #{e}" + end + Rails.logger.info "send over. #{req}" + end + end + end \ No newline at end of file diff --git a/config/menu.yml.production b/config/menu.yml.production index 55318e811..8929d002e 100644 --- a/config/menu.yml.production +++ b/config/menu.yml.production @@ -22,14 +22,6 @@ button: - name: "更多" sub_button: - - - type: "view" - name: "加入班级" - url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=join_class#wechat_redirect" - - - type: "view" - name: "加入项目" - url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e1ab05163a28e37&redirect_uri=https://www.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=join_project#wechat_redirect" - type: "view" name: "历史推文" diff --git a/config/menu.yml.test b/config/menu.yml.test index 45e23aaf3..303b30c26 100644 --- a/config/menu.yml.test +++ b/config/menu.yml.test @@ -22,14 +22,6 @@ button: - name: "更多" sub_button: - - - type: "view" - name: "加入班级" - url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=join_class#wechat_redirect" - - - type: "view" - name: "加入项目" - url: "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc09454f171153c2d&redirect_uri=https://test.forge.trustie.net/wechat/user_activities&response_type=code&scope=snsapi_base&state=join_project#wechat_redirect" - type: "view" name: "历史推文" diff --git a/config/wechat.yml.template b/config/wechat.yml.template index adda8e7e8..8ca6ac237 100644 --- a/config/wechat.yml.template +++ b/config/wechat.yml.template @@ -25,6 +25,7 @@ default: &default project_review_notice: "kdb-8UlMjTc3z51Qcf8g2vY4i_nE4OGKZAucdQma_2E" join_project_notice: "TtXvy0XMIQyCgpnXHhoB8t-x0QIfy-78gAJXsGf9afg" project_issue_notice: "HP8JejOnkzmvFopTarc0l1Tp4bU9qnxzdH27x3186lI" + at_notice: "U3kqzgriCaqkPI9qX0NDQOInJ5hiwHCz6wgTsPysSx4" 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 8c0dafc2f..12cee4751 100644 --- a/config/wechat.yml.test +++ b/config/wechat.yml.test @@ -25,6 +25,7 @@ default: &default project_review_notice: "ip192wVXTav3qchgUn9_7B6lFfTlCZjwL7A1tncTOuc" join_project_notice: "3KnMQEMUCmQWkB5JvzrpmguEwnN8bvUHUdpOTudxv_M" project_issue_notice: "HAF2aCta7BtnaOd_cotGvU4tErGWwCd9I9aiClFN7w8" + at_notice: "p4HfyZQuF8O5bP_44RbbJS30SGojLJAuZEqp34iB4JU" 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/activities.html b/public/assets/wechat/activities.html index 506dcc724..2d45f4d17 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -40,7 +40,7 @@
- +