12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package user_merchant
- import (
- "context"
- "gd_management/apis"
- "gd_management/common.in/utils"
- "gd_management/errors"
- "fmt"
- "github.com/astaxie/beego/orm"
- "go.uber.org/zap"
- "time"
- )
- func ManagementGetMerchantDataApiQuota(ctx context.Context, req *apis.ManagementGetMerchantDataApiQuotaReq, reply *apis.ManagementGetMerchantDataApiQuotaReply) (err error) {
- var startTime, endTime int64
- var count, countPerDay, comboType int
- now := time.Now().Unix()
- o := orm.NewOrm()
- sql := "select start_time, end_time, count, count_per_day, combo_type from t_gd_merchant_data_api where id=?"
- err = o.Raw(sql, req.MerchantDataApiId).QueryRow(&startTime, &endTime, &count, &countPerDay, &comboType)
- if err != nil {
- l.Error("mysql",
- zap.String("sql", sql),
- zap.String("fields", fmt.Sprintf("id:%d", req.MerchantDataApiId)),
- zap.String("error", err.Error()))
- if err == orm.ErrNoRows {
- return errors.DataBaseNoRecord
- }
- return errors.DataBaseError
- }
- if comboType == 1 {
- reply.Count = count
- reply.Type = 1
- } else {
- reply.DayCount = countPerDay
- remain := endTime - now
- if remain < 0 {
- reply.DayNumber = 0
- } else {
- reply.DayNumber = int(remain / (24 * 3600))
- }
- reply.Type = 2
- }
- l.Debug(utils.MarshalJsonString(req, reply))
- return nil
- }
|