payment.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package contract
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/fms_api/controller/resp"
  6. "hongze/fms_api/global"
  7. "hongze/fms_api/models/fms"
  8. "hongze/fms_api/utils"
  9. "time"
  10. )
  11. type PaymentController struct{}
  12. // UpdatePaymentPayType
  13. // @Title 修改付款方式
  14. // @Description 修改付款方式
  15. // @Param request body fms.UpdatePaymentPayTypeReq true "type json string"
  16. // @Success 200 string "操作成功"
  17. // @router /contract/payment/update_pay_type [post]
  18. func (ct *PaymentController) UpdatePaymentPayType(c *gin.Context) {
  19. req := new(fms.UpdatePaymentPayTypeReq)
  20. err := c.ShouldBind(&req)
  21. if err != nil {
  22. errs, ok := err.(validator.ValidationErrors)
  23. if !ok {
  24. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  25. return
  26. }
  27. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  28. return
  29. }
  30. ob := new(fms.ContractInvoice)
  31. item, e := ob.Fetch(req.ContractPaymentId)
  32. if e != nil {
  33. if e == utils.ErrNoRow {
  34. resp.Fail("到款登记不存在或已被删除", c)
  35. return
  36. }
  37. resp.FailMsg("获取到款登记失败", "Err:"+e.Error(), c)
  38. return
  39. }
  40. nowTime := time.Now().Local()
  41. item.PayType = req.PayType
  42. item.ModifyTime = nowTime
  43. updateCols := []string{"PayType", "ModifyTime"}
  44. if e = item.Update(updateCols); e != nil {
  45. resp.FailMsg("操作失败", "更新到款登记失败, Err:"+e.Error(), c)
  46. return
  47. }
  48. resp.Ok("操作成功", c)
  49. }
  50. // DistributePaymentServiceAmount
  51. // @Title 分配套餐金额
  52. // @Description 分配套餐金额
  53. // @Param request body fms.DistributePaymentServiceAmountReq true "type json string"
  54. // @Success 200 string "操作成功"
  55. // @router /contract/payment/distribute_service_amount [post]
  56. func (ct *PaymentController) DistributePaymentServiceAmount(c *gin.Context) {
  57. req := new(fms.DistributePaymentServiceAmountReq)
  58. err := c.ShouldBind(&req)
  59. if err != nil {
  60. errs, ok := err.(validator.ValidationErrors)
  61. if !ok {
  62. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  63. return
  64. }
  65. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  66. return
  67. }
  68. addList := make([]*fms.ContractPaymentServiceAmount, 0)
  69. for i := range req.List {
  70. if req.List[i].Amount <= 0 {
  71. continue
  72. }
  73. if req.List[i].ServiceTemplateId <= 0 {
  74. resp.Fail("套餐信息有误", c)
  75. return
  76. }
  77. v := &fms.ContractPaymentServiceAmount{
  78. ContractRegisterId: req.ContractRegisterId,
  79. ContractPaymentId: req.ContractPaymentId,
  80. ServiceTemplatePid: req.List[i].ServiceTemplatePid,
  81. ServiceTemplateId: req.List[i].ServiceTemplateId,
  82. Amount: req.List[i].Amount,
  83. }
  84. v.Set()
  85. addList = append(addList, v)
  86. }
  87. if e := fms.CreatePaymentServiceAmount(req.ContractRegisterId, req.ContractPaymentId, addList); e != nil {
  88. resp.FailMsg("操作失败", "新增到款套餐金额失败, Err: "+e.Error(), c)
  89. return
  90. }
  91. resp.Ok("操作成功", c)
  92. }