account.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "encoding/binary"
  5. "time"
  6. "go-common/app/job/main/figure/conf"
  7. "go-common/app/job/main/figure/model"
  8. "github.com/pkg/errors"
  9. )
  10. // UpdateAccountExp update user exp
  11. func (d *Dao) UpdateAccountExp(c context.Context, mid, exp int64) (err error) {
  12. var (
  13. expByte = make([]byte, 8)
  14. ctx, cancel = context.WithTimeout(c, time.Duration(conf.Conf.HBase.WriteTimeout))
  15. )
  16. defer cancel()
  17. binary.BigEndian.PutUint64(expByte, uint64(exp))
  18. values := map[string]map[string][]byte{model.USFamilyUser: map[string][]byte{model.USColumnExp: expByte}}
  19. if _, err = d.hbase.PutStr(ctx, model.UserInfoTable, d.rowKey(mid), values); err != nil {
  20. err = errors.Wrapf(err, "mid(%d), hbase.Put(key: %s, values: %v)", d.rowKey(mid), values)
  21. }
  22. return
  23. }
  24. // IncArchiveViews .
  25. func (d *Dao) IncArchiveViews(c context.Context, mid int64) (err error) {
  26. var (
  27. incrByte = make([]byte, 8)
  28. ctx, cancel = context.WithTimeout(c, time.Duration(conf.Conf.HBase.WriteTimeout))
  29. )
  30. defer cancel()
  31. binary.BigEndian.PutUint64(incrByte, uint64(1))
  32. values := map[string]map[string][]byte{model.USFamilyUser: map[string][]byte{model.USColumnArchiveViews: incrByte}}
  33. if _, err = d.hbase.Increment(ctx, model.UserInfoTable, d.rowKey(mid), values); err != nil {
  34. err = errors.Wrapf(err, "msg(%v), hbase.Increment(key: %s values: %v)", mid, d.rowKey(mid), values)
  35. }
  36. return
  37. }