Skip to content

Commit a667685

Browse files
committed
commit
1 parent a788ee9 commit a667685

File tree

2 files changed

+104
-38
lines changed

2 files changed

+104
-38
lines changed

Proto/proto_raw/Msg_RetCode.proto

+1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ enum MessageRetCode {
6363
MRC_GIFTCODE_UNASSIGNED = 502; //礼包码未分配
6464
MRC_GIFTCODE_WRONG_CHANNEL = 503; //错误的渠道
6565
MRC_GIFTCODE_WRONG_AREA = 504; //错误的区服
66+
MRC_GIFTCODE_NO_MORE = 505; //己被领完了
6667
}
6768

Server/Src/LoginServer/GiftCodeManager.cpp

+103-38
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ BOOL GiftCodeManager::ProceeGiftCodeThread()
6161
if (!tDBConnection.open(strHost.c_str(), strUser.c_str(), strPwd.c_str(), strDb.c_str(), nPort))
6262
{
6363
CLog::GetInstancePtr()->LogError("GiftCodeManager::Init Error: Can not open mysql database! Reason:%s", tDBConnection.GetErrorMsg());
64+
CLog::GetInstancePtr()->LogError("GiftCodeManager::Init Error: Host:[%s]-User:[%s]-Pwd:[%s]-DBName:[%s]", strHost.c_str(), strUser.c_str(), strPwd.c_str(), strDb.c_str());
6465
return FALSE;
6566
}
6667

@@ -108,7 +109,7 @@ BOOL GiftCodeManager::ProceeGiftCodeThread()
108109
std::string strNowTime = CommonFunc::TimeToString(CommonFunc::GetCurrTime());
109110
snprintf(szSql, SQL_BUFF_LEN, "select * from giftcode_base where giftcode ='%s' and '%s' > starttime and '%s' < endtime", pTmpNode->m_strCode.c_str(), strNowTime.c_str(), strNowTime.c_str());
110111
CppMySQLQuery codeResult = tDBConnection.querySQL(szSql);
111-
if (!codeResult.hasResult())
112+
if (tDBConnection.GetErrorNo() != 0)
112113
{
113114
CLog::GetInstancePtr()->LogError("GiftCodeManager::get gift code failure Error :%s", tDBConnection.GetErrorMsg());
114115
pTmpNode->m_dwResult = MRC_GIFTCODE_INVALIDE_CODE;
@@ -152,43 +153,107 @@ BOOL GiftCodeManager::ProceeGiftCodeThread()
152153
continue;
153154
}
154155

