作者 yangfu

消息 我提交的

@@ -130,7 +130,7 @@ where user_id=? and company_id=? and review_status in (%v) @@ -130,7 +130,7 @@ where user_id=? and company_id=? and review_status in (%v)
130 func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 130 func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
131 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from ( 131 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
132 select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time from ( 132 select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time from (
133 -select id,approve_time,approve_data,uid,chance_id,approve_message,create_at process_create_time 133 +select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time
134 from audit_flow_process where uid=? and enable_status =1 and review_status in (%v) and (?=0 or id<?) 134 from audit_flow_process where uid=? and enable_status =1 and review_status in (%v) and (?=0 or id<?)
135 )a left outer join chance b on a.chance_id = b.id 135 )a left outer join chance b on a.chance_id = b.id
136 )a left outer join chance_data b on a.chance_id =b.chance_id 136 )a left outer join chance_data b on a.chance_id =b.chance_id
@@ -183,7 +183,7 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag @@ -183,7 +183,7 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag
183 func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) { 183 func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
184 sql := `select a.*,b.images,b.speechs,b.videos from ( 184 sql := `select a.*,b.images,b.speechs,b.videos from (
185 select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data from ( 185 select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data from (
186 -select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time,data 186 +select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time,data,sender_user_id
187 from user_msg where receive_user_id=? and source_type=1 and (?=0 or id<?) and msg_type=? 187 from user_msg where receive_user_id=? and source_type=1 and (?=0 or id<?) and msg_type=?
188 )a left outer join chance b on a.source_id = b.id 188 )a left outer join chance b on a.source_id = b.id
189 )a left outer join chance_data b on a.source_id =b.chance_id 189 )a left outer join chance_data b on a.source_id =b.chance_id
@@ -271,6 +271,7 @@ type MsgChanceApproveItemOrm struct { @@ -271,6 +271,7 @@ type MsgChanceApproveItemOrm struct {
271 Id int64 `orm:"column(id)"` //消息id 271 Id int64 `orm:"column(id)"` //消息id
272 MsgTime time.Time `orm:"column(msg_time)"` 272 MsgTime time.Time `orm:"column(msg_time)"`
273 ReceiveUserId int64 `orm:"column(receive_user_id)"` 273 ReceiveUserId int64 `orm:"column(receive_user_id)"`
  274 + SenderUserId int64 `orm:"column(sender_user_id)"`
274 CreateTime time.Time `orm:"column(create_at)"` 275 CreateTime time.Time `orm:"column(create_at)"`
275 Message string `orm:"column(message)"` 276 Message string `orm:"column(message)"`
276 IsRead int64 `orm:"column(is_read)"` 277 IsRead int64 `orm:"column(is_read)"`
@@ -67,11 +67,34 @@ func SendApproveMsg(receiverId int64, name string, companyId int64, chanceId int @@ -67,11 +67,34 @@ func SendApproveMsg(receiverId int64, name string, companyId int64, chanceId int
67 } 67 }
68 68
69 //发送审批消息 69 //发送审批消息
70 -func SendApproveMsgByFormat(receiverId int64, name string, companyId int64, chanceId int64, chanceTypeId int, format string, data protocol.MsgData) (err error) { 70 +func SendApproveMsgWithHeader(header *protocol.RequestHeader, receiverId int64, chanceId int64, chanceTypeId int, reviewStatus int, msgType int, data protocol.MsgData) (err error) {
  71 + return sendApproveMsg(header, receiverId, "", header.CompanyId, chanceId, chanceTypeId, reviewStatus, msgType, data)
  72 +}
  73 +
  74 +//发送审批消息
  75 +func sendApproveMsg(header *protocol.RequestHeader, receiverId int64, name string, companyId int64, chanceId int64, chanceTypeId int, reviewStatus int, msgType int, data protocol.MsgData) (err error) {
71 var ( 76 var (
72 userMsg *models.UserMsg 77 userMsg *models.UserMsg
73 chanceType *models.ChanceType 78 chanceType *models.ChanceType
  79 + format string
74 ) 80 )
  81 + switch reviewStatus {
  82 + case protocol.ReviewStatusAuditging:
  83 + format = MessageApproving
  84 + break
  85 + case protocol.ReviewStatusReturn:
  86 + format = MessageApproveReject
  87 + break
  88 + case protocol.ReviewStatusPass:
  89 + format = MessageApproveSuccess
  90 + break
  91 + case protocol.ReviewStatusAutoPass:
  92 + format = MessageApproveAutoPass
  93 + break
  94 + default:
  95 + format = MessageApproving
  96 + break
  97 + }
75 if chanceType, err = models.GetChanceTypeById(chanceTypeId); err != nil { 98 if chanceType, err = models.GetChanceTypeById(chanceTypeId); err != nil {
76 return 99 return
77 } 100 }
@@ -79,18 +102,51 @@ func SendApproveMsgByFormat(receiverId int64, name string, companyId int64, chan @@ -79,18 +102,51 @@ func SendApproveMsgByFormat(receiverId int64, name string, companyId int64, chan
79 Id: idgen.Next(), 102 Id: idgen.Next(),
80 CompanyId: companyId, 103 CompanyId: companyId,
81 ReceiveUserId: receiverId, 104 ReceiveUserId: receiverId,
82 - MsgType: protocol.MsgTypeAuditBy, 105 + MsgType: msgType,
83 Message: fmt.Sprintf(format, chanceType.Name), 106 Message: fmt.Sprintf(format, chanceType.Name),
84 SourceId: chanceId, 107 SourceId: chanceId,
85 SourceType: protocol.SourceTypeChance, 108 SourceType: protocol.SourceTypeChance,
86 IsPublic: 0, 109 IsPublic: 0,
87 CreateAt: time.Now(), 110 CreateAt: time.Now(),
  111 + ChanceId: chanceId,
  112 + Data: common.AssertJson(data),
  113 + }
  114 + if header != nil {
  115 + userMsg.SenderUserId = header.UserId
  116 + }
  117 + if _, err = models.AddUserMsg(userMsg); err != nil {
  118 + return
  119 + }
  120 + logMsgWithHeaer(header, userMsg, name)
  121 + return
  122 +}
  123 +
  124 +//发送审批消息
  125 +func SendApproveMsgByFormat(header *protocol.RequestHeader, receiverId int64, chanceId int64, message string, data protocol.MsgData) (err error) {
  126 + var (
  127 + userMsg *models.UserMsg
  128 + //chanceType *models.ChanceType
  129 + )
  130 + //if chanceType, err = models.GetChanceTypeById(chanceTypeId); err != nil {
  131 + // return
  132 + //}
  133 + userMsg = &models.UserMsg{
  134 + Id: idgen.Next(),
  135 + CompanyId: header.CompanyId,
  136 + ReceiveUserId: receiverId,
  137 + MsgType: protocol.MsgTypeAuditBy,
  138 + Message: message, //fmt.Sprintf(message, chanceType.Name),
  139 + SourceId: chanceId,
  140 + SourceType: protocol.SourceTypeChance,
  141 + IsPublic: 0,
  142 + CreateAt: time.Now(),
88 Data: common.AssertJson(data), 143 Data: common.AssertJson(data),
  144 + SenderUserId: header.UserId,
89 } 145 }
90 if _, err = models.AddUserMsg(userMsg); err != nil { 146 if _, err = models.AddUserMsg(userMsg); err != nil {
91 return 147 return
92 } 148 }
93 - logMsg(userMsg, name) 149 + logMsg(userMsg, "")
94 return 150 return
95 } 151 }
96 152
@@ -211,6 +267,11 @@ func logMsg(msg *models.UserMsg, name string) { @@ -211,6 +267,11 @@ func logMsg(msg *models.UserMsg, name string) {
211 msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType)) 267 msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType))
212 } 268 }
213 269
  270 +func logMsgWithHeaer(header *protocol.RequestHeader, msg *models.UserMsg, name string) {
  271 + log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v 发送人:%v",
  272 + msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType, header.UserId))
  273 +}
  274 +
