contract.go 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package crm
  2. import (
  3. "hongze/fms_api/global"
  4. "hongze/fms_api/models/base"
  5. "time"
  6. )
  7. // Contract CRM系统合同
  8. type Contract struct {
  9. ContractId int `gorm:"primaryKey;column:contract_id"`
  10. ContractCode string `description:"合同编号,长度32位"`
  11. SellerId int `description:"所属销售id"`
  12. SellerName string `description:"所属销售名称"`
  13. ProductId int `description:"产品id,1:ficc;2:权益"`
  14. ContractBusinessType string `description:"合同业务类型,枚举值:'业务合同','代付合同'"`
  15. ContractType string `description:"合同类型,枚举值:'新签合同','续约合同','补充协议'"`
  16. Status string `description:"合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废','已解约'"`
  17. StartDate time.Time `description:"合同开始日期"`
  18. EndDate time.Time `description:"合同结束日期"`
  19. OriginalPrice float64 `description:"合同原金额,优惠前的金额"`
  20. Price float64 `description:"实际金额,优惠后的金额"`
  21. PayRemark string `description:"付款方式说明,长度255位"`
  22. PayChannel string `description:"付款渠道,长度255位"`
  23. CompanyName string `description:"客户名称,甲方名称,长度32位"`
  24. CreditCode string `description:"社会统一信用代码,长度64位"`
  25. ProvinceId int `description:"省级id"`
  26. Province string `description:"省级名称,长度16位"`
  27. CityId int `description:"市级id"`
  28. City string `description:"市级名称,长度32位"`
  29. Address string `description:"详细地址"`
  30. Fax string `description:"传真,长度32位"`
  31. Phone string `description:"电话,长度32位"`
  32. Postcode string `description:"邮编,长度16位"`
  33. Remark string `description:"补充内容,长度255位"`
  34. SellerRemark string `description:"销售备注,长度255位"`
  35. ModifyContent string `description:"修改内容"`
  36. ApprovalRemark string `description:"审核备注"`
  37. FileUrl string `description:"合同文件地址"`
  38. CheckBackFileUrl string `description:"签回合同文件地址"`
  39. RescindFileUrl string `description:"解约合同文件地址"`
  40. TemplateId int `description:"模板id"`
  41. SourceId int `description:"来源合同id,默认是0;如果是通过其他合同复制过来的,那么就是原合同的id"`
  42. IsDelete int `description:"是否已经删除,0:未删除,1:已删除" json:"-"`
  43. ApproveTime time.Time `description:"审批时间"`
  44. InvalidTime time.Time `description:"作废时间"`
  45. CheckBackFileTime time.Time `description:"合同签回时间"`
  46. RescindTime time.Time `description:"解约时间"`
  47. ModifyTime time.Time `description:"合同最近一次修改时间"`
  48. CreateTime time.Time `description:"合同添加时间"`
  49. }
  50. func (c *Contract) TableName() string {
  51. return "contract"
  52. }
  53. func (c *Contract) PageList(page base.IPage, condition string, pars []interface{}) (count int64, results []*Contract, err error) {
  54. results = make([]*Contract, 0)
  55. query := global.MYSQL["report"].Model(Contract{}).
  56. Where("is_delete = 0").
  57. Where(condition, pars...)
  58. query.Count(&count)
  59. if len(page.GetOrderItemsString()) > 0 {
  60. query = query.Order(page.GetOrderItemsString())
  61. }
  62. err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
  63. return
  64. }
  65. // ContractSearchListReq CRM系统合同-搜索列表请求体
  66. type ContractSearchListReq struct {
  67. Keyword string `json:"keyword" form:"keyword" binding:"omitempty" description:"关键词"`
  68. ProductId int `json:"product_id" form:"product_id" description:"产品: 0-全部; 1-FICC; 2-权益"`
  69. base.PageReq
  70. }
  71. // ContractSearchListResp CRM系统合同-搜索列表响应体
  72. type ContractSearchListResp struct {
  73. ContractId int `json:"contract_id" description:"合同ID"`
  74. ContractCode string `json:"contract_code" description:"合同编号"`
  75. ProductId int `json:"product_id" description:"产品ID"`
  76. CompanyName string `json:"company_name" description:"客户名称"`
  77. RelateContractCode string `json:"relate_contract_code" description:"代付合同关联的实际使用方合同编号"`
  78. ActualCompanyName string `json:"actual_company_name" description:"实际使用方"`
  79. SellerId int `json:"seller_id" description:"销售ID"`
  80. SellerName string `json:"seller_name" description:"销售名称"`
  81. ContractTypeKey int `json:"contract_type_key" description:"FMS合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议;"`
  82. ContractType string `json:"contract_type" description:"CRM合同类型: 新签合同; 续约合同; 补充协议;"`
  83. Price float64 `json:"price" description:"合同金额"`
  84. StartDate string `json:"start_date" description:"合同开始日期"`
  85. EndDate string `json:"end_date" description:"合同结束日期"`
  86. ActualPayCompanies string `json:"actual_pay_companies" description:"该合同关联的所有代付方, 英文逗号拼接"`
  87. ContractTypeInt int `json:"contract_type_int" description:"CRM合同类型: 1新签合同; 2续约合同; 3补充协议;"`
  88. ContractBusinessTypeInt int `json:"contract_business_type_int" description:"合同业务类型,1'业务合同', 2'代付合同;"`
  89. }
  90. // PayCompanyRelation 代付合同
  91. type PayCompanyRelation struct {
  92. ContractId int `description:"代付合同ID"`
  93. ContractCode string `description:"代付合同编号"`
  94. CompanyName string `description:"代付方名称"`
  95. PaymentOnBehalfContractId int `description:"实际使用方合同ID"`
  96. }
  97. // GetPayCompanyByContractIds 通过代付合同IDs获取关联客户信息
  98. func GetPayCompanyByContractIds(condition string, pars []interface{}) (results []*PayCompanyRelation, err error) {
  99. results = make([]*PayCompanyRelation, 0)
  100. query := global.MYSQL["report"].
  101. Table("contract as a").
  102. Select("a.contract_id, a.contract_code, a.company_name, b.payment_on_behalf_contract_id").
  103. Joins("JOIN contract_relation b ON a.contract_id = b.contract_id").
  104. Where("a.is_delete = 0").
  105. Where(condition, pars...)
  106. err = query.Find(&results).Error
  107. return
  108. }
  109. // ContractActualPayCompanies 代付合同信息
  110. type ContractActualPayCompanies struct {
  111. ContractId int `json:"contract_id" description:"业务合同ID"`
  112. ActualPayCompanies string `json:"actual_pay_companies" description:"关联的代付方名称, 英文逗号拼接"`
  113. }
  114. // GetContractActualPayCompaniesByContractIds 通过合同IDs获取代付客户信息
  115. func GetContractActualPayCompaniesByContractIds(condition string, pars []interface{}) (results []*ContractActualPayCompanies, err error) {
  116. results = make([]*ContractActualPayCompanies, 0)
  117. query := global.MYSQL["report"].
  118. Table("contract_relation AS a").
  119. Select("a.contract_id, GROUP_CONCAT(DISTINCT b.company_name) AS actual_pay_companies").
  120. Joins("JOIN contract AS b ON a.payment_on_behalf_contract_id = b.contract_id").
  121. Where("b.is_delete = 0").
  122. Where(condition, pars...).
  123. Group("a.contract_id")
  124. err = query.Find(&results).Error
  125. return
  126. }
  127. // ContractDetail 合同详情信息(包含服务信息等)
  128. type ContractDetail struct {
  129. Contract
  130. StartDateStr string `description:"合同起始时间(字符串形式)"`
  131. EndDateStr string `description:"合同结束时间(字符串形式)"`
  132. ApproveTimeStr string `description:"审批时间(字符串形式)"`
  133. InvalidTimeStr string `description:"作废时间(字符串形式)"`
  134. CheckBackFileTimeStr string `description:"合同签回时间(字符串形式)"`
  135. RescindTimeStr string `description:"解约时间(字符串形式)"`
  136. ModifyTimeStr string `description:"最近一次更新时间(字符串形式)"`
  137. CreateTimeStr string `description:"合同添加时间(字符串形式)"`
  138. Service []*ContractServiceAndDetailRespItem
  139. RelationContractDetailList []*ContractDetail `description:"关联合同详情"`
  140. PermissionLookList []*PermissionLookList `description:"合同里面的权限列表"`
  141. }
  142. type PermissionLookList struct {
  143. ClassifyName string `description:"分类"`
  144. Items []*PermissionLookItem
  145. }
  146. type PermissionLookItem struct {
  147. ChartPermissionId int `description:"权限id"`
  148. PermissionName string `description:"权限名称"`
  149. ClassifyName string `description:"分类"`
  150. }
  151. // GetContractDetailById 根据合同ID获取合同详情信息
  152. func GetContractDetailById(contractId int) (detail *ContractDetail, err error) {
  153. detail = new(ContractDetail)
  154. item := new(Contract)
  155. query := global.MYSQL["report"].
  156. Model(Contract{}).
  157. Where("contract_id = ?", contractId)
  158. err = query.Find(&item).Error
  159. if err != nil {
  160. return
  161. }
  162. detail.Contract = *item
  163. return
  164. }
  165. // ContractServiceDetailReq CRM系统合同-合同套餐及品种权限详情请求体
  166. type ContractServiceDetailReq struct {
  167. ContractId int `json:"contract_id" form:"contract_id" binding:"required,gte=1" description:"合同ID"`
  168. }