HttpSocket.cpp 20 KB

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