moral.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package grpc
  2. import (
  3. "context"
  4. "go-common/app/service/main/member/api"
  5. )
  6. // Moral Get member moral info
  7. func (s *MemberServer) Moral(ctx context.Context, req *api.MemberMidReq) (*api.MoralReply, error) {
  8. res, err := s.svr.Moral(ctx, req.Mid)
  9. if err != nil {
  10. return nil, err
  11. }
  12. moralReply := &api.MoralReply{
  13. Mid: res.Mid,
  14. Moral: res.Moral,
  15. Added: res.Added,
  16. Deducted: res.Deducted,
  17. LastRecoverDate: res.LastRecoverDate,
  18. }
  19. return moralReply, nil
  20. }
  21. // MoralLog Get member moral logs
  22. func (s *MemberServer) MoralLog(ctx context.Context, req *api.MemberMidReq) (*api.UserLogsReply, error) {
  23. res, err := s.svr.MoralLog(ctx, req.Mid)
  24. if err != nil {
  25. return nil, err
  26. }
  27. userLogs := make([]*api.UserLogReply, 0, len(res))
  28. for _, v := range res {
  29. userLog := &api.UserLogReply{
  30. Mid: v.Mid,
  31. Ip: v.IP,
  32. Ts: v.TS,
  33. LogId: v.LogID,
  34. Content: v.Content,
  35. }
  36. userLogs = append(userLogs, userLog)
  37. }
  38. userLogsReply := &api.UserLogsReply{
  39. UserLogs: userLogs,
  40. }
  41. return userLogsReply, nil
  42. }
  43. // AddMoral Add member's moral value
  44. func (s *MemberServer) AddMoral(ctx context.Context, req *api.UpdateMoralReq) (*api.EmptyStruct, error) {
  45. err := s.svr.UpdateMoral(ctx, api.ToArgUpdateMoral(req))
  46. if err != nil {
  47. return nil, err
  48. }
  49. return &api.EmptyStruct{}, nil
  50. }
  51. // BatchAddMoral Batch add member's moral value
  52. func (s *MemberServer) BatchAddMoral(ctx context.Context, req *api.UpdateMoralsReq) (*api.UpdateMoralsReply, error) {
  53. res, err := s.svr.UpdateMorals(ctx, api.ToArgUpdateMorals(req))
  54. if err != nil {
  55. return nil, err
  56. }
  57. updateMoralsReply := &api.UpdateMoralsReply{
  58. AfterMorals: res,
  59. }
  60. return updateMoralsReply, nil
  61. }