You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
53 lines
1.2 KiB
package coupon
|
|
|
|
import (
|
|
"CouponBackendGo/internal/dao"
|
|
"CouponBackendGo/internal/model/dto"
|
|
"CouponBackendGo/internal/service"
|
|
"context"
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
)
|
|
|
|
type (
|
|
sCoupon struct{}
|
|
)
|
|
|
|
func init() {
|
|
service.RegisterCoupon(New())
|
|
}
|
|
|
|
func New() service.ICoupon {
|
|
return &sCoupon{}
|
|
}
|
|
|
|
func (s *sCoupon) GetCouponList(ctx context.Context, pageNo int, pageSize int) (couponList []*dto.DtoCoupon, err error) {
|
|
err = dao.Coupon.Ctx(ctx).Where("deleted", 0).Order("updated_at desc, end_time desc").Page(pageNo, pageSize).Scan(&couponList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *sCoupon) GetCouponListTotal(ctx context.Context) (total int, err error) {
|
|
total, err = dao.Coupon.Ctx(ctx).Where("deleted", 0).Count()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *sCoupon) GetCoupon(ctx context.Context, id int) (coupon *dto.DtoCoupon, err error) {
|
|
err = dao.Coupon.Ctx(ctx).WherePri(id).Scan(&coupon)
|
|
coupon.Status = 0 //待使用期
|
|
if coupon.StartTime.Unix() <= gtime.Now().Unix() {
|
|
if coupon.EndTime.Unix() <= gtime.Now().Unix() {
|
|
coupon.Status = 2 //使用期后
|
|
} else {
|
|
coupon.Status = 1 //使用期中
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|