155-
if (nUseNum >= nTotalNum)
156-
{
157-
pTmpNode->m_dwResult = MRC_GIFTCODE_AREADY_USED;
158-
m_ArrFinishNode.push(pTmpNode);
159-
continue;
160-
}
161-
162-
if (nUseType == 1) //表示只能一人使用
163-
{
164-
if (uRoleID > 0)
165-
{
166-
pTmpNode->m_dwResult = MRC_GIFTCODE_AREADY_USED;
167-
m_ArrFinishNode.push(pTmpNode);
168-
continue;
169-
}
170-
171-
snprintf(szSql, SQL_BUFF_LEN, "update giftcode_base set roleid=%lld, usenum = 1 where giftcode ='%s'", pTmpNode->m_uRoleID, pTmpNode->m_strCode.c_str());
172-
tDBConnection.execSQL(szSql);
173-
}
174-
else if (nUseType == 2) //表示可以多人使用
175-
{
176-
snprintf(szSql, SQL_BUFF_LEN, "select * from giftcode_used where giftcode ='%s' and roleid = %lld", pTmpNode->m_strCode.c_str(), pTmpNode->m_uRoleID);
177-
CppMySQLQuery usedResult = tDBConnection.querySQL(szSql);
178-
if (usedResult.hasResult() && usedResult.numRow() > 0)
179-
{
180-
pTmpNode->m_dwResult = MRC_GIFTCODE_AREADY_USED;
181-
m_ArrFinishNode.push(pTmpNode);
182-
continue;
183-
}
184-
185-
snprintf(szSql, SQL_BUFF_LEN, "insert into giftcode_used(roleid, accountid,areaid, giftcode, usetime) values(%lld, %lld, %d, '%s', '%s')", pTmpNode->m_uRoleID, pTmpNode->m_uAccountID, pTmpNode->m_dwAreaID,
186-
pTmpNode->m_strCode.c_str(), CommonFunc::TimeToString(CommonFunc::GetCurrTime()).c_str());
187-
tDBConnection.execSQL(szSql);
188-
189-
snprintf(szSql, SQL_BUFF_LEN, "update giftcode_base set usenum = usenum +1 where giftcode ='%s'", pTmpNode->m_strCode.c_str());
190-
tDBConnection.execSQL(szSql);
191-
}
156+
if (nUseType == 1) //表示只能一人使用
157+
{
158+
if (uRoleID > 0)
159+
{
160+
pTmpNode->m_dwResult = MRC_GIFTCODE_AREADY_USED;
161+
m_ArrFinishNode.push(pTmpNode);
162+
continue;
163+
}
164+
165+
snprintf(szSql, SQL_BUFF_LEN, "update giftcode_base set roleid=%lld, usenum = 1 where giftcode ='%s'", pTmpNode->m_uRoleID, pTmpNode->m_strCode.c_str());
166+
if (tDBConnection.execSQL(szSql) <= 0 || tDBConnection.GetErrorNo() != 0)
167+
{
168+
pTmpNode->m_dwResult = MRC_UNKNOW_ERROR;
169+
m_ArrFinishNode.push(pTmpNode);
170+
continue;
171+
}
172+
}
173+
else if (nUseType == 2) //表示可以多人使用
174+
{
175+
if (nUseNum >= nTotalNum)
176+
{
177+
pTmpNode->m_dwResult = MRC_GIFTCODE_NO_MORE;
178+
m_ArrFinishNode.push(pTmpNode);
179+
continue;
180+
}
181+
182+
snprintf(szSql, SQL_BUFF_LEN, "select * from giftcode_used where giftcode ='%s' and roleid = %lld", pTmpNode->m_strCode.c_str(), pTmpNode->m_uRoleID);
183+
CppMySQLQuery usedResult = tDBConnection.querySQL(szSql);
184+
if (tDBConnection.GetErrorNo() != 0)
185+
{
186+
pTmpNode->m_dwResult = MRC_UNKNOW_ERROR;
187+
m_ArrFinishNode.push(pTmpNode);
188+
continue;
189+
}
190+
191+
if (usedResult.numRow() > 0)
192+
{
193+
pTmpNode->m_dwResult = MRC_GIFTCODE_AREADY_USED;
194+
m_ArrFinishNode.push(pTmpNode);
195+
continue;
196+
}
197+
198+
snprintf(szSql, SQL_BUFF_LEN, "insert into giftcode_used(roleid, accountid,areaid, giftcode, usetime, awardid) values(%lld, %lld, %d, '%s', %lld, %d)", pTmpNode->m_uRoleID, pTmpNode->m_uAccountID, pTmpNode->m_dwAreaID,
199+
pTmpNode->m_strCode.c_str(), CommonFunc::GetCurrTime(), nAwardID);
200+
if (tDBConnection.execSQL(szSql) <= 0 || tDBConnection.GetErrorNo() != 0)
201+
{
202+
pTmpNode->m_dwResult = MRC_UNKNOW_ERROR;
203+
m_ArrFinishNode.push(pTmpNode);
204+
continue;
205+
}
206+
207+
snprintf(szSql, SQL_BUFF_LEN, "update giftcode_base set usenum = usenum +1 where giftcode ='%s'", pTmpNode->m_strCode.c_str());
208+
if (tDBConnection.execSQL(szSql) <= 0 || tDBConnection.GetErrorNo() != 0)
209+
{
210+
pTmpNode->m_dwResult = MRC_UNKNOW_ERROR;
211+
m_ArrFinishNode.push(pTmpNode);
212+
continue;
213+
}
214+
}
215+
else if (nUseType == 3) //表示可以多人使用
216+
{
217+
if (uRoleID > 0)
218+
{
219+
pTmpNode->m_dwResult = MRC_GIFTCODE_AREADY_USED;
220+
m_ArrFinishNode.push(pTmpNode);
221+
continue;
222+
}
223+
224+
snprintf(szSql, SQL_BUFF_LEN, "select * from giftcode_used where awardid = %d and roleid = %lld", nAwardID, pTmpNode->m_uRoleID);
225+
CppMySQLQuery usedResult = tDBConnection.querySQL(szSql);
226+
if (tDBConnection.GetErrorNo() != 0)
227+
{
228+
pTmpNode->m_dwResult = MRC_UNKNOW_ERROR;
229+
m_ArrFinishNode.push(pTmpNode);
230+
continue;
231+
}
232+
233+
if (usedResult.numRow() > 0)
234+
{
235+
pTmpNode->m_dwResult = MRC_GIFTCODE_AREADY_USED;
236+
m_ArrFinishNode.push(pTmpNode);
237+
continue;
238+
}
239+
240+
snprintf(szSql, SQL_BUFF_LEN, "insert into giftcode_used(roleid, accountid,areaid, giftcode, usetime, awardid) values(%lld, %lld, %d, '%s', %lld, %d)", pTmpNode->m_uRoleID, pTmpNode->m_uAccountID, pTmpNode->m_dwAreaID,
241+
pTmpNode->m_strCode.c_str(), CommonFunc::GetCurrTime(), nAwardID);
242+
if (tDBConnection.execSQL(szSql) <= 0 || tDBConnection.GetErrorNo() != 0)
243+
{
244+
pTmpNode->m_dwResult = MRC_UNKNOW_ERROR;
245+
m_ArrFinishNode.push(pTmpNode);
246+
continue;
247+
}
248+
249+
snprintf(szSql, SQL_BUFF_LEN, "update giftcode_base set roleid=%lld, usenum = 1 where giftcode ='%s'", pTmpNode->m_uRoleID, pTmpNode->m_strCode.c_str());
250+
if (tDBConnection.execSQL(szSql) <= 0 || tDBConnection.GetErrorNo() != 0)
251+
{
252+
pTmpNode->m_dwResult = MRC_UNKNOW_ERROR;
253+
m_ArrFinishNode.push(pTmpNode);
254+
continue;
255+
}
256+
}
192257
#endif
193258

194259
std::map<UINT32, AwardNode>::iterator itor = mapAwardList.find(nAwardID);

0 commit comments

Comments
 (0)