contract_payment_service_amount.go 3.8 KB

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