Documentation ¶
Index ¶
- type ExpiredEnvelopeDomain
- type RedEnvelopeGoods
- type RedEnvelopeGoodsDao
- func (dao *RedEnvelopeGoodsDao) FindExpired(offset, size int) []RedEnvelopeGoods
- func (dao *RedEnvelopeGoodsDao) GetOne(envelopeNo string) *RedEnvelopeGoods
- func (dao *RedEnvelopeGoodsDao) Insert(po *RedEnvelopeGoods) (int64, error)
- func (dao *RedEnvelopeGoodsDao) UpdateBalance(envelopeNo string, amount decimal.Decimal) (int64, error)
- func (dao *RedEnvelopeGoodsDao) UpdateOrderStatus(envelopeNo string, status services.OrderStatus) (int64, error)
- type RedEnvelopeItem
- type RedEnvelopeItemDao
- func (dao *RedEnvelopeItemDao) FindItems(envelopeNo string) []*RedEnvelopeItem
- func (dao *RedEnvelopeItemDao) GetByUser(envelopeNo, userId string) *RedEnvelopeItem
- func (dao *RedEnvelopeItemDao) GetOne(itemNo string) *RedEnvelopeItem
- func (dao *RedEnvelopeItemDao) Insert(form *RedEnvelopeItem) (int64, error)
- func (dao *RedEnvelopeItemDao) ListReceivedItems(userId string, page, size int) []*RedEnvelopeItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpiredEnvelopeDomain ¶
type ExpiredEnvelopeDomain struct {
// contains filtered or unexported fields
}
func (*ExpiredEnvelopeDomain) Expired ¶
func (e *ExpiredEnvelopeDomain) Expired() (err error)
func (*ExpiredEnvelopeDomain) ExpiredOne ¶
func (e *ExpiredEnvelopeDomain) ExpiredOne(goods RedEnvelopeGoods) (err error)
发起退款流程
type RedEnvelopeGoods ¶
type RedEnvelopeGoods struct { Id int64 `db:"id,omitempty"` //自增ID EnvelopeNo string `db:"envelope_no,uni"` //红包编号,红包唯一标识 EnvelopeType int `db:"envelope_type"` //红包类型:普通红包,碰运气红包 Username sql.NullString `db:"username"` //用户名称 UserId string `db:"user_id"` //用户编号, 红包所属用户 Blessing sql.NullString `db:"blessing"` //祝福语 Amount decimal.Decimal `db:"amount"` //红包总金额 AmountOne decimal.Decimal `db:"amount_one"` //单个红包金额,碰运气红包无效 Quantity int `db:"quantity"` //红包总数量 RemainAmount decimal.Decimal `db:"remain_amount"` //红包剩余金额额 RemainQuantity int `db:"remain_quantity"` //红包剩余数量 ExpiredAt time.Time `db:"expired_at"` //过期时间 Status services.OrderStatus `db:"status"` //红包状态:0红包初始化,1启用,2失效 OrderType services.OrderType `db:"order_type"` //订单类型:发布单、退款单 PayStatus services.PayStatus `db:"pay_status"` //支付状态:未支付,支付中,已支付,支付失败 CreatedAt time.Time `db:"created_at,omitempty"` //创建时间 UpdatedAt time.Time `db:"updated_at,omitempty"` //更新时间 OriginEnvelopeNo string `db:"origin_envelope_no"` //原关联订单号 }
func (*RedEnvelopeGoods) FromDTO ¶
func (po *RedEnvelopeGoods) FromDTO(dto *services.RedEnvelopeGoodsDTO)
func (*RedEnvelopeGoods) ToDTO ¶
func (po *RedEnvelopeGoods) ToDTO() *services.RedEnvelopeGoodsDTO
type RedEnvelopeGoodsDao ¶
type RedEnvelopeGoodsDao struct {
// contains filtered or unexported fields
}
定义红包商品 Dao 结构体
func (*RedEnvelopeGoodsDao) FindExpired ¶
func (dao *RedEnvelopeGoodsDao) FindExpired(offset, size int) []RedEnvelopeGoods
5. 红包过期退款 - 包过期的所有红包都查询出来,过期红包数量过多时,需要使用分页功能,使用数据库的 limit 实现,通过 offset 和 size 来设定
func (*RedEnvelopeGoodsDao) GetOne ¶
func (dao *RedEnvelopeGoodsDao) GetOne(envelopeNo string) *RedEnvelopeGoods
3. 查询红包 - 根据红包编号查询红包的状态
func (*RedEnvelopeGoodsDao) Insert ¶
func (dao *RedEnvelopeGoodsDao) Insert(po *RedEnvelopeGoods) (int64, error)
1. 发红包 - 将红包商品信息插入数据库
func (*RedEnvelopeGoodsDao) UpdateBalance ¶
func (dao *RedEnvelopeGoodsDao) UpdateBalance(envelopeNo string, amount decimal.Decimal) (int64, error)
- 抢红包 - 更新红包剩余数量和剩余金额 使用乐观锁而非事务行锁来更新红包剩余数量和剩余金额,通过在 sql 语句中的 where 部分实现, 除了能够避免出现负库存的问题,还能够减少实际数据更新操作,过滤掉部分无效的更新,从而提高总体的性能。
func (*RedEnvelopeGoodsDao) UpdateOrderStatus ¶
func (dao *RedEnvelopeGoodsDao) UpdateOrderStatus(envelopeNo string, status services.OrderStatus) (int64, error)
4. 红包过期退款 - 更新红包订单状态
type RedEnvelopeItem ¶
type RedEnvelopeItem struct { Id int64 `db:"id,omitempty"` //自增ID ItemNo string `db:"item_no,uni"` //红包订单详情编号 EnvelopeNo string `db:"envelope_no"` //红包编号,红包唯一标识 RecvUsername sql.NullString `db:"recv_username"` //红包接收者用户名称 RecvUserId string `db:"recv_user_id"` //红包接收者用户编号 Amount decimal.Decimal `db:"amount"` //收到金额 Quantity int `db:"quantity"` //收到数量:对于收红包来说是1 RemainAmount decimal.Decimal `db:"remain_amount"` //收到后红包剩余金额 AccountNo string `db:"account_no"` //红包接收者账户ID PayStatus int `db:"pay_status"` //支付状态:未支付,支付中,已支付,支付失败 CreatedAt time.Time `db:"created_at,omitempty"` //创建时间 UpdatedAt time.Time `db:"updated_at,omitempty"` //更新时间 Desc string `db:"desc"` }
func (*RedEnvelopeItem) FromDTO ¶
func (po *RedEnvelopeItem) FromDTO(dto *services.RedEnvelopeItemDTO)
func (*RedEnvelopeItem) ToDTO ¶
func (po *RedEnvelopeItem) ToDTO() *services.RedEnvelopeItemDTO
type RedEnvelopeItemDao ¶
type RedEnvelopeItemDao struct {
// contains filtered or unexported fields
}
func (*RedEnvelopeItemDao) FindItems ¶
func (dao *RedEnvelopeItemDao) FindItems(envelopeNo string) []*RedEnvelopeItem
func (*RedEnvelopeItemDao) GetByUser ¶
func (dao *RedEnvelopeItemDao) GetByUser(envelopeNo, userId string) *RedEnvelopeItem
func (*RedEnvelopeItemDao) GetOne ¶
func (dao *RedEnvelopeItemDao) GetOne(itemNo string) *RedEnvelopeItem
查询 GetOne
func (*RedEnvelopeItemDao) Insert ¶
func (dao *RedEnvelopeItemDao) Insert(form *RedEnvelopeItem) (int64, error)
func (*RedEnvelopeItemDao) ListReceivedItems ¶
func (dao *RedEnvelopeItemDao) ListReceivedItems(userId string, page, size int) []*RedEnvelopeItem
Click to show internal directories.
Click to hide internal directories.