user_merchant_h5_combo_info.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 ManagementGetMerchantH5Combo(ctx context.Context, req *apis.ManagementGetMerchantH5ComboReq, reply *apis.ManagementGetMerchantH5ComboReply) (err error) {
  13. var startTime, endTime int64
  14. var count, comboType int
  15. now := time.Now().Unix()
  16. o := orm.NewOrm()
  17. sql := "select start_time, end_time, count from t_gd_merchant_data_api where id=?"
  18. err = o.Raw(sql, req.MerchantH5ServiceId).QueryRow(&startTime, &endTime, &count)
  19. if err != nil {
  20. l.Error("mysql",
  21. zap.String("sql", sql),
  22. zap.String("fields", fmt.Sprintf("id:%d", req.MerchantH5ServiceId)),
  23. zap.String("error", err.Error()))
  24. if err == orm.ErrNoRows {
  25. return errors.DataBaseNoRecord
  26. }
  27. return errors.DataBaseError
  28. }
  29. comboType = 2
  30. if endTime == 0 {
  31. comboType = 1
  32. }
  33. if comboType == 1 {
  34. reply.Count = count
  35. reply.Type = 1
  36. } else {
  37. reply.DayCount = count
  38. remain := endTime - now
  39. if remain < 0 {
  40. reply.DayNumber = 0
  41. } else {
  42. reply.DayNumber = int(remain / (24 * 3600))
  43. }
  44. reply.Type = 2
  45. }
  46. l.Debug(utils.MarshalJsonString(req, reply))
  47. return nil
  48. }