1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package entity
- import (
- "time"
- "xiaoniaokuaiyan.com/xiaoniao/constants"
- "gopkg.in/guregu/null.v3"
- )
- type DiscountTicket struct {
- Id int `db:"id" json:"id"`
- TypeId int `db:"type_id" json:"type_id"`
- Mobile string `db:"mobile",validate:"regexp=^1\d{10,10}$" json:"mobile"`
- Value int `db:"value" json:"value"`
- UseMaxValue int `db:"use_max_value" json:"use_max_value"`
- Deadline string `db:"deadline" json:"deadline"`
- Status int `db:"status" json:"status"`
- OrderId string `db:"order_id" json:"order_id"`
- CreatedAt string `db:"created_at" json:"created_at"`
- BindProducts string `db:"bind_products" json:"bind_products"`
- }
- type DiscountTicketDB struct {
- Id int `db:"id"`
- TypeId int `db:"type_id"`
- Mobile string `db:"mobile"`
- Value int `db:"value"`
- UseMaxValue null.Int `db:"use_max_value"`
- Deadline string `db:"deadline"`
- Status int `db:"status"`
- OrderId null.String `db:"order_id"`
- CreatedAt string `db:"created_at"`
- BindProducts null.String `db:"bind_products"`
- LianrenId null.Int `db:"lianren_id"`
- }
- func (ticket *DiscountTicketDB) IsValid(useMaxVal int) bool {
- if ticket.TypeId == int(constants.COUPONTYPE_LIMIT) && ticket.UseMaxValue.Int64 > int64(useMaxVal) {
- return false
- }
- return ticket.Status == 0 && !ticket.IsExpired() //&& !ticket.OrderId.Valid
- }
- func (ticket *DiscountTicketDB) IsExpired() bool {
- deadline, _ := time.Parse("2006-01-02", ticket.Deadline)
- return deadline.Before(time.Now().AddDate(0, 0, -1))
- }
|