HttpSocket.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. #include "pch.h"
  2. #include "HttpSocket.h"
  3. #include <set>
  4. #include <chrono>
  5. #include <ctime>
  6. #include <iomanip>
  7. #include <sstream>
  8. #include <string>
  9. #include <utility>
  10. using namespace bsoncxx::builder::basic;
  11. using namespace chrono;
  12. mongocxx::instance g_instance{};
  13. HttpSocket::HttpSocket()
  14. {
  15. __int64 itime = funclib::gettimestamp();
  16. m_random = default_random_engine(itime);
  17. m_pmsgservice = boost::make_shared<boost::asio::io_context>();
  18. m_pmsgwork = boost::make_shared<boost::asio::io_context::work>(*m_pmsgservice);
  19. data_time = boost::make_shared<boost::asio::deadline_timer>(*m_pmsgservice);
  20. //数据库配置
  21. string strip = funclib::getdatainfo();
  22. //strip = "mongodb://datzahndle:pajdt873hyu3h37@110.40.64.236:37317";
  23. //strip = "mongodb://110.40.59.112:37317";
  24. //strip = "mongodb://192.168.0.220:27017";
  25. m_puri = boost::make_shared<mongocxx::uri>(strip.c_str());
  26. m_pclient = boost::make_shared <mongocxx::client>(*m_puri);
  27. m_pdb = boost::make_shared<mongocxx::database>();
  28. m_platform = boost::make_shared<mongocxx::database>();
  29. m_gamelog = boost::make_shared<mongocxx::database>();
  30. m_pvipuserdb = boost::make_shared<mongocxx::database>();
  31. m_ptask = boost::make_shared<mongocxx::database>();
  32. m_viplog = boost::make_shared<mongocxx::database>();
  33. m_webdata = boost::make_shared<mongocxx::database>();
  34. m_pallindex = boost::make_shared<mongocxx::collection>();
  35. m_pcoll = boost::make_shared<mongocxx::collection>();
  36. m_plosewincoll = boost::make_shared<mongocxx::collection>();
  37. m_pvipuser = boost::make_shared<mongocxx::collection>();
  38. m_pplayuseronline = boost::make_shared<mongocxx::collection>();
  39. m_userloginonline = boost::make_shared<mongocxx::collection>();
  40. m_pusertradeinfo = boost::make_shared<mongocxx::collection>();
  41. m_pviptradeinfo = boost::make_shared<mongocxx::collection>();
  42. m_poperatinfo = boost::make_shared<mongocxx::collection>();
  43. m_pgameviploginfo = boost::make_shared<mongocxx::collection>();
  44. m_pgameserverloginfo = boost::make_shared<mongocxx::collection>();
  45. m_pvipalllogcache = boost::make_shared<mongocxx::collection>();
  46. m_pserverlogcache = boost::make_shared<mongocxx::collection>();
  47. m_puserlogcache = boost::make_shared<mongocxx::collection>();
  48. m_pgameuserloginfo = boost::make_shared<mongocxx::collection>();
  49. m_pviplogcache = boost::make_shared<mongocxx::collection>();
  50. m_pgameprizelog = boost::make_shared<mongocxx::collection>();
  51. m_puserdowninfo = boost::make_shared<mongocxx::collection>();
  52. m_pvipscore = boost::make_shared<mongocxx::collection>();
  53. m_pvipscoredate = boost::make_shared<mongocxx::collection>();
  54. m_pvipuseraccounts = boost::make_shared<mongocxx::collection>();
  55. m_puserdatainfo = boost::make_shared<mongocxx::collection>();
  56. m_pvipconfigure = boost::make_shared<mongocxx::collection>();
  57. m_pusersub = boost::make_shared<mongocxx::collection>();
  58. m_pexechangerate = boost::make_shared<mongocxx::collection>();
  59. m_pthreeadmin = boost::make_shared<mongocxx::collection>();
  60. m_pconfig = boost::make_shared<mongocxx::collection>();
  61. m_pkinditem = boost::make_shared<mongocxx::collection>();
  62. m_pipwhite = boost::make_shared<mongocxx::collection>();
  63. m_papplyviplog = boost::make_shared<mongocxx::collection>();
  64. m_pvipmsglog = boost::make_shared<mongocxx::collection>();
  65. m_pgamelist = boost::make_shared<mongocxx::collection>();
  66. m_pgamegameitem = boost::make_shared<mongocxx::collection>();
  67. m_ppopularizesit = boost::make_shared<mongocxx::collection>();
  68. m_activityfreegame = boost::make_shared<mongocxx::collection>();
  69. m_pmarquee = boost::make_shared<mongocxx::collection>();
  70. m_pcustomerlink = boost::make_shared<mongocxx::collection>();
  71. m_pcredittopwinner = boost::make_shared<mongocxx::collection>();
  72. m_resendorder = boost::make_shared<mongocxx::collection>();
  73. m_pareagames = boost::make_shared<mongocxx::collection>();
  74. m_pplayrecordini = boost::make_shared<mongocxx::collection>();
  75. m_pgamebet = boost::make_shared<mongocxx::collection>();
  76. m_pactivityini = boost::make_shared<mongocxx::collection>();
  77. m_pplatformini = boost::make_shared<mongocxx::collection>();
  78. m_pthirddeveloper = boost::make_shared<mongocxx::collection>();
  79. m_pthirdgames = boost::make_shared<mongocxx::collection>();
  80. m_pgameprizelog = boost::make_shared<mongocxx::collection>();
  81. *m_pdb = (*m_pclient)["accounts"];
  82. *m_platform = (*m_pclient)["platform"];
  83. *m_gamelog = (*m_pclient)["gamelog"];
  84. *m_ptask = (*m_pclient)["task"];
  85. *m_viplog = (*m_pclient)["viplog"];
  86. *m_webdata = (*m_pclient)["webdata"];
  87. *m_pvipuserdb = (*m_pclient)["vipuser"];
  88. *m_pallindex = (*m_pdb)["allindex"];
  89. *m_pcoll = (*m_pdb)["userinfo"];
  90. *m_plosewincoll = (*m_pdb)["losewin"];
  91. *m_pvipuser = (*m_pvipuserdb)["user"];
  92. *m_pplayuseronline = (*m_gamelog)["playuseronline"];
  93. *m_userloginonline = (*m_gamelog)["userloginonline"];
  94. *m_poperatinfo = (*m_gamelog)["operatinfo"];
  95. *m_puserdowninfo = (*m_gamelog)["userdowninfo"];
  96. *m_pusertradeinfo = (*m_pvipuserdb)["usertradeinfo"];
  97. *m_pgameviploginfo = (*m_gamelog)["gameviploginfo"];
  98. *m_pgameserverloginfo = (*m_gamelog)["gameserverloginfo"];
  99. *m_pvipalllogcache = (*m_gamelog)["vipalllogcache"];
  100. *m_pserverlogcache = (*m_gamelog)["serverlogcache"];
  101. *m_puserlogcache = (*m_gamelog)["userlogcache"];
  102. *m_pgameuserloginfo = (*m_gamelog)["gameuserloginfo"];
  103. *m_pviplogcache = (*m_gamelog)["viplogcache"];
  104. *m_pgameprizelog = (*m_gamelog)["gameprizelog"];
  105. *m_resendorder = (*m_gamelog)["resendorder"];
  106. *m_pviptradeinfo = (*m_pvipuserdb)["viptradeinfo"];
  107. *m_pvipscore = (*m_pvipuserdb)["vipscore"];
  108. *m_pvipscoredate = (*m_pvipuserdb)["vipscoredate"];
  109. *m_pvipuseraccounts = (*m_pvipuserdb)["vipuseraccounts"];
  110. *m_puserdatainfo = (*m_gamelog)["userdatainfo"];
  111. *m_pvipconfigure = (*m_pvipuserdb)["vipconfigure"];
  112. *m_pthreeadmin = (*m_pvipuserdb)["threeadmin"];
  113. *m_pusersub = (*m_pvipuserdb)["usersub"];
  114. *m_pexechangerate = (*m_platform)["exechangerate"];
  115. *m_pkinditem = (*m_platform)["kinditem"];
  116. *m_pgamelist = (*m_platform)["gamelist"];
  117. *m_pgamegameitem = (*m_platform)["gamegameitem"];
  118. *m_ppopularizesit = (*m_pvipuserdb)["popularizesit"]; // 推广网站
  119. *m_pmarquee = (*m_pvipuserdb)["marquee"]; // 信用代理跑马灯
  120. *m_pcustomerlink = (*m_pvipuserdb)["customerlink"];
  121. *m_pcredittopwinner = (*m_gamelog)["credittopwinner"];
  122. *m_pplatformini = (*m_platform)["platformini"];
  123. //task
  124. *m_pconfig = (*m_ptask)["config"];
  125. *m_pipwhite = (*m_pvipuserdb)["ipwhite"];
  126. //viplog
  127. *m_papplyviplog = (*m_viplog)["applyviplog"];
  128. *m_pvipmsglog = (*m_viplog)["vipmsglog"];
  129. //freegame
  130. *m_activityfreegame = (*m_pvipuserdb)["freegameactivity"];
  131. //areagame
  132. *m_pareagames = (*m_platform)["areagames"];
  133. *m_pplayrecordini = (*m_platform)["playrecordini"];
  134. // 游戏投注配置
  135. *m_pgamebet = (*m_platform)["gamebet"];
  136. // 游戏活动配置
  137. *m_pactivityini = (*m_webdata)["activeini"];
  138. // 第三方厂商
  139. *m_pthirddeveloper = (*m_platform)["thirddeveloper"];
  140. // 第三方厂商游戏
  141. *m_pthirdgames = (*m_platform)["thirdgames"];
  142. m_strshahead = "X-REQUEST-SIGN";
  143. m_strshaheadcontent = "6e4c91001979851a97c2b5360f044ff67b48e186d6ecd4394532851bffdeeae9";
  144. m_psendhttp = weblib::httpini();
  145. m_brun = false;
  146. m_msgthread = thread([this] {
  147. m_ucurid = funclib::getcurid();
  148. m_brun = true;
  149. m_pmsgservice->run();
  150. m_brun = false;
  151. });
  152. m_msgthread.detach();
  153. while (!m_brun)
  154. {
  155. this_thread::yield();
  156. }
  157. }
  158. HttpSocket::~HttpSocket()
  159. {
  160. }
  161. // 毫秒时间戳 → ISO-8601 UTC 时间字符串
  162. string to_iso8601_utc_string(chrono::system_clock::time_point tp)
  163. {
  164. auto ms = duration_cast<milliseconds>(tp.time_since_epoch()) % 1000;
  165. time_t t = system_clock::to_time_t(tp);
  166. tm tm = *gmtime(&t);
  167. ostringstream oss;
  168. oss << put_time(&tm, "%Y-%m-%d %H:%M:%S");
  169. oss << '.' << setfill('0') << setw(3) << ms.count();
  170. return oss.str();
  171. }
  172. struct stUserInfo
  173. {
  174. __int64 ispreaderid = 0;
  175. __int32 iareaid = 0;
  176. __int64 iuserid = 0;
  177. };
  178. static map<string, stUserInfo> map_acctouserinfo;
  179. void HttpSocket::init()
  180. {
  181. while (true)
  182. {
  183. static __int64 iLastTime = 0;
  184. if (funclib::gettimestamp() - iLastTime < 1000)
  185. this_thread::sleep_for(milliseconds(iLastTime + 1000 - funclib::gettimestamp()));
  186. auto tp = system_clock::time_point(milliseconds(funclib::gettimestamp()));
  187. auto secs = duration_cast<seconds>(tp.time_since_epoch()).count();
  188. auto isecondFrom = secs - 60;//上一分钟
  189. if (iLastTime == 0) // 第一次启动拉24小时
  190. {
  191. int64_t hour = secs / 3600;
  192. isecondFrom = (hour - 24) * 3600;
  193. }
  194. iLastTime = funclib::gettimestamp();
  195. auto prev_hour_tp = system_clock::time_point(seconds(isecondFrom));
  196. auto next_hour_tp = system_clock::time_point(seconds(secs + 60)); // 下一分钟
  197. string datafrom = to_iso8601_utc_string(prev_hour_tp);
  198. string datatto = to_iso8601_utc_string(next_hour_tp);
  199. getgamehistory(datafrom, datatto, 0);
  200. }
  201. }
  202. //拉取日志
  203. void HttpSocket::getgamehistory(string dataFrom, string dataTo, __int32 ifirstpage)
  204. {
  205. m_writelog("--------------------getgamehistory-------------------------");
  206. __int32 ipage = ifirstpage;
  207. __int32 inextpage = 0;
  208. __int32 ipagesize = 500;
  209. rapidjson::Document doc;
  210. doc.SetObject();
  211. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  212. doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
  213. doc.AddMember("page", ipage, allocator);
  214. doc.AddMember("size", ipagesize, allocator);
  215. doc.AddMember("dateFrom", rapidjson::Value(dataFrom.c_str(), allocator), allocator);
  216. doc.AddMember("dateTo", rapidjson::Value(dataTo.c_str(), allocator), allocator);
  217. string strjson = funclib::doctojson(doc);
  218. string strtarget = "v2/tw/getGameHistory";
  219. string stronlytoken = funclib::getonlytoken(1, m_ucurid);
  220. sendreelmsg(stronlytoken, strtarget, strjson, move([this, ipage, ipagesize, dataFrom, dataTo](string strdata, int iret) {
  221. if (iret == 200)
  222. {
  223. rettype::type tret{ rettype::type::ini };
  224. rapidjson::Document docdata;
  225. rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
  226. string stronlyid = "";
  227. string strgid = "";
  228. string straccount = "";
  229. string strroundData = "";
  230. string strgameResultUrl = "";
  231. string strcurrency = "";
  232. string strdbquestid = "";
  233. __int32 ibrandid = 2;
  234. __int64 iwinscore = 0;
  235. __int64 ibetscore = 0;
  236. double_t dwinmul = 0;
  237. if (ok)
  238. {
  239. rapidjson::Value arrbets(rapidjson::kArrayType);
  240. if (docdata.HasMember("records") && docdata["records"].IsArray())
  241. {
  242. arrbets = docdata["records"].GetArray();
  243. for (rapidjson::SizeType i = 0; i < arrbets.Size(); ++i)
  244. {
  245. const rapidjson::Value& recorditem = arrbets[i];
  246. if (!recorditem.IsObject())
  247. continue;
  248. if (!recorditem.HasMember("roundFinished") || !recorditem["roundFinished"].GetBool())
  249. continue;
  250. if (!recorditem.HasMember("id"))
  251. continue;
  252. if(!recorditem.HasMember("launchAlias"))
  253. continue;
  254. if (!recorditem.HasMember("playerId"))
  255. continue;
  256. if (!recorditem.HasMember("totalWin"))
  257. continue;
  258. if (!recorditem.HasMember("totalBet"))
  259. continue;
  260. if (!recorditem.HasMember("roundDate"))
  261. continue;
  262. if (!recorditem.HasMember("gameResultUrl"))
  263. continue;
  264. if(!recorditem.HasMember("currency"))
  265. continue;
  266. stronlyid = recorditem["id"].GetString();
  267. auto findrecord = make_document(kvp("onlyid", stronlyid.c_str()), kvp("brandid", ibrandid));
  268. auto result = m_pgameprizelog->find_one(findrecord.view());
  269. if (result)
  270. continue; // 重复
  271. straccount = recorditem["playerId"].GetString();
  272. stUserInfo stuserinfo = map_acctouserinfo[straccount];
  273. if (!stuserinfo.iuserid)
  274. {
  275. auto finduser = m_pcoll->find_one(make_document(kvp("account", straccount.c_str())));
  276. if (!finduser || !finduser->view()["userid"])
  277. continue;
  278. stuserinfo.iuserid = finduser->view()["userid"].get_int64();
  279. if(finduser->view()["spreaderid"])
  280. stuserinfo.ispreaderid = finduser->view()["spreaderid"].get_int64();
  281. if(finduser->view()["areaid"])
  282. stuserinfo.iareaid = finduser->view()["areaid"].get_int32();
  283. map_acctouserinfo[straccount] = stuserinfo;
  284. }
  285. iwinscore = static_cast<__int64>(std::stod(recorditem["totalWin"].GetString()) * 100);
  286. ibetscore = static_cast<__int64>(std::stod(recorditem["totalBet"].GetString()) * 100);
  287. dwinmul = iwinscore / ibetscore;
  288. strgid = recorditem["launchAlias"].GetString();
  289. strroundData = recorditem["roundDate"].GetString();
  290. strgameResultUrl = recorditem["gameResultUrl"].GetString();
  291. strcurrency = recorditem["currency"].GetString();
  292. document recorddoc;
  293. //convertJsonToBson(recorddoc, recorditem);
  294. recorddoc.append(kvp("onlyid", stronlyid.c_str()));
  295. recorddoc.append(kvp("dbquestid", stronlyid.c_str()));
  296. recorddoc.append(kvp("brandid", ibrandid));
  297. recorddoc.append(kvp("gid", strgid.c_str()));
  298. recorddoc.append(kvp("userid", stuserinfo.iuserid));
  299. recorddoc.append(kvp("areaid", stuserinfo.iareaid));
  300. recorddoc.append(kvp("spreaderid", stuserinfo.ispreaderid));
  301. recorddoc.append(kvp("roundDate", strroundData.c_str()));
  302. recorddoc.append(kvp("gameResultUrl", strgameResultUrl.c_str()));
  303. recorddoc.append(kvp("winscore", iwinscore));
  304. recorddoc.append(kvp("betscore", ibetscore));
  305. recorddoc.append(kvp("dwinmul", dwinmul));
  306. recorddoc.append(kvp("account", straccount.c_str()));
  307. recorddoc.append(kvp("currency", strcurrency.c_str()));
  308. recorddoc.append(kvp("scoretype", 1));
  309. recorddoc.append(kvp("inserttime", funclib::gettimestamp()));
  310. m_pgameprizelog->insert_one(recorddoc.view());
  311. }
  312. }
  313. if (docdata.HasMember("total") && (ipage + 1) * ipagesize < docdata["total"].GetInt())
  314. getgamehistory(dataFrom, dataTo, ipage+1);
  315. }
  316. }
  317. }));
  318. }
  319. void HttpSocket::sendreelmsg(string stronly, string strtarget, string strjson, function<void(string, int)>&& dofun)
  320. {
  321. weblib::httpinfo thttpinfo;
  322. thttpinfo.strurl = "https://transfer-wallet-service.stage.iconic-21.com";
  323. // thttpinfo.strurl = "http://127.0.0.1:6000";
  324. thttpinfo.strtarget = strtarget;
  325. thttpinfo.stronly = stronly;
  326. string strshaheadcontent = m_strshaheadcontent + strjson;
  327. strshaheadcontent = sha256_to_base16(strshaheadcontent);
  328. thttpinfo.addheadinfo.insert(make_pair(m_strshahead, strshaheadcontent));
  329. thttpinfo.strjson = strjson;
  330. thttpinfo.setresult_int.insert(404);
  331. stringstream sss;
  332. sss << "strurl=" << thttpinfo.strurl << " strtarget=" << strtarget << " strshaheadcontent=" << strshaheadcontent << " strjson=" << strjson;
  333. m_writelog(sss.str());
  334. weblib::sendhttp(m_psendhttp, move(thttpinfo), move(dofun));
  335. }
  336. ///////////////////////////////////////// JsonToBson///////////////////////////////////////////
  337. // 主转换函数(处理JSON对象)
  338. void convertJsonToBson(bsoncxx::builder::basic::document& doc, const rapidjson::Value& jsonValue)
  339. {
  340. if (!jsonValue.IsObject()) {
  341. throw runtime_error("Expected JSON object");
  342. }
  343. for (auto it = jsonValue.MemberBegin(); it != jsonValue.MemberEnd(); ++it)
  344. {
  345. const string key = it->name.GetString();
  346. const rapidjson::Value& value = it->value;
  347. if (value.IsInt()) {
  348. doc.append(kvp(key, value.GetInt()));
  349. }
  350. else if (value.IsUint()) {
  351. doc.append(kvp(key, static_cast<int32_t>(value.GetUint())));
  352. }
  353. else if (value.IsInt64()) {
  354. doc.append(kvp(key, static_cast<int64_t>(value.GetInt64())));
  355. }
  356. else if (value.IsUint64()) {
  357. doc.append(kvp(key, static_cast<int64_t>(value.GetUint64())));
  358. }
  359. else if (value.IsDouble()) {
  360. doc.append(kvp(key, value.GetDouble()));
  361. }
  362. else if (value.IsString()) {
  363. doc.append(kvp(key, value.GetString()));
  364. }
  365. else if (value.IsBool()) {
  366. doc.append(kvp(key, value.GetBool()));
  367. }
  368. else if (value.IsNull()) {
  369. doc.append(kvp(key, bsoncxx::types::b_null()));
  370. }
  371. else if (value.IsArray()) {
  372. bsoncxx::builder::basic::array arr;
  373. for (int i = 0; i < value.Size(); i++) {
  374. convertJsonValueToBson(arr, value[i]);
  375. }
  376. doc.append(kvp(key, arr));
  377. }
  378. else if (value.IsObject()) {
  379. bsoncxx::builder::basic::document sub_doc;
  380. convertJsonToBson(sub_doc, value);
  381. doc.append(kvp(key, sub_doc));
  382. }
  383. }
  384. }
  385. // 处理JSON值(可用于数组元素)
  386. void convertJsonValueToBson(bsoncxx::builder::basic::array& arr, const rapidjson::Value& jsonValue)
  387. {
  388. if (jsonValue.IsInt()) {
  389. arr.append(jsonValue.GetInt());
  390. }
  391. else if (jsonValue.IsUint()) {
  392. arr.append(static_cast<int32_t>(jsonValue.GetUint()));
  393. }
  394. else if (jsonValue.IsInt64()) {
  395. arr.append(static_cast<int64_t>(jsonValue.GetInt64()));
  396. }
  397. else if (jsonValue.IsUint64()) {
  398. arr.append(static_cast<int64_t>(jsonValue.GetUint64()));
  399. }
  400. else if (jsonValue.IsDouble()) {
  401. arr.append(jsonValue.GetDouble());
  402. }
  403. else if (jsonValue.IsString()) {
  404. arr.append(jsonValue.GetString());
  405. }
  406. else if (jsonValue.IsBool()) {
  407. arr.append(jsonValue.GetBool());
  408. }
  409. else if (jsonValue.IsNull()) {
  410. arr.append(bsoncxx::types::b_null());
  411. }
  412. else if (jsonValue.IsArray()) {
  413. for (int i = 0; i < jsonValue.Size(); i++) {
  414. convertJsonValueToBson(arr, jsonValue[i]);
  415. }
  416. }
  417. else if (jsonValue.IsObject()) {
  418. bsoncxx::builder::basic::document sub_doc;
  419. convertJsonToBson(sub_doc, jsonValue);
  420. arr.append(sub_doc);
  421. }
  422. }
  423. // 处理JSON数组(入口函数)
  424. void handleArray(bsoncxx::builder::basic::document& doc, const string& key, const rapidjson::Value& arrayValue)
  425. {
  426. if (!arrayValue.IsArray()) {
  427. throw runtime_error("Expected JSON array");
  428. }
  429. bsoncxx::builder::basic::array arr;
  430. for (int i = 0; i < arrayValue.Size(); i++)
  431. {
  432. convertJsonValueToBson(arr, arrayValue[i]);
  433. }
  434. doc.append(kvp(key, arr));
  435. }
  436. ///////////////////////////////////////// JsonToBson end///////////////////////////////////////////
  437. //
  438. //
  439. //game log cnt
  440. /*string HttpSocket::gamelogcnt(map<string, string> getdata)
  441. {
  442. gamelogcntdata tgamelogcntdata;
  443. getvaluedata(getdata, tgamelogcntdata);
  444. string strret{};
  445. bool bret = tgamelogcntdata.datavalue();
  446. if (!bret)
  447. {
  448. strret = funclib::rettojson(1, "param erro");
  449. return strret;
  450. }
  451. document finddoc;
  452. finddoc.append(kvp("$and", make_array(make_document(kvp("inserttime", make_document(kvp("$gte", tgamelogcntdata.ibegintime)))),
  453. make_document(kvp("inserttime", make_document(kvp("$lt", tgamelogcntdata.iendtime)))))));
  454. //admin 查询所有的
  455. if (tgamelogcntdata.ispreaderid != 1)
  456. {
  457. finddoc.append(kvp("spreaderid", tgamelogcntdata.ispreaderid));
  458. }
  459. else
  460. {
  461. if (!tgamelogcntdata.strgid.empty())
  462. {
  463. finddoc.append(kvp("gid", tgamelogcntdata.strgid.c_str()));
  464. if (tgamelogcntdata.iuserid > 0)
  465. {
  466. finddoc.append(kvp("playercnt", make_document(kvp("$elemMatch", make_document("$eq", 5)))));
  467. }
  468. }
  469. auto findcntall = m_pgameserverloginfo->find(finddoc.view());
  470. for (auto& doc : findcntall)
  471. {
  472. if (doc["playercnt"])
  473. {
  474. bsoncxx::document::element arrayField = doc["playercnt"];
  475. if (arrayField.type() == bsoncxx::type::k_array)
  476. {
  477. bsoncxx::builder::basic::array array_wheel{};
  478. bsoncxx::array::view arrayView = arrayField.get_array();
  479. for (auto& element : arrayView)
  480. {
  481. ijptbet += element["jptbet"].get_int64();
  482. ijptwin += element["jptwin"].get_int64();
  483. ijptcnt += element["jptcnt"].get_int64();
  484. }
  485. }
  486. }
  487. }
  488. }
  489. }*/