contract_payment_service_amount.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. base.TimeBase
  16. }
  17. func (c *ContractPaymentServiceAmount) TableName() string {
  18. return "contract_payment_service_amount"
  19. }
  20. func (c *ContractPaymentServiceAmount) Create() (err error) {
  21. err = global.DEFAULT_MYSQL.Create(c).Error
  22. return
  23. }
  24. func (c *ContractPaymentServiceAmount) AddInBatches(list []*ContractPaymentServiceAmount) (err error) {
  25. err = global.DEFAULT_MYSQL.CreateInBatches(list, len(list)).Error
  26. return
  27. }
  28. func (c *ContractPaymentServiceAmount) Update(updateCols []string) (err error) {
  29. err = global.DEFAULT_MYSQL.Model(c).Select(updateCols).Updates(c).Error
  30. return
  31. }
  32. func (c *ContractPaymentServiceAmount) List(condition string, pars []interface{}) (list []*ContractPaymentServiceAmount, err error) {
  33. list = make([]*ContractPaymentServiceAmount, 0)
  34. err = global.DEFAULT_MYSQL.Model(c).
  35. Where("is_deleted = 0").
  36. Where(condition, pars...).
  37. Find(&list).Error
  38. return
  39. }
  40. // ContractPaymentServiceAmountItem 到款套餐分配信息
  41. type ContractPaymentServiceAmountItem struct {
  42. ContractPaymentServiceAmountId int `json:"contract_payment_service_amount_id"`
  43. ContractPaymentId int `json:"contract_payment_id" description:"到款登记ID"`
  44. ServiceTemplateId int `json:"service_template_id" description:"套餐ID"`
  45. ServiceTemplatePid int `json:"service_template_pid" description:"套餐父级ID"`
  46. ServiceTemplateName string `json:"service_template_name"`
  47. Amount float64 `json:"amount" description:"分配金额"`
  48. }
  49. // DistributePaymentServiceAmountReq 到款登记-分配套餐金额请求体
  50. type DistributePaymentServiceAmountReq struct {
  51. ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"`
  52. ContractPaymentId int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
  53. List []*DistributePaymentServiceAmountItem `json:"list"`
  54. }
  55. // GetPaymentServiceAmountReq 到款登记-查询分配套餐金额请求体
  56. type GetPaymentServiceAmountReq struct {
  57. ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"`
  58. ContractPaymentId int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
  59. }
  60. // DistributePaymentServiceAmountItem 到款登记-分配套餐金额列表信息
  61. type DistributePaymentServiceAmountItem struct {
  62. ContractPaymentServiceAmountId int `json:"contract_payment_service_amount_id"`
  63. ServiceTemplateId int `json:"service_template_id" description:"套餐ID"`
  64. ServiceTemplatePid int `json:"service_template_pid" description:"套餐父级ID"`
  65. Amount float64 `json:"amount" description:"分配金额"`
  66. }
  67. // CreatePaymentServiceAmount 分配到款套餐金额
  68. func CreatePaymentServiceAmount(registerId, payId int, addList []*ContractPaymentServiceAmount) (err error) {
  69. tx := global.DEFAULT_MYSQL.Begin()
  70. defer func() {
  71. if err != nil {
  72. tx.Rollback()
  73. } else {
  74. tx.Commit()
  75. }
  76. }()
  77. // 删除原分配信息
  78. sql := `DELETE FROM contract_payment_service_amount WHERE contract_register_id = ? AND contract_payment_id = ?`
  79. tx.Exec(sql, registerId, payId)
  80. // 新增分配信息
  81. if len(addList) > 0 {
  82. tx.CreateInBatches(addList, len(addList))
  83. }
  84. return
  85. }
  86. // GetIndustryServiceTempAmount 获取对应的主客观分配的金额
  87. func GetIndustryServiceTempAmount(contractPaymentIds []int) (list []*ContractPaymentServiceAmount, err error) {
  88. err = global.DEFAULT_MYSQL.Model(ContractPaymentServiceAmount{}).
  89. Where("is_deleted = 0").
  90. Where("service_template_pid > 0").
  91. Find(&list).Error
  92. return
  93. }