contract_service_template.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package fms
  2. import (
  3. "hongze/fms_api/global"
  4. "time"
  5. )
  6. // ContractServiceTemplate 合同服务模板表
  7. type ContractServiceTemplate struct {
  8. ServiceTemplateId int `gorm:"primaryKey;column:service_template_id" json:"service_template_id"`
  9. ProductId int `gorm:"column:product_id" json:"product_id" description:"产品id"`
  10. Pid int `gorm:"column:pid" json:"pid" description:"父级id"`
  11. Title string `gorm:"column:title" json:"title" description:"套餐名称"`
  12. Value string `gorm:"column:value" json:"value" description:"对应的数据"`
  13. SelectType string `gorm:"column:select_type" json:"select_type" description:"选择器类型,单选还是多选,radio;单选:checkbox"`
  14. SelectName string `gorm:"column:select_name" json:"select_name" description:"选择器名称"`
  15. TableValue string `gorm:"column:table_value" json:"table_value" description:"表格数据,用于word生成时的json数据"`
  16. Remark string `gorm:"column:remark" json:"remark" description:"表头备注"`
  17. ChartPermissionId int `gorm:"column:chart_permission_id" json:"chart_permission_id" description:"权限id"`
  18. CreateTime time.Time `gorm:"column:create_time" json:"create_time" description:"创建时间"`
  19. ModifyTime time.Time `gorm:"column:modify_time" json:"modify_time" description:"修改时间"`
  20. IsDelete int `gorm:"column:is_delete" json:"-" description:"删除状态: 0-正常; 1-删除"`
  21. }
  22. func (st *ContractServiceTemplate) TableName() string {
  23. return "contract_service_template"
  24. }
  25. func (st *ContractServiceTemplate) List(condition string, pars []interface{}) (list []*ContractServiceTemplate, err error) {
  26. list = make([]*ContractServiceTemplate, 0)
  27. err = global.DEFAULT_MYSQL.Model(st).
  28. Where("is_delete = 0").
  29. Where(condition, pars...).
  30. Find(&list).Error
  31. return
  32. }
  33. func (st *ContractServiceTemplate) OrderList(condition string, pars []interface{}) (list []*ContractServiceTemplate, err error) {
  34. list = make([]*ContractServiceTemplate, 0)
  35. err = global.DEFAULT_MYSQL.Model(st).
  36. Where("is_delete = 0").
  37. Where(condition, pars...).
  38. Order("sort ASC ").
  39. Find(&list).Error
  40. return
  41. }
  42. type ContractServiceTemplateItem struct {
  43. ServiceTemplateId int `json:"service_template_id" description:"套餐模板ID"`
  44. ProductId int `json:"product_id" description:"产品ID"`
  45. Pid int `json:"pid" description:"父级ID"`
  46. ParentTitle string `json:"parent_title" description:"父级套餐名称"`
  47. Title string `json:"title" description:"套餐名称"`
  48. Value string `json:"value" description:"对应的数据"`
  49. SelectType string `json:"select_type" description:"选择器类型:radio-单选; checkbox-多选"`
  50. SelectName string `json:"select_name" description:"选择器名称"`
  51. ChartPermissionId int `json:"chart_permission_id" description:"权限ID"`
  52. }
  53. type ContractServiceTemplateList struct {
  54. Title string `json:"title"`
  55. Children []*ContractServiceTemplateMapItems `json:"children"`
  56. }
  57. type ContractServiceTemplateMapItems struct {
  58. ContractServiceTemplateItem
  59. Children []*ContractServiceTemplateMapItems `json:"children"`
  60. Detail []*ContractServiceDetail `json:"detail"`
  61. }
  62. type ContractServiceTemplateMapItems2 struct {
  63. ServiceTemplateId int `json:"service_template_id" description:"套餐模板ID"`
  64. ProductId int `json:"product_id" description:"产品id"`
  65. Pid int `json:"pid" description:"父级id"`
  66. Title string `json:"title" description:"套餐名称"`
  67. Value string `json:"value" description:"对应的数据"`
  68. SelectType string `json:"select_type" description:"选择器类型,单选还是多选,radio;单选:checkbox"`
  69. SelectName string `json:"select_name" description:"选择器名称"`
  70. ChartPermissionId int `json:"chart_permission_id" description:"权限id"`
  71. Children []*ContractServiceTemplateMapItems `json:"children"`
  72. Detail []*ContractServiceDetail `json:"detail"`
  73. }
  74. // ContractServiceListReq CRM系统合同套餐-列表请求体
  75. type ContractServiceListReq struct {
  76. ProductId string `json:"product_id" form:"product_id" description:"产品:空值-全部; 1-FICC; 2-权益"`
  77. }
  78. func GetContractServiceTemplateMapByProductId(productId int) (items []*ContractServiceTemplateItem, err error) {
  79. items = make([]*ContractServiceTemplateItem, 0)
  80. err = global.DEFAULT_MYSQL.Table("contract_service_template").
  81. Where("product_id = ? AND pid = 0 AND is_delete = 0", productId).
  82. Order("sort ASC").
  83. Find(&items).Error
  84. return
  85. }
  86. func GetContractServiceTemplateAllByProductId(productId int) (items []*ContractServiceTemplateItem, err error) {
  87. items = make([]*ContractServiceTemplateItem, 0)
  88. err = global.DEFAULT_MYSQL.Table("contract_service_template").
  89. Where("product_id = ? AND is_delete = 0", productId).
  90. Order("sort ASC").
  91. Find(&items).Error
  92. return
  93. }
  94. func GetContractServiceTemplateMapByParentId(parentId int) (items []*ContractServiceTemplateItem, err error) {
  95. items = make([]*ContractServiceTemplateItem, 0)
  96. err = global.DEFAULT_MYSQL.Table("contract_service_template").
  97. Where("pid = ? AND is_delete = 0", parentId).
  98. Find(&items).Error
  99. return
  100. }
  101. // GetContractServiceTemplateById 主键获取合同套餐模板
  102. func GetContractServiceTemplateById(templateId int) (item *ContractServiceTemplate, err error) {
  103. err = global.DEFAULT_MYSQL.Model(ContractServiceTemplate{}).
  104. Where("service_template_id = ? AND is_delete = 0", templateId).
  105. First(&item).Error
  106. return
  107. }
  108. func GetContractServiceTemplateSecond() (items []*ContractServiceTemplateItem, err error) {
  109. items = make([]*ContractServiceTemplateItem, 0)
  110. err = global.DEFAULT_MYSQL.Table("contract_service_template").
  111. Where("pid = 0 AND is_delete = 0").
  112. Order("sort ASC").
  113. Find(&items).Error
  114. return
  115. }
  116. type ContractServiceTemplateFullName struct {
  117. ContractServiceTemplateItem
  118. ParentTitle string
  119. }
  120. type ContractServiceTemplateFormat struct {
  121. FormatTitle string
  122. ServiceTemplateId int
  123. ServiceTemplatePid int
  124. ServiceProductId int
  125. }
  126. type ContractServiceTemplateFormatList []ContractServiceTemplateFormat
  127. func (c ContractServiceTemplateFormatList) Len() int {
  128. return len(c)
  129. }
  130. func (c ContractServiceTemplateFormatList) Less(i, j int) bool {
  131. return c[i].ServiceTemplateId < c[j].ServiceTemplateId
  132. }
  133. func (c ContractServiceTemplateFormatList) Swap(i, j int) {
  134. c[i], c[j] = c[j], c[i]
  135. }
  136. func GetContractServiceTemplateFullName() (items []*ContractServiceTemplateFullName, err error) {
  137. err = global.DEFAULT_MYSQL.Table("contract_service_template as t1").
  138. Select("t1.*, t2.title as parent_title").
  139. Joins(" left join contract_service_template as t2 on t1.pid = t2.service_template_id").
  140. Where("t1.is_delete = 0").
  141. Order("t1.service_template_id ASC").
  142. Find(&items).Error
  143. return
  144. }
  145. // GetContractServiceTemplateByTitle 用名称获取合同套餐模板
  146. func GetContractServiceTemplateByTitle(titles string) (items []*ContractServiceTemplate, err error) {
  147. err = global.DEFAULT_MYSQL.Model(ContractServiceTemplate{}).
  148. Where("title IN (?)", titles).
  149. Scan(&items).Error
  150. return
  151. }