contract.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package contract
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mobile_admin/models/custom"
  6. contractCustom "hongze/hongze_mobile_admin/models/custom/contract"
  7. "hongze/hongze_mobile_admin/models/tables/contract"
  8. "hongze/hongze_mobile_admin/models/tables/contract_operation_record"
  9. "hongze/hongze_mobile_admin/models/tables/contract_service_detail"
  10. "hongze/hongze_mobile_admin/utils"
  11. )
  12. //作废合同
  13. func InvalidContract(contractId int, opUser *custom.AdminWx) (err error) {
  14. //查询当前合同信息
  15. nowContract, err := contract.GetContractById(contractId)
  16. if err != nil {
  17. if err.Error() == utils.ErrNoRow() {
  18. err = errors.New(fmt.Sprint("根据合同编号:", contractId, " 找不到初始合同"))
  19. }
  20. return
  21. }
  22. if nowContract.SellerId != opUser.AdminId && opUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
  23. err = errors.New("当前账号无操作权限")
  24. return
  25. }
  26. if nowContract.Status != "已审批" {
  27. err = errors.New("合同状态异常,不允许作废,当前合同状态:" + nowContract.Status)
  28. return
  29. }
  30. //如果删除状态 >0,那么代表已经被删除了
  31. if nowContract.IsDelete > 0 {
  32. err = errors.New("该合同已删除")
  33. return
  34. }
  35. //合同作废
  36. err = contract.InvalidContract(nowContract)
  37. if err != nil {
  38. return
  39. }
  40. //添加操作日志
  41. remark := "作废合同模板"
  42. _ = contract_operation_record.AddContractOperationRecord(nowContract.ContractId, opUser.AdminId, 0, "invalid", opUser.RealName, remark)
  43. return
  44. }
  45. //根据id获取合同详情(包含服务)
  46. func GetContractDetail(contractId int) (contractDetail *contract.ContractDetail, err error) {
  47. contractDetail, err = contract.GetContractDetailById(contractId)
  48. if err != nil {
  49. if err.Error() == utils.ErrNoRow() {
  50. err = errors.New("找不到该合同")
  51. }
  52. return
  53. }
  54. serviceList, err := contractCustom.GetContractServiceAndDetailList(contractId)
  55. if err != nil {
  56. err = errors.New(fmt.Sprint("查找合同服务异常", err))
  57. return
  58. }
  59. for i := 0; len(serviceList) > i; i++ {
  60. if serviceList[i].HasDetail == "是" {
  61. list, detailErr := contract_service_detail.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
  62. if detailErr != nil {
  63. err = errors.New(fmt.Sprint("查找合同服务详情异常", detailErr))
  64. return
  65. }
  66. serviceList[i].DetailList = list
  67. }
  68. }
  69. contractDetail.Service = serviceList
  70. return
  71. }
  72. //上传签回合同附件
  73. func UploadCheckBackFile(contractId int, fileUrl string, opUser *custom.AdminWx) (err error) {
  74. //获取合同信息
  75. contractInfo, err := contract.GetContractById(contractId)
  76. if err != nil {
  77. return
  78. }
  79. //合同状态判断
  80. if contractInfo.Status != "已审批" && contractInfo.Status != "已签回" {
  81. err = errors.New("合同状态异常,不允许上传签回合同附件,当前合同状态:" + contractInfo.Status)
  82. return
  83. }
  84. contractInfo.CheckBackFileUrl = fileUrl
  85. contractInfo.Status = "已签回"
  86. var updateCol = []string{"CheckBackFileUrl", "Status"}
  87. contractInfo.Update(updateCol)
  88. //添加操作日志
  89. remark := "上传签回合同附件"
  90. _ = contract_operation_record.AddContractOperationRecord(contractInfo.ContractId, opUser.AdminId, 0, "upload", opUser.RealName, remark)
  91. return
  92. }