1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568 |
- #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());
- }
- std::uint32_t HttpSocket::m_gucurid = 0;
- HttpSocket::HttpSocket()
- {
- m_random = std::default_random_engine(time(NULL));
- //数据库配置
- {
- std::string strkkk3 = "mongodb://127.0.0.1:27017";
- m_puri = boost::make_shared<mongocxx::uri>(strkkk3.c_str());
- }
- m_pclient = boost::make_shared <mongocxx::client>(*m_puri);
- m_platform = boost::make_shared<mongocxx::database>();
- m_pdb = boost::make_shared<mongocxx::database>();
- m_gamelog = boost::make_shared<mongocxx::database>();
- m_pvipuserdb = boost::make_shared<mongocxx::database>();
- m_pallindex = boost::make_shared<mongocxx::collection>();
- m_pcoll = boost::make_shared<mongocxx::collection>();
- m_plosewincoll = boost::make_shared<mongocxx::collection>();
- m_pvipuser = boost::make_shared<mongocxx::collection>();
- m_pplayuseronline = boost::make_shared<mongocxx::collection>();
- m_userloginonline = boost::make_shared<mongocxx::collection>();
- m_pusertradeinfo = boost::make_shared<mongocxx::collection>();
- m_pviptradeinfo = boost::make_shared<mongocxx::collection>();
- m_poperatinfo = boost::make_shared<mongocxx::collection>();
- m_pvipscore = boost::make_shared<mongocxx::collection>();
- m_pvipscoredate = boost::make_shared<mongocxx::collection>();
- m_pvipuseraccounts = boost::make_shared<mongocxx::collection>();
- m_puserdatainfo = boost::make_shared<mongocxx::collection>();
- m_pthreeadmin = boost::make_shared<mongocxx::collection>();
- m_pgameprizelog = boost::make_shared<mongocxx::collection>();
- m_pvipconfigure = boost::make_shared<mongocxx::collection>();
- m_pgamelist = boost::make_shared<mongocxx::collection>();
- *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"];
- m_strshahead = "X-REQUEST-SIGN";
- m_strshaheadcontent = "6e4c91001979851a97c2b5360f044ff67b48e186d6ecd4394532851bffdeeae9";
- m_ucurid = m_gucurid++;
- m_psendhttp = weblib::httpini();
- //获取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()
- {
- weblib::delhttp(m_psendhttp);
- }
- void HttpSocket::init()
- {
- staticdata tstaticdata;
- try
- {
- makegamelist(tstaticdata);
- m_updatestatic("staticdata", tstaticdata);
- }
- catch (const std::exception&)
- {
- }
- }
- bool HttpSocket::postmsg(std::function<void(std::string&, int)> funhttpmsg, std::map<std::string, std::string> getdata)
- {
- try
- {
- std::string strtojson{};
- auto& findkey = getdata.find("itype");
- if (findkey != getdata.end())
- {
- std::int32_t itype = funclib::strtonum<std::int32_t>(findkey->second);
- //玩家账号注册
- if (itype == HTTPREGUSER)
- {
- strtojson = regaccount(getdata);
- }
- //更新玩家分数
- else if (itype == HTTPUPDATEUSERSCORE)
- {
- strtojson = updateuserscore(getdata, funhttpmsg);
- }
- //把玩家踢出游戏
- else if (itype == HTTPADMINKICKUSER)
- {
- strtojson = adminhituser(getdata, funhttpmsg);
- }
- //管理员禁止管理员所属玩家
- 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 if (itype == HTTPLOGINREEL)
- {
- reelplay(getdata, funhttpmsg);
- }
- else
- {
- return false;
- }
- funhttpmsg(strtojson, 200);
- return true;
- }
- 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, 200);
- return true;
- }
- }
- catch (std::exception& e)
- {
- }
- std::string strerror{ "{\"error\":1}" };
- int iret = -1;
- funhttpmsg(strerror, iret);
- return true;
- }
- void HttpSocket::updatemsg(std::string strtype, boost::any getdata)
- {
- if (strtype == "staticdata")
- {
- m_staticdata = boost::any_cast<staticdata>(getdata);
- }
- }
- 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<std::string>("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<rapidjson::StringBuffer> writer(buffer);
- subgamedoc.Accept(writer);
- tstaticdata.m_mapregiongame[strGid] = std::string(buffer.GetString());
- }
- }
- }
- rapidjson::Document sortedkindidArray;
- sortedkindidArray.SetArray();
- // 排序
- {
- std::vector<const rapidjson::Value*> 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<const rapidjson::Value*> 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<byte> 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<std::string, std::string> 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<std::string, std::string> getdata)
- {
- reguser treguser;
- getvaluedata(getdata, treguser);
- std::string strret{};
- bool bret = treguser.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
-
- if (!threeadmin->view()["adminuserid"] || !threeadmin->view()["region"])
- {
- strret = funclib::rettojson(Err_Agent_LackInfo, "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(Err_No_Agent, 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(Err_OutOfState_Agent, "spreaderid is disabled");
- return strret;
- }
- //查询第三方平台开通的空账号当天数量不超过1000个
- std::int64_t ilogondate = ilocaltime / 86400000 * 86400000;
- ilogondate = funclib::getlocaltounixstamp(ilogondate);
- auto findusernull = make_document(kvp("spreaderid", adminuserid), (kvp("registerlogonip", registerip.c_str())),
- kvp("registerdate", make_document(kvp("$gte", ilogondate))));
- std::int64_t iusernull = m_pcoll->count_documents(findusernull.view());
- if (iusernull > 1000)
- {
- strret = funclib::rettojson(Err_CreateUserNumberError, "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(Err_Create_PlayerAccount, "account create erro");
- return strret;
- }
- if (iscore < 0)
- {
- strret = funclib::rettojson(Err_UserScoreLessZero, "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 = make_document(kvp("name", iname));
- auto update = make_document(kvp("$inc", make_document(kvp("useridindex", iinc))),
- kvp("$inc", make_document(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(Err_Create_PlayerIndex, "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(Err_Create_UserIdDuplication, "userid is exist");
- return strret;
- }
- if (findlosewin)
- {
- strret = funclib::rettojson(Err_Create_AlreadHasLoseWin, "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(Err_Create_UserAccDuplication, " account is exist");
- return strret;
- }
- if (!vipuser->view()["score"] || !vipuser->view()["name"] || !vipuser->view()["account"] || !vipuser->view()["loginip"])
- {
- strret = funclib::rettojson(Err_Agent_LackInfo, " 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(Err_AgentScoreNotEnough, "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(Err_Create_PlayerAccount, "user create erro");
- return strret;
- }
- }
- catch (const std::exception&)
- {
- strret = funclib::rettojson(Err_Create_UserAccDuplication, "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(Err_Create_AlreadHasLoseWin, "user create erro");
- return strret;
- }
- //写注册日志
- auto findlogtime = make_document(kvp("inserttime", irechargetime));
- auto findlogset = make_document(kvp("$inc", make_document(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 = make_document(kvp("userid", adminuserid));
- auto vipupdate = make_document(kvp("$inc", make_document(kvp("score", ivipscore))));
- auto vipretscore = m_pvipuser->find_one_and_update(vipcriteria.view(), vipupdate.view());
- if (!vipretscore)
- {
- strret = funclib::rettojson(Err_Create_InsertUserInfo, "modify score erro");
- return strret;
- }
- //记录充值分数
- auto rechargecriteria = make_document(kvp("userid", userid));
- auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", iscore))),
- kvp("$inc", make_document(kvp("todayczscore", iscore))),
- kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
- m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
- __int64 iOne32 = 1;
- auto vipscorecriteria = make_document(kvp("business", iOne32));
- auto vipscoreupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(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 = make_document(kvp("inserttime", inserttimetemp));
- auto vipscoredateupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(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<std::string, std::string> getdata, std::function<void(std::string&, int)>& dofun)
- {
- userscore tuserscore;
- getvaluedata(getdata, tuserscore);
- std::string strret{};
- auto findscore = getdata.find("score");
- if (findscore == getdata.end())
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- std::int32_t iret = 0;
- tuserscore.score = stringToint64_t(findscore->second, iret);
- if (iret == -1)
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- bool bret = tuserscore.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- //用户不存在不减商家的分数
- auto firstuser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "userid" << tuserscore.iuserid << bsoncxx::builder::stream::finalize);
- if (!firstuser || firstuser->view()["spreaderid"])
- {
- strret = funclib::rettojson(11, "user is not exist");
- return strret;
- }
- std::int64_t adminuserid = firstuser->view()["spreaderid"].get_int64();
- auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
- if (!vipuser)
- {
- strret = funclib::rettojson(Err_No_Agent, "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(Err_OutOfState_Agent, "spreaderid is disabled");
- return strret;
- }
- if (!vipuser->view()["score"])
- {
- strret = funclib::rettojson(Err_Agent_LackInfo, "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;
- std::string strwebonlyuser{};
- //商家送分
- if (tuserscore.score < 0)
- {
- //可以赠送
- if (vipscore + tuserscore.score >= 0)
- {
- //用户不存在不减商家的分数
- 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();
- strwebonlyuser = firstuser->view()["webuser"].get_utf8().value.data();
- iuserid = firstuser->view()["userid"].get_int64();
- //减商家分数
- auto criteria = make_document(kvp("userid", adminuserid));
- auto update = make_document(kvp("$inc", make_document(kvp("score", tuserscore.score))));
- auto retscore = m_pvipuser->find_one_and_update(criteria.view(), update.view());
- if (!retscore)
- {
- strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "modify score erro");
- return strret;
- }
- if (!retscore->view()["score"] || !retscore->view()["name"] || !retscore->view()["account"])
- {
- strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "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();
- if(retscore->view()["loginip"])
- strspreaderip = retscore->view()["loginip"].get_utf8().value.data();
- afterspreaderscore = beforespreaderscore + tuserscore.score;
- //加用户分数
- tuserscore.score = -1 * tuserscore.score;
- tradescore = tuserscore.score;
- auto usercriteria = make_document(kvp("userid", iuserid));
- auto userupdate = make_document(kvp("$inc", make_document(kvp("score", tuserscore.score))));
- auto userretscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view());
- if (!userretscore)
- {
- strret = funclib::rettojson(Err_UserUpdateScoreFailed, "add user score erro");
- return strret;
- }
- __int64 iOne32 = 1;
- auto vipscorecriteria = make_document(kvp("business", iOne32));
- auto vipscoreupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(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 = make_document(kvp("inserttime", inserttimetemp));
- auto vipscoredateupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
- m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view());
- }
- }
- }
- //记录充值分数
- auto rechargecriteria = make_document(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 = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
- kvp("$set", make_document(kvp("todayczscore", tradescore))),
- kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
- m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
- }
- else
- {
- auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
- kvp("$inc", make_document(kvp("todayczscore", tradescore))),
- kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
- m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
- }
- }
- else
- {
- auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
- kvp("$inc", make_document(kvp("todayczscore", tradescore))),
- kvp("$set", make_document(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(Err_AgentScoreNotEnough, "business score isnot enough");
- return strret;
- }
- //如果玩家在线,从游戏中扣除
- auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
- {
- //通知游戏更新分数
- bool bfind = false;
- std::string struserip{};
- if (useroline && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"])
- {
- struserip = useroline->view()["userip"].get_utf8().value.data();
- bfind = true;
- }
- if (bfind && m_gamemsg && !struserip.empty())
- {
- rapidjson::Document docgame;
- docgame.SetObject();
- rapidjson::Document::AllocatorType& allocatorgame = docgame.GetAllocator();
- docgame.AddMember("agent", rapidjson::Value(strspreaderaccount.c_str(), allocatorgame), allocatorgame);
- docgame.AddMember("user", rapidjson::Value(strwebonlyuser.c_str(), allocatorgame), allocatorgame);
- docgame.AddMember("score", tuserscore.score * -1, allocatorgame);
- weblib::httpinfo thttpinfo{};
- thttpinfo.strurl = std::move(struserip);
- thttpinfo.strtarget = "webapi/updatescore";
- thttpinfo.strjson = funclib::doctojson(docgame);
- m_gamemsg(thttpinfo, std::move(dofun));
- return {};
- }
- }
- 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(Err_UpdateScoreTrickyError, "tricky bugs occured, please try again later!");
- return strret;
- }
- }
- }
- //用户不存在不能下分
- auto userretscore = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "userid" << tuserscore.iuserid << bsoncxx::builder::stream::finalize);
- if (!userretscore || !userretscore->view()["userid"])
- {
- strret = funclib::rettojson(Err_No_Player, "user isnot exist");
- return strret;
- }
- //玩家在玩游戏不能下分
- auto vipuser = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << tuserscore.iuserid << bsoncxx::builder::stream::finalize);
- if (vipuser)
- {
- strret = funclib::rettojson(Err_Player_InGame, "user is playing");
- return strret;
- }
- if (!userretscore->view()["score"] || !userretscore->view()["account"] || !userretscore->view()["lastlogonip"] || !userretscore->view()["webuser"])
- {
- strret = funclib::rettojson(Err_Player_LackInfo, "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(Err_Trade_UserScoreLack, "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();
- strwebonlyuser = userretscore->view()["webuser"].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(Err_No_Agent, "business is not exist");
- return strret;
- }
- if (!firstadmin->view()["score"] || !firstadmin->view()["name"] || !firstadmin->view()["account"] || !firstadmin->view()["loginip"])
- {
- strret = funclib::rettojson(Err_Agent_LackInfo, "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 = make_document(kvp("userid", tuserscore.iuserid));
- auto userupdate = make_document(kvp("$inc", make_document(kvp("score", tuserscore.score))));
- auto tempscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view());
- if (!tempscore)
- {
- strret = funclib::rettojson(Err_UserUpdateScoreFailed, "reduce user score erro");
- return strret;
- }
- afteruserscore = beforeuserscore + tuserscore.score;
- //增加商家的分数
- tuserscore.score = -1 * tuserscore.score;
- tradescore = tuserscore.score;
- //添加玩家总下分
- auto xiafenupdate = make_document(kvp("$inc", make_document(kvp("totalxfscore", tradescore))));
- m_plosewincoll->find_one_and_update(usercriteria.view(), xiafenupdate.view());
-
- auto admincriteria = make_document(kvp("userid", adminuserid));
- auto adminupdate = make_document(kvp("$inc", make_document(kvp("score", tradescore))));
- auto adminretscore = m_pvipuser->find_one_and_update(admincriteria.view(), adminupdate.view());
- if (!adminretscore)
- {
- strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "add business score erro");
- return strret;
- }
- __int64 iOne32 = 1;
- auto vipscorecriteria = make_document(kvp("business", iOne32));
- auto vipscoreupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(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 = make_document(kvp("inserttime", inserttimetemp));
- auto vipscoredateupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(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);
- {
- //通知游戏更新分数
- bool bfind = false;
- std::string struserip{};
- if (useroline && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"])
- {
- struserip = useroline->view()["userip"].get_utf8().value.data();
- bfind = true;
- }
- if (bfind && m_gamemsg && !struserip.empty())
- {
- rapidjson::Document docgame;
- docgame.SetObject();
- rapidjson::Document::AllocatorType& allocatorgame = docgame.GetAllocator();
- docgame.AddMember("agent", rapidjson::Value(strspreaderaccount.c_str(), allocatorgame), allocatorgame);
- docgame.AddMember("user", rapidjson::Value(strwebonlyuser.c_str(), allocatorgame), allocatorgame);
- docgame.AddMember("score", tuserscore.score * -1, allocatorgame);
- weblib::httpinfo thttpinfo{};
- thttpinfo.strurl = std::move(struserip);
- thttpinfo.strtarget = "webapi/updatescore";
- thttpinfo.strjson = funclib::doctojson(docgame);
- m_gamemsg(thttpinfo, std::move(dofun));
- return {};
- }
- }
- }
- //收分成功
- strret = funclib::rettojson(-1, "ok");
- return strret;
- }
- //把玩家踢出游戏
- std::string HttpSocket::adminhituser(std::map<std::string, std::string> getdata, std::function<void(std::string&, int)>& dofun)
- {
- kickuser tkickuser;
- getvaluedata(getdata, tkickuser);
- std::string strret{};
- bool bret = tkickuser.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_No_Player, "the user is not exist");
- return strret;
- }
- if (!finduser->view()["spreaderid"])
- {
- strret = funclib::rettojson(Err_Player_LackInfo, "the spreaderid is not exist");
- return strret;
- }
- if (!finduser->view()["userid"] || !finduser->view()["webuser"])
- {
- strret = funclib::rettojson(Err_Player_LackInfo, "the user is not exist");
- return strret;
- }
- userspreadid = finduser->view()["spreaderid"].get_int64();
- userid = finduser->view()["userid"].get_int64();
- std::string strextension1{};
- std::string strwebonlyuser{};
- strwebonlyuser = finduser->view()["webuser"].get_utf8().value.data();
- //判断三方平台是否存在
- 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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_Agent_LackInfo, "spreaderid isnot exist");
- return strret;
- }
- if (adminuserid != userspreadid || userspreadid == 0 || !vipuser->view()["account"])
- {
- strret = funclib::rettojson(Err_No_Agent, "the business is not exist");
- return strret;
- }
- if (vipuser->view()["account"])
- {
- strextension1 = vipuser->view()["account"].get_utf8().value.data();
- }
- auto finduserview = make_document(kvp("userid", finduser->view()["userid"].get_int64()));
- auto useroline = m_pplayuseronline->find_one(finduserview.view());
- bool bfind = false;
- std::string struserip{};
- std::int64_t iuserid{ 0 };
- std::int32_t iserverid{ 0 };
- std::int64_t icontextid{ 0 };
- if (useroline && useroline->view()["userid"] && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"])
- {
- iuserid = useroline->view()["userid"].get_int64();
- icontextid = useroline->view()["contextid"].get_int64();
- iserverid = useroline->view()["serverid"].get_int32();
- struserip = useroline->view()["userip"].get_utf8().value.data();
- bfind = true;
- }
- if (bfind && m_gamemsg && !struserip.empty())
- {
- rapidjson::Document docgame;
- docgame.SetObject();
- rapidjson::Document::AllocatorType& allocatorgame = docgame.GetAllocator();
- docgame.AddMember("agent", rapidjson::Value(strextension1.c_str(), allocatorgame), allocatorgame);
- docgame.AddMember("user", rapidjson::Value(strwebonlyuser.c_str(), allocatorgame), allocatorgame);
- weblib::httpinfo thttpinfo{};
- thttpinfo.strurl = std::move(struserip);
- thttpinfo.strtarget = "webapi/deluser";
- thttpinfo.strjson = funclib::doctojson(docgame);
- m_gamemsg(thttpinfo, std::move([this, iuserid, iserverid, icontextid, dofun = std::move(dofun)](std::string &strdata, int iret)mutable
- {
- //踢出成功
- std::string strtojson = funclib::rettojson(-1, "ok");
- if (strdata == "del")
- {
- std::function<void()> tfun = [this, iuserid, iserverid, icontextid, dofun = std::move(dofun), strtojson]() mutable{
- auto finduserview = make_document(kvp("userid", iuserid), kvp("serverid", iserverid), kvp("contextid", icontextid));
- m_pplayuseronline->delete_one(finduserview.view());
- dofun(strtojson, 200);
- };
- m_postmsg(std::move(tfun));
- return;
- }
- dofun(strtojson, 200);
- }));
- return {};
- }
- else
- {
- std::string strtojson = funclib::errotojson(Err_Player_NotOnline);
- return strtojson;
- }
- }
- //管理员禁止管理员所属玩家
- std::string HttpSocket::adminforbiduser(std::map<std::string, std::string> getdata)
- {
- prohibituser tprohibituser;
- getvaluedata(getdata, tprohibituser);
- std::string strret{};
- bool bret = tprohibituser.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_No_Agent, "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(Err_OutOfState_Agent, "spreaderid is disabled");
- return strret;
- }
- auto userupdate = make_document(kvp("$set", make_document(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<std::string, std::string> getdata)
- {
- getaccount tgetaccount;
- getvaluedata(getdata, tgetaccount);
- std::string strret{};
- bool bret = tgetaccount.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_No_Agent, "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(Err_OutOfState_Agent, "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(Err_No_Player, "the account is not exist");
- return strret;
- }
- if (!finduser->view()["spreaderid"])
- {
- strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist1");
- return strret;
- }
- ispreaderid = finduser->view()["spreaderid"].get_int64();
- if (ispreaderid != iadminuserid)
- {
- strret = funclib::rettojson(Err_UserIdNotMatchSpreadId, "the account is not belong to you");
- return strret;
- }
- if (!finduser->view()["userid"])
- {
- strret = funclib::rettojson(Err_Player_LackInfo, "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(Err_LoseWinTableNotFound, "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<std::string, std::string> getdata)
- {
- userinfo tuserinfo;
- getvaluedata(getdata, tuserinfo);
- std::string strret{};
- bool bret = tuserinfo.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_No_Agent, "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(Err_OutOfState_Agent, "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(Err_UserIdNotMatchSpreadId, "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<std::string, std::string> getdata)
- {
- adminprohibituser tadminprohibituser;
- getvaluedata(getdata, tadminprohibituser);
- std::string strret{};
- bool bret = tadminprohibituser.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_No_Agent, "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(Err_OutOfState_Agent, "spreaderid is disabled");
- return strret;
- }
- auto userupdate = make_document(kvp("$set", make_document(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<std::string, std::string> getdata)
- {
- sellbuyscoreinfo tsellbuyscoreinfo;
- getvaluedata(getdata, tsellbuyscoreinfo);
- std::string strret{};
- bool bret = tsellbuyscoreinfo.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- rapidjson::Document doc;
- doc.SetObject();
- rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
- doc.AddMember("ret", -1, allocator);
- __int64 adminuserid = 0;
- __int64 beforuserscore = 0;
- __int64 afteruserscore = 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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
- return strret;
- }*/
-
- if (tsellbuyscoreinfo.iuserid > 0) // 查询玩家
- {
- auto finduser = m_pcoll->find_one(make_document(kvp("userid", tsellbuyscoreinfo.iuserid)));
- if (!finduser || !finduser->view()["spreaderid"])
- {
- strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist1");
- return strret;
- }
- adminuserid = finduser->view()["spreaderid"].get_int64();
- }
- else
- {
- adminuserid = tsellbuyscoreinfo.iagentid;
- }
- auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
- if (!vipuser)
- {
- strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
- return strret;
- }
- __int32 vipstate = 1;
- if (vipuser->view()["state"])
- vipstate = vipuser->view()["state"].get_int32();
- if (vipstate != 0)
- {
- strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
- return strret;
- }
- auto timeview = make_document(kvp("inserttime", -1));
- mongocxx::options::find options;
- options.sort(timeview.view());
- options.limit(20);
- options.skip(tsellbuyscoreinfo.ipagenum * 20);
- document findinfo;
- findinfo.append(kvp("inserttime", make_document(kvp("$lte", tsellbuyscoreinfo.endtime), kvp("$gt", tsellbuyscoreinfo.begintime))));
- if (tsellbuyscoreinfo.iuserid > 0)
- findinfo.append(kvp("userid", tsellbuyscoreinfo.iuserid));
- else if(adminuserid > 0)
- findinfo.append(kvp("spreaderid", adminuserid));
- else
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- 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();
-
- if (!tempinfo["userid"])
- continue;
- sellbuyinfodoc.AddMember("userid", tempinfo["userid"].get_int64(), sallocator);
- itype = 0;
- if (tempinfo["type"])
- itype = tempinfo["type"].get_int32();
- sellbuyinfodoc.AddMember("type", itype, sallocator);
-
- itradescore = 0;
- if (tempinfo["tradescore"])
- itradescore = tempinfo["tradescore"].get_int64();
- std::string stritradescore = getdouble(itradescore);
- sellbuyinfodoc.AddMember("tradescore", rapidjson::Value(stritradescore.c_str(), sallocator), sallocator);
- beforuserscore = 0;
- if (tempinfo["beforeuserscore"])
- beforuserscore = tempinfo["beforeuserscore"].get_int64();
- std::string strbeforuserscore = getdouble(beforuserscore);
- sellbuyinfodoc.AddMember("beforeuserscore", rapidjson::Value(strbeforuserscore.c_str(), sallocator), sallocator);
- afteruserscore = 0;
- if (tempinfo["afteruserscore"])
- afteruserscore = tempinfo["afteruserscore"].get_int64();
- std::string strafteruserscore = getdouble(afteruserscore);
- sellbuyinfodoc.AddMember("afteruserscore", rapidjson::Value(strafteruserscore.c_str(), sallocator), sallocator);
- inserttime = 0;
- if (tempinfo["inserttime"])
- inserttime = tempinfo["inserttime"].get_int64();
- sellbuyinfodoc.AddMember("inserttime", inserttime, sallocator);
- rapidjson::Value element(rapidjson::kObjectType);
- element.CopyFrom(sellbuyinfodoc, allocator);
- timeArray.PushBack(element, allocator);
- }
- doc.AddMember("data", timeArray, allocator);
- //操作成功
- strret = funclib::doctojson(doc);
- return strret;
- }
- //查询游戏每局记录
- std::string HttpSocket::playgameinfo(std::map<std::string, std::string> getdata)
- {
- playinfo tplayinfo;
- getvaluedata(getdata, tplayinfo);
- std::string strret{};
- bool bret = tplayinfo.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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 || !threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- iadminuserid = threeadmin->view()["adminuserid"].get_int64();
- auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "userid" << tplayinfo.iuserid << bsoncxx::builder::stream::finalize);
- if (!finduser)
- {
- strret = funclib::rettojson(Err_No_Player, "the account is not exist");
- return strret;
- }
- if (!finduser->view()["spreaderid"])
- {
- strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist1");
- return strret;
- }
- userspreadid = finduser->view()["spreaderid"].get_int64();
- if (iadminuserid != userspreadid)
- {
- strret = funclib::rettojson(Err_Player_LackInfo, "the account does not belong to you");
- return strret;
- }
- auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize);
- if (!vipuser)
- {
- strret = funclib::rettojson(Err_No_Agent, "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(Err_OutOfState_Agent, "spreaderid is disabled");
- return strret;
- }
- auto findinfo = make_document(kvp("userid", tplayinfo.iuserid), kvp("gametype", tplayinfo.igametype),
- kvp("inserttime", make_document(kvp("$lte", tplayinfo.endtime), kvp("$gte", tplayinfo.begintime))));
- auto timeview = make_document(kvp("inserttime", -1));
- mongocxx::options::find options;
- options.sort(timeview.view());
- options.limit(tplayinfo.ipagesize);
- options.skip(tplayinfo.ipagenum* tplayinfo.ipagesize);
- 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"])
- continue;
-
- strtemp = tempinfo["dbquestid"].get_utf8().value.data();
- gameinfodoc.AddMember("betid", rapidjson::Value(strtemp.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();
- gameinfodoc.AddMember("tableid", itemp32, 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();
- }
- gameinfodoc.AddMember("inserttime", itemp64, 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<std::string, std::string> 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(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_No_Agent, "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(Err_OutOfState_Agent, "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(Err_AgengtHasNoPlayer, "the vip don't have player");
- return strret;
- }
- auto findinfo = make_document(
- kvp("inserttime", make_document(kvp("$lte", tplayscoreinfo.endtime), 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<std::string, std::string> getdata)
- {
- updateingot tupdateingot;
- getvaluedata(getdata, tupdateingot);
- std::string strret{};
- auto findscore = getdata.find("score");
- if (findscore == getdata.end())
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- std::int32_t iret = 0;
- tupdateingot.score = stringToint64_t(findscore->second, iret);
- if (iret == -1)
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- if (tupdateingot.score <= 0)
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- bool bret = tupdateingot.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_No_Agent, "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(Err_OutOfState_Agent, "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(Err_No_Player, "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(Err_Player_LackInfo, "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(Err_Player_LackInfo, "the account is not exist1");
- return strret;
- }
- userspreadid = finduser->view()["spreaderid"].get_int64();
- if (userspreadid != iadminuserid)
- {
- strret = funclib::rettojson(Err_UserIdNotMatchSpreadId, "the account is not belong to you");
- return strret;
- }
- //目前只支持赠送奖励码
- if (tupdateingot.score <= 0)
- {
- strret = funclib::rettojson(Err_ScoreParamError, "the score's erro");
- return strret;
- }
- itempscore = ivipscore - tupdateingot.score;
- //判断vip有没有足够的分数
- if (itempscore < 0)
- {
- strret = funclib::rettojson(Err_AgentScoreNotEnough, "the vip does not have enough score");
- return strret;
- }
- afteruserscore = beforeuserscore + tupdateingot.score;
- //获取要减的分数
- itempscore = tupdateingot.score * -1;
- //减商家分数
- auto criteria = make_document(kvp("userid", iadminuserid));
- auto update = make_document(kvp("$inc", make_document(kvp("score", itempscore))));
- auto retscore = m_pvipuser->find_one_and_update(criteria.view(), update.view());
- if (!retscore)
- {
- strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "modify score erro");
- return strret;
- }
- if (!retscore->view()["score"] || !retscore->view()["name"] || !retscore->view()["account"] || !retscore->view()["loginip"])
- {
- strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "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 = make_document(kvp("userid", iuserid));
- auto userupdate = make_document(kvp("$inc", make_document(kvp("score", itempscore))),
- kvp("$inc", make_document(kvp("ingot", itempscore))));
- auto userretscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view());
- if (!userretscore)
- {
- strret = funclib::rettojson(Err_UserUpdateScoreFailed, "add user score erro");
- return strret;
- }
- //加用户分数
- tradescore = tupdateingot.score;
- __int64 iOne32 = 1;
- auto vipscorecriteria = make_document(kvp("business", iOne32));
- auto vipscoreupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(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 = make_document(kvp("inserttime", inserttimetemp));
- auto vipscoredateupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
- m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view());
- }
- }
- }
- //记录充值分数
- auto rechargecriteria = make_document(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 = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
- kvp("$set", make_document(kvp("todayczscore", tradescore))),
- kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
- m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
- }
- else
- {
- auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
- kvp("$inc", make_document(kvp("todayczscore", tradescore))),
- kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
- m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
- }
- }
- else
- {
- auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
- kvp("$inc", make_document(kvp("todayczscore", tradescore))),
- kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
- m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
- }
- //记录奖励码总数
- //auto temptotalingot = make_document(kvp("$inc", make_document(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<std::string, std::string> getdata)
- {
- backingot tbackingot;
- getvaluedata(getdata, tbackingot);
- std::string strret{};
- auto findscore = getdata.find("score");
- if (findscore == getdata.end())
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- std::int32_t iret = 0;
- tbackingot.score = stringToint64_t(findscore->second, iret);
- if (iret == -1)
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- if (tbackingot.score <= 0)
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- bool bret = tbackingot.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_No_Agent, "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(Err_OutOfState_Agent, "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(Err_No_Player, "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(Err_Player_LackInfo, "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(Err_Trade_UserScoreLack, "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(Err_Player_LackInfo, "the account is not exist1");
- return strret;
- }
- userspreadid = finduser->view()["spreaderid"].get_int64();
- if (userspreadid != iadminuserid)
- {
- strret = funclib::rettojson(Err_UserIdNotMatchSpreadId, "the account is not belong to you");
- return strret;
- }
- //减用户的奖励码
- itempscore = -1* tbackingot.score;
- auto usercriteria = make_document(kvp("userid", iuserid));
- auto userupdate = make_document(kvp("$inc", make_document(kvp("score", itempscore))),
- kvp("$inc", make_document(kvp("ingot", itempscore))));
- auto tempscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view());
- if (!tempscore)
- {
- strret = funclib::rettojson(Err_UserUpdateScoreFailed, "reduce user score erro");
- return strret;
- }
- afteruserscore = beforeuserscore - tbackingot.score;
- //增加商家的分数
- tradescore = tbackingot.score;
- //添加玩家总下分
- auto xiafenupdate = make_document(kvp("$inc", make_document(kvp("totalxfscore", tradescore))));
- m_plosewincoll->find_one_and_update(usercriteria.view(), xiafenupdate.view());
- //增加商家的分数
- auto admincriteria = make_document(kvp("userid", iadminuserid));
- auto adminupdate = make_document(kvp("$inc", make_document(kvp("score", tradescore))));
- auto adminretscore = m_pvipuser->find_one_and_update(admincriteria.view(), adminupdate.view());
- if (!adminretscore)
- {
- strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "add business score erro");
- return strret;
- }
- __int64 iOne32 = 1;
- auto vipscorecriteria = make_document(kvp("business", iOne32));
- auto vipscoreupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(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 = make_document(kvp("inserttime", inserttimetemp));
- auto vipscoredateupdate = make_document(kvp("$inc", make_document(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 = make_document(kvp("$set", make_document(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<std::string, std::string> getdata)
- {
- allplayscoreinfo tallplayscoreinfo;
- getvaluedata(getdata, tallplayscoreinfo);
- std::string strret{};
- bool bret = tallplayscoreinfo.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "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(Err_KeyNotExist, "code or key isnot exist");
- return strret;
- }
- if (!threeadmin->view()["adminuserid"])
- {
- strret = funclib::rettojson(Err_ThreeAdminLackInfo, "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(Err_No_Agent, "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(Err_OutOfState_Agent, "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(make_document(kvp("userid", 1), 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<std::int64_t, std::string>::value_type(tempuserid, tempname));
- }
- badd = true;
- }
- if (!badd)
- {
- strret = funclib::rettojson(Err_AgengtHasNoPlayer, "the vip don't have player");
- return strret;
- }
- std::int32_t iskipnum = 1000 * tallplayscoreinfo.ipagenum;
- if (iskipnum < 0)
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- std::int64_t dectime = tallplayscoreinfo.endtime - tallplayscoreinfo.begintime;
- if (dectime > 604800000)
- {
- strret = funclib::rettojson(Err_OverQueryTimeLimit, "time erro");
- return strret;
- }
- // NEWLOG(INFO, "msglog") << "-------" << "tallplayscoreinfo.begintime=" << tallplayscoreinfo.begintime
- // << " tallplayscoreinfo.endtime=" << tallplayscoreinfo.endtime << " iadminuserid=" << iadminuserid
- // << " iskipnum=" << iskipnum;
- taggameuserlog tempvect;
- document files_filter;
- files_filter.append(kvp("spreaderid", iadminuserid));
- files_filter.append(kvp("$and",
- make_array(
- make_document(kvp("inserttime",
- make_document(kvp("$gte", tallplayscoreinfo.begintime)))),
- make_document(kvp("inserttime",
- make_document(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;
- }
- std::string HttpSocket::reelplay(std::map<std::string, std::string> getdata, std::function<void(std::string&, int)>& dofun)
- {
- reelplayuser treelplayuser;
- getvaluedata(getdata, treelplayuser);
- std::string strret;
- m_writelog("--------------------reelplay-------------------------");
- bool bret = treelplayuser.datavalue();
- if (!bret)
- {
- strret = funclib::rettojson(Err_ParamError, "param erro");
- return strret;
- }
- std::int32_t iareaid{ 0 };
- std::int64_t ispreaderid{ 0 };
- //验证代理是否存在
- auto findagentview = make_document(kvp("account", treelplayuser.strextension1.c_str()), kvp("cert", treelplayuser.strcert.c_str()));
- auto vipuser = m_pvipuser->find_one(findagentview.view());
- if (!vipuser || !vipuser->view()["userid"] || !vipuser->view()["areaid"] || !vipuser->view()["apitype"])
- {
- strret = funclib::errotojson(Err_No_Agent);
- return strret;
- }
- iareaid = vipuser->view()["areaid"].get_int32();
- ispreaderid = vipuser->view()["areaid"].get_int32();
- std::int32_t userstate = 1;
- if (vipuser && vipuser->view()["state"])
- {
- userstate = vipuser->view()["state"].get_int32();
- }
- if (userstate != 0)
- {
- strret = funclib::rettojson(Err_OutOfState_Agent, "agent statue error");
- return strret;
- }
- std::int32_t iapitype = vipuser->view()["apitype"].get_int32();
- if (iapitype != 2)
- {
- strret = funclib::rettojson(Err_OutOfState_Agent, "agent type error");
- return strret;
- }
- auto findwebuser = make_document(kvp("account", treelplayuser.struseracc.c_str()));
- auto findneuserdata = m_pcoll->find_one(findwebuser.view());
- if (!findneuserdata)
- {
- //用户账号存在
- strret = funclib::errotojson(Err_No_Player);
- return strret;
- }
- std::int64_t iscore{ 0 };
- if (findneuserdata && findneuserdata->view()["score"])
- {
- iscore = findneuserdata->view()["score"].get_int64();
- }
- std::string struseracc = treelplayuser.struseracc;
- createreeluser(struseracc, iscore, dofun);
- return {};
- }
- void HttpSocket::sendreelmsg(std::string stronly, std::string strtarget, std::string strjson, std::function<void(std::string, int)>&& dofun)
- {
- weblib::httpinfo thttpinfo;
- thttpinfo.strurl = "https://transfer-wallet-service.stage.iconic-21.com";
- // thttpinfo.strurl = "http://127.0.0.1:6000";
- thttpinfo.strtarget = strtarget;
- thttpinfo.stronly = stronly;
- std::string strshaheadcontent = m_strshaheadcontent + strjson;
- strshaheadcontent = sha256_to_base16(strshaheadcontent);
- thttpinfo.addheadinfo.insert(std::make_pair(m_strshahead, strshaheadcontent));
- thttpinfo.strjson = strjson;
- std::stringstream sss;
- sss << "strurl=" << thttpinfo.strurl << " strtarget=" << strtarget << " strshaheadcontent=" << strshaheadcontent << " strjson=" << strjson;
- m_writelog(sss.str());
- weblib::sendhttp(m_psendhttp, std::move(thttpinfo), std::move(dofun));
- }
- //检查玩家钱包
- void HttpSocket::checkreeluserbalance(std::string struseracc, std::int64_t iscore)
- {
- rapidjson::Document doc;
- doc.SetObject();
- rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
- doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
- doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
- //std::string strjson{ "{\"casino\":\"luckybet777\",\"playerId\":\"testPlayer_5\",\"currency\":\"EUR\",\"country\":\"US\"}" };
- std::string strjson = funclib::doctojson(doc);
- std::string strtarget = "v2/tw/balance";
- }
- //创建玩家
- void HttpSocket::createreeluser(std::string struseracc, std::int64_t iscore, std::function<void(std::string&, int)>& dofun)
- {
- m_writelog("--------------------createreeluser-------------------------");
- rapidjson::Document doc;
- doc.SetObject();
- rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
- doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
- doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
- doc.AddMember("currency", rapidjson::Value("EUR", allocator), allocator);
- doc.AddMember("country", rapidjson::Value("US", allocator), allocator);
- //std::string strjson{ "{\"casino\":\"luckybet777\",\"playerId\":\"testPlayer_5\",\"currency\":\"EUR\",\"country\":\"US\"}" };
- std::string strjson = funclib::doctojson(doc);
- std::string strtarget = "v2/tw/createPlayer";
- //创建玩家
- sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, iscore, dofun](std::string strdata, int iret) {
-
- std::stringstream strlog;
- strlog << "创建玩家: iret=" << iret << " strdata=" << strdata;
- m_writelog(strlog.str());
- bool bhaveuser{ false };
- if (iret == 200)
- {
- rettype::type tret{ rettype::type::ini };
- rapidjson::Document docdata;
- rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
- if (ok)
- {
- std::string strstatus{};
- tret = funclib::getjsonvalue(docdata, "status", strstatus);
- if (tret == rettype::type::exist)
- {
- if (strstatus == "ok")
- {
- bhaveuser = true;
- }
- }
- }
- }
- //玩家创建成功
- if (bhaveuser)
- {
- reelusertrans(struseracc, iscore, dofun);
- }
- else
- {
- std::string strret = funclib::errotojson(-1);
- dofun(strret, 200);
- }
- }));
- }
- void HttpSocket::reelusertrans(std::string struseracc, std::int64_t iscore, std::function<void(std::string&, int)> dofun)
- {
- m_writelog("--------------------reelusertrans-------------------------");
- if (iscore > 0)
- {
- rapidjson::Document doc;
- doc.SetObject();
- rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
- std::string strscore = funclib::getdouble(iscore);
- std::string strtransid = funclib::getonlytoken(1, m_ucurid);
- doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
- doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
- doc.AddMember("transactionId", rapidjson::Value(strtransid.c_str(), allocator), allocator);
- doc.AddMember("amount", rapidjson::Value(strscore.c_str(), allocator), allocator);
- std::string strjson = funclib::doctojson(doc);
- std::string strtarget = "v2/tw/transfer";
- sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun, iscore](std::string strdata, int iret) {
- std::stringstream strlog;
- strlog << "转账: iscore=" << iscore << " iret=" << iret << " strdata=" << strdata;
- m_writelog(strlog.str());
- double dscore{ 0 };
- bool bscore{ false };
- if (iret == 200)
- {
- rettype::type tret{ rettype::type::ini };
- rapidjson::Document docdata;
- rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
- if (ok)
- {
- tret = funclib::getjsonvalue(docdata, "balance", dscore);
- if (tret == rettype::type::exist)
- {
- bscore = true;
- }
- else
- {
- std::string strscore{};
- tret = funclib::getjsonvalue(docdata, "balance", strscore);
- if (tret == rettype::type::exist)
- {
- try
- {
- dscore = std::stod(strscore);
- bscore = true;
- }
- catch (const std::exception&)
- {
- bscore = false;
- }
- }
- }
- }
- }
- //转账成功
- if (bscore)
- {
- //执行扣分操作
- m_postmsg(std::move([this]() {
-
- //验证代理是否存在
- //auto findagentview = make_document(kvp("account", treelplayuser.strextension1.c_str()), kvp("cert", treelplayuser.strcert.c_str()));
- //auto vipuser = m_pvipuser->find_one(findagentview.view());
- //if (!vipuser || !vipuser->view()["userid"] || !vipuser->view()["areaid"] || !vipuser->view()["apitype"])
- //{
- //strret = funclib::errotojson(Err_No_Agent);
- //return strret;
- //}
- }));
- //直接拉取游戏
- getreelgameurl(struseracc, dofun);
- }
- else
- {
- std::string strret = funclib::errotojson(-1);
- dofun(strret, 200);
- }
- }));
- }
- else
- {
- m_writelog("iscore = 0, 直接拉取游戏");
- //直接拉取游戏
- getreelgameurl(struseracc, dofun);
- }
- }
- //拉取游戏
- void HttpSocket::getreelgameurl(std::string struseracc, std::function<void(std::string&, int)> dofun)
- {
- m_writelog("--------------------getreelgameurl-------------------------");
- rapidjson::Document doc;
- doc.SetObject();
- rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
- //cashier:URL for opening the cashier on Casino site when a player has no funds.
- //homepage:URL for returning to Lobby page on Casino site. This link is used for Exit button in mobile version of games.
- //{"casino":"whitebom","playerId":"testPlayer_1","launchAlias":"launch_main_rol_01","language":"en","cashier":"https://cashier.com","homepage":"https://home.com"}
- std::string strtransid = funclib::getonlytoken(1, m_ucurid);
- doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
- doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
- doc.AddMember("launchAlias", rapidjson::Value("launch_main_rol_01", allocator), allocator);
- doc.AddMember("language", rapidjson::Value("en", allocator), allocator);
- doc.AddMember("cashier", rapidjson::Value("https://cashier.com", allocator), allocator);
- doc.AddMember("homepage", rapidjson::Value("https://home.com", allocator), allocator);
- std::string strjson = funclib::doctojson(doc);
- std::string strtarget = "v2/tw/startGame";
- sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun](std::string strdata, int iret) {
-
- std::stringstream strlog;
- strlog << "拉取游戏: iret=" << iret << " strdata=" << strdata;
- m_writelog(strlog.str());
- if (iret == 200)
- {
- rettype::type tret{ rettype::type::ini };
- rapidjson::Document docdata;
- rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
- if (ok)
- {
- dofun(strdata, 200);
- }
- }
- else
- {
- std::string strret = funclib::errotojson(-1);
- dofun(strret, 200);
- }
-
- }));
- }
|