search.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/admin/main/point/model"
  6. "go-common/library/database/elastic"
  7. "github.com/pkg/errors"
  8. )
  9. // PointHistory get point change history from es.
  10. func (d *Dao) PointHistory(c context.Context, arg *model.ArgPointHistory) (res *model.SearchData, err error) {
  11. var changeTimeFrom, changeTimeTo string
  12. req := d.es.NewRequest(_searchBussinss).Index(_searchBussinss).Pn(int(arg.PN)).Ps(int(arg.PS))
  13. req.Fields("id", "mid", "order_id", "relation_id", "point_balance", "change_time", "change_type", "remark", "operator")
  14. if arg.ChangeType != 0 {
  15. req.WhereEq("change_type", arg.ChangeType)
  16. }
  17. if arg.Mid > 0 {
  18. req.WhereEq("mid", arg.Mid)
  19. }
  20. if arg.StartChangeTime != 0 {
  21. changeTimeFrom = time.Unix(arg.StartChangeTime, 0).Format("2006-01-02 15:04:05")
  22. }
  23. if arg.EndChangeTime != 0 {
  24. changeTimeTo = time.Unix(arg.EndChangeTime, 0).Format("2006-01-02 15:04:05")
  25. }
  26. req.WhereRange("change_time", changeTimeFrom, changeTimeTo, elastic.RangeScopeLcRc)
  27. req.Order("change_time", "desc")
  28. res = &model.SearchData{}
  29. if err = req.Scan(c, &res); err != nil {
  30. err = errors.WithStack(err)
  31. }
  32. return
  33. }