seal.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package seal
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mobile_admin/models/tables/seal"
  6. "hongze/hongze_mobile_admin/utils"
  7. "strings"
  8. "time"
  9. )
  10. //添加用印
  11. func AddSeal(userId, contractId, fileNum int, userName, use, useCompanyName, companyName, creditCode, serviceType, sealType, remark, fileUrl string) (sealInfo *seal.Seal, err error) {
  12. useList := []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议"}
  13. serviceTypeList := []string{"新增业务", "续约业务", "补充协议"}
  14. sealTypeList := []string{"合同章", "公章", "法人章"}
  15. if !strings.Contains(strings.Join(useList, ","), use) {
  16. err = errors.New("用印用途异常")
  17. return
  18. }
  19. if !strings.Contains(strings.Join(serviceTypeList, ","), serviceType) {
  20. err = errors.New("业务类型异常")
  21. return
  22. }
  23. if !strings.Contains(strings.Join(sealTypeList, ","), sealType) {
  24. err = errors.New("加盖印章类型异常")
  25. return
  26. }
  27. sealCode, err := seal.GetSealCode()
  28. if err != nil {
  29. return
  30. }
  31. sealInfo = &seal.Seal{
  32. Code: sealCode,
  33. UserId: userId,
  34. UserName: userName,
  35. Use: use,
  36. CompanyName: companyName,
  37. UseCompanyName: useCompanyName,
  38. CreditCode: creditCode,
  39. ServiceType: serviceType,
  40. SealType: sealType,
  41. Status: "待提交",
  42. Remark: remark,
  43. FileUrl: fileUrl,
  44. FileNum: fileNum,
  45. ContractId: contractId,
  46. ModifyTime: time.Now(),
  47. CreateTime: time.Now(),
  48. }
  49. err = seal.AddSeal(sealInfo)
  50. return
  51. }
  52. //修改用印
  53. func Edit(sealId, userId, contractId, fileNum int, use, companyName, userCompanyName, creditCode, serviceType, sealType, remark, fileUrl string) (sealInfo *seal.Seal, err error) {
  54. useList := []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议"}
  55. serviceTypeList := []string{"新增业务", "续约业务", "补充协议"}
  56. sealTypeList := []string{"合同章", "公章", "法人章"}
  57. if !strings.Contains(strings.Join(useList, ","), use) {
  58. err = errors.New("用印用途异常")
  59. return
  60. }
  61. if !strings.Contains(strings.Join(serviceTypeList, ","), serviceType) {
  62. err = errors.New("业务类型异常")
  63. return
  64. }
  65. if !strings.Contains(strings.Join(sealTypeList, ","), sealType) {
  66. err = errors.New("加盖印章类型异常")
  67. return
  68. }
  69. //查询当前合同信息
  70. sealInfo, err = seal.GetSealInfoById(sealId)
  71. if err != nil {
  72. if err.Error() == utils.ErrNoRow() {
  73. err = errors.New(fmt.Sprint("根据用印编号:", sealId, " 找不到该用印"))
  74. }
  75. return
  76. }
  77. if sealInfo.UserId != userId {
  78. err = errors.New("当前账号无操作权限")
  79. return
  80. }
  81. ignoreStatus := []string{"待提交", "已撤回", "已驳回"}
  82. if !strings.Contains(strings.Join(ignoreStatus, ","), sealInfo.Status) {
  83. err = errors.New("用印状态异常,不允许修改,当前用印状态:" + sealInfo.Status)
  84. return
  85. }
  86. //sealId,userId int, userName, use, companyName, creditCode, serviceType, sealType, remark, fileUrl string
  87. sealInfo.Use = use
  88. sealInfo.CompanyName = companyName
  89. sealInfo.UseCompanyName = userCompanyName
  90. sealInfo.CreditCode = creditCode
  91. sealInfo.ServiceType = serviceType
  92. sealInfo.SealType = sealType
  93. sealInfo.Remark = remark
  94. sealInfo.FileUrl = fileUrl
  95. sealInfo.FileNum = fileNum
  96. sealInfo.ContractId = contractId
  97. sealInfo.ModifyTime = time.Now()
  98. sealInfo.Status = "待提交" //用印状态
  99. err = sealInfo.Update([]string{"Use", "CompanyName", "CreditCode", "ServiceType", "SealType", "Remark", "FileUrl", "ModifyTime", "Status"})
  100. return
  101. }