approval.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. package seal
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_mobile_admin/models/custom"
  7. "hongze/hongze_mobile_admin/models/tables/admin"
  8. "hongze/hongze_mobile_admin/models/tables/approval_flow_node"
  9. "hongze/hongze_mobile_admin/models/tables/company_approval_message"
  10. "hongze/hongze_mobile_admin/models/tables/contract_approval"
  11. "hongze/hongze_mobile_admin/models/tables/contract_approval_record"
  12. "hongze/hongze_mobile_admin/models/tables/seal"
  13. "hongze/hongze_mobile_admin/services"
  14. "hongze/hongze_mobile_admin/services/alarm_msg"
  15. "hongze/hongze_mobile_admin/services/flow"
  16. "hongze/hongze_mobile_admin/utils"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. //消息来源
  22. var sourceType = 3
  23. //提交审批
  24. func Apply(sealInfo *seal.Seal) (err error) {
  25. //发起审批
  26. approval, contractApprovalRecordList, err := apply(sealInfo)
  27. if err != nil {
  28. return
  29. }
  30. //待办通知
  31. {
  32. //发送消息下级审批人
  33. go messageToNodeUser(contractApprovalRecordList[0].NodeId, approval.ApplyUserId, approval.ContractApprovalId, 1, 1, sealInfo.CompanyName, sealInfo.Use)
  34. //go messageToAllCcUser(approval.ApplyUserId, approval.ContractApprovalId, 1, 1, sealInfo.CompanyName, sealInfo.Use)
  35. }
  36. return
  37. }
  38. // GetFlowTypeBySealType 根据盖章类型(多选,逗号拼接)获取审批流的类型
  39. func GetFlowTypeBySealType(sealType string) (flowType int) {
  40. flowType = 5 // 合同章
  41. longFlow := "公章,法人章" // 盖章类型包含其中之一则审批流变成6
  42. sealTypeArr := strings.Split(sealType, ",")
  43. for _, itemType := range sealTypeArr {
  44. if strings.Contains(longFlow, itemType) {
  45. flowType = 6
  46. }
  47. }
  48. return
  49. }
  50. //审批人修改后重新提交审批单
  51. func CheckApply(sealInfo *seal.Seal, opUser *custom.AdminWx) (err error) {
  52. //发起审批
  53. approvalInfo, contractApprovalRecordList, err := apply(sealInfo)
  54. if err != nil {
  55. return
  56. }
  57. //校验一级审批人是否与当前提交人一致,如果一致的话,那么审批通过且不发送消息给一级审批人
  58. var contractApprovalRecord *contract_approval_record.ContractApprovalRecord
  59. for _, tmpContractApprovalRecord := range contractApprovalRecordList {
  60. if tmpContractApprovalRecord.NodeId == approvalInfo.CurrNodeId && tmpContractApprovalRecord.ApproveUserId == opUser.AdminId {
  61. contractApprovalRecord = tmpContractApprovalRecord
  62. }
  63. }
  64. //如果一级审批人和当前提交人一致,那么审批通过,且不发送消息给一级审批人
  65. if contractApprovalRecord != nil {
  66. sealInfo, approvalInfo, approvalRecord, tmpErr := CheckApproveAuth(sealInfo.SealId, opUser)
  67. if tmpErr != nil {
  68. err = tmpErr
  69. return
  70. }
  71. err = Approved(sealInfo, approvalInfo, approvalRecord, opUser, "")
  72. } else {
  73. //如果一级审批人和当前提交人不一致,那么发送消息给一级审批人,重走审批流程
  74. //待办通知
  75. {
  76. //发送消息下级审批人
  77. go messageToNodeUser(contractApprovalRecordList[0].NodeId, approvalInfo.ApplyUserId, approvalInfo.ContractApprovalId, 1, 1, sealInfo.CompanyName, sealInfo.Use)
  78. //发送消息给所有的抄送人
  79. //go messageToAllCcUser(approval.ApplyUserId, approval.ContractApprovalId, 1, 1, sealInfo.CompanyName, sealInfo.Use)
  80. }
  81. }
  82. return
  83. }
  84. //发起审批
  85. func apply(sealInfo *seal.Seal) (approval *contract_approval.ContractApproval, contractApprovalRecordList []*contract_approval_record.ContractApprovalRecord, err error) {
  86. //用印状态判断
  87. ignoreStatus := []string{"待提交", "已撤回", "已驳回"}
  88. if !strings.Contains(strings.Join(ignoreStatus, ","), sealInfo.Status) {
  89. err = errors.New("用印单状态异常,不允许提交审批,当前用印单状态:" + sealInfo.Status)
  90. return
  91. }
  92. //将用印数据存为快照
  93. sealDetailByte, err := json.Marshal(sealInfo)
  94. if err != nil {
  95. err = errors.New(fmt.Sprint("用印单异常,当前用印单数据格式化失败:", err))
  96. return
  97. }
  98. //获取审批流
  99. flowId := GetFlowTypeBySealType(sealInfo.SealType)
  100. flowItemInfo, err := flow.GetApprovalFlow(flowId)
  101. if err != nil {
  102. return
  103. }
  104. if len(flowItemInfo.NodeList) <= 0 {
  105. err = errors.New("审批流程未配置")
  106. return
  107. }
  108. //校验是否存在待审批的审批单(其实没有多大意义,只是为了 异常数据校验)
  109. approval = &contract_approval.ContractApproval{
  110. ContractId: sealInfo.SealId,
  111. ApprovalType: "seal",
  112. Status: "待审批",
  113. ApplyContent: sealInfo.Use,
  114. ContractDetail: string(sealDetailByte),
  115. ApplyUserId: sealInfo.UserId,
  116. ApplyUserName: sealInfo.UserName,
  117. FlowId: flowItemInfo.FlowId,
  118. FlowVersion: flowItemInfo.CurrVersion,
  119. CurrNodeId: flowItemInfo.NodeList[0].NodeId,
  120. StartNodeId: flowItemInfo.NodeList[0].NodeId,
  121. ModifyTime: time.Now(),
  122. CreateTime: time.Now(),
  123. }
  124. has, err := approval.CheckPendingByContractId(sealInfo.SealId, "seal")
  125. if err != nil {
  126. return
  127. }
  128. if has {
  129. err = errors.New("用印异常,不允许提交审批,存在待审核的审批单")
  130. return
  131. }
  132. ApproveUserMap := make(map[int]approval_flow_node.User)
  133. for _, nodeItem := range flowItemInfo.NodeList {
  134. //审批流记录
  135. if len(nodeItem.UserList) <= 0 {
  136. err = errors.New(fmt.Sprint("审批流程异常,没有可审批的人员,Err:", err))
  137. return
  138. }
  139. for _, userItem := range nodeItem.UserList {
  140. contractApprovalRecord := &contract_approval_record.ContractApprovalRecord{
  141. Status: "待审批",
  142. ApproveRemark: "",
  143. ApproveUserId: userItem.AdminId,
  144. ApproveUserName: userItem.Name,
  145. ApproveRoleTypeCode: userItem.RoleTypeCode,
  146. NodeId: nodeItem.NodeId,
  147. NodeType: nodeItem.NodeType,
  148. NextNodeId: nodeItem.NextNodeId,
  149. PrevNodeId: nodeItem.PrevNodeId,
  150. CreateTime: time.Now(),
  151. ModifyTime: time.Now(),
  152. }
  153. contractApprovalRecordList = append(contractApprovalRecordList, contractApprovalRecord)
  154. ApproveUserMap[userItem.AdminId] = userItem
  155. }
  156. }
  157. err = approval.Apply(approval, contractApprovalRecordList)
  158. if err != nil {
  159. return
  160. }
  161. return
  162. }
  163. //撤销合同
  164. func CancelApply(sealInfo *seal.Seal, opUserId int, opUserName string) (err error) {
  165. if sealInfo == nil {
  166. err = errors.New("审批流异常,没有审批流信息")
  167. return
  168. }
  169. //用印状态判断
  170. if sealInfo.Status != "待审批" {
  171. err = errors.New("用印状态异常,不允许撤回申请,当前用印状态:" + sealInfo.Status)
  172. return
  173. }
  174. //校验操作人与合同申请人是否同一人
  175. if sealInfo.UserId != opUserId {
  176. err = errors.New("操作人异常,不允许撤回非本人提交的申请:" + strconv.Itoa(sealInfo.UserId))
  177. return
  178. }
  179. //获取最近一次待审批的审批单信息
  180. approvalInfo, err := contract_approval.GetLastContractApprovalByContractId(sealInfo.SealId, "seal")
  181. if err != nil {
  182. return
  183. }
  184. if approvalInfo.Status != "待审批" {
  185. err = errors.New("审批单状态异常,审批单状态:" + sealInfo.Status)
  186. return
  187. }
  188. //获取当前审批单的审批流信息
  189. approvalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalIdAndNodeId(approvalInfo.ContractApprovalId, approvalInfo.CurrNodeId)
  190. if err != nil {
  191. err = errors.New("获取审批失败,Err:" + err.Error())
  192. return
  193. }
  194. if len(approvalRecordList) <= 0 {
  195. err = errors.New("找不到对应的审批流")
  196. }
  197. for _, tmpApprovalRecord := range approvalRecordList {
  198. //判断当前节点是否存在上级节点,如果存在,那么说明
  199. if tmpApprovalRecord.PrevNodeId > 0 {
  200. err = errors.New("合同已存在审批操作,不允许撤回申请")
  201. return
  202. }
  203. }
  204. //获取当前审批单中所有待审批的流程流
  205. contractApprovalRecordList, err := contract_approval_record.GetPendingContractApprovalRecordListByContractId(approvalInfo.ContractApprovalId, approvalInfo.CurrNodeId)
  206. if err != nil {
  207. return
  208. }
  209. //撤回审批流
  210. err = approvalInfo.Cancel(approvalInfo, contractApprovalRecordList)
  211. if err != nil {
  212. return
  213. }
  214. // 操作日志
  215. err = seal.AddSealOperationRecord(sealInfo.SealId, opUserId, 0, "cancel", opUserName, "撤回用印申请", "")
  216. if err != nil {
  217. err = errors.New("新增用印日志失败")
  218. return
  219. }
  220. ////添加操作日志
  221. //remark := "撤回申请"
  222. //_ = contract_operation_record.AddContractOperationRecord(contractInfo.ContractId, contractInfo.SellerId, contractApprovalRecord.ContractApprovalRecordId, "cancel_apply", contractInfo.SellerName, remark)
  223. //作废原有消息
  224. for _, contractApprovalRecord := range contractApprovalRecordList {
  225. go company_approval_message.CancelCompanyApprovalMessage(contractApprovalRecord.ContractApprovalRecordId, 2)
  226. }
  227. return
  228. }
  229. //校验审批操作权限
  230. func CheckApproveAuth(sealId int, opUser *custom.AdminWx) (sealInfo *seal.Seal, approvalInfo *contract_approval.ContractApproval, approvalRecord *contract_approval_record.ContractApprovalRecord, err error) {
  231. //用印详情
  232. sealInfo, err = seal.GetSealInfoById(sealId)
  233. if err != nil {
  234. err = errors.New("获取用印失败,Err:" + err.Error())
  235. return
  236. }
  237. //合同状态判断
  238. if sealInfo.Status != "待审批" {
  239. err = errors.New("用印状态异常,不允许驳回申请,当前合同状态:" + sealInfo.Status)
  240. return
  241. }
  242. //获取该最近一条审批单详情
  243. approvalInfo, err = contract_approval.GetLastContractApprovalByContractId(sealInfo.SealId, "seal")
  244. if err != nil {
  245. err = errors.New("获取审批单失败,Err:" + err.Error())
  246. return
  247. }
  248. if approvalInfo.Status != "待审批" {
  249. err = errors.New("当前审批单状态异常,不允许审批,审批单状态:" + approvalInfo.Status)
  250. return
  251. }
  252. //审批流
  253. approvalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalIdAndNodeId(approvalInfo.ContractApprovalId, approvalInfo.CurrNodeId)
  254. if err != nil {
  255. err = errors.New("获取审批失败,Err:" + err.Error())
  256. return
  257. }
  258. for _, tmpApprovalRecord := range approvalRecordList {
  259. if tmpApprovalRecord.NodeType == "check" && tmpApprovalRecord.ApproveUserId == opUser.AdminId {
  260. approvalRecord = tmpApprovalRecord
  261. }
  262. }
  263. if approvalRecord == nil {
  264. err = errors.New("当前账号没有审批权限")
  265. return
  266. }
  267. return
  268. }
  269. //驳回审批
  270. func Reject(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractApproval, approvalRecord *contract_approval_record.ContractApprovalRecord, opUser *custom.AdminWx, rejectRemark string) (err error) {
  271. err = reject(sealInfo, approvalInfo, approvalRecord, opUser, rejectRemark)
  272. if err != nil {
  273. return
  274. }
  275. //添加操作日志
  276. //remark := "驳回申请"
  277. //_ = contract_operation_record.AddContractOperationRecord(contractInfo.ContractId, opUserId, approvalRecord.ContractApprovalRecordId, "reject", opUserName, remark)
  278. //待办通知
  279. {
  280. content := sealInfo.CompanyName + " 用印已驳回"
  281. approvalSysUser, _ := admin.GetAdminById(sealInfo.UserId)
  282. go services.AddCompanyApprovalMessage(opUser.AdminId, sealInfo.UserId, 0, approvalRecord.ContractApprovalRecordId, 2, sourceType, 3, sealInfo.CompanyName, content, content, approvalSysUser.Mobile, "")
  283. //发送消息给所有的抄送人
  284. //go messageToAllCcUser(opUserId, approvalRecord.ContractApprovalId, 2, 3, sealInfo.CompanyName, content)
  285. }
  286. return
  287. }
  288. //审批人修改后驳回
  289. func CheckReject(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractApproval, approvalRecord *contract_approval_record.ContractApprovalRecord, opUser *custom.AdminWx, rejectRemark string) (err error) {
  290. err = reject(sealInfo, approvalInfo, approvalRecord, opUser, rejectRemark)
  291. if err != nil {
  292. return
  293. }
  294. return
  295. }
  296. //实际驳回
  297. func reject(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractApproval, approvalRecord *contract_approval_record.ContractApprovalRecord, opUser *custom.AdminWx, rejectRemark string) (err error) {
  298. if approvalRecord == nil {
  299. err = errors.New("审批流异常,没有审批流信息")
  300. return
  301. }
  302. //审批流状态判断
  303. if approvalRecord.Status != "待审批" {
  304. err = errors.New("审批流状态异常,不允许驳回申请,当前审批流状态:" + approvalRecord.Status)
  305. return
  306. }
  307. //判断是否审批类型,如果不是审批类型,那么就没有审批权限
  308. if approvalRecord.NodeType != "check" {
  309. err = errors.New("当前账号没有审批权限")
  310. return
  311. }
  312. //操作人
  313. opUserId := opUser.AdminId
  314. opUserName := opUser.RealName
  315. //操作权限校验
  316. if opUser.RoleTypeCode != approvalRecord.ApproveRoleTypeCode {
  317. err = errors.New("当前账号没有审批权限")
  318. return
  319. }
  320. if approvalRecord.ApproveUserId > 0 && approvalRecord.ApproveUserId != opUserId {
  321. err = errors.New("当前账号没有审批权限,需要指定人操作")
  322. return
  323. }
  324. //审批单状态判断
  325. if approvalInfo.Status != "待审批" {
  326. err = errors.New("审批单状态异常,不允许驳回申请,当前审批单状态:" + approvalInfo.Status)
  327. return
  328. }
  329. //用印状态判断
  330. if sealInfo.Status != "待审批" {
  331. err = errors.New("用印状态异常,不允许驳回申请,当前用印状态:" + sealInfo.Status)
  332. return
  333. }
  334. err = approvalInfo.Reject(approvalInfo, approvalRecord, opUserId, opUserName, rejectRemark)
  335. if err != nil {
  336. return
  337. }
  338. // 操作日志
  339. err = seal.AddSealOperationRecord(sealInfo.SealId, opUser.AdminId, approvalRecord.ContractApprovalRecordId, "reject", opUser.RealName, "驳回审批", rejectRemark)
  340. if err != nil {
  341. err = errors.New("新增用印日志失败")
  342. return
  343. }
  344. return
  345. }
  346. //审批通过
  347. func Approved(sealInfo *seal.Seal, approvalInfo *contract_approval.ContractApproval, approvalRecord *contract_approval_record.ContractApprovalRecord, opUser *custom.AdminWx, approvedRemark string) (err error) {
  348. if approvalRecord == nil {
  349. err = errors.New("审批流异常,没有审批流信息")
  350. return
  351. }
  352. //审批流状态判断
  353. if approvalRecord.Status != "待审批" {
  354. err = errors.New("审批流状态异常,不允许审批,当前审批流状态:" + approvalRecord.Status)
  355. return
  356. }
  357. //判断是否审批类型,如果不是审批类型,那么就没有审批权限
  358. if approvalRecord.NodeType != "check" {
  359. err = errors.New("当前账号没有审批权限")
  360. return
  361. }
  362. //操作人
  363. opUserId := opUser.AdminId
  364. //opUserName := opUser.RealName
  365. //操作权限校验
  366. if opUser.RoleTypeCode != approvalRecord.ApproveRoleTypeCode {
  367. err = errors.New("当前账号没有审批权限")
  368. return
  369. }
  370. if approvalRecord.ApproveUserId > 0 && approvalRecord.ApproveUserId != opUserId {
  371. err = errors.New("当前账号没有审批权限,需要指定人操作")
  372. return
  373. }
  374. //审批单状态判断
  375. if approvalInfo.Status != "待审批" {
  376. err = errors.New("审批单状态异常,不允许审批,当前审批单状态:" + approvalInfo.Status)
  377. return
  378. }
  379. //用印状态判断
  380. if sealInfo.Status != "待审批" {
  381. err = errors.New("用印状态异常,不允许审批,当前用印状态:" + sealInfo.Status)
  382. return
  383. }
  384. err = approvalInfo.Approved(approvalInfo, approvalRecord, approvedRemark)
  385. if err != nil {
  386. return
  387. }
  388. // 操作日志
  389. err = seal.AddSealOperationRecord(sealInfo.SealId, opUser.AdminId, approvalRecord.ContractApprovalRecordId, "approved", opUser.RealName, "通过审批", "")
  390. if err != nil {
  391. err = errors.New("新增用印日志失败")
  392. return
  393. }
  394. //添加操作日志
  395. //remark := "审批通过"
  396. //_ = contract_operation_record.AddContractOperationRecord(contractInfo.ContractId, opUserId, approvalRecord.ContractApprovalRecordId, "approval", opUserName, remark)
  397. //发送信息给所有抄送人
  398. content := sealInfo.CompanyName + " 用印已审核"
  399. //go messageToAllCcUser(opUserId, approvalRecord.ContractApprovalId, 2, 2, sealInfo.CompanyName, content)
  400. //如果下一个节点属于结束节点,那么通知对应的销售
  401. if approvalRecord.NextNodeId == 0 {
  402. //待办通知(通知销售已经审核通过了)
  403. {
  404. content := sealInfo.CompanyName + " 用印已审核"
  405. approvalSysUser, _ := admin.GetAdminById(sealInfo.UserId)
  406. go services.AddCompanyApprovalMessage(opUserId, sealInfo.UserId, 0, approvalRecord.ContractApprovalRecordId, 2, sourceType, 2, sealInfo.CompanyName, content, content, approvalSysUser.Mobile, "")
  407. }
  408. } else {
  409. //获取下级节点信息
  410. flowNodeInfo, tmpErr := approval_flow_node.GetByNodeId(approvalRecord.NextNodeId)
  411. if tmpErr != nil {
  412. err = tmpErr
  413. return
  414. }
  415. //如果该级节点是抄送类型,那么需要将该节点给处理掉
  416. if flowNodeInfo.NodeType == "cc" {
  417. go approvedByCc(approvedRemark, approvalRecord)
  418. } else {
  419. //发送消息下级审批人
  420. go messageToNodeUser(approvalRecord.NextNodeId, sealInfo.UserId, approvalInfo.ContractApprovalId, 1, 1, sealInfo.CompanyName, content)
  421. }
  422. }
  423. return
  424. }
  425. //审批通过(抄送节点)
  426. func approvedByCc(approvedRemark string, sourceApprovalRecord *contract_approval_record.ContractApprovalRecord) (err error) {
  427. //下个流程节点id
  428. nextNodeId := 0
  429. //获取审批单中抄送节点的所有数据列表
  430. approvalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractIdAndNode(sourceApprovalRecord.ContractApprovalId, sourceApprovalRecord.NextNodeId)
  431. if err != nil {
  432. return
  433. }
  434. //遍历所有的抄送单
  435. for _, approvalRecord := range approvalRecordList {
  436. nextNodeId = approvalRecord.NextNodeId
  437. //审批流状态判断
  438. if approvalRecord.Status != "待审批" {
  439. err = errors.New("审批流状态异常,不允许审批,当前审批流状态:" + approvalRecord.Status)
  440. return
  441. }
  442. //判断是否审批类型,如果不是审批类型,那么就没有审批权限
  443. if approvalRecord.NodeType != "cc" {
  444. err = errors.New("当前账号不是抄送权限")
  445. return
  446. }
  447. }
  448. //获取审批单详情
  449. approvalInfo, err := contract_approval.GetContractApprovalById(sourceApprovalRecord.ContractApprovalId)
  450. if err != nil {
  451. return
  452. }
  453. //获取用印信息
  454. sealInfo, err := seal.GetSealInfoById(approvalInfo.ContractId)
  455. if err != nil {
  456. return
  457. }
  458. //if contractApprovalRecord
  459. err = approvalInfo.ApprovedByCc(approvalInfo, approvalRecordList, approvedRemark, nextNodeId)
  460. if err != nil {
  461. return
  462. }
  463. content := sealInfo.CompanyName + " 用印已审核"
  464. //发送消息给抄送人
  465. go messageToNodeUser(approvalRecordList[0].NodeId, sealInfo.UserId, approvalInfo.ContractApprovalId, 2, 2, sealInfo.CompanyName, content)
  466. //如果下一个节点属于结束节点,那么通知对应的销售
  467. if nextNodeId == 0 {
  468. //待办通知
  469. {
  470. content = sealInfo.CompanyName + " 用印已审核"
  471. approvalSysUser, _ := admin.GetAdminById(sealInfo.UserId)
  472. go services.AddCompanyApprovalMessage(sourceApprovalRecord.ApproveUserId, sealInfo.UserId, 0, sourceApprovalRecord.ContractApprovalRecordId, 2, sourceType, 2, sealInfo.CompanyName, content, content, approvalSysUser.Mobile, "")
  473. }
  474. } else {
  475. //获取下级节点信息
  476. flowNodeInfo, tmpErr := approval_flow_node.GetByNodeId(nextNodeId)
  477. if tmpErr != nil {
  478. err = tmpErr
  479. return
  480. }
  481. //如果下级节点是抄送类型,那么还是需要处理抄送节点逻辑
  482. if flowNodeInfo.NodeType == "cc" {
  483. go approvedByCc(approvedRemark, sourceApprovalRecord)
  484. } else {
  485. //如果下级级节点是审批类型
  486. //发送消息下级审批人
  487. go messageToNodeUser(nextNodeId, sealInfo.UserId, approvalInfo.ContractApprovalId, 1, 1, sealInfo.CompanyName, approvalInfo.ApplyContent)
  488. }
  489. }
  490. return
  491. }
  492. //抄送信息给用户(根据节点来推送)
  493. func messageToNodeUser(flowNodeId, createUserId, contractApprovalId, messageType, approvalStatus int, companyName, content string) (err error) {
  494. defer func() {
  495. if err != nil {
  496. //go utils.SendEmail("抄送信息给用户失败"+time.Now().Format("2006-01-02 15:04:05"), ";Err:"+err.Error(), utils.EmailSendToUsers)
  497. go alarm_msg.SendAlarmMsg("抄送信息给用户失败:"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  498. utils.FileLog.Info("抄送信息给用户失败,Err:%s,%s", err.Error())
  499. }
  500. }()
  501. //获取审批单中抄送节点的所有数据列表
  502. contractApprovalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractIdAndNode(contractApprovalId, flowNodeId)
  503. if err != nil {
  504. return
  505. }
  506. err = messageToUser(contractApprovalRecordList, createUserId, messageType, approvalStatus, companyName, content)
  507. return
  508. }
  509. //发送信息给所有抄送人
  510. // @param createUserId 消息发起人
  511. // @param contractApprovalId 审批单id
  512. // @param messageType 消息类型:1:申请消息,2:审批结果
  513. // @param approvalStatus 审批状态:1:待审批,2:已审批,3:已驳回"
  514. // @param companyName 企业客户名称
  515. // @param content 消息内容
  516. func messageToAllCcUser(createUserId, contractApprovalId, messageType, approvalStatus int, companyName, content string) (err error) {
  517. //获取审批单中抄送节点的所有数据列表
  518. contractApprovalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalId(contractApprovalId)
  519. if err != nil {
  520. return
  521. }
  522. err = messageToUser(contractApprovalRecordList, createUserId, messageType, approvalStatus, companyName, content)
  523. return
  524. }
  525. //抄送信息给用户(发送给所有抄送人)
  526. // @param createUserId 待审批、抄送记录
  527. // @param createUserId 消息发起人
  528. // @param contractApprovalId 审批单id
  529. // @param messageType 消息类型:1:申请消息,2:审批结果
  530. // @param approvalStatus 审批状态:1:待审批,2:已审批,3:已驳回"
  531. // @param companyName 企业客户名称
  532. // @param content 消息内容
  533. func messageToUser(contractApprovalRecordList []*contract_approval_record.ContractApprovalRecord, createUserId, messageType, approvalStatus int, companyName, content string) (err error) {
  534. for _, contractApprovalRecord := range contractApprovalRecordList {
  535. sysUserMobile := ""
  536. sysUser, _ := admin.GetAdminById(contractApprovalRecord.ApproveUserId)
  537. if sysUser != nil {
  538. sysUserMobile = sysUser.Mobile
  539. }
  540. //接收人,就是审批记录里面的待审核人(抄送人)
  541. receiveUserId := contractApprovalRecord.ApproveUserId
  542. go services.AddCompanyApprovalMessage(createUserId, receiveUserId, 0, contractApprovalRecord.ContractApprovalRecordId, messageType, sourceType, approvalStatus, companyName, content, content, sysUserMobile, "")
  543. }
  544. return
  545. }