HttpSocket.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. static bool bAllPageDone = false; //这次请求是否请求完所有分页
  180. void HttpSocket::init()
  181. {
  182. static __int64 itimefrom = 0;
  183. static __int64 itimeto = 0;
  184. static __int32 ipage = 0;
  185. getsynctime(itimefrom, itimeto, ipage, bAllPageDone);
  186. while (true)
  187. {
  188. static __int64 inowtime = funclib::gettimestamp();
  189. if (itimeto == 0)
  190. {
  191. itimeto = inowtime - 1000;
  192. itimefrom = itimeto - 1000;
  193. }
  194. else if (inowtime - itimeto < 1000)
  195. {
  196. if(!bAllPageDone)
  197. continue;
  198. this_thread::sleep_for(milliseconds(itimeto + 1000 - inowtime));
  199. }
  200. if (bAllPageDone)
  201. ipage = 0;
  202. bAllPageDone = false;
  203. itimefrom = itimeto;
  204. itimeto = funclib::gettimestamp();
  205. auto pid = std::this_thread::get_id();
  206. getgamehistory(itimefrom, itimeto, ipage);
  207. }
  208. }
  209. //拉取日志
  210. void HttpSocket::getgamehistory(__int64 itimefrom, __int64 itimeto, __int32 ifirstpage)
  211. {
  212. m_writelog("--------------------getgamehistory-------------------------");
  213. __int32 ipage = ifirstpage;
  214. __int32 inextpage = 0;
  215. __int32 ipagesize = 1;
  216. rapidjson::Document doc;
  217. doc.SetObject();
  218. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  219. string datefrom = to_iso8601_utc_string(system_clock::time_point(seconds(itimefrom / 1000)));
  220. string dateto = to_iso8601_utc_string(system_clock::time_point(seconds(itimeto / 1000)));
  221. doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
  222. doc.AddMember("page", ipage, allocator);
  223. doc.AddMember("size", ipagesize, allocator);
  224. doc.AddMember("dateFrom", rapidjson::Value(datefrom.c_str(), allocator), allocator);
  225. doc.AddMember("dateTo", rapidjson::Value(dateto.c_str(), allocator), allocator);
  226. string strjson = funclib::doctojson(doc);
  227. string strtarget = "v2/tw/getGameHistory";
  228. sendreelmsg("luckybet777", strtarget, strjson, move([this, ipage, ipagesize, itimefrom, itimeto](string strdata, int iret) {
  229. if (iret == 200)
  230. {
  231. rettype::type tret{ rettype::type::ini };
  232. rapidjson::Document docdata;
  233. rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
  234. string stronlyid = "";
  235. string strgid = "";
  236. string straccount = "";
  237. string strroundData = "";
  238. string strgameResultUrl = "";
  239. string strcurrency = "";
  240. string strdbquestid = "";
  241. __int32 ibrandid = 2;
  242. __int64 iwinscore = 0;
  243. __int64 ibetscore = 0;
  244. double_t dwinmul = 0;
  245. if (ok)
  246. {
  247. static int itotalsize = 0;
  248. if (docdata.HasMember("total"))
  249. itotalsize = docdata["total"].GetInt();
  250. rapidjson::Value arrbets(rapidjson::kArrayType);
  251. if (docdata.HasMember("records") && docdata["records"].IsArray())
  252. {
  253. arrbets = docdata["records"].GetArray();
  254. for (rapidjson::SizeType i = 0; i < arrbets.Size(); ++i)
  255. {
  256. const rapidjson::Value& recorditem = arrbets[i];
  257. if (!recorditem.IsObject())
  258. continue;
  259. if (!recorditem.HasMember("roundFinished") || !recorditem["roundFinished"].GetBool())
  260. continue;
  261. if (!recorditem.HasMember("id"))
  262. continue;
  263. if(!recorditem.HasMember("launchAlias"))
  264. continue;
  265. if (!recorditem.HasMember("playerId"))
  266. continue;
  267. if (!recorditem.HasMember("totalWin"))
  268. continue;
  269. if (!recorditem.HasMember("totalBet"))
  270. continue;
  271. if (!recorditem.HasMember("roundDate"))
  272. continue;
  273. if (!recorditem.HasMember("gameResultUrl"))
  274. continue;
  275. if(!recorditem.HasMember("currency"))
  276. continue;
  277. stronlyid = recorditem["id"].GetString();
  278. //auto findrecord = make_document(kvp("onlyid", stronlyid.c_str()), kvp("brandid", ibrandid));
  279. //auto result = m_pgameprizelog->find_one(findrecord.view());
  280. //if (result)
  281. // continue; // 重复
  282. straccount = recorditem["playerId"].GetString();
  283. stUserInfo stuserinfo = map_acctouserinfo[straccount];
  284. if (!stuserinfo.iuserid)
  285. {
  286. auto finduser = m_pcoll->find_one(make_document(kvp("account", straccount.c_str())));
  287. if (!finduser || !finduser->view()["userid"])
  288. continue;
  289. stuserinfo.iuserid = finduser->view()["userid"].get_int64();
  290. if(finduser->view()["spreaderid"])
  291. stuserinfo.ispreaderid = finduser->view()["spreaderid"].get_int64();
  292. if(finduser->view()["areaid"])
  293. stuserinfo.iareaid = finduser->view()["areaid"].get_int32();
  294. map_acctouserinfo[straccount] = stuserinfo;
  295. }
  296. iwinscore = static_cast<__int64>(std::stod(recorditem["totalWin"].GetString()) * 100);
  297. ibetscore = static_cast<__int64>(std::stod(recorditem["totalBet"].GetString()) * 100);
  298. if(ibetscore > 0)
  299. dwinmul = iwinscore / ibetscore;
  300. strgid = recorditem["launchAlias"].GetString();
  301. strroundData = recorditem["roundDate"].GetString();
  302. strgameResultUrl = recorditem["gameResultUrl"].GetString();
  303. strcurrency = recorditem["currency"].GetString();
  304. document recorddoc;
  305. //convertJsonToBson(recorddoc, recorditem);
  306. recorddoc.append(kvp("onlyid", stronlyid.c_str()));
  307. recorddoc.append(kvp("dbquestid", stronlyid.c_str()));
  308. recorddoc.append(kvp("brandid", ibrandid));
  309. recorddoc.append(kvp("gid", strgid.c_str()));
  310. recorddoc.append(kvp("userid", stuserinfo.iuserid));
  311. recorddoc.append(kvp("areaid", stuserinfo.iareaid));
  312. recorddoc.append(kvp("spreaderid", stuserinfo.ispreaderid));
  313. recorddoc.append(kvp("roundDate", strroundData.c_str()));
  314. recorddoc.append(kvp("gameResultUrl", strgameResultUrl.c_str()));
  315. recorddoc.append(kvp("winscore", iwinscore));
  316. recorddoc.append(kvp("betscore", ibetscore));
  317. recorddoc.append(kvp("dwinmul", dwinmul));
  318. recorddoc.append(kvp("account", straccount.c_str()));
  319. recorddoc.append(kvp("currency", strcurrency.c_str()));
  320. recorddoc.append(kvp("scoretype", 1));
  321. recorddoc.append(kvp("inserttime", funclib::gettimestamp()));
  322. m_pgameprizelog->insert_one(recorddoc.view());
  323. }
  324. }
  325. if((ipage + 1) * ipagesize >= itotalsize)
  326. bAllPageDone = true;
  327. setsynctime(itimefrom, itimeto, ipage + 1, bAllPageDone);
  328. if(!bAllPageDone)
  329. getgamehistory(itimefrom, itimeto, ipage + 1);
  330. }
  331. }
  332. }));
  333. }
  334. void HttpSocket::sendreelmsg(string stronly, string strtarget, string strjson, function<void(string, int)>&& dofun)
  335. {
  336. weblib::httpinfo thttpinfo;
  337. thttpinfo.strurl = "https://transfer-wallet-service.stage.iconic-21.com";
  338. // thttpinfo.strurl = "http://127.0.0.1:6000";
  339. thttpinfo.strtarget = strtarget;
  340. thttpinfo.stronly = stronly;
  341. string strshaheadcontent = m_strshaheadcontent + strjson;
  342. strshaheadcontent = sha256_to_base16(strshaheadcontent);
  343. thttpinfo.addheadinfo.insert(make_pair(m_strshahead, strshaheadcontent));
  344. thttpinfo.strjson = strjson;
  345. thttpinfo.setresult_int.insert(404);
  346. stringstream sss;
  347. sss << "strurl=" << thttpinfo.strurl << " strtarget=" << strtarget << " strshaheadcontent=" << strshaheadcontent << " strjson=" << strjson;
  348. m_writelog(sss.str());
  349. weblib::sendhttp(m_psendhttp, move(thttpinfo), move(dofun));
  350. }
  351. void HttpSocket::getsynctime(__int64& itimefrom, __int64& itimeto, __int32& ipage, bool& bdone)
  352. {
  353. itimefrom = 0;
  354. itimeto = 0;
  355. ipage = 0;
  356. auto finddeveloper = m_pthirddeveloper->find_one(make_document(kvp("id", 2)));
  357. if (finddeveloper && finddeveloper->view()["logtimefrom"] && finddeveloper->view()["logtimeto"] &&
  358. finddeveloper->view()["logpage"] && finddeveloper->view()["logdone"])
  359. {
  360. itimefrom = finddeveloper->view()["logtimefrom"].get_int64();
  361. itimeto = finddeveloper->view()["logtimeto"].get_int64();
  362. ipage = finddeveloper->view()["logpage"].get_int32();
  363. bdone = finddeveloper->view()["logdone"].get_bool();
  364. }
  365. }
  366. void HttpSocket::setsynctime(__int64 itimefrom, __int64 itimeto, __int32 ipage, bool bdone)
  367. {
  368. m_pthirddeveloper->find_one_and_update(make_document(kvp("id", 2)),
  369. make_document(kvp("$set" , make_document(kvp("logtimefrom", itimefrom), kvp("logtimeto", itimeto), kvp("logpage", ipage), kvp("logdone", bdone)))));
  370. }
  371. ///////////////////////////////////////// JsonToBson///////////////////////////////////////////
  372. // 主转换函数(处理JSON对象)
  373. void convertJsonToBson(bsoncxx::builder::basic::document& doc, const rapidjson::Value& jsonValue)
  374. {
  375. if (!jsonValue.IsObject()) {
  376. throw runtime_error("Expected JSON object");
  377. }
  378. for (auto it = jsonValue.MemberBegin(); it != jsonValue.MemberEnd(); ++it)
  379. {
  380. const string key = it->name.GetString();
  381. const rapidjson::Value& value = it->value;
  382. if (value.IsInt()) {
  383. doc.append(kvp(key, value.GetInt()));
  384. }
  385. else if (value.IsUint()) {
  386. doc.append(kvp(key, static_cast<int32_t>(value.GetUint())));
  387. }
  388. else if (value.IsInt64()) {
  389. doc.append(kvp(key, static_cast<int64_t>(value.GetInt64())));
  390. }
  391. else if (value.IsUint64()) {
  392. doc.append(kvp(key, static_cast<int64_t>(value.GetUint64())));
  393. }
  394. else if (value.IsDouble()) {
  395. doc.append(kvp(key, value.GetDouble()));
  396. }
  397. else if (value.IsString()) {
  398. doc.append(kvp(key, value.GetString()));
  399. }
  400. else if (value.IsBool()) {
  401. doc.append(kvp(key, value.GetBool()));
  402. }
  403. else if (value.IsNull()) {
  404. doc.append(kvp(key, bsoncxx::types::b_null()));
  405. }
  406. else if (value.IsArray()) {
  407. bsoncxx::builder::basic::array arr;
  408. for (int i = 0; i < value.Size(); i++) {
  409. convertJsonValueToBson(arr, value[i]);
  410. }
  411. doc.append(kvp(key, arr));
  412. }
  413. else if (value.IsObject()) {
  414. bsoncxx::builder::basic::document sub_doc;
  415. convertJsonToBson(sub_doc, value);
  416. doc.append(kvp(key, sub_doc));
  417. }
  418. }
  419. }
  420. // 处理JSON值(可用于数组元素)
  421. void convertJsonValueToBson(bsoncxx::builder::basic::array& arr, const rapidjson::Value& jsonValue)
  422. {
  423. if (jsonValue.IsInt()) {
  424. arr.append(jsonValue.GetInt());
  425. }
  426. else if (jsonValue.IsUint()) {
  427. arr.append(static_cast<int32_t>(jsonValue.GetUint()));
  428. }
  429. else if (jsonValue.IsInt64()) {
  430. arr.append(static_cast<int64_t>(jsonValue.GetInt64()));
  431. }
  432. else if (jsonValue.IsUint64()) {
  433. arr.append(static_cast<int64_t>(jsonValue.GetUint64()));
  434. }
  435. else if (jsonValue.IsDouble()) {
  436. arr.append(jsonValue.GetDouble());
  437. }
  438. else if (jsonValue.IsString()) {
  439. arr.append(jsonValue.GetString());
  440. }
  441. else if (jsonValue.IsBool()) {
  442. arr.append(jsonValue.GetBool());
  443. }
  444. else if (jsonValue.IsNull()) {
  445. arr.append(bsoncxx::types::b_null());
  446. }
  447. else if (jsonValue.IsArray()) {
  448. for (int i = 0; i < jsonValue.Size(); i++) {
  449. convertJsonValueToBson(arr, jsonValue[i]);
  450. }
  451. }
  452. else if (jsonValue.IsObject()) {
  453. bsoncxx::builder::basic::document sub_doc;
  454. convertJsonToBson(sub_doc, jsonValue);
  455. arr.append(sub_doc);
  456. }
  457. }
  458. // 处理JSON数组(入口函数)
  459. void handleArray(bsoncxx::builder::basic::document& doc, const string& key, const rapidjson::Value& arrayValue)
  460. {
  461. if (!arrayValue.IsArray()) {
  462. throw runtime_error("Expected JSON array");
  463. }
  464. bsoncxx::builder::basic::array arr;
  465. for (int i = 0; i < arrayValue.Size(); i++)
  466. {
  467. convertJsonValueToBson(arr, arrayValue[i]);
  468. }
  469. doc.append(kvp(key, arr));
  470. }
  471. ///////////////////////////////////////// JsonToBson end///////////////////////////////////////////
  472. //
  473. //
  474. //game log cnt
  475. /*string HttpSocket::gamelogcnt(map<string, string> getdata)
  476. {
  477. gamelogcntdata tgamelogcntdata;
  478. getvaluedata(getdata, tgamelogcntdata);
  479. string strret{};
  480. bool bret = tgamelogcntdata.datavalue();
  481. if (!bret)
  482. {
  483. strret = funclib::rettojson(1, "param erro");
  484. return strret;
  485. }
  486. document finddoc;
  487. finddoc.append(kvp("$and", make_array(make_document(kvp("inserttime", make_document(kvp("$gte", tgamelogcntdata.ibegintime)))),
  488. make_document(kvp("inserttime", make_document(kvp("$lt", tgamelogcntdata.iendtime)))))));
  489. //admin 查询所有的
  490. if (tgamelogcntdata.ispreaderid != 1)
  491. {
  492. finddoc.append(kvp("spreaderid", tgamelogcntdata.ispreaderid));
  493. }
  494. else
  495. {
  496. if (!tgamelogcntdata.strgid.empty())
  497. {
  498. finddoc.append(kvp("gid", tgamelogcntdata.strgid.c_str()));
  499. if (tgamelogcntdata.iuserid > 0)
  500. {
  501. finddoc.append(kvp("playercnt", make_document(kvp("$elemMatch", make_document("$eq", 5)))));
  502. }
  503. }
  504. auto findcntall = m_pgameserverloginfo->find(finddoc.view());
  505. for (auto& doc : findcntall)
  506. {
  507. if (doc["playercnt"])
  508. {
  509. bsoncxx::document::element arrayField = doc["playercnt"];
  510. if (arrayField.type() == bsoncxx::type::k_array)
  511. {
  512. bsoncxx::builder::basic::array array_wheel{};
  513. bsoncxx::array::view arrayView = arrayField.get_array();
  514. for (auto& element : arrayView)
  515. {
  516. ijptbet += element["jptbet"].get_int64();
  517. ijptwin += element["jptwin"].get_int64();
  518. ijptcnt += element["jptcnt"].get_int64();
  519. }
  520. }
  521. }
  522. }
  523. }
  524. }*/