123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611 |
- #include "pch.h"
- #include "HttpSocket.h"
- #include <set>
- #include <chrono>
- #include <ctime>
- #include <iomanip>
- #include <sstream>
- #include <string>
- #include <utility>
- #include <boost/lexical_cast.hpp>
- #include <boost/chrono.hpp>
- #include <boost/date_time/posix_time/posix_time.hpp>
- using namespace bsoncxx::builder::basic;
- using namespace chrono;
- mongocxx::instance g_instance{};
- std::int64_t getstrfromstamp(std::string strtime)
- {
- __int64 igettime = 0;
- boost::replace_all(strtime, " ", "T");
- boost::replace_all(strtime, "-", "");
- boost::replace_all(strtime, ":", "");
- strtime += "000";
- boost::posix_time::ptime ssp = boost::posix_time::from_iso_string(strtime);
- boost::posix_time::time_duration time_from_epoch = boost::posix_time::microsec_clock::universal_time() - boost::posix_time::microsec_clock::local_time();
- boost::posix_time::ptime epoch(boost::gregorian::date(1970, boost::gregorian::Jan, 1));
- boost::posix_time::time_duration time_epoch = ssp - epoch;
- igettime = time_epoch.total_milliseconds() + time_from_epoch.total_milliseconds() / 360000 * 360000;
- return igettime;
- }
- HttpSocket::HttpSocket()
- {
- __int64 itime = funclib::gettimestamp();
- m_random = default_random_engine(itime);
- m_pmsgservice = boost::make_shared<boost::asio::io_context>();
- m_pmsgwork = boost::make_shared<boost::asio::io_context::work>(*m_pmsgservice);
- data_time = boost::make_shared<boost::asio::deadline_timer>(*m_pmsgservice);
- //数据库配置
- string strip = funclib::getdatainfo();
- //strip = "mongodb://datzahndle:pajdt873hyu3h37@110.40.64.236:37317";
- //strip = "mongodb://110.40.59.112:37317";
- //strip = "mongodb://192.168.0.220:27017";
- m_puri = boost::make_shared<mongocxx::uri>(strip.c_str());
- m_pclient = boost::make_shared <mongocxx::client>(*m_puri);
- m_pdb = boost::make_shared<mongocxx::database>();
- m_platform = boost::make_shared<mongocxx::database>();
- m_gamelog = boost::make_shared<mongocxx::database>();
- m_pvipuserdb = boost::make_shared<mongocxx::database>();
- m_ptask = boost::make_shared<mongocxx::database>();
- m_viplog = boost::make_shared<mongocxx::database>();
- m_webdata = boost::make_shared<mongocxx::database>();
- m_pallindex = boost::make_shared<mongocxx::collection>();
- m_pcoll = boost::make_shared<mongocxx::collection>();
- m_plosewincoll = boost::make_shared<mongocxx::collection>();
- m_pvipuser = boost::make_shared<mongocxx::collection>();
- m_pplayuseronline = boost::make_shared<mongocxx::collection>();
- m_userloginonline = boost::make_shared<mongocxx::collection>();
- m_pusertradeinfo = boost::make_shared<mongocxx::collection>();
- m_pviptradeinfo = boost::make_shared<mongocxx::collection>();
- m_poperatinfo = boost::make_shared<mongocxx::collection>();
- m_pgameviploginfo = boost::make_shared<mongocxx::collection>();
- m_pgameserverloginfo = boost::make_shared<mongocxx::collection>();
- m_pvipalllogcache = boost::make_shared<mongocxx::collection>();
- m_pserverlogcache = boost::make_shared<mongocxx::collection>();
- m_puserlogcache = boost::make_shared<mongocxx::collection>();
- m_pgameuserloginfo = boost::make_shared<mongocxx::collection>();
- m_pviplogcache = boost::make_shared<mongocxx::collection>();
- m_pgameprizelog = boost::make_shared<mongocxx::collection>();
- m_puserdowninfo = boost::make_shared<mongocxx::collection>();
- m_pvipscore = boost::make_shared<mongocxx::collection>();
- m_pvipscoredate = boost::make_shared<mongocxx::collection>();
- m_pvipuseraccounts = boost::make_shared<mongocxx::collection>();
- m_puserdatainfo = boost::make_shared<mongocxx::collection>();
- m_pvipconfigure = boost::make_shared<mongocxx::collection>();
- m_pusersub = boost::make_shared<mongocxx::collection>();
- m_pexechangerate = boost::make_shared<mongocxx::collection>();
- m_pthreeadmin = boost::make_shared<mongocxx::collection>();
- m_pconfig = boost::make_shared<mongocxx::collection>();
- m_pkinditem = boost::make_shared<mongocxx::collection>();
- m_pipwhite = boost::make_shared<mongocxx::collection>();
- m_papplyviplog = boost::make_shared<mongocxx::collection>();
- m_pvipmsglog = boost::make_shared<mongocxx::collection>();
- m_pgamelist = boost::make_shared<mongocxx::collection>();
- m_pgamegameitem = boost::make_shared<mongocxx::collection>();
- m_ppopularizesit = boost::make_shared<mongocxx::collection>();
- m_activityfreegame = boost::make_shared<mongocxx::collection>();
- m_pmarquee = boost::make_shared<mongocxx::collection>();
- m_pcustomerlink = boost::make_shared<mongocxx::collection>();
- m_pcredittopwinner = boost::make_shared<mongocxx::collection>();
- m_resendorder = boost::make_shared<mongocxx::collection>();
- m_pareagames = boost::make_shared<mongocxx::collection>();
- m_pplayrecordini = boost::make_shared<mongocxx::collection>();
- m_pgamebet = boost::make_shared<mongocxx::collection>();
- m_pactivityini = boost::make_shared<mongocxx::collection>();
- m_pplatformini = boost::make_shared<mongocxx::collection>();
- m_pthirddeveloper = boost::make_shared<mongocxx::collection>();
- m_pthirdgames = boost::make_shared<mongocxx::collection>();
- m_pgameprizelog = boost::make_shared<mongocxx::collection>();
- *m_pdb = (*m_pclient)["accounts"];
- *m_platform = (*m_pclient)["platform"];
- *m_gamelog = (*m_pclient)["gamelog"];
- *m_ptask = (*m_pclient)["task"];
- *m_viplog = (*m_pclient)["viplog"];
- *m_webdata = (*m_pclient)["webdata"];
- *m_pvipuserdb = (*m_pclient)["vipuser"];
- *m_pallindex = (*m_pdb)["allindex"];
- *m_pcoll = (*m_pdb)["userinfo"];
- *m_plosewincoll = (*m_pdb)["losewin"];
- *m_pvipuser = (*m_pvipuserdb)["user"];
- *m_pplayuseronline = (*m_gamelog)["playuseronline"];
- *m_userloginonline = (*m_gamelog)["userloginonline"];
- *m_poperatinfo = (*m_gamelog)["operatinfo"];
- *m_puserdowninfo = (*m_gamelog)["userdowninfo"];
- *m_pusertradeinfo = (*m_pvipuserdb)["usertradeinfo"];
- *m_pgameviploginfo = (*m_gamelog)["gameviploginfo"];
- *m_pgameserverloginfo = (*m_gamelog)["gameserverloginfo"];
- *m_pvipalllogcache = (*m_gamelog)["vipalllogcache"];
- *m_pserverlogcache = (*m_gamelog)["serverlogcache"];
- *m_puserlogcache = (*m_gamelog)["userlogcache"];
- *m_pgameuserloginfo = (*m_gamelog)["gameuserloginfo"];
- *m_pviplogcache = (*m_gamelog)["viplogcache"];
- *m_pgameprizelog = (*m_gamelog)["gameprizelog"];
- *m_resendorder = (*m_gamelog)["resendorder"];
- *m_pviptradeinfo = (*m_pvipuserdb)["viptradeinfo"];
- *m_pvipscore = (*m_pvipuserdb)["vipscore"];
- *m_pvipscoredate = (*m_pvipuserdb)["vipscoredate"];
- *m_pvipuseraccounts = (*m_pvipuserdb)["vipuseraccounts"];
- *m_puserdatainfo = (*m_gamelog)["userdatainfo"];
- *m_pvipconfigure = (*m_pvipuserdb)["vipconfigure"];
- *m_pthreeadmin = (*m_pvipuserdb)["threeadmin"];
- *m_pusersub = (*m_pvipuserdb)["usersub"];
- *m_pexechangerate = (*m_platform)["exechangerate"];
- *m_pkinditem = (*m_platform)["kinditem"];
- *m_pgamelist = (*m_platform)["gamelist"];
- *m_pgamegameitem = (*m_platform)["gamegameitem"];
- *m_ppopularizesit = (*m_pvipuserdb)["popularizesit"]; // 推广网站
- *m_pmarquee = (*m_pvipuserdb)["marquee"]; // 信用代理跑马灯
- *m_pcustomerlink = (*m_pvipuserdb)["customerlink"];
- *m_pcredittopwinner = (*m_gamelog)["credittopwinner"];
- *m_pplatformini = (*m_platform)["platformini"];
- //task
- *m_pconfig = (*m_ptask)["config"];
- *m_pipwhite = (*m_pvipuserdb)["ipwhite"];
- //viplog
- *m_papplyviplog = (*m_viplog)["applyviplog"];
- *m_pvipmsglog = (*m_viplog)["vipmsglog"];
- //freegame
- *m_activityfreegame = (*m_pvipuserdb)["freegameactivity"];
- //areagame
- *m_pareagames = (*m_platform)["areagames"];
- *m_pplayrecordini = (*m_platform)["playrecordini"];
- // 游戏投注配置
- *m_pgamebet = (*m_platform)["gamebet"];
- // 游戏活动配置
- *m_pactivityini = (*m_webdata)["activeini"];
- // 第三方厂商
- *m_pthirddeveloper = (*m_platform)["thirddeveloper"];
- // 第三方厂商游戏
- *m_pthirdgames = (*m_platform)["thirdgames"];
- m_strshahead = "X-REQUEST-SIGN";
- m_strshaheadcontent = "6e4c91001979851a97c2b5360f044ff67b48e186d6ecd4394532851bffdeeae9";
- m_psendhttp = weblib::httpini();
-
- m_brun = false;
- m_msgthread = thread([this] {
- m_ucurid = funclib::getcurid();
- m_brun = true;
- m_pmsgservice->run();
- m_brun = false;
- });
- m_msgthread.detach();
- while (!m_brun)
- {
- this_thread::yield();
- }
- }
- HttpSocket::~HttpSocket()
- {
-
- }
- // 毫秒时间戳 → ISO-8601 UTC 时间字符串
- string to_iso8601_utc_string(chrono::system_clock::time_point tp)
- {
- auto ms = duration_cast<milliseconds>(tp.time_since_epoch()) % 1000;
- time_t t = system_clock::to_time_t(tp);
- tm tm = *gmtime(&t);
- ostringstream oss;
- oss << put_time(&tm, "%Y-%m-%d %H:%M:%S");
- oss << '.' << setfill('0') << setw(3) << ms.count();
- return oss.str();
- }
- struct stUserInfo
- {
- __int64 ispreaderid = 0;
- __int32 iareaid = 0;
- __int64 iuserid = 0;
- };
- static map<string, stUserInfo> map_acctouserinfo;
- static bool bAllPageDone = false; //这次请求是否请求完所有分页
- void HttpSocket::init()
- {
- __int64 itimefrom = 0;
- __int64 itimeto = 0;
- __int32 ipage = 0;
- __int64 inowtime = 0;
- bool bFirst = true;
- loaddbsynctime(itimefrom, itimeto, ipage, bAllPageDone);
- while (true)
- {
- inowtime = funclib::gettimestamp();
- if (itimeto == 0)
- {
- itimeto = inowtime - 1000;
- itimefrom = itimeto - 1000;
- }
- else if (inowtime - itimeto < 1000)
- {
- this_thread::sleep_for(milliseconds(itimeto + 1000 - inowtime));
- }
- if (!bFirst && !bAllPageDone)
- continue;
- else
- ipage = 0;
- bAllPageDone = false;
- bFirst = false;
- itimefrom = itimeto;
- itimeto = funclib::gettimestamp();
-
- getgamehistory(itimefrom, itimeto, ipage);
- }
- }
- //拉取日志
- void HttpSocket::getgamehistory(__int64 itimefrom, __int64 itimeto, __int32 ifirstpage)
- {
- m_writelog("--------------------getgamehistory-------------------------");
- __int32 ipage = ifirstpage;
- __int32 inextpage = 0;
- __int32 ipagesize = 500;
- rapidjson::Document doc;
- doc.SetObject();
- rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
- string datefrom = to_iso8601_utc_string(system_clock::time_point(seconds(itimefrom / 1000)));
- string dateto = to_iso8601_utc_string(system_clock::time_point(seconds(itimeto / 1000)));
- doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
- doc.AddMember("page", ipage, allocator);
- doc.AddMember("size", ipagesize, allocator);
- doc.AddMember("dateFrom", rapidjson::Value(datefrom.c_str(), allocator), allocator);
- doc.AddMember("dateTo", rapidjson::Value(dateto.c_str(), allocator), allocator);
- string strjson = funclib::doctojson(doc);
- string strtarget = "v2/tw/getGameHistory";
-
- sendreelmsg("luckybet777", strtarget, strjson, move([this, ipage, ipagesize, itimefrom, itimeto](string strdata, int iret) {
- if (iret == 200)
- {
- rettype::type tret{ rettype::type::ini };
- rapidjson::Document docdata;
- rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
- string stronlyid = "";
- string strgid = "";
- string straccount = "";
- string strroundData = "";
- string strgameResultUrl = "";
- string strcurrency = "";
- string strdbquestid = "";
- __int32 ibrandid = 2;
- __int64 iwinscore = 0;
- __int64 ibetscore = 0;
- double_t dwinmul = 0;
- if (ok)
- {
- static int itotalsize = 0;
- if (docdata.HasMember("total"))
- itotalsize = docdata["total"].GetInt();
-
- rapidjson::Value arrbets(rapidjson::kArrayType);
- if (docdata.HasMember("records") && docdata["records"].IsArray())
- {
- arrbets = docdata["records"].GetArray();
- for (rapidjson::SizeType i = 0; i < arrbets.Size(); ++i)
- {
- const rapidjson::Value& recorditem = arrbets[i];
- if (!recorditem.IsObject())
- continue;
- if (!recorditem.HasMember("roundFinished") || !recorditem["roundFinished"].GetBool())
- continue;
- if (!recorditem.HasMember("id"))
- continue;
- if(!recorditem.HasMember("launchAlias"))
- continue;
- if (!recorditem.HasMember("playerId"))
- continue;
- if (!recorditem.HasMember("totalWin"))
- continue;
- if (!recorditem.HasMember("totalBet"))
- continue;
- if (!recorditem.HasMember("roundDate"))
- continue;
- if (!recorditem.HasMember("gameResultUrl"))
- continue;
- if(!recorditem.HasMember("currency"))
- continue;
- stronlyid = recorditem["id"].GetString();
- //auto findrecord = make_document(kvp("onlyid", stronlyid.c_str()), kvp("brandid", ibrandid));
- //auto result = m_pgameprizelog->find_one(findrecord.view());
- //if (result)
- // continue; // 重复
- straccount = recorditem["playerId"].GetString();
- stUserInfo stuserinfo = map_acctouserinfo[straccount];
- if (!stuserinfo.iuserid)
- {
- auto finduser = m_pcoll->find_one(make_document(kvp("account", straccount.c_str())));
- if (!finduser || !finduser->view()["userid"])
- continue;
- stuserinfo.iuserid = finduser->view()["userid"].get_int64();
- if(finduser->view()["spreaderid"])
- stuserinfo.ispreaderid = finduser->view()["spreaderid"].get_int64();
- if(finduser->view()["areaid"])
- stuserinfo.iareaid = finduser->view()["areaid"].get_int32();
- map_acctouserinfo[straccount] = stuserinfo;
- }
- iwinscore = static_cast<__int64>(std::stod(recorditem["totalWin"].GetString()) * 100);
- ibetscore = static_cast<__int64>(std::stod(recorditem["totalBet"].GetString()) * 100);
- if(ibetscore > 0)
- dwinmul = iwinscore / ibetscore;
- strgid = recorditem["launchAlias"].GetString();
- strroundData = recorditem["roundDate"].GetString();
- strgameResultUrl = recorditem["gameResultUrl"].GetString();
- strcurrency = recorditem["currency"].GetString();
- document recorddoc;
- //convertJsonToBson(recorddoc, recorditem);
- recorddoc.append(kvp("onlyid", stronlyid.c_str()));
- recorddoc.append(kvp("dbquestid", stronlyid.c_str()));
- recorddoc.append(kvp("brandid", ibrandid));
- recorddoc.append(kvp("gid", strgid.c_str()));
- recorddoc.append(kvp("userid", stuserinfo.iuserid));
- recorddoc.append(kvp("areaid", stuserinfo.iareaid));
- recorddoc.append(kvp("spreaderid", stuserinfo.ispreaderid));
- recorddoc.append(kvp("roundDate", strroundData.c_str()));
- recorddoc.append(kvp("gameResultUrl", strgameResultUrl.c_str()));
- recorddoc.append(kvp("winscore", iwinscore));
- recorddoc.append(kvp("betscore", ibetscore));
- recorddoc.append(kvp("dwinmul", dwinmul));
- recorddoc.append(kvp("account", straccount.c_str()));
- recorddoc.append(kvp("currency", strcurrency.c_str()));
- recorddoc.append(kvp("scoretype", 1));
- std::int64_t icreateime = getstrfromstamp(strroundData);
- recorddoc.append(kvp("inserttime", icreateime));
- m_pgameprizelog->insert_one(recorddoc.view());
- }
- }
-
- if((ipage + 1) * ipagesize >= itotalsize)
- bAllPageDone = true;
-
- setdbsynctime(itimefrom, itimeto, ipage + 1, bAllPageDone);
- if(!bAllPageDone)
- getgamehistory(itimefrom, itimeto, ipage + 1);
- }
- }
- }));
- }
- void HttpSocket::sendreelmsg(string stronly, string strtarget, string strjson, function<void(string, int)>&& dofun)
- {
- weblib::httpinfo thttpinfo;
- thttpinfo.strurl = "https://transfer-wallet-service.stage.iconic-21.com";
- // thttpinfo.strurl = "http://127.0.0.1:6000";
- thttpinfo.strtarget = strtarget;
- thttpinfo.stronly = stronly;
- string strshaheadcontent = m_strshaheadcontent + strjson;
- strshaheadcontent = sha256_to_base16(strshaheadcontent);
- thttpinfo.addheadinfo.insert(make_pair(m_strshahead, strshaheadcontent));
- thttpinfo.strjson = strjson;
- thttpinfo.setresult_int.insert(404);
- stringstream sss;
- sss << "strurl=" << thttpinfo.strurl << " strtarget=" << strtarget << " strshaheadcontent=" << strshaheadcontent << " strjson=" << strjson;
- m_writelog(sss.str());
- weblib::sendhttp(m_psendhttp, move(thttpinfo), move(dofun));
- }
- void HttpSocket::loaddbsynctime(__int64& itimefrom, __int64& itimeto, __int32& ipage, bool& bdone)
- {
- itimefrom = 0;
- itimeto = 0;
- ipage = 0;
- auto finddeveloper = m_pthirddeveloper->find_one(make_document(kvp("id", 2)));
- if (finddeveloper && finddeveloper->view()["logtimefrom"] && finddeveloper->view()["logtimeto"] &&
- finddeveloper->view()["logpage"] && finddeveloper->view()["logdone"])
- {
- itimefrom = finddeveloper->view()["logtimefrom"].get_int64();
- itimeto = finddeveloper->view()["logtimeto"].get_int64();
- ipage = finddeveloper->view()["logpage"].get_int32();
- bdone = finddeveloper->view()["logdone"].get_bool();
- }
- }
- void HttpSocket::setdbsynctime(__int64 itimefrom, __int64 itimeto, __int32 ipage, bool bdone)
- {
- m_pthirddeveloper->find_one_and_update(make_document(kvp("id", 2)),
- make_document(kvp("$set" , make_document(kvp("logtimefrom", itimefrom), kvp("logtimeto", itimeto), kvp("logpage", ipage), kvp("logdone", bdone)))));
- }
- ///////////////////////////////////////// JsonToBson///////////////////////////////////////////
- // 主转换函数(处理JSON对象)
- void convertJsonToBson(bsoncxx::builder::basic::document& doc, const rapidjson::Value& jsonValue)
- {
- if (!jsonValue.IsObject()) {
- throw runtime_error("Expected JSON object");
- }
- for (auto it = jsonValue.MemberBegin(); it != jsonValue.MemberEnd(); ++it)
- {
- const string key = it->name.GetString();
- const rapidjson::Value& value = it->value;
- if (value.IsInt()) {
- doc.append(kvp(key, value.GetInt()));
- }
- else if (value.IsUint()) {
- doc.append(kvp(key, static_cast<int32_t>(value.GetUint())));
- }
- else if (value.IsInt64()) {
- doc.append(kvp(key, static_cast<int64_t>(value.GetInt64())));
- }
- else if (value.IsUint64()) {
- doc.append(kvp(key, static_cast<int64_t>(value.GetUint64())));
- }
- else if (value.IsDouble()) {
- doc.append(kvp(key, value.GetDouble()));
- }
- else if (value.IsString()) {
- doc.append(kvp(key, value.GetString()));
- }
- else if (value.IsBool()) {
- doc.append(kvp(key, value.GetBool()));
- }
- else if (value.IsNull()) {
- doc.append(kvp(key, bsoncxx::types::b_null()));
- }
- else if (value.IsArray()) {
- bsoncxx::builder::basic::array arr;
- for (int i = 0; i < value.Size(); i++) {
- convertJsonValueToBson(arr, value[i]);
- }
- doc.append(kvp(key, arr));
- }
- else if (value.IsObject()) {
- bsoncxx::builder::basic::document sub_doc;
- convertJsonToBson(sub_doc, value);
- doc.append(kvp(key, sub_doc));
- }
- }
- }
- // 处理JSON值(可用于数组元素)
- void convertJsonValueToBson(bsoncxx::builder::basic::array& arr, const rapidjson::Value& jsonValue)
- {
- if (jsonValue.IsInt()) {
- arr.append(jsonValue.GetInt());
- }
- else if (jsonValue.IsUint()) {
- arr.append(static_cast<int32_t>(jsonValue.GetUint()));
- }
- else if (jsonValue.IsInt64()) {
- arr.append(static_cast<int64_t>(jsonValue.GetInt64()));
- }
- else if (jsonValue.IsUint64()) {
- arr.append(static_cast<int64_t>(jsonValue.GetUint64()));
- }
- else if (jsonValue.IsDouble()) {
- arr.append(jsonValue.GetDouble());
- }
- else if (jsonValue.IsString()) {
- arr.append(jsonValue.GetString());
- }
- else if (jsonValue.IsBool()) {
- arr.append(jsonValue.GetBool());
- }
- else if (jsonValue.IsNull()) {
- arr.append(bsoncxx::types::b_null());
- }
- else if (jsonValue.IsArray()) {
- for (int i = 0; i < jsonValue.Size(); i++) {
- convertJsonValueToBson(arr, jsonValue[i]);
- }
- }
- else if (jsonValue.IsObject()) {
- bsoncxx::builder::basic::document sub_doc;
- convertJsonToBson(sub_doc, jsonValue);
- arr.append(sub_doc);
- }
- }
- // 处理JSON数组(入口函数)
- void handleArray(bsoncxx::builder::basic::document& doc, const string& key, const rapidjson::Value& arrayValue)
- {
- if (!arrayValue.IsArray()) {
- throw runtime_error("Expected JSON array");
- }
- bsoncxx::builder::basic::array arr;
- for (int i = 0; i < arrayValue.Size(); i++)
- {
- convertJsonValueToBson(arr, arrayValue[i]);
- }
- doc.append(kvp(key, arr));
- }
- ///////////////////////////////////////// JsonToBson end///////////////////////////////////////////
- //
- //
- //game log cnt
- /*string HttpSocket::gamelogcnt(map<string, string> getdata)
- {
- gamelogcntdata tgamelogcntdata;
- getvaluedata(getdata, tgamelogcntdata);
- string strret{};
- bool bret = tgamelogcntdata.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(1, "param erro");
- return strret;
- }
- document finddoc;
- finddoc.append(kvp("$and", make_array(make_document(kvp("inserttime", make_document(kvp("$gte", tgamelogcntdata.ibegintime)))),
- make_document(kvp("inserttime", make_document(kvp("$lt", tgamelogcntdata.iendtime)))))));
- //admin 查询所有的
- if (tgamelogcntdata.ispreaderid != 1)
- {
- finddoc.append(kvp("spreaderid", tgamelogcntdata.ispreaderid));
- }
- else
- {
- if (!tgamelogcntdata.strgid.empty())
- {
- finddoc.append(kvp("gid", tgamelogcntdata.strgid.c_str()));
- if (tgamelogcntdata.iuserid > 0)
- {
- finddoc.append(kvp("playercnt", make_document(kvp("$elemMatch", make_document("$eq", 5)))));
- }
- }
- auto findcntall = m_pgameserverloginfo->find(finddoc.view());
- for (auto& doc : findcntall)
- {
- if (doc["playercnt"])
- {
- bsoncxx::document::element arrayField = doc["playercnt"];
- if (arrayField.type() == bsoncxx::type::k_array)
- {
- bsoncxx::builder::basic::array array_wheel{};
- bsoncxx::array::view arrayView = arrayField.get_array();
- for (auto& element : arrayView)
- {
- ijptbet += element["jptbet"].get_int64();
- ijptwin += element["jptwin"].get_int64();
- ijptcnt += element["jptcnt"].get_int64();
- }
- }
- }
- }
- }
- }*/
|