1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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 ManagementGetMerchantH5Combo(ctx context.Context, req *apis.ManagementGetMerchantH5ComboReq, reply *apis.ManagementGetMerchantH5ComboReply) (err error) {
- var startTime, endTime int64
- var count, comboType int
- now := time.Now().Unix()
- o := orm.NewOrm()
- sql := "select start_time, end_time, count from t_gd_merchant_data_api where id=?"
- err = o.Raw(sql, req.MerchantH5ServiceId).QueryRow(&startTime, &endTime, &count)
- if err != nil {
- l.Error("mysql",
- zap.String("sql", sql),
- zap.String("fields", fmt.Sprintf("id:%d", req.MerchantH5ServiceId)),
- zap.String("error", err.Error()))
- if err == orm.ErrNoRows {
- return errors.DataBaseNoRecord
- }
- return errors.DataBaseError
- }
- comboType = 2
- if endTime == 0 {
- comboType = 1
- }
- if comboType == 1 {
- reply.Count = count
- reply.Type = 1
- } else {
- reply.DayCount = count
- 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
- }
|