qingjie před 3 týdny
rodič
revize
edbee0070f
3 změnil soubory, kde provedl 66 přidání a 248 odebrání
  1. 58 237
      webapi/webapi/HttpSocket.cpp
  2. 7 10
      webapi/webapi/HttpSocket.h
  3. 1 1
      webapi/webapi/data.h

+ 58 - 237
webapi/webapi/HttpSocket.cpp

@@ -58,6 +58,7 @@ HttpSocket::HttpSocket()
 	m_pvipconfigure = boost::make_shared<mongocxx::collection>();
 	m_pgamelist = boost::make_shared<mongocxx::collection>();
 	m_pthirdtranslog = boost::make_shared<mongocxx::collection>();
+	m_pthirddeveloper = boost::make_shared<mongocxx::collection>();
 
 	*m_pdb = (*m_pclient)["accounts"];
 	*m_gamelog = (*m_pclient)["gamelog"];
@@ -82,6 +83,7 @@ HttpSocket::HttpSocket()
 	*m_pvipconfigure = (*m_pvipuserdb)["vipconfigure"];
 	*m_pgamelist = (*m_platform)["gamelist"];
 	*m_pthirdtranslog = (*m_gamelog)["thirdtranslog"];
+	*m_pthirddeveloper = (*m_platform)["thirddeveloper"];
 
 	m_strshahead = "X-REQUEST-SIGN";
 	m_strshaheadcontent = "6e4c91001979851a97c2b5360f044ff67b48e186d6ecd4394532851bffdeeae9";
@@ -200,10 +202,6 @@ bool HttpSocket::postmsg(std::function<void(std::string&, int)> funhttpmsg, std:
 			{
 				reelplay(getdata, funhttpmsg);
 			}
-			else if (itype == HTTPLOGOUTREEL)
-			{
-				reellogout(getdata, funhttpmsg);
-			}
 			else
 			{
 				return false;
@@ -3279,7 +3277,6 @@ std::string HttpSocket::reelplay(std::map<std::string, std::string> getdata, std
 {
 	reelplayuser treelplayuser;
 	getvaluedata(getdata, treelplayuser);
-
 	std::string strret;
 
 	m_writelog("--------------------reelplay-------------------------");
@@ -3291,23 +3288,52 @@ std::string HttpSocket::reelplay(std::map<std::string, std::string> getdata, std
 		return "";
 	}
 
-	std::int32_t iareaid{ 0 };
-	std::int64_t ispreaderid{ 0 };
-	
 	auto findwebuser = make_document(kvp("account", treelplayuser.struseracc.c_str()), kvp("dynamicpass", treelplayuser.strcert.c_str()));
 	auto findneuserdata = m_pcoll->find_one(findwebuser.view());
-	if (!findneuserdata)
+	if (!findneuserdata || !findneuserdata->view()["userid"])
 	{
 		dofun(funclib::rettojson(Err_No_Player, "param erro"), 200);
 		return "";
 	}
 
+	__int32 iusertype = 0;
+	if (findneuserdata->view()["usertype"])
+		iusertype = findneuserdata->view()["usertype"].get_int32();
+	auto finddeveloper = m_pthirddeveloper->find_one(make_document(kvp("id", 2)));
+	std::set<__int32> setcurrency;
+	if (finddeveloper && finddeveloper->view()["currency"] && finddeveloper->view()["currency"].type() == bsoncxx::type::k_array) 
+	{
+		auto arr = finddeveloper->view()["currency"].get_array().value;
+		for (auto&& elem : arr) 
+		{
+			if (elem.type() == bsoncxx::type::k_int32)
+			{
+				setcurrency.insert(elem.get_int32().value);
+			}		
+		}
+	}
+
+	if ((iusertype == 0 && setcurrency.end() == setcurrency.find(1)) || // 不支持真金
+		(iusertype == 2 && setcurrency.end() == setcurrency.find(3))) // 不支持免费币
+	{
+		dofun(funclib::rettojson(Err_GAMECURRENCY_NOTMATCH, "currency type error"), 200);
+		return "";
+	}
+
+	std::int64_t iuserid = findneuserdata->view()["userid"].get_int64();
+	auto res_play = m_pplayuseronline->find_one(make_document(kvp("userid", iuserid)));
+	if (res_play)
+	{
+		dofun(funclib::rettojson(Err_Player_InGame, "player alread in games"), 200);
+		return "";
+	}
+
 	std::int64_t iscore{ 0 };
 	if (findneuserdata && findneuserdata->view()["score"])
 	{
 		iscore = findneuserdata->view()["score"].get_int64();
 	}
-	createreeluser(treelplayuser.struseracc, treelplayuser.ikindid, iscore, dofun);
+	createreeluser(treelplayuser.struseracc, treelplayuser.ikindid, iscore, iuserid, dofun);
 
 	return {};
 }
@@ -3331,60 +3357,9 @@ void HttpSocket::sendreelmsg(std::string stronly, std::string strtarget, std::st
 	weblib::sendhttp(m_psendhttp, std::move(thttpinfo), std::move(dofun));
 }
 
-//检查玩家钱包
-void HttpSocket::checkreeluserbalance(std::string struseracc, std::function<void(std::string&, int)> dofun)
-{
-	rapidjson::Document doc;
-	doc.SetObject();
-	rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
-
-	doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
-	doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
-	//std::string strjson{ "{\"casino\":\"luckybet777\",\"playerId\":\"testPlayer_5\",\"currency\":\"EUR\",\"country\":\"US\"}" };
-
-	std::string strjson = funclib::doctojson(doc);
-	std::string strtarget = "v2/tw/balance";
-
-	sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun](std::string strdata, int iret) {
-
-		std::stringstream strlog;
-		strlog << "检查玩家钱包: iret=" << iret << " strdata=" << strdata;
-		m_writelog(strlog.str());
-
-		if (iret == 200)
-		{
-			rettype::type tret{ rettype::type::ini };
-			rapidjson::Document docdata;
-			rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
-			if (ok)
-			{
-				double dscore{ 0 };
-				std::string strscore{};
-				tret = funclib::getjsonvalue(docdata, "balance", strscore);
-				if (tret == rettype::type::exist)
-				{
-					try
-					{
-						dscore = std::stod(strscore);	
-						reeltranstouser(struseracc, (std::int64_t)dscore, dofun);
-					}
-					catch (const std::exception&)
-					{
-					}
-				}
-			}
-		}
-		else
-		{
-			std::string strret = funclib::errotojson(-1);
-			dofun(strret, 200);
-		}
-
-		}));
-}
 
 //创建玩家
