order.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package http
  2. import (
  3. "fmt"
  4. "go-common/app/service/main/vip/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/metadata"
  9. )
  10. func status(c *bm.Context) {
  11. var (
  12. o *model.OrderInfo
  13. vip *model.VipInfo
  14. err error
  15. )
  16. arg := new(struct {
  17. OrderNo string `form:"order_no" validate:"required"`
  18. })
  19. if err = c.Bind(arg); err != nil {
  20. log.Error("c.Bind err(%+v)", err)
  21. return
  22. }
  23. if o, err = vipSvc.OrderInfo(c, arg.OrderNo); err != nil {
  24. log.Error("vipSvc.OrderInfo(%s) err(%+v)", arg.OrderNo, err)
  25. c.JSON(nil, err)
  26. return
  27. }
  28. if o == nil {
  29. c.JSON(nil, ecode.VipOrderNotFoundErr)
  30. return
  31. }
  32. res := new(struct {
  33. OrderNo string `json:"order_no"`
  34. Status int8 `json:"status"`
  35. Message *model.OrderMessage `json:"message"`
  36. })
  37. res.OrderNo = o.OrderNo
  38. res.Status = o.Status
  39. if o.Status == model.SUCCESS {
  40. if vip, err = vipSvc.VipInfo(c, o.Mid); err != nil {
  41. c.JSON(nil, err)
  42. return
  43. }
  44. message := new(model.OrderMessage)
  45. message.RightButton = "知道了"
  46. message.Title = "开通成功"
  47. message.Content = fmt.Sprintf("你已成功开通%d个月大会员,目前有效期%s", o.BuyMonths, vip.VipOverdueTime.Time().Format("2006-01-02"))
  48. res.Message = message
  49. } else if o.Status == model.FAILED {
  50. message := new(model.OrderMessage)
  51. message.RightButton = "知道了"
  52. message.Title = "支付失败"
  53. message.Content = fmt.Sprintf("订单号:%s \nUID:%d \n支付失败了,试试重新购买吧。", o.OrderNo, vip.Mid)
  54. res.Message = message
  55. }
  56. c.JSON(res, nil)
  57. }
  58. func orders(c *bm.Context) {
  59. var (
  60. orders []*model.PayOrderResp
  61. total int64
  62. err error
  63. )
  64. arg := new(struct {
  65. Mid int64 `form:"mid" validate:"required,min=1,gte=1"`
  66. Ps int `form:"ps" default:"20" validate:"min=0,max=50"`
  67. Pn int `form:"pn" default:"1"`
  68. })
  69. if err = c.Bind(arg); err != nil {
  70. log.Error("c.Bind err(%+v)", err)
  71. return
  72. }
  73. if orders, total, err = vipSvc.OrderList(c, arg.Mid, arg.Pn, arg.Ps); err != nil {
  74. log.Error("vipSvc.OrderList(%d) err(%+v)", arg.Mid, err)
  75. c.JSON(nil, err)
  76. return
  77. }
  78. res := new(struct {
  79. Data []*model.PayOrderResp `json:"list"`
  80. Total int64 `json:"total"`
  81. })
  82. res.Data = orders
  83. res.Total = total
  84. c.JSON(orders, nil)
  85. }
  86. func createOrder(c *bm.Context) {
  87. var (
  88. err error
  89. pp map[string]interface{}
  90. )
  91. arg := new(model.ArgCreateOrder)
  92. if err = c.Bind(arg); err != nil {
  93. log.Error("c.Bind err(%+v)", err)
  94. return
  95. }
  96. if pp, err = vipSvc.CreateOrder(c, arg, metadata.String(c, metadata.RemoteIP)); err != nil {
  97. log.Error("vipSvc.CreateOrder(%d) err(%+v)", arg.Mid, err)
  98. c.JSON(nil, err)
  99. return
  100. }
  101. c.JSON(pp, nil)
  102. }
  103. func pannelInfoNew(c *bm.Context) {
  104. var (
  105. pi *model.PannelInfo
  106. err error
  107. )
  108. arg := new(model.ArgPannel)
  109. if err = c.Bind(arg); err != nil {
  110. log.Error("pannelInfoNew(%+v)", err)
  111. return
  112. }
  113. if pi, err = vipSvc.PannelInfoNew(c, arg.Mid, arg); err != nil {
  114. log.Error("vipSvc.PannelInfoNew(%d) err(%+v)", arg.Mid, err)
  115. c.JSON(nil, err)
  116. return
  117. }
  118. c.JSON(pi, nil)
  119. }
  120. func createOldOrder(c *bm.Context) {
  121. var (
  122. err error
  123. )
  124. arg := new(model.ArgOldPayOrder)
  125. if err = c.Bind(arg); err != nil {
  126. log.Error("c.Bind err(%+v)", err)
  127. return
  128. }
  129. c.JSON(nil, vipSvc.CreateOldOrder(c, arg))
  130. }
  131. func orderMng(c *bm.Context) {
  132. var (
  133. err error
  134. order *model.OrderMng
  135. )
  136. arg := new(struct {
  137. Mid int64 `form:"mid" validate:"required,min=1,gte=1"`
  138. })
  139. if err = c.Bind(arg); err != nil {
  140. log.Error("c.Bind err(%+v)", err)
  141. return
  142. }
  143. if order, err = vipSvc.OrderMng(c, arg.Mid); err != nil {
  144. c.JSON(nil, err)
  145. return
  146. }
  147. c.JSON(order, err)
  148. }
  149. func rescision(c *bm.Context) {
  150. var (
  151. err error
  152. )
  153. arg := new(struct {
  154. Mid int64 `form:"mid" validate:"required,mid=1,gte=1"`
  155. DeviceType int32 `form:"deviceType" validate:"required"`
  156. })
  157. if err = c.Bind(arg); err != nil {
  158. return
  159. }
  160. err = vipSvc.Rescision(c, arg.Mid, arg.DeviceType)
  161. c.JSON(nil, err)
  162. }