蛋蛋星球-制度模式
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

527 lignes
19 KiB

  1. package egg_energy
  2. import (
  3. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  4. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  5. "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  6. "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
  7. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
  8. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  9. "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc/sys_cfg"
  10. egg_system_rules "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils"
  11. "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/cache"
  12. "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
  13. zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/logx"
  14. es2 "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  15. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  16. "encoding/json"
  17. "errors"
  18. "fmt"
  19. "github.com/olivere/elastic/v7"
  20. "github.com/shopspring/decimal"
  21. "strings"
  22. "time"
  23. "xorm.io/xorm"
  24. )
  25. // SettlementGiveActivityCoin 结算观看激励广告得到蛋蛋积分
  26. func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ecpm string, ch *rabbit.Channel) (rewardValue float64, err error) {
  27. egg_system_rules.FilePutContents("SettlementGiveActivityCoin", egg_system_rules.SerializeStr(user))
  28. uid := user.Id
  29. now := time.Now()
  30. //TODO::拒绝重复异常回调
  31. redisKey := fmt.Sprintf(md2.UserNextWatchAdDate, uid)
  32. nextWatchAdDate, _ := cache.GetString(redisKey)
  33. if nextWatchAdDate != "" {
  34. nextWatchAdDateValue := egg_system_rules.String2Time(nextWatchAdDate)
  35. if nextWatchAdDateValue.After(time.Now()) {
  36. return 0, errors.New("未到可观看时间~~")
  37. }
  38. }
  39. //1、查找 `egg_energy_basic_setting` 基础设置
  40. eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(engine)
  41. eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  42. "key": "is_open",
  43. "value": 1,
  44. })
  45. if err != nil {
  46. return
  47. }
  48. if eggEnergyBasicSetting == nil {
  49. err = errors.New("蛋蛋能量设置未开启!")
  50. return
  51. }
  52. var videoRewardSystem *md2.VideoRewardSystemStruct
  53. err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem)
  54. if err != nil {
  55. return
  56. }
  57. if eggEnergyBasicSetting.VideoRewardIsOpen == 1 {
  58. if videoRewardSystem.RewardTotalNum == "" || videoRewardSystem.IntervalMinutes == "" || videoRewardSystem.EachRoundHour == "" {
  59. err = errors.New("视屏奖励机制设置未完全!")
  60. return
  61. }
  62. var rewardSystem []*md2.RewardSystemStruct
  63. err = json.Unmarshal([]byte(eggEnergyBasicSetting.RewardSystem), &rewardSystem)
  64. if err != nil {
  65. return
  66. }
  67. if len(rewardSystem) == 0 {
  68. err = errors.New("未设置奖励机制!")
  69. return
  70. }
  71. go dealEcpm(user, ecpm, ch) //TODO::协程处理ecpm的变化
  72. //TODO::奖励多少个活跃积分(根据ecpm, 新用户机制, 蛋蛋分机制)
  73. sysCfgDb := sys_cfg.NewSysCfgDb(engine)
  74. videoRewardUnitPrice := sysCfgDb.SysCfgGetWithDb(enum.VideoRewardUnitPrice)
  75. if videoRewardUnitPrice != "" { //处理ecpm
  76. var coin model.VirtualCoin
  77. _, err = engine.Where("id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).Get(&coin)
  78. if err != nil {
  79. return rewardValue, err
  80. }
  81. activePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin.ExchangeRatio)
  82. videoRewardUnitPriceValue, _ := decimal.NewFromString(videoRewardUnitPrice)
  83. rewardValue, _ = videoRewardUnitPriceValue.Mul(activePointsCoinExchangeRatioValue).Float64()
  84. } else {
  85. rewardValue = egg_system_rules.StrToFloat64(videoRewardSystem.RewardValue)
  86. }
  87. var newUserRewardRules *md2.NewUserRewardRules
  88. err = json.Unmarshal([]byte(eggEnergyBasicSetting.NewUserIncentiveRules), &newUserRewardRules)
  89. if err != nil {
  90. return
  91. }
  92. userCreateAt := egg_system_rules.String2Time(user.CreateAt)
  93. if int(now.Sub(userCreateAt).Hours()/24) <= newUserRewardRules.ContinueDays { //处理新用户机制
  94. rewardValue *= newUserRewardRules.RewardCoefficient
  95. }
  96. score := 60.00
  97. esIndex := es.GetLatestEffectiveIndexFromAlias(now)
  98. esIndexName := md.EggEnergyUserEggScoreEsAlias + "_" + esIndex
  99. results, err1 := es2.FirstDoc(esIndexName, esIndex+"_"+egg_system_rules.Int64ToStr(user.Id))
  100. if err1 != nil {
  101. if !elastic.IsNotFound(err1) {
  102. return rewardValue, err1
  103. }
  104. }
  105. if !elastic.IsNotFound(err1) {
  106. var doc md.EggEnergyUserEggScoreEs
  107. err = json.Unmarshal(results.Source, &doc)
  108. if err != nil {
  109. return
  110. }
  111. score = doc.ScoreValue
  112. }
  113. eggPointPartitionCoefficientManagementDb := implement.NewEggPointPartitionCoefficientManagementDb(engine)
  114. eggPointPartitionCoefficientManagements, err1 := eggPointPartitionCoefficientManagementDb.EggPointPartitionCoefficientManagementGetAll()
  115. if err1 != nil {
  116. return rewardValue, err1
  117. }
  118. for _, v := range *eggPointPartitionCoefficientManagements { //处理蛋蛋分机制
  119. if egg_system_rules.StrToFloat64(v.StartScore) <= score && egg_system_rules.StrToFloat64(v.EndScore) > score {
  120. rewardValue *= egg_system_rules.StrToFloat64(v.Coefficient)
  121. }
  122. }
  123. //处理圈层奖励
  124. var rewardSystemMap = map[int]*md2.RewardSystemStruct{}
  125. for _, v := range rewardSystem {
  126. rewardSystemMap[v.Level] = v
  127. }
  128. publicPlatoonUserRelationDb := implement.NewPublicPlatoonUserRelationDb(engine)
  129. publicPlatoonUserRelation, err1 := publicPlatoonUserRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  130. "key": "uid",
  131. "value": uid,
  132. })
  133. if err1 != nil {
  134. return rewardValue, err1
  135. }
  136. var rewardFather []struct {
  137. Uid int64 `json:"uid"` //用户id
  138. RewardValue float64 `json:"reward_value"` //奖励值
  139. StartAt string `json:"start_at"`
  140. EndAt string `json:"end_at"`
  141. SignId int64 `json:"sign_id"`
  142. }
  143. var fatherUids []string
  144. if publicPlatoonUserRelation != nil {
  145. fatherUids = strings.Split(publicPlatoonUserRelation.FatherUid, "-")
  146. }
  147. for k, id := range fatherUids {
  148. tmpOneCirclesPublicPlatoonUserRelation, err11 := publicPlatoonUserRelationDb.PublicPlatoonUserRelationGetOneByParams(map[string]interface{}{
  149. "key": "id",
  150. "value": id,
  151. })
  152. if err11 != nil {
  153. return rewardValue, err11
  154. }
  155. if tmpOneCirclesPublicPlatoonUserRelation == nil {
  156. continue
  157. }
  158. if tmpOneCirclesPublicPlatoonUserRelation.Uid <= 0 {
  159. //待填充位
  160. continue
  161. }
  162. fatherUid := egg_system_rules.Int64ToStr(tmpOneCirclesPublicPlatoonUserRelation.Uid)
  163. fatherReward := rewardSystemMap[k+1]
  164. //TODO::判断是否活跃
  165. var m model.EggSignIn
  166. has, err33 := engine.Where("uid =?", fatherUid).And("end_time >=?", time.Now().Format("2006-01-02 15:04:05")).Get(&m)
  167. if err33 != nil {
  168. return rewardValue, err33
  169. }
  170. if !has {
  171. //不活跃不需要奖励
  172. continue
  173. }
  174. //判断是否满足奖励条件
  175. userRelateDb := implement.NewUserRelateDb(engine)
  176. userCount, _, err2 := userRelateDb.SumUserRelateByParentUid(fatherUid)
  177. if err2 != nil {
  178. return rewardValue, err2
  179. }
  180. if fatherReward != nil && userCount >= egg_system_rules.StrToInt64(fatherReward.RewardCondition) {
  181. fatherRewardValue := rewardValue * (egg_system_rules.StrToFloat64(fatherReward.RewardValue) / 100)
  182. rewardFather = append(rewardFather, struct {
  183. Uid int64 `json:"uid"` //用户id
  184. RewardValue float64 `json:"reward_value"` //奖励值
  185. StartAt string `json:"start_at"`
  186. EndAt string `json:"end_at"`
  187. SignId int64 `json:"sign_id"`
  188. }{
  189. Uid: egg_system_rules.StrToInt64(fatherUid),
  190. RewardValue: fatherRewardValue,
  191. StartAt: m.StartTime,
  192. EndAt: m.EndTime,
  193. SignId: m.Id,
  194. })
  195. }
  196. }
  197. //处理直推奖励
  198. var directPushRewardSetting *md2.DirectPushRewardSettingStruct
  199. err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &directPushRewardSetting)
  200. if err != nil {
  201. return
  202. }
  203. fatherRewardValue := rewardValue * (egg_system_rules.StrToFloat64(directPushRewardSetting.RewardRateValue) / 100)
  204. var fatherSign model.EggSignIn
  205. if directPushRewardSetting.MemberSelfIsOpenGetTeamReward == "1" {
  206. fmt.Println("user:::::::::::::", user)
  207. has, err44 := engine.Where("uid =?", user.ParentUid).And("end_time >=?", time.Now().Format("2006-01-02 15:04:05")).Get(&fatherSign)
  208. if err44 != nil {
  209. return rewardValue, err44
  210. }
  211. if !has {
  212. //不活跃不需要奖励
  213. fatherRewardValue = 0
  214. }
  215. }
  216. session := engine.NewSession()
  217. defer func() {
  218. session.Close()
  219. if err := recover(); err != nil {
  220. _ = zhios_order_relate_logx.Error(err)
  221. }
  222. }()
  223. session.Begin()
  224. //给相应的用户加上"个人"活跃积分
  225. err = rule.DealUserVirtualCoin(session, md.DealUserVirtualCoinReq{
  226. Kind: "add",
  227. Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyWatchAdRewardPersonalActiveCoin),
  228. TransferType: int(enum.EggEnergyWatchAdRewardPersonalActiveCoin),
  229. CoinId: eggEnergyBasicSetting.PersonEggPointsCoinId,
  230. Uid: uid,
  231. Amount: rewardValue,
  232. })
  233. if err != nil {
  234. _ = session.Rollback()
  235. fmt.Println("err:::::2222", err)
  236. return rewardValue, err
  237. }
  238. //给相应的用户上级加上"团队"活跃积分
  239. if fatherRewardValue > 0 {
  240. err = rule.DealUserVirtualCoin(session, md.DealUserVirtualCoinReq{
  241. Kind: "add",
  242. Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyWatchAdRewardFansActiveCoin),
  243. TransferType: int(enum.EggEnergyWatchAdRewardFansActiveCoin),
  244. CoinId: eggEnergyBasicSetting.TeamEggPointsCoinId,
  245. Uid: user.ParentUid,
  246. Amount: fatherRewardValue,
  247. })
  248. if err != nil {
  249. _ = session.Rollback()
  250. fmt.Println("err:::::2222", err)
  251. return rewardValue, err
  252. }
  253. }
  254. //给相应的用户加上"团队"活跃积分
  255. for _, vv := range rewardFather {
  256. if vv.RewardValue > 0 {
  257. //TODO::推入rabbitmq 异步处理
  258. ch.Publish(md2.EggEnergyExchange, md.DealUserVirtualCoinReq{
  259. Kind: "add",
  260. Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyWatchAdRewardTeamActiveCoin),
  261. TransferType: int(enum.EggEnergyWatchAdRewardTeamActiveCoin),
  262. CoinId: eggEnergyBasicSetting.TeamEggPointsCoinId,
  263. Uid: vv.Uid,
  264. Amount: vv.RewardValue,
  265. }, md2.EggEnergyRoutKeyForSettlementPublicGiveActivityCoin)
  266. ch.Publish(md2.EggEnergyExchange, md2.EggEnergyTeamAssistanceReq{
  267. AssistanceUid: uid,
  268. Uid: vv.Uid,
  269. AssistanceValue: vv.RewardValue,
  270. SignStart: vv.StartAt,
  271. SignEnd: vv.EndAt,
  272. SignId: vv.SignId,
  273. }, md2.EggEnergyTeamAssistance)
  274. }
  275. }
  276. err = session.Commit()
  277. if err != nil {
  278. _ = session.Rollback()
  279. return rewardValue, errors.New("事务提交失败")
  280. }
  281. }
  282. //增加 egg_user_watch_records 记录
  283. eggEnergyUserWatchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(engine)
  284. eggEnergyUserWatchRecords, err1 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{
  285. "key": "uid",
  286. "value": uid,
  287. })
  288. if err1 != nil {
  289. return rewardValue, err1
  290. }
  291. if eggEnergyUserWatchRecords == nil {
  292. residueWatchAdNum := egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) - 1
  293. if residueWatchAdNum < 0 {
  294. residueWatchAdNum = egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum)
  295. }
  296. eggEnergyUserWatchRecords = &model.EggEnergyUserWatchRecords{
  297. Uid: uid,
  298. NextWatchAdDate: now.Add(time.Hour * time.Duration(egg_system_rules.StrToInt(videoRewardSystem.EachRoundHour))),
  299. ResidueWatchAdNum: egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) - 1,
  300. CreateAt: now.Format("2006-01-02 15:04:05"),
  301. UpdateAt: now.Format("2006-01-02 15:04:05"),
  302. }
  303. _, err2 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsInsert(eggEnergyUserWatchRecords)
  304. if err2 != nil {
  305. return rewardValue, err2
  306. }
  307. } else {
  308. residueWatchAdNum := eggEnergyUserWatchRecords.ResidueWatchAdNum - 1
  309. nextWatchAdDate := eggEnergyUserWatchRecords.NextWatchAdDate
  310. if residueWatchAdNum == 0 { //最后一条广告
  311. residueWatchAdNum = egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum)
  312. }
  313. if residueWatchAdNum == egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum)-1 { //第一条广告
  314. nextWatchAdDate = now.Add(time.Hour * time.Duration(egg_system_rules.StrToInt(videoRewardSystem.EachRoundHour)))
  315. }
  316. eggEnergyUserWatchRecords.ResidueWatchAdNum = residueWatchAdNum
  317. eggEnergyUserWatchRecords.NextWatchAdDate = nextWatchAdDate
  318. _, err2 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsUpdate(eggEnergyUserWatchRecords.Id, eggEnergyUserWatchRecords, "residue_watch_ad_num", "next_watch_ad_date")
  319. if err2 != nil {
  320. return rewardValue, err2
  321. }
  322. }
  323. var watchAdDate string
  324. if eggEnergyUserWatchRecords.ResidueWatchAdNum == egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) {
  325. if eggEnergyUserWatchRecords.NextWatchAdDate.Before(time.Now()) {
  326. watchAdDate = ""
  327. } else {
  328. watchAdDate = eggEnergyUserWatchRecords.NextWatchAdDate.Format("2006-01-02 15:04:05")
  329. }
  330. } else {
  331. watchAdDate = time.Now().Add(time.Duration(egg_system_rules.StrToInt64(videoRewardSystem.IntervalMinutes)) * time.Second).Format("2006-01-02 15:04:05")
  332. }
  333. cache.SetEx(redisKey, watchAdDate, 60*60*24) //TODO::默认缓存1小时
  334. return
  335. }
  336. func dealEcpm(user model.User, ecpm string, ch *rabbit.Channel) {
  337. //查找缓存中的ecpm值和当前的ecpm是否一致
  338. key := fmt.Sprintf(md.UserEcpmCacheKey, user.Id)
  339. ecpmCacheValue, _ := cache.GetString(key)
  340. if ecpmCacheValue == "" || ecpmCacheValue != ecpm {
  341. //更新缓存值
  342. cache.SetEx(key, ecpm, md.UserEcpmCacheTime)
  343. //TODO::推入rabbitmq 异步处理
  344. ch.Publish(md2.EggEnergyExchange, md.DealUserEcpmReq{
  345. Uid: user.Id,
  346. Ecpm: ecpm,
  347. }, md2.EggEnergyRoutKeyForDealUserEcpm)
  348. }
  349. }
  350. func ActivityCoinToAlipayRealName(engine *xorm.Engine, uid int64, amount string) (err error) {
  351. session := engine.NewSession()
  352. defer func() {
  353. session.Close()
  354. if err := recover(); err != nil {
  355. _ = zhios_order_relate_logx.Error(err)
  356. }
  357. }()
  358. session.Begin()
  359. err = rule.DealUserWallet(session, md.DealUserWalletReq{
  360. Direction: "sub",
  361. Kind: int(enum.UserToAlipayRealName),
  362. Title: enum.UserToAlipayRealName.String(),
  363. Uid: uid,
  364. Amount: egg_system_rules.StrToFloat64(amount),
  365. })
  366. if err != nil {
  367. session.Rollback()
  368. return err
  369. }
  370. return session.Commit()
  371. amountValue, _ := decimal.NewFromString(amount)
  372. //1、查找 `egg_energy_basic_setting` 基础设置
  373. eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(engine)
  374. eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  375. "key": "is_open",
  376. "value": 1,
  377. })
  378. if err != nil {
  379. return
  380. }
  381. if eggEnergyBasicSetting == nil {
  382. err = errors.New("蛋蛋能量设置未开启!")
  383. return
  384. }
  385. var coin model.VirtualCoin
  386. _, err = engine.Where("id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).Get(&coin)
  387. if err != nil {
  388. return
  389. }
  390. personActivePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin.ExchangeRatio)
  391. //2、判断个人蛋蛋积分是否足够
  392. var personUserVirtualAmount model.UserVirtualAmount
  393. _, err = engine.Where("coin_id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).And("uid =?", uid).Get(&personUserVirtualAmount)
  394. if err != nil {
  395. fmt.Println("err:::::1111", err)
  396. return
  397. }
  398. personUserVirtualAmountValue, _ := decimal.NewFromString(personUserVirtualAmount.Amount)
  399. needVirtualAmountValue := amountValue.Mul(personActivePointsCoinExchangeRatioValue)
  400. needVirtualAmount, _ := amountValue.Mul(personActivePointsCoinExchangeRatioValue).Float64()
  401. if personUserVirtualAmountValue.LessThan(needVirtualAmountValue) {
  402. err = errors.New("当前蛋蛋积分不足!")
  403. return
  404. }
  405. //3、扣除对应个人蛋蛋积分
  406. session = engine.NewSession()
  407. defer func() {
  408. session.Close()
  409. if err := recover(); err != nil {
  410. _ = zhios_order_relate_logx.Error(err)
  411. }
  412. }()
  413. session.Begin()
  414. //给相应的用户加上"个人"活跃积分
  415. err = rule.DealUserVirtualCoin(session, md.DealUserVirtualCoinReq{
  416. Kind: "sub",
  417. Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggPointCoinToAliPayRealName),
  418. TransferType: int(enum.EggPointCoinToAliPayRealName),
  419. CoinId: eggEnergyBasicSetting.PersonEggPointsCoinId,
  420. Uid: uid,
  421. Amount: needVirtualAmount,
  422. })
  423. if err != nil {
  424. _ = session.Rollback()
  425. fmt.Println("err:::::2222", err)
  426. return err
  427. }
  428. err = session.Commit()
  429. if err != nil {
  430. _ = session.Rollback()
  431. return errors.New("事务提交失败")
  432. }
  433. return
  434. }
  435. func CheckActivityCoinToAlipayRealName(engine *xorm.Engine, uid int64, amount string) (err error, isCan bool) {
  436. amountValue, _ := decimal.NewFromString(amount)
  437. //1、查找 `egg_energy_basic_setting` 基础设置
  438. eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(engine)
  439. eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  440. "key": "is_open",
  441. "value": 1,
  442. })
  443. if err != nil {
  444. return
  445. }
  446. if eggEnergyBasicSetting == nil {
  447. err = errors.New("蛋蛋能量设置未开启!")
  448. return
  449. }
  450. var coin model.VirtualCoin
  451. _, err = engine.Where("id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).Get(&coin)
  452. if err != nil {
  453. return
  454. }
  455. personActivePointsCoinExchangeRatioValue, _ := decimal.NewFromString(coin.ExchangeRatio)
  456. //2、判断个人蛋蛋积分是否足够
  457. var personUserVirtualAmount model.UserVirtualAmount
  458. _, err = engine.Where("coin_id = ?", eggEnergyBasicSetting.PersonEggPointsCoinId).And("uid =?", uid).Get(&personUserVirtualAmount)
  459. if err != nil {
  460. fmt.Println("err:::::1111", err)
  461. return
  462. }
  463. personUserVirtualAmountValue, _ := decimal.NewFromString(personUserVirtualAmount.Amount)
  464. needVirtualAmountValue := amountValue.Mul(personActivePointsCoinExchangeRatioValue)
  465. if personUserVirtualAmountValue.GreaterThan(needVirtualAmountValue) {
  466. isCan = true
  467. }
  468. return
  469. }
  470. // CalcUserContinuousDailyActivityDays 计算用户连续活跃天数
  471. func CalcUserContinuousDailyActivityDays(engine *xorm.Engine, uid int, startDate string, endDate string) (err error, days int, isContinuousDailyActivity bool) {
  472. startAt, err := time.ParseInLocation("2006-01-02", startDate, time.Local) //起始时间
  473. endAt, err := time.ParseInLocation("2006-01-02", endDate, time.Local) //起始时间
  474. var list []model.EggEnergyUserActivity
  475. err = engine.Where("date >= ?", startAt.Format("2006-01-02")).
  476. And("date < ?", endAt.Format("2006-01-02")).
  477. And("uid =?", uid).Find(&list)
  478. if err != nil {
  479. fmt.Println("err:::::1111", err)
  480. return
  481. }
  482. days = len(list)
  483. diffDays := egg_system_rules.GetDiffDays(endAt, startAt) //相差天数
  484. if days == diffDays {
  485. isContinuousDailyActivity = true
  486. }
  487. return
  488. }