coupon

package
v0.0.0-...-4e81a15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2017 License: GPL-3.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// CouponGoodsAll 全场优惠券
	CouponGoodsAll = "ALL"

	// CouponNORMAL 未使用
	CouponNORMAL = "NORMAL"
	// CouponCOMPLETED 已使用
	CouponCOMPLETED = "COMPLETED"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Coupon

type Coupon struct {
	CouponID     int       `json:"couponID" db:"coupon_id"`         // 优惠券ID
	Active       bool      `json:"active" db:"active"`              // 是否可用
	Label        string    `json:"label" db:"label"`                // 优惠券名称
	GoodsID      string    `json:"goodsID" db:"goods_id"`           // 商品ID,以下划线分割,ALL代表全场
	Money        float32   `json:"money" db:"money"`                // 优惠券金额
	Requirement  float32   `json:"requirement" db:"requirement"`    // 优惠券使用条件
	ZoomImg      string    `json:"zoomImg" db:"zoom_img"`           // 缩放图
	CoverImg     string    `json:"coverImg" db:"cover_img"`         // 封面图
	ReceiveCount int       `json:"receiveCount" db:"receive_count"` // 已领取的数量
	RemainCount  int       `json:"remainCount" db:"remain_count"`   // 库存
	UseCount     int       `json:"useCount" db:"use_count"`         // 已使用的数量
	OnSendTime   time.Time `json:"onSendTime" db:"on_send_time"`    // 发放开始时间
	OffSendTime  time.Time `json:"offSendTime" db:"off_send_time"`  // 发放结束时间
	OnUseTime    time.Time `json:"onUseTime" db:"on_use_time"`      // 使用开始时间
	OffUseTime   time.Time `json:"offUseTime" db:"off_use_time"`    // 使用结束时间
	ReceiveLimit int       `json:"receiveLimit" db:"receive_limit"` // 单人领取上限:-1表示无限制,大于0表示单人可领取的上限
	CreateTime   time.Time `json:"createTime" db:"create_time"`     // 创建时间
	UpdateTime   time.Time `json:"updateTime" db:"update_time"`     // 更新时间
}

Coupon 优惠券

func (*Coupon) SplitGoodsID

func (c *Coupon) SplitGoodsID() (bool, []int)

SplitGoodsID 分割GoodsID为数组

type CouponDB

type CouponDB struct {
	DB *sqlx.DB
}

func (*CouponDB) Delete

func (db *CouponDB) Delete(couponID int) error

Delete 删除优惠券

func (*CouponDB) GetByID

func (db *CouponDB) GetByID(couponID int) (*Coupon, error)

GetByID 获取指定优惠券

func (*CouponDB) GetUserCoupon

func (db *CouponDB) GetUserCoupon(userCouponID int) (*UserCoupon, error)

GetUserCoupon 获取指定优惠券

func (*CouponDB) GetUserCouponByUserID

func (db *CouponDB) GetUserCouponByUserID(userID, couponID int) ([]UserCoupon, error)

GetUserCouponByUserID 获取指定用户优惠券

func (*CouponDB) Insert

func (db *CouponDB) Insert(c *Coupon) error

Insert 添加活动优惠券

func (*CouponDB) List

func (db *CouponDB) List() ([]Coupon, error)

List 列出所有有效优惠券,创建开始时间排序

func (*CouponDB) ListExpiredUserCoupon

func (db *CouponDB) ListExpiredUserCoupon(userID, offset, limit int) ([]UserCoupon, int, error)

ListExpiredUserCoupon 列出用户已过期的优惠券,以过期时间排序

func (*CouponDB) ListUsedUserCoupon

func (db *CouponDB) ListUsedUserCoupon(userID, offset, limit int) ([]UserCoupon, int, error)

ListUsedUserCoupon 列出用户已使用的优惠券,以使用时间排序

func (*CouponDB) ListValidUserCoupon

func (db *CouponDB) ListValidUserCoupon(userID int) ([]UserCoupon, error)

ListValidUserCoupon 列出用户未使用的优惠券,以领取时间排序

func (*CouponDB) ListValidUserCouponByMoney

func (db *CouponDB) ListValidUserCouponByMoney(userID int) ([]UserCoupon, error)

ListValidUserCouponByMoney 列出用户未使用的优惠券,按优惠金额倒序排序

func (*CouponDB) Update

func (db *CouponDB) Update(c *Coupon) error

Update 更新优惠券信息

type CouponTx

type CouponTx struct {
	Tx *sqlx.Tx
}

func (*CouponTx) InsertUserCoupon

func (tx *CouponTx) InsertUserCoupon(userID int, coupon *Coupon) error

InsertUserCoupon 领取优惠券

func (*CouponTx) ReceiveCoupon

func (tx *CouponTx) ReceiveCoupon(couponID int) error

ReceiveCoupon 减少优惠券的库存,增加该优惠券的领取量

func (*CouponTx) RollbackUserCoupon

func (tx *CouponTx) RollbackUserCoupon(userCouponID int) error

RollbackUserCoupon 返还优惠券

func (*CouponTx) UpdateCouponUseCount

func (tx *CouponTx) UpdateCouponUseCount(couponID, count int) error

UpdateCouponUseCount 更新优惠券使用量,count小于0时为回滚优惠券使用量,count大于0为增加优惠券使用量

func (*CouponTx) UpdateUserCoupon

func (tx *CouponTx) UpdateUserCoupon(userCouponID int, orderID string) error

UpdateUserCoupon 使用优惠券,未验证优惠券有效性

type UserCoupon

type UserCoupon struct {
	UserCouponID int       `json:"userCouponID" db:"user_coupon_id"` // 用户优惠券ID
	UserID       int       `json:"userID" db:"user_id"`              // 用户ID
	CouponID     int       `json:"couponID" db:"coupon_id"`          // 优惠券ID
	Label        string    `json:"label" db:"label"`                 // 优惠券名称
	GoodsID      string    `json:"goodsID" db:"goods_id"`            // 商品ID,以下划线分割,ALL代表全场
	Money        float32   `json:"money" db:"money"`                 // 优惠券金额
	Requirement  float32   `json:"requirement" db:"requirement"`     // 优惠券使用条件
	ZoomImg      string    `json:"zoomImg" db:"zoom_img"`            // 缩放图
	CoverImg     string    `json:"coverImg" db:"cover_img"`          // 封面图
	OnUseTime    time.Time `json:"onUseTime" db:"on_use_time"`       // 使用开始时间
	OffUseTime   time.Time `json:"offUseTime" db:"off_use_time"`     // 使用结束时间
	Used         bool      `json:"used" db:"used"`                   // 是否已使用
	UseTime      time.Time `json:"useTime" db:"use_time"`            // 使用时间
	OrderID      string    `json:"orderID" db:"order_id"`            // 使用时的订单ID
	CreateTime   time.Time `json:"createTime" db:"create_time"`      // 创建时间
	UpdateTime   time.Time `json:"updateTime" db:"update_time"`      // 更新时间
}

UserCoupon 用户的优惠券

func (*UserCoupon) IsValid

func (uc *UserCoupon) IsValid() error

IsValid 优惠券是否是有效的

func (*UserCoupon) SplitGoodsID

func (uc *UserCoupon) SplitGoodsID() (bool, []int)

SplitGoodsID 分割GoodsID为数组

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL