contract_pre_payment.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package fms
  2. import (
  3. "hongze/fms_api/global"
  4. "hongze/fms_api/models/base"
  5. "hongze/fms_api/utils"
  6. "time"
  7. )
  8. // ContractInvoice 合同开票表
  9. type ContractPrePayment struct {
  10. PrePayId int `gorm:"primaryKey;column:pre_pay_id" json:"pre_pay_id" description:"预付款ID"`
  11. CompanyName string `json:"company_name" description:"客户名称"`
  12. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  13. ContractCode string `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
  14. Amount float64 `gorm:"column:amount" json:"amount" description:"换算后的金额(人民币)"`
  15. OriginAmount float64 `gorm:"column:origin_amount" json:"origin_amount" description:"到款金额"`
  16. CurrencyUnit string `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
  17. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  18. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  19. AdminId int `gorm:"column:admin_id" json:"admin_id" description:"操作人ID"`
  20. AdminName string `gorm:"column:admin_name" json:"admin_name" description:"操作人姓名"`
  21. Remark string `gorm:"column:remark" json:"remark" description:"备注信息"`
  22. StartDate time.Time `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
  23. EndDate time.Time `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
  24. NewCompany int `gorm:"column:new_company" json:"new_company" description:"是否为新客户: 0-否; 1-是"`
  25. base.TimeBase
  26. }
  27. type ContractPrePaymentRespItem struct {
  28. PrePayId int `gorm:"primaryKey;column:pre_pay_id" json:"pre_pay_id" description:"预付款ID"`
  29. CompanyName string `json:"company_name" description:"客户名称"`
  30. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  31. ContractCode string `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
  32. Amount float64 `gorm:"column:amount" json:"amount" description:"换算后的金额(人民币)"`
  33. OriginAmount float64 `gorm:"column:origin_amount" json:"origin_amount" description:"到款金额"`
  34. CurrencyUnit string `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
  35. UnitName string `gorm:"unit_name" json:"unit_name" description:"单位名称"`
  36. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  37. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  38. AdminId int `gorm:"column:admin_id" json:"admin_id" description:"操作人ID"`
  39. AdminName string `gorm:"column:admin_name" json:"admin_name" description:"操作人姓名"`
  40. Remark string `gorm:"column:remark" json:"remark" description:"备注信息"`
  41. StartDate string `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
  42. EndDate string `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
  43. NewCompany int `gorm:"column:new_company" json:"new_company" description:"是否为新客户: 0-否; 1-是"`
  44. CreateTime string `gorm:"autoCreateTime;column:create_time" json:"create_time" description:"创建时间"`
  45. ModifyTime string `gorm:"autoUpdateTime:milli;column:modify_time" json:"modify_time" description:"最后更新时间"`
  46. }
  47. func (c *ContractPrePayment) TableName() string {
  48. return "contract_pre_payment"
  49. }
  50. // ContractRegisterListReq 合同登记列表请求体
  51. type PrePayListReq struct {
  52. Keyword string `json:"keyword" form:"keyword" binding:"omitempty" description:"关键词"`
  53. StartDate string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"约定开始时间"`
  54. EndDate string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"约定结束时间"`
  55. SortType int `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
  56. base.PageReq
  57. }
  58. // GetPrePayItemPageList 获取预登记列表-分页
  59. func GetPrePayItemPageList(page base.IPage, condition string, pars []interface{}) (count int64, results []*ContractPrePaymentRespItem, err error) {
  60. list := make([]*ContractPrePayment, 0)
  61. query := global.DEFAULT_MYSQL.Table("contract_pre_payment").
  62. Where(condition, pars...)
  63. query.Count(&count)
  64. if len(page.GetOrderItemsString()) > 0 {
  65. query = query.Order(page.GetOrderItemsString())
  66. }
  67. err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&list).Error
  68. if err != nil {
  69. return
  70. }
  71. for i := range list {
  72. results = append(results, formatPrePay2Item(list[i]))
  73. }
  74. return
  75. }
  76. // formatPrePay2Item 格式化PrePay
  77. func formatPrePay2Item(item *ContractPrePayment) (formatItem *ContractPrePaymentRespItem) {
  78. formatItem = new(ContractPrePaymentRespItem)
  79. formatItem.PrePayId = item.PrePayId
  80. formatItem.ContractRegisterId = item.ContractRegisterId
  81. formatItem.ContractCode = item.ContractCode
  82. formatItem.CompanyName = item.CompanyName
  83. formatItem.SellerId = item.SellerId
  84. formatItem.SellerName = item.SellerName
  85. formatItem.Amount = item.Amount
  86. formatItem.OriginAmount = item.OriginAmount
  87. formatItem.CurrencyUnit = item.CurrencyUnit
  88. formatItem.StartDate = utils.TimeTransferString(utils.FormatDate, item.StartDate)
  89. formatItem.EndDate = utils.TimeTransferString(utils.FormatDate, item.EndDate)
  90. formatItem.AdminId = item.AdminId
  91. formatItem.AdminName = item.AdminName
  92. formatItem.Remark = item.Remark
  93. formatItem.NewCompany = item.NewCompany
  94. formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
  95. formatItem.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, item.ModifyTime)
  96. return
  97. }
  98. // PrepayAddReq 新增到款预登记请求体
  99. type PrepayAddReq struct {
  100. CompanyName string `json:"company_name" binding:"required" description:"客户名称"`
  101. SellerId int `json:"seller_id" binding:"required" description:"CRM系统-销售ID"`
  102. SellerName string `json:"seller_name" binding:"required" description:"CRM系统-销售名称"`
  103. Amount float64 `json:"amount" binding:"required" description:"到款金额"`
  104. CurrencyUnit string `json:"currency_unit" binding:"required" description:"货币单位"`
  105. StartDate string `json:"start_date" binding:"required" description:"约定开始日期"`
  106. EndDate string `json:"end_date" binding:"required" description:"约定结束日期"`
  107. Remark string `json:"remark" description:"备注信息"`
  108. NewCompany int `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
  109. }
  110. func (c *ContractPrePayment) Create() (err error) {
  111. err = global.DEFAULT_MYSQL.Create(c).Error
  112. return
  113. }
  114. func (c *ContractPrePayment) Fetch(id int) (item *ContractPrePayment, err error) {
  115. err = global.DEFAULT_MYSQL.Model(c).Where(" pre_pay_id = ?", id).First(&item).Error
  116. return
  117. }
  118. func (c *ContractPrePayment) Update(updateCols []string) (err error) {
  119. err = global.DEFAULT_MYSQL.Model(c).Select(updateCols).Updates(c).Error
  120. return
  121. }
  122. // 删除
  123. func (c *ContractPrePayment) Delete() (err error) {
  124. err = global.DEFAULT_MYSQL.Delete(c).Error
  125. return
  126. }
  127. // PrepayEditReq 编辑到款预登记请求体
  128. type PrepayEditReq struct {
  129. PrePayId int `json:"pre_pay_id" binding:"required,gte=1" description:"预付款ID"`
  130. PrepayAddReq
  131. }
  132. // PrepayDelReq 删除到款预登记
  133. type PrepayDelReq struct {
  134. PrePayId int `json:"pre_pay_id" binding:"required,gte=1" description:"预付款ID"`
  135. }