互动
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.

51 lines
2.3 KiB

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 LiveRedPackInfoTN = TableNamePrefix + "live_red_pack_info"
  7. type LiveRedPackInfo struct {
  8. Id int64 `json:"live_red_pack_info_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. UserId int64 `json:"user_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. GroupId string `json:"group_id" xorm:"not null default '' comment('聊天室地址') VARCHAR(128)"`
  15. Prompt string `json:"prompt" xorm:"not null default 0 comment('祝福语') VARCHAR(255)"`
  16. Amount int64 `json:"amount" xorm:"not null default 0 comment('红包金额, 分') INT(18)"`
  17. OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('订单号') VARCHAR(128)"`
  18. Error string `json:"error" xorm:"not null default '' comment('出现错误') VARCHAR(255)"`
  19. Status int `json:"status" xorm:"not null default 0 comment('-1尚未支付0支付成功1已推送2已作废')"`
  20. }
  21. func (t *LiveRedPackInfo) TableName() string {
  22. return LiveRedPackInfoTN
  23. }
  24. func (t *LiveRedPackInfo) Add() (int64, error) {
  25. return core.GetXormAuto().InsertOne(t)
  26. }
  27. func GetLiveRedPackInfos(status int) ([]*LiveRedPackInfo, error) {
  28. infos := make([]*LiveRedPackInfo, 0)
  29. err := core.GetXormAuto().Where("is_delete=0 and status=?", status).Find(&infos)
  30. return infos, err
  31. }
  32. func (t *LiveRedPackInfo) GetByOutTradeNo(outTradeNo string) (bool, error) {
  33. return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
  34. }
  35. func (t *LiveRedPackInfo) UpdateStatusById(id interface{}, status int) (int64, error) {
  36. return core.GetXormAuto().Where("id=?", id).Cols("status").Update(&LiveRedPack{Status: status})
  37. }
  38. func (t *LiveRedPackInfo) UpdateStatusByOutTradeNo(outTradeNo string, status int) (int64, error) {
  39. t.Status = status
  40. return core.GetXormAuto().Where("is_delete=0 and status=0 and out_trade_no=?", outTradeNo).Update(t)
  41. }