contract_relation.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package crm
  2. import "hongze/fms_api/global"
  3. // ContractRelation 合同关系表结构体
  4. type ContractRelation struct {
  5. ContractId int `description:"业务合同id"`
  6. PaymentOnBehalfContractId int `description:"代付合同id"`
  7. }
  8. type RelationContractQuery struct {
  9. ContractId int `description:"合同id"`
  10. CompanyName string `description:"甲方名称"`
  11. PaymentOnBehalfContractId int `description:"代付合同id"`
  12. }
  13. type RelationContractList struct {
  14. ContractId int `description:"合同id"`
  15. CompanyName string `description:"甲方名称"`
  16. PaymentOnBehalfContractId int `description:"代付合同id"`
  17. Price float64 `description:"付款金额"`
  18. Service []*ContractServiceAndDetail
  19. }
  20. // GetContractRelationListByRelationContractId 根据业务合同id获取对应的代付合同基础信息
  21. func GetContractRelationListByRelationContractId(contractId int) (list []*RelationContractList, err error) {
  22. results := make([]*RelationContractQuery, 0)
  23. list = make([]*RelationContractList, 0)
  24. query := global.MYSQL["report"].
  25. Table("contract AS a").
  26. Select("b.contract_id, a.company_name, b.payment_on_behalf_contract_id").
  27. Joins("JOIN contract_relation b ON a.contract_id = b.payment_on_behalf_contract_id").
  28. Where("a.status IN ('已签回','已审批') AND a.is_delete = 0 AND b.contract_id = ?", contractId).
  29. Order("a.contract_id ASC")
  30. err = query.Find(&results).Error
  31. if err != nil {
  32. return
  33. }
  34. for i := range results {
  35. list = append(list, &RelationContractList{
  36. ContractId: results[i].ContractId,
  37. CompanyName: results[i].CompanyName,
  38. PaymentOnBehalfContractId: results[i].PaymentOnBehalfContractId,
  39. })
  40. }
  41. return
  42. }
  43. // GetContractRelationListByPaymentOnBehalfContractId 根据代付合同id获取对应的业务合同基础信息
  44. func GetContractRelationListByPaymentOnBehalfContractId(contractId int) (list []*RelationContractList, err error) {
  45. results := make([]*RelationContractQuery, 0)
  46. list = make([]*RelationContractList, 0)
  47. query := global.MYSQL["report"].
  48. Table("contract AS a").
  49. Select("a.contract_id, a.company_name, b.payment_on_behalf_contract_id").
  50. Joins("JOIN contract_relation b ON a.contract_id = b.contract_id").
  51. Where("a.status IN ('已签回','已审批') AND a.is_delete = 0 AND b.payment_on_behalf_contract_id = ?", contractId).
  52. Order("a.contract_id ASC")
  53. err = query.Find(&results).Error
  54. if err != nil {
  55. return
  56. }
  57. for i := range results {
  58. list = append(list, &RelationContractList{
  59. ContractId: results[i].ContractId,
  60. CompanyName: results[i].CompanyName,
  61. PaymentOnBehalfContractId: results[i].PaymentOnBehalfContractId,
  62. })
  63. }
  64. return
  65. }