user_merchant_base_api_quota_info.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package user_merchant
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/common.in/utils"
  6. "gd_management/errors"
  7. "fmt"
  8. "github.com/astaxie/beego/orm"
  9. "go.uber.org/zap"
  10. "time"
  11. )
  12. func ManagementGetMerchantDataApiQuota(ctx context.Context, req *apis.ManagementGetMerchantDataApiQuotaReq, reply *apis.ManagementGetMerchantDataApiQuotaReply) (err error) {
  13. var startTime, endTime int64
  14. var count, countPerDay, comboType int
  15. now := time.Now().Unix()
  16. o := orm.NewOrm()
  17. sql := "select start_time, end_time, count, count_per_day, combo_type from t_gd_merchant_data_api where id=?"
  18. err = o.Raw(sql, req.MerchantDataApiId).QueryRow(&startTime, &endTime, &count, &countPerDay, &comboType)
  19. if err != nil {
  20. l.Error("mysql",
  21. zap.String("sql", sql),
  22. zap.String("fields", fmt.Sprintf("id:%d", req.MerchantDataApiId)),
  23. zap.String("error", err.Error()))
  24. if err == orm.ErrNoRows {
  25. return errors.DataBaseNoRecord
  26. }
  27. return errors.DataBaseError
  28. }
  29. if comboType == 1 {
  30. reply.Count = count
  31. reply.Type = 1
  32. } else {
  33. reply.DayCount = countPerDay
  34. remain := endTime - now
  35. if remain < 0 {
  36. reply.DayNumber = 0
  37. } else {
  38. reply.DayNumber = int(remain / (24 * 3600))
  39. }
  40. reply.Type = 2
  41. }
  42. l.Debug(utils.MarshalJsonString(req, reply))
  43. return nil
  44. }