作者 yangfu

审批修改

@@ -114,3 +114,12 @@ func GetUserByUcid(ucid int64) (v *User, err error) { @@ -114,3 +114,12 @@ func GetUserByUcid(ucid int64) (v *User, err error) {
114 } 114 }
115 return nil, err 115 return nil, err
116 } 116 }
  117 +
  118 +func GetUserByUcidEnable(ucid int64) (v *User, err error) {
  119 + o := orm.NewOrm()
  120 + sql := "select id,nick_name from `user` where id = (select user_id from user_company where user_company.id=? and user_company.enable=1) and enable_status=1"
  121 + if err = o.Raw(sql, ucid).QueryRow(&v); err == nil {
  122 + return v, nil
  123 + }
  124 + return nil, err
  125 +}
@@ -628,6 +628,9 @@ func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance) @@ -628,6 +628,9 @@ func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance)
628 Name: p.UserName, 628 Name: p.UserName,
629 }) 629 })
630 } 630 }
  631 + if len(item.ApproveUsers) == 1 {
  632 + item.ApproveUsers = make([]protocol.UserItem, 0)
  633 + }
631 rsp.ApproveProcess = append(rsp.ApproveProcess, item) 634 rsp.ApproveProcess = append(rsp.ApproveProcess, item)
632 break 635 break
633 } 636 }
@@ -1065,29 +1065,43 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -1065,29 +1065,43 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
1065 } 1065 }
1066 break 1066 break
1067 } 1067 }
1068 - if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人  
1069 - userIds = append(userIds, 0) 1068 + var tmpUserIds []int64
  1069 + for z := range userIds {
  1070 + uid := userIds[z]
  1071 + if uid == header.UserId { //审核人自己 转交给管理员
  1072 + continue
  1073 + }
  1074 + if uid == 0 {
  1075 + continue
  1076 + }
  1077 + tmpUserIds = append(tmpUserIds, uid)
  1078 + }
  1079 + userIds = tmpUserIds
  1080 + if len(userIds) == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //当前步骤没有用户 默认一个空审核人
  1081 + //userIds = append(userIds, 0)
  1082 + userIds = append(userIds, admin.Id)
  1083 + log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v -> admin:%v", chanceId, config.Level, company.AdminId))
  1084 + }
  1085 + if len(userIds) == 0 && auditConfig.NoApprover == protocol.NoApproverPass {
  1086 + log.Info(fmt.Sprintf("配置审核人为空 自动通过审批 chance_id:%v", chanceId))
  1087 + return
1070 } 1088 }
  1089 + userIds = append(userIds, admin.Id) //最后添加一个管理员,如果上面审核人都是空的那么使用最后的审核人
1071 for j := 0; j < len(userIds); j++ { 1090 for j := 0; j < len(userIds); j++ {
1072 uid := userIds[j] 1091 uid := userIds[j]
1073 - if uid == 0 && auditConfig.NoApprover == protocol.NoApproverPass {  
1074 - log.Info(fmt.Sprintf("配置审核人为空 自动通过审批 chance_id:%v", chanceId)) 1092 + var e error
  1093 + if len(v) > 0 && j == (len(userIds)-1) { //如果列表有人了,就不使用最后添加进来的审批人
1075 continue 1094 continue
1076 } 1095 }
1077 - if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员  
1078 - uid = admin.Id  
1079 - }  
1080 - if uid == 0 {  
1081 - uid = admin.Id  
1082 - }  
1083 - if uid == header.UserId { //审核人自己 转交给管理员  
1084 - log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))  
1085 - uid = admin.Id 1096 + if j == (len(userIds)-1) && auditConfig.NoApprover == protocol.NoApproverPass {
  1097 + log.Info(fmt.Sprintf("配置审核人已被删除:%v 自动通过审批 chance_id:%v", userIds, chanceId))
  1098 + continue
1086 } 1099 }
1087 - if approver, err = models.GetUserByUcid(uid); err != nil {  
1088 - log.Error(uid, err)  
1089 - return 1100 + if approver, e = models.GetUserByUcidEnable(uid); e != nil {
  1101 + log.Error(uid, e)
  1102 + continue
1090 } 1103 }
  1104 +
1091 item := &models.AuditFlowProcess{ 1105 item := &models.AuditFlowProcess{
1092 Id: idgen.Next(), 1106 Id: idgen.Next(),
1093 ChanceId: chanceId, 1107 ChanceId: chanceId,