package crm import "hongze/fms_api/global" // ContractRelation 合同关系表结构体 type ContractRelation struct { ContractId int `description:"业务合同id"` PaymentOnBehalfContractId int `description:"代付合同id"` } type RelationContractQuery struct { ContractId int `description:"合同id"` CompanyName string `description:"甲方名称"` PaymentOnBehalfContractId int `description:"代付合同id"` } type RelationContractList struct { ContractId int `description:"合同id"` CompanyName string `description:"甲方名称"` PaymentOnBehalfContractId int `description:"代付合同id"` Price float64 `description:"付款金额"` Service []*ContractServiceAndDetail } // GetContractRelationListByRelationContractId 根据业务合同id获取对应的代付合同基础信息 func GetContractRelationListByRelationContractId(contractId int) (list []*RelationContractList, err error) { results := make([]*RelationContractQuery, 0) list = make([]*RelationContractList, 0) query := global.MYSQL["report"]. Table("contract AS a"). Select("b.contract_id, a.company_name, b.payment_on_behalf_contract_id"). Joins("JOIN contract_relation b ON a.contract_id = b.payment_on_behalf_contract_id"). Where("a.status IN ('已签回','已审批') AND a.is_delete = 0 AND b.contract_id = ?", contractId). Order("a.contract_id ASC") err = query.Find(&results).Error if err != nil { return } for i := range results { list = append(list, &RelationContractList{ ContractId: results[i].ContractId, CompanyName: results[i].CompanyName, PaymentOnBehalfContractId: results[i].PaymentOnBehalfContractId, }) } return } // GetContractRelationListByPaymentOnBehalfContractId 根据代付合同id获取对应的业务合同基础信息 func GetContractRelationListByPaymentOnBehalfContractId(contractId int) (list []*RelationContractList, err error) { results := make([]*RelationContractQuery, 0) list = make([]*RelationContractList, 0) query := global.MYSQL["report"]. Table("contract AS a"). Select("a.contract_id, a.company_name, b.payment_on_behalf_contract_id"). Joins("JOIN contract_relation b ON a.contract_id = b.contract_id"). Where("a.status IN ('已签回','已审批') AND a.is_delete = 0 AND b.payment_on_behalf_contract_id = ?", contractId). Order("a.contract_id ASC") err = query.Find(&results).Error if err != nil { return } for i := range results { list = append(list, &RelationContractList{ ContractId: results[i].ContractId, CompanyName: results[i].CompanyName, PaymentOnBehalfContractId: results[i].PaymentOnBehalfContractId, }) } return }