HttpSocket.cpp 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568
  1. #include "pch.h"
  2. #include "HttpSocket.h"
  3. #include "md5.h"
  4. mongocxx::instance g_instance{};
  5. using namespace bsoncxx::builder::basic;
  6. bool comparegamelist(const rapidjson::Value& a, const rapidjson::Value& b)
  7. {
  8. if (!a.HasMember("SortID") || !strcmp(a["SortID"].GetString(), "-1"))
  9. return false;
  10. if (!b.HasMember("SortID") || !strcmp(b["SortID"].GetString(), "-1"))
  11. return true;
  12. std::string stra = a["SortID"].GetString();
  13. std::string strb = b["SortID"].GetString();
  14. if (stra.empty() || strb.empty())
  15. {
  16. return false;
  17. }
  18. return std::stoi(a["SortID"].GetString()) < std::stoi(b["SortID"].GetString());
  19. }
  20. std::uint32_t HttpSocket::m_gucurid = 0;
  21. HttpSocket::HttpSocket()
  22. {
  23. m_random = std::default_random_engine(time(NULL));
  24. //数据库配置
  25. {
  26. std::string strkkk3 = "mongodb://127.0.0.1:27017";
  27. m_puri = boost::make_shared<mongocxx::uri>(strkkk3.c_str());
  28. }
  29. m_pclient = boost::make_shared <mongocxx::client>(*m_puri);
  30. m_platform = boost::make_shared<mongocxx::database>();
  31. m_pdb = boost::make_shared<mongocxx::database>();
  32. m_gamelog = boost::make_shared<mongocxx::database>();
  33. m_pvipuserdb = boost::make_shared<mongocxx::database>();
  34. m_pallindex = boost::make_shared<mongocxx::collection>();
  35. m_pcoll = boost::make_shared<mongocxx::collection>();
  36. m_plosewincoll = boost::make_shared<mongocxx::collection>();
  37. m_pvipuser = boost::make_shared<mongocxx::collection>();
  38. m_pplayuseronline = boost::make_shared<mongocxx::collection>();
  39. m_userloginonline = boost::make_shared<mongocxx::collection>();
  40. m_pusertradeinfo = boost::make_shared<mongocxx::collection>();
  41. m_pviptradeinfo = boost::make_shared<mongocxx::collection>();
  42. m_poperatinfo = boost::make_shared<mongocxx::collection>();
  43. m_pvipscore = boost::make_shared<mongocxx::collection>();
  44. m_pvipscoredate = boost::make_shared<mongocxx::collection>();
  45. m_pvipuseraccounts = boost::make_shared<mongocxx::collection>();
  46. m_puserdatainfo = boost::make_shared<mongocxx::collection>();
  47. m_pthreeadmin = boost::make_shared<mongocxx::collection>();
  48. m_pgameprizelog = boost::make_shared<mongocxx::collection>();
  49. m_pvipconfigure = boost::make_shared<mongocxx::collection>();
  50. m_pgamelist = boost::make_shared<mongocxx::collection>();
  51. *m_pdb = (*m_pclient)["accounts"];
  52. *m_gamelog = (*m_pclient)["gamelog"];
  53. *m_platform = (*m_pclient)["platform"];
  54. *m_pvipuserdb = (*m_pclient)["vipuser"];
  55. *m_pallindex = (*m_pdb)["allindex"];
  56. *m_pcoll = (*m_pdb)["userinfo"];
  57. *m_plosewincoll = (*m_pdb)["losewin"];
  58. *m_pgameprizelog = (*m_gamelog)["gameprizelog"];
  59. *m_pvipuser = (*m_pvipuserdb)["user"];
  60. *m_pplayuseronline = (*m_gamelog)["playuseronline"];
  61. *m_userloginonline = (*m_gamelog)["userloginonline"];
  62. *m_poperatinfo = (*m_gamelog)["operatinfo"];
  63. *m_pusertradeinfo = (*m_pvipuserdb)["usertradeinfo"];
  64. *m_pviptradeinfo = (*m_pvipuserdb)["viptradeinfo"];
  65. *m_pvipscore = (*m_pvipuserdb)["vipscore"];
  66. *m_pvipscoredate = (*m_pvipuserdb)["vipscoredate"];
  67. *m_pvipuseraccounts= (*m_pvipuserdb)["vipuseraccounts"];
  68. *m_puserdatainfo = (*m_gamelog)["userdatainfo"];
  69. *m_pthreeadmin = (*m_pvipuserdb)["threeadmin"];
  70. *m_pvipconfigure = (*m_pvipuserdb)["vipconfigure"];
  71. *m_pgamelist = (*m_platform)["gamelist"];
  72. m_strshahead = "X-REQUEST-SIGN";
  73. m_strshaheadcontent = "6e4c91001979851a97c2b5360f044ff67b48e186d6ecd4394532851bffdeeae9";
  74. m_ucurid = m_gucurid++;
  75. m_psendhttp = weblib::httpini();
  76. //获取gamelist
  77. funcmsg fun1 = std::bind(&HttpSocket::getgamelist, this, std::placeholders::_1);
  78. m_callmsg.insert(make_pair("api/game/gamelist", fun1));
  79. }
  80. HttpSocket::~HttpSocket()
  81. {
  82. stopmsg();
  83. }
  84. void HttpSocket::stopmsg()
  85. {
  86. weblib::delhttp(m_psendhttp);
  87. }
  88. void HttpSocket::init()
  89. {
  90. staticdata tstaticdata;
  91. try
  92. {
  93. makegamelist(tstaticdata);
  94. m_updatestatic("staticdata", tstaticdata);
  95. }
  96. catch (const std::exception&)
  97. {
  98. }
  99. }
  100. bool HttpSocket::postmsg(std::function<void(std::string&, int)> funhttpmsg, std::map<std::string, std::string> getdata)
  101. {
  102. try
  103. {
  104. std::string strtojson{};
  105. auto& findkey = getdata.find("itype");
  106. if (findkey != getdata.end())
  107. {
  108. std::int32_t itype = funclib::strtonum<std::int32_t>(findkey->second);
  109. //玩家账号注册
  110. if (itype == HTTPREGUSER)
  111. {
  112. strtojson = regaccount(getdata);
  113. }
  114. //更新玩家分数
  115. else if (itype == HTTPUPDATEUSERSCORE)
  116. {
  117. strtojson = updateuserscore(getdata, funhttpmsg);
  118. }
  119. //把玩家踢出游戏
  120. else if (itype == HTTPADMINKICKUSER)
  121. {
  122. strtojson = adminhituser(getdata, funhttpmsg);
  123. }
  124. //管理员禁止管理员所属玩家
  125. else if (itype == HTTPADMINPROHIBITUSER)
  126. {
  127. strtojson = adminforbiduser(getdata);
  128. }
  129. //获取账号
  130. else if (itype == HTTPGETUSERACCOUNT)
  131. {
  132. strtojson = getuseraccount(getdata);
  133. }
  134. //修改玩家信息
  135. else if (itype == HTTPMODIFYUSERPWD)
  136. {
  137. strtojson = modifyuserinfo(getdata);
  138. }
  139. //管理员禁止直属玩家
  140. else if (itype == HTTPADMINPROHIBITMYUSER)
  141. {
  142. strtojson = adminforbidmyuser(getdata);
  143. }
  144. //查询充值记录
  145. else if (itype == HTTPLOOKUPCZ)
  146. {
  147. strtojson = sellbuyinfo(getdata);
  148. }
  149. //查询每局游戏记录
  150. else if (itype == HTTPLOOKUPPLAYGAME)
  151. {
  152. strtojson = playgameinfo(getdata);
  153. }
  154. //查询玩家总下注和总赢回
  155. else if (itype == HTTPLOOKUPUSERPLAYSCORE)
  156. {
  157. strtojson = getuserplayscoreinfo(getdata);
  158. }
  159. //添加奖励码
  160. else if (itype == HTTPLUPDATEUSERINGOT)
  161. {
  162. strtojson = updateuseringot(getdata);
  163. }
  164. //下奖励码
  165. else if (itype == HTTPLBACKINGOT)
  166. {
  167. strtojson = backuseringot(getdata);
  168. }
  169. //查询用户总压注
  170. else if (itype == HTTPLOOKUPALLUSERPLAYSCORE)
  171. {
  172. strtojson = getalluserplayscoreinfo(getdata);
  173. }
  174. //登录真人视讯
  175. else if (itype == HTTPLOGINREEL)
  176. {
  177. reelplay(getdata, funhttpmsg);
  178. }
  179. else
  180. {
  181. return false;
  182. }
  183. funhttpmsg(strtojson, 200);
  184. return true;
  185. }
  186. else
  187. {
  188. const auto& findpathkey = getdata.find("path_key");
  189. if (findpathkey != getdata.end())
  190. {
  191. auto& funmsg = m_callmsg.find(findpathkey->second);
  192. if (funmsg != m_callmsg.end())
  193. {
  194. try
  195. {
  196. strtojson = funmsg->second(getdata);
  197. }
  198. catch (std::exception& e)
  199. {
  200. //NEWLOG(INFO, "msglog") << e.what();
  201. strtojson = "";
  202. }
  203. }
  204. }
  205. funhttpmsg(strtojson, 200);
  206. return true;
  207. }
  208. }
  209. catch (std::exception& e)
  210. {
  211. }
  212. std::string strerror{ "{\"error\":1}" };
  213. int iret = -1;
  214. funhttpmsg(strerror, iret);
  215. return true;
  216. }
  217. void HttpSocket::updatemsg(std::string strtype, boost::any getdata)
  218. {
  219. if (strtype == "staticdata")
  220. {
  221. m_staticdata = boost::any_cast<staticdata>(getdata);
  222. }
  223. }
  224. void HttpSocket::makegamelist(staticdata& tstaticdata)
  225. {
  226. tstaticdata = m_staticdata;
  227. tstaticdata.m_maparead.clear();
  228. std::int32_t iareaid = 0;
  229. std::string strcode = "";
  230. //auto findarea = m_pexechangerate->find({});
  231. //for (const auto& doc : findarea)
  232. //{
  233. // iareaid = doc["areaid"].get_int32();
  234. // strcode = doc["code"].get_utf8().value.data();
  235. // tstaticdata.m_maparead.insert(std::make_pair(iareaid, strcode));
  236. //}
  237. //std::string strip{};
  238. //boost::property_tree::ptree pt;
  239. //try
  240. //{
  241. // boost::property_tree::ini_parser::read_ini("d:\\game\\config.ini", pt);
  242. // strip = pt.get<std::string>("ip.wkey");
  243. // //NEWLOG(INFO, "clienterro") << "ip=" << strip;
  244. //}
  245. //catch (const std::exception& e)
  246. //{
  247. // //NEWLOG(INFO, "clienterro") << "ip=" << strip;
  248. //}
  249. //获取url
  250. std::int32_t iurlname = 9;
  251. auto findurl = make_document(kvp("name", iurlname));
  252. auto urlinfo = m_pallindex->find_one(findurl.view());
  253. if (urlinfo && urlinfo->view()["url"])
  254. {
  255. tstaticdata.m_strgameurl = urlinfo->view()["url"].get_utf8().value.data();
  256. }
  257. rapidjson::Document gamelist;
  258. gamelist.SetObject();
  259. rapidjson::Document::AllocatorType& allocator = gamelist.GetAllocator();
  260. rapidjson::Document subgame;
  261. subgame.SetObject();
  262. rapidjson::Document::AllocatorType& suballocator = subgame.GetAllocator();
  263. auto pgamelist = m_pgamelist->find_one({});
  264. if (pgamelist)
  265. {
  266. std::string strgameicourl = "";
  267. bsoncxx::document::view subdoc = pgamelist->view()["data"].get_document().value;
  268. if (subdoc["test"] && 1 == subdoc["test"].get_int32()) // 测试环境
  269. tstaticdata.bTest = true;
  270. gamelist.AddMember("downloadurl", rapidjson::Value(subdoc["downloadurl"].get_utf8().value.data(), allocator), allocator);
  271. gamelist.AddMember("android_url", rapidjson::Value(subdoc["android_url"].get_utf8().value.data(), allocator), allocator);
  272. gamelist.AddMember("resversion", rapidjson::Value(subdoc["resversion"].get_utf8().value.data(), allocator), allocator);
  273. gamelist.AddMember("baseversion", rapidjson::Value(subdoc["baseversion"].get_utf8().value.data(), allocator), allocator);
  274. if (subdoc["zib"])
  275. gamelist.AddMember("zib", subdoc["zib"].get_int32(), allocator);
  276. if (subdoc["s3"])
  277. gamelist.AddMember("s3", rapidjson::Value(subdoc["s3"].get_utf8().value.data(), allocator), allocator);
  278. if (subdoc["uploadurl"])
  279. {
  280. gamelist.AddMember("uploadurl", rapidjson::Value(subdoc["uploadurl"].get_utf8().value.data(), allocator), allocator);
  281. }
  282. if (subdoc["return_url"])
  283. {
  284. tstaticdata.m_strreturnurl = subdoc["return_url"].get_utf8().value.data();
  285. gamelist.AddMember("return_url", rapidjson::Value(tstaticdata.m_strreturnurl.c_str(), allocator), allocator);
  286. subgame.AddMember("return_url", rapidjson::Value(tstaticdata.m_strreturnurl.c_str(), allocator), allocator);
  287. }
  288. if (tstaticdata.bTest)//添加测试key
  289. gamelist.AddMember("key", rapidjson::Value("3F6AE262B8F2255EF7EB", allocator), allocator);
  290. if (subdoc["logurl"])
  291. {
  292. tstaticdata.m_strlogurl = subdoc["logurl"].get_utf8().value.data();
  293. gamelist.AddMember("logurl", rapidjson::Value(tstaticdata.m_strlogurl.c_str(), allocator), allocator);
  294. }
  295. if (subdoc["gameicourl"])
  296. {
  297. strgameicourl = subdoc["gameicourl"].get_utf8().value.data();
  298. tstaticdata.m_gameiconurl = strgameicourl;
  299. subgame.AddMember("gameicourl", rapidjson::Value(strgameicourl.c_str(), allocator), allocator);
  300. gamelist.AddMember("gameicourl", rapidjson::Value(strgameicourl.c_str(), allocator), allocator);
  301. }
  302. //创建数组
  303. rapidjson::Value kindidArray(rapidjson::kArrayType);
  304. rapidjson::Value subgameArray(rapidjson::kArrayType);
  305. std::int32_t ikindid = 0;
  306. std::string strkindid{};
  307. auto tempview = subdoc["gamelist"].get_array().value;
  308. for (const bsoncxx::array::element& msg : tempview)
  309. {
  310. if (msg.type() == bsoncxx::type::k_document)
  311. {
  312. bsoncxx::document::view ksubdoc = msg.get_document().value;
  313. rapidjson::Document subgamedoc;
  314. subgamedoc.SetObject();
  315. rapidjson::Document::AllocatorType& ksubgamedocallocator = subgamedoc.GetAllocator();
  316. rapidjson::Document kindiddoc;
  317. kindiddoc.SetObject();
  318. rapidjson::Document::AllocatorType& kallocator = kindiddoc.GetAllocator();
  319. strkindid = ksubdoc["KindID"].get_utf8().value.data();
  320. kindiddoc.AddMember("KindID", rapidjson::Value(strkindid.c_str(), kallocator), kallocator);
  321. ikindid = 0;
  322. try
  323. {
  324. ikindid = std::stoi(strkindid);
  325. }
  326. catch (std::exception& e)
  327. {
  328. ikindid = 0;
  329. }
  330. std::string strkindname = ksubdoc["KindName"].get_utf8().value.data();
  331. std::string strsubgid = "";
  332. if (ksubdoc["GID"] && ikindid != 0)
  333. {
  334. strsubgid = ksubdoc["GID"].get_utf8().value.data();
  335. if (strsubgid.empty())
  336. continue;
  337. if (!strgameicourl.empty())
  338. {
  339. std::string strgametype = ksubdoc["gametype"].get_utf8().value.data();
  340. subgamedoc.AddMember("gid", rapidjson::Value(strsubgid.c_str(), ksubgamedocallocator), ksubgamedocallocator);
  341. subgamedoc.AddMember("name", rapidjson::Value(ksubdoc["KindName"].get_utf8().value.data(), ksubgamedocallocator), ksubgamedocallocator);
  342. subgamedoc.AddMember("gametype", rapidjson::Value(strgametype.c_str(), ksubgamedocallocator), ksubgamedocallocator);
  343. if (ksubdoc["SubLogo"])
  344. {
  345. std::string strsubicon = ksubdoc["SubLogo"].get_utf8().value.data();
  346. kindiddoc.AddMember("SubLogo", rapidjson::Value(strsubicon.c_str(), kallocator), kallocator);
  347. }
  348. }
  349. kindiddoc.AddMember("GID", rapidjson::Value(strsubgid.c_str(), kallocator), kallocator);
  350. }
  351. kindiddoc.AddMember("KindName", rapidjson::Value(strkindname.c_str(), kallocator), kallocator);
  352. kindiddoc.AddMember("ModuleName", rapidjson::Value(ksubdoc["ModuleName"].get_utf8().value.data(), kallocator), kallocator);
  353. kindiddoc.AddMember("ResVersion", rapidjson::Value(ksubdoc["ResVersion"].get_utf8().value.data(), kallocator), kallocator);
  354. if (ksubdoc["SortID"])
  355. {
  356. kindiddoc.AddMember("SortID", rapidjson::Value(ksubdoc["SortID"].get_utf8().value.data(), kallocator), kallocator);
  357. subgamedoc.AddMember("SortID", rapidjson::Value(ksubdoc["SortID"].get_utf8().value.data(), ksubgamedocallocator), ksubgamedocallocator);
  358. }
  359. if (ksubdoc["hot"])
  360. {
  361. subgamedoc.AddMember("hot", ksubdoc["hot"].get_int32(), ksubgamedocallocator);
  362. }
  363. if (ksubdoc["new"])
  364. {
  365. subgamedoc.AddMember("new", ksubdoc["new"].get_int32(), ksubgamedocallocator);
  366. }
  367. if (ksubdoc["brand"])
  368. {
  369. std::string sbrand = ksubdoc["brand"].get_utf8().value.data();
  370. kindiddoc.AddMember("brand", rapidjson::Value(sbrand.c_str(), kallocator), kallocator);
  371. subgamedoc.AddMember("brand", rapidjson::Value(sbrand.c_str(), ksubgamedocallocator), ksubgamedocallocator);
  372. }
  373. if (subdoc["gametype"])
  374. {
  375. kindiddoc.AddMember("gametype", rapidjson::Value(ksubdoc["gametype"].get_utf8().value.data(), kallocator), kallocator);
  376. }
  377. if (ksubdoc["SubLogo"])
  378. {
  379. kindiddoc.AddMember("SubLogo", rapidjson::Value(ksubdoc["SubLogo"].get_utf8().value.data(), kallocator), kallocator);
  380. subgamedoc.AddMember("SubLogo", rapidjson::Value(ksubdoc["SubLogo"].get_utf8().value.data(), ksubgamedocallocator), ksubgamedocallocator);
  381. }
  382. //把文档加入数组
  383. rapidjson::Value element(rapidjson::kObjectType);
  384. element.CopyFrom(kindiddoc, allocator);
  385. kindidArray.PushBack(element, allocator);
  386. rapidjson::Value subgameelement(rapidjson::kObjectType);
  387. subgameelement.CopyFrom(subgamedoc, suballocator);
  388. subgameArray.PushBack(subgameelement, suballocator);
  389. if (subgamedoc.HasMember("gid"))
  390. {
  391. std::string strGid = subgamedoc["gid"].GetString();
  392. // 序列化JSON对象到StringBuffer
  393. rapidjson::StringBuffer buffer;
  394. rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
  395. subgamedoc.Accept(writer);
  396. tstaticdata.m_mapregiongame[strGid] = std::string(buffer.GetString());
  397. }
  398. }
  399. }
  400. rapidjson::Document sortedkindidArray;
  401. sortedkindidArray.SetArray();
  402. // 排序
  403. {
  404. std::vector<const rapidjson::Value*> gameListVector;
  405. for (int i = 0; i < kindidArray.Size(); ++i) {
  406. gameListVector.push_back(&kindidArray[i]);
  407. }
  408. std::sort(gameListVector.begin(), gameListVector.end(), [](const rapidjson::Value* a, const rapidjson::Value* b) { return comparegamelist(*a, *b); });
  409. for (const rapidjson::Value* game : gameListVector) {
  410. if (!game->HasMember("GID"))
  411. continue;
  412. rapidjson::Value element(rapidjson::kObjectType);
  413. element.CopyFrom(*game, allocator);
  414. sortedkindidArray.PushBack(element, allocator);
  415. }
  416. }
  417. gamelist.AddMember("gamelist", sortedkindidArray, allocator);
  418. rapidjson::Document sortedsubgameArray;
  419. sortedsubgameArray.SetArray();
  420. // 排序
  421. {
  422. std::vector<const rapidjson::Value*> gameListVector;
  423. for (int i = 0; i < subgameArray.Size(); ++i) {
  424. gameListVector.push_back(&subgameArray[i]);
  425. }
  426. std::sort(gameListVector.begin(), gameListVector.end(), [](const rapidjson::Value* a, const rapidjson::Value* b) { return comparegamelist(*a, *b); });
  427. for (const rapidjson::Value* game : gameListVector) {
  428. rapidjson::Value element(rapidjson::kObjectType);
  429. element.CopyFrom(*game, suballocator);
  430. sortedsubgameArray.PushBack(element, suballocator);
  431. }
  432. }
  433. subgame.AddMember("gamelist", sortedsubgameArray, suballocator);
  434. subgame.AddMember("gameurl", rapidjson::Value(tstaticdata.m_strgameurl.c_str(), allocator), suballocator);
  435. }
  436. gamelist.AddMember("shareurl", rapidjson::Value(tstaticdata.m_strgameurl.c_str(), allocator), allocator);
  437. std::string strgamelist = funclib::doctojson(gamelist);
  438. tstaticdata.m_strsubgame = funclib::doctojson(subgame);
  439. std::stringstream strsss;
  440. std::string strbase64encode;
  441. funclib::Base64Encode(strgamelist, strbase64encode);
  442. byte tbyte;
  443. byte ttemp;
  444. std::deque<byte> bstemp;
  445. bstemp.clear();
  446. for (auto tchar : strbase64encode)
  447. {
  448. tbyte = tchar;
  449. tbyte = ~tbyte;
  450. ttemp = tbyte;
  451. tbyte = ((ttemp & 0xf0) >> 4) | ((tbyte & 0x0f) << 4);
  452. bstemp.push_front(tbyte);
  453. }
  454. std::stringstream sss;
  455. for (auto& tchar : bstemp)
  456. {
  457. strsss << tchar;
  458. }
  459. tstaticdata.m_strgamelist = strsss.str();
  460. if (!tstaticdata.bTest) // 正式环境屏蔽接口
  461. {
  462. m_callmsg.erase("/api/game/popularizesit");
  463. m_callmsg.erase("/api/game/popularizelogin");
  464. m_callmsg.erase("/api/game/popularizegetkey");
  465. m_callmsg.erase("/api/game/popularizegetcurrency");
  466. }
  467. return;
  468. }
  469. //获得游戏列表
  470. std::string HttpSocket::getgamelist(std::map<std::string, std::string> getdata)
  471. {
  472. return m_staticdata.m_strgamelist;
  473. }
  474. std::string HttpSocket::getuseraccount(std::int32_t iregion)
  475. {
  476. std::string straccount = "";
  477. __int32 iac = 0;
  478. for (iac = 0; iac < 10000; iac++)
  479. {
  480. std::stringstream strtempaccount;
  481. std::stringstream strnum;
  482. if (iregion > 0 && iregion < 10)
  483. {
  484. strtempaccount << "0" << iregion;
  485. }
  486. else
  487. {
  488. strtempaccount << iregion;
  489. }
  490. std::uniform_int_distribution<__int64> disrand(1, 100000000);
  491. __int64 irand = disrand(m_random);
  492. strnum << irand;
  493. __int32 ilen = strnum.str().length();
  494. ilen = 8 - ilen;
  495. for (int i = 0; i < ilen; i++)
  496. {
  497. strtempaccount << "0";
  498. }
  499. strtempaccount << strnum.str();
  500. auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << strtempaccount.str().c_str() << bsoncxx::builder::stream::finalize);
  501. if (finduser)
  502. {
  503. continue;
  504. }
  505. straccount = strtempaccount.str();
  506. return straccount;
  507. }
  508. return straccount;
  509. }
  510. //玩家账号注册
  511. std::string HttpSocket::regaccount(std::map<std::string, std::string> getdata)
  512. {
  513. reguser treguser;
  514. getvaluedata(getdata, treguser);
  515. std::string strret{};
  516. bool bret = treguser.datavalue();
  517. if (!bret)
  518. {
  519. strret = funclib::rettojson(Err_ParamError, "param erro");
  520. return strret;
  521. }
  522. std::string strspreadername;
  523. std::string strspreaderaccount;
  524. std::string straccount = "";
  525. std::string strpwd = "";
  526. std::string strloginpwd = "";
  527. std::string strmobilephone = treguser.phone;
  528. std::string strname = treguser.name;
  529. std::string strinfo = treguser.info;
  530. std::string struserip;
  531. std::string strspreaderip;
  532. std::string registerip = "127.0.0.1";
  533. std::string strspreaderidall;
  534. std::stringstream sss;
  535. __int64 inserttime = funclib::gettimestamp();
  536. __int64 ilocaltime = funclib::getlocaltimestamp();
  537. __int32 iregion = 1;
  538. __int64 iscore = treguser.score;
  539. __int64 beforespreaderscore = 0;
  540. __int64 afterspreaderscore = 0;
  541. __int64 adminuserid = 0;
  542. __int64 ispreaderid = 0;
  543. std::int32_t iareaid = 0;
  544. //判断三方平台是否存在
  545. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << treguser.authcode.c_str() \
  546. << "authkey" << treguser.authkey.c_str() << bsoncxx::builder::stream::finalize);
  547. if (!threeadmin)
  548. {
  549. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  550. return strret;
  551. }
  552. if (!threeadmin->view()["adminuserid"] || !threeadmin->view()["region"])
  553. {
  554. strret = funclib::rettojson(Err_Agent_LackInfo, "adminuserid or region exist");
  555. return strret;
  556. }
  557. adminuserid = threeadmin->view()["adminuserid"].get_int64();
  558. iregion = threeadmin->view()["region"].get_int32();
  559. ispreaderid = adminuserid;
  560. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
  561. if (!vipuser)
  562. {
  563. straccount += " spreaderid isnot exist";
  564. strret = funclib::rettojson(Err_No_Agent, straccount);
  565. return strret;
  566. }
  567. __int32 vipstate = 0;
  568. if (vipuser->view()["state"] && vipuser->view()["areaid"])
  569. {
  570. vipstate = vipuser->view()["state"].get_int32();
  571. iareaid = vipuser->view()["areaid"].get_int32();
  572. }
  573. else
  574. vipstate = 1;
  575. if (vipstate != 0)
  576. {
  577. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  578. return strret;
  579. }
  580. //查询第三方平台开通的空账号当天数量不超过1000个
  581. std::int64_t ilogondate = ilocaltime / 86400000 * 86400000;
  582. ilogondate = funclib::getlocaltounixstamp(ilogondate);
  583. auto findusernull = make_document(kvp("spreaderid", adminuserid), (kvp("registerlogonip", registerip.c_str())),
  584. kvp("registerdate", make_document(kvp("$gte", ilogondate))));
  585. std::int64_t iusernull = m_pcoll->count_documents(findusernull.view());
  586. if (iusernull > 1000)
  587. {
  588. strret = funclib::rettojson(Err_CreateUserNumberError, "create use num erro");
  589. return strret;
  590. }
  591. for (int i = 0; i < 6; i++)
  592. {
  593. std::uniform_int_distribution<__int32> disrand(1, 61);
  594. __int64 irand = disrand(m_random);
  595. strpwd += g_chars.at(irand);
  596. }
  597. strloginpwd = strpwd;
  598. //获取新账号
  599. straccount = getuseraccount(iregion);
  600. if (straccount == "")
  601. {
  602. strret = funclib::rettojson(Err_Create_PlayerAccount, "account create erro");
  603. return strret;
  604. }
  605. if (iscore < 0)
  606. {
  607. strret = funclib::rettojson(Err_UserScoreLessZero, "user score must greater than or equal to zero");
  608. return strret;
  609. }
  610. __int32 izero32 = 0;
  611. __int64 izero64 = 0;
  612. __int64 userid = 0;
  613. __int64 gameid = 0;
  614. __int64 ione64 = 1;
  615. std::string strmac = "11111111111111111111111111111111";
  616. struserip = registerip;
  617. MD5 tempMD5(strpwd);
  618. strpwd = tempMD5.toStrUpper();
  619. __int32 iname = 2;
  620. __int64 iinc = 1;
  621. //获取索引
  622. auto criteria = make_document(kvp("name", iname));
  623. auto update = make_document(kvp("$inc", make_document(kvp("useridindex", iinc))),
  624. kvp("$inc", make_document(kvp("gameidindex", iinc))));
  625. auto newtemp = m_pallindex->find_one_and_update(criteria.view(), update.view());
  626. if (newtemp && newtemp->view()["useridindex"] && newtemp->view()["gameidindex"])
  627. {
  628. userid = newtemp->view()["useridindex"].get_int64();
  629. gameid = newtemp->view()["gameidindex"].get_int64();
  630. }
  631. else
  632. {
  633. strret = funclib::rettojson(Err_Create_PlayerIndex, "userid create erro");
  634. return strret;
  635. }
  636. auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "userid" << userid << bsoncxx::builder::stream::finalize);
  637. auto findlosewin = m_plosewincoll->find_one(bsoncxx::builder::stream::document{} << "userid" << userid << bsoncxx::builder::stream::finalize);
  638. if (finduser)
  639. {
  640. strret = funclib::rettojson(Err_Create_UserIdDuplication, "userid is exist");
  641. return strret;
  642. }
  643. if (findlosewin)
  644. {
  645. strret = funclib::rettojson(Err_Create_AlreadHasLoseWin, "user losewin exist");
  646. return strret;
  647. }
  648. auto findaccount = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << straccount.c_str() << bsoncxx::builder::stream::finalize);
  649. if (findaccount)
  650. {
  651. strret = funclib::rettojson(Err_Create_UserAccDuplication, " account is exist");
  652. return strret;
  653. }
  654. if (!vipuser->view()["score"] || !vipuser->view()["name"] || !vipuser->view()["account"] || !vipuser->view()["loginip"])
  655. {
  656. strret = funclib::rettojson(Err_Agent_LackInfo, " account is exist1");
  657. return strret;
  658. }
  659. __int64 ivipscore = vipuser->view()["score"].get_int64();
  660. beforespreaderscore = ivipscore;
  661. strspreadername = vipuser->view()["name"].get_utf8().value.data();
  662. strspreaderaccount = vipuser->view()["account"].get_utf8().value.data();
  663. strspreaderip = vipuser->view()["loginip"].get_utf8().value.data();
  664. //生成时给玩家加分
  665. if (iscore > 0)
  666. {
  667. if (ivipscore < iscore)
  668. {
  669. strret = funclib::rettojson(Err_AgentScoreNotEnough, "your spreader score is not enough");
  670. return strret;
  671. }
  672. afterspreaderscore = beforespreaderscore - iscore;
  673. ivipscore = -1 * iscore;
  674. }
  675. else
  676. iscore = 0;
  677. //代理树添加
  678. sss << ",";
  679. sss << ispreaderid;
  680. while (ispreaderid != 0)
  681. {
  682. auto findvip = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << ispreaderid << bsoncxx::builder::stream::finalize);
  683. if (findvip)
  684. {
  685. ispreaderid = findvip->view()["spreaderid"].get_int64();
  686. sss << ",";
  687. sss << ispreaderid;
  688. }
  689. }
  690. sss << ",";
  691. strspreaderidall = sss.str();
  692. //玩家基本信息插入缓存
  693. auto userbuilder = bsoncxx::builder::stream::document{};
  694. userbuilder << "userid" << userid << "gameid" << gameid << "areaid" << iareaid << "devicetype" << izero32 << "name" << strname.c_str() << "state" << izero32 << "usertype" << izero32
  695. << "userright" << izero32 << "score" << iscore << "insurescore" << izero64 << "spreaderid" << adminuserid << "spreaderidall" << strspreaderidall.c_str()
  696. << "logontime" << izero64 << "account" << straccount.c_str() << "nickname" << straccount.c_str() << "faceid" << izero32
  697. << "logonpwd" << strpwd.c_str() << "insurepwd" << strpwd.c_str() << "lastlogonmachineid" << strmac.c_str()
  698. << "regstermachineid" << strmac.c_str() << "lastlogonip" << registerip.c_str() << "registerlogonip" << registerip.c_str() << "registerdate" << inserttime
  699. << "dynamicpass" << strmac.c_str() << "mobilephone" << strmobilephone.c_str() << "info" << strinfo.c_str();
  700. try
  701. {
  702. auto resultuser = m_pcoll->insert_one(userbuilder.view());
  703. if (!resultuser)
  704. {
  705. strret = funclib::rettojson(Err_Create_PlayerAccount, "user create erro");
  706. return strret;
  707. }
  708. }
  709. catch (const std::exception&)
  710. {
  711. strret = funclib::rettojson(Err_Create_UserAccDuplication, "user create erro, account already exists");
  712. return strret;
  713. }
  714. __int64 irechargetime = ilocaltime / (24 * 60 * 60 * 1000);
  715. irechargetime *= (24 * 60 * 60 * 1000);
  716. auto builder = bsoncxx::builder::stream::document{};
  717. builder << "userid" << userid << "todaylwscore" << izero64 << "twolwscore" << izero64
  718. << "threelwscore" << izero64 << "alllwscore" << izero64 << "todayczscore" << izero64
  719. << "totalczscore" << izero64 << "totalxfscore" << izero64 << "lwupdatelwtime" << inserttime << "rechargetime" << irechargetime
  720. << "pointcontrolcount" << izero64 << "pointcompelettime" << izero64 << "registertime" << inserttime;
  721. auto result = m_plosewincoll->insert_one(builder.view());
  722. if (!result)
  723. {
  724. m_pcoll->delete_one(bsoncxx::builder::stream::document{} << "userid" << userid << bsoncxx::builder::stream::finalize);
  725. strret = funclib::rettojson(Err_Create_AlreadHasLoseWin, "user create erro");
  726. return strret;
  727. }
  728. //写注册日志
  729. auto findlogtime = make_document(kvp("inserttime", irechargetime));
  730. auto findlogset = make_document(kvp("$inc", make_document(kvp("regnum", ione64))));
  731. mongocxx::options::find_one_and_update options;
  732. options.upsert(true);
  733. m_puserdatainfo->find_one_and_update(findlogtime.view(), findlogset.view(), options);
  734. if (iscore > 0)
  735. {
  736. auto vipcriteria = make_document(kvp("userid", adminuserid));
  737. auto vipupdate = make_document(kvp("$inc", make_document(kvp("score", ivipscore))));
  738. auto vipretscore = m_pvipuser->find_one_and_update(vipcriteria.view(), vipupdate.view());
  739. if (!vipretscore)
  740. {
  741. strret = funclib::rettojson(Err_Create_InsertUserInfo, "modify score erro");
  742. return strret;
  743. }
  744. //记录充值分数
  745. auto rechargecriteria = make_document(kvp("userid", userid));
  746. auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", iscore))),
  747. kvp("$inc", make_document(kvp("todayczscore", iscore))),
  748. kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
  749. m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
  750. __int64 iOne32 = 1;
  751. auto vipscorecriteria = make_document(kvp("business", iOne32));
  752. auto vipscoreupdate = make_document(kvp("$inc", make_document(kvp("sellscore", iscore))));
  753. mongocxx::options::find_one_and_update options;
  754. options.upsert(true);
  755. auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options);
  756. if (vipscore)
  757. {
  758. if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"])
  759. {
  760. __int64 sellscore = vipscore->view()["sellscore"].get_int64();
  761. __int64 buyscore = vipscore->view()["buyscore"].get_int64();
  762. if (sellscore != 0)
  763. {
  764. buyscore += iscore;
  765. double buysellrate = buyscore;
  766. buysellrate /= sellscore;
  767. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  768. m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view());
  769. }
  770. }
  771. }
  772. __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000);
  773. inserttimetemp *= (24 * 60 * 60 * 1000);
  774. auto vipscoredate = make_document(kvp("inserttime", inserttimetemp));
  775. auto vipscoredateupdate = make_document(kvp("$inc", make_document(kvp("sellscore", iscore))));
  776. auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options);
  777. if (retvipscore)
  778. {
  779. if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"])
  780. {
  781. __int64 sellscore = retvipscore->view()["sellscore"].get_int64();
  782. __int64 buyscore = retvipscore->view()["buyscore"].get_int64();
  783. if (sellscore != 0)
  784. {
  785. buyscore += iscore;
  786. double buysellrate = buyscore;
  787. buysellrate /= sellscore;
  788. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  789. m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view());
  790. }
  791. }
  792. }
  793. //生成转账记录
  794. __int32 itype = 1;
  795. auto builder = bsoncxx::builder::stream::document{};
  796. builder << "userid" << userid << "name" << strname.c_str() << "useraccount" << straccount.c_str() << "userip" << struserip.c_str()
  797. << "spreaderid" << adminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str()
  798. << "spreaderip" << strspreaderip.c_str() << "beforeuserscore" << izero64 << "beforespreaderscore" << beforespreaderscore << "afteruserscore" << iscore
  799. << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << iscore << "inserttime" << inserttime;
  800. m_pusertradeinfo->insert_one(builder.view());
  801. }
  802. //生成成功
  803. rapidjson::Document doc;
  804. doc.SetObject();
  805. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  806. doc.AddMember("ret", -1, allocator);
  807. doc.AddMember("account", rapidjson::Value(straccount.c_str(), allocator), allocator);
  808. doc.AddMember("name", rapidjson::Value(strname.c_str(), allocator), allocator);
  809. doc.AddMember("pwd", rapidjson::Value(strloginpwd.c_str(), allocator), allocator);
  810. strret = funclib::doctojson(doc);
  811. return strret;
  812. }
  813. //玩家更新分数
  814. std::string HttpSocket::updateuserscore(std::map<std::string, std::string> getdata, std::function<void(std::string&, int)>& dofun)
  815. {
  816. userscore tuserscore;
  817. getvaluedata(getdata, tuserscore);
  818. std::string strret{};
  819. auto findscore = getdata.find("score");
  820. if (findscore == getdata.end())
  821. {
  822. strret = funclib::rettojson(Err_ParamError, "param erro");
  823. return strret;
  824. }
  825. std::int32_t iret = 0;
  826. tuserscore.score = stringToint64_t(findscore->second, iret);
  827. if (iret == -1)
  828. {
  829. strret = funclib::rettojson(Err_ParamError, "param erro");
  830. return strret;
  831. }
  832. bool bret = tuserscore.datavalue();
  833. if (!bret)
  834. {
  835. strret = funclib::rettojson(Err_ParamError, "param erro");
  836. return strret;
  837. }
  838. __int32 ione32 = 1;
  839. //判断三方平台是否存在
  840. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tuserscore.authcode.c_str() \
  841. << "authkey" << tuserscore.authkey.c_str() << bsoncxx::builder::stream::finalize);
  842. if (!threeadmin)
  843. {
  844. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  845. return strret;
  846. }
  847. //用户不存在不减商家的分数
  848. auto firstuser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "userid" << tuserscore.iuserid << bsoncxx::builder::stream::finalize);
  849. if (!firstuser || firstuser->view()["spreaderid"])
  850. {
  851. strret = funclib::rettojson(11, "user is not exist");
  852. return strret;
  853. }
  854. std::int64_t adminuserid = firstuser->view()["spreaderid"].get_int64();
  855. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
  856. if (!vipuser)
  857. {
  858. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  859. return strret;
  860. }
  861. __int32 vipstate = 0;
  862. if (vipuser->view()["state"])
  863. {
  864. vipstate = vipuser->view()["state"].get_int32();
  865. }
  866. else
  867. vipstate = 1;
  868. if (vipstate != 0)
  869. {
  870. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  871. return strret;
  872. }
  873. if (!vipuser->view()["score"])
  874. {
  875. strret = funclib::rettojson(Err_Agent_LackInfo, "score isnot exist");
  876. return strret;
  877. }
  878. __int64 iuserid = 0;
  879. __int64 inserttime = funclib::gettimestamp();
  880. __int64 ilocaltime = funclib::getlocaltimestamp();
  881. __int64 vipscore = vipuser->view()["score"].get_int64();
  882. __int64 beforeuserscore = 0;
  883. __int64 useringot = 0;
  884. __int64 beforespreaderscore = 0;
  885. __int64 afteruserscore = 0;
  886. __int64 afterspreaderscore = 0;
  887. __int64 tradescore = 0;
  888. // type=1商家送分给玩家;type=2商家给玩家收分
  889. __int32 itype = 0;
  890. std::string strusername;
  891. std::string struseraccount;
  892. std::string struserip;
  893. std::string strspreadername;
  894. std::string strspreaderaccount;
  895. std::string strspreaderip;
  896. std::string strwebonlyuser{};
  897. //商家送分
  898. if (tuserscore.score < 0)
  899. {
  900. //可以赠送
  901. if (vipscore + tuserscore.score >= 0)
  902. {
  903. //用户不存在不减商家的分数
  904. if (!firstuser->view()["score"] || !firstuser->view()["name"] || !firstuser->view()["account"] || !firstuser->view()["lastlogonip"] || !firstuser->view()["userid"])
  905. {
  906. strret = funclib::rettojson(11, "user is not exist");
  907. return strret;
  908. }
  909. beforeuserscore = firstuser->view()["score"].get_int64();
  910. strusername = firstuser->view()["name"].get_utf8().value.data();
  911. struseraccount = firstuser->view()["account"].get_utf8().value.data();
  912. struserip = firstuser->view()["lastlogonip"].get_utf8().value.data();
  913. strwebonlyuser = firstuser->view()["webuser"].get_utf8().value.data();
  914. iuserid = firstuser->view()["userid"].get_int64();
  915. //减商家分数
  916. auto criteria = make_document(kvp("userid", adminuserid));
  917. auto update = make_document(kvp("$inc", make_document(kvp("score", tuserscore.score))));
  918. auto retscore = m_pvipuser->find_one_and_update(criteria.view(), update.view());
  919. if (!retscore)
  920. {
  921. strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "modify score erro");
  922. return strret;
  923. }
  924. if (!retscore->view()["score"] || !retscore->view()["name"] || !retscore->view()["account"])
  925. {
  926. strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "modify score erro1");
  927. return strret;
  928. }
  929. beforespreaderscore = retscore->view()["score"].get_int64();
  930. strspreadername = retscore->view()["name"].get_utf8().value.data();
  931. strspreaderaccount = retscore->view()["account"].get_utf8().value.data();
  932. if(retscore->view()["loginip"])
  933. strspreaderip = retscore->view()["loginip"].get_utf8().value.data();
  934. afterspreaderscore = beforespreaderscore + tuserscore.score;
  935. //加用户分数
  936. tuserscore.score = -1 * tuserscore.score;
  937. tradescore = tuserscore.score;
  938. auto usercriteria = make_document(kvp("userid", iuserid));
  939. auto userupdate = make_document(kvp("$inc", make_document(kvp("score", tuserscore.score))));
  940. auto userretscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view());
  941. if (!userretscore)
  942. {
  943. strret = funclib::rettojson(Err_UserUpdateScoreFailed, "add user score erro");
  944. return strret;
  945. }
  946. __int64 iOne32 = 1;
  947. auto vipscorecriteria = make_document(kvp("business", iOne32));
  948. auto vipscoreupdate = make_document(kvp("$inc", make_document(kvp("sellscore", tradescore))));
  949. mongocxx::options::find_one_and_update options;
  950. options.upsert(true);
  951. auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options);
  952. if (vipscore)
  953. {
  954. if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"])
  955. {
  956. __int64 sellscore = vipscore->view()["sellscore"].get_int64();
  957. __int64 buyscore = vipscore->view()["buyscore"].get_int64();
  958. if (sellscore != 0)
  959. {
  960. buyscore += tradescore;
  961. double buysellrate = buyscore;
  962. buysellrate /= sellscore;
  963. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  964. m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view());
  965. }
  966. }
  967. }
  968. __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000);
  969. inserttimetemp *= (24 * 60 * 60 * 1000);
  970. auto vipscoredate = make_document(kvp("inserttime", inserttimetemp));
  971. auto vipscoredateupdate = make_document(kvp("$inc", make_document(kvp("sellscore", tradescore))));
  972. auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options);
  973. if (retvipscore)
  974. {
  975. if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"])
  976. {
  977. __int64 sellscore = retvipscore->view()["sellscore"].get_int64();
  978. __int64 buyscore = retvipscore->view()["buyscore"].get_int64();
  979. if (sellscore != 0)
  980. {
  981. buyscore += tradescore;
  982. double buysellrate = buyscore;
  983. buysellrate /= sellscore;
  984. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  985. m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view());
  986. }
  987. }
  988. }
  989. //记录充值分数
  990. auto rechargecriteria = make_document(kvp("userid", iuserid));
  991. auto findlw = m_plosewincoll->find_one(rechargecriteria.view());
  992. if (findlw)
  993. {
  994. //判断清除当天充值属性
  995. __int64 irechargetime = 0;
  996. if (findlw->view()["rechargetime"])
  997. {
  998. irechargetime = findlw->view()["rechargetime"].get_int64();
  999. }
  1000. irechargetime /= (24 * 60 * 60 * 1000);
  1001. irechargetime *= (24 * 60 * 60 * 1000);
  1002. if (irechargetime != inserttimetemp)
  1003. {
  1004. auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
  1005. kvp("$set", make_document(kvp("todayczscore", tradescore))),
  1006. kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
  1007. m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
  1008. }
  1009. else
  1010. {
  1011. auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
  1012. kvp("$inc", make_document(kvp("todayczscore", tradescore))),
  1013. kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
  1014. m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
  1015. }
  1016. }
  1017. else
  1018. {
  1019. auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
  1020. kvp("$inc", make_document(kvp("todayczscore", tradescore))),
  1021. kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
  1022. m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
  1023. }
  1024. afteruserscore = beforeuserscore + tuserscore.score;
  1025. //生成转账记录
  1026. itype = 1;
  1027. auto builder = bsoncxx::builder::stream::document{};
  1028. builder << "userid" << iuserid << "name" << strusername.c_str() << "useraccount" << struseraccount.c_str() << "userip" << struserip.c_str()
  1029. << "spreaderid" << adminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str()
  1030. << "spreaderip" << strspreaderip.c_str() << "beforeuserscore" << beforeuserscore << "beforespreaderscore" << beforespreaderscore
  1031. << "afteruserscore" << afteruserscore << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << tradescore << "inserttime" << inserttime;
  1032. m_pusertradeinfo->insert_one(builder.view());
  1033. }
  1034. else
  1035. {
  1036. strret = funclib::rettojson(Err_AgentScoreNotEnough, "business score isnot enough");
  1037. return strret;
  1038. }
  1039. //如果玩家在线,从游戏中扣除
  1040. auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  1041. {
  1042. //通知游戏更新分数
  1043. bool bfind = false;
  1044. std::string struserip{};
  1045. if (useroline && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"])
  1046. {
  1047. struserip = useroline->view()["userip"].get_utf8().value.data();
  1048. bfind = true;
  1049. }
  1050. if (bfind && m_gamemsg && !struserip.empty())
  1051. {
  1052. rapidjson::Document docgame;
  1053. docgame.SetObject();
  1054. rapidjson::Document::AllocatorType& allocatorgame = docgame.GetAllocator();
  1055. docgame.AddMember("agent", rapidjson::Value(strspreaderaccount.c_str(), allocatorgame), allocatorgame);
  1056. docgame.AddMember("user", rapidjson::Value(strwebonlyuser.c_str(), allocatorgame), allocatorgame);
  1057. docgame.AddMember("score", tuserscore.score * -1, allocatorgame);
  1058. weblib::httpinfo thttpinfo{};
  1059. thttpinfo.strurl = std::move(struserip);
  1060. thttpinfo.strtarget = "webapi/updatescore";
  1061. thttpinfo.strjson = funclib::doctojson(docgame);
  1062. m_gamemsg(thttpinfo, std::move(dofun));
  1063. return {};
  1064. }
  1065. }
  1066. strret = funclib::rettojson(-1, "ok");
  1067. return strret;
  1068. }
  1069. //商家收分
  1070. if (tuserscore.score > 0)
  1071. {
  1072. auto finddisablebuyscore = m_pvipconfigure->find_one(bsoncxx::builder::stream::document{} << "disablebuyscore" << ione32 << bsoncxx::builder::stream::finalize);
  1073. if (finddisablebuyscore)
  1074. {
  1075. if (finddisablebuyscore->view()["disablebuyscore"])
  1076. {
  1077. __int32 idisablebuyscore = finddisablebuyscore->view()["disablebuyscore"].get_int32();
  1078. if (idisablebuyscore == 1)
  1079. {
  1080. strret = funclib::rettojson(Err_UpdateScoreTrickyError, "tricky bugs occured, please try again later!");
  1081. return strret;
  1082. }
  1083. }
  1084. }
  1085. //用户不存在不能下分
  1086. auto userretscore = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "userid" << tuserscore.iuserid << bsoncxx::builder::stream::finalize);
  1087. if (!userretscore || !userretscore->view()["userid"])
  1088. {
  1089. strret = funclib::rettojson(Err_No_Player, "user isnot exist");
  1090. return strret;
  1091. }
  1092. //玩家在玩游戏不能下分
  1093. auto vipuser = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << tuserscore.iuserid << bsoncxx::builder::stream::finalize);
  1094. if (vipuser)
  1095. {
  1096. strret = funclib::rettojson(Err_Player_InGame, "user is playing");
  1097. return strret;
  1098. }
  1099. if (!userretscore->view()["score"] || !userretscore->view()["account"] || !userretscore->view()["lastlogonip"] || !userretscore->view()["webuser"])
  1100. {
  1101. strret = funclib::rettojson(Err_Player_LackInfo, "user is playing1");
  1102. return strret;
  1103. }
  1104. //分数不够不能下分
  1105. beforeuserscore = userretscore->view()["score"].get_int64();
  1106. //获取奖励码
  1107. if (userretscore->view()["ingot"])
  1108. {
  1109. useringot = userretscore->view()["ingot"].get_int64();
  1110. }
  1111. //用真实分数减去奖励码分数得到真实能下分数
  1112. useringot = beforeuserscore - useringot;
  1113. if (useringot < tuserscore.score)
  1114. {
  1115. strret = funclib::rettojson(Err_Trade_UserScoreLack, "user score is not enough");
  1116. return strret;
  1117. }
  1118. strusername = userretscore->view()["name"].get_utf8().value.data();
  1119. struseraccount = userretscore->view()["account"].get_utf8().value.data();
  1120. struserip = userretscore->view()["lastlogonip"].get_utf8().value.data();
  1121. strwebonlyuser = userretscore->view()["webuser"].get_utf8().value.data();
  1122. //商家不存在不能减用户的分
  1123. auto firstadmin = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
  1124. if (!firstadmin)
  1125. {
  1126. strret = funclib::rettojson(Err_No_Agent, "business is not exist");
  1127. return strret;
  1128. }
  1129. if (!firstadmin->view()["score"] || !firstadmin->view()["name"] || !firstadmin->view()["account"] || !firstadmin->view()["loginip"])
  1130. {
  1131. strret = funclib::rettojson(Err_Agent_LackInfo, "business is not exist1");
  1132. return strret;
  1133. }
  1134. beforespreaderscore = firstadmin->view()["score"].get_int64();
  1135. strspreadername = firstadmin->view()["name"].get_utf8().value.data();
  1136. strspreaderaccount = firstadmin->view()["account"].get_utf8().value.data();
  1137. strspreaderip = firstadmin->view()["loginip"].get_utf8().value.data();
  1138. //减用户分数
  1139. tuserscore.score = -1 * tuserscore.score;
  1140. auto usercriteria = make_document(kvp("userid", tuserscore.iuserid));
  1141. auto userupdate = make_document(kvp("$inc", make_document(kvp("score", tuserscore.score))));
  1142. auto tempscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view());
  1143. if (!tempscore)
  1144. {
  1145. strret = funclib::rettojson(Err_UserUpdateScoreFailed, "reduce user score erro");
  1146. return strret;
  1147. }
  1148. afteruserscore = beforeuserscore + tuserscore.score;
  1149. //增加商家的分数
  1150. tuserscore.score = -1 * tuserscore.score;
  1151. tradescore = tuserscore.score;
  1152. //添加玩家总下分
  1153. auto xiafenupdate = make_document(kvp("$inc", make_document(kvp("totalxfscore", tradescore))));
  1154. m_plosewincoll->find_one_and_update(usercriteria.view(), xiafenupdate.view());
  1155. auto admincriteria = make_document(kvp("userid", adminuserid));
  1156. auto adminupdate = make_document(kvp("$inc", make_document(kvp("score", tradescore))));
  1157. auto adminretscore = m_pvipuser->find_one_and_update(admincriteria.view(), adminupdate.view());
  1158. if (!adminretscore)
  1159. {
  1160. strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "add business score erro");
  1161. return strret;
  1162. }
  1163. __int64 iOne32 = 1;
  1164. auto vipscorecriteria = make_document(kvp("business", iOne32));
  1165. auto vipscoreupdate = make_document(kvp("$inc", make_document(kvp("buyscore", tradescore))));
  1166. mongocxx::options::find_one_and_update options;
  1167. options.upsert(true);
  1168. auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options);
  1169. if (vipscore)
  1170. {
  1171. if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"])
  1172. {
  1173. __int64 sellscore = vipscore->view()["sellscore"].get_int64();
  1174. __int64 buyscore = vipscore->view()["buyscore"].get_int64();
  1175. if (sellscore != 0)
  1176. {
  1177. buyscore += tradescore;
  1178. double buysellrate = buyscore;
  1179. buysellrate /= sellscore;
  1180. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  1181. m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view());
  1182. }
  1183. }
  1184. }
  1185. __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000);
  1186. inserttimetemp *= (24 * 60 * 60 * 1000);
  1187. auto vipscoredate = make_document(kvp("inserttime", inserttimetemp));
  1188. auto vipscoredateupdate = make_document(kvp("$inc", make_document(kvp("buyscore", tradescore))));
  1189. auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options);
  1190. if (retvipscore)
  1191. {
  1192. if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"])
  1193. {
  1194. __int64 sellscore = retvipscore->view()["sellscore"].get_int64();
  1195. __int64 buyscore = retvipscore->view()["buyscore"].get_int64();
  1196. if (sellscore != 0)
  1197. {
  1198. buyscore += tradescore;
  1199. double buysellrate = buyscore;
  1200. buysellrate /= sellscore;
  1201. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  1202. m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view());
  1203. }
  1204. }
  1205. }
  1206. afterspreaderscore = beforespreaderscore + tuserscore.score;
  1207. //生成交易记录
  1208. itype = 2;
  1209. auto builder = bsoncxx::builder::stream::document{};
  1210. builder << "userid" << iuserid << "name" << strusername.c_str() << "useraccount" << struseraccount.c_str() << "userip" << struserip.c_str()
  1211. << "spreaderid" << adminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str() << "spreaderip" << strspreaderip.c_str()
  1212. << "beforeuserscore" << beforeuserscore << "beforespreaderscore" << beforespreaderscore << "afteruserscore" << afteruserscore
  1213. << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << tradescore << "inserttime" << inserttime;
  1214. auto result = m_pusertradeinfo->insert_one(builder.view());
  1215. //如果玩家在线,从游戏中扣除
  1216. auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  1217. {
  1218. //通知游戏更新分数
  1219. bool bfind = false;
  1220. std::string struserip{};
  1221. if (useroline && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"])
  1222. {
  1223. struserip = useroline->view()["userip"].get_utf8().value.data();
  1224. bfind = true;
  1225. }
  1226. if (bfind && m_gamemsg && !struserip.empty())
  1227. {
  1228. rapidjson::Document docgame;
  1229. docgame.SetObject();
  1230. rapidjson::Document::AllocatorType& allocatorgame = docgame.GetAllocator();
  1231. docgame.AddMember("agent", rapidjson::Value(strspreaderaccount.c_str(), allocatorgame), allocatorgame);
  1232. docgame.AddMember("user", rapidjson::Value(strwebonlyuser.c_str(), allocatorgame), allocatorgame);
  1233. docgame.AddMember("score", tuserscore.score * -1, allocatorgame);
  1234. weblib::httpinfo thttpinfo{};
  1235. thttpinfo.strurl = std::move(struserip);
  1236. thttpinfo.strtarget = "webapi/updatescore";
  1237. thttpinfo.strjson = funclib::doctojson(docgame);
  1238. m_gamemsg(thttpinfo, std::move(dofun));
  1239. return {};
  1240. }
  1241. }
  1242. }
  1243. //收分成功
  1244. strret = funclib::rettojson(-1, "ok");
  1245. return strret;
  1246. }
  1247. //把玩家踢出游戏
  1248. std::string HttpSocket::adminhituser(std::map<std::string, std::string> getdata, std::function<void(std::string&, int)>& dofun)
  1249. {
  1250. kickuser tkickuser;
  1251. getvaluedata(getdata, tkickuser);
  1252. std::string strret{};
  1253. bool bret = tkickuser.datavalue();
  1254. if (!bret)
  1255. {
  1256. strret = funclib::rettojson(Err_ParamError, "param erro");
  1257. return strret;
  1258. }
  1259. __int64 userspreadid = 0;
  1260. __int64 userid = 0;
  1261. auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tkickuser.acc.c_str() << bsoncxx::builder::stream::finalize);
  1262. if (!finduser)
  1263. {
  1264. strret = funclib::rettojson(Err_No_Player, "the user is not exist");
  1265. return strret;
  1266. }
  1267. if (!finduser->view()["spreaderid"])
  1268. {
  1269. strret = funclib::rettojson(Err_Player_LackInfo, "the spreaderid is not exist");
  1270. return strret;
  1271. }
  1272. if (!finduser->view()["userid"] || !finduser->view()["webuser"])
  1273. {
  1274. strret = funclib::rettojson(Err_Player_LackInfo, "the user is not exist");
  1275. return strret;
  1276. }
  1277. userspreadid = finduser->view()["spreaderid"].get_int64();
  1278. userid = finduser->view()["userid"].get_int64();
  1279. std::string strextension1{};
  1280. std::string strwebonlyuser{};
  1281. strwebonlyuser = finduser->view()["webuser"].get_utf8().value.data();
  1282. //判断三方平台是否存在
  1283. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tkickuser.authcode.c_str() \
  1284. << "authkey" << tkickuser.authkey.c_str() << bsoncxx::builder::stream::finalize);
  1285. if (!threeadmin)
  1286. {
  1287. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  1288. return strret;
  1289. }
  1290. if (!threeadmin->view()["adminuserid"])
  1291. {
  1292. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
  1293. return strret;
  1294. }
  1295. std::int64_t adminuserid = threeadmin->view()["adminuserid"].get_int64();
  1296. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
  1297. if (!vipuser)
  1298. {
  1299. strret = funclib::rettojson(Err_Agent_LackInfo, "spreaderid isnot exist");
  1300. return strret;
  1301. }
  1302. if (adminuserid != userspreadid || userspreadid == 0 || !vipuser->view()["account"])
  1303. {
  1304. strret = funclib::rettojson(Err_No_Agent, "the business is not exist");
  1305. return strret;
  1306. }
  1307. if (vipuser->view()["account"])
  1308. {
  1309. strextension1 = vipuser->view()["account"].get_utf8().value.data();
  1310. }
  1311. auto finduserview = make_document(kvp("userid", finduser->view()["userid"].get_int64()));
  1312. auto useroline = m_pplayuseronline->find_one(finduserview.view());
  1313. bool bfind = false;
  1314. std::string struserip{};
  1315. std::int64_t iuserid{ 0 };
  1316. std::int32_t iserverid{ 0 };
  1317. std::int64_t icontextid{ 0 };
  1318. if (useroline && useroline->view()["userid"] && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"])
  1319. {
  1320. iuserid = useroline->view()["userid"].get_int64();
  1321. icontextid = useroline->view()["contextid"].get_int64();
  1322. iserverid = useroline->view()["serverid"].get_int32();
  1323. struserip = useroline->view()["userip"].get_utf8().value.data();
  1324. bfind = true;
  1325. }
  1326. if (bfind && m_gamemsg && !struserip.empty())
  1327. {
  1328. rapidjson::Document docgame;
  1329. docgame.SetObject();
  1330. rapidjson::Document::AllocatorType& allocatorgame = docgame.GetAllocator();
  1331. docgame.AddMember("agent", rapidjson::Value(strextension1.c_str(), allocatorgame), allocatorgame);
  1332. docgame.AddMember("user", rapidjson::Value(strwebonlyuser.c_str(), allocatorgame), allocatorgame);
  1333. weblib::httpinfo thttpinfo{};
  1334. thttpinfo.strurl = std::move(struserip);
  1335. thttpinfo.strtarget = "webapi/deluser";
  1336. thttpinfo.strjson = funclib::doctojson(docgame);
  1337. m_gamemsg(thttpinfo, std::move([this, iuserid, iserverid, icontextid, dofun = std::move(dofun)](std::string &strdata, int iret)mutable
  1338. {
  1339. //踢出成功
  1340. std::string strtojson = funclib::rettojson(-1, "ok");
  1341. if (strdata == "del")
  1342. {
  1343. std::function<void()> tfun = [this, iuserid, iserverid, icontextid, dofun = std::move(dofun), strtojson]() mutable{
  1344. auto finduserview = make_document(kvp("userid", iuserid), kvp("serverid", iserverid), kvp("contextid", icontextid));
  1345. m_pplayuseronline->delete_one(finduserview.view());
  1346. dofun(strtojson, 200);
  1347. };
  1348. m_postmsg(std::move(tfun));
  1349. return;
  1350. }
  1351. dofun(strtojson, 200);
  1352. }));
  1353. return {};
  1354. }
  1355. else
  1356. {
  1357. std::string strtojson = funclib::errotojson(Err_Player_NotOnline);
  1358. return strtojson;
  1359. }
  1360. }
  1361. //管理员禁止管理员所属玩家
  1362. std::string HttpSocket::adminforbiduser(std::map<std::string, std::string> getdata)
  1363. {
  1364. prohibituser tprohibituser;
  1365. getvaluedata(getdata, tprohibituser);
  1366. std::string strret{};
  1367. bool bret = tprohibituser.datavalue();
  1368. if (!bret)
  1369. {
  1370. strret = funclib::rettojson(Err_ParamError, "param erro");
  1371. return strret;
  1372. }
  1373. __int64 adminuserid = 0;
  1374. //判断三方平台是否存在
  1375. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tprohibituser.authcode.c_str() \
  1376. << "authkey" << tprohibituser.authkey.c_str() << bsoncxx::builder::stream::finalize);
  1377. if (!threeadmin)
  1378. {
  1379. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  1380. return strret;
  1381. }
  1382. if (!threeadmin->view()["adminuserid"])
  1383. {
  1384. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
  1385. return strret;
  1386. }
  1387. adminuserid = threeadmin->view()["adminuserid"].get_int64();
  1388. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
  1389. if (!vipuser)
  1390. {
  1391. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  1392. return strret;
  1393. }
  1394. __int32 vipstate = 0;
  1395. if (vipuser->view()["state"])
  1396. {
  1397. vipstate = vipuser->view()["state"].get_int32();
  1398. }
  1399. else
  1400. vipstate = 1;
  1401. if (vipstate != 0)
  1402. {
  1403. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  1404. return strret;
  1405. }
  1406. auto userupdate = make_document(kvp("$set", make_document(kvp("state", tprohibituser.state))));
  1407. //禁止自己玩家
  1408. m_pcoll->update_one(bsoncxx::builder::stream::document{} << "spreaderid" << adminuserid << "account" << tprohibituser.account.c_str() << bsoncxx::builder::stream::finalize, userupdate.view());
  1409. //操作成功
  1410. strret = funclib::rettojson(-1, "ok");
  1411. return strret;
  1412. }
  1413. //获取账号
  1414. std::string HttpSocket::getuseraccount(std::map<std::string, std::string> getdata)
  1415. {
  1416. getaccount tgetaccount;
  1417. getvaluedata(getdata, tgetaccount);
  1418. std::string strret{};
  1419. bool bret = tgetaccount.datavalue();
  1420. if (!bret)
  1421. {
  1422. strret = funclib::rettojson(Err_ParamError, "param erro");
  1423. return strret;
  1424. }
  1425. __int64 ispreaderid = 0;
  1426. __int64 iadminuserid = 0;
  1427. __int64 iuserid = 0;
  1428. __int64 iregistertime = 0;
  1429. __int64 iloginlasttime = 0;
  1430. __int64 iscore = 0;
  1431. __int64 iingot = 0;
  1432. std::string strscore;
  1433. std::string stringot;
  1434. __int32 istate = 0;
  1435. rapidjson::Document doc;
  1436. doc.SetObject();
  1437. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  1438. doc.AddMember("ret", -1, allocator);
  1439. //判断三方平台是否存在
  1440. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tgetaccount.authcode.c_str() \
  1441. << "authkey" << tgetaccount.authkey.c_str() << bsoncxx::builder::stream::finalize);
  1442. if (!threeadmin)
  1443. {
  1444. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  1445. return strret;
  1446. }
  1447. if (!threeadmin->view()["adminuserid"])
  1448. {
  1449. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
  1450. return strret;
  1451. }
  1452. iadminuserid = threeadmin->view()["adminuserid"].get_int64();
  1453. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize);
  1454. if (!vipuser)
  1455. {
  1456. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  1457. return strret;
  1458. }
  1459. __int32 vipstate = 0;
  1460. if (vipuser->view()["state"])
  1461. {
  1462. vipstate = vipuser->view()["state"].get_int32();
  1463. }
  1464. else
  1465. vipstate = 1;
  1466. if (vipstate != 0)
  1467. {
  1468. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  1469. return strret;
  1470. }
  1471. auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tgetaccount.account.c_str() << bsoncxx::builder::stream::finalize);
  1472. if (!finduser)
  1473. {
  1474. strret = funclib::rettojson(Err_No_Player, "the account is not exist");
  1475. return strret;
  1476. }
  1477. if (!finduser->view()["spreaderid"])
  1478. {
  1479. strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist1");
  1480. return strret;
  1481. }
  1482. ispreaderid = finduser->view()["spreaderid"].get_int64();
  1483. if (ispreaderid != iadminuserid)
  1484. {
  1485. strret = funclib::rettojson(Err_UserIdNotMatchSpreadId, "the account is not belong to you");
  1486. return strret;
  1487. }
  1488. if (!finduser->view()["userid"])
  1489. {
  1490. strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist2");
  1491. return strret;
  1492. }
  1493. iuserid = finduser->view()["userid"].get_int64();
  1494. std::string onlinestatus = "0";
  1495. auto findonline = m_userloginonline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  1496. if (findonline)
  1497. {
  1498. onlinestatus = "1";
  1499. }
  1500. auto findplayonline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  1501. if (findplayonline)
  1502. {
  1503. onlinestatus = "2";
  1504. }
  1505. doc.AddMember("onlinestatus", rapidjson::Value(onlinestatus.c_str(), allocator), allocator);
  1506. auto findlosewin = m_plosewincoll->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  1507. if (!findlosewin)
  1508. {
  1509. strret = funclib::rettojson(Err_LoseWinTableNotFound, "the account is not exist");
  1510. return strret;
  1511. }
  1512. iregistertime = 0;
  1513. if (findlosewin->view()["registertime"])
  1514. {
  1515. iregistertime = findlosewin->view()["registertime"].get_int64();
  1516. }
  1517. std::string straccount{};
  1518. if (finduser->view()["account"])
  1519. {
  1520. straccount = finduser->view()["account"].get_utf8().value.data();
  1521. doc.AddMember("account", rapidjson::Value(straccount.c_str(), allocator), allocator);
  1522. }
  1523. std::string strname{};
  1524. if (finduser->view()["name"])
  1525. {
  1526. strname = finduser->view()["name"].get_utf8().value.data();
  1527. doc.AddMember("name", rapidjson::Value(strname.c_str(), allocator), allocator);
  1528. }
  1529. std::string strregtime = "";
  1530. if (iregistertime >= 0)
  1531. {
  1532. strregtime = funclib::gettimefromstamp(iregistertime);
  1533. doc.AddMember("regtime", rapidjson::Value(strregtime.c_str(), allocator), allocator);
  1534. }
  1535. iingot = 0;
  1536. if (finduser->view()["ingot"])
  1537. {
  1538. iingot = finduser->view()["ingot"].get_int64();
  1539. }
  1540. stringot = getdouble(iingot);
  1541. iscore = 0;
  1542. if (finduser->view()["score"])
  1543. {
  1544. iscore = finduser->view()["score"].get_int64();
  1545. iscore -= iingot;
  1546. }
  1547. strscore = getdouble(iscore);
  1548. istate = 0;
  1549. if (finduser->view()["state"])
  1550. {
  1551. istate = finduser->view()["state"].get_int32();
  1552. }
  1553. doc.AddMember("ingot", rapidjson::Value(stringot.c_str(), allocator), allocator);
  1554. doc.AddMember("score", rapidjson::Value(strscore.c_str(), allocator), allocator);
  1555. if (!istate)
  1556. {
  1557. doc.AddMember("state", rapidjson::Value("0", allocator), allocator);
  1558. }
  1559. else
  1560. {
  1561. doc.AddMember("state", rapidjson::Value("1", allocator), allocator);
  1562. }
  1563. std::string strmemo{};
  1564. if (finduser->view()["info"])
  1565. {
  1566. strmemo = finduser->view()["info"].get_utf8().value.data();
  1567. }
  1568. doc.AddMember("memo", rapidjson::Value(strmemo.c_str(), allocator), allocator);
  1569. std::string strregip{};
  1570. if (finduser->view()["registerlogonip"])
  1571. {
  1572. strregip = finduser->view()["registerlogonip"].get_utf8().value.data();
  1573. }
  1574. doc.AddMember("regip", rapidjson::Value(strregip.c_str(), allocator), allocator);
  1575. iloginlasttime = 0;
  1576. if (finduser->view()["logontime"])
  1577. {
  1578. iloginlasttime = finduser->view()["logontime"].get_int64();
  1579. }
  1580. std::string strloginlasttime = "";
  1581. if (iloginlasttime >= 0)
  1582. {
  1583. strloginlasttime = funclib::gettimefromstamp(iloginlasttime);
  1584. }
  1585. doc.AddMember("loginlasttime", rapidjson::Value(strloginlasttime.c_str(), allocator), allocator);
  1586. std::string strloginip{};
  1587. if (finduser->view()["lastlogonip"])
  1588. {
  1589. strloginip = finduser->view()["lastlogonip"].get_utf8().value.data();
  1590. }
  1591. doc.AddMember("loginip", rapidjson::Value(strloginip.c_str(), allocator), allocator);
  1592. std::string strremark{};
  1593. if (finduser->view()["regstermachineid"])
  1594. {
  1595. strremark = finduser->view()["regstermachineid"].get_utf8().value.data();
  1596. }
  1597. doc.AddMember("remark", rapidjson::Value(strremark.c_str(), allocator), allocator);
  1598. //操作成功
  1599. strret = funclib::doctojson(doc);
  1600. return strret;
  1601. }
  1602. //修改下级玩家信息
  1603. std::string HttpSocket::modifyuserinfo(std::map<std::string, std::string> getdata)
  1604. {
  1605. userinfo tuserinfo;
  1606. getvaluedata(getdata, tuserinfo);
  1607. std::string strret{};
  1608. bool bret = tuserinfo.datavalue();
  1609. if (!bret)
  1610. {
  1611. strret = funclib::rettojson(Err_ParamError, "param erro");
  1612. return strret;
  1613. }
  1614. //判断三方平台是否存在
  1615. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tuserinfo.authcode.c_str() \
  1616. << "authkey" << tuserinfo.authkey.c_str() << bsoncxx::builder::stream::finalize);
  1617. if (!threeadmin)
  1618. {
  1619. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  1620. return strret;
  1621. }
  1622. if (!threeadmin->view()["adminuserid"])
  1623. {
  1624. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
  1625. return strret;
  1626. }
  1627. __int64 iadminuserid = threeadmin->view()["adminuserid"].get_int64();
  1628. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize);
  1629. if (!vipuser)
  1630. {
  1631. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  1632. return strret;
  1633. }
  1634. __int32 vipstate = 0;
  1635. if (vipuser->view()["state"])
  1636. {
  1637. vipstate = vipuser->view()["state"].get_int32();
  1638. }
  1639. else
  1640. vipstate = 1;
  1641. if (vipstate != 0)
  1642. {
  1643. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  1644. return strret;
  1645. }
  1646. auto findone = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "spreaderid" << iadminuserid << "account" << tuserinfo.account.c_str() << bsoncxx::builder::stream::finalize);
  1647. if (!findone)
  1648. {
  1649. strret = funclib::rettojson(Err_UserIdNotMatchSpreadId, "the account is not belong to you");
  1650. return strret;
  1651. }
  1652. if (!tuserinfo.pwd.empty())
  1653. {
  1654. MD5 tempMD5(tuserinfo.pwd);
  1655. tuserinfo.pwd = tempMD5.toStrUpper();
  1656. //修改下级玩家信息
  1657. m_pcoll->update_one(bsoncxx::builder::stream::document{} << "spreaderid" << iadminuserid << "account" << tuserinfo.account.c_str()
  1658. << bsoncxx::builder::stream::finalize, bsoncxx::builder::stream::document{} << "$set" << bsoncxx::builder::stream::open_document << "logonpwd" << tuserinfo.pwd.c_str()
  1659. << bsoncxx::builder::stream::close_document << bsoncxx::builder::stream::finalize);
  1660. }
  1661. strret = funclib::rettojson(-1, "ok");
  1662. return strret;
  1663. }
  1664. //管理员禁止自己直属玩家
  1665. std::string HttpSocket::adminforbidmyuser(std::map<std::string, std::string> getdata)
  1666. {
  1667. adminprohibituser tadminprohibituser;
  1668. getvaluedata(getdata, tadminprohibituser);
  1669. std::string strret{};
  1670. bool bret = tadminprohibituser.datavalue();
  1671. if (!bret)
  1672. {
  1673. strret = funclib::rettojson(Err_ParamError, "param erro");
  1674. return strret;
  1675. }
  1676. //判断三方平台是否存在
  1677. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tadminprohibituser.authcode.c_str() \
  1678. << "authkey" << tadminprohibituser.authkey.c_str() << bsoncxx::builder::stream::finalize);
  1679. if (!threeadmin)
  1680. {
  1681. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  1682. return strret;
  1683. }
  1684. if (!threeadmin->view()["adminuserid"])
  1685. {
  1686. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
  1687. return strret;
  1688. }
  1689. std::int64_t adminuserid = threeadmin->view()["adminuserid"].get_int64();
  1690. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
  1691. if (!vipuser)
  1692. {
  1693. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  1694. return strret;
  1695. }
  1696. __int32 vipstate = 0;
  1697. if (vipuser->view()["state"])
  1698. {
  1699. vipstate = vipuser->view()["state"].get_int32();
  1700. }
  1701. else
  1702. vipstate = 1;
  1703. if (vipstate != 0)
  1704. {
  1705. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  1706. return strret;
  1707. }
  1708. auto userupdate = make_document(kvp("$set", make_document(kvp("state", tadminprohibituser.state))));
  1709. //禁止自己玩家
  1710. m_pcoll->update_many(bsoncxx::builder::stream::document{} << "spreaderid" << adminuserid << bsoncxx::builder::stream::finalize, userupdate.view());
  1711. strret = funclib::rettojson(-1, "ok");
  1712. return strret;
  1713. }
  1714. //查询充值记录
  1715. std::string HttpSocket::sellbuyinfo(std::map<std::string, std::string> getdata)
  1716. {
  1717. sellbuyscoreinfo tsellbuyscoreinfo;
  1718. getvaluedata(getdata, tsellbuyscoreinfo);
  1719. std::string strret{};
  1720. bool bret = tsellbuyscoreinfo.datavalue();
  1721. if (!bret)
  1722. {
  1723. strret = funclib::rettojson(Err_ParamError, "param erro");
  1724. return strret;
  1725. }
  1726. rapidjson::Document doc;
  1727. doc.SetObject();
  1728. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  1729. doc.AddMember("ret", -1, allocator);
  1730. __int64 adminuserid = 0;
  1731. __int64 beforuserscore = 0;
  1732. __int64 afteruserscore = 0;
  1733. __int64 itradescore = 0;
  1734. double dtradescore = 0.0f;
  1735. __int64 inserttime = 0;
  1736. __int32 itype = 0;
  1737. //判断三方平台是否存在
  1738. /*auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tsellbuyscoreinfo.authcode.c_str() \
  1739. << "authkey" << tsellbuyscoreinfo.authkey.c_str() << bsoncxx::builder::stream::finalize);
  1740. if (!threeadmin)
  1741. {
  1742. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  1743. return strret;
  1744. }
  1745. if (!threeadmin->view()["adminuserid"])
  1746. {
  1747. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
  1748. return strret;
  1749. }*/
  1750. if (tsellbuyscoreinfo.iuserid > 0) // 查询玩家
  1751. {
  1752. auto finduser = m_pcoll->find_one(make_document(kvp("userid", tsellbuyscoreinfo.iuserid)));
  1753. if (!finduser || !finduser->view()["spreaderid"])
  1754. {
  1755. strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist1");
  1756. return strret;
  1757. }
  1758. adminuserid = finduser->view()["spreaderid"].get_int64();
  1759. }
  1760. else
  1761. {
  1762. adminuserid = tsellbuyscoreinfo.iagentid;
  1763. }
  1764. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << adminuserid << bsoncxx::builder::stream::finalize);
  1765. if (!vipuser)
  1766. {
  1767. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  1768. return strret;
  1769. }
  1770. __int32 vipstate = 1;
  1771. if (vipuser->view()["state"])
  1772. vipstate = vipuser->view()["state"].get_int32();
  1773. if (vipstate != 0)
  1774. {
  1775. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  1776. return strret;
  1777. }
  1778. auto timeview = make_document(kvp("inserttime", -1));
  1779. mongocxx::options::find options;
  1780. options.sort(timeview.view());
  1781. options.limit(20);
  1782. options.skip(tsellbuyscoreinfo.ipagenum * 20);
  1783. document findinfo;
  1784. findinfo.append(kvp("inserttime", make_document(kvp("$lte", tsellbuyscoreinfo.endtime), kvp("$gt", tsellbuyscoreinfo.begintime))));
  1785. if (tsellbuyscoreinfo.iuserid > 0)
  1786. findinfo.append(kvp("userid", tsellbuyscoreinfo.iuserid));
  1787. else if(adminuserid > 0)
  1788. findinfo.append(kvp("spreaderid", adminuserid));
  1789. else
  1790. {
  1791. strret = funclib::rettojson(Err_ParamError, "param erro");
  1792. return strret;
  1793. }
  1794. auto tradeinfo = m_pusertradeinfo->find(findinfo.view(), options);
  1795. rapidjson::Value timeArray(rapidjson::kArrayType);
  1796. for (auto &tempinfo:tradeinfo)
  1797. {
  1798. rapidjson::Document sellbuyinfodoc;
  1799. sellbuyinfodoc.SetObject();
  1800. rapidjson::Document::AllocatorType& sallocator = sellbuyinfodoc.GetAllocator();
  1801. if (!tempinfo["userid"])
  1802. continue;
  1803. sellbuyinfodoc.AddMember("userid", tempinfo["userid"].get_int64(), sallocator);
  1804. itype = 0;
  1805. if (tempinfo["type"])
  1806. itype = tempinfo["type"].get_int32();
  1807. sellbuyinfodoc.AddMember("type", itype, sallocator);
  1808. itradescore = 0;
  1809. if (tempinfo["tradescore"])
  1810. itradescore = tempinfo["tradescore"].get_int64();
  1811. std::string stritradescore = getdouble(itradescore);
  1812. sellbuyinfodoc.AddMember("tradescore", rapidjson::Value(stritradescore.c_str(), sallocator), sallocator);
  1813. beforuserscore = 0;
  1814. if (tempinfo["beforeuserscore"])
  1815. beforuserscore = tempinfo["beforeuserscore"].get_int64();
  1816. std::string strbeforuserscore = getdouble(beforuserscore);
  1817. sellbuyinfodoc.AddMember("beforeuserscore", rapidjson::Value(strbeforuserscore.c_str(), sallocator), sallocator);
  1818. afteruserscore = 0;
  1819. if (tempinfo["afteruserscore"])
  1820. afteruserscore = tempinfo["afteruserscore"].get_int64();
  1821. std::string strafteruserscore = getdouble(afteruserscore);
  1822. sellbuyinfodoc.AddMember("afteruserscore", rapidjson::Value(strafteruserscore.c_str(), sallocator), sallocator);
  1823. inserttime = 0;
  1824. if (tempinfo["inserttime"])
  1825. inserttime = tempinfo["inserttime"].get_int64();
  1826. sellbuyinfodoc.AddMember("inserttime", inserttime, sallocator);
  1827. rapidjson::Value element(rapidjson::kObjectType);
  1828. element.CopyFrom(sellbuyinfodoc, allocator);
  1829. timeArray.PushBack(element, allocator);
  1830. }
  1831. doc.AddMember("data", timeArray, allocator);
  1832. //操作成功
  1833. strret = funclib::doctojson(doc);
  1834. return strret;
  1835. }
  1836. //查询游戏每局记录
  1837. std::string HttpSocket::playgameinfo(std::map<std::string, std::string> getdata)
  1838. {
  1839. playinfo tplayinfo;
  1840. getvaluedata(getdata, tplayinfo);
  1841. std::string strret{};
  1842. bool bret = tplayinfo.datavalue();
  1843. if (!bret)
  1844. {
  1845. strret = funclib::rettojson(Err_ParamError, "param erro");
  1846. return strret;
  1847. }
  1848. __int64 iadminuserid = 0;
  1849. __int64 userspreadid = 0;
  1850. //判断三方平台是否存在
  1851. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tplayinfo.authcode.c_str() \
  1852. << "authkey" << tplayinfo.authkey.c_str() << bsoncxx::builder::stream::finalize);
  1853. if (!threeadmin || !threeadmin->view()["adminuserid"])
  1854. {
  1855. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  1856. return strret;
  1857. }
  1858. iadminuserid = threeadmin->view()["adminuserid"].get_int64();
  1859. auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "userid" << tplayinfo.iuserid << bsoncxx::builder::stream::finalize);
  1860. if (!finduser)
  1861. {
  1862. strret = funclib::rettojson(Err_No_Player, "the account is not exist");
  1863. return strret;
  1864. }
  1865. if (!finduser->view()["spreaderid"])
  1866. {
  1867. strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist1");
  1868. return strret;
  1869. }
  1870. userspreadid = finduser->view()["spreaderid"].get_int64();
  1871. if (iadminuserid != userspreadid)
  1872. {
  1873. strret = funclib::rettojson(Err_Player_LackInfo, "the account does not belong to you");
  1874. return strret;
  1875. }
  1876. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize);
  1877. if (!vipuser)
  1878. {
  1879. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  1880. return strret;
  1881. }
  1882. __int32 vipstate = 0;
  1883. if (vipuser->view()["state"])
  1884. {
  1885. vipstate = vipuser->view()["state"].get_int32();
  1886. }
  1887. else
  1888. vipstate = 1;
  1889. if (vipstate != 0)
  1890. {
  1891. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  1892. return strret;
  1893. }
  1894. auto findinfo = make_document(kvp("userid", tplayinfo.iuserid), kvp("gametype", tplayinfo.igametype),
  1895. kvp("inserttime", make_document(kvp("$lte", tplayinfo.endtime), kvp("$gte", tplayinfo.begintime))));
  1896. auto timeview = make_document(kvp("inserttime", -1));
  1897. mongocxx::options::find options;
  1898. options.sort(timeview.view());
  1899. options.limit(tplayinfo.ipagesize);
  1900. options.skip(tplayinfo.ipagenum* tplayinfo.ipagesize);
  1901. auto tradeinfo = m_pgameprizelog->find(findinfo.view(), options);
  1902. rapidjson::Document doc;
  1903. doc.SetObject();
  1904. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  1905. doc.AddMember("ret", -1, allocator);
  1906. __int64 itemp64 = 0;
  1907. __int64 itemp32 = 0;
  1908. std::string strtemp;
  1909. rapidjson::Value timeArray(rapidjson::kArrayType);
  1910. for (auto &tempinfo : tradeinfo)
  1911. {
  1912. rapidjson::Document gameinfodoc;
  1913. gameinfodoc.SetObject();
  1914. rapidjson::Document::AllocatorType& gallocator = gameinfodoc.GetAllocator();
  1915. if (!tempinfo["dbquestid"])
  1916. continue;
  1917. strtemp = tempinfo["dbquestid"].get_utf8().value.data();
  1918. gameinfodoc.AddMember("betid", rapidjson::Value(strtemp.c_str(), gallocator), gallocator);
  1919. std::string useraccount{};
  1920. if (tempinfo["account"])
  1921. {
  1922. useraccount = tempinfo["account"].get_utf8().value.data();
  1923. }
  1924. gameinfodoc.AddMember("useraccount", rapidjson::Value(useraccount.c_str(), gallocator), gallocator);
  1925. std::string gamename{};
  1926. if (tempinfo["servername"])
  1927. {
  1928. gamename = tempinfo["servername"].get_utf8().value.data();
  1929. }
  1930. gameinfodoc.AddMember("gamename", rapidjson::Value(gamename.c_str(), gallocator), gallocator);
  1931. itemp32 = 0;
  1932. if (tempinfo["tableid"])
  1933. {
  1934. itemp32 = tempinfo["tableid"].get_int32();
  1935. gameinfodoc.AddMember("tableid", itemp32, gallocator);
  1936. }
  1937. itemp64 = 0;
  1938. if (tempinfo["betscore"])
  1939. {
  1940. itemp64 = tempinfo["betscore"].get_int64();
  1941. }
  1942. strtemp = getdouble(itemp64);
  1943. gameinfodoc.AddMember("betscore", rapidjson::Value(strtemp.c_str(), gallocator), gallocator);
  1944. itemp64 = 0;
  1945. if (tempinfo["winscore"])
  1946. {
  1947. itemp64 = tempinfo["winscore"].get_int64();
  1948. }
  1949. strtemp = getdouble(itemp64);
  1950. gameinfodoc.AddMember("winscore", rapidjson::Value(strtemp.c_str(), gallocator), gallocator);
  1951. itemp64 = 0;
  1952. if (tempinfo["userscore"])
  1953. {
  1954. itemp64 = tempinfo["userscore"].get_int64();
  1955. }
  1956. strtemp = getdouble(itemp64);
  1957. gameinfodoc.AddMember("userscore", rapidjson::Value(strtemp.c_str(), gallocator), gallocator);
  1958. itemp64 = 0;
  1959. if (tempinfo["inserttime"])
  1960. {
  1961. itemp64 = tempinfo["inserttime"].get_int64();
  1962. }
  1963. gameinfodoc.AddMember("inserttime", itemp64, gallocator);
  1964. rapidjson::Value element(rapidjson::kObjectType);
  1965. element.CopyFrom(gameinfodoc, allocator);
  1966. timeArray.PushBack(element, allocator);
  1967. }
  1968. doc.AddMember("gameinfo", timeArray, allocator);
  1969. //操作成功
  1970. strret = funclib::doctojson(doc);
  1971. return strret;
  1972. }
  1973. //获取总赌注和总输赢
  1974. std::string HttpSocket::getuserplayscoreinfo(std::map<std::string, std::string> getdata)
  1975. {
  1976. playscoreinfo tplayscoreinfo;
  1977. getvaluedata(getdata, tplayscoreinfo);
  1978. std::string strret{};
  1979. char account[30][LEN_ACCOUNTS]{0};
  1980. std::int32_t iaccountnum = 0;
  1981. bool bret = tplayscoreinfo.datavalue();
  1982. if (!bret)
  1983. {
  1984. strret = funclib::rettojson(Err_ParamError, "param erro");
  1985. return strret;
  1986. }
  1987. bret = false;
  1988. std::string stemp = "";
  1989. for (int i = 0; i < 30 && !bret; i++)
  1990. {
  1991. stemp = straccount(tplayscoreinfo.account, bret);
  1992. if (stemp.length() > LEN_ACCOUNTS - 1)
  1993. stemp = stemp.substr(0, LEN_ACCOUNTS - 1);
  1994. memcpy_s(account[i], LEN_ACCOUNTS, stemp.c_str(), stemp.length());
  1995. iaccountnum++;
  1996. }
  1997. std::map<__int64, __int64> mapuserall;
  1998. mapuserall.clear();
  1999. __int64 iadminuserid = 0;
  2000. //判断三方平台是否存在
  2001. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tplayscoreinfo.authcode.c_str() \
  2002. << "authkey" << tplayscoreinfo.authkey.c_str() << bsoncxx::builder::stream::finalize);
  2003. if (!threeadmin)
  2004. {
  2005. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  2006. return strret;
  2007. }
  2008. if (!threeadmin->view()["adminuserid"])
  2009. {
  2010. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "spreaderid isnot exist");
  2011. return strret;
  2012. }
  2013. iadminuserid = threeadmin->view()["adminuserid"].get_int64();
  2014. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize);
  2015. if (!vipuser)
  2016. {
  2017. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  2018. return strret;
  2019. }
  2020. __int32 vipstate = 0;
  2021. if (vipuser->view()["state"])
  2022. {
  2023. vipstate = vipuser->view()["state"].get_int32();
  2024. }
  2025. else
  2026. vipstate = 1;
  2027. if (vipstate != 0)
  2028. {
  2029. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  2030. return strret;
  2031. }
  2032. __int64 tempuserid = 0;
  2033. std::string tempaccount = "";
  2034. auto finduser = m_pcoll->find(bsoncxx::builder::stream::document{} << "spreaderid" << iadminuserid << bsoncxx::builder::stream::finalize);
  2035. for (auto& doc : finduser)
  2036. {
  2037. tempuserid = doc["userid"].get_int64();
  2038. tempaccount = doc["account"].get_utf8().value.data();
  2039. bool bfind = false;
  2040. for (int i = 0; i < iaccountnum; i++)
  2041. {
  2042. if (tempaccount == account[i])
  2043. {
  2044. bfind = true;
  2045. break;
  2046. }
  2047. }
  2048. if(bfind)
  2049. mapuserall.insert(std::map<__int64, __int64>::value_type(tempuserid, tempuserid));
  2050. }
  2051. if (mapuserall.begin() == mapuserall.end())
  2052. {
  2053. strret = funclib::rettojson(Err_AgengtHasNoPlayer, "the vip don't have player");
  2054. return strret;
  2055. }
  2056. auto findinfo = make_document(
  2057. kvp("inserttime", make_document(kvp("$lte", tplayscoreinfo.endtime), kvp("$gte", tplayscoreinfo.begintime))));
  2058. auto tradeinfo = m_pgameprizelog->find(findinfo.view());
  2059. //玩家总下注
  2060. __int64 iuserallbet = 0;
  2061. //玩家总赢回
  2062. __int64 iuserallwin = 0;
  2063. __int64 itemp64 = 0;
  2064. for (auto& tempinfo : tradeinfo)
  2065. {
  2066. itemp64 = 0;
  2067. if (tempinfo["userid"])
  2068. {
  2069. itemp64 = tempinfo["userid"].get_int64();
  2070. auto tempfinduser = mapuserall.find(itemp64);
  2071. if (tempfinduser == mapuserall.end())
  2072. continue;
  2073. }
  2074. else
  2075. continue;
  2076. itemp64 = 0;
  2077. if (tempinfo["betscore"])
  2078. {
  2079. itemp64 = tempinfo["betscore"].get_int64();
  2080. iuserallbet += itemp64;
  2081. }
  2082. itemp64 = 0;
  2083. if (tempinfo["winscore"])
  2084. {
  2085. itemp64 = tempinfo["winscore"].get_int64();
  2086. iuserallwin += itemp64;
  2087. }
  2088. }
  2089. rapidjson::Document doc;
  2090. doc.SetObject();
  2091. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  2092. doc.AddMember("ret", -1, allocator);
  2093. std::string strtemp;
  2094. strtemp = getdouble(iuserallbet);
  2095. doc.AddMember("userallbet", rapidjson::Value(strtemp.c_str(), allocator), allocator);
  2096. strtemp = getdouble(iuserallwin);
  2097. doc.AddMember("userallwin", rapidjson::Value(strtemp.c_str(), allocator), allocator);
  2098. //操作成功
  2099. strret = funclib::doctojson(doc);
  2100. return strret;
  2101. }
  2102. //添加奖励码
  2103. std::string HttpSocket::updateuseringot(std::map<std::string, std::string> getdata)
  2104. {
  2105. updateingot tupdateingot;
  2106. getvaluedata(getdata, tupdateingot);
  2107. std::string strret{};
  2108. auto findscore = getdata.find("score");
  2109. if (findscore == getdata.end())
  2110. {
  2111. strret = funclib::rettojson(Err_ParamError, "param erro");
  2112. return strret;
  2113. }
  2114. std::int32_t iret = 0;
  2115. tupdateingot.score = stringToint64_t(findscore->second, iret);
  2116. if (iret == -1)
  2117. {
  2118. strret = funclib::rettojson(Err_ParamError, "param erro");
  2119. return strret;
  2120. }
  2121. if (tupdateingot.score <= 0)
  2122. {
  2123. strret = funclib::rettojson(Err_ParamError, "param erro");
  2124. return strret;
  2125. }
  2126. bool bret = tupdateingot.datavalue();
  2127. if (!bret)
  2128. {
  2129. strret = funclib::rettojson(Err_ParamError, "param erro");
  2130. return strret;
  2131. }
  2132. std::string strusername = "";
  2133. std::string struseraccount = "";
  2134. std::string struserip = "";
  2135. std::string strspreadername = "";
  2136. std::string strspreaderaccount = "";
  2137. std::string strspreaderip = "";
  2138. std::stringstream sss;
  2139. __int64 iuserid = 0;
  2140. __int64 ingot = 0;
  2141. __int64 ingottemp = 0;
  2142. __int64 tradescore = 0;
  2143. __int64 iadminuserid = 0;
  2144. __int64 userspreadid = 0;
  2145. __int64 ivipscore = 0;
  2146. __int64 beforeuserscore = 0;
  2147. __int64 afteruserscore = 0;
  2148. __int64 itempscore = 0;
  2149. __int64 beforespreaderscore = 0;
  2150. __int64 afterspreaderscore = 0;
  2151. __int64 inserttime = funclib::gettimestamp();
  2152. __int64 ilocaltime = funclib::getlocaltimestamp();
  2153. //判断三方平台是否存在
  2154. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tupdateingot.authcode.c_str() \
  2155. << "authkey" << tupdateingot.authkey.c_str() << bsoncxx::builder::stream::finalize);
  2156. if (!threeadmin)
  2157. {
  2158. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  2159. return strret;
  2160. }
  2161. if (!threeadmin->view()["adminuserid"])
  2162. {
  2163. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
  2164. return strret;
  2165. }
  2166. iadminuserid = threeadmin->view()["adminuserid"].get_int64();
  2167. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize);
  2168. if (!vipuser)
  2169. {
  2170. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  2171. return strret;
  2172. }
  2173. __int32 vipstate = 0;
  2174. if (vipuser->view()["state"])
  2175. {
  2176. vipstate = vipuser->view()["state"].get_int32();
  2177. }
  2178. else
  2179. vipstate = 1;
  2180. if (vipstate != 0)
  2181. {
  2182. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  2183. return strret;
  2184. }
  2185. if (vipuser->view()["score"])
  2186. ivipscore = vipuser->view()["score"].get_int64();
  2187. auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tupdateingot.account.c_str() << bsoncxx::builder::stream::finalize);
  2188. if (!finduser || !finduser->view()["userid"])
  2189. {
  2190. strret = funclib::rettojson(Err_No_Player, "the account is not exist");
  2191. return strret;
  2192. }
  2193. if (!finduser->view()["score"] || !finduser->view()["name"] || !finduser->view()["account"] || !finduser->view()["lastlogonip"] || !finduser->view()["userid"])
  2194. {
  2195. strret = funclib::rettojson(Err_Player_LackInfo, "user is not exist1");
  2196. return strret;
  2197. }
  2198. iuserid = finduser->view()["userid"].get_int64();
  2199. if(finduser->view()["ingot"])
  2200. ingot = finduser->view()["ingot"].get_int64();
  2201. beforeuserscore = finduser->view()["score"].get_int64();
  2202. strusername = finduser->view()["name"].get_utf8().value.data();
  2203. struseraccount = finduser->view()["account"].get_utf8().value.data();
  2204. struserip = finduser->view()["lastlogonip"].get_utf8().value.data();
  2205. if (!finduser->view()["spreaderid"])
  2206. {
  2207. strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist1");
  2208. return strret;
  2209. }
  2210. userspreadid = finduser->view()["spreaderid"].get_int64();
  2211. if (userspreadid != iadminuserid)
  2212. {
  2213. strret = funclib::rettojson(Err_UserIdNotMatchSpreadId, "the account is not belong to you");
  2214. return strret;
  2215. }
  2216. //目前只支持赠送奖励码
  2217. if (tupdateingot.score <= 0)
  2218. {
  2219. strret = funclib::rettojson(Err_ScoreParamError, "the score's erro");
  2220. return strret;
  2221. }
  2222. itempscore = ivipscore - tupdateingot.score;
  2223. //判断vip有没有足够的分数
  2224. if (itempscore < 0)
  2225. {
  2226. strret = funclib::rettojson(Err_AgentScoreNotEnough, "the vip does not have enough score");
  2227. return strret;
  2228. }
  2229. afteruserscore = beforeuserscore + tupdateingot.score;
  2230. //获取要减的分数
  2231. itempscore = tupdateingot.score * -1;
  2232. //减商家分数
  2233. auto criteria = make_document(kvp("userid", iadminuserid));
  2234. auto update = make_document(kvp("$inc", make_document(kvp("score", itempscore))));
  2235. auto retscore = m_pvipuser->find_one_and_update(criteria.view(), update.view());
  2236. if (!retscore)
  2237. {
  2238. strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "modify score erro");
  2239. return strret;
  2240. }
  2241. if (!retscore->view()["score"] || !retscore->view()["name"] || !retscore->view()["account"] || !retscore->view()["loginip"])
  2242. {
  2243. strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "modify score erro1");
  2244. return strret;
  2245. }
  2246. beforespreaderscore = retscore->view()["score"].get_int64();
  2247. strspreadername = retscore->view()["name"].get_utf8().value.data();
  2248. strspreaderaccount = retscore->view()["account"].get_utf8().value.data();
  2249. strspreaderip = retscore->view()["loginip"].get_utf8().value.data();
  2250. afterspreaderscore = beforespreaderscore + itempscore;
  2251. //给用户家奖金码
  2252. itempscore = tupdateingot.score;
  2253. auto usercriteria = make_document(kvp("userid", iuserid));
  2254. auto userupdate = make_document(kvp("$inc", make_document(kvp("score", itempscore))),
  2255. kvp("$inc", make_document(kvp("ingot", itempscore))));
  2256. auto userretscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view());
  2257. if (!userretscore)
  2258. {
  2259. strret = funclib::rettojson(Err_UserUpdateScoreFailed, "add user score erro");
  2260. return strret;
  2261. }
  2262. //加用户分数
  2263. tradescore = tupdateingot.score;
  2264. __int64 iOne32 = 1;
  2265. auto vipscorecriteria = make_document(kvp("business", iOne32));
  2266. auto vipscoreupdate = make_document(kvp("$inc", make_document(kvp("sellscore", tradescore))));
  2267. mongocxx::options::find_one_and_update options;
  2268. options.upsert(true);
  2269. auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options);
  2270. if (vipscore)
  2271. {
  2272. if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"])
  2273. {
  2274. __int64 sellscore = vipscore->view()["sellscore"].get_int64();
  2275. __int64 buyscore = vipscore->view()["buyscore"].get_int64();
  2276. if (sellscore != 0)
  2277. {
  2278. buyscore += tradescore;
  2279. double buysellrate = buyscore;
  2280. buysellrate /= sellscore;
  2281. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  2282. m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view());
  2283. }
  2284. }
  2285. }
  2286. __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000);
  2287. inserttimetemp *= (24 * 60 * 60 * 1000);
  2288. auto vipscoredate = make_document(kvp("inserttime", inserttimetemp));
  2289. auto vipscoredateupdate = make_document(kvp("$inc", make_document(kvp("sellscore", tradescore))));
  2290. auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options);
  2291. if (retvipscore)
  2292. {
  2293. if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"])
  2294. {
  2295. __int64 sellscore = retvipscore->view()["sellscore"].get_int64();
  2296. __int64 buyscore = retvipscore->view()["buyscore"].get_int64();
  2297. if (sellscore != 0)
  2298. {
  2299. buyscore += tradescore;
  2300. double buysellrate = buyscore;
  2301. buysellrate /= sellscore;
  2302. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  2303. m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view());
  2304. }
  2305. }
  2306. }
  2307. //记录充值分数
  2308. auto rechargecriteria = make_document(kvp("userid", iuserid));
  2309. auto findlw = m_plosewincoll->find_one(rechargecriteria.view());
  2310. if (findlw)
  2311. {
  2312. //判断清除当天充值属性
  2313. __int64 irechargetime = 0;
  2314. if (findlw->view()["rechargetime"])
  2315. {
  2316. irechargetime = findlw->view()["rechargetime"].get_int64();
  2317. }
  2318. irechargetime /= (24 * 60 * 60 * 1000);
  2319. irechargetime *= (24 * 60 * 60 * 1000);
  2320. if (irechargetime != inserttimetemp)
  2321. {
  2322. auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
  2323. kvp("$set", make_document(kvp("todayczscore", tradescore))),
  2324. kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
  2325. m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
  2326. }
  2327. else
  2328. {
  2329. auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
  2330. kvp("$inc", make_document(kvp("todayczscore", tradescore))),
  2331. kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
  2332. m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
  2333. }
  2334. }
  2335. else
  2336. {
  2337. auto rechargeupdate = make_document(kvp("$inc", make_document(kvp("totalczscore", tradescore))),
  2338. kvp("$inc", make_document(kvp("todayczscore", tradescore))),
  2339. kvp("$set", make_document(kvp("rechargetime", ilocaltime))));
  2340. m_plosewincoll->find_one_and_update(rechargecriteria.view(), rechargeupdate.view());
  2341. }
  2342. //记录奖励码总数
  2343. //auto temptotalingot = make_document(kvp("$inc", make_document(kvp("allingot", tradescore))));
  2344. //m_plosewincoll->update_one(rechargecriteria.view(), temptotalingot.view());
  2345. //生成转账记录
  2346. __int32 itype = 1;
  2347. auto builder = bsoncxx::builder::stream::document{};
  2348. builder << "userid" << iuserid << "name" << strusername.c_str() << "useraccount" << struseraccount.c_str() << "userip" << struserip.c_str()
  2349. << "spreaderid" << iadminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str()
  2350. << "spreaderip" << strspreaderip.c_str() << "beforeuserscore" << beforeuserscore << "beforespreaderscore" << beforespreaderscore
  2351. << "afteruserscore" << afteruserscore << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << tradescore << "inserttime" << inserttime;
  2352. m_pusertradeinfo->insert_one(builder.view());
  2353. auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  2354. auto loginoline = m_userloginonline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  2355. if (loginoline && loginoline->view()["contextid"] && loginoline->view()["userip"])
  2356. {
  2357. //通知游戏更新分数
  2358. CMD_CS_C_UpdateScoreEx tempUpdateScore;
  2359. ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore));
  2360. tempUpdateScore.dwUserID = iuserid;
  2361. tempUpdateScore.addscore = tradescore;
  2362. std::string strloginip{};
  2363. tempUpdateScore.dwLoginContextID = loginoline->view()["contextid"].get_int64();
  2364. strloginip = loginoline->view()["userip"].get_utf8().value.data();
  2365. //m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore));
  2366. }
  2367. if (useroline && useroline->view()["serverid"] && useroline->view()["contextid"] && useroline->view()["userip"])
  2368. {
  2369. //通知游戏更新分数
  2370. CMD_CS_C_UpdateScoreEx tempUpdateScore;
  2371. ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore));
  2372. tempUpdateScore.dwUserID = iuserid;
  2373. tempUpdateScore.addscore = tradescore;
  2374. std::string strloginip{};
  2375. tempUpdateScore.wgameserverid = useroline->view()["serverid"].get_int32();
  2376. tempUpdateScore.dwGameContextID = useroline->view()["contextid"].get_int64();
  2377. strloginip = useroline->view()["userip"].get_utf8().value.data();
  2378. //m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore));
  2379. }
  2380. strret = funclib::rettojson(-1, "ok");
  2381. return strret;
  2382. }
  2383. //回退奖励码
  2384. std::string HttpSocket::backuseringot(std::map<std::string, std::string> getdata)
  2385. {
  2386. backingot tbackingot;
  2387. getvaluedata(getdata, tbackingot);
  2388. std::string strret{};
  2389. auto findscore = getdata.find("score");
  2390. if (findscore == getdata.end())
  2391. {
  2392. strret = funclib::rettojson(Err_ParamError, "param erro");
  2393. return strret;
  2394. }
  2395. std::int32_t iret = 0;
  2396. tbackingot.score = stringToint64_t(findscore->second, iret);
  2397. if (iret == -1)
  2398. {
  2399. strret = funclib::rettojson(Err_ParamError, "param erro");
  2400. return strret;
  2401. }
  2402. if (tbackingot.score <= 0)
  2403. {
  2404. strret = funclib::rettojson(Err_ParamError, "param erro");
  2405. return strret;
  2406. }
  2407. bool bret = tbackingot.datavalue();
  2408. if (!bret)
  2409. {
  2410. strret = funclib::rettojson(Err_ParamError, "param erro");
  2411. return strret;
  2412. }
  2413. std::string strusername = "";
  2414. std::string struseraccount = "";
  2415. std::string struserip = "";
  2416. std::string strspreadername = "";
  2417. std::string strspreaderaccount = "";
  2418. std::string strspreaderip = "";
  2419. std::stringstream sss;
  2420. __int64 iuserid = 0;
  2421. __int64 ingot = 0;
  2422. __int64 ingottemp = 0;
  2423. __int64 tradescore = 0;
  2424. __int64 iadminuserid = 0;
  2425. __int64 userspreadid = 0;
  2426. __int64 beforeuserscore = 0;
  2427. __int64 afteruserscore = 0;
  2428. __int64 itempscore = 0;
  2429. __int64 beforespreaderscore = 0;
  2430. __int64 afterspreaderscore = 0;
  2431. __int64 inserttime = funclib::gettimestamp();
  2432. __int64 ilocaltime = funclib::getlocaltimestamp();
  2433. //目前支持下分奖励码
  2434. if (tbackingot.score <= 0)
  2435. {
  2436. strret = funclib::rettojson(1, "the score's erro");
  2437. return strret;
  2438. }
  2439. //判断三方平台是否存在
  2440. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tbackingot.authcode.c_str() \
  2441. << "authkey" << tbackingot.authkey.c_str() << bsoncxx::builder::stream::finalize);
  2442. if (!threeadmin)
  2443. {
  2444. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  2445. return strret;
  2446. }
  2447. if (!threeadmin->view()["adminuserid"])
  2448. {
  2449. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "id isnot exist");
  2450. return strret;
  2451. }
  2452. iadminuserid = threeadmin->view()["adminuserid"].get_int64();
  2453. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize);
  2454. if (!vipuser)
  2455. {
  2456. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  2457. return strret;
  2458. }
  2459. __int64 ivipscore = vipuser->view()["score"].get_int64();
  2460. beforespreaderscore = ivipscore;
  2461. strspreadername = vipuser->view()["name"].get_utf8().value.data();
  2462. strspreaderaccount = vipuser->view()["account"].get_utf8().value.data();
  2463. strspreaderip = vipuser->view()["loginip"].get_utf8().value.data();
  2464. __int32 vipstate = 0;
  2465. if (vipuser->view()["state"])
  2466. {
  2467. vipstate = vipuser->view()["state"].get_int32();
  2468. }
  2469. else
  2470. vipstate = 1;
  2471. if (vipstate != 0)
  2472. {
  2473. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  2474. return strret;
  2475. }
  2476. auto useroline = m_pplayuseronline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  2477. if (useroline)
  2478. {
  2479. strret = funclib::rettojson(15, "user is playing");
  2480. return strret;
  2481. }
  2482. auto finduser = m_pcoll->find_one(bsoncxx::builder::stream::document{} << "account" << tbackingot.account.c_str() << bsoncxx::builder::stream::finalize);
  2483. if (!finduser || !finduser->view()["userid"])
  2484. {
  2485. strret = funclib::rettojson(Err_No_Player, "the account is not exist");
  2486. return strret;
  2487. }
  2488. if (!finduser->view()["score"] || !finduser->view()["name"] || !finduser->view()["account"] || !finduser->view()["lastlogonip"] || !finduser->view()["userid"])
  2489. {
  2490. strret = funclib::rettojson(Err_Player_LackInfo, "user is not exist1");
  2491. return strret;
  2492. }
  2493. iuserid = finduser->view()["userid"].get_int64();
  2494. if (finduser->view()["ingot"])
  2495. ingot = finduser->view()["ingot"].get_int64();
  2496. //判断奖励码是否够
  2497. if (ingot < tbackingot.score)
  2498. {
  2499. strret = funclib::rettojson(Err_Trade_UserScoreLack, "user's score not enough");
  2500. return strret;
  2501. }
  2502. beforeuserscore = finduser->view()["score"].get_int64();
  2503. beforeuserscore += ingot;
  2504. strusername = finduser->view()["name"].get_utf8().value.data();
  2505. struseraccount = finduser->view()["account"].get_utf8().value.data();
  2506. struserip = finduser->view()["lastlogonip"].get_utf8().value.data();
  2507. if (!finduser->view()["spreaderid"])
  2508. {
  2509. strret = funclib::rettojson(Err_Player_LackInfo, "the account is not exist1");
  2510. return strret;
  2511. }
  2512. userspreadid = finduser->view()["spreaderid"].get_int64();
  2513. if (userspreadid != iadminuserid)
  2514. {
  2515. strret = funclib::rettojson(Err_UserIdNotMatchSpreadId, "the account is not belong to you");
  2516. return strret;
  2517. }
  2518. //减用户的奖励码
  2519. itempscore = -1* tbackingot.score;
  2520. auto usercriteria = make_document(kvp("userid", iuserid));
  2521. auto userupdate = make_document(kvp("$inc", make_document(kvp("score", itempscore))),
  2522. kvp("$inc", make_document(kvp("ingot", itempscore))));
  2523. auto tempscore = m_pcoll->find_one_and_update(usercriteria.view(), userupdate.view());
  2524. if (!tempscore)
  2525. {
  2526. strret = funclib::rettojson(Err_UserUpdateScoreFailed, "reduce user score erro");
  2527. return strret;
  2528. }
  2529. afteruserscore = beforeuserscore - tbackingot.score;
  2530. //增加商家的分数
  2531. tradescore = tbackingot.score;
  2532. //添加玩家总下分
  2533. auto xiafenupdate = make_document(kvp("$inc", make_document(kvp("totalxfscore", tradescore))));
  2534. m_plosewincoll->find_one_and_update(usercriteria.view(), xiafenupdate.view());
  2535. //增加商家的分数
  2536. auto admincriteria = make_document(kvp("userid", iadminuserid));
  2537. auto adminupdate = make_document(kvp("$inc", make_document(kvp("score", tradescore))));
  2538. auto adminretscore = m_pvipuser->find_one_and_update(admincriteria.view(), adminupdate.view());
  2539. if (!adminretscore)
  2540. {
  2541. strret = funclib::rettojson(Err_AgentUpdateScoreFailed, "add business score erro");
  2542. return strret;
  2543. }
  2544. __int64 iOne32 = 1;
  2545. auto vipscorecriteria = make_document(kvp("business", iOne32));
  2546. auto vipscoreupdate = make_document(kvp("$inc", make_document(kvp("buyscore", tradescore))));
  2547. mongocxx::options::find_one_and_update options;
  2548. options.upsert(true);
  2549. auto vipscore = m_pvipscore->find_one_and_update(vipscorecriteria.view(), vipscoreupdate.view(), options);
  2550. if (vipscore)
  2551. {
  2552. if (vipscore->view()["sellscore"] && vipscore->view()["buyscore"])
  2553. {
  2554. __int64 sellscore = vipscore->view()["sellscore"].get_int64();
  2555. __int64 buyscore = vipscore->view()["buyscore"].get_int64();
  2556. if (sellscore != 0)
  2557. {
  2558. buyscore += tradescore;
  2559. double buysellrate = buyscore;
  2560. buysellrate /= sellscore;
  2561. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  2562. m_pvipscore->update_one(vipscorecriteria.view(), vipscoreupdate.view());
  2563. }
  2564. }
  2565. }
  2566. __int64 inserttimetemp = ilocaltime / (24 * 60 * 60 * 1000);
  2567. inserttimetemp *= (24 * 60 * 60 * 1000);
  2568. auto vipscoredate = make_document(kvp("inserttime", inserttimetemp));
  2569. auto vipscoredateupdate = make_document(kvp("$inc", make_document(kvp("buyscore", tradescore))));
  2570. auto retvipscore = m_pvipscoredate->find_one_and_update(vipscoredate.view(), vipscoredateupdate.view(), options);
  2571. if (retvipscore)
  2572. {
  2573. if (retvipscore->view()["sellscore"] && retvipscore->view()["buyscore"])
  2574. {
  2575. __int64 sellscore = retvipscore->view()["sellscore"].get_int64();
  2576. __int64 buyscore = retvipscore->view()["buyscore"].get_int64();
  2577. if (sellscore != 0)
  2578. {
  2579. buyscore += tradescore;
  2580. double buysellrate = buyscore;
  2581. buysellrate /= sellscore;
  2582. auto vipscoreupdate = make_document(kvp("$set", make_document(kvp("buysellrate", buysellrate))));
  2583. m_pvipscoredate->update_one(vipscoredate.view(), vipscoreupdate.view());
  2584. }
  2585. }
  2586. }
  2587. afterspreaderscore = beforespreaderscore + tbackingot.score;
  2588. //生成交易记录
  2589. __int32 itype = 2;
  2590. auto builder = bsoncxx::builder::stream::document{};
  2591. builder << "userid" << iuserid << "name" << strusername.c_str() << "useraccount" << struseraccount.c_str() << "userip" << struserip.c_str()
  2592. << "spreaderid" << iadminuserid << "spreadername" << strspreadername.c_str() << "spreaderaccount" << strspreaderaccount.c_str() << "spreaderip" << strspreaderip.c_str()
  2593. << "beforeuserscore" << beforeuserscore << "beforespreaderscore" << beforespreaderscore << "afteruserscore" << afteruserscore
  2594. << "afterspreaderscore" << afterspreaderscore << "type" << itype << "tradescore" << tradescore << "inserttime" << inserttime;
  2595. auto result = m_pusertradeinfo->insert_one(builder.view());
  2596. //如果在大厅更新玩家分数
  2597. auto loginoline = m_userloginonline->find_one(bsoncxx::builder::stream::document{} << "userid" << iuserid << bsoncxx::builder::stream::finalize);
  2598. if (loginoline && loginoline->view()["contextid"] && loginoline->view()["userip"])
  2599. {
  2600. //通知游戏更新分数
  2601. CMD_CS_C_UpdateScoreEx tempUpdateScore;
  2602. ZeroMemory(&tempUpdateScore, sizeof(tempUpdateScore));
  2603. tempUpdateScore.dwUserID = iuserid;
  2604. tempUpdateScore.addscore = -tradescore;
  2605. std::string strloginip{};
  2606. tempUpdateScore.dwLoginContextID = loginoline->view()["contextid"].get_int64();
  2607. strloginip = loginoline->view()["userip"].get_utf8().value.data();
  2608. //m_gamemsg(strloginip, &tempUpdateScore, sizeof(tempUpdateScore));
  2609. }
  2610. strret = funclib::rettojson(-1, "ok");
  2611. return strret;
  2612. }
  2613. //获取所有总赌注和总输赢
  2614. std::string HttpSocket::getalluserplayscoreinfo(std::map<std::string, std::string> getdata)
  2615. {
  2616. allplayscoreinfo tallplayscoreinfo;
  2617. getvaluedata(getdata, tallplayscoreinfo);
  2618. std::string strret{};
  2619. bool bret = tallplayscoreinfo.datavalue();
  2620. if (!bret)
  2621. {
  2622. strret = funclib::rettojson(Err_ParamError, "param erro");
  2623. return strret;
  2624. }
  2625. __int64 iadminuserid = 0;
  2626. __int64 iallplaynum = 0;
  2627. __int64 iallusernum = 0;
  2628. //判断三方平台是否存在
  2629. auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << tallplayscoreinfo.authcode.c_str() \
  2630. << "authkey" << tallplayscoreinfo.authkey.c_str() << bsoncxx::builder::stream::finalize);
  2631. if (!threeadmin)
  2632. {
  2633. strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
  2634. return strret;
  2635. }
  2636. if (!threeadmin->view()["adminuserid"])
  2637. {
  2638. strret = funclib::rettojson(Err_ThreeAdminLackInfo, "spreaderid isnot exist");
  2639. return strret;
  2640. }
  2641. iadminuserid = threeadmin->view()["adminuserid"].get_int64();
  2642. auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << iadminuserid << bsoncxx::builder::stream::finalize);
  2643. if (!vipuser)
  2644. {
  2645. strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
  2646. return strret;
  2647. }
  2648. __int32 vipstate = 0;
  2649. if (vipuser->view()["state"])
  2650. {
  2651. vipstate = vipuser->view()["state"].get_int32();
  2652. }
  2653. else
  2654. vipstate = 1;
  2655. if (vipstate != 0)
  2656. {
  2657. strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
  2658. return strret;
  2659. }
  2660. bool badd = false;
  2661. __int64 tempuserid = 0;
  2662. std::string tempaccount = "";
  2663. m_useridarray.clear();
  2664. m_mapuseridname.clear();
  2665. std::string tempname;
  2666. mongocxx::options::find options;
  2667. options.projection(make_document(kvp("userid", 1), kvp("name", 1)));
  2668. auto finduser = m_pcoll->find(bsoncxx::builder::stream::document{} << "spreaderid" << iadminuserid << bsoncxx::builder::stream::finalize, options);
  2669. for (auto& doc : finduser)
  2670. {
  2671. tempuserid = doc["userid"].get_int64();
  2672. //在没有写入账号的时候返回名下所有账号
  2673. //m_useridarray.append(tempuserid);
  2674. //ub8的玩家把账号改成昵称
  2675. if (iadminuserid == 311)
  2676. {
  2677. tempname = "";
  2678. if(doc["name"])
  2679. tempname = doc["name"].get_utf8().value.data();
  2680. m_mapuseridname.insert(std::unordered_map<std::int64_t, std::string>::value_type(tempuserid, tempname));
  2681. }
  2682. badd = true;
  2683. }
  2684. if (!badd)
  2685. {
  2686. strret = funclib::rettojson(Err_AgengtHasNoPlayer, "the vip don't have player");
  2687. return strret;
  2688. }
  2689. std::int32_t iskipnum = 1000 * tallplayscoreinfo.ipagenum;
  2690. if (iskipnum < 0)
  2691. {
  2692. strret = funclib::rettojson(Err_ParamError, "param erro");
  2693. return strret;
  2694. }
  2695. std::int64_t dectime = tallplayscoreinfo.endtime - tallplayscoreinfo.begintime;
  2696. if (dectime > 604800000)
  2697. {
  2698. strret = funclib::rettojson(Err_OverQueryTimeLimit, "time erro");
  2699. return strret;
  2700. }
  2701. // NEWLOG(INFO, "msglog") << "-------" << "tallplayscoreinfo.begintime=" << tallplayscoreinfo.begintime
  2702. // << " tallplayscoreinfo.endtime=" << tallplayscoreinfo.endtime << " iadminuserid=" << iadminuserid
  2703. // << " iskipnum=" << iskipnum;
  2704. taggameuserlog tempvect;
  2705. document files_filter;
  2706. files_filter.append(kvp("spreaderid", iadminuserid));
  2707. files_filter.append(kvp("$and",
  2708. make_array(
  2709. make_document(kvp("inserttime",
  2710. make_document(kvp("$gte", tallplayscoreinfo.begintime)))),
  2711. make_document(kvp("inserttime",
  2712. make_document(kvp("$lt", tallplayscoreinfo.endtime)))))));
  2713. tempvect.allpagenum = m_pgameprizelog->count_documents(files_filter.view());
  2714. //NEWLOG(INFO, "msglog") << "tempvect.allpagenum=" << tempvect.allpagenum;
  2715. tempvect.allrecordnum = tempvect.allpagenum;
  2716. tempvect.allpagenum /= 1000;
  2717. tempvect.allpagenum += 1;
  2718. mongocxx::options::find gamelogoptions;
  2719. gamelogoptions.limit(1000);
  2720. gamelogoptions.skip(iskipnum);
  2721. auto tradeinfo = m_pgameprizelog->find(files_filter.view(), gamelogoptions);
  2722. tempvect.recordnum = 0;
  2723. tempvect.curpagenum = tallplayscoreinfo.ipagenum;
  2724. __int64 iscore = 0;
  2725. std::int64_t ifinduserid = 0;
  2726. for (auto& doc : tradeinfo)
  2727. {
  2728. gameuserlog tempuserlog={};
  2729. if(doc["dbquestid"])
  2730. tempuserlog.dbquestid = doc["dbquestid"].get_int64();
  2731. if(doc["userid"])
  2732. ifinduserid = doc["userid"].get_int64();
  2733. //ub8的玩家把账号改成昵称
  2734. if (iadminuserid == 311)
  2735. {
  2736. auto& username = m_mapuseridname.find(ifinduserid);
  2737. if (username != m_mapuseridname.end())
  2738. {
  2739. tempuserlog.account = username->second;
  2740. }
  2741. }
  2742. else
  2743. {
  2744. if (doc["account"])
  2745. {
  2746. tempuserlog.account = doc["account"].get_utf8().value.data();
  2747. }
  2748. }
  2749. if(doc["serverid"])
  2750. tempuserlog.serverid = doc["serverid"].get_int32();
  2751. if(doc["betscore"])
  2752. iscore = doc["betscore"].get_int64();
  2753. tempuserlog.betscore = getdouble(iscore);
  2754. if(doc["winscore"])
  2755. iscore = doc["winscore"].get_int64();
  2756. tempuserlog.winscore = getdouble(iscore);
  2757. if(doc["userscore"])
  2758. iscore = doc["userscore"].get_int64();
  2759. tempuserlog.userscore = getdouble(iscore);
  2760. if(doc["inserttime"])
  2761. tempuserlog.inserttime = doc["inserttime"].get_int64();
  2762. if(doc["servername"])
  2763. tempuserlog.servername = doc["servername"].get_utf8().value.data();
  2764. tempvect.userlog.push_back(tempuserlog);
  2765. tempvect.recordnum++;
  2766. }
  2767. //NEWLOG(INFO, "msglog") << "fun ok";
  2768. rapidjson::Document doc;
  2769. doc.SetObject();
  2770. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  2771. doc.AddMember("ret", -1, allocator);
  2772. doc.AddMember("info", rapidjson::Value("ok", allocator), allocator);
  2773. doc.AddMember("allrecordnum", tempvect.allrecordnum, allocator);
  2774. doc.AddMember("recordnum", tempvect.recordnum, allocator);
  2775. doc.AddMember("curpagenum", tempvect.curpagenum, allocator);
  2776. doc.AddMember("allpagenum", tempvect.allpagenum, allocator);
  2777. rapidjson::Value timeArray(rapidjson::kArrayType);
  2778. for (auto& tempinfo : tempvect.userlog)
  2779. {
  2780. rapidjson::Document userlogdoc;
  2781. userlogdoc.SetObject();
  2782. rapidjson::Document::AllocatorType& uallocator = userlogdoc.GetAllocator();
  2783. userlogdoc.AddMember("dbquestid", tempinfo.dbquestid, uallocator);
  2784. userlogdoc.AddMember("account", rapidjson::Value(tempinfo.account.c_str(), uallocator), uallocator);
  2785. userlogdoc.AddMember("servername", rapidjson::Value(tempinfo.servername.c_str(), uallocator), uallocator);
  2786. userlogdoc.AddMember("serverid", tempinfo.serverid, uallocator);
  2787. userlogdoc.AddMember("betscore", rapidjson::Value(tempinfo.betscore.c_str(), uallocator), uallocator);
  2788. userlogdoc.AddMember("winscore", rapidjson::Value(tempinfo.winscore.c_str(), uallocator), uallocator);
  2789. userlogdoc.AddMember("userscore", rapidjson::Value(tempinfo.userscore.c_str(), uallocator), uallocator);
  2790. userlogdoc.AddMember("gamelog", rapidjson::Value(tempinfo.gamelog.c_str(), uallocator), uallocator);
  2791. userlogdoc.AddMember("inserttime", tempinfo.inserttime, uallocator);
  2792. rapidjson::Value element(rapidjson::kObjectType);
  2793. element.CopyFrom(userlogdoc, allocator);
  2794. timeArray.PushBack(element, allocator);
  2795. }
  2796. doc.AddMember("userlog", timeArray, allocator);
  2797. strret = funclib::doctojson(doc);
  2798. //NEWLOG(INFO, "msglog") << strret;
  2799. return strret;
  2800. }
  2801. std::string HttpSocket::reelplay(std::map<std::string, std::string> getdata, std::function<void(std::string&, int)>& dofun)
  2802. {
  2803. reelplayuser treelplayuser;
  2804. getvaluedata(getdata, treelplayuser);
  2805. std::string strret;
  2806. m_writelog("--------------------reelplay-------------------------");
  2807. bool bret = treelplayuser.datavalue();
  2808. if (!bret)
  2809. {
  2810. strret = funclib::rettojson(Err_ParamError, "param erro");
  2811. return strret;
  2812. }
  2813. std::int32_t iareaid{ 0 };
  2814. std::int64_t ispreaderid{ 0 };
  2815. //验证代理是否存在
  2816. auto findagentview = make_document(kvp("account", treelplayuser.strextension1.c_str()), kvp("cert", treelplayuser.strcert.c_str()));
  2817. auto vipuser = m_pvipuser->find_one(findagentview.view());
  2818. if (!vipuser || !vipuser->view()["userid"] || !vipuser->view()["areaid"] || !vipuser->view()["apitype"])
  2819. {
  2820. strret = funclib::errotojson(Err_No_Agent);
  2821. return strret;
  2822. }
  2823. iareaid = vipuser->view()["areaid"].get_int32();
  2824. ispreaderid = vipuser->view()["areaid"].get_int32();
  2825. std::int32_t userstate = 1;
  2826. if (vipuser && vipuser->view()["state"])
  2827. {
  2828. userstate = vipuser->view()["state"].get_int32();
  2829. }
  2830. if (userstate != 0)
  2831. {
  2832. strret = funclib::rettojson(Err_OutOfState_Agent, "agent statue error");
  2833. return strret;
  2834. }
  2835. std::int32_t iapitype = vipuser->view()["apitype"].get_int32();
  2836. if (iapitype != 2)
  2837. {
  2838. strret = funclib::rettojson(Err_OutOfState_Agent, "agent type error");
  2839. return strret;
  2840. }
  2841. auto findwebuser = make_document(kvp("account", treelplayuser.struseracc.c_str()));
  2842. auto findneuserdata = m_pcoll->find_one(findwebuser.view());
  2843. if (!findneuserdata)
  2844. {
  2845. //用户账号存在
  2846. strret = funclib::errotojson(Err_No_Player);
  2847. return strret;
  2848. }
  2849. std::int64_t iscore{ 0 };
  2850. if (findneuserdata && findneuserdata->view()["score"])
  2851. {
  2852. iscore = findneuserdata->view()["score"].get_int64();
  2853. }
  2854. std::string struseracc = treelplayuser.struseracc;
  2855. createreeluser(struseracc, iscore, dofun);
  2856. return {};
  2857. }
  2858. void HttpSocket::sendreelmsg(std::string stronly, std::string strtarget, std::string strjson, std::function<void(std::string, int)>&& dofun)
  2859. {
  2860. weblib::httpinfo thttpinfo;
  2861. thttpinfo.strurl = "https://transfer-wallet-service.stage.iconic-21.com";
  2862. // thttpinfo.strurl = "http://127.0.0.1:6000";
  2863. thttpinfo.strtarget = strtarget;
  2864. thttpinfo.stronly = stronly;
  2865. std::string strshaheadcontent = m_strshaheadcontent + strjson;
  2866. strshaheadcontent = sha256_to_base16(strshaheadcontent);
  2867. thttpinfo.addheadinfo.insert(std::make_pair(m_strshahead, strshaheadcontent));
  2868. thttpinfo.strjson = strjson;
  2869. std::stringstream sss;
  2870. sss << "strurl=" << thttpinfo.strurl << " strtarget=" << strtarget << " strshaheadcontent=" << strshaheadcontent << " strjson=" << strjson;
  2871. m_writelog(sss.str());
  2872. weblib::sendhttp(m_psendhttp, std::move(thttpinfo), std::move(dofun));
  2873. }
  2874. //检查玩家钱包
  2875. void HttpSocket::checkreeluserbalance(std::string struseracc, std::int64_t iscore)
  2876. {
  2877. rapidjson::Document doc;
  2878. doc.SetObject();
  2879. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  2880. doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
  2881. doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
  2882. //std::string strjson{ "{\"casino\":\"luckybet777\",\"playerId\":\"testPlayer_5\",\"currency\":\"EUR\",\"country\":\"US\"}" };
  2883. std::string strjson = funclib::doctojson(doc);
  2884. std::string strtarget = "v2/tw/balance";
  2885. }
  2886. //创建玩家
  2887. void HttpSocket::createreeluser(std::string struseracc, std::int64_t iscore, std::function<void(std::string&, int)>& dofun)
  2888. {
  2889. m_writelog("--------------------createreeluser-------------------------");
  2890. rapidjson::Document doc;
  2891. doc.SetObject();
  2892. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  2893. doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
  2894. doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
  2895. doc.AddMember("currency", rapidjson::Value("EUR", allocator), allocator);
  2896. doc.AddMember("country", rapidjson::Value("US", allocator), allocator);
  2897. //std::string strjson{ "{\"casino\":\"luckybet777\",\"playerId\":\"testPlayer_5\",\"currency\":\"EUR\",\"country\":\"US\"}" };
  2898. std::string strjson = funclib::doctojson(doc);
  2899. std::string strtarget = "v2/tw/createPlayer";
  2900. //创建玩家
  2901. sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, iscore, dofun](std::string strdata, int iret) {
  2902. std::stringstream strlog;
  2903. strlog << "创建玩家: iret=" << iret << " strdata=" << strdata;
  2904. m_writelog(strlog.str());
  2905. bool bhaveuser{ false };
  2906. if (iret == 200)
  2907. {
  2908. rettype::type tret{ rettype::type::ini };
  2909. rapidjson::Document docdata;
  2910. rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
  2911. if (ok)
  2912. {
  2913. std::string strstatus{};
  2914. tret = funclib::getjsonvalue(docdata, "status", strstatus);
  2915. if (tret == rettype::type::exist)
  2916. {
  2917. if (strstatus == "ok")
  2918. {
  2919. bhaveuser = true;
  2920. }
  2921. }
  2922. }
  2923. }
  2924. //玩家创建成功
  2925. if (bhaveuser)
  2926. {
  2927. reelusertrans(struseracc, iscore, dofun);
  2928. }
  2929. else
  2930. {
  2931. std::string strret = funclib::errotojson(-1);
  2932. dofun(strret, 200);
  2933. }
  2934. }));
  2935. }
  2936. void HttpSocket::reelusertrans(std::string struseracc, std::int64_t iscore, std::function<void(std::string&, int)> dofun)
  2937. {
  2938. m_writelog("--------------------reelusertrans-------------------------");
  2939. if (iscore > 0)
  2940. {
  2941. rapidjson::Document doc;
  2942. doc.SetObject();
  2943. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  2944. std::string strscore = funclib::getdouble(iscore);
  2945. std::string strtransid = funclib::getonlytoken(1, m_ucurid);
  2946. doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
  2947. doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
  2948. doc.AddMember("transactionId", rapidjson::Value(strtransid.c_str(), allocator), allocator);
  2949. doc.AddMember("amount", rapidjson::Value(strscore.c_str(), allocator), allocator);
  2950. std::string strjson = funclib::doctojson(doc);
  2951. std::string strtarget = "v2/tw/transfer";
  2952. sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun, iscore](std::string strdata, int iret) {
  2953. std::stringstream strlog;
  2954. strlog << "转账: iscore=" << iscore << " iret=" << iret << " strdata=" << strdata;
  2955. m_writelog(strlog.str());
  2956. double dscore{ 0 };
  2957. bool bscore{ false };
  2958. if (iret == 200)
  2959. {
  2960. rettype::type tret{ rettype::type::ini };
  2961. rapidjson::Document docdata;
  2962. rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
  2963. if (ok)
  2964. {
  2965. tret = funclib::getjsonvalue(docdata, "balance", dscore);
  2966. if (tret == rettype::type::exist)
  2967. {
  2968. bscore = true;
  2969. }
  2970. else
  2971. {
  2972. std::string strscore{};
  2973. tret = funclib::getjsonvalue(docdata, "balance", strscore);
  2974. if (tret == rettype::type::exist)
  2975. {
  2976. try
  2977. {
  2978. dscore = std::stod(strscore);
  2979. bscore = true;
  2980. }
  2981. catch (const std::exception&)
  2982. {
  2983. bscore = false;
  2984. }
  2985. }
  2986. }
  2987. }
  2988. }
  2989. //转账成功
  2990. if (bscore)
  2991. {
  2992. //执行扣分操作
  2993. m_postmsg(std::move([this]() {
  2994. //验证代理是否存在
  2995. //auto findagentview = make_document(kvp("account", treelplayuser.strextension1.c_str()), kvp("cert", treelplayuser.strcert.c_str()));
  2996. //auto vipuser = m_pvipuser->find_one(findagentview.view());
  2997. //if (!vipuser || !vipuser->view()["userid"] || !vipuser->view()["areaid"] || !vipuser->view()["apitype"])
  2998. //{
  2999. //strret = funclib::errotojson(Err_No_Agent);
  3000. //return strret;
  3001. //}
  3002. }));
  3003. //直接拉取游戏
  3004. getreelgameurl(struseracc, dofun);
  3005. }
  3006. else
  3007. {
  3008. std::string strret = funclib::errotojson(-1);
  3009. dofun(strret, 200);
  3010. }
  3011. }));
  3012. }
  3013. else
  3014. {
  3015. m_writelog("iscore = 0, 直接拉取游戏");
  3016. //直接拉取游戏
  3017. getreelgameurl(struseracc, dofun);
  3018. }
  3019. }
  3020. //拉取游戏
  3021. void HttpSocket::getreelgameurl(std::string struseracc, std::function<void(std::string&, int)> dofun)
  3022. {
  3023. m_writelog("--------------------getreelgameurl-------------------------");
  3024. rapidjson::Document doc;
  3025. doc.SetObject();
  3026. rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
  3027. //cashier:URL for opening the cashier on Casino site when a player has no funds.
  3028. //homepage:URL for returning to Lobby page on Casino site. This link is used for Exit button in mobile version of games.
  3029. //{"casino":"whitebom","playerId":"testPlayer_1","launchAlias":"launch_main_rol_01","language":"en","cashier":"https://cashier.com","homepage":"https://home.com"}
  3030. std::string strtransid = funclib::getonlytoken(1, m_ucurid);
  3031. doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
  3032. doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
  3033. doc.AddMember("launchAlias", rapidjson::Value("launch_main_rol_01", allocator), allocator);
  3034. doc.AddMember("language", rapidjson::Value("en", allocator), allocator);
  3035. doc.AddMember("cashier", rapidjson::Value("https://cashier.com", allocator), allocator);
  3036. doc.AddMember("homepage", rapidjson::Value("https://home.com", allocator), allocator);
  3037. std::string strjson = funclib::doctojson(doc);
  3038. std::string strtarget = "v2/tw/startGame";
  3039. sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun](std::string strdata, int iret) {
  3040. std::stringstream strlog;
  3041. strlog << "拉取游戏: iret=" << iret << " strdata=" << strdata;
  3042. m_writelog(strlog.str());
  3043. if (iret == 200)
  3044. {
  3045. rettype::type tret{ rettype::type::ini };
  3046. rapidjson::Document docdata;
  3047. rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
  3048. if (ok)
  3049. {
  3050. dofun(strdata, 200);
  3051. }
  3052. }
  3053. else
  3054. {
  3055. std::string strret = funclib::errotojson(-1);
  3056. dofun(strret, 200);
  3057. }
  3058. }));
  3059. }