Browse Source

继续做副屏

张洋 3 years ago
parent
commit
6d2682e9a2

+ 14 - 11
bin/Win32/Debug/zhipuzi_pos_windows/skin/fuping_wnd.xml

@@ -3,16 +3,12 @@
 	<Font id="0" name="微软雅黑" size="22" />
 	<Font id="1" name="微软雅黑" size="32" />
 	
-	<VerticalLayout bkimage="shoukuan_bkg.png" >
-		<HorizontalLayout name="shoukuan_title_bkg" height="44" bkcolor="0xFF3CB371">
-			<Label name="memo_dlg_title" text="智铺子收银系统" height="44" align="left" valign="center" padding="0,0,0,0" textcolor="#FFFFFFFF" font="2"/>
-		</HorizontalLayout>		
-		
+	<VerticalLayout bkimage="shoukuan_bkg.png" >		
 		<HorizontalLayout>
 			<VerticalLayout width="400">
 				<HorizontalLayout height="80">
 					<Label text="欢迎光临" font="1" align="center"></Label>
-				</HorizontalLayout>
+				</HorizontalLayout>				
 				
 				<List name="list_diandan_cart" padding="0,10,0,0" itemlinecolor="#FF000000" vscrollbar="true">
 					<ListHeader inset="10,0,0,0"/>
@@ -20,6 +16,12 @@
 					<ListHeaderItem text="数量" width="80" align="center" />
 					<ListHeaderItem text="金额" width="80" align="center" />
 				</List>
+				
+				<Control height="1" bkcolor="#FFEBE8E8"></Control>
+				
+				<VerticalLayout height="200">
+					<Label text="应付:0元" font="0" align="right"></Label>
+				</VerticalLayout>
 			</VerticalLayout>
 			
 			<Control width="1" bkcolor="#FFEBE8E8"></Control>
@@ -28,12 +30,13 @@
 				<HorizontalLayout>
 					<Control name="lunbo_image"></Control>
 				</HorizontalLayout>
-				
-				<Control height="1" bkcolor="#FFEBE8E8"></Control>
-				
-				<HorizontalLayout height="200">
-				</HorizontalLayout>
 			</VerticalLayout>
 		</HorizontalLayout>
+		
+		<HorizontalLayout name="shoukuan_title_bkg" height="52" bkcolor="0xFF3CB371">
+			<Control></Control>
+			<Control bkimage="main_logo.png" width="179" height="46" padding="0,3,0,3"></Control>
+			<Control></Control>
+		</HorizontalLayout>	
 	</VerticalLayout>
 </Window>

+ 32 - 0
zhipuzi_pos_windows/helper/CLewaimaiJson.cpp

@@ -101,3 +101,35 @@ std::string CLewaimaiJson::ParamMapToJsonstring(std::map<string, string> param)
 
 	return result;
 }
+
+std::string CLewaimaiJson::ToString(const rapidjson::Value& valObj)
+{
+	if (valObj.IsString())
+	{
+		return valObj.GetString();
+	}
+	else if (valObj.IsInt())
+	{
+		return to_string(valObj.GetInt());
+	}
+	else
+	{
+		return "";
+	}
+}
+
+int CLewaimaiJson::ToInt(const rapidjson::Value& valObj)
+{
+	if (valObj.IsString())
+	{
+		return atoi(std::string(valObj.GetString()).c_str());
+	}
+	else if (valObj.IsInt())
+	{
+		return valObj.GetInt();
+	}
+	else
+	{
+		return 0;
+	}
+}

+ 3 - 0
zhipuzi_pos_windows/helper/CLewaimaiJson.h

@@ -32,5 +32,8 @@ public:
 
 	//把一个map转化成json字符串,map的key是json的名字,map的value是json的value
 	static std::string ParamMapToJsonstring(std::map<string, string> param);
+
+	static std::string ToString(const rapidjson::Value& valObj);
+	static int ToInt(const rapidjson::Value& valObj);
 };
 

