discount_ticket.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package entity
  2. import (
  3. "time"
  4. "xiaoniaokuaiyan.com/xiaoniao/constants"
  5. "gopkg.in/guregu/null.v3"
  6. )
  7. type DiscountTicket struct {
  8. Id int `db:"id" json:"id"`
  9. TypeId int `db:"type_id" json:"type_id"`
  10. Mobile string `db:"mobile",validate:"regexp=^1\d{10,10}$" json:"mobile"`
  11. Value int `db:"value" json:"value"`
  12. UseMaxValue int `db:"use_max_value" json:"use_max_value"`
  13. Deadline string `db:"deadline" json:"deadline"`
  14. Status int `db:"status" json:"status"`
  15. OrderId string `db:"order_id" json:"order_id"`
  16. CreatedAt string `db:"created_at" json:"created_at"`
  17. BindProducts string `db:"bind_products" json:"bind_products"`
  18. }
  19. type DiscountTicketDB struct {
  20. Id int `db:"id"`
  21. TypeId int `db:"type_id"`
  22. Mobile string `db:"mobile"`
  23. Value int `db:"value"`
  24. UseMaxValue null.Int `db:"use_max_value"`
  25. Deadline string `db:"deadline"`
  26. Status int `db:"status"`
  27. OrderId null.String `db:"order_id"`
  28. CreatedAt string `db:"created_at"`
  29. BindProducts null.String `db:"bind_products"`
  30. LianrenId null.Int `db:"lianren_id"`
  31. }
  32. func (ticket *DiscountTicketDB) IsValid(useMaxVal int) bool {
  33. if ticket.TypeId == int(constants.COUPONTYPE_LIMIT) && ticket.UseMaxValue.Int64 > int64(useMaxVal) {
  34. return false
  35. }
  36. return ticket.Status == 0 && !ticket.IsExpired() //&& !ticket.OrderId.Valid
  37. }
  38. func (ticket *DiscountTicketDB) IsExpired() bool {
  39. deadline, _ := time.Parse("2006-01-02", ticket.Deadline)
  40. return deadline.Before(time.Now().AddDate(0, 0, -1))
  41. }