contract_pre_payment.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. PaymentDate time.Time `gorm:"column:payment_date" json:"payment_date" description:"约定结束时间"`
  26. base.TimeBase
  27. }
  28. type ContractPrePaymentRespItem struct {
  29. PrePayId int `gorm:"primaryKey;column:pre_pay_id" json:"pre_pay_id" description:"预付款ID"`
  30. CompanyName string `json:"company_name" description:"客户名称"`
  31. ContractRegisterId int `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
  32. ContractCode string `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
  33. Amount float64 `gorm:"column:amount" json:"amount" description:"换算后的金额(人民币)"`
  34. OriginAmount float64 `gorm:"column:origin_amount" json:"origin_amount" description:"到款金额"`
  35. CurrencyUnit string `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
  36. UnitName string `gorm:"unit_name" json:"unit_name" description:"单位名称"`
  37. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  38. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  39. AdminId int `gorm:"column:admin_id" json:"admin_id" description:"操作人ID"`
  40. AdminName string `gorm:"column:admin_name" json:"admin_name" description:"操作人姓名"`
  41. Remark string `gorm:"column:remark" json:"remark" description:"备注信息"`
  42. StartDate string `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
  43. EndDate string `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
  44. PaymentDate string `gorm:"column:payment_date" json:"payment_date" description:"约定结束时间"`
  45. NewCompany int `gorm:"column:new_company" json:"new_company" description:"是否为新客户: 0-否; 1-是"`
  46. CreateTime string `gorm:"autoCreateTime;column:create_time" json:"create_time" description:"创建时间"`
  47. ModifyTime string `gorm:"autoUpdateTime:milli;column:modify_time" json:"modify_time" description:"最后更新时间"`
  48. }
  49. func (c *ContractPrePayment) TableName() string {
  50. return "contract_pre_payment"
  51. }
  52. // ContractRegisterListReq 合同登记列表请求体
  53. type PrePayListReq struct {
  54. Keyword string `json:"keyword" form:"keyword" binding:"omitempty" description:"关键词"`
  55. StartDate string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"约定开始时间"`
  56. EndDate string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"约定结束时间"`
  57. SortType int `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
  58. base.PageReq
  59. }
  60. // GetPrePayItemPageList 获取预登记列表-分页
  61. func GetPrePayItemPageList(page base.IPage, condition string, pars []interface{}) (count int64, results []*ContractPrePaymentRespItem, err error) {
  62. list := make([]*ContractPrePayment, 0)
  63. query := global.DEFAULT_MYSQL.Table("contract_pre_payment").
  64. Where(condition, pars...)
  65. query.Count(&count)
  66. if len(page.GetOrderItemsString()) > 0 {
  67. query = query.Order(page.GetOrderItemsString())
  68. }
  69. err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&list).Error
  70. if err != nil {
  71. return
  72. }
  73. for i := range list {
  74. results = append(results, formatPrePay2Item(list[i]))
  75. }
  76. return
  77. }
  78. // formatPrePay2Item 格式化PrePay
  79. func formatPrePay2Item(item *ContractPrePayment) (formatItem *ContractPrePaymentRespItem) {
  80. formatItem = new(ContractPrePaymentRespItem)
  81. formatItem.PrePayId = item.PrePayId
  82. formatItem.ContractRegisterId = item.ContractRegisterId
  83. formatItem.ContractCode = item.ContractCode
  84. formatItem.CompanyName = item.CompanyName
  85. formatItem.SellerId = item.SellerId
  86. formatItem.SellerName = item.SellerName
  87. formatItem.Amount = item.Amount
  88. formatItem.OriginAmount = item.OriginAmount
  89. formatItem.CurrencyUnit = item.CurrencyUnit
  90. formatItem.StartDate = utils.TimeTransferString(utils.FormatDate, item.StartDate)
  91. formatItem.EndDate = utils.TimeTransferString(utils.FormatDate, item.EndDate)
  92. formatItem.AdminId = item.AdminId
  93. formatItem.AdminName = item.AdminName
  94. formatItem.Remark = item.Remark
  95. formatItem.NewCompany = item.NewCompany
  96. formatItem.PaymentDate = utils.TimeTransferString(utils.FormatDate, item.PaymentDate)
  97. formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
  98. formatItem.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, item.ModifyTime)
  99. return
  100. }
  101. // PrepayAddReq 新增到款预登记请求体
  102. type PreRegisterAddReq struct {
  103. CompanyName string `json:"company_name" binding:"required" description:"客户名称"`
  104. StartDate string `json:"start_date" description:"约定开始日期"`
  105. EndDate string `json:"end_date" description:"约定结束日期"`
  106. RegisterType int `json:"register_type" description:"预登记类型 3-开票预登记 4-到款预登记"`
  107. ProductIds string `gorm:"column:product_ids" json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
  108. SellerIds string `json:"seller_ids" description:"CRM系统-销售ID"`
  109. ContractType int `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
  110. HasPayment int `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
  111. List []PreRegisterAddReqItem `json:"list" binding:"required" description:"预登记列表"`
  112. Services []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
  113. }
  114. type PreRegisterAddReqItem struct {
  115. Amount float64 `json:"amount" binding:"required" description:"到款金额"`
  116. CurrencyUnit string `json:"currency_unit" binding:"required" description:"货币单位"`
  117. Remark string `json:"remark" description:"备注信息"`
  118. RegisterDate string `json:"register_date" description:"到款或开票日期"`
  119. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  120. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  121. ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  122. }
  123. func (c *ContractPrePayment) Create() (err error) {
  124. err = global.DEFAULT_MYSQL.Create(c).Error
  125. return
  126. }
  127. func (c *ContractPrePayment) Fetch(id int) (item *ContractPrePayment, err error) {
  128. err = global.DEFAULT_MYSQL.Model(c).Where(" pre_pay_id = ?", id).First(&item).Error
  129. return
  130. }
  131. func (c *ContractPrePayment) Update(updateCols []string) (err error) {
  132. err = global.DEFAULT_MYSQL.Model(c).Select(updateCols).Updates(c).Error
  133. return
  134. }
  135. // 删除
  136. func (c *ContractPrePayment) Delete() (err error) {
  137. err = global.DEFAULT_MYSQL.Delete(c).Error
  138. return
  139. }
  140. // PrepayEditReq 编辑到款预登记请求体
  141. type PreRegisterEditReq struct {
  142. PreRegisterId int `json:"pre_register_id" description:"预登记ID"`
  143. ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"登记ID"`
  144. CompanyName string `json:"company_name" binding:"required" description:"客户名称"`
  145. StartDate string `json:"start_date" description:"约定开始日期"`
  146. EndDate string `json:"end_date" description:"约定结束日期"`
  147. RegisterType int `json:"register_type" description:"预登记类型 3-开票预登记 4-到款预登记"`
  148. ProductIds string `gorm:"column:product_ids" json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
  149. SellerIds string `json:"seller_ids" description:"CRM系统-销售ID"`
  150. DelInvoiceIds []int `json:"del_invoice_ids" description:"删除的开票到款记录ids"`
  151. DelPreRegisterIds []int `json:"del_pre_register_ids" description:"删除的预登记记录ids"`
  152. ContractType int `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
  153. HasPayment int `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
  154. List []*PreRegisterEditReqItem
  155. Services []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
  156. }
  157. type PreRegisterEditReqItem struct {
  158. PreRegisterId int `json:"pre_register_id" description:"预登记ID"`
  159. InvoiceId int `json:"contract_invoice_id" description:"开票ID"`
  160. ArriveId int `json:"arrive_id" description:"到款ID"`
  161. Amount float64 `json:"amount" binding:"required" description:"到款金额"`
  162. CurrencyUnit string `json:"currency_unit" binding:"required" description:"货币单位"`
  163. Remark string `json:"remark" description:"备注信息"`
  164. RegisterDate string `json:"register_date" description:"到款或开票日期"`
  165. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  166. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  167. ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  168. }
  169. // PreRegisterDelReq 预登记删除请求体
  170. type PreRegisterDelReq struct {
  171. ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"登记ID"`
  172. InvoiceId int `json:"invoice_id" description:"开票ID"`
  173. ArriveId int `json:"arrive_id" description:"到款ID"`
  174. PreRegisterId int `json:"pre_register_id" description:"预登记ID"`
  175. }
  176. type PreRegisterSaveReqItem struct {
  177. PreRegisterId int `json:"pre_register_id" description:"预登记ID"`
  178. InvoiceId int `json:"contract_invoice_id" description:"开票ID"`
  179. Amount float64 `json:"amount" binding:"required" description:"到款金额"`
  180. CurrencyUnit string `json:"currency_unit" binding:"required" description:"货币单位"`
  181. Remark string `json:"remark" description:"备注信息"`
  182. RegisterDate string `json:"register_date" description:"到款或开票日期"`
  183. SellerId int `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
  184. SellerName string `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
  185. ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
  186. }
  187. // PreRegisterSaveReq 预登记保存请求体
  188. type PreRegisterSaveReq struct {
  189. PreRegisterId int `json:"pre_register_id" description:"预登记ID"`
  190. ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"登记ID"`
  191. CompanyName string `json:"company_name" description:"客户名称"`
  192. StartDate string `json:"start_date" binding:"required" description:"约定开始日期"`
  193. EndDate string `json:"end_date" binding:"required" description:"约定结束日期"`
  194. RegisterType int `json:"register_type" description:"预登记类型 3-开票预登记 4-到款预登记"`
  195. ProductIds string `gorm:"column:product_ids" json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
  196. SellerIds string `json:"seller_ids" description:"CRM系统-销售ID"`
  197. ContractType int `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
  198. HasPayment int `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
  199. List []PreRegisterSaveReqItem `json:"list" binding:"required" description:"预登记列表"`
  200. Services []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
  201. }