server.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Package server generate by warden_gen
  2. package server
  3. import (
  4. "context"
  5. v1 "go-common/app/service/main/coupon/api"
  6. "go-common/app/service/main/coupon/model"
  7. "go-common/app/service/main/coupon/service"
  8. "go-common/library/net/rpc/warden"
  9. )
  10. // New VipInfo warden rpc server
  11. func New(c *warden.ServerConfig, svr *service.Service) *warden.Server {
  12. ws := warden.NewServer(c)
  13. v1.RegisterCouponServer(ws.Server(), &server{svr})
  14. ws, err := ws.Start()
  15. if err != nil {
  16. panic(err)
  17. }
  18. return ws
  19. }
  20. type server struct {
  21. svr *service.Service
  22. }
  23. var _ v1.CouponServer = &server{}
  24. func (s *server) CaptchaToken(c context.Context, req *v1.CaptchaTokenReq) (res *v1.CaptchaTokenReply, err error) {
  25. var token *model.Token
  26. if token, err = s.svr.CaptchaToken(c, req.Ip); err != nil || token == nil {
  27. return
  28. }
  29. return &v1.CaptchaTokenReply{
  30. Token: token.Token,
  31. Url: token.URL,
  32. }, err
  33. }
  34. func (s *server) UseCouponCode(c context.Context, req *v1.UseCouponCodeReq) (res *v1.UseCouponCodeResp, err error) {
  35. var data *model.UseCouponCodeResp
  36. if data, err = s.svr.UseCouponCode(c, &model.ArgUseCouponCode{
  37. Token: req.Token,
  38. Code: req.Code,
  39. Verify: req.Verify,
  40. IP: req.Ip,
  41. Mid: req.Mid,
  42. }); err != nil || data == nil {
  43. return
  44. }
  45. return &v1.UseCouponCodeResp{
  46. CouponToken: data.CouponToken,
  47. CouponAmount: data.CouponAmount,
  48. FullAmount: data.FullAmount,
  49. PlatfromLimitExplain: data.PlatfromLimitExplain,
  50. ProductLimitMonth: data.ProductLimitMonth,
  51. ProductLimitRenewal: data.ProductLimitRenewal,
  52. }, err
  53. }
  54. func (s *server) UsableAllowanceCouponV2(c context.Context, req *v1.UsableAllowanceCouponV2Req) (res *v1.UsableAllowanceCouponV2Reply, err error) {
  55. var (
  56. data *model.CouponTipInfo
  57. ci *v1.ModelCouponAllowancePanelInfo
  58. )
  59. if data, err = s.svr.UsableAllowanceCouponV2(c, req); err != nil {
  60. return
  61. }
  62. if data.CouponInfo != nil {
  63. ci = &v1.ModelCouponAllowancePanelInfo{
  64. CouponToken: data.CouponInfo.CouponToken,
  65. CouponAmount: data.CouponInfo.Amount,
  66. State: data.CouponInfo.State,
  67. FullAmount: data.CouponInfo.FullAmount,
  68. FullLimitExplain: data.CouponInfo.FullLimitExplain,
  69. ScopeExplain: data.CouponInfo.ScopeExplain,
  70. CouponDiscountPrice: data.CouponInfo.CouponDiscountPrice,
  71. StartTime: data.CouponInfo.StartTime,
  72. ExpireTime: data.CouponInfo.ExpireTime,
  73. Selected: int32(data.CouponInfo.Selected),
  74. DisablesExplains: data.CouponInfo.DisablesExplains,
  75. OrderNo: data.CouponInfo.OrderNO,
  76. Name: data.CouponInfo.Name,
  77. Usable: int32(data.CouponInfo.Usable),
  78. }
  79. }
  80. return &v1.UsableAllowanceCouponV2Reply{
  81. CouponTip: data.CouponTip,
  82. CouponInfo: ci,
  83. }, err
  84. }