214 //保查审核日志 275 //保查审核日志
215 func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param ...interface{}) (err error) { 276 func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param ...interface{}) (err error) {
216 var ( 277 var (
@@ -351,6 +351,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -351,6 +351,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
351 log.Info(fmt.Sprintf("用户%v 更新机会审核状态 process_id:%v 状态:%v", header.UserId, process.Id, request.ReviewStatus)) 351 log.Info(fmt.Sprintf("用户%v 更新机会审核状态 process_id:%v 状态:%v", header.UserId, process.Id, request.ReviewStatus))
352 orm := orm.NewOrm() 352 orm := orm.NewOrm()
353 orm.Begin() 353 orm.Begin()
  354 + //退回同时生成一条提交记录
354 if request.ReviewStatus == protocol.ReviewStatusReturn { 355 if request.ReviewStatus == protocol.ReviewStatusReturn {
355 mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态 356 mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态
356 //增加一条待处理记录到审核列表 357 //增加一条待处理记录到审核列表
@@ -362,10 +363,9 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -362,10 +363,9 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
362 } 363 }
363 } 364 }
364 { 365 {
365 - //更新下一批次的审核 366 + //发送审核消息给提交机会的
366 var nextApprovers []int64 367 var nextApprovers []int64
367 - if err = agg.SendApprovedMsg(chance.UserId, "",  
368 - header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy, protocol.MsgData{Score: &request.ApproveData.Score}); err != nil { 368 + if err = agg.SendApproveMsgWithHeader(header, chance.UserId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy, protocol.MsgData{Score: &request.ApproveData.Score}); err != nil {
369 log.Error(err) 369 log.Error(err)
370 orm.Rollback() 370 orm.Rollback()
371 return 371 return
@@ -474,8 +474,8 @@ func setChanceAutoPass(header *protocol.RequestHeader, chance *models.Chance, or @@ -474,8 +474,8 @@ func setChanceAutoPass(header *protocol.RequestHeader, chance *models.Chance, or
474 chance.ApproveTime = time.Now() 474 chance.ApproveTime = time.Now()
475 chance.ReviewStatus = protocol.ReviewStatusPass 475 chance.ReviewStatus = protocol.ReviewStatusPass
476 msgData := protocol.MsgData{Score: &approveData.Score} 476 msgData := protocol.MsgData{Score: &approveData.Score}
477 - if err = agg.SendApproveMsgByFormat(chance.UserId, "",  
478 - header.CompanyId, chance.Id, chance.ChanceTypeId, fmt.Sprintf(agg.MessageApproveAutoPass, chanceType.Name), msgData); err != nil { 477 + //发送给机会提交人
  478 + if err = agg.SendApproveMsgByFormat(header, chance.UserId, chance.Id, fmt.Sprintf(agg.MessageApproveAutoPass, chanceType.Name), msgData); err != nil {
479 log.Error(err) 479 log.Error(err)
480 return 480 return
481 } 481 }
@@ -1431,7 +1431,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1431,7 +1431,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1431 //CreateTime: chance.CreateTime.Unix() * 1000, 1431 //CreateTime: chance.CreateTime.Unix() * 1000,
1432 } 1432 }
1433 if item.ApproveTime < 0 { 1433 if item.ApproveTime < 0 {
1434 - item.ApproveTime = 0 1434 + item.ApproveTime = chance.UpdateTime.Unix() * 1000
1435 } 1435 }
1436 jsonUnmarshal(chance.SourceContent, &item.FormList) 1436 jsonUnmarshal(chance.SourceContent, &item.FormList)
1437 item.FormList = clearEmptyForm(item.FormList) 1437 item.FormList = clearEmptyForm(item.FormList)
@@ -1449,6 +1449,9 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1449,6 +1449,9 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1449 //审核过的才有审核时间 1449 //审核过的才有审核时间
1450 if request.ReviewStatus != protocol.ReviewStatusAuditging { 1450 if request.ReviewStatus != protocol.ReviewStatusAuditging {
1451 approve.ApproveTime = chance.ApproveTime.Unix() * 1000 1451 approve.ApproveTime = chance.ApproveTime.Unix() * 1000
  1452 + if approve.ApproveTime < 0 {
  1453 + approve.ApproveTime = chance.ChanceApproveTime.Unix() * 1000
  1454 + }
1452 } 1455 }
1453 commItem.Approve = approve 1456 commItem.Approve = approve
1454 //审核完有审核数据 1457 //审核完有审核数据
@@ -328,8 +328,11 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance @@ -328,8 +328,11 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
328 } else if chance.ChanceEnableStatus == 0 { //机会关闭 328 } else if chance.ChanceEnableStatus == 0 { //机会关闭
329 commItem.ChanceStatus = protocol.ChanceStatusClose 329 commItem.ChanceStatus = protocol.ChanceStatusClose
330 } 330 }
331 -  
332 - if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil { 331 + approveUserId := chance.ChanceUserId
  332 + if chance.SenderUserId != 0 {
  333 + approveUserId = chance.SenderUserId
  334 + }
  335 + if provider, err = agg.GetUserBaseInfo(approveUserId, header.CompanyId); err != nil {
333 commItem.ChanceStatus = protocol.ChanceStatusDelete 336 commItem.ChanceStatus = protocol.ChanceStatusDelete
334 log.Error(err) 337 log.Error(err)
335 continue 338 continue