123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package test
- import (
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mongodb"
- "fmt"
- "strings"
- "testing"
- "time"
- )
- const SkTimes = "-" //-默认全部 1653877526-1653877526开始时间-结束时间 开始时间不传默认0结束时间不传默认当前时间 -必加
- func Test_Award(t *testing.T) {
- Mgo := &mongodb.MongodbSim{
- MongodbAddr: "192.168.3.206:27080",
- Size: 5,
- DbName: "qfw",
- UserName: "",
- Password: "",
- ReplSet: "",
- }
- Mgo.InitPool()
- query := map[string]interface{}{}
- query["i_shareCount"] = map[string]interface{}{
- "$gt": 0,
- "$lte": 4,
- }
- auser, _ := Mgo.Find("user", query, "", `{"_id":1}`, false, -1, -1)
- var users []string
- for _, v := range *auser {
- users = append(users, common.InterfaceToStr(v["_id"]))
- }
- q := map[string]interface{}{}
- ndatas := []map[string]interface{}{}
- skTimes := strings.Split(SkTimes, "-")
- stime := skTimes[0]
- etime := skTimes[1]
- fmt.Println(common.Int64All(stime), common.If(common.Int64All(etime) == 0, time.Now().Unix(), common.Int64All(etime)))
- for _, u := range users {
- q["$or"] = []map[string]interface{}{
- {"share_uid": u},
- {"shared_uid": u},
- }
- q["createtime"] = map[string]interface{}{
- "$gte": common.Int64All(stime),
- "$lt": common.If(common.Int64All(etime) == 0, time.Now().Unix(), common.Int64All(etime)),
- }
- data, _ := Mgo.Find("user_share", q, `{"createtime":1}`, `{"_id":1,"createtime":1,"shared_uid":1}`, false, 0, 4)
- if len(*data) > 0 {
- for _, vv := range *data {
- ndata := map[string]interface{}{}
- if common.InterfaceToStr(vv["shared_uid"]) == u {
- ndata["getway"] = "被邀请注册成功"
- } else {
- ndata["getway"] = "邀请好友成功"
- }
- ndata["userid"] = u
- ndata["award"] = "subvip"
- ndata["num"] = 7
- ndata["date"] = vv["createtime"]
- ndata["activity_code"] = "inviteRegister"
- ndata["detail"] = ""
- ndatas = append(ndatas, ndata)
- }
- }
- }
- Mgo.SaveBulk("activity_award", ndatas...)
- }
|