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

76 lines
3.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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. "time"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. )
  6. const ReWardHistoryTableName = TableNamePrefix + "reward_history"
  7. //打赏历史
  8. type RewardHistory struct {
  9. Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
  10. IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否删除') TINYINT(1)"`
  11. CreatedAt time.Time `json:"create_at" xorm:"created comment('创建时间') TIMESTAMP"`
  12. UpdatedAt time.Time `json:"update_at" xorm:"updated comment('更新时间') TIMESTAMP"`
  13. OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('微信订单号') VARCHAR(128)"`
  14. CustomerId int `json:"customer_id" xorm:"not null default 0 comment('客户id') INT(11)"`
  15. RewardServerId int `json:"reward_server_id" xorm:"not null default 0 comment('打赏服务id') INT(11)"`
  16. ActivityId int `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
  17. ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
  18. RehearsalId int `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/0正式') INT(11)"`
  19. UserId int `json:"user_id" xorm:"not null default 0 comment('用户得id') INT(11)"`
  20. Content string `json:"content" xorm:"not null comment('内容') text"`
  21. Amount float64 `json:"amount" xorm:"not null default(0.00) comment('金额')"`
  22. Status int `json:"status" xorm:"not null default(0) comment('-1未支付,0未审核,1未通过,2已通过,3已推送,4已退款') INT(11)"`
  23. ReviewTime int `json:"review_time" xorm:"not null default(0) comment('审核时间') INT(11)"`
  24. ExpireTime int64 `json:"expire_time" xorm:"not null default(0) comment('过期时间') INT(11)"`
  25. Type int `json:"type" xorm:"not null default 0 comment('线下h5/直播 = 0/1') TINYINT(1)"`
  26. Version int `json:"version" xorm:"not null version comment('乐观锁') INT(11)"`
  27. // 额外字段
  28. RewardAmount string `json:"reward_amount" xorm:"-" description:"同上, 字符串"`
  29. User *User `json:"user" xorm:"-" description:"用户信息"`
  30. }
  31. func (t *RewardHistory) TableName() string {
  32. return ReWardHistoryTableName
  33. }
  34. func (t *RewardHistory) GetByOutTradeNo(outTradeNo string) (bool, error) {
  35. return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
  36. }
  37. func (t *RewardHistory) UpdateStatus(id int, status int) (int64, error) {
  38. t.Status = status
  39. return core.GetXormAuto().Where("id=?", id).Cols("status").Update(t)
  40. }
  41. func (t *RewardHistory) UpdateStatusByIds(ids []int, status int) error {
  42. if len(ids) > 0 {
  43. _, err := core.GetXormAuto().In("id", ids).Cols("status").
  44. Update(&RewardHistory{Status: status})
  45. return err
  46. }
  47. return nil
  48. }
  49. func GetRewardHistoryByIds(ids interface{}) ([]*RewardHistory, error) {
  50. result := make([]*RewardHistory, 0)
  51. err := core.GetXormAuto().Where("is_delete=0 and status=0").In("id", ids).Find(&result)
  52. return result, err
  53. }
  54. func GetExpireRewardHistory() ([]*RewardHistory, error) {
  55. result := make([]*RewardHistory, 0)
  56. err := core.GetXormAuto().Where("is_delete=0 and status=0 and rehearsal_id = 0 or type <> 0 "+
  57. " and expire_time <= ?", time.Now().Unix()).Find(&result)
  58. return result, err
  59. }
  60. func (t *RewardHistory) SumMoney(serverId, rehearsalId, archId interface{}) (float64, error) {
  61. return core.GetXormAuto().Where("reward_server_id=? and status=3 and is_delete=0 and rehearsal_id=? and arch_id=?",
  62. serverId, rehearsalId, archId).Sum(t, "amount")
  63. }