point.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package service
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "go-common/app/admin/main/point/model"
  6. pointmol "go-common/app/service/main/point/model"
  7. "go-common/library/ecode"
  8. )
  9. // PointConfList .
  10. func (s *Service) PointConfList(c context.Context) (res []*model.PointConf, err error) {
  11. res, err = s.dao.PointConfList(c)
  12. if res == nil {
  13. return
  14. }
  15. for _, v := range res {
  16. v.Name = s.appMap[v.AppID]
  17. }
  18. return
  19. }
  20. // PointCoinInfo .
  21. func (s *Service) PointCoinInfo(c context.Context, id int64) (res *model.PointConf, err error) {
  22. res, err = s.dao.PointCoinInfo(c, id)
  23. if res == nil {
  24. return
  25. }
  26. res.Name = s.appMap[res.AppID]
  27. return
  28. }
  29. // PointCoinAdd .
  30. func (s *Service) PointCoinAdd(c context.Context, pc *model.PointConf) (id int64, err error) {
  31. if _, ok := s.appMap[pc.AppID]; !ok {
  32. err = ecode.RequestErr
  33. return
  34. }
  35. return s.dao.PointCoinAdd(c, pc)
  36. }
  37. // PointCoinEdit .
  38. func (s *Service) PointCoinEdit(c context.Context, pc *model.PointConf) (err error) {
  39. var (
  40. info *model.PointConf
  41. )
  42. if info, err = s.PointCoinInfo(c, pc.ID); err != nil {
  43. err = errors.WithStack(err)
  44. return
  45. }
  46. if info == nil {
  47. err = ecode.RequestErr
  48. return
  49. }
  50. if _, err = s.dao.PointCoinEdit(c, pc); err != nil {
  51. err = errors.WithStack(err)
  52. return
  53. }
  54. return
  55. }
  56. // PointHistory .
  57. func (s *Service) PointHistory(c context.Context, arg *model.ArgPointHistory) (res *model.PageInfo, err error) {
  58. var sr *model.SearchData
  59. if sr, err = s.dao.PointHistory(c, arg); err != nil {
  60. return
  61. }
  62. res = &model.PageInfo{
  63. Item: sr.Result,
  64. Count: sr.Page.Total,
  65. CurrentPage: sr.Page.PN,
  66. }
  67. return
  68. }
  69. // PointAdd point add.
  70. func (s *Service) PointAdd(c context.Context, pc *pointmol.ArgPoint) (err error) {
  71. var (
  72. status int8
  73. )
  74. if status, err = s.pointRPC.AddPoint(c, pc); err != nil {
  75. err = errors.Wrapf(err, "s.pointRPC.AddPoint(%v)", pc)
  76. return
  77. }
  78. if status != model.PointAddSuc {
  79. err = errors.New("point add not success")
  80. }
  81. return
  82. }