gamedao.go 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/container/gmap"
  6. "github.com/gogf/gf/frame/g"
  7. "gmanager/library/base"
  8. "gmanager/library/mongo/util"
  9. "log"
  10. "github.com/gogf/gf/container/garray"
  11. "github.com/gogf/gf/os/gtime"
  12. "github.com/gogf/gf/util/gconv"
  13. "go.mongodb.org/mongo-driver/bson"
  14. "go.mongodb.org/mongo-driver/bson/primitive"
  15. "go.mongodb.org/mongo-driver/mongo"
  16. "go.mongodb.org/mongo-driver/mongo/options"
  17. )
  18. // 查询多个
  19. func (m *Mgo) FindAllItemm(form *base.BaseForm) (*mongo.Cursor, int) {
  20. client := DB.Mongo
  21. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  22. sid := 0
  23. itemType := ""
  24. if form.Params["operTable"] != "" {
  25. sid = gconv.Int(form.Params["operTable"])
  26. }
  27. filter := bson.D{{"serverid", sid}}
  28. SORT := bson.D{{"_id", 1}} //filter := bson.D{{key,value}}
  29. Limit := gconv.Int64(form.Rows)
  30. Skip := form.Page - 1
  31. SkipNum := gconv.Int64(Skip) * Limit
  32. groupStage := bson.D{{"$group", bson.D{
  33. {"_id", ""},
  34. {"sum", bson.D{{"$sum", "$itemNum"}}},
  35. {"count", bson.D{{"$sum", 1}}},
  36. }}}
  37. matchStage := bson.D{{"$match", bson.D{{"serverid", sid}}}}
  38. if form.Params["logType"] != "" {
  39. itemType = form.Params["logType"]
  40. filter = bson.D{{"serverid", sid}, {"type", itemType}}
  41. matchStage = bson.D{{"$match", bson.D{{"serverid", sid}, {"type", itemType}}}}
  42. }
  43. showInfoCursor, err := collection.Aggregate(context.TODO(), mongo.Pipeline{matchStage, groupStage})
  44. var showsWithInfo []bson.M
  45. if err = showInfoCursor.All(context.TODO(), &showsWithInfo); err != nil {
  46. fmt.Println(err)
  47. }
  48. if showsWithInfo == nil {
  49. return nil, 0
  50. }
  51. datarow := gconv.Int(showsWithInfo[0]["count"])
  52. datasum := gconv.Int(showsWithInfo[0]["sum"])
  53. form.TotalSize = datarow
  54. form.TotalPage = datarow / form.Rows
  55. fmt.Println(len(showsWithInfo))
  56. findOptions := options.Find().SetSort(SORT).SetLimit(Limit).SetSkip(SkipNum)
  57. singleResult, err := collection.Find(context.TODO(), filter, findOptions)
  58. if err != nil {
  59. fmt.Println(err)
  60. }
  61. return singleResult, datasum
  62. }
  63. func (m *Mgo) FindAllTime(form *base.BaseForm) *mongo.Cursor {
  64. client := DB.Mongo
  65. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  66. //collection.
  67. starttime := form.Params["starttime"]
  68. if starttime == "" {
  69. starttime = gtime.Now().Format("Y-m-d")
  70. } else {
  71. starttime = gtime.New(gconv.Time(starttime)).Format("Y-m-d")
  72. }
  73. fmt.Println("--=-" + starttime)
  74. filter := bson.D{{"checkTimeday", starttime}}
  75. singleResult, _ := collection.Find(context.TODO(), filter)
  76. return singleResult
  77. }
  78. func (m *Mgo) FindDauTime(starttime string) *mongo.Cursor {
  79. client := DB.Mongo
  80. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  81. filter := bson.D{{"logTime", starttime}}
  82. singleResult, _ := collection.Find(context.TODO(), filter)
  83. return singleResult
  84. }
  85. func (m *Mgo) FindDauTimeUser(starttime string, roles interface{}, time string) *mongo.Cursor {
  86. client := DB.Mongo
  87. collection, _ := client.Database(m.database).Collection(m.collection + "_" + starttime).Clone()
  88. filter := bson.D{{"userid", bson.M{"$in": roles}}}
  89. singleResult, _ := collection.Find(context.TODO(), filter)
  90. return singleResult
  91. }
  92. func (m *Mgo) FindDauTimeChannel(starttime string, channel string) int {
  93. client := DB.Mongo
  94. collection, _ := client.Database(m.database).Collection(m.collection + "_" + starttime).Clone()
  95. filter := bson.D{{"channelId", channel}}
  96. values, err := collection.Distinct(context.TODO(), "userid", filter)
  97. if err != nil {
  98. //log.Fatal(err)
  99. log.Println(err)
  100. }
  101. return len(values)
  102. }
  103. func (m *Mgo) FindRegTime() []bson.M {
  104. client := DB.Mongo
  105. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  106. dateBson := bson.M{"$dateToString": bson.M{"format": "%Y-%m-%d", "date": bson.M{"$add": bson.A{gconv.Time(28800), "$register.registerTime"}}}}
  107. pipe := []bson.M{
  108. {"$project": bson.M{"date": dateBson, "user_id": "$register.openId"}},
  109. {"$group": bson.M{"_id": bson.M{"date": "$date", "user": "$user_id"}}},
  110. {"$group": bson.M{"_id": "$_id.date", "count": bson.M{"$sum": 1}}},
  111. {"$project": bson.M{"date": "$_id", "count": 1, "_id": 0}},
  112. }
  113. ginfo, err := collection.Aggregate(context.TODO(), pipe)
  114. if err != nil {
  115. fmt.Println(err)
  116. }
  117. var showsWithInfo []bson.M
  118. if err = ginfo.All(context.TODO(), &showsWithInfo); err != nil {
  119. fmt.Println(err)
  120. }
  121. //listMap := gmap.NewListMap(true)
  122. //for _, b := range showsWithInfo {
  123. // listMap.Set(b["count"],b["date"])
  124. //
  125. //}
  126. fmt.Println(showsWithInfo)
  127. return showsWithInfo
  128. }
  129. func (m *Mgo) FindDau() []bson.M {
  130. client := DB.Mongo
  131. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  132. dateBson := bson.M{"$dateToString": bson.M{"format": "%Y-%m-%d", "date": bson.M{"$add": bson.A{gconv.Time(28800), "$loginTime.loginTime"}}}}
  133. pipe := []bson.M{
  134. {"$project": bson.M{"date": dateBson, "user_id": "$loginTime.openId"}},
  135. {"$group": bson.M{"_id": bson.M{"date": "$date", "user": "$user_id"}}},
  136. {"$group": bson.M{"_id": "$_id.date", "count": bson.M{"$sum": 1}}},
  137. {"$project": bson.M{"date": "$_id", "count": 1, "_id": 0}},
  138. }
  139. ginfo, err := collection.Aggregate(context.TODO(), pipe)
  140. if err != nil {
  141. fmt.Println(err)
  142. }
  143. var showsWithInfo []bson.M
  144. if err = ginfo.All(context.TODO(), &showsWithInfo); err != nil {
  145. fmt.Println(err)
  146. }
  147. fmt.Println(showsWithInfo)
  148. return showsWithInfo
  149. }
  150. func (m *Mgo) FindNew(startTime int64, endTime int64) *garray.Array {
  151. client := DB.Mongo
  152. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  153. //filter := bson.D{bson.M{"register.registerTime":bson.D{{"$gte",startTime},{"$lte",endTime}}}, "_id": 1}
  154. filter := bson.D{{"register.registerTime", bson.D{{"$gte", startTime}, {"$lte", endTime}}}}
  155. //oppo:=bson.M{"register.openId": 1}
  156. var findoptions *options.FindOptions
  157. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  158. if err != nil {
  159. fmt.Println(err)
  160. }
  161. var showsWithInfo []bson.M
  162. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  163. fmt.Println(err)
  164. }
  165. list := garray.New(false)
  166. for _, b := range showsWithInfo {
  167. s2 := b["register"].(primitive.M)
  168. list.Append(s2["uid"])
  169. }
  170. return list
  171. }
  172. func (m *Mgo) FindNewByServerId(startTime int64, endTime int64, serverId string) *garray.Array {
  173. client := DB.Mongo
  174. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  175. //filter := bson.D{bson.M{"register.registerTime":bson.D{{"$gte",startTime},{"$lte",endTime}}}, "_id": 1}
  176. filter := bson.D{{"register.serverId", serverId}, {"register.registerTime", bson.D{{"$gte", startTime}, {"$lte", endTime}}}}
  177. //oppo:=bson.M{"register.openId": 1}
  178. var findoptions *options.FindOptions
  179. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  180. if err != nil {
  181. fmt.Println(err)
  182. }
  183. var showsWithInfo []bson.M
  184. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  185. fmt.Println(err)
  186. }
  187. list := garray.New(false)
  188. for _, b := range showsWithInfo {
  189. s2 := b["register"].(primitive.M)
  190. list.Append(s2["uid"])
  191. }
  192. return list
  193. }
  194. func (m *Mgo) FindLogin(startTime int64, endTime int64, roles interface{}) int {
  195. client := DB.Mongo
  196. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  197. //filter := bson.D{bson.M{"register.registerTime":bson.D{{"$gte",startTime},{"$lte",endTime}}}, "_id": 1}
  198. filter := bson.D{
  199. {"loginTime.loginTime", bson.D{{"$gte", startTime}, {"$lte", endTime}}},
  200. {"loginTime.uid", bson.M{"$in": roles}}}
  201. //oppo:=bson.M{"register.openId": 1}
  202. var findoptions *options.FindOptions
  203. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  204. if err != nil {
  205. fmt.Println(err)
  206. }
  207. var showsWithInfo []bson.M
  208. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  209. fmt.Println(err)
  210. }
  211. list := garray.New(false)
  212. for _, b := range showsWithInfo {
  213. s2 := b["loginTime"].(primitive.M)
  214. if list.Contains(s2["uid"]) {
  215. continue
  216. }
  217. list.Append(s2["uid"])
  218. }
  219. return list.Len()
  220. }
  221. // 充值过的用户
  222. func (m *Mgo) FindPay(startTime string, endTime string, roles interface{}, serverId string) int {
  223. client := DB.Mongo
  224. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  225. //filter := bson.D{bson.M{"register.registerTime":bson.D{{"$gte",startTime},{"$lte",endTime}}}, "_id": 1}
  226. filter := bson.D{}
  227. if serverId == "" {
  228. filter = bson.D{
  229. {"creattime", bson.D{{"$gte", startTime}, {"$lte", endTime}}},
  230. {"status", gconv.Int32(1)},
  231. {"handlestatus", gconv.Int32(1)},
  232. {"uid", bson.M{"$in": roles}}}
  233. } else {
  234. filter = bson.D{
  235. {"creattime", bson.D{{"$gte", startTime}, {"$lte", endTime}}},
  236. {"status", gconv.Int32(1)},
  237. {"handlestatus", gconv.Int32(1)},
  238. {"region", gconv.Int32(serverId)},
  239. {"uid", bson.M{"$in": roles}}}
  240. }
  241. //oppo:=bson.M{"register.openId": 1}
  242. var findoptions *options.FindOptions
  243. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  244. if err != nil {
  245. fmt.Println(err)
  246. }
  247. var showsWithInfo []bson.M
  248. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  249. fmt.Println(err)
  250. }
  251. list := garray.New(false)
  252. for _, b := range showsWithInfo {
  253. if list.Contains(b["uid"]) {
  254. continue
  255. }
  256. list.Append(b["uid"])
  257. }
  258. return list.Len()
  259. }
  260. func (m *Mgo) FindLogin1(startTime int64, endTime int64, roles interface{}, serverId string) int {
  261. client := DB.Mongo
  262. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  263. //filter := bson.D{bson.M{"register.registerTime":bson.D{{"$gte",startTime},{"$lte",endTime}}}, "_id": 1}
  264. filter := bson.D{
  265. {"loginTime.loginTime", bson.D{{"$gte", startTime}, {"$lte", endTime}}},
  266. {"loginTime.serverId", serverId},
  267. {"loginTime.uid", bson.M{"$in": roles}}}
  268. //oppo:=bson.M{"register.openId": 1}
  269. var findoptions *options.FindOptions
  270. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  271. if err != nil {
  272. fmt.Println(err)
  273. }
  274. var showsWithInfo []bson.M
  275. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  276. fmt.Println(err)
  277. }
  278. list := garray.New(false)
  279. for _, b := range showsWithInfo {
  280. s2 := b["loginTime"].(primitive.M)
  281. if list.Contains(s2["uid"]) {
  282. continue
  283. }
  284. list.Append(s2["uid"])
  285. }
  286. return list.Len()
  287. }
  288. func (m *Mgo) FindLogin2(startTime int64, endTime int64) int {
  289. client := DB.Mongo
  290. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  291. //filter := bson.D{bson.M{"register.registerTime":bson.D{{"$gte",startTime},{"$lte",endTime}}}, "_id": 1}
  292. filter := bson.D{
  293. {"loginTime.loginTime", bson.D{{"$gte", startTime}, {"$lte", endTime}}}}
  294. //oppo:=bson.M{"register.openId": 1}
  295. var findoptions *options.FindOptions
  296. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  297. if err != nil {
  298. fmt.Println(err)
  299. }
  300. var showsWithInfo []bson.M
  301. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  302. fmt.Println(err)
  303. }
  304. list := garray.New(false)
  305. for _, b := range showsWithInfo {
  306. s2 := b["loginTime"].(primitive.M)
  307. if list.Contains(s2["uid"]) {
  308. continue
  309. }
  310. list.Append(s2["uid"])
  311. }
  312. return list.Len()
  313. }
  314. //查询各服务器的注册人数
  315. func (m *Mgo) FindRegisterByServer(startTime int64, endTime int64) *mongo.Cursor {
  316. client := DB.Mongo
  317. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  318. groupStage := bson.D{{"$group", bson.D{
  319. {"_id", "$register.serverId"},
  320. {"count", bson.D{{"$sum", 1}}},
  321. }}}
  322. matchStage := bson.D{{"$match", bson.D{{"register.registerTime", bson.D{{"$gte", startTime}, {"$lte", endTime}}}}}}
  323. showInfoCursor, err := collection.Aggregate(context.TODO(), mongo.Pipeline{matchStage, groupStage})
  324. if err != nil {
  325. fmt.Println(err)
  326. }
  327. return showInfoCursor
  328. }
  329. //查询各服务器的登录人数
  330. func (m *Mgo) FindLoginByServer(startTime int64, endTime int64) *mongo.Cursor {
  331. client := DB.Mongo
  332. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  333. pipe := []bson.M{
  334. {"$match": bson.M{"loginTime.loginTime": bson.M{"$gte": startTime, "$lte": endTime}}},
  335. {"$group": bson.M{"_id": bson.M{"serverId": "$loginTime.serverId", "uid": "$loginTime.uid"}, "count": bson.M{"$sum": 1}}},
  336. {"$project": bson.M{"serverId": "$_id.serverId", "uid": "$_id.uid", "count": 1}},
  337. }
  338. showInfoCursor, err := collection.Aggregate(context.TODO(), pipe)
  339. if err != nil {
  340. fmt.Println(err)
  341. }
  342. return showInfoCursor
  343. }
  344. func (m *Mgo) FindLiuCun(filter bson.D, serverId string) *mongo.Cursor {
  345. client := DB.Mongo
  346. if serverId == "" {
  347. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  348. //oppo:=bson.M{"register.openId": 1}
  349. singleResult, err := collection.Find(context.TODO(), filter)
  350. if err != nil {
  351. fmt.Println(err)
  352. }
  353. return singleResult
  354. } else {
  355. collection, _ := client.Database(m.database).Collection(m.collection + "_" + serverId).Clone()
  356. //oppo:=bson.M{"register.openId": 1}
  357. singleResult, err := collection.Find(context.TODO(), filter)
  358. if err != nil {
  359. fmt.Println(err)
  360. }
  361. return singleResult
  362. }
  363. }
  364. func (m *Mgo) FindHour(filter bson.D, page util.Page) *mongo.Cursor {
  365. client := DB.Mongo
  366. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  367. SORT := bson.D{{"_id", -1}} //1:升序; -1:降序
  368. findOptions := options.Find().SetSort(SORT).SetLimit(page.PageSize).SetSkip(gconv.Int64(page.PageSize * (page.CurrentPage - 1)))
  369. singleResult, err := collection.Find(context.TODO(), filter, findOptions)
  370. if err != nil {
  371. fmt.Println(err)
  372. }
  373. return singleResult
  374. }
  375. func (m *Mgo) GetDataByTimeDesc(filter bson.D, page util.Page) *mongo.Cursor {
  376. client := DB.Mongo
  377. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  378. SORT := bson.D{{"creatday", -1}} //1:升序; -1:降序
  379. findOptions := options.Find().SetSort(SORT).SetLimit(page.PageSize).SetSkip(gconv.Int64(page.PageSize * (page.CurrentPage - 1)))
  380. singleResult, err := collection.Find(context.TODO(), filter, findOptions)
  381. if err != nil {
  382. fmt.Println(err)
  383. }
  384. return singleResult
  385. }
  386. func (m *Mgo) GetDataByServerTimeDesc(filter bson.D, page util.Page, serverId string) *mongo.Cursor {
  387. client := DB.Mongo
  388. collection, _ := client.Database(m.database).Collection(m.collection + "_" + serverId).Clone()
  389. SORT := bson.D{{"creatday", -1}} //1:升序; -1:降序
  390. findOptions := options.Find().SetSort(SORT).SetLimit(page.PageSize).SetSkip(gconv.Int64(page.PageSize * (page.CurrentPage - 1)))
  391. singleResult, err := collection.Find(context.TODO(), filter, findOptions)
  392. if err != nil {
  393. fmt.Println(err)
  394. }
  395. return singleResult
  396. }
  397. func (m *Mgo) GetDataByServerTimeDesc2(filter bson.D, page util.Page, serverId string) *mongo.Cursor {
  398. client := DB.Mongo
  399. collection, _ := client.Database(m.database + serverId).Collection(m.collection).Clone()
  400. SORT := bson.D{{"time", -1}} //1:升序; -1:降序
  401. findOptions := options.Find().SetSort(SORT).SetLimit(page.PageSize).SetSkip(gconv.Int64(page.PageSize * (page.CurrentPage - 1)))
  402. singleResult, err := collection.Find(context.TODO(), filter, findOptions)
  403. if err != nil {
  404. fmt.Println(err)
  405. }
  406. return singleResult
  407. }
  408. func (m *Mgo) FindHourByServer(filter bson.D, page util.Page, serverId string) *mongo.Cursor {
  409. client := DB.Mongo
  410. collection, _ := client.Database(m.database).Collection(m.collection + "_" + serverId).Clone()
  411. SORT := bson.D{{"_id", -1}} //1:升序; -1:降序
  412. findOptions := options.Find().SetSort(SORT).SetLimit(page.PageSize).SetSkip(gconv.Int64(page.PageSize * (page.CurrentPage - 1)))
  413. singleResult, err := collection.Find(context.TODO(), filter, findOptions)
  414. if err != nil {
  415. fmt.Println(err)
  416. }
  417. return singleResult
  418. }
  419. func (m *Mgo) FindListByServer(filter bson.D, serverId string) *mongo.Cursor {
  420. client := DB.Mongo
  421. collection, _ := client.Database(m.database).Collection(m.collection + "_" + serverId).Clone()
  422. singleResult, err := collection.Find(context.TODO(), filter)
  423. if err != nil {
  424. fmt.Println(err)
  425. }
  426. return singleResult
  427. }
  428. func (m *Mgo) FindUser(filter bson.D, serverId string) *mongo.Cursor {
  429. client := DB.Mongo
  430. collection, _ := client.Database(m.database + serverId).Collection(m.collection).Clone()
  431. //oppo:=bson.M{"register.openId": 1}
  432. singleResult, err := collection.Find(context.TODO(), filter)
  433. if err != nil {
  434. fmt.Println(err)
  435. }
  436. return singleResult
  437. }
  438. func (m *Mgo) FindLV(serverId string) *mongo.Cursor {
  439. client := DB.Mongo
  440. collection, _ := client.Database(m.database + serverId).Collection(m.collection).Clone()
  441. pipe := []bson.M{
  442. {"$group": bson.M{"_id": "$playerManager.level", "value": bson.M{"$sum": 1}}},
  443. {"$sort": bson.M{"_id": 1}},
  444. }
  445. showInfoCursor, err := collection.Aggregate(context.TODO(), pipe)
  446. if err != nil {
  447. fmt.Println(err)
  448. }
  449. return showInfoCursor
  450. }
  451. func (m *Mgo) FindVIP(serverId string) *mongo.Cursor {
  452. client := DB.Mongo
  453. collection, _ := client.Database(m.database + serverId).Collection(m.collection).Clone()
  454. pipe := []bson.M{
  455. {"$group": bson.M{"_id": "$playerManager.vipLevel", "value": bson.M{"$sum": 1}}},
  456. {"$sort": bson.M{"_id": 1}},
  457. }
  458. showInfoCursor, err := collection.Aggregate(context.TODO(), pipe)
  459. if err != nil {
  460. fmt.Println(err)
  461. }
  462. return showInfoCursor
  463. }
  464. func (m *Mgo) FindServerInfoList(filter bson.D) *mongo.Cursor {
  465. client := DB.Mongo
  466. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  467. singleResult, err := collection.Find(context.TODO(), filter)
  468. if err != nil {
  469. fmt.Println(err)
  470. }
  471. return singleResult
  472. }
  473. // 新增服务器信息
  474. func (m *Mgo) AddServer(value interface{}) *mongo.InsertOneResult {
  475. client := DB.Mongo
  476. collection := client.Database(m.database).Collection(m.collection)
  477. insertResult, err := collection.InsertOne(context.TODO(), value)
  478. if err != nil {
  479. fmt.Println(err)
  480. }
  481. return insertResult
  482. }
  483. // 更新服务器信息
  484. func (m *Mgo) UpdateServer(id int, value interface{}) *mongo.UpdateResult {
  485. serverInfo := gconv.Map(value)
  486. client := DB.Mongo
  487. collection := client.Database(m.database).Collection(m.collection)
  488. filter := bson.D{{"_id", id}}
  489. update := bson.D{{"$set", bson.D{
  490. {"name", gconv.String(serverInfo["Name"])},
  491. {"ip", gconv.String(serverInfo["Ip"])},
  492. {"port", gconv.String(serverInfo["Port"])},
  493. {"plat", gconv.String(serverInfo["Plat"])},
  494. {"state", gconv.String(serverInfo["State"])},
  495. {"open_time", gconv.String(serverInfo["OpenTime"])},
  496. {"open_type", gconv.String(serverInfo["OpenType"])},
  497. {"is_banreg", gconv.String(serverInfo["IsBanreg"])},
  498. {"is_new", gconv.String(serverInfo["IsNew"])},
  499. {"server_version", gconv.String(serverInfo["ServerVersion"])},
  500. {"gm_ip", gconv.String(serverInfo["GMIp"])},
  501. {"gm_port", gconv.String(serverInfo["GMPort"])},
  502. {"isWhite", gconv.String(serverInfo["IsWhite"])},
  503. {"currency", gconv.String(serverInfo["Currency"])},
  504. {"time_zone", gconv.String(serverInfo["Timezone"])},
  505. {"exportdata", gconv.String(serverInfo["Exportdata"])},
  506. }}}
  507. updateResult, err := collection.UpdateOne(context.TODO(), filter, update)
  508. fmt.Println(updateResult)
  509. if err != nil {
  510. fmt.Println(err)
  511. }
  512. return updateResult
  513. }
  514. func (m *Mgo) DelServer(filter bson.D) *mongo.DeleteResult {
  515. client := DB.Mongo
  516. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  517. deleteResult, err := collection.DeleteOne(context.TODO(), filter)
  518. if err != nil {
  519. fmt.Println(err)
  520. }
  521. return deleteResult
  522. }
  523. //白名单列表
  524. func (m *Mgo) FindWhiteList(filter bson.D, page util.Page) *mongo.Cursor {
  525. client := DB.Mongo
  526. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  527. SORT := bson.D{{"_id", -1}} //1:升序; -1:降序
  528. findOptions := options.Find().SetSort(SORT).SetLimit(page.PageSize).SetSkip(gconv.Int64(page.PageSize * (page.CurrentPage - 1)))
  529. singleResult, err := collection.Find(context.TODO(), filter, findOptions)
  530. if err != nil {
  531. fmt.Println(err)
  532. }
  533. return singleResult
  534. }
  535. //黑名单列表
  536. func (m *Mgo) FindBlackList(filter bson.D, page util.Page) *mongo.Cursor {
  537. client := DB.Mongo
  538. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  539. SORT := bson.D{{"_id", -1}} //1:升序; -1:降序
  540. findOptions := options.Find().SetSort(SORT).SetLimit(page.PageSize).SetSkip(gconv.Int64(page.PageSize * (page.CurrentPage - 1)))
  541. singleResult, err := collection.Find(context.TODO(), filter, findOptions)
  542. if err != nil {
  543. fmt.Println(err)
  544. }
  545. return singleResult
  546. }
  547. //新增、更新单个
  548. func (m *Mgo) AddWhiteList(id int, value interface{}) *mongo.UpdateResult {
  549. client := DB.Mongo
  550. collection := client.Database(m.database).Collection(m.collection)
  551. filter := bson.D{{"_id", id}}
  552. update := bson.D{{"$set", value}}
  553. fmt.Println(value)
  554. options1 := options.Update().SetUpsert(true)
  555. updateResult, err := collection.UpdateOne(context.TODO(), filter, update, options1)
  556. fmt.Println(updateResult)
  557. if err != nil {
  558. fmt.Println(err)
  559. }
  560. return updateResult
  561. }
  562. //新增、更新单个
  563. func (m *Mgo) AddBlackList(id string, openid string, value interface{}) int {
  564. res := 1
  565. client := DB.Mongo
  566. collection := client.Database(m.database).Collection(m.collection)
  567. //如果id为空 添加
  568. if id == "" {
  569. insertResult, err := collection.InsertOne(context.TODO(), value)
  570. fmt.Println(insertResult)
  571. if err != nil {
  572. res = 0
  573. fmt.Println(err)
  574. }
  575. } else {
  576. obj_id, _ := primitive.ObjectIDFromHex(id)
  577. filter := bson.D{{"_id", obj_id}}
  578. update := bson.D{{"$set", value}}
  579. //options1 := options.Update().SetUpsert(true)
  580. updateResult, err := collection.UpdateOne(context.TODO(), filter, update)
  581. fmt.Println(updateResult)
  582. if err != nil {
  583. res = 0
  584. fmt.Println(err)
  585. }
  586. }
  587. return res
  588. }
  589. func (m *Mgo) DelWhiteList(filter bson.D) *mongo.DeleteResult {
  590. client := DB.Mongo
  591. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  592. deleteResult, err := collection.DeleteOne(context.TODO(), filter)
  593. if err != nil {
  594. fmt.Println(err)
  595. }
  596. return deleteResult
  597. }
  598. func (m *Mgo) DelBlackList(filter bson.D) *mongo.DeleteResult {
  599. client := DB.Mongo
  600. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  601. deleteResult, err := collection.DeleteOne(context.TODO(), filter)
  602. if err != nil {
  603. fmt.Println(err)
  604. }
  605. return deleteResult
  606. }
  607. //公告
  608. func (m *Mgo) FindNoticeInfo(filter bson.D) *mongo.Cursor {
  609. client := DB.Mongo
  610. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  611. singleResult, err := collection.Find(context.TODO(), filter)
  612. if err != nil {
  613. fmt.Println(err)
  614. }
  615. return singleResult
  616. }
  617. //新增、更新单个
  618. func (m *Mgo) AddNoticeInfo(id string, value interface{}) *mongo.UpdateResult {
  619. client := DB.Mongo
  620. collection := client.Database(m.database).Collection(m.collection)
  621. filter := bson.D{{"_id", id}}
  622. update := bson.D{{"$set", value}}
  623. fmt.Println(value)
  624. options1 := options.Update().SetUpsert(true)
  625. updateResult, err := collection.UpdateOne(context.TODO(), filter, update, options1)
  626. fmt.Println(updateResult)
  627. if err != nil {
  628. fmt.Println(err)
  629. }
  630. return updateResult
  631. }
  632. func (m *Mgo) DelNoticeInfo(filter bson.D) *mongo.DeleteResult {
  633. client := DB.Mongo
  634. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  635. deleteResult, err := collection.DeleteOne(context.TODO(), filter)
  636. if err != nil {
  637. fmt.Println(err)
  638. }
  639. return deleteResult
  640. }
  641. func (m *Mgo) FindRechargeInfo(filter bson.D, serverId string) *mongo.Cursor {
  642. client := DB.Mongo
  643. collection, _ := client.Database(m.database + serverId).Collection(m.collection).Clone()
  644. singleResult, err := collection.Find(context.TODO(), filter)
  645. if err != nil {
  646. fmt.Println("err==================", err)
  647. }
  648. return singleResult
  649. }
  650. //查询一天的注册/登录人数 例:creatDay = "2021-06-08"
  651. func (m *Mgo) GetOneDayRegister(creatDay string) int {
  652. client := DB.Mongo
  653. sum := 0
  654. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  655. matchStage := bson.D{{"$match", bson.D{{"creatday", creatDay}}}}
  656. groupStage := bson.D{{"$group", bson.D{
  657. {"_id", "$creatday"},
  658. {"sum", bson.D{{"$sum", "$newuser"}}},
  659. }}}
  660. singleResult, err := collection.Aggregate(context.TODO(), mongo.Pipeline{matchStage, groupStage})
  661. if err != nil {
  662. fmt.Println(err)
  663. }
  664. var showsWithInfo []bson.M
  665. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  666. fmt.Println(err)
  667. }
  668. for _, b := range showsWithInfo {
  669. sum = sum + gconv.Int(b["sum"])
  670. }
  671. return sum
  672. }
  673. func (m *Mgo) GetOneDayRegisterByServer(creatDay string, serverId string) int {
  674. client := DB.Mongo
  675. sum := 0
  676. collection, _ := client.Database(m.database).Collection(m.collection + "_" + serverId).Clone()
  677. matchStage := bson.D{{"$match", bson.D{{"creatday", creatDay}}}}
  678. groupStage := bson.D{{"$group", bson.D{
  679. {"_id", "$creatday"},
  680. {"sum", bson.D{{"$sum", "$newuser"}}},
  681. }}}
  682. singleResult, err := collection.Aggregate(context.TODO(), mongo.Pipeline{matchStage, groupStage})
  683. if err != nil {
  684. fmt.Println(err)
  685. }
  686. var showsWithInfo []bson.M
  687. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  688. fmt.Println(err)
  689. }
  690. for _, b := range showsWithInfo {
  691. sum = sum + gconv.Int(b["sum"])
  692. }
  693. return sum
  694. }
  695. //查询注册账号数
  696. func (m *Mgo) GetOneDayRegisterAccount(creatDay string, serverId string) int {
  697. client := DB.Mongo
  698. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  699. startTime := gtime.NewFromStr(creatDay)
  700. //时间范围
  701. daystartTime := startTime.Local().TimestampMilli()
  702. dayendTime := startTime.Clone().AddDate(0, 0, 1).Local().TimestampMilli() - 1
  703. //注册时间条件
  704. pipe := []bson.M{}
  705. if serverId == "" {
  706. pipe = []bson.M{
  707. {"$match": bson.M{"register.registerTime": bson.M{"$gte": daystartTime, "$lte": dayendTime}}},
  708. {"$group": bson.M{"_id": bson.M{"openId": "$register.openId"}, "count": bson.M{"$sum": 1}}},
  709. {"$project": bson.M{"openId": "$_id.openId", "count": 1}},
  710. }
  711. } else {
  712. pipe = []bson.M{
  713. {"$match": bson.M{"register.serverId": serverId, "register.registerTime": bson.M{"$gte": daystartTime, "$lte": dayendTime}}},
  714. {"$group": bson.M{"_id": bson.M{"openId": "$register.openId"}, "count": bson.M{"$sum": 1}}},
  715. {"$project": bson.M{"openId": "$_id.openId", "count": 1}},
  716. }
  717. }
  718. showInfoCursor, err := collection.Aggregate(context.TODO(), pipe)
  719. if err != nil {
  720. fmt.Println(err)
  721. }
  722. var showsWithInfo []bson.M
  723. if err = showInfoCursor.All(context.TODO(), &showsWithInfo); err != nil {
  724. fmt.Println(err)
  725. }
  726. return len(showsWithInfo)
  727. }
  728. func (m *Mgo) GetLoginNum(filter bson.D) int {
  729. sum := 0
  730. client := DB.Mongo
  731. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  732. singleResult, err := collection.Find(context.TODO(), filter)
  733. if err != nil {
  734. fmt.Println(err)
  735. }
  736. var showsWithInfo []bson.M
  737. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  738. fmt.Println(err)
  739. }
  740. for _, b := range showsWithInfo {
  741. sum = sum + gconv.Int(b["newuser"])
  742. }
  743. return sum
  744. }
  745. //获得当天老用户登录数(当天登录人数-当天注册人数)
  746. func (m *Mgo) GetOldUserLoginNum(creatDay string) int {
  747. client := DB.Mongo
  748. startTime := gtime.NewFromStr(creatDay)
  749. //时间范围
  750. daystartTime := startTime.Local().TimestampMilli()
  751. dayendTime := startTime.Clone().AddDate(0, 0, 1).Local().TimestampMilli() - 1
  752. //注册时间条件
  753. filter := bson.D{{"register.registerTime", bson.D{{"$gte", daystartTime}, {"$lte", dayendTime}}}}
  754. var findoptions *options.FindOptions
  755. collection, _ := client.Database(g.Config().GetString("db.core")).Collection("logRegister").Clone()
  756. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  757. if err != nil {
  758. fmt.Println(err)
  759. }
  760. var showsWithInfo []bson.M
  761. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  762. fmt.Println(err)
  763. }
  764. list := garray.New(false)
  765. //遍历加入注册用户集合
  766. for _, b := range showsWithInfo {
  767. s2 := b["register"].(primitive.M)
  768. list.Append(s2["uid"])
  769. }
  770. //fmt.Println("注册=======================", list)
  771. usersList := gconv.SliceAny(list)
  772. collection1, _ := client.Database(g.Config().GetString("db.core")).Collection("logLogin").Clone()
  773. //查询登录用户条件
  774. filter1 := bson.D{
  775. {"loginTime.loginTime", bson.D{{"$gte", daystartTime}, {"$lte", dayendTime}}},
  776. {"loginTime.uid", bson.M{"$nin": gconv.Ints(usersList)}}}
  777. var findoptions1 *options.FindOptions
  778. singleResult1, err := collection1.Find(context.TODO(), filter1, findoptions1)
  779. if err != nil {
  780. fmt.Println(err)
  781. }
  782. var showsWithInfo1 []bson.M
  783. if err = singleResult1.All(context.TODO(), &showsWithInfo1); err != nil {
  784. fmt.Println(err)
  785. }
  786. list1 := garray.New(false)
  787. for _, b := range showsWithInfo1 {
  788. s2 := b["loginTime"].(primitive.M)
  789. if list1.Contains(s2["uid"]) {
  790. continue
  791. }
  792. list1.Append(s2["uid"])
  793. }
  794. //fmt.Println("登录=======================",list1)
  795. return list1.Len()
  796. }
  797. func (m *Mgo) GetOldUserLoginNumByServer(creatDay string, serverId string) int {
  798. client := DB.Mongo
  799. startTime := gtime.NewFromStr(creatDay)
  800. //时间范围
  801. daystartTime := startTime.Local().TimestampMilli()
  802. dayendTime := startTime.Clone().AddDate(0, 0, 1).Local().TimestampMilli() - 1
  803. //注册时间条件
  804. filter := bson.D{
  805. {"register.serverId", serverId},
  806. {"register.registerTime", bson.D{{"$gte", daystartTime}, {"$lte", dayendTime}}},
  807. }
  808. var findoptions *options.FindOptions
  809. collection, _ := client.Database(g.Config().GetString("db.core")).Collection("logRegister").Clone()
  810. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  811. if err != nil {
  812. fmt.Println(err)
  813. }
  814. var showsWithInfo []bson.M
  815. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  816. fmt.Println(err)
  817. }
  818. list := garray.New(false)
  819. //遍历加入注册用户集合
  820. for _, b := range showsWithInfo {
  821. s2 := b["register"].(primitive.M)
  822. list.Append(s2["uid"])
  823. }
  824. //fmt.Println("注册=======================", list)
  825. usersList := gconv.SliceAny(list)
  826. collection1, _ := client.Database(g.Config().GetString("db.core")).Collection("logLogin").Clone()
  827. //查询登录用户条件
  828. filter1 := bson.D{
  829. {"loginTime.serverId", serverId},
  830. {"loginTime.loginTime", bson.D{{"$gte", daystartTime}, {"$lte", dayendTime}}},
  831. {"loginTime.uid", bson.M{"$nin": gconv.Ints(usersList)}}}
  832. var findoptions1 *options.FindOptions
  833. singleResult1, err := collection1.Find(context.TODO(), filter1, findoptions1)
  834. if err != nil {
  835. fmt.Println(err)
  836. }
  837. var showsWithInfo1 []bson.M
  838. if err = singleResult1.All(context.TODO(), &showsWithInfo1); err != nil {
  839. fmt.Println(err)
  840. }
  841. list1 := garray.New(false)
  842. for _, b := range showsWithInfo1 {
  843. s2 := b["loginTime"].(primitive.M)
  844. if list1.Contains(s2["uid"]) {
  845. continue
  846. }
  847. list1.Append(s2["uid"])
  848. }
  849. //fmt.Println("登录=======================",list1)
  850. return list1.Len()
  851. }
  852. func (m *Mgo) GetPayInfoTask(filter bson.D) *mongo.Cursor {
  853. client := DB.Mongo
  854. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  855. singleResult, err := collection.Find(context.TODO(), filter)
  856. if err != nil {
  857. fmt.Println(err)
  858. }
  859. return singleResult
  860. }
  861. //插入单个
  862. func (m *Mgo) InsertOneByServer(value interface{}, serverId string) *mongo.InsertOneResult {
  863. client := DB.Mongo
  864. collection := client.Database(m.database).Collection(m.collection + "_" + serverId)
  865. insertResult, err := collection.InsertOne(context.TODO(), value)
  866. if err != nil {
  867. fmt.Println(err)
  868. }
  869. return insertResult
  870. }
  871. // 添加修改 统计充值汇总
  872. func (m *Mgo) InsertAndUpdateStatisticalRecharge(id primitive.ObjectID, value interface{}, serverId string) *mongo.UpdateResult {
  873. statisticalRecharge := gconv.Map(value)
  874. client := DB.Mongo
  875. filter := bson.D{{"_id", id}}
  876. update := bson.D{{"$set", bson.D{
  877. {"creatday", gconv.String(statisticalRecharge["creatday"])},
  878. {"new_recharge_num", gconv.Int32(statisticalRecharge["newrechargenum"])},
  879. {"new_recharge_amount", gconv.Float64(statisticalRecharge["newrechargeamount"])},
  880. {"new_recharge_count", gconv.Int32(statisticalRecharge["newrechargecount"])},
  881. {"recharge_num", gconv.Int32(statisticalRecharge["rechargenum"])},
  882. {"recharge_amount", gconv.Float64(statisticalRecharge["rechargeamount"])},
  883. {"recharge_count", gconv.Int32(statisticalRecharge["rechargecount"])},
  884. }}}
  885. options := options.Update().SetUpsert(true)
  886. if serverId == "" {
  887. collection := client.Database(m.database).Collection(m.collection)
  888. updateResult, err := collection.UpdateOne(context.TODO(), filter, update, options)
  889. if err != nil {
  890. fmt.Println(err)
  891. }
  892. return updateResult
  893. } else {
  894. collection := client.Database(m.database).Collection(m.collection + "_" + serverId)
  895. updateResult, err := collection.UpdateOne(context.TODO(), filter, update, options)
  896. if err != nil {
  897. fmt.Println(err)
  898. }
  899. return updateResult
  900. }
  901. }
  902. // pay表 取符合条件的服务器id
  903. func (m *Mgo) GetPayServerId(filter bson.D) *mongo.Cursor {
  904. client := DB.Mongo
  905. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  906. pipe := []bson.M{
  907. {"$match": filter},
  908. {"$group": bson.M{"_id": bson.M{"region": "$region"}}},
  909. {"$project": bson.M{"region": "$_id.region"}},
  910. }
  911. showInfoCursor, err := collection.Aggregate(context.TODO(), pipe)
  912. if err != nil {
  913. fmt.Println(err)
  914. }
  915. return showInfoCursor
  916. }
  917. //查询当日新增玩家累计付费信息
  918. func (m *Mgo) GetTodayNewCumulativeRecharge(todayUsers []interface{}, creatDay string, serverid string) interface{} {
  919. amount, count, num := 0, 0, 0
  920. resMap := gmap.New()
  921. userList := garray.New(false)
  922. todayBs := bson.D{}
  923. if serverid == "" {
  924. todayBs = bson.D{
  925. {"uid", bson.M{"$in": gconv.Ints(todayUsers)}},
  926. {"status", gconv.Int32(1)},
  927. {"handlestatus", gconv.Int32(1)},
  928. {"creattime", bson.D{{"$lte", creatDay + " 23:59:59"}}}}
  929. } else {
  930. todayBs = bson.D{
  931. {"uid", bson.M{"$in": gconv.Ints(todayUsers)}},
  932. {"status", gconv.Int32(1)},
  933. {"handlestatus", gconv.Int32(1)},
  934. {"region", gconv.Int32(serverid)},
  935. {"creattime", bson.D{{"$lte", creatDay + " 23:59:59"}}}}
  936. }
  937. client := DB.Mongo
  938. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  939. singleResult, err := collection.Find(context.TODO(), todayBs)
  940. if err != nil {
  941. fmt.Println(err)
  942. }
  943. var showsWithInfo []bson.M
  944. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  945. fmt.Println(err)
  946. }
  947. for _, v := range showsWithInfo {
  948. if !userList.Contains(v["uid"]) {
  949. num = num + 1
  950. }
  951. userList.Append(v["uid"])
  952. count = count + 1
  953. amount = amount + gconv.Int(v["money"])
  954. }
  955. resMap.Set("amount", amount)
  956. resMap.Set("count", count)
  957. resMap.Set("num", num)
  958. return resMap
  959. }
  960. func (m *Mgo) GetLtvStatistical(startTime string, endTime string, roles interface{}, serverId string) int64 {
  961. var res int64
  962. res = 0
  963. client := DB.Mongo
  964. collection, _ := client.Database(m.database).Collection(m.collection).Clone()
  965. filter := bson.D{}
  966. if (serverId == "") {
  967. filter = bson.D{
  968. {"creattime", bson.D{{"$gte", startTime}, {"$lte", endTime}}},
  969. {"uid", bson.M{"$in": roles}},
  970. {"status", gconv.Int32(1)},
  971. {"handlestatus", gconv.Int32(1)},
  972. }
  973. } else {
  974. filter = bson.D{
  975. {"creattime", bson.D{{"$gte", startTime}, {"$lte", endTime}}},
  976. {"uid", bson.M{"$in": roles}},
  977. {"region", gconv.Int32(serverId)},
  978. {"status", gconv.Int32(1)},
  979. {"handlestatus", gconv.Int32(1)},
  980. }
  981. }
  982. var findoptions *options.FindOptions
  983. singleResult, err := collection.Find(context.TODO(), filter, findoptions)
  984. if err != nil {
  985. fmt.Println(err)
  986. }
  987. var showsWithInfo []bson.M
  988. if err = singleResult.All(context.TODO(), &showsWithInfo); err != nil {
  989. fmt.Println(err)
  990. }
  991. for _, b := range showsWithInfo {
  992. res = res + (gconv.Int64(b["money"]))
  993. }
  994. return res
  995. }
  996. func (m *Mgo) FindUserList(filter bson.M, serverId string, projection bson.M) *mongo.Cursor {
  997. client := DB.Mongo
  998. collection, _ := client.Database(m.database + serverId).Collection(m.collection).Clone()
  999. //oppo:=bson.M{"register.openId": 1}
  1000. options := options.Find().SetProjection(projection)
  1001. singleResult, err := collection.Find(context.TODO(), filter,options)
  1002. if err != nil {
  1003. fmt.Println(err)
  1004. }
  1005. return singleResult
  1006. }