shareToaward_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package test
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mongodb"
  5. "fmt"
  6. "strings"
  7. "testing"
  8. "time"
  9. )
  10. const SkTimes = "-" //-默认全部 1653877526-1653877526开始时间-结束时间 开始时间不传默认0结束时间不传默认当前时间 -必加
  11. func Test_Award(t *testing.T) {
  12. Mgo := &mongodb.MongodbSim{
  13. MongodbAddr: "192.168.3.206:27080",
  14. Size: 5,
  15. DbName: "qfw",
  16. UserName: "",
  17. Password: "",
  18. ReplSet: "",
  19. }
  20. Mgo.InitPool()
  21. query := map[string]interface{}{}
  22. query["i_shareCount"] = map[string]interface{}{
  23. "$gt": 0,
  24. "$lte": 4,
  25. }
  26. auser, _ := Mgo.Find("user", query, "", `{"_id":1}`, false, -1, -1)
  27. var users []string
  28. for _, v := range *auser {
  29. users = append(users, common.InterfaceToStr(v["_id"]))
  30. }
  31. q := map[string]interface{}{}
  32. ndatas := []map[string]interface{}{}
  33. skTimes := strings.Split(SkTimes, "-")
  34. stime := skTimes[0]
  35. etime := skTimes[1]
  36. fmt.Println(common.Int64All(stime), common.If(common.Int64All(etime) == 0, time.Now().Unix(), common.Int64All(etime)))
  37. for _, u := range users {
  38. q["$or"] = []map[string]interface{}{
  39. {"share_uid": u},
  40. {"shared_uid": u},
  41. }
  42. q["createtime"] = map[string]interface{}{
  43. "$gte": common.Int64All(stime),
  44. "$lt": common.If(common.Int64All(etime) == 0, time.Now().Unix(), common.Int64All(etime)),
  45. }
  46. data, _ := Mgo.Find("user_share", q, `{"createtime":1}`, `{"_id":1,"createtime":1,"shared_uid":1}`, false, 0, 4)
  47. if len(*data) > 0 {
  48. for _, vv := range *data {
  49. ndata := map[string]interface{}{}
  50. if common.InterfaceToStr(vv["shared_uid"]) == u {
  51. ndata["getway"] = "被邀请注册成功"
  52. } else {
  53. ndata["getway"] = "邀请好友成功"
  54. }
  55. ndata["userid"] = u
  56. ndata["award"] = "subvip"
  57. ndata["num"] = 7
  58. ndata["date"] = vv["createtime"]
  59. ndata["activity_code"] = "inviteRegister"
  60. ndata["detail"] = ""
  61. ndatas = append(ndatas, ndata)
  62. }
  63. }
  64. }
  65. Mgo.SaveBulk("activity_award", ndatas...)
  66. }