company_contract_approval.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package contract
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. //获取审批列表数据数量
  7. func GetCompanyApprovalListCount(condition string, pars []interface{}) (count int, err error) {
  8. o := orm.NewOrm()
  9. sql := `
  10. SELECT a.* from contract_approval a
  11. JOIN company_approval c ON a.contract_id = c.company_approval_id
  12. INNER JOIN company AS e ON e.company_id=c.company_id
  13. WHERE
  14. a.approval_type = "company" `
  15. sql += condition
  16. sql += ` GROUP BY a.contract_id `
  17. sql = `select count(*) count from (` + sql + `) b`
  18. err = o.Raw(sql, pars).QueryRow(&count)
  19. return
  20. }
  21. //审批列表
  22. type CompanyApprovalList struct {
  23. ContractApprovalId int `description:"审批单id"`
  24. ContractId int `description:"客户单id"`
  25. ContractApprovalRecordId int `description:"审批流id"`
  26. ContractCode string `description:"合同编号"`
  27. Status string `description:"审批单状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
  28. ApplyContent string `description:"待审内容"`
  29. ContractDetail string `json:"-" description:"提交审批时的客户审批信息;客户审批快照"`
  30. ContractInfo ContractDetail `description:"提交审批时的合同信息;合同快照"`
  31. ApproveRemark string `description:"审核备注"`
  32. CompanyName string `description:"客户名称"`
  33. SellerId int `description:"销售id"`
  34. ApplyUserId int `description:"申请人id"`
  35. CurrNodeId int `description:"当前节点"`
  36. StartNodeId int `description:"开始节点"`
  37. ProductId int `description:"产品id,1:ficc;2:权益"`
  38. SellerName string `description:"销售名称"`
  39. StartDate time.Time `description:"合同开始日期"`
  40. EndDate time.Time `description:"合同结束日期"`
  41. CreateTime time.Time `description:"发起审批的时间"`
  42. ModifyTime time.Time `description:"最后一次修改的时间"`
  43. ApproveTime time.Time `description:"审批时间"`
  44. StartDateStr string `description:"合同开始日期(字符串类型)"`
  45. EndDateStr string `description:"合同结束日期(字符串类型)"`
  46. CreateTimeStr string `description:"发起审批的时间(字符串类型)"`
  47. ModifyTimeStr string `description:"最后一次修改的时间(字符串类型)"`
  48. ApproveTimeStr string `description:"审批时间(字符串类型)"`
  49. CompanyId int
  50. CreditCode string `description:"社会统一信用码"`
  51. CompanyType string `description:"客户类型"`
  52. IndustryName string `description:"行业名称"`
  53. ApprovalTime string `description:"提交申请时间"`
  54. CompanyProductStatus string `description:"客户状态"`
  55. ApproveContent string `description:"待审内容"`
  56. ApproveStatus string `description:"当前状态"`
  57. ApplyMethod int `description:"申请类型:1:试用->正式,2:冻结—>试用,3:流失—>正式,4:试用延期,5:原销售申请领取流失客户,6:正式客户申请服务更新"`
  58. ApplyReasons string `description:"申请理由"`
  59. FreezeStartDate string `description:"冻结开始日期"`
  60. FreezeEndDate string `description:"冻结结束日期"`
  61. FreezeExpireDays int `description:"冻结到期天数"`
  62. Address string `description:"地址"`
  63. Source string `description:"客户来源"`
  64. ExpireDay int `description:"服务到期天数"`
  65. CompanyApprovalId int `description:"审批记录ID"`
  66. ApprovalCount int `description:"已延期审批次数"`
  67. CompanyContractId int `description:"合同id"`
  68. DelayPermission string `description:"延期申请品种"`
  69. ApplyRealName string `description:"申请人姓名"`
  70. }
  71. //获取审批列表数据
  72. func GetCompanyApprovalList(childCondition, condition string, childPars, pars []interface{}, startSize, pageSize int) (list []*CompanyApprovalList, err error) {
  73. o := orm.NewOrm()
  74. sql := `
  75. SELECT
  76. a.contract_approval_id,a.contract_id,a.apply_content,a.contract_detail,a.approve_remark,a.create_time,a.modify_time,a.status,a.curr_node_id,a.start_node_id,a.apply_user_id,c.approve_time,c.company_approval_id,c.approve_status,c.company_id,c.product_id,c.apply_real_name,d.company_type,d.industry_name,d.seller_name,d.status company_product_status,c.approve_status,c.apply_method,c.apply_reasons,d.freeze_start_date,d.freeze_end_date,e.address,d.source,c.approve_remark,d.start_date,d.end_date,c.company_contract_id,e.company_name,e.credit_code
  77. from contract_approval a
  78. join ( SELECT max( contract_approval_id ) max_id,contract_id FROM contract_approval where 1=1 and approval_type="company" `
  79. sql += childCondition
  80. sql += ` GROUP BY contract_id ) b on a.contract_approval_id=b.max_id
  81. INNER JOIN company_approval AS c ON a.contract_id=c.company_approval_id
  82. INNER JOIN company_product AS d ON d.company_id=c.company_id AND d.product_id=c.product_id
  83. INNER JOIN company AS e ON e.company_id=d.company_id
  84. WHERE 1=1 and a.approval_type="company" `
  85. sql += condition
  86. sql += ` group by contract_id order by modify_time desc LIMIT ?,? `
  87. _, err = o.Raw(sql, childPars, pars, startSize, pageSize).QueryRows(&list)
  88. return
  89. }
  90. // GetContractApprovalIdList 根据客户申请单id获取
  91. func GetContractApprovalIdList(companyApprovalIds string, approveUserId int) (list []*ContractApproval, err error) {
  92. o := orm.NewOrm()
  93. sql := `
  94. SELECT
  95. a.* from contract_approval a
  96. where contract_approval_id in ( SELECT max( contract_approval_id ) max_id FROM contract_approval where 1=1 and a.approval_type="company" and contract_id in (` + companyApprovalIds + `)
  97. `
  98. sql += ` order by modify_time desc `
  99. _, err = o.Raw(sql).QueryRows(&list)
  100. return
  101. }