• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            積木

            No sub title

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            直接上代碼
              1 #include "stdafx.h"
              2 #include <fstream>
              3 #include "Json.h"
              4 
              5 #include "ShopLogic.h"
              6 #include "src/FileCsv/WebUrlConfig.h"
              7 #include "src/support/GlobalDefine.h"
              8 
              9 using namespace std;
             10 
             11 const char *g_pcszWebDataSaveFile = "shopWebData_";
             12 
             13 ///////////////////////////////////////////////////////////////////////////////
             14 /// class CShopData
             15 /// 
             16 CShopData *getShopData() {
             17     return ChaSingleton<CShopData>::singleton();
             18 }
             19 
             20 CShopData::CShopData() {
             21 
             22 }
             23 
             24 CShopData::~CShopData() {
             25 
             26 }
             27 
             28 /// 
             29 /// Add by (jacc.kim) [2014-10-16 17:01]
             30 /// 將從web下發的商品列表數據保存到本地配置中.注意:如果列表為空,則不保存,
             31 /// 同時舊有的本地數據也不清空。
             32 /// 
             33 void CShopData::saveShopWebItems(const TShopWebDataVec &vecItems) {
             34     if (vecItems.empty()) {
             35         return ;
             36     }
             37     ShopWebDataLog("========================================================");
             38     ShopWebDataLog("準備保存寶石商店數據到本地文件.");
             39     std::string strFileName("");
             40     this->generateWebDataSaveFileName(strFileName);
             41     ShopWebDataLog("保存數據文件名稱: %s", strFileName.c_str());
             42     ofstream fout;
             43     fout.open(strFileName.c_str());
             44     if (!fout.is_open()) {
             45         ShopWebDataLog("打開或創建文件失敗");
             46         return ;
             47     }
             48     Json::Value jRoot;
             49     Json::Value jArray;
             50     Json::Value jItem;
             51     Json::Value jHttpData;
             52     Json::Value jTreasureInfo;
             53     typedef Json::Value::Int        TJInt;
             54 
             55     CShopHttpDataTotal *pWebDataItem = NULL;
             56     const TShopWebDataVec::size_type nAmount = vecItems.size();
             57     for (TShopWebDataVec::size_type nIdx = 0; nIdx < nAmount; ++nIdx) {
             58         pWebDataItem = vecItems[nIdx];
             59         if (NULL == pWebDataItem) {
             60             continue ;
             61         }
             62         // 保存 網絡商店的數據(即:CShopHttpData) 數據
             63         jHttpData["pc_id"= pWebDataItem->httpData.pc_id.c_str();
             64         jHttpData["pc_name"= pWebDataItem->httpData.pc_name.c_str();
             65         jHttpData["pc_point"= (TJInt)pWebDataItem->httpData.pc_point;
             66         jHttpData["pc_type"= pWebDataItem->httpData.pc_type.c_str();
             67         jHttpData["pc_flag"= (TJInt)pWebDataItem->httpData.pc_flag;
             68         jHttpData["pc_credit_rate"= pWebDataItem->httpData.pc_credit_rate.c_str();
             69         jHttpData["pcc_price_usd"= pWebDataItem->httpData.pcc_price_usd.c_str();
             70         jHttpData["pcc_price_cfg"= pWebDataItem->httpData.pcc_price_cfg.c_str();
             71         jHttpData["pcc_memo"= pWebDataItem->httpData.pcc_memo.c_str();
             72         jHttpData["pc_free_point"= (TJInt)pWebDataItem->httpData.pc_free_point;
             73         jHttpData["ppc_end_time"= pWebDataItem->httpData.ppc_end_time.c_str();
             74 #ifdef ORDERS_PROMOTIONS
             75         jHttpData["pcc_presen_count"= (TJInt)pWebDataItem->httpData.pcc_presen_count;
             76 #else //#ifdef ORDERS_PROMOTIONS
             77         jHttpData["pcc_presen_count"= (TJInt)0;
             78 #endif//#ifdef ORDERS_PROMOTIONS
             79 
             80         // 保存 商城財產相關信息(即:TreasureInfo) 數據
             81         jTreasureInfo["nIconStatus"= (TJInt)pWebDataItem->localData.nIconStatus;
             82         jTreasureInfo["nTextStatus"= (TJInt)pWebDataItem->localData.nTextStatus;
             83         jTreasureInfo["nBuyType"= (TJInt)pWebDataItem->localData.nBuyType;
             84         jTreasureInfo["nCostType"= (TJInt)pWebDataItem->localData.nCostType;
             85         jTreasureInfo["nBuyNumber"= (TJInt)pWebDataItem->localData.nBuyNumber;
             86         jTreasureInfo["nCostNumber"= (TJInt)pWebDataItem->localData.nCostNumber;
             87         jTreasureInfo["nCapacityPercentage"= (TJInt)pWebDataItem->localData.nCapacityPercentage;
             88         jTreasureInfo["strName"= pWebDataItem->localData.strName.c_str();
             89         jTreasureInfo["strTitleTid"= pWebDataItem->localData.strTitleTid.c_str();
             90         jTreasureInfo["strIconAddress"= pWebDataItem->localData.strIconAddress.c_str();
             91         jTreasureInfo["nCooling"= (TJInt)pWebDataItem->localData.nCooling;
             92 
             93         jItem["CShopHttpData"= jHttpData;
             94         jItem["TreasureInfo"= jTreasureInfo;
             95         jArray.append(jItem);
             96     }
             97     ShopWebDataLog("待保存的寶石商店數據: %d 條, 實際保存成功: %d 條"
             98         , static_cast<int>(nAmount), static_cast<int>(jArray.size()));
             99     jRoot["CShopHttpDataTotal"= jArray;
            100     fout << jRoot.toStyledString() << endl;
            101     fout.close();
            102 }
            103 
            104 /// 
            105 /// Add by (jacc.kim) [2014-10-16 17:02]
            106 /// 從本地加載web商品列表數據.并返回.注意:剛進入接口內部時,參數列表必被清空.
            107 /// 然后再從本地文件中加載.
            108 /// 
            109 void CShopData::getLocalShopWebItems(TShopWebDataVec &vecOutItems) {
            110     ShopWebDataLog("--------------------------------------------------------");
            111     ShopWebDataLog("準備從本地提取數據寶石商店數據.");
            112     vecOutItems.clear();
            113     std::string strFileName("");
            114     this->generateWebDataSaveFileName(strFileName);
            115     ShopWebDataLog("本地數據源文件名稱: %s", strFileName.c_str());
            116     ifstream fin;
            117     fin.open(strFileName.c_str());
            118     if (!fin.is_open()) {
            119         ShopWebDataLog("本地數據源文件不存在或已損壞,打開失敗");
            120         return ;
            121     }
            122     Json::Reader jReader;
            123     Json::Value jRoot;
            124     Json::Value jHttpData;
            125     Json::Value jTreasureInfo;
            126     if (!jReader.parse(fin, jRoot)) {
            127         ShopWebDataLog("本地數據源文件糟破壞,解析失敗");
            128         return ;
            129     }
            130     CShopHttpDataTotal *pWebDataItem = NULL;
            131     const int nAmount = static_cast<int>(jRoot["CShopHttpDataTotal"].size());
            132     for (int nIdx = 0; nIdx < nAmount; ++nIdx) {
            133         pWebDataItem = new CShopHttpDataTotal();
            134         if (NULL == pWebDataItem) {
            135             break ;
            136         }
            137         jHttpData = jRoot["CShopHttpDataTotal"][nIdx]["CShopHttpData"];
            138         pWebDataItem->httpData.pc_id            = jHttpData["pc_id"].asString();
            139         pWebDataItem->httpData.pc_name          = jHttpData["pc_name"].asString();
            140         pWebDataItem->httpData.pc_point         = jHttpData["pc_point"].asInt();
            141         pWebDataItem->httpData.pc_type          = jHttpData["pc_type"].asString();
            142         pWebDataItem->httpData.pc_flag          = jHttpData["pc_flag"].asInt();
            143         pWebDataItem->httpData.pc_credit_rate   = jHttpData["pc_credit_rate"].asString();
            144         pWebDataItem->httpData.pcc_price_usd    = jHttpData["pcc_price_usd"].asString();
            145         pWebDataItem->httpData.pcc_price_cfg    = jHttpData["pcc_price_cfg"].asString();
            146         pWebDataItem->httpData.pcc_memo         = jHttpData["pcc_memo"].asString();
            147         pWebDataItem->httpData.pc_free_point    = jHttpData["pc_free_point"].asInt();
            148         pWebDataItem->httpData.ppc_end_time     = jHttpData["ppc_end_time"].asString();
            149 #ifdef ORDERS_PROMOTIONS
            150         pWebDataItem->httpData.pcc_presen_count = jHttpData["pcc_presen_count"].asInt();
            151 #else //#ifdef ORDERS_PROMOTIONS
            152         // do nothing here..
            153 #endif//#ifdef ORDERS_PROMOTIONS
            154 
            155         jTreasureInfo = jRoot["CShopHttpDataTotal"][nIdx]["TreasureInfo"];
            156         pWebDataItem->localData.nIconStatus         = jTreasureInfo["nIconStatus"].asInt();
            157         pWebDataItem->localData.nTextStatus         = jTreasureInfo["nTextStatus"].asInt();
            158         pWebDataItem->localData.nBuyType            = jTreasureInfo["nBuyType"].asInt();
            159         pWebDataItem->localData.nCostType           = jTreasureInfo["nCostType"].asInt();
            160         pWebDataItem->localData.nBuyNumber          = jTreasureInfo["nBuyNumber"].asInt();
            161         pWebDataItem->localData.nCostNumber         = jTreasureInfo["nCostNumber"].asInt();
            162         pWebDataItem->localData.nCapacityPercentage = jTreasureInfo["nCapacityPercentage"].asInt();
            163         pWebDataItem->localData.strName             = jTreasureInfo["strName"].asString();
            164         pWebDataItem->localData.strTitleTid         = jTreasureInfo["strTitleTid"].asString();
            165         pWebDataItem->localData.strIconAddress      = jTreasureInfo["strIconAddress"].asString();
            166         pWebDataItem->localData.nCooling            = jTreasureInfo["nCooling"].asInt();
            167 
            168         vecOutItems.push_back(pWebDataItem);
            169     }
            170     ShopWebDataLog("本地數據源共: %d 條數據, 實際解析成功: %d 條"
            171         , nAmount, static_cast<int>(vecOutItems.size()));
            172     fin.close();
            173 }
            174 
            175 void CShopData::generateWebDataSaveFileName(std::string &strFileName) {
            176     strFileName = g_pcszWebDataSaveFile;
            177     CWebUrlConfig *pUrlCfg = CWebUrlConfigInstance::singleton();
            178     std::string strGameId = pUrlCfg->getWebUrlAddress("gameid");
            179     strFileName = strFileName + strGameId + ".json";
            180 }


            posted on 2014-10-21 09:49 Jacc.Kim 閱讀(3606) 評論(0)  編輯 收藏 引用 所屬分類: VC / C++
            2021精品国产综合久久| 91亚洲国产成人久久精品网址 | 99久久国产亚洲综合精品| 武侠古典久久婷婷狼人伊人| 久久精品亚洲福利| 久久人妻无码中文字幕| 久久精品国产清高在天天线| 久久AⅤ人妻少妇嫩草影院| 精品国产乱码久久久久软件| 久久国产亚洲精品麻豆| 亚洲另类欧美综合久久图片区| 久久ww精品w免费人成| 亚洲第一永久AV网站久久精品男人的天堂AV | 99久久亚洲综合精品网站| 伊人久久大香线蕉无码麻豆 | 久久国产AVJUST麻豆| 久久天堂电影网| 亚洲综合伊人久久综合| 久久99久久成人免费播放| 久久久久人妻精品一区| 伊人精品久久久久7777| 大香网伊人久久综合网2020| 久久99精品久久久久久动态图| 亚洲国产精品成人久久蜜臀 | 99久久精品免费看国产| 嫩草伊人久久精品少妇AV| 亚洲午夜福利精品久久| 久久久久国产精品嫩草影院| 精品国产一区二区三区久久| 亚洲人成精品久久久久| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 久久综合狠狠综合久久97色| 国产精品久久久久久久久| 色综合久久无码五十路人妻| 欧美亚洲国产精品久久| 久久久久99这里有精品10| 久久人妻少妇嫩草AV蜜桃| 欧美性猛交xxxx免费看久久久| 久久久久亚洲AV无码专区网站 | 久久久久亚洲国产| 99久久精品免费看国产一区二区三区|