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

73 lines
4.1 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
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 ShakeRedEnvelopeRecordTableName = TableNamePrefix + "shake_red_envelope_record"
  7. type ShakeRedEnvelopeRecord struct {
  8. Id int `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
  9. IsDelete bool `json:"-" xorm:"default(0)" description:"是否删除"`
  10. CreatedAt time.Time `json:"-" xorm:"created" description:"创建时间"`
  11. UpdatedAt time.Time `json:"-" xorm:"updated" description:"更新时间"`
  12. ActivityId int `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
  13. RehearsalId int `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id/0正式') INT(11)"`
  14. ShakeRedEnvelopeType int `json:"red_envelope_type" xorm:"not null default 0 comment('红包类型[0摇红包1直播红包]')"`
  15. ShakeRedEnvelopeRuleId int `json:"shake_red_envelope_rule_id,omitempty" xorm:"not null default 0 comment('摇红包规则id') INT(11)"`
  16. ShakeRedEnvelopeActivityId int `json:"shake_red_envelope_activity_id,omitempty" 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. AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
  19. Name string `json:"name" xorm:"not null default '' comment('红包名字') VARCHAR(255)"`
  20. UserId int `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"`
  21. Amount float64 `json:"amount" xorm:"not null default 0.00 comment('金额') DECIMAL(18)"`
  22. IsValid bool `json:"is_valid,omitempty" xorm:"-"`
  23. IsDraw int `json:"is_draw" xorm:"not null default 0 comment('-1未被摇中,0已被摇中1被提取')"`
  24. MchBillno string `json:"mch_billno" xorm:"not null default '' comment('微信红包订单号') VARCHAR(128)"`
  25. Version int `json:"version" xorm:"not null version default 0 comment('乐观锁') INT(11)"`
  26. }
  27. func (t *ShakeRedEnvelopeRecord) TableName() string {
  28. return ShakeRedEnvelopeRecordTableName
  29. }
  30. func (t *ShakeRedEnvelopeRecord) ExistRecord(reid, srid, uid int) (bool, error) {
  31. return core.GetXormAuto().Where("is_delete=0 and rehearsal_id=? and "+
  32. "shake_red_envelope_rule_id=? and user_id=?", reid, srid, uid).Exist(t)
  33. }
  34. func (t *ShakeRedEnvelopeRecord) Total(aid, rid, said, srid int) (int64, error) {
  35. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and "+
  36. "shake_red_envelope_activity_id=? and shake_red_envelope_rule_id=?", aid, rid, said, srid).Count(t)
  37. }
  38. func (t *ShakeRedEnvelopeRecord) Sum(aid, rid, said, srid int) (float64, error) {
  39. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and "+
  40. "shake_red_envelope_activity_id=? and shake_red_envelope_rule_id=?", aid, rid, said, srid).
  41. Sum(t, "amount")
  42. }
  43. func (t *ShakeRedEnvelopeRecord) Count(aid, rid, said, srid int, status int) (int64, error) {
  44. return core.GetXormAuto().Where("is_delete=0 and is_draw=? and activity_id=? and rehearsal_id=? and "+
  45. "shake_red_envelope_activity_id=? and shake_red_envelope_rule_id=?", status, aid, rid, said, srid).Count(t)
  46. }
  47. func (t *ShakeRedEnvelopeRecord) GetByRuleId(ruleId, rehearsalId, _type, archId interface{}) (bool, error) {
  48. return core.GetXormAuto().Where("is_delete=0 and is_draw=-1 and shake_red_envelope_type = ? and "+
  49. "shake_red_envelope_rule_id=? and rehearsal_id=? and arch_id=?", _type, ruleId, rehearsalId, archId).Get(t)
  50. }
  51. func GetRedEnvelopesByUserId(userId, activityId, rehearsalId int, archId interface{}) ([]*ShakeRedEnvelopeRecord, error) {
  52. records := make([]*ShakeRedEnvelopeRecord, 0)
  53. err := core.GetXormAuto().Where("user_id=? and rehearsal_id=? and activity_id=? and arch_id=? and "+
  54. "is_delete=0 and is_draw<>-1", userId, rehearsalId, activityId, archId).Desc("created_at").
  55. Find(&records)
  56. for index := range records {
  57. records[index].IsValid = true
  58. }
  59. return records, err
  60. }