2016-08-03 14:55:54 +08:00
#coding=utf-8
2014-05-21 16:45:11 +08:00
class AppliedProject < ActiveRecord :: Base
2016-07-28 16:22:33 +08:00
attr_accessible :project_id , :user_id , :role
2014-05-21 16:45:11 +08:00
2015-09-08 16:55:36 +08:00
belongs_to :user
belongs_to :project
2016-07-28 16:22:33 +08:00
has_many :applied_messages , :class_name = > 'AppliedMessage' , :as = > :applied , :dependent = > :destroy
2015-09-08 16:55:36 +08:00
after_create :send_appliled_message
2016-07-28 16:22:33 +08:00
# 仅仅给项目管理人员发送消息
2015-09-08 16:55:36 +08:00
def send_appliled_message
2016-07-28 16:22:33 +08:00
self . project . managers . each do | member |
2016-07-29 20:50:55 +08:00
self . applied_messages << AppliedMessage . new ( :user_id = > member . user_id , :status = > true , :viewed = > false , :applied_user_id = > self . user_id , :role = > self . role , :project_id = > self . project_id )
2016-08-03 09:37:24 +08:00
#----------------微信通知----------------------
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
2016-08-04 15:32:25 +08:00
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
2016-08-03 09:37:24 +08:00
end
#--------------------------------------------
2015-09-08 16:55:36 +08:00
end
# end
end
2014-05-22 11:58:43 +08:00
#删除用户申请
def self . deleteappiled ( userid , projectid )
@applieds = AppliedProject . where ( " user_id = ? and project_id = ? " , userid , projectid )
@applieds . each do | applied |
applied . destroy
end
end
2014-05-21 16:45:11 +08:00
end