-void HttpSocket::createreeluser(std::string struseracc, __int32 ikindid, std::int64_t iscore, std::function<void(std::string&, int)> dofun)
+void HttpSocket::createreeluser(std::string struseracc, __int32 ikindid, std::int64_t iscore, __int64 iuserid, std::function<void(std::string&, int)> dofun)
 {
 	m_writelog("--------------------createreeluser-------------------------");
 	rapidjson::Document doc;
@@ -3401,7 +3376,7 @@ void HttpSocket::createreeluser(std::string struseracc, __int32 ikindid, std::in
 	std::string strtarget = "v2/tw/createPlayer";
 
 	//创建玩家
-	sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, iscore, ikindid, dofun](std::string strdata, int iret) {
+	sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, iscore, ikindid, iuserid, dofun](std::string strdata, int iret) {
 		
 		std::stringstream strlog;
 		strlog << "创建玩家: iret=" << iret << " strdata=" << strdata;
@@ -3430,7 +3405,7 @@ void HttpSocket::createreeluser(std::string struseracc, __int32 ikindid, std::in
 		//玩家创建成功
 		if (bhaveuser)
 		{
-			reelusertrans(struseracc, ikindid, iscore, dofun);
+			reelusertrans(struseracc, ikindid, iscore, iuserid, dofun);
 		}
 		else
 		{
@@ -3440,7 +3415,7 @@ void HttpSocket::createreeluser(std::string struseracc, __int32 ikindid, std::in
 		}));
 }
 
-void HttpSocket::reelusertrans(std::string struseracc, __int32 ikindid, std::int64_t iscore, std::function<void(std::string&, int)> dofun)
+void HttpSocket::reelusertrans(std::string struseracc, __int32 ikindid, std::int64_t iscore, __int64 iuserid, std::function<void(std::string&, int)> dofun)
 {
 	m_writelog("--------------------reelusertrans-------------------------");
 	if (iscore > 0)
@@ -3459,14 +3434,12 @@ void HttpSocket::reelusertrans(std::string struseracc, __int32 ikindid, std::int
 		std::string strjson = funclib::doctojson(doc);
 		std::string strtarget = "v2/tw/transfer";
 
-		sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun, iscore, ikindid, strtransid](std::string strdata, int iret) {
+		sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun, iscore, ikindid, iuserid, strtransid](std::string strdata, int iret) {
 
 			std::stringstream strlog;
 			strlog << "转账: iscore=" << iscore << " iret=" << iret << " strdata=" << strdata;
 			m_writelog(strlog.str());
 
-			double dscore{ 0 };
-			bool bscore{ false };
 			if (iret == 200)
 			{
 				rettype::type tret{ rettype::type::ini };
@@ -3474,42 +3447,15 @@ void HttpSocket::reelusertrans(std::string struseracc, __int32 ikindid, std::int
 				rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
 				if (ok)
 				{
-					tret = funclib::getjsonvalue(docdata, "balance", dscore);
-					if (tret == rettype::type::exist)
+					// 更新玩家分数
+					if (docdata.HasMember("balance") && updateusertrans(struseracc, ikindid, strtransid, iscore * -1))
 					{
-						bscore = true;
-					}
-					else
-					{
-						std::string strscore{};
-						tret = funclib::getjsonvalue(docdata, "balance", strscore);
-						if (tret == rettype::type::exist)
-						{
-							try
-							{
-								dscore = std::stod(strscore);
-								bscore = true;
-							}
-							catch (const std::exception&)
-							{
-								bscore = false;
-							}	
-						}
+						//直接拉取游戏
+						getreelgameurl(struseracc, ikindid, iuserid, dofun);
+						return;
 					}
 				}
-			}
-
-			//转账成功
-			if (bscore)
-			{
-				// 更新玩家分数
-				if (updateusertrans(struseracc, ikindid, strtransid, iscore*-1))
-				{
-					//直接拉取游戏
-					getreelgameurl(struseracc, ikindid, dofun);
-					return;
-				}
-			}			
+			}					
 			dofun(funclib::rettojson(Err_TRANS_FAILED, "trans failed"), 200);
 			}));
 	}
