互动
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
2.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "time"
  5. )
  6. const LiveRedPackTN = TableNamePrefix + "live_red_pack"
  7. type LiveRedPack struct {
  8. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  9. IsDelete bool `json:"-" xorm:"not null default 0 comment('是否删除') TINYINT(1)"`
  10. CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
  11. UpdatedAt time.Time `json:"updated_at" xorm:"not null updated default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
  12. LiveRedPackInfoId int64 `json:"live_red_pack_info_id" xorm:"not null default 0 comment('红包信息id') INT(11)"`
  13. ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"`
  14. Receiver int64 `json:"receiver" xorm:"not null default 0 comment('[0未领取/非0领取用户id]') INT(11)"`
  15. OpenId string `json:"open_id" xorm:"not null default '' comment('用户openid') VARCHAR(128)"`
  16. Amount int `json:"amount" xorm:"not null default 0 comment('红包金额, 分') INT(18)"`
  17. TransferType int `json:"transfer_type" xorm:"not null default 0 comment('转账方式[0微信红包1微信零钱]') TINYINT(1)"`
  18. PartnerTradeNo string `json:"partner_trade_no" xorm:"not null default '' comment('转账单号') VARCHAR(128) "`
  19. Status int `json:"status" xorm:"not null default 0 comment('0 未被领取 1 已被领取 2 已发送 3 出现错误') TINYINT(1)"`
  20. Version int `json:"version" xorm:"not null version comment('乐观锁') INT(11)"`
  21. }
  22. func (t LiveRedPack) TableName() string {
  23. return LiveRedPackTN
  24. }
  25. func (t *LiveRedPack) Add() (int64, error) {
  26. return core.GetXormAuto().InsertOne(t)
  27. }
  28. func (t *LiveRedPack) GetByInfoId(infoId int64) (bool, error) {
  29. return core.GetXormAuto().Where("live_red_package_info_id=? and is_delete=0", infoId).Get(t)
  30. }
  31. func (t *LiveRedPack) UpdateStatusById(id interface{}, status int) (int64, error) {
  32. t.Status = status
  33. return core.GetXormAuto().Where("id=?", id).
  34. Cols("receiver, open_id, transfer_type, transfer_no, status").Update(t)
  35. }
  36. func GetRedPacksByStatus(status interface{}) ([]*LiveRedPack, error) {
  37. redPacks := make([]*LiveRedPack, 0)
  38. err := core.GetXormAuto().Where("is_delete=0 and status=?", status).Find(&redPacks)
  39. return redPacks, err
  40. }
  41. func (t *LiveRedPack) GetByTransferNo(transferNo string) (bool, error) {
  42. return core.GetXormAuto().Where("is_delete=0 and transfer_no=?", transferNo).Get(t)
  43. }