check.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package model
  2. import (
  3. "active/tools"
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "git.jiaxianghudong.com/go/logs"
  9. "git.jiaxianghudong.com/webs/pkg/pb"
  10. )
  11. //OpenTimes 开始时间
  12. type OpenTimes struct {
  13. Start string `json:"time_start"`
  14. End string `json:"time_end"`
  15. }
  16. //AdsOpenTimes 开始时间
  17. type AdsOpenTimes struct {
  18. Start string `json:"istimeoffon_time_start"`
  19. End string `json:"istimeoffon_time_end"`
  20. }
  21. //Tagdata 活动数据
  22. type Tagdata struct {
  23. Start string `json:"radix,omitempty"`
  24. RebateType string `json:"rebate_type,omitempty"`
  25. GoodIDs string `json:"goodids,omitempty"`
  26. RuleImg string `json:"rule_bgimg,omitempty"`
  27. ActiveModel string `json:"active_model,omitempty"`
  28. ActiveType string `json:"active_type,omitempty"`
  29. GoodsType string `json:"goods_type,omitempty"`
  30. GrandTotal []interface{} `json:"grand_total,omitempty"`
  31. ActiveTitleImg []interface{} `json:"active_title_img,omitempty"`
  32. InvestmentRebate []interface{} `json:"investment_rebate,omitempty"`
  33. GiftBag []interface{} `json:"gift_bag,omitempty"`
  34. Welfare []interface{} `json:"welfare,omitempty"`
  35. Rank []interface{} `json:"rank,omitempty"`
  36. }
  37. //CheckOpenCondition 判断限制渠道,包,地区
  38. func CheckOpenCondition(u *pb.User, openCond string) bool {
  39. if openCond != "" {
  40. opencondition := make(map[string]string)
  41. err := json.Unmarshal([]byte(openCond), &opencondition)
  42. if err != nil {
  43. logs.Errorf("Opencondition: %s err: %v", openCond, err)
  44. return false
  45. }
  46. if val, ok := opencondition["channel_app"]; ok && val != "" {
  47. channelapp := strings.Split(val, ",")
  48. if !tools.InStringArray(fmt.Sprintf("%d-%d", u.ChannelID, u.AppID), channelapp) {
  49. return false
  50. }
  51. }
  52. if val, ok := opencondition["region"]; ok && val != "000000" && val != "0" && val != u.Region {
  53. logs.Debug("region != 000000 and != ", u.Region, " continue")
  54. return false
  55. }
  56. }
  57. return true
  58. }
  59. //GetOpenTime 获取活动时间
  60. func (opentm *OpenTimes) GetOpenTime(tm string) {
  61. if tm != "" {
  62. err := json.Unmarshal([]byte(tm), &opentm)
  63. if err != nil {
  64. logs.Error(fmt.Sprintf("json opentime:%s err:%v", tm, err))
  65. }
  66. }
  67. }
  68. //CompareTime 活动时间判断
  69. func (opentm *OpenTimes) CompareTime() (bool, string) {
  70. if time.Now().Unix() < tools.TimeParseUnix(opentm.Start, "2006-01-02 15:04:05") || (opentm.Start == "" && opentm.End == "") {
  71. return false, "活动尚未开启!"
  72. }
  73. if time.Now().Unix() > tools.TimeParseUnix(opentm.End, "2006-01-02 15:04:05") {
  74. return false, "活动已经结束!"
  75. }
  76. return true, ""
  77. }
  78. //CompareRegTime 注册时间判断
  79. func (opentm *OpenTimes) CompareRegTime(unix int64) bool {
  80. if unix < tools.TimeParseUnix(opentm.Start, "2006-01-02 15:04:05") || (opentm.Start == "" && opentm.End == "") {
  81. return false
  82. }
  83. return true
  84. }
  85. //CheckTimeOut 显示时间
  86. func CheckTimeOut(begin, end string) (bool, string) {
  87. if time.Now().Unix() < tools.TimeParseUnix(begin, "2006-01-02 15:04:05") {
  88. return false, "当前活动领取时间尚未开启,敬请期待!"
  89. }
  90. if time.Now().Unix() > tools.TimeParseUnix(end, "2006-01-02 15:04:05") {
  91. return false, "当前活动领取时间已结束,谢谢参与!"
  92. }
  93. return true, ""
  94. }
  95. //GetOpenTime 获取活动时间
  96. func (adtm *AdsOpenTimes) GetOpenTime(tm string) {
  97. if tm != "" {
  98. err := json.Unmarshal([]byte(tm), &adtm)
  99. if err != nil {
  100. logs.Error(fmt.Sprintf("json opentime:%s err:%v", tm, err))
  101. }
  102. }
  103. }
  104. //CompareTime 活动时间判断
  105. func (adtm *AdsOpenTimes) CompareTime() (bool, string) {
  106. if time.Now().Unix() < tools.TimeParseUnix(adtm.Start, "2006-01-02 15:04:05") || (adtm.Start == "" && adtm.End == "") {
  107. return false, "活动尚未开启!"
  108. }
  109. if time.Now().Unix() > tools.TimeParseUnix(adtm.End, "2006-01-02 15:04:05") {
  110. return false, "活动已经结束!"
  111. }
  112. return true, ""
  113. }