+ 5 - 0
zhipuzi_pos_windows/page/CDiandanPageUI.cpp

@@ -27,6 +27,8 @@
 
 #include "../print/CPosPrinter.h"
 
+#include "../tool/CShuangpingTool.h"
+
 CDiandanPageUI::CDiandanPageUI()
 {
 }
@@ -1682,6 +1684,9 @@ void CDiandanPageUI::UpdateJiesuanInfo()
 
 	CLabelUI* pYingshou = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_total_yingshou")));
 	pYingshou->SetText((L"应收金额:" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(cur_price, 2)) + L"元").c_str());
+
+	//同步更新副屏的显示内容
+	CShuangpingTool::GetInstance()->UpdateShow(m_cur_diandan_order);
 }
 
 void CDiandanPageUI::ClickFoodAction()

+ 2 - 2
zhipuzi_pos_windows/print/CPosPrinterData.cpp

@@ -31,7 +31,7 @@ std::string CPosPrinterData::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 		//判断是否打印顶部logo
 		if (CShopinfo::GetInstance()->m_machine_logo_open == "1")
 		{
-			std::wstring imagePath = CShopinfo::GetInstance()->GetMachineLogoPath();
+			std::wstring imagePath = CShopinfo::GetInstance()->GetImageTmpPathFromUrl(CShopinfo::GetInstance()->m_machine_logo_url);
 
 			POS_OutBmp(imagePath);
 			POS_FeedLine();
@@ -1085,7 +1085,7 @@ std::string CPosPrinterData::PrintDiandanOrderShouyin(CDiandanOrder& order)
 		//判断是否打印顶部logo
 		if (CShopinfo::GetInstance()->m_machine_logo_open == "1")
 		{
-			std::wstring imagePath = CShopinfo::GetInstance()->GetMachineLogoPath();
+			std::wstring imagePath = CShopinfo::GetInstance()->GetImageTmpPathFromUrl(CShopinfo::GetInstance()->m_machine_logo_url);
 
 			POS_OutBmp(imagePath);
 			POS_FeedLine();

+ 10 - 9
zhipuzi_pos_windows/tool/CShuangpingTool.cpp

@@ -1,8 +1,6 @@
 #include "../pch/pch.h"
 #include "CShuangpingTool.h"
 
-#include "../wnd/CFupingWnd.h"
-
 CShuangpingTool::CShuangpingTool()
 {
 }
@@ -77,25 +75,28 @@ void CShuangpingTool::Init()
 	}
 
 	//创建并初始化副屏窗口
-	CFupingWnd* pFuping = new CFupingWnd();
-	if (pFuping == NULL)
+	m_pFuping = new CFupingWnd();
+	if (m_pFuping == NULL)
 	{
 		m_is_shuangping = false;
 		LOG_INFO("副屏窗口创建失败!");
 		return;
 	}
 
-	pFuping->Create(NULL, _T("智铺子收银系统副屏"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
-	pFuping->SetIcon(IDI_ICON_DUILIB);
+	m_pFuping->Create(NULL, _T("智铺子收银系统副屏"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
+	m_pFuping->SetIcon(IDI_ICON_DUILIB);
 
-	::MoveWindow(pFuping->GetHWND(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, true);
-	pFuping->ShowWindow(true);
+	::MoveWindow(m_pFuping->GetHWND(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, true);
+	m_pFuping->ShowWindow(true);
 }
 
-void CShuangpingTool::UpdateShow()
+void CShuangpingTool::UpdateShow(CDiandanOrder& order)
 {
 	if (m_is_shuangping == false)
 	{
+		//如果都没双屏,就不处理了
 		return;
 	}
+
+	
 }

+ 7 - 2
zhipuzi_pos_windows/tool/CShuangpingTool.h

@@ -1,5 +1,8 @@
 #pragma once
 
+#include "../wnd/CFupingWnd.h"
+#include "../zhipuzi/CDiandanOrder.h"
+
 class CShuangpingTool
 {
 public:
@@ -10,11 +13,11 @@ public:
 		return &instance;
 	}
 
-	//初始化副屏,对副屏情况进行判断
+	//初始化副屏,对副屏情况进行判断(程序刚启动马上就执行)
 	void Init();
 
 	//刷新副屏显示
-	void UpdateShow();
+	void UpdateShow(CDiandanOrder& order);
 
 private:
 	CShuangpingTool();
@@ -27,5 +30,7 @@ private:
 	bool m_is_shuangping = false;
 
 	RECT m_fuping_rect;
+
+	CFupingWnd* m_pFuping = NULL;
 };
 

+ 49 - 0
zhipuzi_pos_windows/wnd/CFupingWnd.cpp

@@ -134,7 +134,56 @@ void CFupingWnd::Notify(TNotifyUI& msg)
 	
 }
 
+//刚启动程序初始化副屏窗口的时候执行,app生命周期只执行一次
 void CFupingWnd::Init()
 {
+	//启动轮播图展示任务
+	std::thread(&CFupingWnd::HandleFupingImage, this).detach();
+}
+
+void CFupingWnd::HandleFupingImage()
+{
+	while (true)
+	{
+		std::vector<std::wstring> lunbo_img_paths = CShopinfo::GetInstance()->m_lunbo_img_paths;
+
+		if (lunbo_img_paths.size() == 0)
+		{
+			//有可能后台没设置轮播图,有可能还没请求到后台最新数据,等待
+			CSystem::my_sleep(2);
+
+			continue;
+		}
+
+		if (m_curImageNum > lunbo_img_paths.size() - 1)
+		{
+			m_curImageNum = 0;
+		}
 
+		std::wstring image_path = lunbo_img_paths[m_curImageNum];
+
+		//判断图片是否存在
+		if (!CSystem::IsFileExist(image_path))
+		{
+			//轮播图的图片还未下载好
+			CSystem::my_sleep(3);
+
+			//2秒后还没下载好,处理下一张
+			m_curImageNum++;
+
+			continue;
+		}
+
+		//轮播图的图片已经下载好了,那么就直接渲染
+		CControlUI* imageControl = static_cast<CControlUI*>(m_pm.FindControl(L"lunbo_image"));
+		imageControl->SetBkImage(image_path.c_str());
+
+		//等待2秒钟,换下一张
+		CSystem::my_sleep(3);
+
+		//2秒后还没下载好,处理下一张
+		m_curImageNum++;
+
+		continue;
+	}
 }

+ 5 - 0
zhipuzi_pos_windows/wnd/CFupingWnd.h

@@ -56,7 +56,12 @@ public:
 
 	LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
 
+	void HandleFupingImage();
+
 public:
 	CPaintManagerUI m_pm;
+
+private:
+	size_t m_curImageNum = 0;
 };
 

+ 114 - 4
zhipuzi_pos_windows/zhipuzi/CShopinfo.cpp

@@ -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;
 }

+ 7 - 1
zhipuzi_pos_windows/zhipuzi/CShopinfo.h

@@ -54,10 +54,13 @@ public:
 	//处理登录接口返回的店铺信息
 	void InitShopinfoByLogin(rapidjson::Value& v_data);
 
-	std::wstring GetMachineLogoPath();
+	//通过图片的路径,计算出图片在本地存储的路径
+	std::wstring GetImageTmpPathFromUrl(std::string image_url);
 
 	bool UpdateOneShopinfo(std::wstring& errmsg);
 
+	bool GetLunboImages(std::vector<std::string>& images, std::wstring& errmsg);
+
 public:
 	//当前系统版本 1餐饮版 2零售版
 	std::string m_version_type;
@@ -178,4 +181,7 @@ public:
 	std::string m_is_giftcard_pay_open;
 	std::string m_is_food_town_card_pay_open;
 	std::string m_is_open_fulika_pay;
+
+	//这个存放的是轮播图副屏在本地对应的文件路径
+	std::vector<std::wstring> m_lunbo_img_paths;
 };