contract_service.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package fms
  2. import (
  3. "hongze/fms_api/global"
  4. "hongze/fms_api/models/base"
  5. )
  6. // ContractService 合同服务套餐
  7. type ContractService struct {
  8. ContractServiceId int `gorm:"primaryKey;column:contract_service_id" json:"contract_service_id"`
  9. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  10. ProductId int `gorm:"column:product_id" json:"product_id" description:"产品ID"`
  11. ServiceTemplateId int `gorm:"column:service_template_id" json:"service_template_id" description:"合同服务模板ID"`
  12. Title string `gorm:"column:title" json:"title" description:"套餐名称"`
  13. Value string `gorm:"column:value" json:"value" description:"套餐的值"`
  14. TableValue string `gorm:"column:table_value" json:"table_value" description:"表格数据,用于word生成时的json数据"`
  15. HasDetail string `gorm:"column:has_detail" json:"has_detail" description:"是否有详情: 无; 有"`
  16. ChartPermissionId int `gorm:"column:chart_permission_id" json:"chart_permission_id" description:"权限ID"`
  17. ChartPermissionIds string `gorm:"column:chart_permission_ids" json:"chart_permission_ids" description:"权限IDs-小套餐"`
  18. base.TimeBase
  19. }
  20. type ContractServiceWithParentTitle struct {
  21. ContractService
  22. Pid int
  23. ParentTitle string
  24. }
  25. func (c *ContractService) TableName() string {
  26. return "contract_service"
  27. }
  28. func (c *ContractService) List(condition string, pars []interface{}) (list []*ContractService, err error) {
  29. list = make([]*ContractService, 0)
  30. err = global.DEFAULT_MYSQL.Model(c).
  31. Where(condition, pars...).
  32. Find(&list).Error
  33. return
  34. }
  35. func (c *ContractService) ListWithWithParentTitle(condition string, pars []interface{}) (list []*ContractServiceWithParentTitle, err error) {
  36. list = make([]*ContractServiceWithParentTitle, 0)
  37. err = global.DEFAULT_MYSQL.Table("contract_service as cv").
  38. Select("cv.*, t1.pid, t2.title as parent_title").
  39. Joins(" left join contract_service_template as t1 on cv.service_template_id = t1.service_template_id").
  40. Joins(" left join contract_service_template as t2 on t1.pid = t2.service_template_id").
  41. Where(condition, pars...).
  42. Find(&list).Error
  43. return
  44. }
  45. // ContractServiceAddReq 新增合同套餐请求体
  46. type ContractServiceAddReq struct {
  47. ServiceTemplateId int `json:"service_template_id" description:"服务套餐id"`
  48. Title string `json:"title" description:"服务套餐名称"`
  49. Value string `json:"value" description:"服务套餐内容"`
  50. ChartPermissionIds string `json:"chart_permission_ids" description:"品种权限"`
  51. //Detail [][]ContractServiceDetailAddReq `json:"detail" description:"详情数据"`
  52. }
  53. // ContractServiceItem 合同的服务内容
  54. type ContractServiceItem struct {
  55. ContractServiceId int `json:"contract_service_id" description:"合同服务ID"`
  56. ContractRegisterId int `json:"contract_register_id" description:"合同登记ID"`
  57. ProductId int `json:"product_id" description:"产品id,1:ficc;2:权益"`
  58. ServiceTemplateId int `json:"service_template_id" description:"合同服务模板id"`
  59. Title string `json:"title" description:"套餐标题"`
  60. Value string `json:"value" description:"套餐的值"`
  61. HasDetail string `json:"has_detail" description:"是否有详情,枚举值:是、否;默认:否"`
  62. TableValue string `json:"table_value" description:"表格数据,用于word生成时的json数据"`
  63. ChartPermissionId int `json:"chart_permission_id" description:"权限id"`
  64. ChartPermissionIds string `json:"chart_permission_ids" description:"品种权限-小套餐"`
  65. }
  66. // ContractServiceAndDetail 合同的服务内容及详情
  67. type ContractServiceAndDetail struct {
  68. ContractServiceId int `json:"contract_service_id" description:"合同服务ID"`
  69. ContractRegisterId int `json:"contract_register_id" description:"合同登记ID"`
  70. ProductId int `json:"product_id" description:"产品id,1:ficc;2:权益"`
  71. ServiceTemplateId int `json:"service_template_id" description:"合同服务模板id"`
  72. Title string `json:"title" description:"套餐标题"`
  73. Value string `json:"value" description:"套餐的值"`
  74. HasDetail string `json:"has_detail" description:"是否有详情,枚举值:是、否;默认:否"`
  75. TableValue string `json:"table_value" description:"表格数据,用于word生成时的json数据"`
  76. ChartPermissionId int `json:"chart_permission_id" description:"权限id"`
  77. ChartPermissionIds string `json:"chart_permission_ids" description:"品种权限-小套餐"`
  78. //Detail []*ContractServiceDetail `json:"detail"`
  79. }
  80. // GetContractServiceAndDetailList 根据id获取合同列表数据
  81. func GetContractServiceAndDetailList(contractRegisterId int) (list []*ContractServiceAndDetail, err error) {
  82. items := make([]*ContractServiceItem, 0)
  83. err = global.DEFAULT_MYSQL.Model(ContractService{}).
  84. Where("contract_register_id = ?", contractRegisterId).
  85. Find(&items).Error
  86. if err != nil {
  87. return
  88. }
  89. list = formatContractServiceAndDetailList(items)
  90. return
  91. }
  92. // formatContractServiceAndDetailList 格式化ContractServiceAndDetailList
  93. func formatContractServiceAndDetailList(list []*ContractServiceItem) (itemList []*ContractServiceAndDetail) {
  94. itemList = make([]*ContractServiceAndDetail, 0)
  95. for i := range list {
  96. itemList = append(itemList, &ContractServiceAndDetail{
  97. ContractServiceId: list[i].ContractServiceId,
  98. ContractRegisterId: list[i].ContractRegisterId,
  99. ProductId: list[i].ProductId,
  100. ServiceTemplateId: list[i].ServiceTemplateId,
  101. Title: list[i].Title,
  102. Value: list[i].Value,
  103. HasDetail: list[i].HasDetail,
  104. TableValue: list[i].TableValue,
  105. ChartPermissionId: list[i].ChartPermissionId,
  106. ChartPermissionIds: list[i].ChartPermissionIds,
  107. })
  108. }
  109. return
  110. }
  111. // GetContractRegisterIdsByTempId 套餐模板ID获取关联的合同登记ID
  112. func GetContractRegisterIdsByTempId(tempIds []string) (registerIds []int, err error) {
  113. err = global.DEFAULT_MYSQL.Model(ContractService{}).
  114. Select("DISTINCT contract_register_id").
  115. Where("service_template_id in (?)", tempIds).
  116. Find(&registerIds).Error
  117. return
  118. }
  119. // ContractRegisterServicesName 合同登记套餐信息
  120. type ContractRegisterServicesName struct {
  121. ContractRegisterId int `json:"contract_register_id" description:"登记ID"`
  122. ServicesName string `json:"services_name" description:"套餐信息, 英文逗号拼接"`
  123. }
  124. // GetContractRegisterServicesNameByRegisterIds 合同登记IDs获取套餐拼接字符串
  125. func GetContractRegisterServicesNameByRegisterIds(registerIds []int) (list []*ContractRegisterServicesName, err error) {
  126. list = make([]*ContractRegisterServicesName, 0)
  127. err = global.DEFAULT_MYSQL.Model(ContractService{}).
  128. Select("contract_register_id, GROUP_CONCAT(title) AS services_name").
  129. Where("contract_register_id IN ? ", registerIds).
  130. Group("contract_register_id").
  131. Find(&list).Error
  132. return
  133. }
  134. // GetContractRegisterServicesByRegisterIds 合同登记IDs获取套餐拼接字符串
  135. func GetContractRegisterServicesByRegisterIds(registerIds []int) (list []*ContractService, err error) {
  136. err = global.DEFAULT_MYSQL.Model(ContractService{}).
  137. Select("*").
  138. Where("contract_register_id IN ?", registerIds).
  139. Find(&list).Error
  140. return
  141. }