seal.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. AffiliatedCompany string `description:"归属公司"`
  34. }
  35. var EnumUse = []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议", "代付合同", "总对总协议"}
  36. var EnumServiceType = []string{"新签合同", "续约合同", "补充协议", "代付合同"}
  37. //GetSealInfoById 根据用印id获取合同信息
  38. func GetSealInfoById(sealId int) (sealInfo *Seal, err error) {
  39. o := orm.NewOrm()
  40. sql := `select * from seal where seal_id = ? `
  41. err = o.Raw(sql, sealId).QueryRow(&sealInfo)
  42. return
  43. }
  44. //GetSealInfoByContractId 根据合同id获取合同信息
  45. func GetSealInfoByContractId(sealId int) (sealInfo *Seal, err error) {
  46. o := orm.NewOrm()
  47. sql := `select * from seal where contract_id = ? and status in ("已审批","已签回") order by seal_id asc limit 1`
  48. err = o.Raw(sql, sealId).QueryRow(&sealInfo)
  49. return
  50. }
  51. //AddSeal 用印添加
  52. func AddSeal(sealInfo *Seal) (err error) {
  53. o := orm.NewOrm()
  54. //用印数据入库
  55. sealId, err := o.Insert(sealInfo)
  56. if err != nil {
  57. return
  58. }
  59. sealInfo.SealId = int(sealId)
  60. return
  61. }
  62. //Update 更新用印信息
  63. func (seal *Seal) Update(cols []string) (err error) {
  64. o := orm.NewOrm()
  65. _, err = o.Update(seal, cols...)
  66. return
  67. }
  68. //DeleteSeal 删除用印
  69. func DeleteSeal(sealInfo *Seal) (err error) {
  70. sealInfo.IsDelete = 1
  71. sealInfo.ModifyTime = time.Now()
  72. sealInfo.InvalidTime = time.Now()
  73. err = sealInfo.Update([]string{"IsDelete", "ModifyTime", "InvalidTime"})
  74. return
  75. }
  76. //Invalid 作废用印
  77. func Invalid(sealInfo *Seal) (err error) {
  78. sealInfo.Status = "已作废"
  79. sealInfo.ModifyTime = time.Now()
  80. sealInfo.InvalidTime = time.Now()
  81. //修改用印数据入库
  82. err = sealInfo.Update([]string{"Status", "ModifyTime", "InvalidTime"})
  83. return
  84. }
  85. //GetSealCode 生成合同编号
  86. func GetSealCode() (code string, err error) {
  87. var num int
  88. o := orm.NewOrm()
  89. today := utils.GetToday(utils.FormatDate)
  90. sql := `SELECT COUNT(1) AS num FROM seal where create_time>=?`
  91. err = o.Raw(sql, today).QueryRow(&num)
  92. if err != nil {
  93. return
  94. }
  95. code = "HZ" + time.Now().Format("20060102") + fmt.Sprintf("%03d", num)
  96. return
  97. }
  98. type CompanyNameList struct {
  99. CompanyName string `description:"客户名称,甲方名称,长度32位"`
  100. }
  101. //GetCompanyNameList 获取客户名称列表数据
  102. func GetCompanyNameList(name string) (list []*CompanyNameList, err error) {
  103. o := orm.NewOrm()
  104. sql := `select * from seal where company_name like '%` + name + `%' group by company_name order by modify_time desc `
  105. _, err = o.Raw(sql).QueryRows(&list)
  106. return
  107. }
  108. //GetCompanyNameListV2 获取客户名称列表数据V2版本
  109. func GetCompanyNameListV2(childCondition, condition string, childPars, pars []interface{}) (list []*CompanyNameList, err error) {
  110. o := orm.NewOrm()
  111. sql := `SELECT c.company_name,a.modify_time from contract_approval a
  112. join
  113. ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 AND approval_type="seal" `
  114. sql += childCondition
  115. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  116. JOIN seal c ON c.seal_id = a.contract_id
  117. JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id
  118. WHERE c.is_delete = 0 AND a.approval_type="seal" `
  119. sql += condition
  120. sql += ` group by company_name order by modify_time desc`
  121. _, err = o.Raw(sql, childPars, pars).QueryRows(&list)
  122. return
  123. }
  124. //GetListCount 获取用印列表数据数量
  125. func GetListCount(condition string, pars []interface{}) (count int, err error) {
  126. o := orm.NewOrm()
  127. sql := "select count(*) AS COUNT from seal where 1=1 AND is_delete = 0 "
  128. sql += condition
  129. err = o.Raw(sql, pars).QueryRow(&count)
  130. return
  131. }
  132. //GetList 获取用印列表
  133. func GetList(condition string, pars []interface{}, startSize, pageSize int) (list []*Seal, err error) {
  134. o := orm.NewOrm()
  135. sql := "select * from seal where 1=1 AND is_delete = 0 "
  136. sql += condition
  137. sql += ` order by modify_time desc LIMIT ?,? `
  138. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  139. return
  140. }