exp.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package grpc
  2. import (
  3. "context"
  4. "go-common/app/service/main/member/api"
  5. "go-common/app/service/main/member/model"
  6. )
  7. // Exp get member exp info
  8. func (s *MemberServer) Exp(ctx context.Context, req *api.MidReq) (*api.LevelInfoReply, error) {
  9. res, err := s.svr.Exp(ctx, req.Mid)
  10. if err != nil {
  11. return nil, err
  12. }
  13. var levelInfoReply = &api.LevelInfoReply{
  14. Cur: res.Cur,
  15. Min: res.Min,
  16. NowExp: res.NowExp,
  17. NextExp: res.NextExp,
  18. }
  19. return levelInfoReply, nil
  20. }
  21. // Level get member lebel info
  22. func (s *MemberServer) Level(ctx context.Context, req *api.MidReq) (*api.LevelInfoReply, error) {
  23. res, err := s.svr.Level(ctx, req.Mid)
  24. if err != nil {
  25. return nil, err
  26. }
  27. var levelInfoReply = &api.LevelInfoReply{
  28. Cur: res.Cur,
  29. Min: res.Min,
  30. NowExp: res.NowExp,
  31. NextExp: res.NextExp,
  32. }
  33. return levelInfoReply, nil
  34. }
  35. // UpdateExp update member exp value
  36. func (s *MemberServer) UpdateExp(ctx context.Context, req *api.AddExpReq) (*api.EmptyStruct, error) {
  37. err := s.svr.UpdateExp(ctx, &model.ArgAddExp{
  38. Mid: req.Mid,
  39. Count: req.Count,
  40. Reason: req.Reason,
  41. Operate: req.Operate,
  42. IP: req.Ip,
  43. })
  44. if err != nil {
  45. return nil, err
  46. }
  47. return &api.EmptyStruct{}, nil
  48. }
  49. // ExpLog get member exp logs
  50. func (s *MemberServer) ExpLog(ctx context.Context, req *api.MidReq) (*api.UserLogsReply, error) {
  51. res, err := s.svr.ExpLog(ctx, req.Mid, req.RealIP)
  52. if err != nil {
  53. return nil, err
  54. }
  55. userLogs := make([]*api.UserLogReply, 0, len(res))
  56. for _, v := range res {
  57. var userLog = &api.UserLogReply{
  58. Mid: v.Mid,
  59. Ip: v.IP,
  60. Ts: v.TS,
  61. LogId: v.LogID,
  62. Content: v.Content,
  63. }
  64. userLogs = append(userLogs, userLog)
  65. }
  66. userLogsReply := &api.UserLogsReply{
  67. UserLogs: userLogs,
  68. }
  69. return userLogsReply, nil
  70. }
  71. // ExpStat get exp status
  72. func (s *MemberServer) ExpStat(ctx context.Context, req *api.MidReq) (*api.ExpStatReply, error) {
  73. res, err := s.svr.Stat(ctx, req.Mid)
  74. if err != nil {
  75. return nil, err
  76. }
  77. expStatReply := &api.ExpStatReply{
  78. Login: res.Login,
  79. Watch: res.Watch,
  80. Coin: res.Coin,
  81. Share: res.Share,
  82. }
  83. return expStatReply, nil
  84. }