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

60 lines
3.4 KiB

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. "hudongzhuanjia/utils/define"
  5. "time"
  6. )
  7. const ShakeRedEnvelopeRuleTableName = TableNamePrefix + "shake_red_envelope_rule"
  8. //摇红包活动规则
  9. type ShakeRedEnvelopeRule struct {
  10. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  11. IsDelete bool `json:"-" xorm:"not null default(0) comment('是否删除')"`
  12. CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间')"`
  13. UpdatedAt time.Time `json:"-" xorm:"not null default 'CURRENT_TIMESTAMP' updated comment('更新时间')"`
  14. ShakeRedEnvelopeActivityId int64 `json:"shake_red_envelope_activity_id" xorm:"not null comment('主活动id')" description:"主活动的id"`
  15. AreaId int64 `json:"area_id" xorm:"not null comment('地区id')" description:"地区id"`
  16. Model string `json:"model" description:"[普通红包,随机红包,阶梯红包]"`
  17. RedEnvelopeNum int `json:"red_envelope_num" xorm:"not null comment('红包个数')" description:"红包个数"`
  18. RandSum float64 `json:"rand_sum" xorm:"decimal not null comment('红包总金额')"`
  19. Single float64 `json:"single" description:"单个金额" xorm:"not null comment('单个金额')"`
  20. Probability float64 `json:"probability" description:"概率[0-100)" xorm:"not null comment('概率')"`
  21. Des string `json:"des" xorm:"not null default('根据对应得概率获得红包') comment('规则描述')"`
  22. ShakeRedEnvelopeStatus string `json:"shake_red_envelope_status" xorm:"not null default('未开始') comment('未开始|进行中|已结束')"`
  23. ShakeRedEnvelopeRuleLadders []*ShakeRedEnvelopeRuleLadder `json:"shake_red_envelope_rule_ladders" xorm:"-" description:"阶梯红包"`
  24. }
  25. func (t *ShakeRedEnvelopeRule) TableName() string {
  26. return ShakeRedEnvelopeRuleTableName
  27. }
  28. func (t *ShakeRedEnvelopeRule) UpdateStatus(id int64, status string) (int64, error) {
  29. t.ShakeRedEnvelopeStatus = status
  30. t.UpdatedAt = time.Now()
  31. return core.GetXormAuto().Where("is_delete=0 and id=?", id).
  32. Cols("shake_red_envelope_status", "updated_at").Update(t)
  33. }
  34. func (t *ShakeRedEnvelopeRule) UpdateToStatusBySids(sids []int64, before, after string) (int64, error) {
  35. t.ShakeRedEnvelopeStatus = after
  36. t.UpdatedAt = time.Now()
  37. return core.GetXormAuto().Where("is_delete=0 and shake_red_envelope_status=? ", before).
  38. In("shake_red_envelope_activity_id", sids).Cols("shake_red_envelope_status", "updated_at").
  39. Update(t)
  40. }
  41. func (t *ShakeRedEnvelopeRule) GetCurrent(aid int64) (bool, error) {
  42. return core.GetXormAuto().Table(t).Alias("r").
  43. Join("LEFT", new(ShakeRedEnvelopeActivity).Alias("a"),
  44. "a.id=r.shake_red_envelope_activity_id and a.is_delete=0").
  45. Where("r.is_delete=0 and (r.shake_red_envelope_status=? or r.shake_red_envelope_status=?) and a.activity_id=?",
  46. define.StatusReady, define.StatusRunning, aid).Get(t)
  47. }
  48. func UpdateSRERuleStatusBySREActivityIds(ids []int64) (int64, error) {
  49. return core.GetXormAuto().Where("is_delete=0").In("shake_red_envelope_activity_id", ids).
  50. Update(&ShakeRedEnvelopeRule{ShakeRedEnvelopeStatus: define.StatusNotBegin})
  51. }