Forráskód Böngészése

新增接口:生成兑换码

Jason 2 hete
szülő
commit
aea56eff84
3 módosított fájl, 187 hozzáadás és 3 törlés
  1. 127 0
      webapi/webapi/HttpSocket.cpp
  2. 4 1
      webapi/webapi/HttpSocket.h
  3. 56 2
      webapi/webapi/data.h

+ 127 - 0
webapi/webapi/HttpSocket.cpp

@@ -59,6 +59,7 @@ HttpSocket::HttpSocket()
 	m_pgamelist = boost::make_shared<mongocxx::collection>();
 	m_pthirdtranslog = boost::make_shared<mongocxx::collection>();
 	m_pthirddeveloper = boost::make_shared<mongocxx::collection>();
+	m_predeemcode = boost::make_shared<mongocxx::collection>();
 
 	*m_pdb = (*m_pclient)["accounts"];
 	*m_gamelog = (*m_pclient)["gamelog"];
@@ -84,6 +85,7 @@ HttpSocket::HttpSocket()
 	*m_pgamelist = (*m_platform)["gamelist"];
 	*m_pthirdtranslog = (*m_gamelog)["thirdtranslog"];
 	*m_pthirddeveloper = (*m_platform)["thirddeveloper"];
+	*m_predeemcode = (*m_pvipuserdb)["redeemcode"];
 
 	m_strshahead = "X-REQUEST-SIGN";
 	m_strshaheadcontent = "6e4c91001979851a97c2b5360f044ff67b48e186d6ecd4394532851bffdeeae9";
