seal.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package seal
  2. import (
  3. "hongze/hz_crm_api/controllers"
  4. "hongze/hz_crm_api/models"
  5. contractService "hongze/hz_crm_api/services/contract"
  6. "hongze/hz_crm_api/services/seal"
  7. "path"
  8. "strconv"
  9. )
  10. // 用印管理
  11. type SealController struct {
  12. controllers.BaseAuthController
  13. }
  14. // 上传签回附件
  15. // @Title 上传签回附件
  16. // @Description 上传签回附件
  17. // @Param request body request.SealUploadCheckBackFileReq true "type json string"
  18. // @Success 200 上传成功
  19. // @router /uploadCheckBackFile [post]
  20. func (this *SealController) UploadCheckBackFile() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. sysUser := this.SysUser
  27. if sysUser == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,SysUser is Empty"
  30. br.Ret = 408
  31. return
  32. }
  33. sealIdStr := this.Ctx.Request.Form.Get("SealId")
  34. if sealIdStr == "" {
  35. br.Msg = "用印ID丢失!"
  36. br.ErrMsg = "用印ID丢失!"
  37. return
  38. }
  39. sealId, err := strconv.Atoi(sealIdStr)
  40. if err != nil {
  41. br.Msg = "用印ID异常!"
  42. br.ErrMsg = "用印ID异常,Err:" + err.Error()
  43. return
  44. }
  45. fileMulti, h, err := this.GetFile("file")
  46. if err != nil {
  47. br.Msg = "获取资源信息失败"
  48. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  49. return
  50. }
  51. // 用印ID
  52. if sealId <= 0 {
  53. br.Msg = "请传入用印编号!"
  54. br.ErrMsg = "请传入用印编号"
  55. return
  56. }
  57. ext := path.Ext(h.Filename)
  58. sealInfo, err := seal.UploadCheckBackFileFromSeal(sealId, ext, fileMulti, sysUser)
  59. if err != nil {
  60. br.Msg = "更新签回附件失败!"
  61. br.ErrMsg = "更新签回附件失败,Err:" + err.Error()
  62. return
  63. }
  64. // 如果是系统合同,那么需要去更新系统的签回附件
  65. if sealInfo.ContractId > 0 {
  66. err = contractService.UploadCheckBackFileFromSeal(sealInfo.ContractId, sealInfo.CheckBackFileUrl, sysUser)
  67. if err != nil {
  68. br.Msg = "更新系统合同状态失败!"
  69. br.ErrMsg = "更新系统合同状态失败,Err:" + err.Error()
  70. return
  71. }
  72. }
  73. br.Ret = 200
  74. br.Success = true
  75. br.Msg = "上传成功"
  76. }