You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/app/models/applied_project.rb

37 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#coding=utf-8
class AppliedProject < ActiveRecord::Base
# status 0未审批 1同意 2拒绝
attr_accessible :project_id, :user_id, :role, :status
belongs_to :user
belongs_to :project
has_many :applied_messages, :class_name => 'AppliedMessage', :as => :applied, :dependent => :destroy
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
after_create :send_appliled_message
# 仅仅给项目管理人员发送消息
def send_appliled_message
self.project.managers.each do |member|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => false, :viewed => false, :applied_user_id => self.user_id, :role => self.role, :project_id => self.project_id)
#----------------微信通知----------------------
# count = ShieldWechatMessage.where("container_type='User' and container_id=#{member.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count
# if count == 0
# ws = WechatService.new
# ws.project_review_notice member.user_id, "review_project_member", self.project_id, "项目成员审批通知。", self.project.name, self.user.show_name, format_time(Time.now),"点击查看申请详情。",self.user.id
# end
#--------------------------------------------
end
# end
end
#删除用户申请
def self.deleteappiled(userid, projectid)
@applieds = AppliedProject.where("user_id = ? and project_id = ?", userid, projectid)
@applieds.each do |applied|
applied.destroy
end
end
end