package fms import ( "hongze/fms_api/global" "hongze/fms_api/models/base" ) // ContractPaymentServiceAmount 到款登记-套餐金额分配表 type ContractPaymentServiceAmount struct { ContractPaymentServiceAmountId int `gorm:"primaryKey;column:contract_payment_service_amount_id" json:"contract_payment_service_amount_id"` ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"合同登记ID"` ContractPaymentId int `gorm:"column:contract_payment_id" json:"contract_payment_id" description:"到款登记ID"` ServiceTemplateId int `gorm:"column:service_template_id" json:"service_template_id" description:"套餐ID"` ServiceTemplatePid int `gorm:"column:service_template_pid" json:"service_template_pid" description:"套餐父级ID"` Amount float64 `gorm:"column:amount" json:"amount" description:"分配金额"` IsDeleted int `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"` base.TimeBase } func (c *ContractPaymentServiceAmount) TableName() string { return "contract_payment_service_amount" } func (c *ContractPaymentServiceAmount) Create() (err error) { err = global.DEFAULT_MYSQL.Create(c).Error return } func (c *ContractPaymentServiceAmount) AddInBatches(list []*ContractPaymentServiceAmount) (err error) { err = global.DEFAULT_MYSQL.CreateInBatches(list, len(list)).Error return } func (c *ContractPaymentServiceAmount) Update(updateCols []string) (err error) { err = global.DEFAULT_MYSQL.Model(c).Select(updateCols).Updates(c).Error return } func (c *ContractPaymentServiceAmount) List(condition string, pars []interface{}) (list []*ContractPaymentServiceAmount, err error) { list = make([]*ContractPaymentServiceAmount, 0) err = global.DEFAULT_MYSQL.Model(c). Where("is_deleted = 0"). Where(condition, pars...). Find(&list).Error return } // ContractPaymentServiceAmountItem 到款套餐分配信息 type ContractPaymentServiceAmountItem struct { ContractPaymentServiceAmountId int `json:"contract_payment_service_amount_id"` ContractPaymentId int `json:"contract_payment_id" description:"到款登记ID"` ServiceTemplateId int `json:"service_template_id" description:"套餐ID"` ServiceTemplatePid int `json:"service_template_pid" description:"套餐父级ID"` ServiceTemplateName string `json:"service_template_name"` Amount float64 `json:"amount" description:"分配金额"` } // DistributePaymentServiceAmountReq 到款登记-分配套餐金额请求体 type DistributePaymentServiceAmountReq struct { ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"` ContractPaymentId int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"` List []*DistributePaymentServiceAmountItem `json:"list"` } // GetPaymentServiceAmountReq 到款登记-查询分配套餐金额请求体 type GetPaymentServiceAmountReq struct { ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"` ContractPaymentId int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"` } // DistributePaymentServiceAmountItem 到款登记-分配套餐金额列表信息 type DistributePaymentServiceAmountItem struct { ContractPaymentServiceAmountId int `json:"contract_payment_service_amount_id"` ServiceTemplateId int `json:"service_template_id" description:"套餐ID"` ServiceTemplatePid int `json:"service_template_pid" description:"套餐父级ID"` Amount float64 `json:"amount" description:"分配金额"` } // CreatePaymentServiceAmount 分配到款套餐金额 func CreatePaymentServiceAmount(registerId, payId int, addList []*ContractPaymentServiceAmount) (err error) { tx := global.DEFAULT_MYSQL.Begin() defer func() { if err != nil { tx.Rollback() } else { tx.Commit() } }() // 删除原分配信息 sql := `DELETE FROM contract_payment_service_amount WHERE contract_register_id = ? AND contract_payment_id = ?` tx.Exec(sql, registerId, payId) // 新增分配信息 if len(addList) > 0 { tx.CreateInBatches(addList, len(addList)) } return } // GetIndustryServiceTempAmount 获取对应的主客观分配的金额 func GetIndustryServiceTempAmount(contractPaymentIds []int) (list []*ContractPaymentServiceAmount, err error) { err = global.DEFAULT_MYSQL.Model(ContractPaymentServiceAmount{}). Where("is_deleted = 0"). Where("service_template_pid > 0"). Find(&list).Error return }