seal.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package seal
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_mobile_admin/utils"
  6. "time"
  7. )
  8. //Seal 用印结构体
  9. type Seal struct {
  10. SealId int `orm:"column(seal_id);pk"`
  11. Code string `description:"用印编号,长度32位"`
  12. UserId int `description:"申请人id"`
  13. UserName string `description:"申请人名称"`
  14. Use string `description:"用印用途,枚举值:'销售合同', '渠道合同', '付款通知函', '招投标', '战略合作协议';默认:销售合同"`
  15. CompanyName string `description:"客户名称,甲方名称,长度32位"`
  16. UseCompanyName string `description:"实际使用方客户名称,长度32位"`
  17. CreditCode string `description:"社会统一信用代码,长度64位"`
  18. ServiceType string `description:"业务类型,枚举值:'新签合同','续约合同','补充协议';默认:新签合同"`
  19. SealType string `description:"加盖印章类型,枚举值:'合同章', '公章', '法人章';默认:合同章"`
  20. Status string `description:"合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已签回'"`
  21. Remark string `description:"补充内容,长度255位"`
  22. ApprovalRemark string `description:"审核备注"`
  23. FileUrl string `description:"文件附件地址"`
  24. CheckBackFileUrl string `description:"已签回的文件地址"`
  25. FileNum int `description:"文件附件份数"`
  26. ContractId int `description:"系统合同id"`
  27. IsDelete int `json:"-" description:"是否已经删除,0:未删除,1:已删除"`
  28. ApproveTime time.Time `description:"审批时间"`
  29. InvalidTime time.Time `description:"作废时间"`
  30. ModifyTime time.Time `description:"最近一次修改时间"`
  31. CreateTime time.Time `description:"添加时间"`
  32. CheckBackFileTime time.Time `description:"签回用印附件时间"`
  33. }
  34. var EnumUse = []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议", "代付合同", "总对总协议"}
  35. var EnumServiceType = []string{"新签合同", "续约合同", "补充协议", "代付合同"}
  36. //GetSealInfoById 根据用印id获取合同信息
  37. func GetSealInfoById(sealId int) (sealInfo *Seal, err error) {
  38. o := orm.NewOrm()
  39. sql := `select * from seal where seal_id = ? `
  40. err = o.Raw(sql, sealId).QueryRow(&sealInfo)
  41. return
  42. }
  43. //GetSealInfoByContractId 根据合同id获取合同信息
  44. func GetSealInfoByContractId(sealId int) (sealInfo *Seal, err error) {
  45. o := orm.NewOrm()
  46. sql := `select * from seal where contract_id = ? and status in ("已审批","已签回") order by seal_id asc limit 1`
  47. err = o.Raw(sql, sealId).QueryRow(&sealInfo)
  48. return
  49. }
  50. //AddSeal 用印添加
  51. func AddSeal(sealInfo *Seal) (err error) {
  52. o := orm.NewOrm()
  53. //用印数据入库
  54. sealId, err := o.Insert(sealInfo)
  55. if err != nil {
  56. return
  57. }
  58. sealInfo.SealId = int(sealId)
  59. return
  60. }
  61. //Update 更新用印信息
  62. func (seal *Seal) Update(cols []string) (err error) {
  63. o := orm.NewOrm()
  64. _, err = o.Update(seal, cols...)
  65. return
  66. }
  67. //DeleteSeal 删除用印
  68. func DeleteSeal(sealInfo *Seal) (err error) {
  69. sealInfo.IsDelete = 1
  70. sealInfo.ModifyTime = time.Now()
  71. sealInfo.InvalidTime = time.Now()
  72. err = sealInfo.Update([]string{"IsDelete", "ModifyTime", "InvalidTime"})
  73. return
  74. }
  75. //Invalid 作废用印
  76. func Invalid(sealInfo *Seal) (err error) {
  77. sealInfo.Status = "已作废"
  78. sealInfo.ModifyTime = time.Now()
  79. sealInfo.InvalidTime = time.Now()
  80. //修改用印数据入库
  81. err = sealInfo.Update([]string{"Status", "ModifyTime", "InvalidTime"})
  82. return
  83. }
  84. //GetSealCode 生成合同编号
  85. func GetSealCode() (code string, err error) {
  86. var num int
  87. o := orm.NewOrm()
  88. today := utils.GetToday(utils.FormatDate)
  89. sql := `SELECT COUNT(1) AS num FROM seal where create_time>=?`
  90. err = o.Raw(sql, today).QueryRow(&num)
  91. if err != nil {
  92. return
  93. }
  94. code = "HZ" + time.Now().Format("20060102") + fmt.Sprintf("%03d", num)
  95. return
  96. }
  97. type CompanyNameList struct {
  98. CompanyName string `description:"客户名称,甲方名称,长度32位"`
  99. }
  100. //GetCompanyNameList 获取客户名称列表数据
  101. func GetCompanyNameList(name string) (list []*CompanyNameList, err error) {
  102. o := orm.NewOrm()
  103. sql := `select * from seal where company_name like '%` + name + `%' group by company_name order by modify_time desc `
  104. _, err = o.Raw(sql).QueryRows(&list)
  105. return
  106. }
  107. //GetCompanyNameListV2 获取客户名称列表数据V2版本
  108. func GetCompanyNameListV2(childCondition, condition string, childPars, pars []interface{}) (list []*CompanyNameList, err error) {
  109. o := orm.NewOrm()
  110. sql := `SELECT c.company_name,a.modify_time from contract_approval a
  111. join
  112. ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 AND approval_type="seal" `
  113. sql += childCondition
  114. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  115. JOIN seal c ON c.seal_id = a.contract_id
  116. JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id
  117. WHERE c.is_delete = 0 AND a.approval_type="seal" `
  118. sql += condition
  119. sql += ` group by company_name order by modify_time desc`
  120. _, err = o.Raw(sql, childPars, pars).QueryRows(&list)
  121. return
  122. }
  123. //GetListCount 获取用印列表数据数量
  124. func GetListCount(condition string, pars []interface{}) (count int, err error) {
  125. o := orm.NewOrm()
  126. sql := "select count(*) AS COUNT from seal where 1=1 AND is_delete = 0 "
  127. sql += condition
  128. err = o.Raw(sql, pars).QueryRow(&count)
  129. return
  130. }
  131. //GetList 获取用印列表
  132. func GetList(condition string, pars []interface{}, startSize, pageSize int) (list []*Seal, err error) {
  133. o := orm.NewOrm()
  134. sql := "select * from seal where 1=1 AND is_delete = 0 "
  135. sql += condition
  136. sql += ` order by modify_time desc LIMIT ?,? `
  137. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  138. return
  139. }