|
|
@@ -1,7 +1,7 @@
|
|
|
#include "../pch/pch.h"
|
|
|
#include "CShopinfo.h"
|
|
|
|
|
|
-
|
|
|
+#include "../tool/CShuangpingTool.h"
|
|
|
|
|
|
CShopinfo::CShopinfo()
|
|
|
{
|
|
|
@@ -79,7 +79,7 @@ void CShopinfo::InitShopinfoByLogin(rapidjson::Value& v_data)
|
|
|
this->m_is_meishicheng = v_authority["is_meishicheng"].GetString();
|
|
|
}
|
|
|
|
|
|
-std::wstring CShopinfo::GetMachineLogoPath()
|
|
|
+std::wstring CShopinfo::GetImageTmpPathFromUrl(std::string image_url)
|
|
|
{
|
|
|
string folderPath = CLewaimaiString::UnicodeToANSI(CSystem::GetProgramDir()) + "\\tmp\\image\\";
|
|
|
std::wstring ws_folderPath = CLewaimaiString::ANSIToUnicode(folderPath);
|
|
|
@@ -90,7 +90,7 @@ std::wstring CShopinfo::GetMachineLogoPath()
|
|
|
}
|
|
|
|
|
|
//纯文件名
|
|
|
- std::string file_name = CLewaimaiString::GetPathOrURLShortName(m_machine_logo_url);
|
|
|
+ std::string file_name = CLewaimaiString::GetPathOrURLShortName(image_url);
|
|
|
|
|
|
//根据文件名,计算文件临时路径
|
|
|
wstring imagePath = ws_folderPath + CLewaimaiString::UTF8ToUnicode(file_name);
|
|
|
@@ -357,7 +357,7 @@ bool CShopinfo::UpdateOneShopinfo(std::wstring& errmsg)
|
|
|
//开始下载小票打印的logo图
|
|
|
std::string logo_url = "http://img.zhipuzi.com" + m_machine_logo_url + "!max400"; //下载小图
|
|
|
|
|
|
- wstring imagePath = GetMachineLogoPath();
|
|
|
+ wstring imagePath = GetImageTmpPathFromUrl(m_machine_logo_url);
|
|
|
if (!CSystem::IsFileExist(imagePath))
|
|
|
{
|
|
|
//图片还不存在,开始下载
|
|
|
@@ -371,5 +371,115 @@ bool CShopinfo::UpdateOneShopinfo(std::wstring& errmsg)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //开始下载副屏轮播图
|
|
|
+ if (CShuangpingTool::GetInstance()->IsShuangping())
|
|
|
+ {
|
|
|
+ std::vector<std::string> lunbo_imgs;
|
|
|
+ lunbo_imgs.clear();
|
|
|
+
|
|
|
+ m_lunbo_img_paths.clear();
|
|
|
+
|
|
|
+ std::wstring lunbo_errmsg;
|
|
|
+ bool ret = GetLunboImages(lunbo_imgs, lunbo_errmsg);
|
|
|
+ if (ret)
|
|
|
+ {
|
|
|
+ //开始下载轮播图图片到本地
|
|
|
+ for (std::vector<std::string>::iterator it = lunbo_imgs.begin(); it != lunbo_imgs.end(); it++)
|
|
|
+ {
|
|
|
+ std::string image_url = *it;
|
|
|
+
|
|
|
+ wstring imagePath = GetImageTmpPathFromUrl(image_url);
|
|
|
+ m_lunbo_img_paths.push_back(imagePath);
|
|
|
+
|
|
|
+ if (!CSystem::IsFileExist(imagePath))
|
|
|
+ {
|
|
|
+ //图片还不存在,开始下载
|
|
|
+ if (URLDownloadToFile(NULL, CLewaimaiString::UTF8ToUnicode(image_url).c_str(), imagePath.c_str(), 0, NULL) == S_OK)
|
|
|
+ {
|
|
|
+ //图片下载成功了,发个消息,更新图片
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LOG_INFO("URLDownloadToFile Fail,Error" << GetLastError());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool CShopinfo::GetLunboImages(std::vector<std::string>& images, std::wstring& errmsg)
|
|
|
+{
|
|
|
+ images.clear();
|
|
|
+
|
|
|
+ std::map<string, string> params;
|
|
|
+
|
|
|
+ std::string response;
|
|
|
+ bool ret = CZhipuziHttpClient::GetInstance()->Request("/site/getlunbo", params, response);
|
|
|
+ if (!ret)
|
|
|
+ {
|
|
|
+ errmsg = _T("网络请求出错");
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ rapidjson::Document document;
|
|
|
+ document.Parse(response.c_str());
|
|
|
+
|
|
|
+ if (document.HasParseError())
|
|
|
+ {
|
|
|
+ errmsg = _T("服务器返回数据格式错误");
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!document.HasMember("data"))
|
|
|
+ {
|
|
|
+ errmsg = _T("服务器返回数据格式错误");
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (document.HasMember("error_code"))
|
|
|
+ {
|
|
|
+ rapidjson::Value& v_errcode = document["error_code"];
|
|
|
+ int errcode = v_errcode.GetInt();
|
|
|
+ if (errcode != 0)
|
|
|
+ {
|
|
|
+ std::string s_errmsg = "response failed! message:" + string(document["error_msg"].GetString());
|
|
|
+ errmsg = CLewaimaiString::UTF8ToUnicode(s_errmsg);
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rapidjson::Value& v_errcode = document["errcode"];
|
|
|
+ int errcode = v_errcode.GetInt();
|
|
|
+ if (errcode != 0)
|
|
|
+ {
|
|
|
+ std::string s_errmsg = "response failed! message:" + string(document["errmsg"].GetString());
|
|
|
+ errmsg = CLewaimaiString::UTF8ToUnicode(s_errmsg);
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获得数据成功
|
|
|
+ rapidjson::Value& data = document["data"];
|
|
|
+
|
|
|
+ rapidjson::Value& data_img = data["img"];
|
|
|
+
|
|
|
+ for (rapidjson::SizeType i = 0; i < data_img.Size(); ++i)
|
|
|
+ {
|
|
|
+ rapidjson::Value& imgs = data_img[i];
|
|
|
+
|
|
|
+ std::string url = CLewaimaiJson::ToString(imgs["url"]);
|
|
|
+
|
|
|
+ images.push_back(url);
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|