#include "pch.h" #include "HttpSocket.h" #include "md5.h" mongocxx::instance g_instance{}; using namespace bsoncxx::builder::basic; bool comparegamelist(const rapidjson::Value& a, const rapidjson::Value& b) { if (!a.HasMember("SortID") || !strcmp(a["SortID"].GetString(), "-1")) return false; if (!b.HasMember("SortID") || !strcmp(b["SortID"].GetString(), "-1")) return true; std::string stra = a["SortID"].GetString(); std::string strb = b["SortID"].GetString(); if (stra.empty() || strb.empty()) { return false; } return std::stoi(a["SortID"].GetString()) < std::stoi(b["SortID"].GetString()); } HttpSocket::HttpSocket() { m_random = std::default_random_engine(time(NULL)); //数据库配置 { std::string strkkk3 = "mongodb://127.0.0.1:27017"; m_puri = boost::make_shared(strkkk3.c_str()); } m_pclient = boost::make_shared (*m_puri); m_platform = boost::make_shared(); m_pdb = boost::make_shared(); m_gamelog = boost::make_shared(); m_pvipuserdb = boost::make_shared(); m_pallindex = boost::make_shared(); m_pcoll = boost::make_shared(); m_plosewincoll = boost::make_shared(); m_pvipuser = boost::make_shared(); m_pplayuseronline = boost::make_shared(); m_userloginonline = boost::make_shared(); m_pusertradeinfo = boost::make_shared(); m_pviptradeinfo = boost::make_shared(); m_poperatinfo = boost::make_shared(); m_pvipscore = boost::make_shared(); m_pvipscoredate = boost::make_shared(); m_pvipuseraccounts = boost::make_shared(); m_puserdatainfo = boost::make_shared(); m_pthreeadmin = boost::make_shared(); m_pgameprizelog = boost::make_shared(); m_pvipconfigure = boost::make_shared(); m_pgamelist = boost::make_shared(); *m_pdb = (*m_pclient)["accounts"]; *m_gamelog = (*m_pclient)["gamelog"]; *m_platform = (*m_pclient)["platform"]; *m_pvipuserdb = (*m_pclient)["vipuser"]; *m_pallindex = (*m_pdb)["allindex"]; *m_pcoll = (*m_pdb)["userinfo"]; *m_plosewincoll = (*m_pdb)["losewin"]; *m_pgameprizelog = (*m_gamelog)["gameprizelog"]; *m_pvipuser = (*m_pvipuserdb)["user"]; *m_pplayuseronline = (*m_gamelog)["playuseronline"]; *m_userloginonline = (*m_gamelog)["userloginonline"]; *m_poperatinfo = (*m_gamelog)["operatinfo"]; *m_pusertradeinfo = (*m_pvipuserdb)["usertradeinfo"]; *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_pthreeadmin = (*m_pvipuserdb)["threeadmin"]; *m_pvipconfigure = (*m_pvipuserdb)["vipconfigure"]; *m_pgamelist = (*m_platform)["gamelist"]; //获取gamelist funcmsg fun1 = std::bind(&HttpSocket::getgamelist, this, std::placeholders::_1); m_callmsg.insert(make_pair("/api/game/gamelist", fun1)); } HttpSocket::~HttpSocket() { stopmsg(); } void HttpSocket::stopmsg() { } void HttpSocket::init() { try { makegamelist(m_staticdata); } catch (const std::exception&) { } } bool HttpSocket::postmsg(std::function funhttpmsg, std::map getdata) { try { std::string strtojson{}; auto& findkey = getdata.find("itype"); if (findkey != getdata.end()) { std::int32_t itype = funclib::strtonum(findkey->second); //玩家账号注册 if (itype == HTTPREGUSER) { strtojson = strtojson = regaccount(getdata); } //更新玩家分数 else if (itype == HTTPUPDATEUSERSCORE) { strtojson = updateuserscore(getdata); } //把玩家踢出游戏 else if (itype == HTTPADMINKICKUSER) { strtojson = adminhituser(getdata); } //管理员禁止管理员所属玩家 else if (itype == HTTPADMINPROHIBITUSER) { strtojson = adminforbiduser(getdata); } //获取账号 else if (itype == HTTPGETUSERACCOUNT) { strtojson = getuseraccount(getdata); } //修改玩家信息 else if (itype == HTTPMODIFYUSERPWD) { strtojson = modifyuserinfo(getdata); } //管理员禁止直属玩家 else if (itype == HTTPADMINPROHIBITMYUSER) { strtojson = adminforbidmyuser(getdata); } //查询充值记录 else if (itype == HTTPLOOKUPCZ) { strtojson = sellbuyinfo(getdata); } //查询每局游戏记录 else if (itype == HTTPLOOKUPPLAYGAME) { strtojson = playgameinfo(getdata); } //查询玩家总下注和总赢回 else if (itype == HTTPLOOKUPUSERPLAYSCORE) { strtojson = getuserplayscoreinfo(getdata); } //添加奖励码 else if (itype == HTTPLUPDATEUSERINGOT) { strtojson = updateuseringot(getdata); } //下奖励码 else if (itype == HTTPLBACKINGOT) { strtojson = backuseringot(getdata); } //查询用户总压注 else if (itype == HTTPLOOKUPALLUSERPLAYSCORE) { strtojson = getalluserplayscoreinfo(getdata); } else { return false; } funhttpmsg(strtojson); } else { const auto& findpathkey = getdata.find("path_key"); if (findpathkey != getdata.end()) { auto& funmsg = m_callmsg.find(findpathkey->second); if (funmsg != m_callmsg.end()) { try { strtojson = funmsg->second(getdata); } catch (std::exception& e) { //NEWLOG(INFO, "msglog") << e.what(); strtojson = ""; } } } funhttpmsg(strtojson); } } catch (std::exception& e) { } return true; } void HttpSocket::makegamelist(staticdata& tstaticdata) { tstaticdata = m_staticdata; tstaticdata.m_maparead.clear(); std::int32_t iareaid = 0; std::string strcode = ""; //auto findarea = m_pexechangerate->find({}); //for (const auto& doc : findarea) //{ // iareaid = doc["areaid"].get_int32(); // strcode = doc["code"].get_utf8().value.data(); // tstaticdata.m_maparead.insert(std::make_pair(iareaid, strcode)); //} //std::string strip{}; //boost::property_tree::ptree pt; //try //{ // boost::property_tree::ini_parser::read_ini("d:\\game\\config.ini", pt); // strip = pt.get("ip.wkey"); // //NEWLOG(INFO, "clienterro") << "ip=" << strip; //} //catch (const std::exception& e) //{ // //NEWLOG(INFO, "clienterro") << "ip=" << strip; //} //获取url std::int32_t iurlname = 9; auto findurl = make_document(kvp("name", iurlname)); auto urlinfo = m_pallindex->find_one(findurl.view()); if (urlinfo && urlinfo->view()["url"]) { tstaticdata.m_strgameurl = urlinfo->view()["url"].get_utf8().value.data(); } rapidjson::Document gamelist; gamelist.SetObject(); rapidjson::Document::AllocatorType& allocator = gamelist.GetAllocator(); rapidjson::Document subgame; subgame.SetObject(); rapidjson::Document::AllocatorType& suballocator = subgame.GetAllocator(); auto pgamelist = m_pgamelist->find_one({}); if (pgamelist) { std::string strgameicourl = ""; bsoncxx::document::view subdoc = pgamelist->view()["data"].get_document().value; if (subdoc["test"] && 1 == subdoc["test"].get_int32()) // 测试环境 tstaticdata.bTest = true; gamelist.AddMember("downloadurl", rapidjson::Value(subdoc["downloadurl"].get_utf8().value.data(), allocator), allocator); gamelist.AddMember("android_url", rapidjson::Value(subdoc["android_url"].get_utf8().value.data(), allocator), allocator); gamelist.AddMember("resversion", rapidjson::Value(subdoc["resversion"].get_utf8().value.data(), allocator), allocator); gamelist.AddMember("baseversion", rapidjson::Value(subdoc["baseversion"].get_utf8().value.data(), allocator), allocator); if (subdoc["zib"]) gamelist.AddMember("zib", subdoc["zib"].get_int32(), allocator); if (subdoc["s3"]) gamelist.AddMember("s3", rapidjson::Value(subdoc["s3"].get_utf8().value.data(), allocator), allocator); if (subdoc["uploadurl"]) { gamelist.AddMember("uploadurl", rapidjson::Value(subdoc["uploadurl"].get_utf8().value.data(), allocator), allocator); } if (subdoc["return_url"]) { tstaticdata.m_strreturnurl = subdoc["return_url"].get_utf8().value.data(); gamelist.AddMember("return_url", rapidjson::Value(tstaticdata.m_strreturnurl.c_str(), allocator), allocator); subgame.AddMember("return_url", rapidjson::Value(tstaticdata.m_strreturnurl.c_str(), allocator), allocator); } if (tstaticdata.bTest)//添加测试key gamelist.AddMember("key", rapidjson::Value("3F6AE262B8F2255EF7EB", allocator), allocator); if (subdoc["logurl"]) { tstaticdata.m_strlogurl = subdoc["logurl"].get_utf8().value.data(); gamelist.AddMember("logurl", rapidjson::Value(tstaticdata.m_strlogurl.c_str(), allocator), allocator); } if (subdoc["gameicourl"]) { strgameicourl = subdoc["gameicourl"].get_utf8().value.data(); tstaticdata.m_gameiconurl = strgameicourl; subgame.AddMember("gameicourl", rapidjson::Value(strgameicourl.c_str(), allocator), allocator); gamelist.AddMember("gameicourl", rapidjson::Value(strgameicourl.c_str(), allocator), allocator); } //创建数组 rapidjson::Value kindidArray(rapidjson::kArrayType); rapidjson::Value subgameArray(rapidjson::kArrayType); std::int32_t ikindid = 0; std::string strkindid{}; auto tempview = subdoc["gamelist"].get_array().value; for (const bsoncxx::array::element& msg : tempview) { if (msg.type() == bsoncxx::type::k_document) { bsoncxx::document::view ksubdoc = msg.get_document().value; rapidjson::Document subgamedoc; subgamedoc.SetObject(); rapidjson::Document::AllocatorType& ksubgamedocallocator = subgamedoc.GetAllocator(); rapidjson::Document kindiddoc; kindiddoc.SetObject(); rapidjson::Document::AllocatorType& kallocator = kindiddoc.GetAllocator(); strkindid = ksubdoc["KindID"].get_utf8().value.data(); kindiddoc.AddMember("KindID", rapidjson::Value(strkindid.c_str(), kallocator), kallocator); ikindid = 0; try { ikindid = std::stoi(strkindid); } catch (std::exception& e) { ikindid = 0; } std::string strkindname = ksubdoc["KindName"].get_utf8().value.data(); std::string strsubgid = ""; if (ksubdoc["GID"] && ikindid != 0) { strsubgid = ksubdoc["GID"].get_utf8().value.data(); if (strsubgid.empty()) continue; if (!strgameicourl.empty()) { std::string strgametype = ksubdoc["gametype"].get_utf8().value.data(); subgamedoc.AddMember("gid", rapidjson::Value(strsubgid.c_str(), ksubgamedocallocator), ksubgamedocallocator); subgamedoc.AddMember("name", rapidjson::Value(ksubdoc["KindName"].get_utf8().value.data(), ksubgamedocallocator), ksubgamedocallocator); subgamedoc.AddMember("gametype", rapidjson::Value(strgametype.c_str(), ksubgamedocallocator), ksubgamedocallocator); if (ksubdoc["SubLogo"]) { std::string strsubicon = ksubdoc["SubLogo"].get_utf8().value.data(); kindiddoc.AddMember("SubLogo", rapidjson::Value(strsubicon.c_str(), kallocator), kallocator); } } kindiddoc.AddMember("GID", rapidjson::Value(strsubgid.c_str(), kallocator), kallocator); } kindiddoc.AddMember("KindName", rapidjson::Value(strkindname.c_str(), kallocator), kallocator); kindiddoc.AddMember("ModuleName", rapidjson::Value(ksubdoc["ModuleName"].get_utf8().value.data(), kallocator), kallocator); kindiddoc.AddMember("ResVersion", rapidjson::Value(ksubdoc["ResVersion"].get_utf8().value.data(), kallocator), kallocator); if (ksubdoc["SortID"]) { kindiddoc.AddMember("SortID", rapidjson::Value(ksubdoc["SortID"].get_utf8().value.data(), kallocator), kallocator); subgamedoc.AddMember("SortID", rapidjson::Value(ksubdoc["SortID"].get_utf8().value.data(), ksubgamedocallocator), ksubgamedocallocator); } if (ksubdoc["hot"]) { subgamedoc.AddMember("hot", ksubdoc["hot"].get_int32(), ksubgamedocallocator); } if (ksubdoc["new"]) { subgamedoc.AddMember("new", ksubdoc["new"].get_int32(), ksubgamedocallocator); } if (ksubdoc["brand"]) { std::string sbrand = ksubdoc["brand"].get_utf8().value.data(); kindiddoc.AddMember("brand", rapidjson::Value(sbrand.c_str(), kallocator), kallocator); subgamedoc.AddMember("brand", rapidjson::Value(sbrand.c_str(), ksubgamedocallocator), ksubgamedocallocator); } if (subdoc["gametype"]) { kindiddoc.AddMember("gametype", rapidjson::Value(ksubdoc["gametype"].get_utf8().value.data(), kallocator), kallocator); } if (ksubdoc["SubLogo"]) { kindiddoc.AddMember("SubLogo", rapidjson::Value(ksubdoc["SubLogo"].get_utf8().value.data(), kallocator), kallocator); subgamedoc.AddMember("SubLogo", rapidjson::Value(ksubdoc["SubLogo"].get_utf8().value.data(), ksubgamedocallocator), ksubgamedocallocator); } //把文档加入数组 rapidjson::Value element(rapidjson::kObjectType); element.CopyFrom(kindiddoc, allocator); kindidArray.PushBack(element, allocator); rapidjson::Value subgameelement(rapidjson::kObjectType); subgameelement.CopyFrom(subgamedoc, suballocator); subgameArray.PushBack(subgameelement, suballocator); if (subgamedoc.HasMember("gid")) { std::string strGid = subgamedoc["gid"].GetString(); // 序列化JSON对象到StringBuffer rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); subgamedoc.Accept(writer); tstaticdata.m_mapregiongame[strGid] = std::string(buffer.GetString()); } } } rapidjson::Document sortedkindidArray; sortedkindidArray.SetArray(); // 排序 { std::vector gameListVector; for (int i = 0; i < kindidArray.Size(); ++i) { gameListVector.push_back(&kindidArray[i]); } std::sort(gameListVector.begin(), gameListVector.end(), [](const rapidjson::Value* a, const rapidjson::Value* b) { return comparegamelist(*a, *b); }); for (const rapidjson::Value* game : gameListVector) { if (!game->HasMember("GID")) continue; rapidjson::Value element(rapidjson::kObjectType); element.CopyFrom(*game, allocator); sortedkindidArray.PushBack(element, allocator); } } gamelist.AddMember("gamelist", sortedkindidArray, allocator); rapidjson::Document sortedsubgameArray; sortedsubgameArray.SetArray(); // 排序 { std::vector gameListVector; for (int i = 0; i < subgameArray.Size(); ++i) { gameListVector.push_back(&subgameArray[i]); } std::sort(gameListVector.begin(), gameListVector.end(), [](const rapidjson::Value* a, const rapidjson::Value* b) { return comparegamelist(*a, *b); }); for (const rapidjson::Value* game : gameListVector) { rapidjson::Value element(rapidjson::kObjectType); element.CopyFrom(*game, suballocator); sortedsubgameArray.PushBack(element, suballocator); } } subgame.AddMember("gamelist", sortedsubgameArray, suballocator); subgame.AddMember("gameurl", rapidjson::Value(tstaticdata.m_strgameurl.c_str(), allocator), suballocator); } gamelist.AddMember("shareurl", rapidjson::Value(tstaticdata.m_strgameurl.c_str(), allocator), allocator); std::string strgamelist = funclib::doctojson(gamelist); tstaticdata.m_strsubgame = funclib::doctojson(subgame); std::stringstream strsss; std::string strbase64encode; funclib::Base64Encode(strgamelist, strbase64encode); byte tbyte; byte ttemp; std::deque bstemp; bstemp.clear(); for (auto tchar : strbase64encode) { tbyte = tchar; tbyte = ~tbyte; ttemp = tbyte; tbyte = ((ttemp & 0xf0) >> 4) | ((tbyte & 0x0f) << 4); bstemp.push_front(tbyte); } std::stringstream sss; for (auto& tchar : bstemp) { strsss << tchar; } tstaticdata.m_strgamelist = strsss.str(); if (!tstaticdata.bTest) // 正式环境屏蔽接口 { m_callmsg.erase("/api/game/popularizesit"); m_callmsg.erase("/api/game/popularizelogin"); m_callmsg.erase("/api/game/popularizegetkey"); m_callmsg.erase("/api/game/popularizegetcurrency"); } return; } //获得游戏列表 std::string HttpSocket::getgamelist(std::map getdata) { return m_staticdata.m_strgamelist; } std::string HttpSocket::getuseraccount(std::int32_t iregion) { std::string straccount = ""; __int32 iac = 0; for (iac = 0; iac < 10000; iac++) { std::stringstream strtempaccount; std::stringstream strnum; if (iregion > 0 && iregion < 10) { strtempaccount << "0" << iregion; } else { strtempaccount << iregion; } std::uniform_int_distribution<__int64> disrand(1, 100000000); __int64 irand = disrand(m_random); strnum << irand; __int32 ilen = strnum.str().length(); ilen = 8 - ilen; for (int i = 0; i < ilen; i++) { strtempaccount << "0"; } strtempaccount << strnum.str(); auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << strtempaccount.str().c_str() << bsoncxx::builder::stream::finalize); if (finduser) { continue; } straccount = strtempaccount.str(); return straccount; } return straccount; } //玩家账号注册 std::string HttpSocket::regaccount(std::map getdata) { reguser treguser; getvaluedata(getdata, treguser); std::string strret{}; bool bret = treguser.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } std::string strspreadername; std::string strspreaderaccount; std::string straccount = ""; std::string strpwd = ""; std::string strloginpwd = ""; std::string strmobilephone = treguser.phone; std::string strname = treguser.name; std::string strinfo = treguser.info; std::string struserip; std::string strspreaderip; std::string registerip = "127.0.0.1"; std::string strspreaderidall; std::stringstream sss; __int64 inserttime = funclib::gettimestamp(); __int64 ilocaltime = funclib::getlocaltimestamp(); __int32 iregion = 1; __int64 iscore = treguser.score; __int64 beforespreaderscore = 0; __int64 afterspreaderscore = 0; __int64 adminuserid = 0; __int64 ispreaderid = 0; std::int32_t iareaid = 0; //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << treguser.authcode.c_str() \ << "authkey" << treguser.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"] || !threeadmin->view()["region"]) { strret = funclib::rettojson(5, "adminuserid or region exist"); return strret; } adminuserid = threeadmin->view()["adminuserid"].get_int64(); iregion = threeadmin->view()["region"].get_int32(); ispreaderid = adminuserid; auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { straccount += " spreaderid isnot exist"; strret = funclib::rettojson(5, straccount); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"] && vipuser->view()["areaid"]) { vipstate = vipuser->view()["state"].get_int32(); iareaid = vipuser->view()["areaid"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } //查询第三方平台开通的空账号当天数量不超过1000个 std::int64_t ilogondate = ilocaltime / 86400000 * 86400000; ilogondate = funclib::getlocaltounixstamp(ilogondate); auto findusernull = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("spreaderid", adminuserid), (bsoncxx::builder::basic::kvp("registerlogonip", registerip.c_str())), bsoncxx::builder::basic::kvp("registerdate", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$gte", ilogondate)))); std::int64_t iusernull = m_pcoll->count_documents(findusernull.view()); if (iusernull > 1000) { strret = funclib::rettojson(10, "create use num erro"); return strret; } for (int i = 0; i < 6; i++) { std::uniform_int_distribution<__int32> disrand(1, 61); __int64 irand = disrand(m_random); strpwd += g_chars.at(irand); } strloginpwd = strpwd; //获取新账号 straccount = getuseraccount(iregion); if (straccount == "") { strret = funclib::rettojson(1, "account create erro"); return strret; } if (iscore < 0) { strret = funclib::rettojson(1, "user score must greater than or equal to zero"); return strret; } __int32 izero32 = 0; __int64 izero64 = 0; __int64 userid = 0; __int64 gameid = 0; __int64 ione64 = 1; std::string strmac = "11111111111111111111111111111111"; struserip = registerip; MD5 tempMD5(strpwd); strpwd = tempMD5.toStrUpper(); __int32 iname = 2; __int64 iinc = 1; //获取索引 auto criteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("name", iname)); auto update = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("useridindex", iinc))), bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("gameidindex", iinc)))); auto newtemp = m_pallindex->find_one_and_update(criteria.view(), update.view()); if (newtemp && newtemp->view()["useridindex"] && newtemp->view()["gameidindex"]) { userid = newtemp->view()["useridindex"].get_int64(); gameid = newtemp->view()["gameidindex"].get_int64(); } else { strret = funclib::rettojson(1, "userid create erro"); return strret; } auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "userid" << userid << bsoncxx::builder::stream::finalize); auto findlosewin = m_plosewincoll->find_one(bsoncxx::builder::stream::document{} << "userid" << userid << bsoncxx::builder::stream::finalize); if (finduser) { strret = funclib::rettojson(2, "userid is exist"); return strret; } if (findlosewin) { strret = funclib::rettojson(3, "user losewin exist"); return strret; } auto findaccount = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << straccount.c_str() << bsoncxx::builder::stream::finalize); if (findaccount) { strret = funclib::rettojson(4, " account is exist"); return strret; } if (!vipuser->view()["score"] || !vipuser->view()["name"] || !vipuser->view()["account"] || !vipuser->view()["loginip"]) { strret = funclib::rettojson(4, " account is exist1"); return strret; } __int64 ivipscore = vipuser->view()["score"].get_int64(); beforespreaderscore = ivipscore; strspreadername = vipuser->view()["name"].get_utf8().value.data(); strspreaderaccount = vipuser->view()["account"].get_utf8().value.data(); strspreaderip = vipuser->view()["loginip"].get_utf8().value.data(); //生成时给玩家加分 if (iscore > 0) { if (ivipscore < iscore) { strret = funclib::rettojson(6, "your spreader score is not enough"); return strret; } afterspreaderscore = beforespreaderscore - iscore; ivipscore = -1 * iscore; } else iscore = 0; //代理树添加 sss << ","; sss << ispreaderid; while (ispreaderid != 0) { auto findvip = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << ispreaderid << bsoncxx::builder::stream::finalize); if (findvip) { ispreaderid = findvip->view()["spreaderid"].get_int64(); sss << ","; sss << ispreaderid; } } sss << ","; strspreaderidall = sss.str(); //玩家基本信息插入缓存 auto userbuilder = bsoncxx::builder::stream::document{}; userbuilder << "userid" << userid << "gameid" << gameid << "areaid" << iareaid << "devicetype" << izero32 << "name" << strname.c_str() << "state" << izero32 << "usertype" << izero32 << "userright" << izero32 << "score" << iscore << "insurescore" << izero64 << "spreaderid" << adminuserid << "spreaderidall" << strspreaderidall.c_str() << "logontime" << izero64 << "account" << straccount.c_str() << "nickname" << straccount.c_str() << "faceid" << izero32 << "logonpwd" << strpwd.c_str() << "insurepwd" << strpwd.c_str() << "lastlogonmachineid" << strmac.c_str() << "regstermachineid" << strmac.c_str() << "lastlogonip" << registerip.c_str() << "registerlogonip" << registerip.c_str() << "registerdate" << inserttime << "dynamicpass" << strmac.c_str() << "mobilephone" << strmobilephone.c_str() << "info" << strinfo.c_str(); try { auto resultuser = m_pcoll->insert_one(userbuilder.view()); if (!resultuser) { strret = funclib::rettojson(8, "user create erro"); return strret; } } catch (const std::exception&) { strret = funclib::rettojson(8, "user create erro, account already exists"); return strret; } __int64 irechargetime = ilocaltime / (24 * 60 * 60 * 1000); irechargetime *= (24 * 60 * 60 * 1000); auto builder = bsoncxx::builder::stream::document{}; builder << "userid" << userid << "todaylwscore" << izero64 << "twolwscore" << izero64 << "threelwscore" << izero64 << "alllwscore" << izero64 << "todayczscore" << izero64 << "totalczscore" << izero64 << "totalxfscore" << izero64 << "lwupdatelwtime" << inserttime << "rechargetime" << irechargetime << "pointcontrolcount" << izero64 << "pointcompelettime" << izero64 << "registertime" << inserttime; auto result = m_plosewincoll->insert_one(builder.view()); if (!result) { m_pcoll->delete_one(bsoncxx::builder::stream::document{} << "userid" << userid << bsoncxx::builder::stream::finalize); strret = funclib::rettojson(9, "user create erro"); return strret; } //写注册日志 auto findlogtime = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", irechargetime)); auto findlogset = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("regnum", ione64)))); mongocxx::options::find_one_and_update options; options.upsert(true); m_puserdatainfo->find_one_and_update(findlogtime.view(), findlogset.view(), options); if (iscore > 0) { auto vipcriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", adminuserid)); auto vipupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", ivipscore)))); auto vipretscore = m_pvipuser->find_one_and_update(vipcriteria.view(), vipupdate.view()); if (!vipretscore) { strret = funclib::rettojson(7, "modify score erro"); return strret; } //记录充值分数 auto rechargecriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", userid)); auto rechargeupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalczscore", iscore))), bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("todayczscore", iscore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("rechargetime", ilocaltime)))); m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view()); __int64 iOne32 = 1; auto vipscorecriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("business", iOne32)); auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("sellscore", iscore)))); mongocxx::options::find_one_and_update options; options.upsert(true); auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options); if (vipscore) { if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"]) { __int64 sellscore = vipscore->view()["sellscore"].get_int64(); __int64 buyscore = vipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += iscore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view()); } } } __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000); inserttimetemp *= (24 * 60 * 60 * 1000); auto vipscoredate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", inserttimetemp)); auto vipscoredateupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("sellscore", iscore)))); auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options); if (retvipscore) { if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"]) { __int64 sellscore = retvipscore->view()["sellscore"].get_int64(); __int64 buyscore = retvipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += iscore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view()); } } } //生成转账记录 __int32 itype = 1; auto builder = bsoncxx::builder::stream::document{}; builder << "userid" << userid << "name" << strname.c_str() << "useraccount" << straccount.c_str() << "userip" << struserip.c_str() << "spreaderid" << adminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str() << "spreaderip" << strspreaderip.c_str() << "beforeuserscore" << izero64 << "beforespreaderscore" << beforespreaderscore << "afteruserscore" << iscore << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << iscore << "inserttime" << inserttime; m_pusertradeinfo->insert_one(builder.view()); } //生成成功 rapidjson::Document doc; doc.SetObject(); rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); doc.AddMember("ret", -1, allocator); doc.AddMember("account", rapidjson::Value(straccount.c_str(), allocator), allocator); doc.AddMember("name", rapidjson::Value(strname.c_str(), allocator), allocator); doc.AddMember("pwd", rapidjson::Value(strloginpwd.c_str(), allocator), allocator); strret = funclib::doctojson(doc); return strret; } //玩家更新分数 std::string HttpSocket::updateuserscore(std::map getdata) { userscore tuserscore; getvaluedata(getdata, tuserscore); std::string strret{}; auto findscore = getdata.find("score"); if (findscore == getdata.end()) { strret = funclib::rettojson(10, "param erro"); return strret; } std::int32_t iret = 0; tuserscore.score = stringToint64_t(findscore->second, iret); if (iret == -1) { strret = funclib::rettojson(10, "param erro"); return strret; } bool bret = tuserscore.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } __int32 ione32 = 1; //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tuserscore.authcode.c_str() \ << "authkey" << tuserscore.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } std::int64_t adminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } if (!vipuser->view()["score"]) { strret = funclib::rettojson(10, "score isnot exist"); return strret; } __int64 iuserid = 0; __int64 inserttime = funclib::gettimestamp(); __int64 ilocaltime = funclib::getlocaltimestamp(); __int64 vipscore = vipuser->view()["score"].get_int64(); __int64 beforeuserscore = 0; __int64 useringot = 0; __int64 beforespreaderscore = 0; __int64 afteruserscore = 0; __int64 afterspreaderscore = 0; __int64 tradescore = 0; // type=1商家送分给玩家;type=2商家给玩家收分 __int32 itype = 0; std::string strusername; std::string struseraccount; std::string struserip; std::string strspreadername; std::string strspreaderaccount; std::string strspreaderip; //商家送分 if (tuserscore.score < 0) { //可以赠送 if (vipscore + tuserscore.score >= 0) { //用户不存在不减商家的分数 auto firstuser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tuserscore.account.c_str() << bsoncxx::builder::stream::finalize); if (!firstuser) { strret = funclib::rettojson(11, "user is not exist"); return strret; } if (!firstuser->view()["score"] || !firstuser->view()["name"] || !firstuser->view()["account"] || !firstuser->view()["lastlogonip"] || !firstuser->view()["userid"]) { strret = funclib::rettojson(11, "user is not exist"); return strret; } beforeuserscore = firstuser->view()["score"].get_int64(); strusername = firstuser->view()["name"].get_utf8().value.data(); struseraccount = firstuser->view()["account"].get_utf8().value.data(); struserip = firstuser->view()["lastlogonip"].get_utf8().value.data(); iuserid = firstuser->view()["userid"].get_int64(); //减商家分数 auto criteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", adminuserid)); auto update = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", tuserscore.score)))); auto retscore = m_pvipuser->find_one_and_update(criteria.view(), update.view()); if (!retscore) { strret = funclib::rettojson(12, "modify score erro"); return strret; } if (!retscore->view()["score"] || !retscore->view()["name"] || !retscore->view()["account"] || !retscore->view()["loginip"]) { strret = funclib::rettojson(12, "modify score erro1"); return strret; } beforespreaderscore = retscore->view()["score"].get_int64(); strspreadername = retscore->view()["name"].get_utf8().value.data(); strspreaderaccount = retscore->view()["account"].get_utf8().value.data(); strspreaderip = retscore->view()["loginip"].get_utf8().value.data(); afterspreaderscore = beforespreaderscore + tuserscore.score; //加用户分数 tuserscore.score = -1 * tuserscore.score; tradescore = tuserscore.score; auto usercriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", iuserid)); auto userupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", tuserscore.score)))); auto userretscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view()); if (!userretscore) { strret = funclib::rettojson(13, "add user score erro"); return strret; } __int64 iOne32 = 1; auto vipscorecriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("business", iOne32)); auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("sellscore", tradescore)))); mongocxx::options::find_one_and_update options; options.upsert(true); auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options); if (vipscore) { if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"]) { __int64 sellscore = vipscore->view()["sellscore"].get_int64(); __int64 buyscore = vipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += tradescore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view()); } } } __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000); inserttimetemp *= (24 * 60 * 60 * 1000); auto vipscoredate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", inserttimetemp)); auto vipscoredateupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("sellscore", tradescore)))); auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options); if (retvipscore) { if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"]) { __int64 sellscore = retvipscore->view()["sellscore"].get_int64(); __int64 buyscore = retvipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += tradescore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view()); } } } //记录充值分数 auto rechargecriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", iuserid)); auto findlw = m_plosewincoll->find_one(rechargecriteria.view()); if (findlw) { //判断清除当天充值属性 __int64 irechargetime = 0; if (findlw->view()["rechargetime"]) { irechargetime = findlw->view()["rechargetime"].get_int64(); } irechargetime /= (24 * 60 * 60 * 1000); irechargetime *= (24 * 60 * 60 * 1000); if (irechargetime != inserttimetemp) { auto rechargeupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalczscore", tradescore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("todayczscore", tradescore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("rechargetime", ilocaltime)))); m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view()); } else { auto rechargeupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalczscore", tradescore))), bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("todayczscore", tradescore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("rechargetime", ilocaltime)))); m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view()); } } else { auto rechargeupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalczscore", tradescore))), bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("todayczscore", tradescore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("rechargetime", ilocaltime)))); m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view()); } afteruserscore = beforeuserscore + tuserscore.score; //生成转账记录 itype = 1; auto builder = bsoncxx::builder::stream::document{}; builder << "userid" << iuserid << "name" << strusername.c_str() << "useraccount" << struseraccount.c_str() << "userip" << struserip.c_str() << "spreaderid" << adminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str() << "spreaderip" << strspreaderip.c_str() << "beforeuserscore" << beforeuserscore << "beforespreaderscore" << beforespreaderscore << "afteruserscore" << afteruserscore << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << tradescore << "inserttime" << inserttime; m_pusertradeinfo->insert_one(builder.view()); } else { strret = funclib::rettojson(14, "business score isnot enough"); return strret; } auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); auto loginoline = m_userloginonline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (loginoline && loginoline->view()["contextid"] && loginoline->view()["userip"]) { //通知游戏更新分数 CMD_CS_C_UpdateScoreEx tempUpdateScore; ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore)); tempUpdateScore.dwUserID = iuserid; tempUpdateScore.addscore = tuserscore.score; std::string strloginip{}; tempUpdateScore.dwLoginContextID = loginoline->view()["contextid"].get_int64(); strloginip = loginoline->view()["userip"].get_utf8().value.data(); m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore)); } if (useroline && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"]) { //通知游戏更新分数 CMD_CS_C_UpdateScoreEx tempUpdateScore; ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore)); tempUpdateScore.dwUserID = iuserid; tempUpdateScore.addscore = tuserscore.score; std::string strloginip{}; tempUpdateScore.wgameserverid = useroline->view()["serverid"].get_int32(); tempUpdateScore.dwGameContextID = useroline->view()["contextid"].get_int64(); strloginip = useroline->view()["userip"].get_utf8().value.data(); m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore)); } strret = funclib::rettojson(-1, "ok"); return strret; } //商家收分 if (tuserscore.score > 0) { auto finddisablebuyscore = m_pvipconfigure->find_one(bsoncxx::builder::stream::document{} << "disablebuyscore" << ione32 << bsoncxx::builder::stream::finalize); if (finddisablebuyscore) { if (finddisablebuyscore->view()["disablebuyscore"]) { __int32 idisablebuyscore = finddisablebuyscore->view()["disablebuyscore"].get_int32(); if (idisablebuyscore == 1) { strret = funclib::rettojson(15, "tricky bugs occured, please try again later!"); return strret; } } } //用户不存在不能下分 auto userretscore = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tuserscore.account.c_str() << bsoncxx::builder::stream::finalize); if (!userretscore || !userretscore->view()["userid"]) { strret = funclib::rettojson(16, "user isnot exist"); return strret; } iuserid = userretscore->view()["userid"].get_int64(); //玩家在玩游戏不能下分 auto vipuser = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (vipuser) { strret = funclib::rettojson(15, "user is playing"); return strret; } if (!userretscore->view()["score"] || !userretscore->view()["account"] || !userretscore->view()["lastlogonip"]) { strret = funclib::rettojson(15, "user is playing1"); return strret; } //分数不够不能下分 beforeuserscore = userretscore->view()["score"].get_int64(); //获取奖励码 if (userretscore->view()["ingot"]) { useringot = userretscore->view()["ingot"].get_int64(); } //用真实分数减去奖励码分数得到真实能下分数 useringot = beforeuserscore - useringot; if (useringot < tuserscore.score) { strret = funclib::rettojson(17, "user score is not enough"); return strret; } strusername = userretscore->view()["name"].get_utf8().value.data(); struseraccount = userretscore->view()["account"].get_utf8().value.data(); struserip = userretscore->view()["lastlogonip"].get_utf8().value.data(); //商家不存在不能减用户的分 auto firstadmin = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize); if (!firstadmin) { strret = funclib::rettojson(18, "business is not exist"); return strret; } if (!firstadmin->view()["score"] || !firstadmin->view()["name"] || !firstadmin->view()["account"] || !firstadmin->view()["loginip"]) { strret = funclib::rettojson(18, "business is not exist1"); return strret; } beforespreaderscore = firstadmin->view()["score"].get_int64(); strspreadername = firstadmin->view()["name"].get_utf8().value.data(); strspreaderaccount = firstadmin->view()["account"].get_utf8().value.data(); strspreaderip = firstadmin->view()["loginip"].get_utf8().value.data(); //减用户分数 tuserscore.score = -1 * tuserscore.score; auto usercriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", iuserid)); auto userupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", tuserscore.score)))); auto tempscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view()); if (!tempscore) { strret = funclib::rettojson(19, "reduce user score erro"); return strret; } afteruserscore = beforeuserscore + tuserscore.score; //增加商家的分数 tuserscore.score = -1 * tuserscore.score; tradescore = tuserscore.score; //添加玩家总下分 auto xiafenupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalxfscore", tradescore)))); m_plosewincoll->find_one_and_update(usercriteria.view(), xiafenupdate.view()); auto admincriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", adminuserid)); auto adminupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", tradescore)))); auto adminretscore = m_pvipuser->find_one_and_update(admincriteria.view(), adminupdate.view()); if (!adminretscore) { strret = funclib::rettojson(20, "add business score erro"); return strret; } __int64 iOne32 = 1; auto vipscorecriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("business", iOne32)); auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buyscore", tradescore)))); mongocxx::options::find_one_and_update options; options.upsert(true); auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options); if (vipscore) { if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"]) { __int64 sellscore = vipscore->view()["sellscore"].get_int64(); __int64 buyscore = vipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += tradescore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view()); } } } __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000); inserttimetemp *= (24 * 60 * 60 * 1000); auto vipscoredate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", inserttimetemp)); auto vipscoredateupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buyscore", tradescore)))); auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options); if (retvipscore) { if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"]) { __int64 sellscore = retvipscore->view()["sellscore"].get_int64(); __int64 buyscore = retvipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += tradescore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view()); } } } afterspreaderscore = beforespreaderscore + tuserscore.score; //生成交易记录 itype = 2; auto builder = bsoncxx::builder::stream::document{}; builder << "userid" << iuserid << "name" << strusername.c_str() << "useraccount" << struseraccount.c_str() << "userip" << struserip.c_str() << "spreaderid" << adminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str() << "spreaderip" << strspreaderip.c_str() << "beforeuserscore" << beforeuserscore << "beforespreaderscore" << beforespreaderscore << "afteruserscore" << afteruserscore << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << tradescore << "inserttime" << inserttime; auto result = m_pusertradeinfo->insert_one(builder.view()); auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); auto loginoline = m_userloginonline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (loginoline && loginoline->view()["contextid"] && loginoline->view()["userip"]) { //通知游戏更新分数 bool bfind = false; CMD_CS_C_UpdateScoreEx tempUpdateScore; ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore)); tempUpdateScore.dwUserID = iuserid; tempUpdateScore.addscore = tradescore * -1; std::string strloginip{}; tempUpdateScore.dwLoginContextID = loginoline->view()["contextid"].get_int64(); strloginip = loginoline->view()["userip"].get_utf8().value.data(); m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore)); } if (useroline && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"]) { //通知游戏更新分数 bool bfind = false; CMD_CS_C_UpdateScoreEx tempUpdateScore; ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore)); tempUpdateScore.dwUserID = iuserid; tempUpdateScore.addscore = tradescore * -1; std::string strloginip{}; tempUpdateScore.wgameserverid = useroline->view()["serverid"].get_int32(); tempUpdateScore.dwGameContextID = useroline->view()["contextid"].get_int64(); strloginip = useroline->view()["userip"].get_utf8().value.data(); m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore)); } } //收分成功 strret = funclib::rettojson(-1, "ok"); return strret; } //把玩家踢出游戏 std::string HttpSocket::adminhituser(std::map getdata) { kickuser tkickuser; getvaluedata(getdata, tkickuser); std::string strret{}; bool bret = tkickuser.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } __int64 userspreadid = 0; __int64 userid = 0; auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tkickuser.acc.c_str() << bsoncxx::builder::stream::finalize); if (!finduser) { strret = funclib::rettojson(31, "the user is not exist"); return strret; } if (!finduser->view()["spreaderid"]) { strret = funclib::rettojson(31, "the spreaderid is not exist"); return strret; } if (!finduser->view()["userid"]) { strret = funclib::rettojson(31, "the user is not exist"); return strret; } userspreadid = finduser->view()["spreaderid"].get_int64(); userid = finduser->view()["userid"].get_int64(); //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tkickuser.authcode.c_str() \ << "authkey" << tkickuser.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } std::int64_t adminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } if (adminuserid != userspreadid || userspreadid == 0) { strret = funclib::rettojson(32, "the business is not exist"); return strret; } auto finduserview = make_document(kvp("userid", userid)); auto useroline = m_pplayuseronline->find_one(finduserview.view()); bool bfind = false; if (useroline && useroline->view()["userid"] && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"]) { std::string strloginip{}; CMD_CS_C_DelOnlineUser tDelOnlineUser; ZeroMemory(&tDelOnlineUser, sizeof(tDelOnlineUser)); tDelOnlineUser.dwUserID = useroline->view()["userid"].get_int64(); tDelOnlineUser.wserverid = useroline->view()["serverid"].get_int32(); tDelOnlineUser.dwGameContextID = useroline->view()["contextid"].get_int64(); strloginip = useroline->view()["userip"].get_utf8().value.data(); m_gamemsg(strloginip, &tDelOnlineUser, sizeof(tDelOnlineUser)); } else { strret = funclib::rettojson(10, "server param erro"); return strret; } //m_pplayuseronline->delete_many(bsoncxx::builder::stream::document{} << "userid" << pkickuser->userid << bsoncxx::builder::stream::finalize); //删除成功 strret = funclib::rettojson(-1, "ok"); return strret; } //管理员禁止管理员所属玩家 std::string HttpSocket::adminforbiduser(std::map getdata) { prohibituser tprohibituser; getvaluedata(getdata, tprohibituser); std::string strret{}; bool bret = tprohibituser.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } __int64 adminuserid = 0; //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tprohibituser.authcode.c_str() \ << "authkey" << tprohibituser.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } adminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } auto userupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("state", tprohibituser.state)))); //禁止自己玩家 m_pcoll->update_one(bsoncxx::builder::stream::document{} << "spreaderid" << adminuserid << "account" << tprohibituser.account.c_str() << bsoncxx::builder::stream::finalize, userupdate.view()); //操作成功 strret = funclib::rettojson(-1, "ok"); return strret; } //获取账号 std::string HttpSocket::getuseraccount(std::map getdata) { getaccount tgetaccount; getvaluedata(getdata, tgetaccount); std::string strret{}; bool bret = tgetaccount.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } __int64 ispreaderid = 0; __int64 iadminuserid = 0; __int64 iuserid = 0; __int64 iregistertime = 0; __int64 iloginlasttime = 0; __int64 iscore = 0; __int64 iingot = 0; std::string strscore; std::string stringot; __int32 istate = 0; rapidjson::Document doc; doc.SetObject(); rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); doc.AddMember("ret", -1, allocator); //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tgetaccount.authcode.c_str() \ << "authkey" << tgetaccount.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } iadminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tgetaccount.account.c_str() << bsoncxx::builder::stream::finalize); if (!finduser) { strret = funclib::rettojson(1, "the account is not exist"); return strret; } if (!finduser->view()["spreaderid"]) { strret = funclib::rettojson(1, "the account is not exist1"); return strret; } ispreaderid = finduser->view()["spreaderid"].get_int64(); if (ispreaderid != iadminuserid) { strret = funclib::rettojson(1, "the account is not belong to you"); return strret; } if (!finduser->view()["userid"]) { strret = funclib::rettojson(1, "the account is not exist2"); return strret; } iuserid = finduser->view()["userid"].get_int64(); std::string onlinestatus = "0"; auto findonline = m_userloginonline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (findonline) { onlinestatus = "1"; } auto findplayonline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (findplayonline) { onlinestatus = "2"; } doc.AddMember("onlinestatus", rapidjson::Value(onlinestatus.c_str(), allocator), allocator); auto findlosewin = m_plosewincoll->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (!findlosewin) { strret = funclib::rettojson(1, "the account is not exist"); return strret; } iregistertime = 0; if (findlosewin->view()["registertime"]) { iregistertime = findlosewin->view()["registertime"].get_int64(); } std::string straccount{}; if (finduser->view()["account"]) { straccount = finduser->view()["account"].get_utf8().value.data(); doc.AddMember("account", rapidjson::Value(straccount.c_str(), allocator), allocator); } std::string strname{}; if (finduser->view()["name"]) { strname = finduser->view()["name"].get_utf8().value.data(); doc.AddMember("name", rapidjson::Value(strname.c_str(), allocator), allocator); } std::string strregtime = ""; if (iregistertime >= 0) { strregtime = funclib::gettimefromstamp(iregistertime); doc.AddMember("regtime", rapidjson::Value(strregtime.c_str(), allocator), allocator); } iingot = 0; if (finduser->view()["ingot"]) { iingot = finduser->view()["ingot"].get_int64(); } stringot = getdouble(iingot); iscore = 0; if (finduser->view()["score"]) { iscore = finduser->view()["score"].get_int64(); iscore -= iingot; } strscore = getdouble(iscore); istate = 0; if (finduser->view()["state"]) { istate = finduser->view()["state"].get_int32(); } doc.AddMember("ingot", rapidjson::Value(stringot.c_str(), allocator), allocator); doc.AddMember("score", rapidjson::Value(strscore.c_str(), allocator), allocator); if (!istate) { doc.AddMember("state", rapidjson::Value("0", allocator), allocator); } else { doc.AddMember("state", rapidjson::Value("1", allocator), allocator); } std::string strmemo{}; if (finduser->view()["info"]) { strmemo = finduser->view()["info"].get_utf8().value.data(); } doc.AddMember("memo", rapidjson::Value(strmemo.c_str(), allocator), allocator); std::string strregip{}; if (finduser->view()["registerlogonip"]) { strregip = finduser->view()["registerlogonip"].get_utf8().value.data(); } doc.AddMember("regip", rapidjson::Value(strregip.c_str(), allocator), allocator); iloginlasttime = 0; if (finduser->view()["logontime"]) { iloginlasttime = finduser->view()["logontime"].get_int64(); } std::string strloginlasttime = ""; if (iloginlasttime >= 0) { strloginlasttime = funclib::gettimefromstamp(iloginlasttime); } doc.AddMember("loginlasttime", rapidjson::Value(strloginlasttime.c_str(), allocator), allocator); std::string strloginip{}; if (finduser->view()["lastlogonip"]) { strloginip = finduser->view()["lastlogonip"].get_utf8().value.data(); } doc.AddMember("loginip", rapidjson::Value(strloginip.c_str(), allocator), allocator); std::string strremark{}; if (finduser->view()["regstermachineid"]) { strremark = finduser->view()["regstermachineid"].get_utf8().value.data(); } doc.AddMember("remark", rapidjson::Value(strremark.c_str(), allocator), allocator); //操作成功 strret = funclib::doctojson(doc); return strret; } //修改下级玩家信息 std::string HttpSocket::modifyuserinfo(std::map getdata) { userinfo tuserinfo; getvaluedata(getdata, tuserinfo); std::string strret{}; bool bret = tuserinfo.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tuserinfo.authcode.c_str() \ << "authkey" << tuserinfo.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } __int64 iadminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } auto findone = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "spreaderid" << iadminuserid << "account" << tuserinfo.account.c_str() << bsoncxx::builder::stream::finalize); if (!findone) { strret = funclib::rettojson(0, "the account is not belong to you"); return strret; } if (!tuserinfo.pwd.empty()) { MD5 tempMD5(tuserinfo.pwd); tuserinfo.pwd = tempMD5.toStrUpper(); //修改下级玩家信息 m_pcoll->update_one(bsoncxx::builder::stream::document{} << "spreaderid" << iadminuserid << "account" << tuserinfo.account.c_str() << bsoncxx::builder::stream::finalize, bsoncxx::builder::stream::document{} << "$set" << bsoncxx::builder::stream::open_document << "logonpwd" << tuserinfo.pwd.c_str() << bsoncxx::builder::stream::close_document << bsoncxx::builder::stream::finalize); } strret = funclib::rettojson(-1, "ok"); return strret; } //管理员禁止自己直属玩家 std::string HttpSocket::adminforbidmyuser(std::map getdata) { adminprohibituser tadminprohibituser; getvaluedata(getdata, tadminprohibituser); std::string strret{}; bool bret = tadminprohibituser.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tadminprohibituser.authcode.c_str() \ << "authkey" << tadminprohibituser.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } std::int64_t adminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } auto userupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("state", tadminprohibituser.state)))); //禁止自己玩家 m_pcoll->update_many(bsoncxx::builder::stream::document{} << "spreaderid" << adminuserid << bsoncxx::builder::stream::finalize, userupdate.view()); strret = funclib::rettojson(-1, "ok"); return strret; } //查询充值记录 std::string HttpSocket::sellbuyinfo(std::map getdata) { sellbuyscoreinfo tsellbuyscoreinfo; getvaluedata(getdata, tsellbuyscoreinfo); std::string strret{}; bool bret = tsellbuyscoreinfo.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } rapidjson::Document doc; doc.SetObject(); rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); doc.AddMember("ret", -1, allocator); __int64 adminuserid = 0; __int64 itradescore = 0; double dtradescore = 0.0f; __int64 inserttime = 0; __int32 itype = 0; //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tsellbuyscoreinfo.authcode.c_str() \ << "authkey" << tsellbuyscoreinfo.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } adminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } auto timeview = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", -1)); mongocxx::options::find options; options.sort(timeview.view()); options.limit(20); options.skip(tsellbuyscoreinfo.ipagenum * 20); auto findinfo = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("spreaderid", adminuserid), bsoncxx::builder::basic::kvp("inserttime", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$lte", tsellbuyscoreinfo.endtime), bsoncxx::builder::basic::kvp("$gt", tsellbuyscoreinfo.begintime)))); auto tradeinfo = m_pusertradeinfo->find(findinfo.view(), options); rapidjson::Value timeArray(rapidjson::kArrayType); for (auto &tempinfo:tradeinfo) { rapidjson::Document sellbuyinfodoc; sellbuyinfodoc.SetObject(); rapidjson::Document::AllocatorType& sallocator = sellbuyinfodoc.GetAllocator(); std::string useraccount{}; if (tempinfo["useraccount"]) { useraccount = tempinfo["useraccount"].get_utf8().value.data(); } sellbuyinfodoc.AddMember("useraccount", rapidjson::Value(useraccount.c_str(), sallocator), sallocator); std::string stritype{ "0" }; if (tempinfo["type"]) { itype = tempinfo["type"].get_int32(); try { stritype = std::to_string(itype); } catch (const std::exception&) { stritype = "0"; } } sellbuyinfodoc.AddMember("sellbuy", rapidjson::Value(stritype.c_str(), sallocator), sallocator); std::string stritradescore{"0"}; if (tempinfo["tradescore"]) { itradescore = tempinfo["tradescore"].get_int64(); } stritradescore = getdouble(itradescore); sellbuyinfodoc.AddMember("tradescore", rapidjson::Value(stritradescore.c_str(), sallocator), sallocator); inserttime = 0; if (tempinfo["inserttime"]) { inserttime = tempinfo["inserttime"].get_int64(); } std::string strinserttime{}; if (inserttime >= 0) { strinserttime = funclib::gettimefromstamp(inserttime); } sellbuyinfodoc.AddMember("inserttime", rapidjson::Value(strinserttime.c_str(), sallocator), sallocator); rapidjson::Value element(rapidjson::kObjectType); element.CopyFrom(sellbuyinfodoc, allocator); timeArray.PushBack(element, allocator); } doc.AddMember("sellbuyinfo", timeArray, allocator); //操作成功 strret = funclib::doctojson(doc); return strret; } //查询游戏每局记录 std::string HttpSocket::playgameinfo(std::map getdata) { playinfo tplayinfo; getvaluedata(getdata, tplayinfo); std::string strret{}; bool bret = tplayinfo.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } __int64 iadminuserid = 0; __int64 userspreadid = 0; //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tplayinfo.authcode.c_str() \ << "authkey" << tplayinfo.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } iadminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tplayinfo.account.c_str() << bsoncxx::builder::stream::finalize); if (!finduser) { strret = funclib::rettojson(1, "the account is not exist"); return strret; } if (!finduser->view()["spreaderid"]) { strret = funclib::rettojson(1, "the account is not exist1"); return strret; } userspreadid = finduser->view()["spreaderid"].get_int64(); if (userspreadid != iadminuserid) { strret = funclib::rettojson(32, "the account is not belong to you"); return strret; } auto findinfo = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("account", tplayinfo.account.c_str()), bsoncxx::builder::basic::kvp("inserttime", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$lte", tplayinfo.endtime), bsoncxx::builder::basic::kvp("$gte", tplayinfo.begintime)))); auto timeview = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", -1)); mongocxx::options::find options; options.sort(timeview.view()); options.limit(1000); options.skip(tplayinfo.ipagenum*1000); auto tradeinfo = m_pgameprizelog->find(findinfo.view(), options); rapidjson::Document doc; doc.SetObject(); rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); doc.AddMember("ret", -1, allocator); __int64 itemp64 = 0; __int64 itemp32 = 0; std::string strtemp; rapidjson::Value timeArray(rapidjson::kArrayType); for (auto &tempinfo : tradeinfo) { rapidjson::Document gameinfodoc; gameinfodoc.SetObject(); rapidjson::Document::AllocatorType& gallocator = gameinfodoc.GetAllocator(); if (tempinfo["dbquestid"]) { itemp64 = tempinfo["dbquestid"].get_int64(); } std::string betid{}; try { betid = std::to_string(itemp64); } catch (const std::exception&) { betid = "0"; } gameinfodoc.AddMember("betid", rapidjson::Value(betid.c_str(), gallocator), gallocator); std::string useraccount{}; if (tempinfo["account"]) { useraccount = tempinfo["account"].get_utf8().value.data(); } gameinfodoc.AddMember("useraccount", rapidjson::Value(useraccount.c_str(), gallocator), gallocator); std::string gamename{}; if (tempinfo["servername"]) { gamename = tempinfo["servername"].get_utf8().value.data(); } gameinfodoc.AddMember("gamename", rapidjson::Value(gamename.c_str(), gallocator), gallocator); itemp32 = 0; if (tempinfo["tableid"]) { itemp32 = tempinfo["tableid"].get_int32(); } std::string tableid{}; try { tableid = std::to_string(itemp32); } catch (const std::exception&) { tableid = "0"; } gameinfodoc.AddMember("tableid", rapidjson::Value(tableid.c_str(), gallocator), gallocator); itemp64 = 0; if (tempinfo["betscore"]) { itemp64 = tempinfo["betscore"].get_int64(); } strtemp = getdouble(itemp64); gameinfodoc.AddMember("betscore", rapidjson::Value(strtemp.c_str(), gallocator), gallocator); itemp64 = 0; if (tempinfo["winscore"]) { itemp64 = tempinfo["winscore"].get_int64(); } strtemp = getdouble(itemp64); gameinfodoc.AddMember("winscore", rapidjson::Value(strtemp.c_str(), gallocator), gallocator); itemp64 = 0; if (tempinfo["userscore"]) { itemp64 = tempinfo["userscore"].get_int64(); } strtemp = getdouble(itemp64); gameinfodoc.AddMember("userscore", rapidjson::Value(strtemp.c_str(), gallocator), gallocator); itemp64 = 0; if (tempinfo["inserttime"]) { itemp64 = tempinfo["inserttime"].get_int64(); } std::string inserttime{}; if (itemp64 >= 0) { inserttime = funclib::gettimefromstamp(itemp64); } gameinfodoc.AddMember("inserttime", rapidjson::Value(inserttime.c_str(), gallocator), gallocator); rapidjson::Value element(rapidjson::kObjectType); element.CopyFrom(gameinfodoc, allocator); timeArray.PushBack(element, allocator); } doc.AddMember("gameinfo", timeArray, allocator); //操作成功 strret = funclib::doctojson(doc); return strret; } //获取总赌注和总输赢 std::string HttpSocket::getuserplayscoreinfo(std::map getdata) { playscoreinfo tplayscoreinfo; getvaluedata(getdata, tplayscoreinfo); std::string strret{}; char account[30][LEN_ACCOUNTS]{0}; std::int32_t iaccountnum = 0; bool bret = tplayscoreinfo.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } bret = false; std::string stemp = ""; for (int i = 0; i < 30 && !bret; i++) { stemp = straccount(tplayscoreinfo.account, bret); if (stemp.length() > LEN_ACCOUNTS - 1) stemp = stemp.substr(0, LEN_ACCOUNTS - 1); memcpy_s(account[i], LEN_ACCOUNTS, stemp.c_str(), stemp.length()); iaccountnum++; } std::map<__int64, __int64> mapuserall; mapuserall.clear(); __int64 iadminuserid = 0; //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tplayscoreinfo.authcode.c_str() \ << "authkey" << tplayscoreinfo.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(9, "spreaderid isnot exist"); return strret; } iadminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } __int64 tempuserid = 0; std::string tempaccount = ""; auto finduser = m_pcoll->find(bsoncxx::builder::stream::document{} << "spreaderid" << iadminuserid << bsoncxx::builder::stream::finalize); for (auto& doc : finduser) { tempuserid = doc["userid"].get_int64(); tempaccount = doc["account"].get_utf8().value.data(); bool bfind = false; for (int i = 0; i < iaccountnum; i++) { if (tempaccount == account[i]) { bfind = true; break; } } if(bfind) mapuserall.insert(std::map<__int64, __int64>::value_type(tempuserid, tempuserid)); } if (mapuserall.begin() == mapuserall.end()) { strret = funclib::rettojson(1, "the vip don't have player"); return strret; } auto findinfo = bsoncxx::builder::basic::make_document( bsoncxx::builder::basic::kvp("inserttime", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$lte", tplayscoreinfo.endtime), bsoncxx::builder::basic::kvp("$gte", tplayscoreinfo.begintime)))); auto tradeinfo = m_pgameprizelog->find(findinfo.view()); //玩家总下注 __int64 iuserallbet = 0; //玩家总赢回 __int64 iuserallwin = 0; __int64 itemp64 = 0; for (auto& tempinfo : tradeinfo) { itemp64 = 0; if (tempinfo["userid"]) { itemp64 = tempinfo["userid"].get_int64(); auto tempfinduser = mapuserall.find(itemp64); if (tempfinduser == mapuserall.end()) continue; } else continue; itemp64 = 0; if (tempinfo["betscore"]) { itemp64 = tempinfo["betscore"].get_int64(); iuserallbet += itemp64; } itemp64 = 0; if (tempinfo["winscore"]) { itemp64 = tempinfo["winscore"].get_int64(); iuserallwin += itemp64; } } rapidjson::Document doc; doc.SetObject(); rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); doc.AddMember("ret", -1, allocator); std::string strtemp; strtemp = getdouble(iuserallbet); doc.AddMember("userallbet", rapidjson::Value(strtemp.c_str(), allocator), allocator); strtemp = getdouble(iuserallwin); doc.AddMember("userallwin", rapidjson::Value(strtemp.c_str(), allocator), allocator); //操作成功 strret = funclib::doctojson(doc); return strret; } //添加奖励码 std::string HttpSocket::updateuseringot(std::map getdata) { updateingot tupdateingot; getvaluedata(getdata, tupdateingot); std::string strret{}; auto findscore = getdata.find("score"); if (findscore == getdata.end()) { strret = funclib::rettojson(10, "param erro"); return strret; } std::int32_t iret = 0; tupdateingot.score = stringToint64_t(findscore->second, iret); if (iret == -1) { strret = funclib::rettojson(10, "param erro"); return strret; } if (tupdateingot.score <= 0) { strret = funclib::rettojson(10, "param erro"); return strret; } bool bret = tupdateingot.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } std::string strusername = ""; std::string struseraccount = ""; std::string struserip = ""; std::string strspreadername = ""; std::string strspreaderaccount = ""; std::string strspreaderip = ""; std::stringstream sss; __int64 iuserid = 0; __int64 ingot = 0; __int64 ingottemp = 0; __int64 tradescore = 0; __int64 iadminuserid = 0; __int64 userspreadid = 0; __int64 ivipscore = 0; __int64 beforeuserscore = 0; __int64 afteruserscore = 0; __int64 itempscore = 0; __int64 beforespreaderscore = 0; __int64 afterspreaderscore = 0; __int64 inserttime = funclib::gettimestamp(); __int64 ilocaltime = funclib::getlocaltimestamp(); //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tupdateingot.authcode.c_str() \ << "authkey" << tupdateingot.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } iadminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } if (vipuser->view()["score"]) ivipscore = vipuser->view()["score"].get_int64(); auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tupdateingot.account.c_str() << bsoncxx::builder::stream::finalize); if (!finduser || !finduser->view()["userid"]) { strret = funclib::rettojson(1, "the account is not exist"); return strret; } if (!finduser->view()["score"] || !finduser->view()["name"] || !finduser->view()["account"] || !finduser->view()["lastlogonip"] || !finduser->view()["userid"]) { strret = funclib::rettojson(11, "user is not exist1"); return strret; } iuserid = finduser->view()["userid"].get_int64(); if(finduser->view()["ingot"]) ingot = finduser->view()["ingot"].get_int64(); beforeuserscore = finduser->view()["score"].get_int64(); strusername = finduser->view()["name"].get_utf8().value.data(); struseraccount = finduser->view()["account"].get_utf8().value.data(); struserip = finduser->view()["lastlogonip"].get_utf8().value.data(); if (!finduser->view()["spreaderid"]) { strret = funclib::rettojson(1, "the account is not exist1"); return strret; } userspreadid = finduser->view()["spreaderid"].get_int64(); if (userspreadid != iadminuserid) { strret = funclib::rettojson(32, "the account is not belong to you"); return strret; } //目前只支持赠送奖励码 if (tupdateingot.score <= 0) { strret = funclib::rettojson(1, "the score's erro"); return strret; } itempscore = ivipscore - tupdateingot.score; //判断vip有没有足够的分数 if (itempscore < 0) { strret = funclib::rettojson(1, "the vip does not have enough score"); return strret; } afteruserscore = beforeuserscore + tupdateingot.score; //获取要减的分数 itempscore = tupdateingot.score * -1; //减商家分数 auto criteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", iadminuserid)); auto update = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", itempscore)))); auto retscore = m_pvipuser->find_one_and_update(criteria.view(), update.view()); if (!retscore) { strret = funclib::rettojson(12, "modify score erro"); return strret; } if (!retscore->view()["score"] || !retscore->view()["name"] || !retscore->view()["account"] || !retscore->view()["loginip"]) { strret = funclib::rettojson(12, "modify score erro1"); return strret; } beforespreaderscore = retscore->view()["score"].get_int64(); strspreadername = retscore->view()["name"].get_utf8().value.data(); strspreaderaccount = retscore->view()["account"].get_utf8().value.data(); strspreaderip = retscore->view()["loginip"].get_utf8().value.data(); afterspreaderscore = beforespreaderscore + itempscore; //给用户家奖金码 itempscore = tupdateingot.score; auto usercriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", iuserid)); auto userupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", itempscore))), bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("ingot", itempscore)))); auto userretscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view()); if (!userretscore) { strret = funclib::rettojson(13, "add user score erro"); return strret; } //加用户分数 tradescore = tupdateingot.score; __int64 iOne32 = 1; auto vipscorecriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("business", iOne32)); auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("sellscore", tradescore)))); mongocxx::options::find_one_and_update options; options.upsert(true); auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options); if (vipscore) { if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"]) { __int64 sellscore = vipscore->view()["sellscore"].get_int64(); __int64 buyscore = vipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += tradescore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view()); } } } __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000); inserttimetemp *= (24 * 60 * 60 * 1000); auto vipscoredate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", inserttimetemp)); auto vipscoredateupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("sellscore", tradescore)))); auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options); if (retvipscore) { if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"]) { __int64 sellscore = retvipscore->view()["sellscore"].get_int64(); __int64 buyscore = retvipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += tradescore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view()); } } } //记录充值分数 auto rechargecriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", iuserid)); auto findlw = m_plosewincoll->find_one(rechargecriteria.view()); if (findlw) { //判断清除当天充值属性 __int64 irechargetime = 0; if (findlw->view()["rechargetime"]) { irechargetime = findlw->view()["rechargetime"].get_int64(); } irechargetime /= (24 * 60 * 60 * 1000); irechargetime *= (24 * 60 * 60 * 1000); if (irechargetime != inserttimetemp) { auto rechargeupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalczscore", tradescore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("todayczscore", tradescore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("rechargetime", ilocaltime)))); m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view()); } else { auto rechargeupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalczscore", tradescore))), bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("todayczscore", tradescore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("rechargetime", ilocaltime)))); m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view()); } } else { auto rechargeupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalczscore", tradescore))), bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("todayczscore", tradescore))), bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("rechargetime", ilocaltime)))); m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view()); } //记录奖励码总数 //auto temptotalingot = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("allingot", tradescore)))); //m_plosewincoll->update_one(rechargecriteria.view(), temptotalingot.view()); //生成转账记录 __int32 itype = 1; auto builder = bsoncxx::builder::stream::document{}; builder << "userid" << iuserid << "name" << strusername.c_str() << "useraccount" << struseraccount.c_str() << "userip" << struserip.c_str() << "spreaderid" << iadminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str() << "spreaderip" << strspreaderip.c_str() << "beforeuserscore" << beforeuserscore << "beforespreaderscore" << beforespreaderscore << "afteruserscore" << afteruserscore << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << tradescore << "inserttime" << inserttime; m_pusertradeinfo->insert_one(builder.view()); auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); auto loginoline = m_userloginonline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (loginoline && loginoline->view()["contextid"] && loginoline->view()["userip"]) { //通知游戏更新分数 CMD_CS_C_UpdateScoreEx tempUpdateScore; ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore)); tempUpdateScore.dwUserID = iuserid; tempUpdateScore.addscore = tradescore; std::string strloginip{}; tempUpdateScore.dwLoginContextID = loginoline->view()["contextid"].get_int64(); strloginip = loginoline->view()["userip"].get_utf8().value.data(); m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore)); } if (useroline && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"]) { //通知游戏更新分数 CMD_CS_C_UpdateScoreEx tempUpdateScore; ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore)); tempUpdateScore.dwUserID = iuserid; tempUpdateScore.addscore = tradescore; std::string strloginip{}; tempUpdateScore.wgameserverid = useroline->view()["serverid"].get_int32(); tempUpdateScore.dwGameContextID = useroline->view()["contextid"].get_int64(); strloginip = useroline->view()["userip"].get_utf8().value.data(); m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore)); } strret = funclib::rettojson(-1, "ok"); return strret; } //回退奖励码 std::string HttpSocket::backuseringot(std::map getdata) { backingot tbackingot; getvaluedata(getdata, tbackingot); std::string strret{}; auto findscore = getdata.find("score"); if (findscore == getdata.end()) { strret = funclib::rettojson(10, "param erro"); return strret; } std::int32_t iret = 0; tbackingot.score = stringToint64_t(findscore->second, iret); if (iret == -1) { strret = funclib::rettojson(10, "param erro"); return strret; } if (tbackingot.score <= 0) { strret = funclib::rettojson(10, "param erro"); return strret; } bool bret = tbackingot.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } std::string strusername = ""; std::string struseraccount = ""; std::string struserip = ""; std::string strspreadername = ""; std::string strspreaderaccount = ""; std::string strspreaderip = ""; std::stringstream sss; __int64 iuserid = 0; __int64 ingot = 0; __int64 ingottemp = 0; __int64 tradescore = 0; __int64 iadminuserid = 0; __int64 userspreadid = 0; __int64 beforeuserscore = 0; __int64 afteruserscore = 0; __int64 itempscore = 0; __int64 beforespreaderscore = 0; __int64 afterspreaderscore = 0; __int64 inserttime = funclib::gettimestamp(); __int64 ilocaltime = funclib::getlocaltimestamp(); //目前支持下分奖励码 if (tbackingot.score <= 0) { strret = funclib::rettojson(1, "the score's erro"); return strret; } //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tbackingot.authcode.c_str() \ << "authkey" << tbackingot.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(5, "id isnot exist"); return strret; } iadminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int64 ivipscore = vipuser->view()["score"].get_int64(); beforespreaderscore = ivipscore; strspreadername = vipuser->view()["name"].get_utf8().value.data(); strspreaderaccount = vipuser->view()["account"].get_utf8().value.data(); strspreaderip = vipuser->view()["loginip"].get_utf8().value.data(); __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (useroline) { strret = funclib::rettojson(15, "user is playing"); return strret; } auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tbackingot.account.c_str() << bsoncxx::builder::stream::finalize); if (!finduser || !finduser->view()["userid"]) { strret = funclib::rettojson(1, "the account is not exist"); return strret; } if (!finduser->view()["score"] || !finduser->view()["name"] || !finduser->view()["account"] || !finduser->view()["lastlogonip"] || !finduser->view()["userid"]) { strret = funclib::rettojson(11, "user is not exist1"); return strret; } iuserid = finduser->view()["userid"].get_int64(); if (finduser->view()["ingot"]) ingot = finduser->view()["ingot"].get_int64(); //判断奖励码是否够 if (ingot < tbackingot.score) { strret = funclib::rettojson(11, "user's score not enough"); return strret; } beforeuserscore = finduser->view()["score"].get_int64(); beforeuserscore += ingot; strusername = finduser->view()["name"].get_utf8().value.data(); struseraccount = finduser->view()["account"].get_utf8().value.data(); struserip = finduser->view()["lastlogonip"].get_utf8().value.data(); if (!finduser->view()["spreaderid"]) { strret = funclib::rettojson(1, "the account is not exist1"); return strret; } userspreadid = finduser->view()["spreaderid"].get_int64(); if (userspreadid != iadminuserid) { strret = funclib::rettojson(32, "the account is not belong to you"); return strret; } //减用户的奖励码 itempscore = -1* tbackingot.score; auto usercriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", iuserid)); auto userupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", itempscore))), bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("ingot", itempscore)))); auto tempscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view()); if (!tempscore) { strret = funclib::rettojson(19, "reduce user score erro"); return strret; } afteruserscore = beforeuserscore - tbackingot.score; //增加商家的分数 tradescore = tbackingot.score; //添加玩家总下分 auto xiafenupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("totalxfscore", tradescore)))); m_plosewincoll->find_one_and_update(usercriteria.view(), xiafenupdate.view()); //增加商家的分数 auto admincriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", iadminuserid)); auto adminupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("score", tradescore)))); auto adminretscore = m_pvipuser->find_one_and_update(admincriteria.view(), adminupdate.view()); if (!adminretscore) { strret = funclib::rettojson(20, "add business score erro"); return strret; } __int64 iOne32 = 1; auto vipscorecriteria = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("business", iOne32)); auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buyscore", tradescore)))); mongocxx::options::find_one_and_update options; options.upsert(true); auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options); if (vipscore) { if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"]) { __int64 sellscore = vipscore->view()["sellscore"].get_int64(); __int64 buyscore = vipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += tradescore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view()); } } } __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000); inserttimetemp *= (24 * 60 * 60 * 1000); auto vipscoredate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", inserttimetemp)); auto vipscoredateupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$inc", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buyscore", tradescore)))); auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options); if (retvipscore) { if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"]) { __int64 sellscore = retvipscore->view()["sellscore"].get_int64(); __int64 buyscore = retvipscore->view()["buyscore"].get_int64(); if (sellscore != 0) { buyscore += tradescore; double buysellrate = buyscore; buysellrate /= sellscore; auto vipscoreupdate = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$set", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("buysellrate", buysellrate)))); m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view()); } } } afterspreaderscore = beforespreaderscore + tbackingot.score; //生成交易记录 __int32 itype = 2; auto builder = bsoncxx::builder::stream::document{}; builder << "userid" << iuserid << "name" << strusername.c_str() << "useraccount" << struseraccount.c_str() << "userip" << struserip.c_str() << "spreaderid" << iadminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str() << "spreaderip" << strspreaderip.c_str() << "beforeuserscore" << beforeuserscore << "beforespreaderscore" << beforespreaderscore << "afteruserscore" << afteruserscore << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << tradescore << "inserttime" << inserttime; auto result = m_pusertradeinfo->insert_one(builder.view()); //如果在大厅更新玩家分数 auto loginoline = m_userloginonline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize); if (loginoline && loginoline->view()["contextid"] && loginoline->view()["userip"]) { //通知游戏更新分数 CMD_CS_C_UpdateScoreEx tempUpdateScore; ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore)); tempUpdateScore.dwUserID = iuserid; tempUpdateScore.addscore = -tradescore; std::string strloginip{}; tempUpdateScore.dwLoginContextID = loginoline->view()["contextid"].get_int64(); strloginip = loginoline->view()["userip"].get_utf8().value.data(); m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore)); } strret = funclib::rettojson(-1, "ok"); return strret; } //获取所有总赌注和总输赢 std::string HttpSocket::getalluserplayscoreinfo(std::map getdata) { allplayscoreinfo tallplayscoreinfo; getvaluedata(getdata, tallplayscoreinfo); std::string strret{}; bool bret = tallplayscoreinfo.datavalue(); if (!bret) { strret = funclib::rettojson(10, "param erro"); return strret; } __int64 iadminuserid = 0; __int64 iallplaynum = 0; __int64 iallusernum = 0; //判断三方平台是否存在 auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tallplayscoreinfo.authcode.c_str() \ << "authkey" << tallplayscoreinfo.authkey.c_str() << bsoncxx::builder::stream::finalize); if (!threeadmin) { strret = funclib::rettojson(5, "code or key isnot exist"); return strret; } if (!threeadmin->view()["adminuserid"]) { strret = funclib::rettojson(9, "spreaderid isnot exist"); return strret; } iadminuserid = threeadmin->view()["adminuserid"].get_int64(); auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize); if (!vipuser) { strret = funclib::rettojson(10, "spreaderid isnot exist"); return strret; } __int32 vipstate = 0; if (vipuser->view()["state"]) { vipstate = vipuser->view()["state"].get_int32(); } else vipstate = 1; if (vipstate != 0) { strret = funclib::rettojson(10, "spreaderid is disabled"); return strret; } bool badd = false; __int64 tempuserid = 0; std::string tempaccount = ""; m_useridarray.clear(); m_mapuseridname.clear(); std::string tempname; mongocxx::options::find options; options.projection(bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("userid", 1), bsoncxx::builder::basic::kvp("name", 1))); auto finduser = m_pcoll->find(bsoncxx::builder::stream::document{} << "spreaderid" << iadminuserid << bsoncxx::builder::stream::finalize, options); for (auto& doc : finduser) { tempuserid = doc["userid"].get_int64(); //在没有写入账号的时候返回名下所有账号 //m_useridarray.append(tempuserid); //ub8的玩家把账号改成昵称 if (iadminuserid == 311) { tempname = ""; if(doc["name"]) tempname = doc["name"].get_utf8().value.data(); m_mapuseridname.insert(std::unordered_map::value_type(tempuserid, tempname)); } badd = true; } if (!badd) { strret = funclib::rettojson(1, "the vip don't have player"); return strret; } std::int32_t iskipnum = 1000 * tallplayscoreinfo.ipagenum; if (iskipnum < 0) { strret = funclib::rettojson(10, "param erro"); return strret; } std::int64_t dectime = tallplayscoreinfo.endtime - tallplayscoreinfo.begintime; if (dectime > 604800000) { strret = funclib::rettojson(10, "time erro"); return strret; } // NEWLOG(INFO, "msglog") << "-------" << "tallplayscoreinfo.begintime=" << tallplayscoreinfo.begintime // << " tallplayscoreinfo.endtime=" << tallplayscoreinfo.endtime << " iadminuserid=" << iadminuserid // << " iskipnum=" << iskipnum; taggameuserlog tempvect; bsoncxx::builder::basic::document files_filter; files_filter.append(bsoncxx::builder::basic::kvp("spreaderid", iadminuserid)); files_filter.append(bsoncxx::builder::basic::kvp("$and", bsoncxx::builder::basic::make_array( bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$gte", tallplayscoreinfo.begintime)))), bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("inserttime", bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("$lt", tallplayscoreinfo.endtime))))))); tempvect.allpagenum = m_pgameprizelog->count_documents(files_filter.view()); //NEWLOG(INFO, "msglog") << "tempvect.allpagenum=" << tempvect.allpagenum; tempvect.allrecordnum = tempvect.allpagenum; tempvect.allpagenum /= 1000; tempvect.allpagenum += 1; mongocxx::options::find gamelogoptions; gamelogoptions.limit(1000); gamelogoptions.skip(iskipnum); auto tradeinfo = m_pgameprizelog->find(files_filter.view(), gamelogoptions); tempvect.recordnum = 0; tempvect.curpagenum = tallplayscoreinfo.ipagenum; __int64 iscore = 0; std::int64_t ifinduserid = 0; for (auto& doc : tradeinfo) { gameuserlog tempuserlog={}; if(doc["dbquestid"]) tempuserlog.dbquestid = doc["dbquestid"].get_int64(); if(doc["userid"]) ifinduserid = doc["userid"].get_int64(); //ub8的玩家把账号改成昵称 if (iadminuserid == 311) { auto& username = m_mapuseridname.find(ifinduserid); if (username != m_mapuseridname.end()) { tempuserlog.account = username->second; } } else { if (doc["account"]) { tempuserlog.account = doc["account"].get_utf8().value.data(); } } if(doc["serverid"]) tempuserlog.serverid = doc["serverid"].get_int32(); if(doc["betscore"]) iscore = doc["betscore"].get_int64(); tempuserlog.betscore = getdouble(iscore); if(doc["winscore"]) iscore = doc["winscore"].get_int64(); tempuserlog.winscore = getdouble(iscore); if(doc["userscore"]) iscore = doc["userscore"].get_int64(); tempuserlog.userscore = getdouble(iscore); if(doc["inserttime"]) tempuserlog.inserttime = doc["inserttime"].get_int64(); if(doc["servername"]) tempuserlog.servername = doc["servername"].get_utf8().value.data(); tempvect.userlog.push_back(tempuserlog); tempvect.recordnum++; } //NEWLOG(INFO, "msglog") << "fun ok"; rapidjson::Document doc; doc.SetObject(); rapidjson::Document::AllocatorType& allocator = doc.GetAllocator(); doc.AddMember("ret", -1, allocator); doc.AddMember("info", rapidjson::Value("ok", allocator), allocator); doc.AddMember("allrecordnum", tempvect.allrecordnum, allocator); doc.AddMember("recordnum", tempvect.recordnum, allocator); doc.AddMember("curpagenum", tempvect.curpagenum, allocator); doc.AddMember("allpagenum", tempvect.allpagenum, allocator); rapidjson::Value timeArray(rapidjson::kArrayType); for (auto& tempinfo : tempvect.userlog) { rapidjson::Document userlogdoc; userlogdoc.SetObject(); rapidjson::Document::AllocatorType& uallocator = userlogdoc.GetAllocator(); userlogdoc.AddMember("dbquestid", tempinfo.dbquestid, uallocator); userlogdoc.AddMember("account", rapidjson::Value(tempinfo.account.c_str(), uallocator), uallocator); userlogdoc.AddMember("servername", rapidjson::Value(tempinfo.servername.c_str(), uallocator), uallocator); userlogdoc.AddMember("serverid", tempinfo.serverid, uallocator); userlogdoc.AddMember("betscore", rapidjson::Value(tempinfo.betscore.c_str(), uallocator), uallocator); userlogdoc.AddMember("winscore", rapidjson::Value(tempinfo.winscore.c_str(), uallocator), uallocator); userlogdoc.AddMember("userscore", rapidjson::Value(tempinfo.userscore.c_str(), uallocator), uallocator); userlogdoc.AddMember("gamelog", rapidjson::Value(tempinfo.gamelog.c_str(), uallocator), uallocator); userlogdoc.AddMember("inserttime", tempinfo.inserttime, uallocator); rapidjson::Value element(rapidjson::kObjectType); element.CopyFrom(userlogdoc, allocator); timeArray.PushBack(element, allocator); } doc.AddMember("userlog", timeArray, allocator); strret = funclib::doctojson(doc); //NEWLOG(INFO, "msglog") << strret; return strret; }