@@ -3517,13 +3463,13 @@ void HttpSocket::reelusertrans(std::string struseracc, __int32 ikindid, std::int
 	{
 		m_writelog("iscore = 0, 直接拉取游戏");
 		//直接拉取游戏
-		getreelgameurl(struseracc, ikindid, dofun);
+		getreelgameurl(struseracc, ikindid, iuserid, dofun);
 	}
 }
 
 
 //拉取游戏
-void HttpSocket::getreelgameurl(std::string struseracc, __int32 ikindid, std::function<void(std::string&, int)> dofun)
+void HttpSocket::getreelgameurl(std::string struseracc, __int32 ikindid, __int64 iuserid, std::function<void(std::string&, int)> dofun)
 {
 	m_writelog("--------------------getreelgameurl-------------------------");
 	rapidjson::Document doc;
@@ -3545,7 +3491,7 @@ void HttpSocket::getreelgameurl(std::string struseracc, __int32 ikindid, std::fu
 	std::string strjson = funclib::doctojson(doc);
 	std::string strtarget = "v2/tw/startGame";
 
-	sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun](std::string strdata, int iret) {
+	sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, ikindid, iuserid, strAlias, dofun](std::string strdata, int iret) {
 		
 		std::stringstream strlog;
 		strlog << "拉取游戏: iret=" << iret << " strdata=" << strdata;
@@ -3562,6 +3508,14 @@ void HttpSocket::getreelgameurl(std::string struseracc, __int32 ikindid, std::fu
 				docdata.AddMember("ret", -1, allocator);
 				docdata.AddMember("info", rapidjson::Value("ok", allocator), allocator);
 				dofun(funclib::doctojson(docdata), 200);
+
+				//添加在线信息
+				m_postmsg(std::move([this, struseracc, ikindid, iuserid, strAlias]() {
+					auto playbuilder = bsoncxx::builder::stream::document{};
+					playbuilder << "userid" << iuserid  <<  "kindid" << ikindid << "brandid" << 2 << "GID" << strAlias.c_str() << "inserttime" << funclib::gettimestamp();
+					m_pplayuseronline->insert_one(playbuilder.view());
+					}
+				));
 			}
 		}
 		else
@@ -3615,138 +3569,5 @@ bool HttpSocket::updateusertrans(std::string struseracc, __int32 ikindid, std::s
 	return true;
 }
 
-//踢玩家下真人视讯平台
-void HttpSocket::reellogout(std::map<std::string, std::string> getdata, std::function<void(std::string&, int)> dofun)
-{
-	string struseracc = "";
-	string strcert = "";
-	auto& findacc = getdata.find("useracc");
-	if (findacc != getdata.end())
-	{
-		struseracc = findacc->second;
-	}
-
-	auto& findcert = getdata.find("cert");
-	if (findcert != getdata.end())
-	{
-		strcert = findcert->second;
-	}
-
-	if (struseracc.empty() || strcert.empty())
-	{
-		return dofun(funclib::rettojson(Err_ParamError, "param erro"), 200);
-	}
-
-	auto findwebuser = make_document(kvp("account", struseracc.c_str()), kvp("dynamicpass", strcert.c_str()));
-	auto findneuserdata = m_pcoll->find_one(findwebuser.view());
-	if (!findneuserdata)
-	{
-		dofun(funclib::rettojson(Err_No_Player, "param erro"), 200);
-		return ;
-	}
-
-	rapidjson::Document doc;
-	doc.SetObject();
-	rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
-
-	doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
-	doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
-	//std::string strjson{ "{\"casino\":\"luckybet777\",\"playerId\":\"testPlayer_5\",\"currency\":\"EUR\",\"country\":\"US\"}" };
-
-	std::string strjson = funclib::doctojson(doc);
-	std::string strtarget = "v2/tw/terminateSession";
-
-	sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun](std::string strdata, int iret) {
-
-		std::stringstream strlog;
-		strlog << "踢玩家下线: iret=" << iret << " strdata=" << strdata;
-		m_writelog(strlog.str());
-		if (iret == 200)
-		{
-			rettype::type tret{ rettype::type::ini };
-			rapidjson::Document docdata;
-			rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
-			if (ok)
-			{
-				checkreeluserbalance(struseracc, dofun);
-			}
-		}		
-		}));
-}
-
-
-//三方转账到玩家
-void HttpSocket::reeltranstouser(std::string struseracc, std::int64_t iscore, std::function<void(std::string&, int)> dofun)
-{
-	m_writelog("--------------------reeltranstouser-------------------------");
-	if (iscore > 0)
-	{
-		rapidjson::Document doc;
-		doc.SetObject();
-		rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();
-
-		iscore = iscore * -1 * 10000;
-		std::string strscore = funclib::getdouble(iscore);
-		std::string strtransid = funclib::getonlytoken(1, m_ucurid);
-
-		doc.AddMember("casino", rapidjson::Value("luckybet777", allocator), allocator);
-		doc.AddMember("playerId", rapidjson::Value(struseracc.c_str(), allocator), allocator);
-		doc.AddMember("transactionId", rapidjson::Value(strtransid.c_str(), allocator), allocator);
-		doc.AddMember("amount", rapidjson::Value(strscore.c_str(), allocator), allocator);
-		std::string strjson = funclib::doctojson(doc);
-		std::string strtarget = "v2/tw/transfer";
-
-		sendreelmsg(struseracc, strtarget, strjson, std::move([this, struseracc, dofun, iscore, strtransid](std::string strdata, int iret) {
-
-			std::stringstream strlog;
-			strlog << "转账到玩家: iscore=" << iscore << " iret=" << iret << " strdata=" << strdata;
-			m_writelog(strlog.str());
-
-			double dscore{ 0 };
-			bool bscore{ false };
-			if (iret == 200)
-			{
-				rettype::type tret{ rettype::type::ini };
-				rapidjson::Document docdata;
-				rapidjson::ParseResult ok = docdata.Parse(strdata.c_str());
-				if (ok)
-				{
-					tret = funclib::getjsonvalue(docdata, "balance", dscore);
-					if (tret == rettype::type::exist)
-					{
-						bscore = true;
-					}
-					else
-					{
-						std::string strscore{};
-						tret = funclib::getjsonvalue(docdata, "balance", strscore);
-						if (tret == rettype::type::exist)
-						{
-							try
-							{
-								dscore = std::stod(strscore);
-								bscore = true;
-							}
-							catch (const std::exception&)
-							{
-								bscore = false;
-							}
-						}
-					}
-				}
-			}
-
-			//转账成功
-			if (bscore)
-			{
-				// 更新玩家分数				
-				updateusertrans(struseracc, 0, strtransid, iscore * -1);
-				dofun(funclib::rettojson(-1, "success"), 200);
-				return;				
-			}
-			dofun(funclib::rettojson(Err_TRANS_FAILED, "trans failed"), 200);
-			}));
-	}	
-}
 
 

