approval.go 21 KB

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