seal.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. AffiliatedCompany string `description:"归属公司"`
  35. }
  36. var EnumUse = []string{"销售合同", "渠道合同", "付款通知函", "招投标", "战略合作协议", "代付合同", "总对总协议"}
  37. var EnumServiceType = []string{"新签合同", "续约合同", "补充协议", "代付合同"}
  38. //var EnumSealType = []string{"合同章", "公章", "法人章"}
  39. // GetSealInfoById 根据用印id获取合同信息
  40. func GetSealInfoById(sealId int) (sealInfo *Seal, err error) {
  41. o := orm.NewOrm()
  42. sql := `select * from seal where seal_id = ? `
  43. err = o.Raw(sql, sealId).QueryRow(&sealInfo)
  44. return
  45. }
  46. // GetSealInfoByContractId 根据合同id获取合同信息
  47. func GetSealInfoByContractId(sealId int) (sealInfo *Seal, err error) {
  48. o := orm.NewOrm()
  49. sql := `select * from seal where contract_id = ? and status in ("已审批","已签回") order by seal_id asc limit 1`
  50. err = o.Raw(sql, sealId).QueryRow(&sealInfo)
  51. return
  52. }
  53. // AddSeal 用印添加
  54. func AddSeal(sealInfo *Seal) (err error) {
  55. o := orm.NewOrm()
  56. //用印数据入库
  57. sealId, err := o.Insert(sealInfo)
  58. if err != nil {
  59. return
  60. }
  61. sealInfo.SealId = int(sealId)
  62. return
  63. }
  64. // Update 更新用印信息
  65. func (seal *Seal) Update(cols []string) (err error) {
  66. o := orm.NewOrm()
  67. _, err = o.Update(seal, cols...)
  68. return
  69. }
  70. // DeleteSeal 删除用印
  71. func DeleteSeal(sealInfo *Seal) (err error) {
  72. sealInfo.IsDelete = 1
  73. sealInfo.ModifyTime = time.Now()
  74. sealInfo.InvalidTime = time.Now()
  75. err = sealInfo.Update([]string{"IsDelete", "ModifyTime", "InvalidTime"})
  76. return
  77. }
  78. // Invalid 作废用印
  79. func Invalid(sealInfo *Seal) (err error) {
  80. sealInfo.Status = "已作废"
  81. sealInfo.ModifyTime = time.Now()
  82. sealInfo.InvalidTime = time.Now()
  83. //修改用印数据入库
  84. err = sealInfo.Update([]string{"Status", "ModifyTime", "InvalidTime"})
  85. return
  86. }
  87. // GetSealCode 生成合同编号
  88. func GetSealCode() (code string, err error) {
  89. var num int
  90. o := orm.NewOrm()
  91. today := utils.GetToday(utils.FormatDate)
  92. sql := `SELECT COUNT(1) AS num FROM seal where create_time>=?`
  93. err = o.Raw(sql, today).QueryRow(&num)
  94. if err != nil {
  95. return
  96. }
  97. code = "HZ" + time.Now().Format("20060102") + fmt.Sprintf("%03d", num)
  98. return
  99. }
  100. type CompanyNameList struct {
  101. CompanyName string `description:"客户名称,甲方名称,长度32位"`
  102. }
  103. // GetCompanyNameList 获取客户名称列表数据
  104. func GetCompanyNameList(name string) (list []*CompanyNameList, err error) {
  105. o := orm.NewOrm()
  106. sql := `select * from seal where company_name like '%` + name + `%' group by company_name order by modify_time desc `
  107. _, err = o.Raw(sql).QueryRows(&list)
  108. return
  109. }
  110. // GetCompanyNameListV2 获取客户名称列表数据V2版本
  111. func GetCompanyNameListV2(childCondition, condition string, childPars, pars []interface{}) (list []*CompanyNameList, err error) {
  112. o := orm.NewOrm()
  113. sql := `SELECT c.company_name,a.modify_time from contract_approval a
  114. join
  115. ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 and approval_type = "seal" `
  116. sql += childCondition
  117. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  118. JOIN seal c ON c.seal_id = a.contract_id
  119. JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id
  120. WHERE c.is_delete = 0 AND a.approval_type="seal" `
  121. sql += condition
  122. sql += ` group by company_name order by modify_time desc`
  123. _, err = o.Raw(sql, childPars, pars).QueryRows(&list)
  124. return
  125. }
  126. // GetListCount 获取用印列表数据数量
  127. func GetListCount(condition string, pars []interface{}) (count int, err error) {
  128. o := orm.NewOrm()
  129. sql := "select count(*) AS COUNT from seal where 1=1 AND is_delete = 0 "
  130. sql += condition
  131. err = o.Raw(sql, pars).QueryRow(&count)
  132. return
  133. }
  134. // GetList 获取用印列表
  135. func GetList(condition string, pars []interface{}, startSize, pageSize int) (list []*Seal, err error) {
  136. o := orm.NewOrm()
  137. sql := "select * from seal where 1=1 AND is_delete = 0 "
  138. sql += condition
  139. sql += ` order by modify_time desc LIMIT ?,? `
  140. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  141. return
  142. }
  143. type SealApprovalItem struct {
  144. ContractApprovalId int `description:"审批单ID"`
  145. ContractId int `description:"合同ID"`
  146. ContractApprovalRecordId int `description:"审批流ID"`
  147. //ContractCode string `description:"合同编号"`
  148. Use string `description:"用印用途,枚举值:'销售合同','渠道合同','付款通知函','招投标','战略合作协议'"`
  149. ContractType string `description:"合同类型,枚举值:'新签合同','续约合同','补充协议','代付合同'"`
  150. Status string `description:"合同状态,枚举值:待审批','已审批','已驳回','已撤回','已签回',默认待审批"`
  151. ApproveStatus string `json:"-" description:"审批单状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
  152. ApplyContent string `description:"申请内容"`
  153. ApplyUserId int `description:"申请人ID"`
  154. ApplyUserName string `description:"申请人名称"`
  155. ContractDetail string `json:"-" description:"提交审批时的合同信息;用印快照"`
  156. ContractInfo contract.ContractDetail `json:"-" description:"提交审批时的合同信息;用印快照"`
  157. ApproveRemark string `description:"审核备注"`
  158. SealType string `description:"用印类型"`
  159. CompanyName string `description:"客户名称"`
  160. FileUrl string `description:"合同下载地址"`
  161. CurrNodeId int `description:"当前审批节点id"`
  162. StartNodeId int `description:"开始审批节点id"`
  163. //UserId int `description:"申请人id"`
  164. //UserName string `description:"申请人名称"`
  165. SealId int `description:"用印审批ID"`
  166. CreateTime time.Time `description:"发起审批的时间"`
  167. ModifyTime time.Time `description:"最后一次修改的时间"`
  168. ApproveTime time.Time `description:"审批时间"`
  169. InvalidTime time.Time `description:"作废时间"`
  170. CheckBackFileUrl string `description:"签回附件地址"`
  171. CheckBackFileTime time.Time `description:"签回用印附件时间"`
  172. CreditCode string `description:"社会信用码"`
  173. CreateTimeStr string `description:"发起审批的时间(字符串)"`
  174. ModifyTimeStr string `description:"最后一次修改的时间(字符串)"`
  175. ApproveTimeStr string `description:"审批时间(字符串)"`
  176. InvalidTimeStr string `description:"作废时间(字符串)"`
  177. CheckBackFileTimeStr string `description:"签回用印附件时间(字符串)"`
  178. ContractCode string `description:"合同编码"`
  179. AffiliatedCompany string `description:"归属公司"`
  180. }
  181. // GetSealApprovalListByWhere 获取用印审批列表-分页
  182. func GetSealApprovalListByWhere(condition, joinCondition string, pars []interface{}, startSize, pageSize int) (list []*SealApprovalItem, total int, err error) {
  183. o := orm.NewOrm()
  184. 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,
  185. 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,c.affiliated_company `
  186. 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" `
  187. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  188. JOIN seal c ON c.seal_id = a.contract_id
  189. JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id ` + joinCondition + `
  190. WHERE c.is_delete = 0 AND a.approval_type="seal" `
  191. sql += condition
  192. sql += ` group by c.seal_id order by c.create_time desc`
  193. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z`
  194. err = o.Raw(totalSql, pars).QueryRow(&total)
  195. if err != nil {
  196. return
  197. }
  198. sql += ` LIMIT ?,? `
  199. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  200. return
  201. }
  202. type SealApprovaExportlItem struct {
  203. ContractApprovalId int `description:"审批单ID"`
  204. ContractId int `description:"合同ID"`
  205. ContractApprovalRecordId int `description:"审批流ID"`
  206. //ContractCode string `description:"合同编号"`
  207. Use string `description:"用印用途,枚举值:'销售合同','渠道合同','付款通知函','招投标','战略合作协议'"`
  208. ContractType string `description:"合同类型,枚举值:'新签合同','续约合同','补充协议','代付合同'"`
  209. Status string `description:"合同状态,枚举值:待审批','已审批','已驳回','已撤回','已签回',默认待审批"`
  210. ApproveStatus string `json:"-" description:"审批单状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
  211. ApplyContent string `description:"申请内容"`
  212. ApplyUserId int `description:"申请人ID"`
  213. ApplyUserName string `description:"申请人名称"`
  214. ContractDetail string `json:"-" description:"提交审批时的合同信息;用印快照"`
  215. ContractInfo contract.ContractDetail `json:"-" description:"提交审批时的合同信息;用印快照"`
  216. ApproveRemark string `description:"审核备注"`
  217. SealType string `description:"用印类型"`
  218. CompanyName string `description:"客户名称"`
  219. FileUrl string `description:"合同下载地址"`
  220. CurrNodeId int `description:"当前审批节点id"`
  221. StartNodeId int `description:"开始审批节点id"`
  222. //UserId int `description:"申请人id"`
  223. //UserName string `description:"申请人名称"`
  224. SealId int `description:"用印审批ID"`
  225. CreateTime time.Time `description:"发起审批的时间"`
  226. ModifyTime time.Time `description:"最后一次修改的时间"`
  227. ApproveTime time.Time `description:"审批时间"`
  228. InvalidTime time.Time `description:"作废时间"`
  229. CheckBackFileUrl string `description:"签回附件地址"`
  230. CheckBackFileTime time.Time `description:"签回用印附件时间"`
  231. CreditCode string `description:"社会信用码"`
  232. CreateTimeStr string `description:"发起审批的时间(字符串)"`
  233. ModifyTimeStr string `description:"最后一次修改的时间(字符串)"`
  234. ApproveTimeStr string `description:"审批时间(字符串)"`
  235. InvalidTimeStr string `description:"作废时间(字符串)"`
  236. CheckBackFileTimeStr string `description:"签回用印附件时间(字符串)"`
  237. ContractCode string `description:"合同编码"`
  238. AffiliatedCompany string `description:"归属公司"`
  239. FirstLevelApprovers string `description:"一级审批人"`
  240. SecondLevelApprovers string `description:"二级审批人"`
  241. ThirdLevelApprovers string `description:"三级审批人"`
  242. FirstLevelCC string `description:"一级抄送人"`
  243. SecondLevelCC string `description:"二级抄送人"`
  244. ThirdLevelCC string `description:"三级抄送人"`
  245. }
  246. // GetSealApprovalList 获取用印审批列表
  247. func GetSealApprovalList(condition, joinCondition string, pars []interface{}) (list []*SealApprovaExportlItem, err error) {
  248. o := orm.NewOrm()
  249. 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,
  250. 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,c.affiliated_company `
  251. 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" `
  252. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  253. JOIN seal c ON c.seal_id = a.contract_id
  254. JOIN contract_approval_record d on a.contract_approval_id=d.contract_approval_id ` + joinCondition + `
  255. WHERE c.is_delete = 0 AND a.approval_type="seal" `
  256. sql += condition
  257. sql += ` group by c.seal_id order by c.create_time desc`
  258. _, err = o.Raw(sql, pars).QueryRows(&list)
  259. return
  260. }