point.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/point/model"
  6. "go-common/library/log"
  7. xtime "go-common/library/time"
  8. )
  9. const (
  10. _timeFormat = "2006-01-02 15:04:05"
  11. )
  12. // AddPoint add point.
  13. func (s *Service) AddPoint(c context.Context, p *model.VipPoint) (err error) {
  14. if _, err = s.dao.AddPoint(c, p); err != nil {
  15. log.Error("%+v", err)
  16. return
  17. }
  18. s.dao.DelPointInfoCache(c, p.Mid)
  19. return
  20. }
  21. // UpdatePoint update point.
  22. func (s *Service) UpdatePoint(c context.Context, p *model.VipPoint, oldpoint *model.VipPoint) (err error) {
  23. if _, err = s.dao.UpdatePoint(c, p, oldpoint.Ver); err != nil {
  24. log.Error("%+v", err)
  25. return
  26. }
  27. s.dao.DelPointInfoCache(c, p.Mid)
  28. return
  29. }
  30. // AddPointHistory add point history.
  31. func (s *Service) AddPointHistory(c context.Context, h *model.VipPointChangeHistoryMsg) (err error) {
  32. var (
  33. history = new(model.VipPointChangeHistory)
  34. changeTime time.Time
  35. )
  36. history.ChangeType = h.ChangeType
  37. history.Mid = h.Mid
  38. history.Operator = h.Operator
  39. history.OrderID = h.OrderID
  40. history.Point = h.Point
  41. history.PointBalance = h.PointBalance
  42. history.RelationID = h.RelationID
  43. history.Remark = h.Remark
  44. if changeTime, err = time.ParseInLocation(_timeFormat, h.ChangeTime, time.Local); err != nil {
  45. log.Error("time.ParseInLocation error %+v", err)
  46. return
  47. }
  48. history.ChangeTime = xtime.Time(changeTime.Unix())
  49. if _, err = s.dao.AddPointHistory(c, history); err != nil {
  50. log.Error("%+v", err)
  51. return
  52. }
  53. return
  54. }
  55. // Notify notify.
  56. func (s *Service) Notify(c context.Context, msg *model.VipPointChangeHistoryMsg) (err error) {
  57. for _, url := range s.c.Properties.NotifyCacheDelURL {
  58. if err = s.dao.NotifyCacheDel(c, url, msg.Mid, "127.0.0.1"); err != nil {
  59. log.Error("NotifyCacheDel fail(%d) %+v", msg.Mid, err)
  60. }
  61. }
  62. return
  63. }