@@ -202,6 +204,11 @@ bool HttpSocket::postmsg(std::function<void(std::string&, int)> funhttpmsg, std:
 			{
 				reelplay(getdata, funhttpmsg);
 			}
+			//兑换码
+			else if (itype == HTTPGENERATEREDEEMCODE)
+			{
+				strtojson = generateredeemcodes(getdata);
+			}
 			else
 			{
 				return false;
@@ -3594,3 +3601,123 @@ bool HttpSocket::updateusertrans(std::string struseracc, __int32 ikindid, std::s
 
 
 
+//生成兑换码
+std::string HttpSocket::generateredeemcodes(std::map<std::string, std::string> getdata)
+{
+	sRedeemCodeGenerate reqparam;
+	getvaluedata(getdata, reqparam);
+	std::string strret{};
+
+	bool bret = reqparam.datavalue();
+	if (!bret)
+	{
+		strret = funclib::rettojson(Err_ParamError, "param erro");
+		return strret;
+	}
+	//if (EA_LEVEL1 != getlevel(reqparam.spreaderid))
+	//{
+	//	strret = funclib::rettojson(2, "you are not admin");
+	//	return strret;
+	//}
+	auto findinfo = m_predeemcode->find_one(make_document(kvp("info", reqparam.info.c_str())));
+	if (findinfo)
+	{
+		strret = funclib::rettojson(Err_RedeemLableDuplicate, "lable duplicate!");
+		return strret;
+	}
+
+	//判断三方平台是否存在
+	auto threeadmin = m_pthreeadmin->find_one(bsoncxx::builder::stream::document{} << "authcode" << reqparam.authcode.c_str() \
+		<< "authkey" << reqparam.authkey.c_str() << bsoncxx::builder::stream::finalize);
+	if (!threeadmin)
+	{
+		strret = funclib::rettojson(Err_KeyNotExist, "code or key isnot exist");
+		return strret;
+	}
+
+	if (!threeadmin->view()["adminuserid"])
+	{
+		strret = funclib::rettojson(Err_ThreeAdminLackInfo, "spreaderid isnot exist");
+		return strret;
+	}
+
+	__int64 ispreaderid = threeadmin->view()["adminuserid"].get_int64();
+	auto vipuser = m_pvipuser->find_one(bsoncxx::builder::stream::document{} << "userid" << ispreaderid << bsoncxx::builder::stream::finalize);
+	if (!vipuser || !vipuser->view()["areaid"])
+	{
+		strret = funclib::rettojson(Err_No_Agent, "spreaderid isnot exist");
+		return strret;
+	}
+
+	__int32 vipstate = 0;
+	if (vipuser->view()["state"])
+	{
+		vipstate = vipuser->view()["state"].get_int32();
+	}
+	else
+		vipstate = 1;
+
+	if (vipstate != 0)
+	{
+		strret = funclib::rettojson(Err_OutOfState_Agent, "spreaderid is disabled");
+		return strret;
+	}
+
+	__int32 iareaid = vipuser->view()["areaid"].get_int32();
+	// 生成兑换码
+	std::set<std::string> setcodes;
+	string strcode = "";
+	std::uniform_int_distribution<int> disrand(1, g_redeemcodechars.length() - 1);
+	while (setcodes.size() < reqparam.iquantity)
+	{
+		strcode = "";
+		for (size_t i = 0; i < 6; ++i) {
+			strcode += g_redeemcodechars.at(disrand(m_random));
+		}
+		if (setcodes.find(strcode) != setcodes.end())
+			continue;
+
+		if (m_predeemcode->count_documents(make_document(kvp("code", strcode.c_str()))) > 0)
+			continue;
+		setcodes.insert(strcode);
+	}
+
+	rapidjson::Document doc;
+	doc.SetObject();
+	rapidjson::Document::AllocatorType& allocator = doc.GetAllocator();	
+	rapidjson::Value codesArray(rapidjson::kArrayType);
+
+	//批量插入
+	mongocxx::options::bulk_write bulk_opts;
+	bulk_opts.ordered(false); // false = 允许乱序执行,提高效率
+	auto bulk = m_predeemcode->create_bulk_write(bulk_opts);
+	__int64 itime = funclib::gettimestamp();
+	for (const auto& strcode : setcodes)
+	{
+		document doc;
+		doc.append(kvp("code", strcode.c_str()), kvp("info", reqparam.info.c_str()), kvp("codetype", reqparam.icodetype), kvp("exchangelimit", reqparam.iexchangelimit),
+			kvp("accountlimit", reqparam.iaccountlimit), kvp("score", reqparam.iscore), kvp("st", reqparam.istarttime), kvp("et", reqparam.iendtime),
+			kvp("open", 1), kvp("usedcount", 0), kvp("inserttime", itime), kvp("areaid", iareaid), kvp("spreaderid", ispreaderid));
+		mongocxx::model::insert_one insert_op{ doc.view() };
+		bulk.append(insert_op);
+
+		codesArray.PushBack(rapidjson::Value(strcode.c_str(), allocator), allocator);
+	}
+
+	// 执行批量 update
+	auto result = bulk.execute();
+	if (result)
+	{
+		doc.AddMember("ret", -1, allocator);
+		doc.AddMember("info", rapidjson::Value("ok", allocator), allocator);
+		doc.AddMember("data", codesArray, allocator);
+		strret = funclib::doctojson(doc);
+		return strret;
+	}
+
+	strret = funclib::rettojson(2, "error");
+	return strret;
+}
+
+
+

+ 4 - 1
webapi/webapi/HttpSocket.h

@@ -90,6 +90,8 @@ protected:
 	boost::shared_ptr<mongocxx::collection> m_pthirdtranslog;
 	// thirdplat 第3方厂商管理
 	boost::shared_ptr<mongocxx::collection> m_pthirddeveloper;
+	// 兑换码
+	boost::shared_ptr<mongocxx::collection> m_predeemcode;
 public:
 	HttpSocket();
 	~HttpSocket();
@@ -142,6 +144,7 @@ protected:
 	//拉取游戏
 	void getreelgameurl(std::string struseracc, __int32 ikindid, __int64 iuserid, std::function<void(std::string&, int)> dofun);
 
-
+	//-------------------------------兑换码---------------------------------------
+	std::string generateredeemcodes(std::map<std::string, std::string> getdata);
 };
 #endif

+ 56 - 2
webapi/webapi/data.h

@@ -64,6 +64,8 @@
 #define HTTPLBACKINGOT				27				//回退奖励码
 #define HTTPLOOKUPALLUSERPLAYSCORE	28				//查询所有玩家总下注和总赢回
 #define HTTPLOGINREEL				29				//登录真人视讯
+#define HTTPGENERATEREDEEMCODE		30				//兑换码
+
 
 #define HTTPMAX						31				//http最大id
 
@@ -78,6 +80,10 @@ static std::string g_chars(
 	"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 	"1234567890");
 
+static std::string g_redeemcodechars(
+	"ABCDEFGHJKLMNPQRSTUVWXYZ"
+	"0123456789");
+
 //msg data
 typedef struct tagMsgBuffer
 {
@@ -174,8 +180,13 @@ enum EErrorCode
 	Err_AgengtHasNoPlayer = 1054, //  代理下没有玩家
 	Err_ScoreParamError = 1055, //  分数参数错误,小于0
 	Err_OverQueryTimeLimit = 1056, //  查询时间超时
-	Err_TRANS_FAILED = 1057, //  转账失败
-	Err_GAMECURRENCY_NOTMATCH = 1058,	// 游戏货币类型不对
+	Err_FreeGameStatue = 1057, //  活动状态不允许操作
+	Err_FreeGamePlayerError = 1058, //  玩家列表参数错误
+	Err_FreeGameMaxCount = 1059, //  代理创建的活动已达到5
+	Err_RedeemLableDuplicate = 1060, //  兑换码标签重复
+	Err_TRANS_FAILED = 1061, //  转账失败
+	Err_GAMECURRENCY_NOTMATCH = 1062,	// 游戏货币类型不对
+
 };
 
 
@@ -707,4 +718,47 @@ public:
 		return true;
 	}
 };
+
+enum ERedeemCodeType
+{
+	ERCT_ONLY = 1, // 唯一码
+	ERCT_SHRE = 2, // 共享码
+	ERCT_MAX,
+};
+
+struct sRedeemCodeGenerate
+{
+	std::string		authcode{};
+	std::string		authkey{};
+	std::string		info = "";					// lable
+	__int32		 iquantity = 0;					// 生成数量
+	__int32		 icodetype = 1;					// ERedeemCodeType  
+	__int32		 iexchangelimit = 1;			// 兑换次数
+	__int32	     iaccountlimit = 1;				// 账号兑换次数
+	__int64      iscore = 0;
+	__int64		 istarttime = 0;
+	__int64		 iendtime = 0;
+
+public:
+	std::string getfieldvalue(std::int32_t index)
+	{
+		const char* value[] = { "authcode", "authkey", "info", "quantity", "type","exchangelimit", "accountlimit", "score", "st", "et" };
+		return value[index];
+	}
+
+	bool datavalue()
+	{
+		if (info.empty() || authcode.empty() || authkey.empty() || (icodetype == 2 && iexchangelimit < 2) || istarttime > iendtime || iscore < 1 || iaccountlimit < 1 || iquantity < 1)
+		{
+			return false;
+		}
+
+		return true;
+	}
+
+	void getdata()
+	{
+
+	}
+};
 #pragma pack()