contract_payment_service_amount.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package fms
  2. import (
  3. "hongze/fms_api/global"
  4. "hongze/fms_api/models/base"
  5. )
  6. // ContractPaymentServiceAmount 到款登记-套餐金额分配表
  7. type ContractPaymentServiceAmount struct {
  8. ContractPaymentServiceAmountId int `gorm:"primaryKey;column:contract_payment_service_amount_id" json:"contract_payment_service_amount_id"`
  9. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"合同登记ID"`
  10. ContractPaymentId int `gorm:"column:contract_payment_id" json:"contract_payment_id" description:"到款登记ID"`
  11. ServiceTemplateId int `gorm:"column:service_template_id" json:"service_template_id" description:"套餐ID"`
  12. ServiceTemplatePid int `gorm:"column:service_template_pid" json:"service_template_pid" description:"套餐父级ID"`
  13. Amount float64 `gorm:"column:amount" json:"amount" description:"分配金额"`
  14. IsDeleted int `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
  15. InitType int `gorm:"column:init_type" json:"init_type" description:"初始分配类型:0人为分配,1自动分配"`
  16. base.TimeBase
  17. }
  18. func (c *ContractPaymentServiceAmount) TableName() string {
  19. return "contract_payment_service_amount"
  20. }
  21. func (c *ContractPaymentServiceAmount) Create() (err error) {
  22. err = global.DEFAULT_MYSQL.Create(c).Error
  23. return
  24. }
  25. func (c *ContractPaymentServiceAmount) AddInBatches(list []*ContractPaymentServiceAmount) (err error) {
  26. err = global.DEFAULT_MYSQL.CreateInBatches(list, len(list)).Error
  27. return
  28. }
  29. func (c *ContractPaymentServiceAmount) Update(updateCols []string) (err error) {
  30. err = global.DEFAULT_MYSQL.Model(c).Select(updateCols).Updates(c).Error
  31. return
  32. }
  33. func (c *ContractPaymentServiceAmount) List(condition string, pars []interface{}) (list []*ContractPaymentServiceAmount, err error) {
  34. list = make([]*ContractPaymentServiceAmount, 0)
  35. err = global.DEFAULT_MYSQL.Model(c).
  36. Where("is_deleted = 0").
  37. Where(condition, pars...).
  38. Find(&list).Error
  39. return
  40. }
  41. // ContractPaymentServiceAmountItem 到款套餐分配信息
  42. type ContractPaymentServiceAmountItem struct {
  43. ContractPaymentServiceAmountId int `json:"contract_payment_service_amount_id"`
  44. ContractPaymentId int `json:"contract_payment_id" description:"到款登记ID"`
  45. ServiceTemplateId int `json:"service_template_id" description:"套餐ID"`
  46. ServiceTemplatePid int `json:"service_template_pid" description:"套餐父级ID"`
  47. ServiceTemplateName string `json:"service_template_name"`
  48. Amount float64 `json:"amount" description:"分配金额"`
  49. ServiceProductId int `json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  50. }
  51. // DistributePaymentServiceAmountReq 到款登记-分配套餐金额请求体
  52. type DistributePaymentServiceAmountReq struct {
  53. ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"`
  54. ContractPaymentId int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
  55. List []*DistributePaymentServiceAmountItem `json:"list"`
  56. }
  57. // GetPaymentServiceAmountReq 到款登记-查询分配套餐金额请求体
  58. type GetPaymentServiceAmountReq struct {
  59. ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"`
  60. ContractPaymentId int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
  61. }
  62. // DistributePaymentServiceAmountItem 到款登记-分配套餐金额列表信息
  63. type DistributePaymentServiceAmountItem struct {
  64. ContractPaymentServiceAmountId int `json:"contract_payment_service_amount_id"`
  65. ServiceTemplateId int `json:"service_template_id" description:"套餐ID"`
  66. ServiceTemplatePid int `json:"service_template_pid" description:"套餐父级ID"`
  67. Amount float64 `json:"amount" description:"分配金额"`
  68. }
  69. // CreatePaymentServiceAmount 分配到款套餐金额
  70. func CreatePaymentServiceAmount(registerId, payId int, addList []*ContractPaymentServiceAmount) (err error) {
  71. tx := global.DEFAULT_MYSQL.Begin()
  72. defer func() {
  73. if err != nil {
  74. tx.Rollback()
  75. } else {
  76. tx.Commit()
  77. }
  78. }()
  79. // 删除原分配信息
  80. sql := `DELETE FROM contract_payment_service_amount WHERE contract_register_id = ? AND contract_payment_id = ?`
  81. tx.Exec(sql, registerId, payId)
  82. // 新增分配信息
  83. if len(addList) > 0 {
  84. tx.CreateInBatches(addList, len(addList))
  85. }
  86. return
  87. }
  88. func DeletePaymentServiceAmountByRegisterId(registerId int) (err error) {
  89. // 删除原自动分配信息
  90. err = global.DEFAULT_MYSQL.
  91. Where("contract_register_id = ? and init_type=1", registerId).
  92. Delete(ContractPaymentServiceAmount{}).Error
  93. return
  94. }