+ 7 - 10
webapi/webapi/HttpSocket.h

@@ -88,7 +88,8 @@ protected:
 	boost::shared_ptr<mongocxx::collection> m_pgamelist;
 	//三方转账记录
 	boost::shared_ptr<mongocxx::collection> m_pthirdtranslog;
-
+	// thirdplat 第3方厂商管理
+	boost::shared_ptr<mongocxx::collection> m_pthirddeveloper;
 public:
 	HttpSocket();
 	~HttpSocket();
@@ -132,19 +133,15 @@ protected:
 	//登录真人视讯
 	std::string reelplay(std::map<std::string, std::string> getdata, std::function<void(std::string&, int)>& dofun);
 	void sendreelmsg(std::string stronly, std::string strtarget, std::string strjson, std::function<void(std::string, int)>&& dofun);
-	//检查玩家钱包
-	void checkreeluserbalance(std::string struseracc, std::function<void(std::string&, int)> dofun);
+
 	//创建玩家
-	void createreeluser(std::string struseracc, __int32 ikindid, std::int64_t iscore, std::function<void(std::string&, int)> dofun);
+	void createreeluser(std::string struseracc, __int32 ikindid, std::int64_t iscore, __int64 iuserid, std::function<void(std::string&, int)> dofun);
 	//玩家转账到三方
