promotion.go 868 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package dao
  2. import (
  3. "go-common/app/service/openplatform/ticket-item/model"
  4. "time"
  5. )
  6. const (
  7. // StatusWaitShelf 待上架
  8. StatusWaitShelf = 1
  9. // StatusUpShelf 已上架
  10. StatusUpShelf = 2
  11. )
  12. // HasPromotion 检查场次id或者票价id下是否有未开售,售卖中的待上架和已上架拼团 checkType 1-场次id 2-票价id
  13. func (d *Dao) HasPromotion(ids []int64, checkType int32) bool {
  14. if ids == nil {
  15. return false
  16. }
  17. status := []int{StatusWaitShelf, StatusUpShelf}
  18. whereStr := "(begin_time > ? OR (begin_time <= ? AND end_time > ?)) AND status IN (?) AND "
  19. if checkType == 1 {
  20. // screen
  21. whereStr += "extra IN (?)"
  22. } else {
  23. // sku
  24. whereStr += "sku_id IN (?)"
  25. }
  26. var count int64
  27. currTime := time.Now().Unix()
  28. d.db.Model(&model.Promotion{}).Where(whereStr, currTime, currTime, currTime, status, ids).Count(&count)
  29. return count > 0
  30. }