github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/game/internal/user_shareInfo.go (about) 1 package internal 2 3 import ( 4 "time" 5 6 "github.com/name5566/leaf/log" 7 8 "msg" 9 10 mgo "gopkg.in/mgo.v2" 11 "gopkg.in/mgo.v2/bson" 12 ) 13 14 /* 15 16 17 我的ID: 自己账户的ID号 18 推荐人ID: 就是上级ID号 19 直推总人数: 直属下级总用户人数 20 昨日直推新增: 昨天新增的直属下级数量 21 团队总人数: 团队所有人数 22 昨日团队新增: 除直属下级外新增的人数 23 昨日直推佣金奖励: 昨天直属下级所带来的收益 24 昨天团队佣金奖励: 昨天自己团队所有人创造的佣金奖励(自己+直属+直属下级) 25 26 27 28 */ 29 func (user *User) ShareInfo() { 30 31 data := new(msg.S2C_ShareInfo) 32 data.AccountId = int64(user.baseData.userData.AccountID) 33 data.ParentId = user.baseData.userData.ParentId 34 now := time.Now() 35 last := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) 36 //获取直推总人数 37 pipe := []bson.M{ 38 { 39 40 "$project": bson.M{ 41 "_id": 1, 42 "agents": 1, 43 "accountid": 1, 44 }, 45 }, 46 47 { 48 49 "$unwind": "$agents", 50 }, 51 { 52 53 "$project": bson.M{ 54 "_id": 1, 55 "agents": 1, 56 "accountid": 1, 57 }, 58 }, 59 60 { 61 62 "$unwind": "$agents.datas", 63 }, 64 { 65 "$match": bson.M{ 66 "agents.level": 1, 67 "accountid": user.baseData.userData.AccountID, 68 }, 69 }, 70 71 { 72 73 "$group": bson.M{ 74 "_id": nil, 75 "sum": bson.M{ 76 "$sum": 1, 77 }, 78 }, 79 }, 80 } 81 data.FirstLevelNumber = getUserAgents(pipe) 82 //获取直推昨日新增人数 83 84 pipe = []bson.M{ 85 { 86 87 "$project": bson.M{ 88 "_id": 1, 89 "agents": 1, 90 "accountid": 1, 91 }, 92 }, 93 94 { 95 96 "$unwind": "$agents", 97 }, 98 { 99 100 "$project": bson.M{ 101 "_id": 1, 102 "agents": 1, 103 "accountid": 1, 104 }, 105 }, 106 107 { 108 109 "$unwind": "$agents.datas", 110 }, 111 { 112 "$match": bson.M{ 113 "agents.level": 1, 114 "accountid": user.baseData.userData.AccountID, 115 "agents.datas.createdat": bson.M{ 116 "$lt": last.Unix(), 117 "$gte": last.Unix() - 24*60*60, 118 }, 119 }, 120 }, 121 122 { 123 124 "$group": bson.M{ 125 "_id": nil, 126 "sum": bson.M{ 127 "$sum": 1, 128 }, 129 }, 130 }, 131 } 132 133 data.FirstLevelAdd = getUserAgents(pipe) 134 135 //获取团队总人数 136 pipe = []bson.M{ 137 { 138 139 "$project": bson.M{ 140 "_id": 1, 141 "agents": 1, 142 "accountid": 1, 143 }, 144 }, 145 146 { 147 148 "$unwind": "$agents", 149 }, 150 { 151 152 "$project": bson.M{ 153 "_id": 1, 154 "agents": 1, 155 "accountid": 1, 156 }, 157 }, 158 159 { 160 161 "$unwind": "$agents.datas", 162 }, 163 164 { 165 166 "$match": bson.M{ 167 "accountid": data.AccountId, 168 }, 169 }, 170 { 171 172 "$group": bson.M{ 173 "_id": nil, 174 "sum": bson.M{ 175 "$sum": 1, 176 }, 177 }, 178 }, 179 } 180 data.TeamNumber = getUserAgents(pipe) 181 182 //获取昨日团队新增人数、、除直属下级外新增的人数 183 pipe = []bson.M{ 184 { 185 186 "$project": bson.M{ 187 "_id": 1, 188 "agents": 1, 189 "accountid": 1, 190 }, 191 }, 192 193 { 194 195 "$unwind": "$agents", 196 }, 197 { 198 199 "$project": bson.M{ 200 "_id": 1, 201 "agents": 1, 202 "accountid": 1, 203 }, 204 }, 205 206 { 207 208 "$unwind": "$agents.datas", 209 }, 210 { 211 "$match": bson.M{ 212 "agents.level": bson.M{ 213 "$gt": 1, 214 }, 215 "accountid": user.baseData.userData.AccountID, 216 "agents.datas.createdat": bson.M{ 217 "$lt": last.Unix(), 218 "$gte": last.Unix() - 24*60*60, 219 }, 220 }, 221 }, 222 223 { 224 225 "$group": bson.M{ 226 "_id": nil, 227 "sum": bson.M{ 228 "$sum": 1, 229 }, 230 }, 231 }, 232 } 233 234 data.TeamAdd = getUserAgents(pipe) 235 user.WriteMsg(data) 236 } 237 238 func getUserAgents(pipe interface{}) int { 239 db := mongoDB.Ref() 240 defer mongoDB.UnRef(db) 241 data := make(map[string]int) 242 err := db.DB(DB).C("userAgents").Pipe(pipe).One(&data) 243 if err != nil && err != mgo.ErrNotFound { 244 log.Error("获取数据失败:%v", err) 245 return 0 246 } 247 if err == mgo.ErrNotFound { 248 return 0 249 } 250 return data["sum"] 251 }