#include "stdAfx.h" #include "BaseShopDBProc.h" #include "ShopJobQueue.h" #include "ShopMain.h" #include #include "CashShop.h" CBaseShopDBProc::CBaseShopDBProc(void) { } CBaseShopDBProc::~CBaseShopDBProc(void) { } void CBaseShopDBProc::InquireSalesVersion (CShopJobBase* job) { CInquireSalesVersion* pJob = (CInquireSalesVersion*)job; ShopProtocol::MSG_SERVER_INQUIRE_SALESVERSION msg; CListVersionInfo* info = _instance(CShopMain)->GetListVersionInfo(); if(!info) { msg.ResultCode = ERROR_CODE_DB_FAIL; } else { msg.SalesZone = info->Zone; msg.Year = info->year; msg.YearIdentity = info->yearId; } SendData(pJob, &msg, msg.dwPacketSize, "版本号查询"); } void CBaseShopDBProc::Inquire(CShopJobBase* job) { CInquireCash* pJob = (CInquireCash*)job; ShopProtocol::MSG_SERVER_INQUIRE_CASH msg(pJob->GameCode); msg.AccountSeq = pJob->AccountSeq; if(!SP_MyCashInfoProcess(pJob, msg)) { msg.ResultCode = ERROR_CODE_DB_FAIL; SendData(pJob, &msg, msg.dwPacketSize, "点劵查询"); } BILLING_LOG(0 > msg.ResultCode ? WZPUBLIC::LEVEL_ERROR : WZPUBLIC::LEVEL_INFO, "<%d> 点劵查询(%d) : %d, [%f, %f, %f]", ::GetTickCount() - pJob->dwReqTick, pJob->AccountSeq, msg.ResultCode, msg.CashPoint, msg.MileagePoint, msg.PPCashPoint ); } bool CBaseShopDBProc::SP_MyCashInfoProcess(CInquireCash* pJob, ShopProtocol::MSG_SERVER_INQUIRE_CASH& msg) { BILLING_LOG(WZPUBLIC::LEVEL_INFO, "%s ( %ld, %ld)", SP_MYCASHINFO, pJob->AccountSeq, pJob->GameCode ); if(!m_pAdoProc->SetCommond(SP_MYCASHINFO)) return false; if(!m_pAdoProc->SetInputParam("AccountSeq", pJob->AccountSeq)) return false; if(!m_pAdoProc->ExecuteEx()) return false; if(!m_pAdoProc->GetFieldValue("CashPoint", msg.CashPoint)) return false; if(!m_pAdoProc->GetFieldValue("PPCashPoint", msg.PPCashPoint)) return false; if(!m_pAdoProc->GetFieldValue("MileagePoint", msg.MileagePoint)) return false; SendData(pJob, &msg, msg.dwPacketSize, "点劵查询"); return true; } void CBaseShopDBProc::BuyProduct(CShopJobBase* job) { CBuyProduct* pJob = (CBuyProduct*)job; ShopProtocol::MSG_SERVER_BUYPRODUCT msg(pJob->GameCode); msg.AccountSeq = pJob->AccountSeq; if(!SP_BuyProductProcess(pJob, msg)) { msg.ResultCode = ERROR_CODE_DB_FAIL; } SendData(pJob, &msg, msg.dwPacketSize, "商品购买"); BILLING_LOG(0 > msg.ResultCode ? WZPUBLIC::LEVEL_ERROR : WZPUBLIC::LEVEL_INFO, "<%d> 商品购买(%d) : %d", ::GetTickCount() - pJob->dwReqTick, pJob->AccountSeq, msg.ResultCode); } bool CBaseShopDBProc::SP_BuyProductProcess(CBuyProduct* pJob, ShopProtocol::MSG_SERVER_BUYPRODUCT& msg) { USES_CONVERSION; BILLING_LOG(WZPUBLIC::LEVEL_INFO, "%s (%d, %d, %d, %d, '%s')", SP_BUYPORDUCT, pJob->AccountSeq, pJob->GameCode, pJob->PackageProductSeq, pJob->PriceSeq, W2A(pJob->CharName)); int Price = 0; CShopPackage* shop_package=NULL; if(!_instance(ConvenienceStore::CashShop)->GetShopListManager()->GetListPtr()->GetPackageListPtr()->GetValueByKey(pJob->PackageProductSeq,shop_package)) return false; if(shop_package->GetProductCount()>1) { Price = shop_package->Price; } else { CShopProduct* shop_product=NULL; CShopProductLink* shop_product_link=NULL; if(!ConvenienceStore::FindShopProduct(shop_package,pJob->PriceSeq,shop_product,shop_product_link)) return false; Price = shop_product_link->Price; } if(!m_pAdoProc->SetCommond(SP_BUYPORDUCT)) return false; if(!m_pAdoProc->SetInputParam("AccountSeq", pJob->AccountSeq)) return false; if(!m_pAdoProc->SetInputParam("PackageProductSeq", pJob->PackageProductSeq)) return false; if(!m_pAdoProc->SetInputParam("Price", Price)) return false; if(!m_pAdoProc->SetInputParam("PriceSeq", pJob->PriceSeq)) return false; if(!m_pAdoProc->ExecuteEx()) return false; if(!m_pAdoProc->GetFieldValue("ResultCode", msg.ResultCode)) return false; if(-1 == msg.ResultCode) return false; return true; } void CBaseShopDBProc::GiftProduct(CShopJobBase* job) { CGiftProduct* pJob = (CGiftProduct*)job; ShopProtocol::MSG_SERVER_GIFTPRODUCT msg(pJob->GameCode); msg.ReceiverSeq = pJob->ReceiverSeq; msg.SenderSeq = pJob->AccountSeq; if(!SP_GiftProductProcess(pJob, msg)) { msg.ResultCode = ERROR_CODE_DB_FAIL; } SendData(pJob, &msg, msg.dwPacketSize, "礼品赠送"); BILLING_LOG(0 > msg.ResultCode ? WZPUBLIC::LEVEL_ERROR : WZPUBLIC::LEVEL_INFO, "<%d> 礼品赠送(%d) : %d", ::GetTickCount() - pJob->dwReqTick, pJob->AccountSeq, msg.ResultCode); } bool CBaseShopDBProc::SP_GiftProductProcess(CGiftProduct* pJob, ShopProtocol::MSG_SERVER_GIFTPRODUCT& msg) { USES_CONVERSION; BILLING_LOG(WZPUBLIC::LEVEL_INFO, "%s (%d, '%s', %d, '%s', '%s', %d, %d, %d)", SP_GIFTPRODUCT, pJob->AccountSeq, W2A(pJob->SenderCharName), pJob->ReceiverSeq, W2A(pJob->ReceiverCharName), W2A(pJob->SendMessage), pJob->GameCode, pJob->PackageProductSeq, pJob->PriceSeq); if(!m_pAdoProc->SetCommond(SP_GIFTPRODUCT)) return false; if(!m_pAdoProc->SetInputParam("SendAccountSeq", pJob->AccountSeq)) return false; if(!m_pAdoProc->SetInputParam("SendCharName", pJob->SenderCharName)) return false; if(!m_pAdoProc->SetInputParam("GetAccountSeq", pJob->ReceiverSeq)) return false; if(!m_pAdoProc->SetInputParam("GetCharName", pJob->ReceiverCharName)) return false; if(!m_pAdoProc->SetInputParam("SendMessage", pJob->SendMessage)) return false; if(!m_pAdoProc->SetInputParam("GameCode", pJob->GameCode)) return false; if(!m_pAdoProc->SetInputParam("PackageProductSeq", pJob->PackageProductSeq)) return false; if(!m_pAdoProc->SetInputParam("PriceSeq", pJob->PriceSeq)) return false; if(!m_pAdoProc->ExecuteEx()) return false; if(!m_pAdoProc->GetFieldValue("ResultCode", msg.ResultCode)) return false; if(-1 == msg.ResultCode) return true; return true; } void CBaseShopDBProc::StorageList(CShopJobBase* job) { CStorageList* pJob = (CStorageList*)job; ShopProtocol::MSG_SERVER_STORAGELIST msg; msg.ResultCode = 0; msg.AccountSeq = pJob->AccountSeq; if(!SP_StorageList(pJob, msg)) { msg.ResultCode = ERROR_CODE_DB_FAIL; SendData(pJob, &msg, msg.dwPacketSize, "保管盒查询"); } BILLING_LOG(0 > msg.ResultCode ? WZPUBLIC::LEVEL_ERROR : WZPUBLIC::LEVEL_INFO, "<%d> 保管盒查询(%d) : %d, [%d]", ::GetTickCount() - pJob->dwReqTick, pJob->AccountSeq, msg.ResultCode, msg.ListCount); } bool CBaseShopDBProc::SP_StorageList(CStorageList* pJob, ShopProtocol::MSG_SERVER_STORAGELIST& msg) { bool GiftMsgFlag = true; char StorageType = 'A'; int NowPage = 1; int PageSize = 100; BILLING_LOG(WZPUBLIC::LEVEL_INFO, "%s (%d, %d, '%c', %d, %d, %d)", SP_STORAGELIST, pJob->AccountSeq, pJob->GameCode, StorageType, GiftMsgFlag ? 1 : 0, NowPage, PageSize); if(!m_pAdoProc->SetCommond(SP_STORAGELIST)) return false; if(!m_pAdoProc->SetInputParam("AccountSeq", pJob->AccountSeq)) return false; if(!m_pAdoProc->SetInputParam("StorageType", StorageType)) return false; if(!m_pAdoProc->ExecuteEx()) return false; std::vector StorageList; if(m_pAdoProc->GetRecordCount()) { do { ShopProtocol::STStorage Storage; if(!m_pAdoProc->GetFieldValue("StorageSeq", Storage.StorageSeq)) continue; if(!m_pAdoProc->GetFieldValue("PriceSeq", Storage.PriceSeq)) continue; if(!m_pAdoProc->GetFieldValue("PackageProductSeq", Storage.PackageProductSeq)) continue; if(!m_pAdoProc->GetFieldValue("DeleteDate", Storage.DeleteDate)) continue; StorageList.push_back(Storage); } while(m_pAdoProc->NextRecord()); } msg.ListCount = StorageList.size(); int nListSize = msg.ListCount * sizeof(ShopProtocol::STStorage); msg.dwPacketSize = msg.PackHeader + nListSize; WBANetwork::Stream stm(msg.dwPacketSize); ShopProtocol::STStorage* pStorageList = (ShopProtocol::STStorage*)(stm.GetBuffer() + msg.PackHeader); int i = 0; std::vector::iterator itr; for(itr = StorageList.begin(), i = 0 ; itr != StorageList.end() ; itr++) { pStorageList[i++] = *itr; } stm.Write(&msg, msg.PackHeader); SendData(pJob, stm.GetBuffer(), msg.dwPacketSize, "保管盒查询"); return true; } void CBaseShopDBProc::StorageUse(CShopJobBase* job) { CUseStorage* pJob = (CUseStorage*)job; if(!SP_StorageUse(pJob)) { BILLING_LOG(WZPUBLIC::LEVEL_INFO, "保管盒物品领取失败!账号GUILD=%d,保管盒ID=%d", pJob->AccountSeq, pJob->StorageSeq ); } } void CBaseShopDBProc::StorageUseAll(CShopJobBase* job) { CUseStorage* pJob = (CUseStorage* )job; USES_CONVERSION; long ResultCode = 0; BILLING_LOG(WZPUBLIC::LEVEL_INFO, "%s (%d)", SP_STORAGEUSEALL,job->AccountSeq); if(!m_pAdoProc->SetCommond(SP_STORAGEUSEALL)) goto FAILD; if(!m_pAdoProc->SetInputParam("AccountSeq",job->AccountSeq)) goto FAILD; if(!m_pAdoProc->ExecuteEx()) goto FAILD; if(!m_pAdoProc->GetFieldValue("ResultCode",ResultCode)) goto FAILD; if(0 != ResultCode) goto FAILD; BYTE EmptySlotNum = pJob->EmptySlotNum; if(m_pAdoProc->GetRecordCount()) { do { int PackageSeq = 0; int PriceSeq = 0; int StorageSeq = 0; if(!m_pAdoProc->GetFieldValue("PackageProductSeq", PackageSeq)) goto FAILD; if(!m_pAdoProc->GetFieldValue("PriceSeq", PriceSeq)) goto FAILD; if(!m_pAdoProc->GetFieldValue("StorageSeq",StorageSeq)) goto FAILD; ConvenienceStore::ProductItem* productitem = _instance(ConvenienceStore::CashShop)->GetProduct(PackageSeq); if(productitem->is_package()) { if(productitem->GetShopPackage()->GetProductCount()>EmptySlotNum) { ShopProtocol::MSG_SERVER_STORAGEUSE_ONE msg; msg.AccountSeq = pJob->AccountSeq; msg.StorageSeq = StorageSeq; msg.ResultCode = -10; SendData(job, &msg, msg.dwPacketSize, "保管盒物品领取空间不足"); continue; } } EmptySlotNum -= productitem->GetShopPackage()->GetProductCount(); UseStorage(productitem,(CUseStorage*)job,PriceSeq); } while(m_pAdoProc->NextRecord()); } return; FAILD: ShopProtocol::MSG_SERVER_STORAGEUSE_ONE msg; msg.ResultCode = ResultCode; SendData(job, &msg, msg.dwPacketSize, "保管盒物品领取"); } bool CBaseShopDBProc::SP_StorageUse(CUseStorage* pJob) { in_addr addr; addr.S_un.S_addr = pJob->AccessIP; USES_CONVERSION; long ResultCode = 0; BILLING_LOG(WZPUBLIC::LEVEL_INFO, "%s (%d, %d, '%s', %d,'%s') ip:%d", SP_STORAGEUSE, pJob->AccountSeq, pJob->GameCode, inet_ntoa(addr), pJob->StorageSeq, W2A(pJob->CharName), pJob->AccessIP); if(!m_pAdoProc->SetCommond(SP_STORAGEUSE)) return false; if(!m_pAdoProc->SetInputParam("AccountSeq", pJob->AccountSeq)) return false; if(!m_pAdoProc->SetInputParam("StorageSeq", pJob->StorageSeq)) return false; if(!m_pAdoProc->ExecuteEx()) return false; if(!m_pAdoProc->GetFieldValue("ResultCode", ResultCode)) return false; if(0 != ResultCode) { ShopProtocol::MSG_SERVER_STORAGEUSE_ONE msg; msg.ResultCode = ResultCode; SendData(pJob, &msg, msg.dwPacketSize, "保管盒物品领取"); return false; } int PackageSeq = 0; int PriceSeq = 0; if(!m_pAdoProc->GetFieldValue("PackageProductSeq", PackageSeq)) return false; if(!m_pAdoProc->GetFieldValue("PriceSeq", PriceSeq)) return false; ConvenienceStore::ProductItem* productitem = _instance(ConvenienceStore::CashShop)->GetProduct(PackageSeq); if(productitem->GetShopPackage()->GetProductCount()>pJob->EmptySlotNum) { ShopProtocol::MSG_SERVER_STORAGEUSE_ONE msg; msg.AccountSeq = pJob->AccountSeq; msg.StorageSeq = pJob->StorageSeq; msg.ResultCode = -10; SendData(pJob, &msg, msg.dwPacketSize, "保管盒物品领取空间不足"); return false; } return UseStorage(productitem,pJob,PriceSeq); } bool CBaseShopDBProc::UseStorage(ConvenienceStore::ProductItem* productitem,CUseStorage* pJob,int PriceSeq) { if(!productitem) return false; if(productitem->is_package()) { ShopProtocol::MSG_SERVER_STORAGEUSE_MULIT msg; std::vector ProductInfoList; std::vector::iterator begin = productitem->GetProductInfoList().begin(); std::vector::iterator end = productitem->GetProductInfoList().end(); for(;begin!=end;++begin) { ShopProtocol::MSG_SERVER_STORAGEUSE_ONE info; info.StorageSeq = pJob->StorageSeq; info.AccountSeq = pJob->AccountSeq; info.ItemProperty.PropertySeq =begin->GetPriceProperty().GetProductLink()->PropertySeq; info.ItemProperty.Value = atoi(begin->GetPriceProperty().GetProductLink()->Value); info.InGameProductID = begin->GetPriceProperty().GetProductLink()->InGameProductID; info.ProductSeq = begin->GetPriceProperty().GetProductLink()->ProductSeq; ProductInfoList.push_back(info); } msg.iListCount = ProductInfoList.size(); int nListSize = msg.iListCount * sizeof(ShopProtocol::MSG_SERVER_STORAGEUSE_ONE); msg.dwPacketSize = msg.PackHeader + nListSize; WBANetwork::Stream stm(msg.dwPacketSize); ShopProtocol::MSG_SERVER_STORAGEUSE_ONE* pStorageList = (ShopProtocol::MSG_SERVER_STORAGEUSE_ONE*)(stm.GetBuffer() + msg.PackHeader); int i = 0; std::vector::iterator itr; for(itr = ProductInfoList.begin(), i = 0 ; itr != ProductInfoList.end() ; itr++) { pStorageList[i++] = *itr; } stm.Write(&msg, msg.PackHeader); SendData(pJob, stm.GetBuffer(), msg.dwPacketSize, "保管盒物品领取"); return true; } else { ShopProtocol::MSG_SERVER_STORAGEUSE_ONE msg; ConvenienceStore::ProductInfo * productInfo = productitem->GetProductInfo(PriceSeq); if(!productInfo) return false; msg.InGameProductID = productInfo->GetPriceProperty().GetProductLink()->InGameProductID; msg.ProductSeq = productInfo->GetPriceProperty().GetProductLink()->ProductSeq; msg.StorageSeq = pJob->StorageSeq; msg.AccountSeq = pJob->AccountSeq; msg.ItemProperty.PropertySeq = productInfo->GetPriceProperty().GetProductLink()->PropertySeq; msg.ItemProperty.Value = atoi(productInfo->GetPriceProperty().GetProductLink()->Value); SendData(pJob, &msg, msg.dwPacketSize, "保管盒物品领取"); return true; } BILLING_LOG(WZPUBLIC::LEVEL_ERROR, "保管盒物品领取未知的商品类型 (%d)(%s)", pJob->AccountSeq, productitem->GetShopPackage()->PackageProductName ); return false; } void CBaseShopDBProc::UseStorageRollBack(CShopJobBase* pJob) { CUseStorage* job = (CUseStorage*)pJob; USES_CONVERSION; long ResultCode = 0; BILLING_LOG(WZPUBLIC::LEVEL_INFO, "%s (%d, %d)", SP_STORAGEUSEROLLBACK, job->AccountSeq, job->StorageSeq); if(!m_pAdoProc->SetCommond(SP_STORAGEUSEROLLBACK)) goto FAILD; if(!m_pAdoProc->SetInputParam("AccountSeq", job->AccountSeq)) goto FAILD; if(!m_pAdoProc->SetInputParam("StorageSeq", job->StorageSeq)) goto FAILD; if(!m_pAdoProc->ExecuteEx()) goto FAILD; if(!m_pAdoProc->GetFieldValue("ResultCode", ResultCode)) goto FAILD; if(0 != ResultCode) goto FAILD; BILLING_LOG(WZPUBLIC::LEVEL_INFO, "商品回档成功! (%d, %d)", job->AccountSeq, job->StorageSeq); return; FAILD: BILLING_LOG(WZPUBLIC::LEVEL_ERROR, "商品回档失败! (%d, %d)", job->AccountSeq, job->StorageSeq); } void CBaseShopDBProc::SendData(CShopJobBase * pJob, void* buffer, DWORD size, char* szMsg) { if(((CShopSession*)pJob->pSession)->SendData(buffer, size)) { BILLING_LOG(WZPUBLIC::LEVEL_INFO, "<%d> 发送成功 (%s)", ::GetTickCount() - pJob->dwReqTick, szMsg); } else { BILLING_LOG(WZPUBLIC::LEVEL_ERROR, "<%d> 发送失败 (%s)", ::GetTickCount() - pJob->dwReqTick, szMsg); } }