-	void reelusertrans(std::string struseracc, __int32 ikindid, std::int64_t iscore, std::function<void(std::string&, int)> dofun);
-	//三方转账到玩家
-	void reeltranstouser(std::string struseracc, std::int64_t iscore, std::function<void(std::string&, int)> dofun);
+	void reelusertrans(std::string struseracc, __int32 ikindid, std::int64_t iscore, __int64 iuserid, std::function<void(std::string&, int)> dofun);
 	bool updateusertrans(std::string struseracc, __int32 ikindid, std::string strtransid, std::int64_t iscore);
 	//拉取游戏
-	void getreelgameurl(std::string struseracc, __int32 ikindid, std::function<void(std::string&, int)> dofun);
-	//踢玩家下真人视讯平台
-	void reellogout(std::map<std::string, std::string> getdata, std::function<void(std::string&, int)> dofun);
+	void getreelgameurl(std::string struseracc, __int32 ikindid, __int64 iuserid, std::function<void(std::string&, int)> dofun);
+
 
 };
 #endif

+ 1 - 1
webapi/webapi/data.h

@@ -64,7 +64,6 @@
 #define HTTPLBACKINGOT				27				//回退奖励码
 #define HTTPLOOKUPALLUSERPLAYSCORE	28				//查询所有玩家总下注和总赢回
 #define HTTPLOGINREEL				29				//登录真人视讯
-#define HTTPLOGOUTREEL				30				//登出真人视讯
 
 #define HTTPMAX						31				//http最大id
 
@@ -176,6 +175,7 @@ enum EErrorCode
 	Err_ScoreParamError = 1055, //  分数参数错误,小于0
 	Err_OverQueryTimeLimit = 1056, //  查询时间超时
 	Err_TRANS_FAILED = 1057, //  转账失败
+	Err_GAMECURRENCY_NOTMATCH = 1058,	// 游戏货币类型不支持
 };