seal.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package seal
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hz_crm_api/models/contract"
  6. "hongze/hz_crm_api/utils"
  7. "time"
  8. )
  9. // Seal 用印结构体
  10. type Seal struct {
  11. SealId int `orm:"column(seal_id);pk"`
  12. Code string `description:"用印编号,长度32位"`
  13. UserId int `description:"申请人id"`
  14. UserName string `description:"申请人名称"`
  15. Use string `description:"用印用途,枚举值:'销售合同', '渠道合同', '付款通知函', '招投标', '战略合作协议';默认:销售合同"`
  16. CompanyName string `description:"客户名称,甲方名称,长度32位"`
  17. UseCompanyName string `description:"实际使用方客户名称,长度32位"`
  18. CreditCode string `description:"社会统一信用代码,长度64位"`
  19. ServiceType string `description:"业务类型,枚举值:'新签合同','续约合同','补充协议';默认:新签合同"`
  20. SealType string `description:"加盖印章类型,枚举值:'合同章', '公章', '法人章';默认:合同章"`
  21. Status string `description:"合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已签回'"`
  22. Remark string `description:"补充内容,长度255位"`
  23. ApprovalRemark string `description:"审核备注"`
  24. FileUrl string `description:"文件附件地址"`
  25. CheckBackFileUrl string `description:"已签回的文件地址"`
  26. FileNum int `description:"文件附件份数"`
  27. ContractId int `description:"系统合同id"`
  28. IsDelete int `json:"-" description:"是否已经删除,0:未删除,1:已删除"`
  29. ApproveTime time.Time `description:"审批时间"`
  30. InvalidTime time.Time `description:"作废时间"`
  31. ModifyTime time.Time `description:"最近一次修改时间"`
  32. CreateTime time.Time `description:"添加时间"`
  33. CheckBackFileTime time.Time `description:"签回用印附件时间"`
  34. }
  35. var EnumUse = []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议", "代付合同", "总对总协议"}
  36. var EnumServiceType = []string{"新签合同", "续约合同", "补充协议", "代付合同"}
  37. //var EnumSealType = []string{"合同章", "公章", "法人章"}
  38. // GetSealInfoById 根据用印id获取合同信息
  39. func GetSealInfoById(sealId int) (sealInfo *Seal, err error) {
  40. o := orm.NewOrm()
  41. sql := `select * from seal where seal_id = ? `
  42. err = o.Raw(sql, sealId).QueryRow(&sealInfo)
  43. return
  44. }
  45. // GetSealInfoByContractId 根据合同id获取合同信息
  46. func GetSealInfoByContractId(sealId int) (sealInfo *Seal, err error) {
  47. o := orm.NewOrm()
  48. sql := `select * from seal where contract_id = ? and status in ("已审批","已签回") order by seal_id asc limit 1`
  49. err = o.Raw(sql, sealId).QueryRow(&sealInfo)
  50. return
  51. }
  52. // AddSeal 用印添加
  53. func AddSeal(sealInfo *Seal) (err error) {
  54. o := orm.NewOrm()
  55. //用印数据入库
  56. sealId, err := o.Insert(sealInfo)
  57. if err != nil {
  58. return
  59. }
  60. sealInfo.SealId = int(sealId)
  61. return
  62. }
  63. // Update 更新用印信息
  64. func (seal *Seal) Update(cols []string) (err error) {
  65. o := orm.NewOrm()
  66. _, err = o.Update(seal, cols...)
  67. return
  68. }
  69. // DeleteSeal 删除用印
  70. func DeleteSeal(sealInfo *Seal) (err error) {
  71. sealInfo.IsDelete = 1
  72. sealInfo.ModifyTime = time.Now()
  73. sealInfo.InvalidTime = time.Now()
  74. err = sealInfo.Update([]string{"IsDelete", "ModifyTime", "InvalidTime"})
  75. return
  76. }
  77. // Invalid 作废用印
  78. func Invalid(sealInfo *Seal) (err error) {
  79. sealInfo.Status = "已作废"
  80. sealInfo.ModifyTime = time.Now()
  81. sealInfo.InvalidTime = time.Now()
  82. //修改用印数据入库
  83. err = sealInfo.Update([]string{"Status", "ModifyTime", "InvalidTime"})
  84. return
  85. }
  86. // GetSealCode 生成合同编号
  87. func GetSealCode() (code string, err error) {
  88. var num int
  89. o := orm.NewOrm()
  90. today := utils.GetToday(utils.FormatDate)
  91. sql := `SELECT COUNT(1) AS num FROM seal where create_time>=?`
  92. err = o.Raw(sql, today).QueryRow(&num)
  93. if err != nil {
  94. return
  95. }
  96. code = "HZ" + time.Now().Format("20060102") + fmt.Sprintf("%03d", num)
  97. return
  98. }
  99. type CompanyNameList struct {
  100. CompanyName string `description:"客户名称,甲方名称,长度32位"`
  101. }
  102. // GetCompanyNameList 获取客户名称列表数据
  103. func GetCompanyNameList(name string) (list []*CompanyNameList, err error) {
  104. o := orm.NewOrm()
  105. sql := `select * from seal where company_name like '%` + name + `%' group by company_name order by modify_time desc `
  106. _, err = o.Raw(sql).QueryRows(&list)
  107. return
  108. }
  109. // GetCompanyNameListV2 获取客户名称列表数据V2版本
  110. func GetCompanyNameListV2(childCondition, condition string, childPars, pars []interface{}) (list []*CompanyNameList, err error) {
  111. o := orm.NewOrm()
  112. sql := `SELECT c.company_name,a.modify_time from contract_approval a
  113. join
  114. ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 and approval_type = "seal" `
  115. sql += childCondition
  116. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  117. JOIN seal c ON c.seal_id = a.contract_id
  118. JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id
  119. WHERE c.is_delete = 0 AND a.approval_type="seal" `
  120. sql += condition
  121. sql += ` group by company_name order by modify_time desc`
  122. _, err = o.Raw(sql, childPars, pars).QueryRows(&list)
  123. return
  124. }
  125. // GetListCount 获取用印列表数据数量
  126. func GetListCount(condition string, pars []interface{}) (count int, err error) {
  127. o := orm.NewOrm()
  128. sql := "select count(*) AS COUNT from seal where 1=1 AND is_delete = 0 "
  129. sql += condition
  130. err = o.Raw(sql, pars).QueryRow(&count)
  131. return
  132. }
  133. // GetList 获取用印列表
  134. func GetList(condition string, pars []interface{}, startSize, pageSize int) (list []*Seal, err error) {
  135. o := orm.NewOrm()
  136. sql := "select * from seal where 1=1 AND is_delete = 0 "
  137. sql += condition
  138. sql += ` order by modify_time desc LIMIT ?,? `
  139. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  140. return
  141. }
  142. type SealApprovalItem struct {
  143. ContractApprovalId int `description:"审批单ID"`
  144. ContractId int `description:"合同ID"`
  145. ContractApprovalRecordId int `description:"审批流ID"`
  146. //ContractCode string `description:"合同编号"`
  147. Use string `description:"用印用途,枚举值:'销售合同','渠道合同','付款通知函','招投标','战略合作协议'"`
  148. ContractType string `description:"合同类型,枚举值:'新签合同','续约合同','补充协议','代付合同'"`
  149. Status string `description:"合同状态,枚举值:待审批','已审批','已驳回','已撤回','已签回',默认待审批"`
  150. ApproveStatus string `json:"-" description:"审批单状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
  151. ApplyContent string `description:"申请内容"`
  152. ApplyUserId int `description:"申请人ID"`
  153. ApplyUserName string `description:"申请人名称"`
  154. ContractDetail string `json:"-" description:"提交审批时的合同信息;用印快照"`
  155. ContractInfo contract.ContractDetail `json:"-" description:"提交审批时的合同信息;用印快照"`
  156. ApproveRemark string `description:"审核备注"`
  157. SealType string `description:"用印类型"`
  158. CompanyName string `description:"客户名称"`
  159. FileUrl string `description:"合同下载地址"`
  160. CurrNodeId int `description:"当前审批节点id"`
  161. StartNodeId int `description:"开始审批节点id"`
  162. //UserId int `description:"申请人id"`
  163. //UserName string `description:"申请人名称"`
  164. SealId int `description:"用印审批ID"`
  165. CreateTime time.Time `description:"发起审批的时间"`
  166. ModifyTime time.Time `description:"最后一次修改的时间"`
  167. ApproveTime time.Time `description:"审批时间"`
  168. InvalidTime time.Time `description:"作废时间"`
  169. CheckBackFileUrl string `description:"签回附件地址"`
  170. CheckBackFileTime time.Time `description:"签回用印附件时间"`
  171. CreditCode string `description:"社会信用码"`
  172. CreateTimeStr string `description:"发起审批的时间(字符串)"`
  173. ModifyTimeStr string `description:"最后一次修改的时间(字符串)"`
  174. ApproveTimeStr string `description:"审批时间(字符串)"`
  175. InvalidTimeStr string `description:"作废时间(字符串)"`
  176. CheckBackFileTimeStr string `description:"签回用印附件时间(字符串)"`
  177. ContractCode string `description:"合同编码"`
  178. }
  179. // GetSealApprovalListByWhere 获取用印审批列表-分页
  180. func GetSealApprovalListByWhere(condition, joinCondition string, pars []interface{}, startSize, pageSize int) (list []*SealApprovalItem, total int, err error) {
  181. o := orm.NewOrm()
  182. fields := `a.contract_approval_id,c.contract_id,a.apply_content,a.approve_remark,a.apply_user_id,a.apply_user_name,a.curr_node_id,a.start_node_id,c.create_time,a.modify_time,a.status approval_status,
  183. c.status,c.seal_id,c.seal_type,c.service_type contract_type,c.use,c.company_name,c.file_url,c.approve_time,c.invalid_time,c.code,c.credit_code,c.check_back_file_time,c.check_back_file_url`
  184. sql := `SELECT ` + fields + ` from contract_approval a JOIN ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 and approval_type = "seal" `
  185. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  186. JOIN seal c ON c.seal_id = a.contract_id
  187. JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id ` + joinCondition + `
  188. WHERE c.is_delete = 0 AND a.approval_type="seal" `
  189. sql += condition
  190. sql += ` group by c.seal_id order by c.create_time desc`
  191. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  192. err = o.Raw(totalSql, pars).QueryRow(&total)
  193. if err != nil {
  194. return
  195. }
  196. sql += ` LIMIT ?,? `
  197. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  198. return
  199. }