active.pay.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package shanghu
  2. import (
  3. "duoduo/apis/shanghu/models"
  4. "duoduo/models/shanghu"
  5. "duoduo/tools/app"
  6. "errors"
  7. "github.com/gin-gonic/gin"
  8. "time"
  9. )
  10. // 待核销金额
  11. func PendingCancelAmount(c *gin.Context) {
  12. var inData models.PendingCancelAmountRequest
  13. var activePayTransSql shanghu.ClientActivePayTrans
  14. var outData models.PendingCancelAmountReply
  15. err := c.ShouldBindJSON(&inData)
  16. if err != nil {
  17. app.Error(c, 400, err, err.Error())
  18. return
  19. }
  20. if inData.Type == 1 { //商家
  21. activePayTransSql.MerchantOpenID = inData.OpenId
  22. activeAmount, err := activePayTransSql.GetPendingCancelByMerchant()
  23. if err != nil {
  24. app.Error(c, 500, err, err.Error())
  25. return
  26. }
  27. outData.Amount = activeAmount.MerchantAmount.String()
  28. } else if inData.Type == 2 { //个人
  29. activePayTransSql.ClientOpenID = inData.OpenId
  30. activeAmount, err := activePayTransSql.GetPendingCancelByClient()
  31. if err != nil {
  32. app.Error(c, 500, err, err.Error())
  33. return
  34. }
  35. outData.Amount = activeAmount.ClientAmount.String()
  36. } else {
  37. app.Error(c, 500, errors.New("type 类型错误"), err.Error())
  38. return
  39. }
  40. app.OK(c, outData, app.Success)
  41. }
  42. // 拼团购买
  43. func GetGroupBuyPay(c *gin.Context) {
  44. var inData models.GetGroupBuyPayRequest
  45. var sqlData shanghu.ClientActivePayTrans
  46. var outData []models.GetGroupBuyPayReply
  47. err := c.ShouldBindJSON(&inData)
  48. if err != nil {
  49. app.Error(c, 400, err, err.Error())
  50. return
  51. }
  52. // 不是商家也不是c端客户
  53. if inData.UserType != 1 && inData.UserType != 2 {
  54. app.Error(c, 500, errors.New("用户类型错误"), err.Error())
  55. return
  56. }
  57. // 核销类型错误
  58. if inData.GroupBuyType != 1 && inData.GroupBuyType != 2 {
  59. app.Error(c, 500, errors.New("核销类型错误"), err.Error())
  60. return
  61. }
  62. var pageSize = 10
  63. var pageIndex = 1
  64. if inData.PageSize != 0 {
  65. pageSize = inData.PageSize
  66. }
  67. if inData.PageIndex != 0 {
  68. pageIndex = inData.PageIndex
  69. }
  70. activeDrawLogList, count, err := sqlData.GetActivePayTransList(pageSize, pageIndex, inData.UserType, inData.GroupBuyType, inData.OpenId)
  71. if err != nil {
  72. app.Error(c, 500, err, err.Error())
  73. return
  74. }
  75. for _, v := range activeDrawLogList {
  76. var data models.GetGroupBuyPayReply
  77. var activeSql shanghu.MerchantActiveConfig
  78. var groupBuySql shanghu.MerchantActiveGroupBuy
  79. data.MerchantAmount = v.MerchantAmount.String()
  80. data.Amount = v.Amount.String()
  81. data.ClientAmount = v.ClientAmount.String()
  82. data.PayTime = v.PayTime.Format(time.DateTime)
  83. activeSql.ID = v.ActiveConfigID
  84. activeInfo, err := activeSql.GetConfigInfoById()
  85. if err != nil {
  86. app.Error(c, 500, err, err.Error())
  87. return
  88. }
  89. data.ActiveName = activeInfo.ActiveName
  90. groupBuySql.ID = v.GroupBuyID
  91. groupBuyInfo, err := groupBuySql.GetMerchantActiveGroupBuyById()
  92. if err != nil {
  93. app.Error(c, 500, err, err.Error())
  94. return
  95. }
  96. data.GroupBuyName = groupBuyInfo.GroupBuyName
  97. data.PayTime = v.PayTime.Format(time.DateTime)
  98. outData = append(outData, data)
  99. }
  100. app.PageOK(c, outData, count, pageIndex, pageSize, app.Success)
  101. }