Jelajahi Sumber

打印功能的改造完成

张洋 4 tahun lalu
induk
melakukan
97849e0a18
41 mengubah file dengan 1182 tambahan dan 1141 penghapusan
  1. 8 11
      bin/Win32/Debug/zhipuzi_pos_windows/skin/diandan_nature_wnd.xml
  2. 4 4
      bin/Win32/Debug/zhipuzi_pos_windows/skin/diandan_page.xml
  3. TEMPAT SAMPAH
      bin/Win32/Debug/zhipuzi_pos_windows/skin/gouwuka_icon.png
  4. TEMPAT SAMPAH
      bin/Win32/Debug/zhipuzi_pos_windows/skin/meishicheng_icon.png
  5. TEMPAT SAMPAH
      bin/Win32/Debug/zhipuzi_pos_windows/skin/num_bkg.png
  6. 0 0
      zhipuzi_pos_windows/helper/CComHelper.cpp
  7. 0 0
      zhipuzi_pos_windows/helper/CComHelper.h
  8. 0 0
      zhipuzi_pos_windows/helper/CExceptionDmp.cpp
  9. 0 0
      zhipuzi_pos_windows/helper/CExceptionDmp.h
  10. 0 0
      zhipuzi_pos_windows/helper/CLewaimaiLog.cpp
  11. 0 0
      zhipuzi_pos_windows/helper/CLewaimaiLog.h
  12. 0 0
      zhipuzi_pos_windows/helper/CLewaimaiTime.cpp
  13. 0 0
      zhipuzi_pos_windows/helper/CLewaimaiTime.h
  14. 0 0
      zhipuzi_pos_windows/helper/CSerialPort.cpp
  15. 0 0
      zhipuzi_pos_windows/helper/CSerialPort.h
  16. 3 0
      zhipuzi_pos_windows/helper/readme.txt
  17. 4 258
      zhipuzi_pos_windows/network/CMessagePush.cpp
  18. 2 38
      zhipuzi_pos_windows/network/CMessagePush.h
  19. 17 44
      zhipuzi_pos_windows/page/CDiandanPageUI.cpp
  20. 3 0
      zhipuzi_pos_windows/page/CDiandanPageUI.h
  21. 5 9
      zhipuzi_pos_windows/page/CSettingPageUI.cpp
  22. 4 1
      zhipuzi_pos_windows/page/CWaimaiOrderInfoPageUI.cpp
  23. 5 1
      zhipuzi_pos_windows/page/CWaimaiOrderListPageUI.cpp
  24. 1 0
      zhipuzi_pos_windows/pch/pch.cpp
  25. 2 2
      zhipuzi_pos_windows/pch/pch.h
  26. 84 0
      zhipuzi_pos_windows/print/CPosPrinter.cpp
  27. 24 0
      zhipuzi_pos_windows/print/CPosPrinter.h
  28. 61 611
      zhipuzi_pos_windows/tool/CPosPrinter.cpp
  29. 73 0
      zhipuzi_pos_windows/print/CPosPrinterData.h
  30. 705 0
      zhipuzi_pos_windows/print/CPosPrinterQueue.cpp
  31. 91 0
      zhipuzi_pos_windows/print/CPosPrinterQueue.h
  32. 0 107
      zhipuzi_pos_windows/tool/CPosPrinter.h
  33. 1 2
      zhipuzi_pos_windows/tool/CSqlite3.h
  34. 1 0
      zhipuzi_pos_windows/tool/readme.txt
  35. 1 1
      zhipuzi_pos_windows/wnd/CChengzhongWnd.h
  36. 1 2
      zhipuzi_pos_windows/wnd/CDiandanNatureWnd.cpp
  37. 7 0
      zhipuzi_pos_windows/wnd/CMainWnd.cpp
  38. 0 1
      zhipuzi_pos_windows/wnd/CMainWnd.h
  39. 3 1
      zhipuzi_pos_windows/zhipuzi/CDiandanOrder.h
  40. 20 12
      zhipuzi_pos_windows/zhipuzi_pos_windows.vcxproj
  41. 52 36
      zhipuzi_pos_windows/zhipuzi_pos_windows.vcxproj.filters

+ 8 - 11
bin/Win32/Debug/zhipuzi_pos_windows/skin/diandan_nature_wnd.xml

@@ -1,21 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<Window size="800,600" caption="0,0,0,36" roundcorner="4,4" >
-	<VerticalLayout bkimage="file='Dialog_BG1.png' corner='4,50,4,4'">
-		<HorizontalLayout height="40" inset="10,2,10,0">
-			<Label name="diandan_nature_title" text="选择商品属性" width="150" />
-			<Control />
+<Window size="800,600" caption="0,0,0,44" roundcorner="4,4" >
+	<VerticalLayout bkimage="file='Dialog_BG1.png' corner='4,50,4,4'">		
+		<HorizontalLayout name="shoukuan_title_bkg" height="44" bkcolor="0xFF3CB371">
+			<Label name="diandan_nature_title" text="选择商品属性" height="44" align="center" valign="center" padding="0,0,0,0" textcolor="#FFFFFFFF" font="2"/>
+			<Button name="closebtn" padding="0,13,15,0" width="16" height="16" tooltip="关闭" normalimage="file='close_normal.png'" hotimage="file='close_hover.png'" pushedimage="file='close_normal.png'"/>
 		</HorizontalLayout>
-		<VerticalLayout inset="15,0,15,15" vscrollbar="true" >
-			<Control height="20" />
 			
-			<VerticalLayout name="diandan_nature_layout" height="418" vscrollbar="true">
-				
-			</VerticalLayout>
+		<VerticalLayout inset="15,0,15,15" name="diandan_nature_layout" vscrollbar="true">
+			
 		</VerticalLayout>
 		
 		<HorizontalLayout height="56" valign="center" padding="0,30,0,20">
 			<Control />
-			<Button name="diandan_nature_save" align="center" width="280" height="44" text="保存" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />
+			<Button name="diandan_nature_save" align="center" width="280" height="44" text="选好了" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />
 			<Control />
 		</HorizontalLayout>
 	</VerticalLayout>

+ 4 - 4
bin/Win32/Debug/zhipuzi_pos_windows/skin/diandan_page.xml

@@ -55,7 +55,7 @@
 						<Button name="btn_diandan_cundan" width="90" height="38" padding="15,50,15,0" text="存单" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />
 						<Button name="btn_diandan_qudan" width="90" height="38" padding="15,15,15,0" text="取单" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />
 						
-						<Label name="diandan_page_qudan_num" text="10" mouse="false" width="20" height="20" textcolor="#FFFFFFFF" bkcolor="#FFFF0000" float="true" pos="85,450,105,470" bordercolor="#FFFF0000" bordersize="2" borderround="15,15" borderstyle="3"></Label>
+						<Label name="diandan_page_qudan_num" text="10" mouse="false" width="19" height="19" align="center" textcolor="#FFFFFFFF" bkimage="num_bkg.png" float="true" pos="85,450,104,469" bordercolor="#FFFF0000" bordersize="0"></Label>
 						
 						<Button name="btn_diandan_zhengdanbeizhu" width="90" height="38" padding="15,15,15,0" text="整单备注" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />
 					</VerticalLayout>
@@ -87,7 +87,7 @@
 						<Label text="更多支付" width="120" height="35" font="2" float="true" pos="440,35,560,70" mouse="false"></Label>
 					</HorizontalLayout>
 					
-					<Button visible="false" name="btn_diandan_jixujiacai" text="继续加菜" height="55" width="510" padding="14,20,0,15" textcolor="#FFFFFFFF"></Button>
+					<Button visible="false" name="btn_diandan_jixujiacai" text="继续点单" height="55" width="510" padding="14,20,0,15" textcolor="#FFFFFFFF"></Button>
 				</VerticalLayout>
 			</VerticalLayout>
 			
@@ -225,13 +225,13 @@
 						
 						<HorizontalLayout name="diandan_jiesuan_zhifufangshi_gouwuka" width="182" hegiht="82" float="true" pos="20,120,200,200">
 							<Button name="diandan_jiesuan_zhifufangshi_gouwuka_btn" text="" heiht="80" width="180" padding="0,0,0,0" textcolor="#FF999999" normalimage="" hotimage="" pushedimage="" bordersize="1" bordercolor="#FFC1C1C1" bkcolor="#FFF7F7F7"></Button>
-							<Control name="zhifu_icon" bkimage="fulika_icon.png" width="30" height="30" float="true" pos="73,10,103,40" mouse="false"></Control>
+							<Control name="zhifu_icon" bkimage="gouwuka_icon.png" width="34" height="28" float="true" pos="73,10,107,38" mouse="false"></Control>
 							<Label name="zhifu_name" text="购物卡" width="180" height="35" font="2" float="true" pos="65,35,245,70" mouse="false"></Label>
 						</HorizontalLayout>
 						
 						<HorizontalLayout name="diandan_jiesuan_zhifufangshi_meishicheng" width="182" hegiht="82" float="true" pos="220,120,400,200">
 							<Button name="diandan_jiesuan_zhifufangshi_meishicheng_btn" text="" heiht="80" width="180" padding="0,0,0,0" textcolor="#FF999999" normalimage="" hotimage="" pushedimage="" bordersize="1" bordercolor="#FFC1C1C1" bkcolor="#FFF7F7F7"></Button>
-							<Control name="zhifu_icon" bkimage="fulika_icon.png" width="30" height="30" float="true" pos="73,10,103,40" mouse="false"></Control>
+							<Control name="zhifu_icon" bkimage="meishicheng_icon.png" width="37" height="27" float="true" pos="73,10,110,37" mouse="false"></Control>
 							<Label name="zhifu_name" text="美食城临时卡" width="180" height="35" font="2" float="true" pos="45,35,225,70" mouse="false"></Label>
 						</HorizontalLayout>
 						

TEMPAT SAMPAH
bin/Win32/Debug/zhipuzi_pos_windows/skin/gouwuka_icon.png


TEMPAT SAMPAH
bin/Win32/Debug/zhipuzi_pos_windows/skin/meishicheng_icon.png


TEMPAT SAMPAH
bin/Win32/Debug/zhipuzi_pos_windows/skin/num_bkg.png


zhipuzi_pos_windows/tool/CComHelper.cpp → zhipuzi_pos_windows/helper/CComHelper.cpp


zhipuzi_pos_windows/tool/CComHelper.h → zhipuzi_pos_windows/helper/CComHelper.h


zhipuzi_pos_windows/tool/CExceptionDmp.cpp → zhipuzi_pos_windows/helper/CExceptionDmp.cpp


zhipuzi_pos_windows/tool/CExceptionDmp.h → zhipuzi_pos_windows/helper/CExceptionDmp.h


zhipuzi_pos_windows/tool/CLewaimaiLog.cpp → zhipuzi_pos_windows/helper/CLewaimaiLog.cpp


zhipuzi_pos_windows/tool/CLewaimaiLog.h → zhipuzi_pos_windows/helper/CLewaimaiLog.h


zhipuzi_pos_windows/tool/CLewaimaiTime.cpp → zhipuzi_pos_windows/helper/CLewaimaiTime.cpp


zhipuzi_pos_windows/tool/CLewaimaiTime.h → zhipuzi_pos_windows/helper/CLewaimaiTime.h


zhipuzi_pos_windows/tool/CSerialPort.cpp → zhipuzi_pos_windows/helper/CSerialPort.cpp


zhipuzi_pos_windows/tool/CSerialPort.h → zhipuzi_pos_windows/helper/CSerialPort.h


+ 3 - 0
zhipuzi_pos_windows/helper/readme.txt

@@ -0,0 +1,3 @@
+helper目录下,主要处理一些与业务逻辑无关的辅助类封装
+
+与业务逻辑有关的清不要放这里

+ 4 - 258
zhipuzi_pos_windows/network/CMessagePush.cpp

@@ -1,13 +1,11 @@
 #include "../pch/pch.h"
 #include "CMessagePush.h"
 
-#include "../tool/CPosPrinter.h"
-#include "../zhipuzi/CWaimaiOrder.h"
-
 #include "mmsystem.h"
-
 #include "PosMessage.h"
 
+#include "../print/CPosPrinter.h"
+
 CMessagePush::~CMessagePush()
 {
 
@@ -30,18 +28,6 @@ void CMessagePush::Start()
 
     //处理订单确认
     std::thread(&CMessagePush::HandleConfirm, this).detach();
-
-	//处理打印
-	std::thread(&CMessagePush::HandlePrinter, this).detach();
-
-    //处理收银打印
-    std::thread(&CMessagePush::HandleShouyinPrinter, this).detach();
-
-	//处理标签打印
-	std::thread(&CMessagePush::HandleBiaoqianPrinter, this).detach();
-
-    //处理厨房打印
-    std::thread(&CMessagePush::HandleChufangPrinter, this).detach();
 }
 
 void CMessagePush::Stop()
@@ -63,34 +49,6 @@ void CMessagePush::Stop()
 		m_confirm_queue.pop();
 	}
 	m_confirm_mutex.unlock();
-
-	m_printer_mutex.lock();
-	while (!m_printer_queue.empty())
-	{
-		m_printer_queue.pop();
-	}
-	m_printer_mutex.unlock();
-
-	m_shouyin_printer_mutex.lock();
-	while (!m_shouyin_printer_queue.empty())
-	{
-		m_shouyin_printer_queue.pop();
-	}
-	m_shouyin_printer_mutex.unlock();
-
-	m_biaoqian_printer_mutex.lock();
-	while (!m_biaoqian_printer_queue.empty())
-	{
-		m_biaoqian_printer_queue.pop();
-	}
-	m_biaoqian_printer_mutex.unlock();
-
-	m_chufang_printer_mutex.lock();
-	while (!m_chufang_printer_queue.empty())
-	{
-		m_chufang_printer_queue.pop();
-	}
-	m_chufang_printer_mutex.unlock();
 }
 
 void CMessagePush::KeepAlive()
@@ -249,13 +207,8 @@ void CMessagePush::ReceiveMessage()
 					AddConfirm(order_id);
 				}
 
-				//判断是否右下角弹框提醒
-				if (CSetting::GetParam("setting_is_new_waimai_dialog") == "1")
-				{
-
-				}
-
-				AddPinter(order_id, order_no, 1);
+				CPosPrinter printer;
+				printer.PrintWaimaiOrder(order_id, order_no);
 			}
 			else if (type == "2")
 			{
@@ -309,47 +262,6 @@ void CMessagePush::AddConfirm(std::string order_id)
     m_confirm_mutex.unlock();
 }
 
-void CMessagePush::AddPinter(std::string order_id, std::string order_no, int print_type)
-{
-    m_printer_mutex.lock();
-
-    WaimaiPinterInfo newPrinter;
-    newPrinter.order_id = order_id;
-    newPrinter.order_no = order_no;
-	newPrinter.print_type = print_type;
-
-    m_printer_queue.push(newPrinter);
-
-    m_printer_mutex.unlock();
-}
-
-void CMessagePush::AddShouyinPrinter(CWaimaiOrder order)
-{
-    m_shouyin_printer_mutex.lock();
-
-    m_shouyin_printer_queue.push(order);
-
-    m_shouyin_printer_mutex.unlock();
-}
-
-void CMessagePush::AddBiaoqianPrinter(CWaimaiOrder order)
-{
-	m_biaoqian_printer_mutex.lock();
-
-	m_biaoqian_printer_queue.push(order);
-
-	m_biaoqian_printer_mutex.unlock();
-}
-
-void CMessagePush::AddChufangPrinter(CWaimaiOrder order)
-{
-    m_chufang_printer_mutex.lock();
-
-    m_chufang_printer_queue.push(order);
-
-    m_chufang_printer_mutex.unlock();
-}
-
 void CMessagePush::HandleVoice()
 {
     while(m_is_work)
@@ -423,172 +335,6 @@ void CMessagePush::HandleConfirm()
 	AddStopNum();
 }
 
-void CMessagePush::HandlePrinter()
-{
-    while(m_is_work)
-    {
-        m_printer_mutex.lock();
-
-        if(m_printer_queue.empty())
-        {
-            m_printer_mutex.unlock();
-
-            CSystem::my_sleep(1);
-            continue;
-        }
-
-        WaimaiPinterInfo printerInfo = m_printer_queue.front();
-        std::string order_id = printerInfo.order_id;
-        std::string order_no = printerInfo.order_no;
-		int print_type = printerInfo.print_type;
-
-        m_printer_queue.pop();
-
-        m_printer_mutex.unlock();
-
-        CWaimaiOrder order;
-		if (print_type == 1)
-		{
-			if (CSetting::GetParam("setting_is_new_waimai_printer") == "1" || CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1" || CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
-			{
-				bool ret = order.InitData(order_id, order_no);
-
-				if (ret == false)
-				{
-					this->AddPinter(order_id, order_no, print_type);
-					continue;
-				}
-			}
-
-			//判断是否自动打印收银小票
-			if (CSetting::GetParam("setting_is_new_waimai_printer") == "1")
-			{
-				AddShouyinPrinter(order);
-			}
-
-			//判断是否自动打印标签小票
-			if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1")
-			{
-				AddBiaoqianPrinter(order);
-			}
-
-			//判断是否进行自动的厨房打印
-			if (CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
-			{
-				AddChufangPrinter(order);
-			}
-		}
-		else
-		{
-			bool ret = order.InitData(order_id, order_no);
-
-			if (ret == false)
-			{
-				this->AddPinter(order_id, order_no, print_type);
-				continue;
-			}
-
-			//手动打印的模式下,收银小票一定打印,标签和厨房如果没开就不打印
-			AddShouyinPrinter(order);
-
-			//判断是否自动打印标签小票
-			if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1")
-			{
-				AddBiaoqianPrinter(order);
-			}
-
-			//判断是否进行自动的厨房打印
-			if (CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
-			{
-				AddChufangPrinter(order);
-			}
-		}
-    }
-
-	AddStopNum();
-}
-
-void CMessagePush::HandleShouyinPrinter()
-{
-    while(m_is_work)
-    {
-        m_shouyin_printer_mutex.lock();
-
-        if(m_shouyin_printer_queue.empty())
-        {
-            m_shouyin_printer_mutex.unlock();
-
-            CSystem::my_sleep(1);
-            continue;
-        }
-
-        CWaimaiOrder order = m_shouyin_printer_queue.front();
-
-        m_shouyin_printer_queue.pop();
-
-        m_shouyin_printer_mutex.unlock();
-
-        CPosPrinter printer;
-        printer.PrintWaimaiOrderShouyin(order);
-    }
-
-	AddStopNum();
-}
-
-void CMessagePush::HandleBiaoqianPrinter()
-{
-	while (m_is_work)
-	{
-		m_biaoqian_printer_mutex.lock();
-
-		if (m_biaoqian_printer_queue.empty())
-		{
-			m_biaoqian_printer_mutex.unlock();
-
-			CSystem::my_sleep(1);
-			continue;
-		}
-
-		CWaimaiOrder order = m_biaoqian_printer_queue.front();
-
-		m_biaoqian_printer_queue.pop();
-
-		m_biaoqian_printer_mutex.unlock();
-
-		CPosPrinter printer;
-		printer.PrintWaimaiOrderBiaoqian(order);
-	}
-
-	AddStopNum();
-}
-
-void CMessagePush::HandleChufangPrinter()
-{
-    while(m_is_work)
-    {
-        m_chufang_printer_mutex.lock();
-
-        if(m_chufang_printer_queue.empty())
-        {
-            m_chufang_printer_mutex.unlock();
-
-            CSystem::my_sleep(1);
-            continue;
-        }
-
-        CWaimaiOrder order = m_chufang_printer_queue.front();
-
-        m_chufang_printer_queue.pop();
-
-        m_chufang_printer_mutex.unlock();
-
-        CPosPrinter printer;
-        printer.PrintWaimaiOrderChufang(order);
-    }
-
-	AddStopNum();
-}
-
 void CMessagePush::AddStopNum()
 {
 	m_nStopNumMutex.lock();

+ 2 - 38
zhipuzi_pos_windows/network/CMessagePush.h

@@ -1,28 +1,10 @@
 #pragma once
 
 #include "../pch/pch.h"
-#include "../zhipuzi/CWaimaiOrder.h"
 
 using boost::asio::ip::tcp;
 
-class CClientMessage
-{
-public:
-	int m_type; //消息类型 0:新的外卖订单
-
-	std::string m_username;
-	std::string m_order_id;
-	std::string m_order_no;
-};
-
-class WaimaiPinterInfo
-{
-public:
-	std::string order_id;
-	std::string order_no;
-	int print_type; //打印类型 1:新订单自动打印 2:手动打印
-};
-
+//这个类专门用于接收服务器端的消息推送
 class CMessagePush
 {
 public:
@@ -49,18 +31,9 @@ public:
 	//队列处理
 	void HandleVoice();
 	void HandleConfirm();
-	void HandlePrinter();
-	void HandleShouyinPrinter();
-	void HandleBiaoqianPrinter();
-	void HandleChufangPrinter();
-
 
 	void AddVoice(int voice_type);
 	void AddConfirm(std::string order_id);
-	void AddPinter(std::string order_id, std::string order_no, int print_type);
-	void AddShouyinPrinter(CWaimaiOrder order);
-	void AddBiaoqianPrinter(CWaimaiOrder order);
-	void AddChufangPrinter(CWaimaiOrder order);
 
 private:
 	void AddStopNum();
@@ -79,18 +52,9 @@ private:
 
 	std::queue<int> m_voice_queue;
 	std::queue<std::string> m_confirm_queue;
-	std::queue<WaimaiPinterInfo> m_printer_queue;
-	std::queue<CWaimaiOrder> m_shouyin_printer_queue;
-	std::queue<CWaimaiOrder> m_biaoqian_printer_queue;
-	std::queue<CWaimaiOrder> m_chufang_printer_queue;
 
 	std::mutex m_voice_mutex;
 	std::mutex m_confirm_mutex;
-	std::mutex m_printer_mutex;
-	std::mutex m_shouyin_printer_mutex;
-	std::mutex m_biaoqian_printer_mutex;
-	std::mutex m_chufang_printer_mutex;
 
 	HWND m_hwnd;
-};
-
+};

+ 17 - 44
zhipuzi_pos_windows/page/CDiandanPageUI.cpp

@@ -2728,15 +2728,7 @@ void CDiandanPageUI::StartWeixinzhifuShoukuan()
 		if (ret == IDOK)
 		{
 			//说明收款成功了,需要进行一些后续的处理
-
-			//更新商品库存
-			this->UpdateFoodStock(pShoukuanWnd->m_kucun_string);
-
-			//初始化页面信息
-			RefreshShow();
-
-			//处理打印
-
+			this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, "weixinzhifu");
 		}
 
 		m_is_show_modal_wnd = false;
@@ -2786,14 +2778,7 @@ void CDiandanPageUI::StartHuiyuanShoukuan()
 		if (ret == IDOK)
 		{
 			//说明收款成功了,需要进行一些后续的处理
-
-			//更新商品库存
-			this->UpdateFoodStock(pShoukuanWnd->m_kucun_string);
-
-			//初始化页面信息
-			RefreshShow();
-
-			//处理打印
+			this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, "huiyuanzhifu");
 
 		}
 
@@ -2845,15 +2830,7 @@ void CDiandanPageUI::StartXianjinShoukuan()
 		if (ret == IDOK)
 		{
 			//说明收款成功了,需要进行一些后续的处理
-
-			//更新商品库存
-			this->UpdateFoodStock(pShoukuanWnd->m_kucun_string);
-
-			//初始化页面信息
-			RefreshShow();
-
-			//处理打印
-
+			this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, "xianjinzhifu");
 		}
 
 		m_is_show_modal_wnd = false;
@@ -2903,15 +2880,7 @@ void CDiandanPageUI::StartFulikaShoukuan()
 		if (ret == IDOK)
 		{
 			//说明收款成功了,需要进行一些后续的处理
-
-			//更新商品库存
-			this->UpdateFoodStock(pShoukuanWnd->m_kucun_string);
-
-			//初始化页面信息
-			RefreshShow();
-
-			//处理打印
-
+			this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, "fulikazhifu");
 		}
 
 		m_is_show_modal_wnd = false;
@@ -2964,15 +2933,7 @@ void CDiandanPageUI::StartZidingyiShoukuan(std::wstring name, std::wstring selfp
 		if (ret == IDOK)
 		{
 			//说明收款成功了,需要进行一些后续的处理
-
-			//更新商品库存
-			this->UpdateFoodStock(pShoukuanWnd->m_kucun_string);
-
-			//初始化页面信息
-			RefreshShow();
-
-			//处理打印
-
+			this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, "zidingyizhifu");
 		}
 
 		m_is_show_modal_wnd = false;
@@ -3126,4 +3087,16 @@ void CDiandanPageUI::StopSerachFood()
 	pTishi->SetVisible(true);
 
 	this->InitFoodShow();
+}
+
+void CDiandanPageUI::StartWorkAfterShoukuan(std::string kucunstring, std::string shoukuan_type)
+{
+	//更新商品库存
+	this->UpdateFoodStock(kucunstring);
+
+	//初始化页面信息
+	RefreshShow();
+
+	//处理打印
+
 }

+ 3 - 0
zhipuzi_pos_windows/page/CDiandanPageUI.h

@@ -165,6 +165,9 @@ public:
 	//停止搜索商品
 	void StopSerachFood();
 
+	//执行付款成功后的所有操作逻辑
+	void StartWorkAfterShoukuan(std::string kucunstring, std::string shoukuan_type);
+
 private:
 	//获取用于提交订单的参数结构
 	std::map<string, string> GetSendorderParams();

+ 5 - 9
zhipuzi_pos_windows/page/CSettingPageUI.cpp

@@ -3,6 +3,8 @@
 
 #include "../wnd/CChufangSettingWnd.h"
 
+#include "../print/CPosPrinter.h"
+
 CSettingPageUI::CSettingPageUI()
 {
 
@@ -129,9 +131,7 @@ void CSettingPageUI::InitShow()
 		std::string setting_printer_usb = CSetting::GetParam("setting_printer_usb");
 		std::wstring ws_setting_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_printer_usb);
 
-		CPosPrinter printer;
-		printer.InitUsb();
-		std::vector<std::wstring> usb_devices = printer.getUsbDevices();
+		std::vector<std::wstring> usb_devices = CPosPrinterQueue::GetInstance()->getUsbDevices();
 
 		int i = 0;
 		int nSelect = -1;
@@ -373,9 +373,7 @@ void CSettingPageUI::InitShow()
 	std::string setting_biaoqian_printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
 	std::wstring ws_setting_biaoqian_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_biaoqian_printer_usb);
 
-	CPosPrinter printer;
-	printer.InitUsb(2);
-	std::vector<std::wstring> usb_devices = printer.getUsbDevices();
+	std::vector<std::wstring> usb_devices = CPosPrinterQueue::GetInstance()->getUsbDevices();
 
 	int i = 0;
 	int nSelect = -1;
@@ -1199,9 +1197,7 @@ void CSettingPageUI::HandleItemSelectMsg(TNotifyUI& msg)
 			std::string setting_printer_usb = CSetting::GetParam("setting_printer_usb");
 			std::wstring ws_setting_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_printer_usb);
 
-			CPosPrinter printer;
-			printer.InitUsb();
-			std::vector<std::wstring> usb_devices = printer.getUsbDevices();
+			std::vector<std::wstring> usb_devices = CPosPrinterQueue::GetInstance()->getUsbDevices();
 
 			int i = 0;
 			int nSelect = -1;

+ 4 - 1
zhipuzi_pos_windows/page/CWaimaiOrderInfoPageUI.cpp

@@ -7,6 +7,8 @@
 
 #include "../network/CMessagePush.h"
 
+#include "../print/CPosPrinter.h"
+
 CWaimaiOrderInfoPageUI::CWaimaiOrderInfoPageUI()
 {
 
@@ -40,7 +42,8 @@ void CWaimaiOrderInfoPageUI::HandleClickMsg(TNotifyUI& msg)
 	}
 	else if (name == _T("waimai_order_info_page_print"))
 	{
-		m_pMainWnd->getMessagePush()->AddPinter(this->m_order.m_order_id, this->m_order.m_order_no, 2);
+		CPosPrinter printer;
+		printer.PrintWaimaiOrder(this->m_order.m_order_id, this->m_order.m_order_no);
 	}
 	else if (name == _T("waimai_order_info_page_confirme"))
 	{

+ 5 - 1
zhipuzi_pos_windows/page/CWaimaiOrderListPageUI.cpp

@@ -8,6 +8,8 @@
 #include "../network/CMessagePush.h"
 #include "../wnd/CWaimaiOrderFailReasonWnd.h"
 
+#include "../print/CPosPrinter.h"
+
 
 CWaimaiOrderListPageUI::CWaimaiOrderListPageUI()
 {
@@ -43,7 +45,9 @@ void CWaimaiOrderListPageUI::HandleClickMsg(TNotifyUI& msg)
 		CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
 		std::string waimai_order_id = item->getOrderID();
 		std::string waimai_order_no = item->getOrderNo();
-		m_pMainWnd->getMessagePush()->AddPinter(waimai_order_id, waimai_order_no, 2);
+
+		CPosPrinter printer;
+		printer.PrintWaimaiOrder(waimai_order_id, waimai_order_no);
 	}
 	else if (name == _T("waimai_order_list_confirme"))
 	{

+ 1 - 0
zhipuzi_pos_windows/pch/pch.cpp

@@ -9,6 +9,7 @@
 //最先初始化sqllite数据
 CSetting CSetting::m_setting;
 
+//然后才初始化网络等
 CZhipuziHttpClient CZhipuziHttpClient::m_client;
 
 CShopinfo CShopinfo::m_shopinfo;

+ 2 - 2
zhipuzi_pos_windows/pch/pch.h

@@ -70,9 +70,9 @@ using namespace rapidjson;
 #include "../helper/CSystem.h"
 #include "../helper/CLewaimaiString.h"
 #include "../helper/CLewaimaiJson.h"
+#include "../helper/CLewaimaiLog.h"
+#include "../helper/CLewaimaiTime.h"
 
-#include "../tool/CLewaimaiLog.h"
-#include "../tool/CLewaimaiTime.h"
 #include "../tool/CSqlite3.h"
 #include "../tool/CSetting.h"
 

+ 84 - 0
zhipuzi_pos_windows/print/CPosPrinter.cpp

@@ -0,0 +1,84 @@
+#include "../pch/pch.h"
+#include "CPosPrinter.h"
+
+CPosPrinter::CPosPrinter()
+{
+}
+
+
+CPosPrinter::~CPosPrinter()
+{
+}
+
+//完成所有打印一个外卖订单的操作
+void CPosPrinter::PrintWaimaiOrder(CWaimaiOrder& order)
+{
+	if (CSetting::GetParam("setting_is_new_waimai_printer") == "1")
+	{
+		//执行收银小票打印操作
+		CPosPrinterData printData;
+		
+		std::string data = printData.PrintWaimaiOrderShouyin(order);
+
+		if (data.length() > 0)
+		{
+			CPosPrinterQueue::GetInstance()->AddShouyinPrinter(data);
+		}
+	}
+
+	if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1")
+	{
+		//执行标签小票打印操作
+		CPosPrinterData printData;
+
+		std::string data = printData.PrintWaimaiOrderBiaoqian(order);
+
+		if (data.length() > 0)
+		{
+			CPosPrinterQueue::GetInstance()->AddBiaoqianPrinter(data);
+		}
+	}
+
+	//判断是否进行自动的厨房打印
+	if (CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
+	{
+		//进行厨房打印
+		CPosPrinterData printData;
+
+		std::vector<ChufangPrinterContent> datas = printData.PrintWaimaiOrderChufang(order);
+
+		if (datas.size() > 0)
+		{
+			for (std::vector<ChufangPrinterContent>::iterator it = datas.begin(); it != datas.end(); it++)
+			{
+				ChufangPrinterContent content = *it;
+
+				if (content.data.length() > 0)
+				{
+					CPosPrinterQueue::GetInstance()->AddChufangPrinter(content);
+				}
+			}
+		}
+	}
+}
+
+void CPosPrinter::PrintWaimaiOrder(std::string order_id, std::string order_no)
+{
+	CWaimaiOrder order;
+
+	bool ret = order.InitData(order_id, order_no);
+
+	PrintWaimaiOrder(order);
+}
+
+//完成所有打印一个点单订单的操作
+void CPosPrinter::PrintDiandanOrder(CDiandanOrder& order)
+{
+	
+}
+
+//获取当前电脑上所有的打印usb设备
+std::vector<std::wstring> CPosPrinter::getUsbDevices()
+{
+	return CPosPrinterQueue::GetInstance()->getUsbDevices();
+}

+ 24 - 0
zhipuzi_pos_windows/print/CPosPrinter.h

@@ -0,0 +1,24 @@
+#pragma once
+
+#include "../pch/pch.h"
+
+#include "CPosPrinterQueue.h"
+
+class CPosPrinter
+{
+public:
+	CPosPrinter();
+	~CPosPrinter();
+
+	//完成所有打印一个外卖订单的操作(不等待,立即返回)
+	void PrintWaimaiOrder(CWaimaiOrder& order);
+
+	void PrintWaimaiOrder(std::string order_id, std::string order_no);
+
+	//完成所有打印一个点单订单的操作(不等待,立即返回)
+	void PrintDiandanOrder(CDiandanOrder& order);
+
+	//获取当前电脑上所有的打印usb设备
+	std::vector<std::wstring> getUsbDevices();
+};
+

+ 61 - 611
zhipuzi_pos_windows/tool/CPosPrinter.cpp

@@ -1,496 +1,23 @@
 #include "../pch/pch.h"
-#include "CPosPrinter.h"
+#include "CPosPrinterData.h"
 
-#include "../tool/CComHelper.h"
 #include "../helper/CBitmapHelper.h"
-
 #include <qrencode/qrencode.h>
 
-CPosPrinter::CPosPrinter(): m_socket(m_io)
+CPosPrinterData::CPosPrinterData()
 {
 }
 
 
-CPosPrinter::~CPosPrinter()
+CPosPrinterData::~CPosPrinterData()
 {
 }
 
 /*
- *usbType是1表示只查找收银小票打印机,会排除已知的标签打印机
- *usbType为2表示所有usb打印机都查找,包含标签与非标签
- **/
-void CPosPrinter::InitUsb(int usbType)
-{
-    //设置中文字符
-    setlocale(LC_CTYPE, "chs");
-
-    //取设备路径
-    int nDevice = GetDevicePath((LPGUID)&USB_GUID, usbType);
-    LOG_INFO("可用的USB打印机数量:" << nDevice);
-
-    //添加usb端口
-    int i = 0;
-
-    while(i < nDevice)
-    {
-		std::string setting_biaoqian_printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
-		std::wstring ws_setting_biaoqian_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_biaoqian_printer_usb);
-
-		if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1" && ws_setting_biaoqian_printer_usb == m_usb_devices[i])
-		{
-			//碰到了一个标签打印机
-			i++;
-			continue;
-		}
-
-        LOG_INFO("准备打开端口 Port = " << m_usb_devices[i].c_str());
-
-        HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
-        if(hPort == INVALID_HANDLE_VALUE)
-        {
-			LOG_INFO("打开USB端口失败, Port = " << m_usb_devices[i].c_str());
-
-            // 打开端口失败
-            DWORD error = GetLastError();
-
-            if(error == 2)
-            {
-                //没有指定的文件
-                LOG_INFO("没有找对对应的usb端口");
-            }
-            else if(error == 5)
-            {
-                LOG_INFO("usb端口被占用!");
-            }
-
-            continue;
-        }
-
-        LOG_INFO("打开usb端口成功,准备进行打印机检测! hPort:" << hPort);
-
-        if(PortTest(hPort) == true)
-        {
-            //端口测试连通,保存起来
-            PrinterHandle newHandle;
-            newHandle.hPort = hPort;
-            newHandle.type = 1;
-
-            m_hPorts.push_back(newHandle);
-        }
-        else
-        {
-            //端口打印机没有连接,那么就直接关闭掉并口,避免占用
-            CloseHandle(hPort);
-        }
-
-        i++;
-    }
-}
-
-bool CPosPrinter::InitOneUsb(wstring usb_path)
-{
-	if (usb_path == L"")
-	{
-		return false;
-	}
-
-    HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
-    if(hPort == INVALID_HANDLE_VALUE)
-    {
-		LOG_INFO("打开USB端口失败, Port = " << usb_path.c_str());
-
-        // 打开端口失败
-        DWORD error = GetLastError();
-
-        if(error == 2)
-        {
-            //没有指定的文件
-            LOG_INFO("没有找对对应的usb端口");
-        }
-        else if(error == 5)
-        {
-            LOG_INFO("usb端口被占用!");
-        }
-
-		return false;
-    }
-
-    LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
-
-    if(PortTest(hPort) == true)
-    {
-        //端口测试连通,保存起来
-        PrinterHandle newHandle;
-        newHandle.hPort = hPort;
-        newHandle.type = 1;
-
-        m_hPorts.push_back(newHandle);
-    }
-    else
-    {
-        //端口打印机没有连接,那么就直接关闭掉并口,避免占用
-        CloseHandle(hPort);
-
-		return false;
-    }
-
-	return true;
-}
-
-bool CPosPrinter::InitBingkou()
-{
-    std::wstring LptStr = L"lpt1";
-
-    HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
-    if(hPort == INVALID_HANDLE_VALUE)
-    {
-		LOG_INFO("打开并口失败, Port = " << LptStr.c_str());
-
-        DWORD error = GetLastError();
-
-        if(error == 2)
-        {
-            //没有指定的文件
-            LOG_INFO("本机器没有并口!");
-        }
-        else if(error == 5)
-        {
-            LOG_INFO("并口被占用!");
-        }
-
-		return false;
-    }
-    else
-    {
-        //这个表示并口可以使用
-        LOG_INFO("找到并口,准备进行打印机检测! hPort:" << hPort);
-
-        if(PortTest(hPort) == true)
-        {
-            //并口测试连通,保存起来
-            PrinterHandle newHandle;
-            newHandle.hPort = hPort;
-            newHandle.type = 2;
-
-            m_hPorts.push_back(newHandle);
-        }
-        else
-        {
-            //并口打印机没有连接,那么就直接关闭掉并口,避免占用
-            CloseHandle(hPort);
-
-			return false;
-        }
-    }
-
-	return true;
-}
-
-void CPosPrinter::InitCom()
-{
-    CComHelper helper;
-    std::vector<std::wstring> comVector = helper.getComPort();
-
-    for(std::vector<std::wstring>::iterator it = comVector.begin(); it != comVector.end(); it++)
-    {
-        std::wstring com2Str = *it;
-
-        HANDLE hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
-        if(hPort == INVALID_HANDLE_VALUE)
-        {
-            DWORD error = GetLastError();
-
-            if(error == 2)
-            {
-                //没有指定的文件
-                LOG_INFO("没有找到对应的串口 " << com2Str.c_str());
-            }
-            else if(error == 5)
-            {
-                LOG_INFO("串口被占用 " << com2Str.c_str());
-            }
-        }
-        else
-        {
-            LOG_INFO(com2Str.c_str() << " success, handle:" << hPort);
-
-            //扎到了可用的串口,设置串口波特率
-            DCB dcb;
-            dcb.DCBlength = sizeof(dcb);
-            GetCommState(hPort, &dcb);
-
-            //佳博的串口打印机,默认是这个波特率
-            dcb.BaudRate = 19200;
-
-            if(!SetCommState(hPort, &dcb))
-            {
-                LOG_INFO("set baudRate failed!");
-
-                CloseHandle(hPort);
-                continue;
-            }
-
-            //设定通讯端口超时参数
-            COMMTIMEOUTS tmouts;
-            tmouts.ReadIntervalTimeout = 100;
-            tmouts.ReadTotalTimeoutMultiplier = 100;
-            tmouts.ReadTotalTimeoutConstant = 100;
-            tmouts.WriteTotalTimeoutConstant = 100;
-            tmouts.WriteTotalTimeoutMultiplier = 100;
-            SetCommTimeouts(hPort, &tmouts);
-
-            //设置端口缓冲
-            SetupComm(hPort, 1024, 1024);
-
-            //清除通讯端口缓存
-            PurgeComm(hPort, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
-
-            //保存端口
-            PrinterHandle newHandle;
-            newHandle.hPort = hPort;
-            newHandle.type = 3;
-
-            m_hPorts.push_back(newHandle);
-        }
-    }
-}
-
-/*
- *找到所有可用的小票打印机,这里只初始化USB,不包含并口、串口、网口
- *智能识别模式不再自动处理串口,串口的需要人工去选择类型
- **/
-void CPosPrinter::InitShouyin()
-{
-    //开始添加usb
-    InitUsb();
-}
-
-/*
- *获取CreateFile的USB端口号
- **/
-int CPosPrinter::GetDevicePath(LPGUID lpGuid, int usbType)
-{
-    HDEVINFO hDevInfoSet;
-    SP_DEVINFO_DATA spDevInfoData;
-    SP_DEVICE_INTERFACE_DATA ifData;
-    PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;
-    int nCount;
-    int nTotle;
-    BOOL bResult;
-
-    //这2个字符串,用于根据usb的名字对比是否为打印机设备
-    wstring strUSBPrint = TEXT("USB 打印支持");
-
-    //xp上是英文
-    wstring strUSBPrint_EN = L"USB Printing Support";
-
-    // 取得一个该GUID相关的设备信息集句柄
-    hDevInfoSet = ::SetupDiGetClassDevs(lpGuid,     // class GUID
-                                        NULL,                    // 无关键字
-                                        NULL,                    // 不指定父窗口句柄
-                                        DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);    // 目前存在的设备
-
-    // 失败...
-    if(hDevInfoSet == INVALID_HANDLE_VALUE)
-    {
-        LOG_INFO("SetupDiGetClassDevs failed \r\n");
-        return 0;
-    }
-
-    // 申请设备接口数据空间
-    pDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)::GlobalAlloc(LMEM_ZEROINIT, INTERFACE_DETAIL_SIZE);
-    pDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
-    nTotle = -1;
-    nCount = 0;
-    bResult = TRUE;
-
-    // 设备序号=0,1,2... 逐一测试设备接口,到失败为止
-    while(bResult)
-    {
-        nTotle++;
-        spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
-
-        // 枚举符合该GUID的设备接口
-        bResult = ::SetupDiEnumDeviceInfo(
-                      hDevInfoSet,     // 设备信息集句柄
-                      (ULONG)nTotle,   // 设备信息集里的设备序号
-                      &spDevInfoData);        // 设备接口信息
-
-        if(bResult)
-        {
-            DWORD DataT;
-            TCHAR buf[MAX_PATH] = { 0 };
-            DWORD nSize = 0;
-
-            // get Friendly Name or Device Description
-            if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
-                                                SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
-            {
-            }
-            else if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
-                    SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
-            {
-            }
-            else
-            {
-                lstrcpy(buf, _T("Unknown"));
-            }
-
-            wstring ws_buf = buf;
-
-            //是否是要找的设备类型
-            if(ws_buf != strUSBPrint && ws_buf != strUSBPrint_EN)
-            {
-                LOG_INFO("not good usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
-                continue;
-            }
-
-            LOG_INFO("good usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
-            ifData.cbSize = sizeof(ifData);
-
-            // 枚舉符合該GUID的設備接口
-            bResult = ::SetupDiEnumDeviceInterfaces(
-                          hDevInfoSet,     // 設備信息集句柄
-                          NULL,            // 不需額外的設備描述
-                          lpGuid,          // GUID
-                          (ULONG)nTotle,   // 設備信息集里的設備序號
-                          &ifData);        // 設備接口信息
-
-            if(bResult)
-            {
-                // 取得该设备接口的细节(设备路径)
-                bResult = SetupDiGetInterfaceDeviceDetail(
-                              hDevInfoSet,    // 设备信息集句柄
-                              &ifData,        // 设备接口信息
-                              pDetail,        // 设备接口细节(设备路径)
-                              INTERFACE_DETAIL_SIZE,    // 输出缓冲区大小
-                              NULL,           // 不需计算输出缓冲区大小(直接用设定值)
-                              NULL);          // 不需额外的设备描述
-
-                if(bResult)
-                {
-                    wstring DevicePath = pDetail->DevicePath;
-
-                    wstring vid = DevicePath.substr(DevicePath.find(_T("vid_"), 0) + 4, 4);
-                    wstring pid = DevicePath.substr(DevicePath.find(_T("pid_"), 0) + 4, 4);
-
-                    LOG_INFO("Vid:" << vid.c_str() << ", Pid:" << pid.c_str());
-
-                    if(usbType == 1 && GetPrinterType(vid, pid) == 2)
-                    {
-                        //标签打印机,暂时不处理打印
-                        LOG_INFO("标签打印机,暂时不打印!");
-                        continue;
-                    }
-
-                    // 复制设备路径到输出缓冲区
-                    m_usb_devices.push_back(DevicePath);
-
-                    // 调整计数值
-                    nCount++;
-
-                    LOG_INFO("Cnt = " << nCount << ",pDetail->DevicePath =" << pDetail->DevicePath);
-                }
-            }
-        }
-        else
-        {
-            //LOG_INFO("SetupDiEnumDeviceInfo FAILED!@");
-        }
-    }
-
-    // 释放设备接口数据空间
-    ::GlobalFree(pDetail);
-
-    // 关闭设备信息集句柄
-    ::SetupDiDestroyDeviceInfoList(hDevInfoSet);
-    return nCount;
-}
-
-/*
- *返回打印机的类型, 1:普通热敏打印机 2:标签打印机 3:发票打印机
- *这里因为不同厂家对vid pid定义不一样,有时候会出现佳博的标签打印机的vid和pid,在别的品牌上变成了热敏打印机,这里如果排除掉别的品牌的热敏打印机就无法打印了,所以这里不能轻易排除
- **/
-int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
-{
-    if(vid == L"6868" && pid == L"0500")
-    {
-        //佳博标签打印机
-        return 2;
-    }
-	else if (vid == L"XXX" && pid == L"XXX")
-	{
-		//发票打印机
-		return 3;
-	}
-
-    return 1;
-}
-
-/*
  *打印收银小票
  **/
-void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
+std::string CPosPrinterData::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 {
-	LOG_INFO("_______________________________开始打印收银小票,订单编号:"<<order.m_order_num.c_str()<<"_________________________");
-
-    //设置模式,后面输出数据不会错
-    m_type = 1;
-
-    std::string printer_leixing = CSetting::GetParam("setting_printer_leixing");
-
-    if(printer_leixing == "auto")
-    {
-        InitShouyin();
-    }
-    else if(printer_leixing == "usb")
-    {
-        std::string printer_usb = CSetting::GetParam("setting_printer_usb");
-        std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
-
-        bool ret = InitOneUsb(ws_printer_usb);
-		if (ret == false)
-		{
-			return;
-		}
-    }
-    else if(printer_leixing == "bingkou")
-    {
-        bool ret = InitBingkou();
-		if (ret == false)
-		{
-			return;
-		}
-    }
-    else if(printer_leixing == "chuankou")
-    {
-        InitCom();
-    }
-    else if(printer_leixing == "wangkou")
-    {
-        m_type = 2;
-
-        std::string wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
-
-        //初始化连接
-        try
-        {
-            boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(wangkou_ip.c_str()), 9100);
-            m_socket.connect(ep);
-        }
-        catch(std::exception& e)
-        {
-            std::string err = e.what();
-            LOG_INFO("网口打印机连接失败,IP地址:" << wangkou_ip.c_str() << ",错误信息:" << err.c_str());
-
-			MessageBoxW(NULL, (L"厨房网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(wangkou_ip)).c_str(), L"打印机连接失败", MB_OK);
-        }
-    }
-
     //读取当前收银打印机的设置
     std::string guige = CSetting::GetParam("setting_printer_guige");
     std::string lianshu = CSetting::GetParam("setting_printer_lianshu");
@@ -905,26 +432,11 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
     //还原打印机初始设置,有些傻逼收银设备居然不是自动调用,比如哗啦啦
     POS_Reset();
 
-    //关闭设备
-    for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
-    {
-        CloseHandle((*it).hPort);
-    }
-
-	if (m_type == 2)
-	{
-		m_socket.close();
-	}
-
-	LOG_INFO("_______________________________结束打印收银小票,订单编号:" << order.m_order_num.c_str() << "_________________________");
-	LOG_INFO("                                                                                                              ");
+	return m_print_content;
 }
 
-
-void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
+std::string CPosPrinterData::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
 {
-    m_type = 1;
-
     std::string printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
     std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
 
@@ -968,9 +480,6 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
 		nDIRECTION = 0;
 	}
 
-    //连接usb端口
-    InitOneUsb(ws_printer_usb);
-
 	//初始化标签打印机
 	BIAOQIAN_Reset(biaoqian_width, biaoqian_height, nDIRECTION);
 
@@ -1078,38 +587,25 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
 			BIAOQIAN_CLS();
         }
     }
+
+	return m_print_content;
 }
 
-void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
+std::vector<ChufangPrinterContent> CPosPrinterData::PrintWaimaiOrderChufang(CWaimaiOrder& order)
 {
-    //设置模式,后面输出数据不会错
-    m_type = 2;
+	std::vector<ChufangPrinterContent> datas;
 
     //读取厨房打印机信息
     std::vector<ChufangPrinter> total_printers = CSetting::getChufangPrints();
 
     for(std::vector<ChufangPrinter>::iterator it = total_printers.begin(); it != total_printers.end(); it++)
     {
+		//清空每个厨房打印机的打印内容
+		m_print_content = "";
+
         ChufangPrinter printer = *it;
         std::string ip = printer.ip;
 
-        //初始化连接
-        try
-        {
-            boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(ip.c_str()), 9100);
-            m_socket.connect(ep);
-        }
-        catch(std::exception& e)
-        {
-            std::string err = e.what();
-            LOG_INFO("厨房网口打印机连接失败,IP地址:" << ip.c_str() << ",错误信息:" << err.c_str());
-
-			MessageBoxW(NULL, (L"厨房网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(ip)).c_str(), L"打印机连接失败", MB_OK);
-
-            //连接失败了,处理下一个厨房打印机
-            continue;
-        }
-
         std::string guige = printer.guige;
         std::string fendan = printer.fendan;
 		std::string fenlei = printer.fenlei;
@@ -1144,8 +640,6 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
 		if (cur_printer_use.size() == 0)
 		{
 			//如果这个厨房打印机没有商品可以打印(开启了商品分类打印可能出现),就直接跳过
-			m_socket.close();
-
 			continue;
 		}
 
@@ -1409,115 +903,71 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
             POS_Reset();
         }
 
-        m_socket.close();
+		ChufangPrinterContent newData;
+		newData.ip = ip;
+		newData.data = m_print_content;
+
+		datas.push_back(newData);
     }
+
+	return datas;
 }
 
-std::vector<std::wstring> CPosPrinter::getUsbDevices()
+std::string CPosPrinterData::PrintDiandanOrderShouyin(CDiandanOrder& order)
 {
-    return m_usb_devices;
+	return "";
 }
 
-int CPosPrinter::WriteData(string msg)
+std::string CPosPrinterData::PrintDiandanOrderBiaoqian(CDiandanOrder& order)
 {
-    return WriteBuf((unsigned char*)msg.c_str(), msg.length());
+	return "";
 }
 
-/*
- *这个函数只负责把数据拼接到打印缓存里面,不负责实际的发送数据
- **/
-int CPosPrinter::WriteBuf(const unsigned char* buf, int len)
+std::vector<ChufangPrinterContent> CPosPrinterData::PrintDiandanOrderChufang(CDiandanOrder& order)
 {
-    if(m_type == 1)
-    {
-		//USB、串口、并口,走这里
-        for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
-        {
-            HANDLE hPort = (*it).hPort;
-
-            //同步写数据
-			DWORD dwWrite;
-
-            BOOL ret = WriteFile(hPort, buf, len, &dwWrite, NULL);
-			if (!ret)
-			{
-				LOG_INFO("WriteFile Failed!, hPort:"<<hPort<<", type:"<<(*it).type);
-			}
-        }
+	std::vector<ChufangPrinterContent> datas;
 
-        return 1;
-    }
-    else
-    {
-		//网口走这里
-        try
-        {
-            m_socket.write_some(boost::asio::buffer(buf, len));
-        }
-        catch(const std::exception& e)
-        {
-			LOG_INFO("网口打印机发送消息失败,错误信息:" << e.what());
-        }
+	return datas;
+}
 
-        return 1;
-    }
+void CPosPrinterData::WriteData(string msg)
+{
+	m_print_content += msg;
 }
 
 /*
- *测试打印机是否连接
+ *这个函数只负责把数据拼接到打印缓存里面,不负责实际的发送数据
  **/
-bool CPosPrinter::PortTest(HANDLE hPort)
+void CPosPrinterData::WriteBuf(const unsigned char* buf, int len)
 {
-	//这里的话目前USB、串口、并口用的都是同步读写模式,有的打印机(比如一些发票打印机)CreateFile会成功,但是WriteFile会一直阻塞卡着,如果检测的话,
-	//在这里会一直卡住,因此这里的检测就不检测了,默认所有的都是连通的
-	//因此,对于智能识别模式,可能会出现无法打印(因为被某些usb打印设备阻塞),这种情况就只能手动选择USB模式,然后重新启动软件
-	return true;
-
-    //标签打印机的查询状态指令
-    char chInitCode[2] = { 0x1b, 0x40};
-
-    DWORD dwWrite;
-
-    BOOL rc = WriteFile(hPort, chInitCode, 2, &dwWrite, NULL);
-
-    if(rc)
-    {
-        LOG_INFO("porttest success, handle:" << hPort);
-
-        return true;
-    }
-    else
-    {
-		LOG_INFO("porttest fail, handle:" << hPort);
-
-		return true;
-    }
-
-    return false;
+	for (int i = 0; i < len; i++)
+	{
+		m_print_content += buf[i];
+	}
 }
 
-int CPosPrinter::POS_Reset(void)
+int CPosPrinterData::POS_Reset(void)
 {
     unsigned char s[2] = {0x1B, 0x40};
     WriteBuf(s, 2);
     return 0;
 }
 
-int CPosPrinter::POS_FeedLine(void)
+int CPosPrinterData::POS_FeedLine(void)
 {
     unsigned char s[1] = {0x0A};
     WriteBuf(s, 1);
     return 0;
 }
 
-int CPosPrinter::POS_Feed(void)
+int CPosPrinterData::POS_Feed(void)
 {
     unsigned char s[3] = { 0x1B, 0x4A, 0x00 };
     WriteBuf(s, 3);
     return 0;
 }
 
-int CPosPrinter::POS_SetMotionUnit(int x, int y)
+int CPosPrinterData::POS_SetMotionUnit(int x, int y)
 {
     string s;
     s = "\x1D\x50\xB4\xB4";
@@ -1529,7 +979,7 @@ int CPosPrinter::POS_SetMotionUnit(int x, int y)
     return 0;
 }
 
-int CPosPrinter::POS_SET_MOVE_X()
+int CPosPrinterData::POS_SET_MOVE_X()
 {
     unsigned char s2[6] = { 0x1B, 0x44, 0x0C, 0x0E, 0x17, 0x00};
     WriteBuf(s2, 6);
@@ -1537,7 +987,7 @@ int CPosPrinter::POS_SET_MOVE_X()
     return 0;
 }
 
-int CPosPrinter::POS_MOVE_X()
+int CPosPrinterData::POS_MOVE_X()
 {
     unsigned char s[1] = { 0x09 };
     WriteBuf(s, 1);
@@ -1545,7 +995,7 @@ int CPosPrinter::POS_MOVE_X()
     return 0;
 }
 
-int CPosPrinter::POS_SET_ABS_X(int x, int y)
+int CPosPrinterData::POS_SET_ABS_X(int x, int y)
 {
     unsigned char cx = (unsigned char)(x);
     unsigned char cy = (unsigned char)(y);
@@ -1555,7 +1005,7 @@ int CPosPrinter::POS_SET_ABS_X(int x, int y)
     return 0;
 }
 
-int CPosPrinter::POS_SET_PRINT_AREA(int x, int y)
+int CPosPrinterData::POS_SET_PRINT_AREA(int x, int y)
 {
     unsigned char cx = (unsigned char)(x);
     unsigned char cy = (unsigned char)(y);
@@ -1569,7 +1019,7 @@ int CPosPrinter::POS_SET_PRINT_AREA(int x, int y)
 /*
  *align_type:0 左对齐 1 居中对齐 2右对齐
  **/
-int CPosPrinter::POS_TextOut(string abc, bool is_double_width, bool is_double_height, int align_type)
+int CPosPrinterData::POS_TextOut(string abc, bool is_double_width, bool is_double_height, int align_type)
 {
     if(is_double_width && is_double_height)
     {
@@ -1627,7 +1077,7 @@ int CPosPrinter::POS_TextOut(string abc, bool is_double_width, bool is_double_he
 /*
  *打印机切纸,直接切不走纸
  **/
-int CPosPrinter::POS_CutPaper()
+int CPosPrinterData::POS_CutPaper()
 {
     unsigned char s[4] = { 0x1D, 0x56, 0x01};
     WriteBuf(s, 3);
@@ -1637,7 +1087,7 @@ int CPosPrinter::POS_CutPaper()
 /*
  *先转换成ANSI格式才能传进来
  **/
-void CPosPrinter::POS_OutQRCode(std::string dataString)
+void CPosPrinterData::POS_OutQRCode(std::string dataString)
 {
 	QRcode * qrCode = nullptr;
 	qrCode = QRcode_encodeString(dataString.c_str(), 0, QR_ECLEVEL_H, QR_MODE_8, 1);
@@ -1741,7 +1191,7 @@ void CPosPrinter::POS_OutQRCode(std::string dataString)
 	return ;
 }
 
-void CPosPrinter::POS_OutBmp(std::wstring ImagePath)
+void CPosPrinterData::POS_OutBmp(std::wstring ImagePath)
 {
 	//初始化
 	POS_Reset();
@@ -1839,7 +1289,7 @@ void CPosPrinter::POS_OutBmp(std::wstring ImagePath)
 	delete[] dataTmp;
 }
 
-void CPosPrinter::BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection)
+void CPosPrinterData::BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection)
 {
     char endTag[3] = {0x0d, 0x0a, 0x00};
 
@@ -1878,7 +1328,7 @@ void CPosPrinter::BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection)
 /*
  *前进一张纸
  **/
-void CPosPrinter::BIAOQIAN_FORMFEED()
+void CPosPrinterData::BIAOQIAN_FORMFEED()
 {
     char endTag[3] = { 0x0d, 0x0a, 0x00 };
 
@@ -1888,7 +1338,7 @@ void CPosPrinter::BIAOQIAN_FORMFEED()
     WriteData(formfeed);
 }
 
-void CPosPrinter::BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_multiplication, int y_multiplication)
+void CPosPrinterData::BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_multiplication, int y_multiplication)
 {
     char endTag[3] = { 0x0d, 0x0a, 0x00 };
 
@@ -1904,7 +1354,7 @@ void CPosPrinter::BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_mult
     WriteData(text);
 }
 
-std::string CPosPrinter::BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication)
+std::string CPosPrinterData::BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication)
 {
 	char endTag[3] = { 0x0d, 0x0a, 0x00 };
 
@@ -1920,7 +1370,7 @@ std::string CPosPrinter::BIAOQIAN_TEXTGet(std::string content, int x, int y, int
 	return text;
 }
 
-void CPosPrinter::BIAOQIAN_PRINT()
+void CPosPrinterData::BIAOQIAN_PRINT()
 {
     char endTag[3] = { 0x0d, 0x0a, 0x00 };
 
@@ -1930,7 +1380,7 @@ void CPosPrinter::BIAOQIAN_PRINT()
     WriteData(print);
 }
 
-void CPosPrinter::BIAOQIAN_CLS()
+void CPosPrinterData::BIAOQIAN_CLS()
 {
     char endTag[3] = { 0x0d, 0x0a, 0x00 };
 
@@ -1940,7 +1390,7 @@ void CPosPrinter::BIAOQIAN_CLS()
     WriteData(cls);
 }
 
-void CPosPrinter::CalWord(string s, int& nHanzi, int& nZimu)
+void CPosPrinterData::CalWord(string s, int& nHanzi, int& nZimu)
 {
     nHanzi = 0;
     nZimu = 0;
@@ -1967,7 +1417,7 @@ void CPosPrinter::CalWord(string s, int& nHanzi, int& nZimu)
 /*
  *规格 1:58mm 2:80mm
  **/
-std::vector<std::string>CPosPrinter::HandleFoodname(std::string oldname, int guige)
+std::vector<std::string>CPosPrinterData::HandleFoodname(std::string oldname, int guige)
 {
     std::vector<std::string> newnameArray;
     int nHanzi, nZimu;
@@ -2062,7 +1512,7 @@ std::vector<std::string>CPosPrinter::HandleFoodname(std::string oldname, int gui
     return newnameArray;
 }
 
-std::string CPosPrinter::HandleFoodItemPrice(std::string oldprice, int guige)
+std::string CPosPrinterData::HandleFoodItemPrice(std::string oldprice, int guige)
 {
     double price = atof(oldprice.c_str());
 
@@ -2116,7 +1566,7 @@ std::string CPosPrinter::HandleFoodItemPrice(std::string oldprice, int guige)
     }
 }
 
-std::string CPosPrinter::HandleFoodQuantity(std::string oldquantity, int guige)
+std::string CPosPrinterData::HandleFoodQuantity(std::string oldquantity, int guige)
 {
     int n = atoi(oldquantity.c_str());
 
@@ -2155,7 +1605,7 @@ std::string CPosPrinter::HandleFoodQuantity(std::string oldquantity, int guige)
     }
 }
 
-std::string CPosPrinter::HandleFoodTotalPrice(std::string oldprice, int guige)
+std::string CPosPrinterData::HandleFoodTotalPrice(std::string oldprice, int guige)
 {
     double price = atof(oldprice.c_str());
 
@@ -2209,7 +1659,7 @@ std::string CPosPrinter::HandleFoodTotalPrice(std::string oldprice, int guige)
     }
 }
 
-std::vector<std::string> CPosPrinter::HandleBiaoqianFoodname(std::string oldname, int nBiaoqianWidth)
+std::vector<std::string> CPosPrinterData::HandleBiaoqianFoodname(std::string oldname, int nBiaoqianWidth)
 {
     std::vector<std::string> newnameArray;
     int nHanzi, nZimu;

+ 73 - 0
zhipuzi_pos_windows/print/CPosPrinterData.h

@@ -0,0 +1,73 @@
+#pragma once
+
+#include "../pch/pch.h"
+#include "../zhipuzi/CWaimaiOrder.h"
+#include "../zhipuzi/CDiandanOrder.h"
+
+class ChufangPrinterContent
+{
+public:
+	std::string ip;
+	std::string data;
+};
+
+//这个类,负责把订单数据转化成打印格式,用于后续打印(这个类本身不处理打印,只处理数据格式)
+class CPosPrinterData
+{
+public:
+    CPosPrinterData();
+    ~CPosPrinterData();
+
+    std::string PrintWaimaiOrderShouyin(CWaimaiOrder& order);
+	std::string PrintWaimaiOrderBiaoqian(CWaimaiOrder& order);
+	std::vector<ChufangPrinterContent> PrintWaimaiOrderChufang(CWaimaiOrder& order);
+
+	std::string PrintDiandanOrderShouyin(CDiandanOrder& order);
+	std::string PrintDiandanOrderBiaoqian(CDiandanOrder& order);
+	std::vector<ChufangPrinterContent> PrintDiandanOrderChufang(CDiandanOrder& order);
+
+private:
+	//把要打印的内容,写到string里面
+	void WriteData(string msg);
+	void WriteBuf(const unsigned char* buf, int len);
+
+	//小票打印机和厨房打印的处理方法
+	int POS_Reset(void);
+	int POS_FeedLine(void);
+	int POS_Feed(void);
+	int POS_SetMotionUnit(int x, int y);
+
+	int POS_SET_MOVE_X();
+	int POS_MOVE_X();
+	int POS_SET_ABS_X(int x, int y);
+	int POS_SET_PRINT_AREA(int x, int y);
+
+	int POS_TextOut(string abc, bool is_double_width = false, bool is_double_height = false, int align_type = 0);
+	int POS_CutPaper();
+	void POS_OutQRCode(std::string dataString);
+	void POS_OutBmp(std::wstring ImagePath);
+
+	//标签打印机的处理方法
+	void BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection);
+	void BIAOQIAN_FORMFEED();
+	void BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_multiplication, int y_multiplication);
+	std::string BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication);
+	void BIAOQIAN_PRINT();
+	void BIAOQIAN_CLS();
+
+	//字符空格计算的辅助函数
+	void CalWord(string s,  int& nHanzi, int& nZimu);
+
+	//对小票打印和厨房打印的名字进行换行处理
+	std::vector<std::string> HandleFoodname(std::string oldname, int guige = 1);
+	std::string HandleFoodItemPrice(std::string oldprice, int guige = 1);
+	std::string HandleFoodQuantity(std::string oldquantity, int guige = 1);
+	std::string HandleFoodTotalPrice(std::string oldprice, int guige = 1);
+
+	//对标签打印的名字进行换行处理
+	std::vector<std::string> HandleBiaoqianFoodname(std::string oldname, int nBiaoqianWdith);
+
+private:
+	//把所有打印命令汇总到一起,然后一次性发送给打印机,这个变量用来存储一个订单的所有命令
+	std::string m_print_content;
+};

+ 705 - 0
zhipuzi_pos_windows/print/CPosPrinterQueue.cpp

@@ -0,0 +1,705 @@
+#include "../pch/pch.h"
+#include "CPosPrinterQueue.h"
+
+#include "../helper/CComHelper.h"
+
+CPosPrinterQueue::CPosPrinterQueue()
+{
+}
+
+
+void CPosPrinterQueue::StartWork()
+{
+	m_is_work = true;
+
+	m_nStopNum = 0;
+
+	//处理收银打印
+	std::thread(&CPosPrinterQueue::HandleShouyinPrinter, this).detach();
+
+	//处理标签打印
+	std::thread(&CPosPrinterQueue::HandleBiaoqianPrinter, this).detach();
+
+	//处理厨房打印
+	std::thread(&CPosPrinterQueue::HandleChufangPrinter, this).detach();
+}
+
+void CPosPrinterQueue::StopWork()
+{
+	m_is_work = false;
+
+	m_shouyin_printer_mutex.lock();
+	while (!m_shouyin_printer_queue.empty())
+	{
+		m_shouyin_printer_queue.pop();
+	}
+	m_shouyin_printer_mutex.unlock();
+
+	m_biaoqian_printer_mutex.lock();
+	while (!m_biaoqian_printer_queue.empty())
+	{
+		m_biaoqian_printer_queue.pop();
+	}
+	m_biaoqian_printer_mutex.unlock();
+
+	m_chufang_printer_mutex.lock();
+	while (!m_chufang_printer_queue.empty())
+	{
+		m_chufang_printer_queue.pop();
+	}
+	m_chufang_printer_mutex.unlock();
+}
+
+void CPosPrinterQueue::AddShouyinPrinter(std::string chufang_data)
+{
+	m_shouyin_printer_mutex.lock();
+
+	m_shouyin_printer_queue.push(chufang_data);
+
+	m_shouyin_printer_mutex.unlock();
+}
+
+void CPosPrinterQueue::AddBiaoqianPrinter(std::string data)
+{
+	m_biaoqian_printer_mutex.lock();
+
+	m_biaoqian_printer_queue.push(data);
+
+	m_biaoqian_printer_mutex.unlock();
+}
+
+void CPosPrinterQueue::AddChufangPrinter(ChufangPrinterContent data)
+{
+	m_chufang_printer_mutex.lock();
+
+	m_chufang_printer_queue.push(data);
+
+	m_chufang_printer_mutex.unlock();
+}
+
+void CPosPrinterQueue::HandleShouyinPrinter()
+{
+	while (m_is_work)
+	{
+		m_shouyin_printer_mutex.lock();
+
+		if (m_shouyin_printer_queue.empty())
+		{
+			m_shouyin_printer_mutex.unlock();
+
+			CSystem::my_sleep(1);
+			continue;
+		}
+
+		std::string data = m_shouyin_printer_queue.front();
+
+		m_shouyin_printer_queue.pop();
+
+		m_shouyin_printer_mutex.unlock();
+
+		SendDataToShouyinPirnter(data);
+	}
+
+	AddStopNum();
+}
+
+void CPosPrinterQueue::HandleBiaoqianPrinter()
+{
+	while (m_is_work)
+	{
+		m_biaoqian_printer_mutex.lock();
+
+		if (m_biaoqian_printer_queue.empty())
+		{
+			m_biaoqian_printer_mutex.unlock();
+
+			CSystem::my_sleep(1);
+			continue;
+		}
+
+		std::string data = m_biaoqian_printer_queue.front();
+
+		m_biaoqian_printer_queue.pop();
+
+		m_biaoqian_printer_mutex.unlock();
+
+		SendDataToBiaoqianPirnter(data);
+	}
+
+	AddStopNum();
+}
+
+void CPosPrinterQueue::HandleChufangPrinter()
+{
+	while (m_is_work)
+	{
+		m_chufang_printer_mutex.lock();
+
+		if (m_chufang_printer_queue.empty())
+		{
+			m_chufang_printer_mutex.unlock();
+
+			CSystem::my_sleep(1);
+			continue;
+		}
+
+		ChufangPrinterContent chufang_data = m_chufang_printer_queue.front();
+
+		m_chufang_printer_queue.pop();
+
+		m_chufang_printer_mutex.unlock();
+
+		SendDataToChufangPirnter(chufang_data);
+	}
+
+	AddStopNum();
+}
+
+void CPosPrinterQueue::AddStopNum()
+{
+	m_nStopNumMutex.lock();
+
+	m_nStopNum++;
+
+	m_nStopNumMutex.unlock();
+
+	if (m_nStopNum == 8)
+	{
+		//确认所有子线程都退出了,再删除自己
+		delete this;
+	}
+}
+
+void CPosPrinterQueue::SendDataToShouyinPirnter(std::string data)
+{
+	//默认是句柄模式
+	int nType = 1;
+
+	//用于厨房打印机和网口类型的收银小票打印
+	boost::asio::io_service m_io;
+	boost::asio::ip::tcp::socket m_socket(m_io);
+
+	std::string printer_leixing = CSetting::GetParam("setting_printer_leixing");
+
+	if (printer_leixing == "auto")
+	{
+		InitUsb();
+
+		if (m_hShouyinPorts.size() == 0)
+		{
+			return;
+		}
+	}
+	else if (printer_leixing == "usb")
+	{
+		std::string printer_usb = CSetting::GetParam("setting_printer_usb");
+		std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
+
+		bool ret = InitOneUsb(ws_printer_usb, 1);
+		if (ret == false)
+		{
+			return;
+		}
+	}
+	else if (printer_leixing == "bingkou")
+	{
+		bool ret = InitBingkou();
+		if (ret == false)
+		{
+			return;
+		}
+	}
+	else if (printer_leixing == "chuankou")
+	{
+		InitCom();
+	}
+	else if (printer_leixing == "wangkou")
+	{
+		//改为网口模式
+		nType = 2;
+
+		std::string wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
+
+		//初始化连接
+		try
+		{
+			boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(wangkou_ip.c_str()), 9100);
+			m_socket.connect(ep);
+		}
+		catch (std::exception& e)
+		{
+			std::string err = e.what();
+			LOG_INFO("网口打印机连接失败,IP地址:" << wangkou_ip.c_str() << ",错误信息:" << err.c_str());
+
+			MessageBoxW(NULL, (L"厨房网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(wangkou_ip)).c_str(), L"打印机连接失败", MB_OK);
+			return;
+		}
+	}
+
+	//开始发送数据
+	if (nType == 1)
+	{
+		//USB、串口、并口,走这里
+		for (std::vector<HANDLE>::iterator it = m_hShouyinPorts.begin(); it != m_hShouyinPorts.end(); it++)
+		{
+			HANDLE hPort = *it;
+
+			//同步写数据
+			DWORD dwWrite;
+
+			BOOL ret = WriteFile(hPort, data.c_str(), data.length(), &dwWrite, NULL);
+			if (!ret)
+			{
+				LOG_INFO("WriteFile Failed!, hPort:" << hPort);
+			}
+		}
+	}
+	else
+	{
+		//网口走这里
+		try
+		{
+			m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
+		}
+		catch (const std::exception& e)
+		{
+			LOG_INFO("网口打印机发送消息失败,错误信息:" << e.what());
+		}
+	}
+
+	//关闭设备
+	for (std::vector<HANDLE>::iterator it = m_hShouyinPorts.begin(); it != m_hShouyinPorts.end(); it++)
+	{
+		CloseHandle(*it);
+	}
+
+	//删除之前旧的句柄
+	m_hShouyinPorts.clear();
+
+	if (nType == 2)
+	{
+		m_socket.close();
+	}
+}
+
+void CPosPrinterQueue::SendDataToBiaoqianPirnter(std::string data)
+{
+	std::string printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
+	std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
+
+	//连接usb端口
+	bool ret = InitOneUsb(ws_printer_usb, 2);
+	if (ret == false)
+	{
+		return;
+	}
+
+	//USB、串口、并口,走这里
+	for (std::vector<HANDLE>::iterator it = m_hBiaoqianPorts.begin(); it != m_hBiaoqianPorts.end(); it++)
+	{
+		HANDLE hPort = *it;
+
+		//同步写数据
+		DWORD dwWrite;
+
+		BOOL ret = WriteFile(hPort, data.c_str(), data.length(), &dwWrite, NULL);
+		if (!ret)
+		{
+			LOG_INFO("WriteFile Failed!, hPort:" << hPort);
+		}
+	}
+
+	//关闭设备
+	for (std::vector<HANDLE>::iterator it = m_hBiaoqianPorts.begin(); it != m_hBiaoqianPorts.end(); it++)
+	{
+		CloseHandle(*it);
+	}
+
+	m_hBiaoqianPorts.clear();
+}
+
+void CPosPrinterQueue::SendDataToChufangPirnter(ChufangPrinterContent chufang_data)
+{
+	boost::asio::io_service m_io;
+	boost::asio::ip::tcp::socket m_socket(m_io);
+
+	//读取厨房打印机信息
+	std::vector<ChufangPrinter> total_printers = CSetting::getChufangPrints();
+
+	std::string ip = chufang_data.ip;
+	std::string data = chufang_data.data;
+
+	//初始化连接
+	try
+	{
+		boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(ip.c_str()), 9100);
+		m_socket.connect(ep);
+	}
+	catch (std::exception& e)
+	{
+		std::string err = e.what();
+		LOG_INFO("厨房网口打印机连接失败,IP地址:" << ip.c_str() << ",错误信息:" << err.c_str());
+
+		MessageBoxW(NULL, (L"厨房网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(ip)).c_str(), L"打印机连接失败", MB_OK);
+
+		//连接失败了,处理下一个厨房打印机
+		return;
+	}
+
+	//网口走这里
+	try
+	{
+		m_socket.write_some(boost::asio::buffer(data.c_str(), data.length()));
+	}
+	catch (const std::exception& e)
+	{
+		LOG_INFO("网口打印机发送消息失败,错误信息:" << e.what());
+	}
+
+	m_socket.close();
+}
+
+/*
+ *usbType是1表示只查找收银小票打印机,会排除已知的标签打印机
+ *usbType为2表示所有usb打印机都查找,包含标签与非标签
+ **/
+void CPosPrinterQueue::InitUsb()
+{
+	//设置中文字符
+	setlocale(LC_CTYPE, "chs");
+
+	//取设备路径
+	int nDevice = GetDevicePath((LPGUID)&USB_GUID);
+	LOG_INFO("可用的USB打印机数量:" << nDevice);
+
+	//添加usb端口
+	int i = 0;
+
+	while (i < nDevice)
+	{
+		std::string setting_biaoqian_printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
+		std::wstring ws_setting_biaoqian_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_biaoqian_printer_usb);
+
+		if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1" && ws_setting_biaoqian_printer_usb == m_usb_devices[i])
+		{
+			//碰到了一个标签打印机
+			i++;
+			continue;
+		}
+
+		LOG_INFO("准备打开端口 Port = " << m_usb_devices[i].c_str());
+
+		HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+		if (hPort == INVALID_HANDLE_VALUE)
+		{
+			LOG_INFO("打开USB端口失败, Port = " << m_usb_devices[i].c_str());
+
+			// 打开端口失败
+			DWORD error = GetLastError();
+
+			if (error == 2)
+			{
+				//没有指定的文件
+				LOG_INFO("没有找对对应的usb端口");
+			}
+			else if (error == 5)
+			{
+				LOG_INFO("usb端口被占用!");
+			}
+
+			continue;
+		}
+
+		LOG_INFO("打开usb端口成功,准备进行打印机检测! hPort:" << hPort);
+
+		m_hShouyinPorts.push_back(hPort);
+
+		i++;
+	}
+}
+
+bool CPosPrinterQueue::InitOneUsb(wstring usb_path, int nType)
+{
+	if (usb_path == L"")
+	{
+		return false;
+	}
+
+	HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+	if (hPort == INVALID_HANDLE_VALUE)
+	{
+		LOG_INFO("打开USB端口失败, Port = " << usb_path.c_str());
+
+		// 打开端口失败
+		DWORD error = GetLastError();
+
+		if (error == 2)
+		{
+			//没有指定的文件
+			LOG_INFO("没有找对对应的usb端口");
+		}
+		else if (error == 5)
+		{
+			LOG_INFO("usb端口被占用!");
+		}
+
+		return false;
+	}
+
+	LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
+
+	if (nType == 1)
+	{
+		m_hShouyinPorts.push_back(hPort);
+	}
+	else
+	{
+		m_hBiaoqianPorts.push_back(hPort);
+	}
+
+	return true;
+}
+
+bool CPosPrinterQueue::InitBingkou()
+{
+	std::wstring LptStr = L"lpt1";
+
+	HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+	if (hPort == INVALID_HANDLE_VALUE)
+	{
+		LOG_INFO("打开并口失败, Port = " << LptStr.c_str());
+
+		DWORD error = GetLastError();
+
+		if (error == 2)
+		{
+			//没有指定的文件
+			LOG_INFO("本机器没有并口!");
+		}
+		else if (error == 5)
+		{
+			LOG_INFO("并口被占用!");
+		}
+
+		return false;
+	}
+	else
+	{
+		//这个表示并口可以使用
+		LOG_INFO("找到并口,准备进行打印机检测! hPort:" << hPort);
+
+		m_hShouyinPorts.push_back(hPort);
+	}
+
+	return true;
+}
+
+void CPosPrinterQueue::InitCom()
+{
+	CComHelper helper;
+	std::vector<std::wstring> comVector = helper.getComPort();
+
+	for (std::vector<std::wstring>::iterator it = comVector.begin(); it != comVector.end(); it++)
+	{
+		std::wstring com2Str = *it;
+
+		HANDLE hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+		if (hPort == INVALID_HANDLE_VALUE)
+		{
+			DWORD error = GetLastError();
+
+			if (error == 2)
+			{
+				//没有指定的文件
+				LOG_INFO("没有找到对应的串口 " << com2Str.c_str());
+			}
+			else if (error == 5)
+			{
+				LOG_INFO("串口被占用 " << com2Str.c_str());
+			}
+		}
+		else
+		{
+			LOG_INFO(com2Str.c_str() << " success, handle:" << hPort);
+
+			//扎到了可用的串口,设置串口波特率
+			DCB dcb;
+			dcb.DCBlength = sizeof(dcb);
+			GetCommState(hPort, &dcb);
+
+			//佳博的串口打印机,默认是这个波特率
+			dcb.BaudRate = 19200;
+
+			if (!SetCommState(hPort, &dcb))
+			{
+				LOG_INFO("set baudRate failed!");
+
+				CloseHandle(hPort);
+				continue;
+			}
+
+			//设定通讯端口超时参数
+			COMMTIMEOUTS tmouts;
+			tmouts.ReadIntervalTimeout = 100;
+			tmouts.ReadTotalTimeoutMultiplier = 100;
+			tmouts.ReadTotalTimeoutConstant = 100;
+			tmouts.WriteTotalTimeoutConstant = 100;
+			tmouts.WriteTotalTimeoutMultiplier = 100;
+			SetCommTimeouts(hPort, &tmouts);
+
+			//设置端口缓冲
+			SetupComm(hPort, 1024, 1024);
+
+			//清除通讯端口缓存
+			PurgeComm(hPort, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
+
+			m_hShouyinPorts.push_back(hPort);
+		}
+	}
+}
+
+/*
+ *获取CreateFile的USB端口号
+ **/
+int CPosPrinterQueue::GetDevicePath(LPGUID lpGuid)
+{
+	HDEVINFO hDevInfoSet;
+	SP_DEVINFO_DATA spDevInfoData;
+	SP_DEVICE_INTERFACE_DATA ifData;
+	PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;
+	int nCount;
+	int nTotle;
+	BOOL bResult;
+
+	//这2个字符串,用于根据usb的名字对比是否为打印机设备
+	wstring strUSBPrint = TEXT("USB 打印支持");
+
+	//xp上是英文
+	wstring strUSBPrint_EN = L"USB Printing Support";
+
+	// 取得一个该GUID相关的设备信息集句柄
+	hDevInfoSet = ::SetupDiGetClassDevs(lpGuid,     // class GUID
+		NULL,                    // 无关键字
+		NULL,                    // 不指定父窗口句柄
+		DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);    // 目前存在的设备
+
+// 失败...
+	if (hDevInfoSet == INVALID_HANDLE_VALUE)
+	{
+		LOG_INFO("SetupDiGetClassDevs failed \r\n");
+		return 0;
+	}
+
+	// 申请设备接口数据空间
+	pDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)::GlobalAlloc(LMEM_ZEROINIT, INTERFACE_DETAIL_SIZE);
+	pDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
+	nTotle = -1;
+	nCount = 0;
+	bResult = TRUE;
+
+	// 设备序号=0,1,2... 逐一测试设备接口,到失败为止
+	while (bResult)
+	{
+		nTotle++;
+		spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+
+		// 枚举符合该GUID的设备接口
+		bResult = ::SetupDiEnumDeviceInfo(
+			hDevInfoSet,     // 设备信息集句柄
+			(ULONG)nTotle,   // 设备信息集里的设备序号
+			&spDevInfoData);        // 设备接口信息
+
+		if (bResult)
+		{
+			DWORD DataT;
+			TCHAR buf[MAX_PATH] = { 0 };
+			DWORD nSize = 0;
+
+			// get Friendly Name or Device Description
+			if (SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
+				SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
+			{
+			}
+			else if (SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
+				SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
+			{
+			}
+			else
+			{
+				lstrcpy(buf, _T("Unknown"));
+			}
+
+			wstring ws_buf = buf;
+
+			//是否是要找的设备类型
+			if (ws_buf != strUSBPrint && ws_buf != strUSBPrint_EN)
+			{
+				LOG_INFO("not good usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
+				continue;
+			}
+
+			LOG_INFO("good usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
+			ifData.cbSize = sizeof(ifData);
+
+			// 枚舉符合該GUID的設備接口
+			bResult = ::SetupDiEnumDeviceInterfaces(
+				hDevInfoSet,     // 設備信息集句柄
+				NULL,            // 不需額外的設備描述
+				lpGuid,          // GUID
+				(ULONG)nTotle,   // 設備信息集里的設備序號
+				&ifData);        // 設備接口信息
+
+			if (bResult)
+			{
+				// 取得该设备接口的细节(设备路径)
+				bResult = SetupDiGetInterfaceDeviceDetail(
+					hDevInfoSet,    // 设备信息集句柄
+					&ifData,        // 设备接口信息
+					pDetail,        // 设备接口细节(设备路径)
+					INTERFACE_DETAIL_SIZE,    // 输出缓冲区大小
+					NULL,           // 不需计算输出缓冲区大小(直接用设定值)
+					NULL);          // 不需额外的设备描述
+
+				if (bResult)
+				{
+					wstring DevicePath = pDetail->DevicePath;
+
+					wstring vid = DevicePath.substr(DevicePath.find(_T("vid_"), 0) + 4, 4);
+					wstring pid = DevicePath.substr(DevicePath.find(_T("pid_"), 0) + 4, 4);
+
+					LOG_INFO("Vid:" << vid.c_str() << ", Pid:" << pid.c_str());
+
+					// 复制设备路径到输出缓冲区
+					m_usb_devices.push_back(DevicePath);
+
+					// 调整计数值
+					nCount++;
+
+					LOG_INFO("Cnt = " << nCount << ",pDetail->DevicePath =" << pDetail->DevicePath);
+				}
+			}
+		}
+		else
+		{
+			//LOG_INFO("SetupDiEnumDeviceInfo FAILED!@");
+		}
+	}
+
+	// 释放设备接口数据空间
+	::GlobalFree(pDetail);
+
+	// 关闭设备信息集句柄
+	::SetupDiDestroyDeviceInfoList(hDevInfoSet);
+	return nCount;
+}
+
+std::vector<std::wstring> CPosPrinterQueue::getUsbDevices()
+{
+	InitUsb();
+
+	return m_usb_devices;
+}

+ 91 - 0
zhipuzi_pos_windows/print/CPosPrinterQueue.h

@@ -0,0 +1,91 @@
+#pragma once
+
+#include "../pch/pch.h"
+
+#include "CPosPrinterData.h"
+
+//SetupDiGetInterfaceDeviceDetail所需要的输出长度,定义足够大
+#define INTERFACE_DETAIL_SIZE 1024
+
+//设备数量上限,假设16台上限
+#define MAX_DEVICE 16
+
+//USB类的GUID,通过这个去找USB打印机
+const GUID USB_GUID = { 0x28d78fad, 0x5a12, 0x11d1, {0xae, 0x5b, 0x00, 0x00, 0xf8, 0x03, 0xa8, 0xc2 } };
+
+//这个类采用队列的模式,执行把数据发送给打印机,注意这个类只负责发送,不负责数据内容的组装
+class CPosPrinterQueue
+{
+public:
+	static CPosPrinterQueue* GetInstance()
+	{
+		static CPosPrinterQueue instance;
+
+		return &instance;
+	}
+
+	//启动工作线程
+	void StartWork();
+
+	//结束工作线程
+	void StopWork();
+
+	//把打印数据添加到消息队列
+	void AddShouyinPrinter(std::string data);
+	void AddBiaoqianPrinter(std::string data);
+	void AddChufangPrinter(ChufangPrinterContent chufang_data);
+
+	//从队列中读数据
+	void HandleShouyinPrinter();
+	void HandleBiaoqianPrinter();
+	void HandleChufangPrinter();
+
+	//执行实际的数据往打印机的发送
+	void SendDataToShouyinPirnter(std::string data);
+	void SendDataToBiaoqianPirnter(std::string data);
+	void SendDataToChufangPirnter(ChufangPrinterContent chufang_data);
+
+	//获取当前电脑上所有的打印usb设备
+	std::vector<std::wstring> getUsbDevices();
+
+private:
+	CPosPrinterQueue();
+
+	//usb打印机的类型 1:收银小票打印机 2:标签打印机
+	void InitUsb();
+
+	//打开某一个指定的usb端口
+	//nType 1 收银打印 2标签打印
+	bool InitOneUsb(wstring usb_path, int nType);
+
+	bool InitBingkou();
+	void InitCom();
+
+	//获取USB打印机的路径
+	int GetDevicePath(LPGUID lpGuid);
+
+	void AddStopNum();
+
+private:
+	std::queue<std::string> m_shouyin_printer_queue;
+	std::queue<std::string> m_biaoqian_printer_queue;
+	std::queue<ChufangPrinterContent> m_chufang_printer_queue;
+
+	std::mutex m_shouyin_printer_mutex;
+	std::mutex m_biaoqian_printer_mutex;
+	std::mutex m_chufang_printer_mutex;
+
+	bool m_is_work;
+
+	int m_nStopNum = 0;
+	std::mutex m_nStopNumMutex;
+
+	//收银小票打印的句柄组合
+	std::vector<HANDLE> m_hShouyinPorts;
+
+	//标签小票打印的句柄组合
+	std::vector<HANDLE> m_hBiaoqianPorts;
+
+	//usb打印机的描述集合,用于设置中心展示所有可选的打印机
+	std::vector<std::wstring> m_usb_devices;
+};

+ 0 - 107
zhipuzi_pos_windows/tool/CPosPrinter.h

@@ -1,107 +0,0 @@
-#pragma once
-
-#include "../pch/pch.h"
-#include "../zhipuzi/CWaimaiOrder.h"
-
-//SetupDiGetInterfaceDeviceDetail所需要的输出长度,定义足够大
-#define INTERFACE_DETAIL_SIZE 1024
-
-//设备数量上限,假设16台上限
-#define MAX_DEVICE 16
-
-//USB类的GUID,通过这个去找USB打印机
-const GUID USB_GUID = {0x28d78fad, 0x5a12, 0x11d1, {0xae, 0x5b, 0x00, 0x00, 0xf8, 0x03, 0xa8, 0xc2 }};
-
-//存储打印端口句柄的结构
-class PrinterHandle
-{
-public:
-	HANDLE hPort;
-	int type; //句柄类型 1:usb 2:并口 3:串口
-};
-
-class CPosPrinter
-{
-public:
-    CPosPrinter();
-    ~CPosPrinter();
-
-    void PrintWaimaiOrderShouyin(CWaimaiOrder& order);
-	void PrintWaimaiOrderBiaoqian(CWaimaiOrder& order);
-	void PrintWaimaiOrderChufang(CWaimaiOrder& order);
-
-	//usb打印机的类型 1:收银小票打印机 2:标签打印机
-	void InitUsb(int usbType = 1);
-	std::vector<std::wstring> getUsbDevices();
-
-private:
-	bool InitBingkou();
-	void InitCom();
-
-	void InitShouyin();
-
-	//打开某一个指定的usb端口
-	bool InitOneUsb(wstring usb_path);
-
-	//usb打印机的类型 1:收银小票打印机 2:标签打印机
-	int GetDevicePath(LPGUID lpGuid, int usbType);
-
-	//判断usb打印机是小票打印机还是标签打印机
-	int GetPrinterType(wstring vid, wstring pid);
-
-	int WriteData(string meg);
-	int WriteBuf(const unsigned char* buf, int len);
-
-	//端口连通性测试
-	bool PortTest(HANDLE hPort);
-
-	//小票打印机和厨房打印的处理方法
-	int POS_Reset(void);
-	int POS_FeedLine(void);
-	int POS_Feed(void);
-	int POS_SetMotionUnit(int x, int y);
-
-	int POS_SET_MOVE_X();
-	int POS_MOVE_X();
-	int POS_SET_ABS_X(int x, int y);
-	int POS_SET_PRINT_AREA(int x, int y);
-
-	int POS_TextOut(string abc, bool is_double_width = false, bool is_double_height = false, int align_type = 0);
-	int POS_CutPaper();
-	void POS_OutQRCode(std::string dataString);
-	void POS_OutBmp(std::wstring ImagePath);
-
-	//标签打印机的处理方法
-	void BIAOQIAN_Reset(int nWidth, int nHeight, int nDirection);
-	void BIAOQIAN_FORMFEED();
-	void BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_multiplication, int y_multiplication);
-	std::string BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication);
-	void BIAOQIAN_PRINT();
-	void BIAOQIAN_CLS();
-
-	//字符空格计算的辅助函数
-	void CalWord(string s,  int& nHanzi, int& nZimu);
-
-	//对小票打印和厨房打印的名字进行换行处理
-	std::vector<std::string> HandleFoodname(std::string oldname, int guige = 1);
-	std::string HandleFoodItemPrice(std::string oldprice, int guige = 1);
-	std::string HandleFoodQuantity(std::string oldquantity, int guige = 1);
-	std::string HandleFoodTotalPrice(std::string oldprice, int guige = 1);
-
-	//对标签打印的名字进行换行处理
-	std::vector<std::string> HandleBiaoqianFoodname(std::string oldname, int nBiaoqianWdith);
-
-private:
-	//收银小票打印的句柄组合
-	std::vector<PrinterHandle> m_hPorts;
-
-	//用于厨房打印机和网口类型的收银小票打印
-	boost::asio::io_service m_io;
-	boost::asio::ip::tcp::socket m_socket;
-
-	//这个是当前的输出模式,是CreateFile模式,还是socket模式
-	int m_type;
-
-	//usb打印机的描述
-	std::vector<std::wstring> m_usb_devices;
-};

+ 1 - 2
zhipuzi_pos_windows/tool/CSqlite3.h

@@ -61,5 +61,4 @@ private:
 	int m_rc;
 
 	sqlite3* m_db = NULL;
-};
-
+};

+ 1 - 0
zhipuzi_pos_windows/tool/readme.txt

@@ -0,0 +1 @@
+tool目录下,存放一些与业务逻辑有关的,比如打印、参数设置等操作

+ 1 - 1
zhipuzi_pos_windows/wnd/CChengzhongWnd.h

@@ -2,7 +2,7 @@
 
 #include "../pch/pch.h"
 #include "CMainWnd.h"
-#include "../tool/CSerialPort.h"
+#include "../helper/CSerialPort.h"
 #include "CModalWnd.h"
 
 class CChengzhongWnd : public CModalWnd

+ 1 - 2
zhipuzi_pos_windows/wnd/CDiandanNatureWnd.cpp

@@ -197,9 +197,8 @@ void CDiandanNatureWnd::Notify(TNotifyUI& msg)
 	{
 		DuiLib::CDuiString senderName = msg.pSender->GetName();
 
-		if (senderName == _T("diandan_nature_closebtn"))
+		if (senderName == _T("closebtn"))
 		{
-			//商品属性暂时不支持退出
 			Close(IDCANCEL);
 			return;
 		}

+ 7 - 0
zhipuzi_pos_windows/wnd/CMainWnd.cpp

@@ -6,6 +6,7 @@
 #include "../page/CWaimaiOrderInfoPageUI.h"
 
 #include "../network/CMessagePush.h"
+#include "../print/CPosPrinter.h"
 
 #include <urlmon.h>
 
@@ -35,6 +36,9 @@ void CMainWnd::Init()
     m_push = new CMessagePush(m_hWnd);
     m_push->Start();
 
+	//启动打印队列
+	CPosPrinterQueue::GetInstance()->StartWork();
+
 	//启动一个线程,开始同步商品图片
 	std::thread(&CMainWnd::UpdateFoodImage, this).detach();
 }
@@ -552,6 +556,9 @@ LRESULT CMainWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHand
 {
     //直接退出程序,或者退出登录都会执行这个
     m_push->Stop();
+
+	CPosPrinterQueue::GetInstance()->StopWork();
+
     bHandled = FALSE;
     return 0;
 }

+ 0 - 1
zhipuzi_pos_windows/wnd/CMainWnd.h

@@ -4,7 +4,6 @@
 
 #include "../control/CWaimaiOrderItemUI.h"
 #include "../zhipuzi/CWaimaiOrder.h"
-#include "../tool/CPosPrinter.h"
 
 #include "../page/CBasePageUI.h"
 

+ 3 - 1
zhipuzi_pos_windows/zhipuzi/CDiandanOrder.h

@@ -23,10 +23,12 @@ public:
 
 	std::string m_guadan_time;
 
-private:
 	//订单的整单备注
 	std::string m_memo;
 
+	//下面这些是专门用于打印的参数,不作为其他用途
+
+
 public:
 
 	int getItemNum();

+ 20 - 12
zhipuzi_pos_windows/zhipuzi_pos_windows.vcxproj

@@ -225,10 +225,12 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="print\CPosPrinter.h" />
+    <ClInclude Include="print\CPosPrinterQueue.h" />
     <ClInclude Include="wnd\CGuadanWnd.h" />
     <ClInclude Include="wnd\CModalWnd.h" />
     <ClInclude Include="wnd\CChengzhongWnd.h" />
-    <ClInclude Include="tool\CSerialPort.h" />
+    <ClInclude Include="helper\CSerialPort.h" />
     <ClInclude Include="wnd\CZidingyiShoukuanWnd.h" />
     <ClInclude Include="wnd\CToastWnd.h" />
     <ClInclude Include="wnd\CFulikaShoukuanWnd.h" />
@@ -259,8 +261,8 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClInclude Include="control\CDiandanFoodItemUI.h" />
     <ClInclude Include="helper\CBitmapHelper.h" />
     <ClInclude Include="network\CZhipuziHttpProxy.h" />
-    <ClInclude Include="tool\CComHelper.h" />
-    <ClInclude Include="tool\CExceptionDmp.h" />
+    <ClInclude Include="helper\CComHelper.h" />
+    <ClInclude Include="helper\CExceptionDmp.h" />
     <ClInclude Include="wnd\CMessageboxWnd.h" />
     <ClInclude Include="wnd\CUpdateWnd.h" />
     <ClInclude Include="wnd\CWaimaiOrderFailReasonWnd.h" />
@@ -276,7 +278,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClInclude Include="zhipuzi\CFoodpackage.h" />
     <ClInclude Include="zhipuzi\CFoodtype.h" />
     <ClInclude Include="zhipuzi\CWaimaiOrder.h" />
-    <ClInclude Include="tool\CPosPrinter.h" />
+    <ClInclude Include="print\CPosPrinterData.h" />
     <ClInclude Include="control\CWaimaiOrderItemUI.h" />
     <ClInclude Include="wnd\CMainWnd.h" />
     <ClInclude Include="wnd\CLoginWnd.h" />
@@ -288,16 +290,18 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClInclude Include="network\CHttpClient.h" />
     <ClInclude Include="control\ControlEx.h" />
     <ClInclude Include="resource\resource.h" />
-    <ClInclude Include="tool\CLewaimaiLog.h" />
+    <ClInclude Include="helper\CLewaimaiLog.h" />
     <ClInclude Include="pch\pch.h" />
-    <ClInclude Include="tool\CLewaimaiTime.h" />
+    <ClInclude Include="helper\CLewaimaiTime.h" />
     <ClInclude Include="helper\CSystem.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="print\CPosPrinter.cpp" />
+    <ClCompile Include="print\CPosPrinterQueue.cpp" />
     <ClCompile Include="wnd\CGuadanWnd.cpp" />
     <ClCompile Include="wnd\CModalWnd.cpp" />
     <ClCompile Include="wnd\CChengzhongWnd.cpp" />
-    <ClCompile Include="tool\CSerialPort.cpp" />
+    <ClCompile Include="helper\CSerialPort.cpp" />
     <ClCompile Include="wnd\CZidingyiShoukuanWnd.cpp" />
     <ClCompile Include="wnd\CToastWnd.cpp" />
     <ClCompile Include="wnd\CFulikaShoukuanWnd.cpp" />
@@ -326,8 +330,8 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClCompile Include="helper\CLewaimaiJson.cpp" />
     <ClCompile Include="control\CDiandanFoodItemUI.cpp" />
     <ClCompile Include="helper\CBitmapHelper.cpp" />
-    <ClCompile Include="tool\CComHelper.cpp" />
-    <ClCompile Include="tool\CExceptionDmp.cpp" />
+    <ClCompile Include="helper\CComHelper.cpp" />
+    <ClCompile Include="helper\CExceptionDmp.cpp" />
     <ClCompile Include="wnd\CMessageboxWnd.cpp" />
     <ClCompile Include="wnd\CUpdateWnd.cpp" />
     <ClCompile Include="wnd\CWaimaiOrderFailReasonWnd.cpp" />
@@ -339,7 +343,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClCompile Include="network\CMessagePush.cpp" />
     <ClCompile Include="zhipuzi\CDiandanOrder.cpp" />
     <ClCompile Include="zhipuzi\CWaimaiOrder.cpp" />
-    <ClCompile Include="tool\CPosPrinter.cpp" />
+    <ClCompile Include="print\CPosPrinterData.cpp" />
     <ClCompile Include="control\CWaimaiOrderItemUI.cpp" />
     <ClCompile Include="wnd\CMainWnd.cpp" />
     <ClCompile Include="wnd\CLoginWnd.cpp" />
@@ -349,10 +353,10 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClCompile Include="helper\CRandomHelper.cpp" />
     <ClCompile Include="helper\CSystem.cpp" />
     <ClCompile Include="network\CHttpClient.cpp" />
-    <ClCompile Include="tool\CLewaimaiLog.cpp" />
+    <ClCompile Include="helper\CLewaimaiLog.cpp" />
     <ClCompile Include="zhipuzi_pos_windows.cpp" />
     <ClCompile Include="pch\pch.cpp" />
-    <ClCompile Include="tool\CLewaimaiTime.cpp" />
+    <ClCompile Include="helper\CLewaimaiTime.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="resource\zhipuzi_pos_windows.rc" />
@@ -363,6 +367,10 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
   <ItemGroup>
     <None Include="resource\zhipuzi_pos_windows.aps" />
   </ItemGroup>
+  <ItemGroup>
+    <Text Include="helper\readme.txt" />
+    <Text Include="tool\readme.txt" />
+  </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>

+ 52 - 36
zhipuzi_pos_windows/zhipuzi_pos_windows.vcxproj.filters

@@ -18,15 +18,9 @@
     <ClInclude Include="pch\pch.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="tool\CLewaimaiTime.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
     <ClInclude Include="helper\CSystem.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="tool\CLewaimaiLog.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
     <ClInclude Include="helper\CLewaimaiString.h">
       <Filter>头文件</Filter>
     </ClInclude>
@@ -45,9 +39,6 @@
     <ClInclude Include="resource\resource.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="tool\CPosPrinter.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
     <ClInclude Include="wnd\CMainWnd.h">
       <Filter>头文件</Filter>
     </ClInclude>
@@ -78,12 +69,6 @@
     <ClInclude Include="helper\CBitmapHelper.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="tool\CComHelper.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
-    <ClInclude Include="tool\CExceptionDmp.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
     <ClInclude Include="control\CDiandanFoodItemUI.h">
       <Filter>头文件</Filter>
     </ClInclude>
@@ -204,9 +189,6 @@
     <ClInclude Include="wnd\CZidingyiShoukuanWnd.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="tool\CSerialPort.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
     <ClInclude Include="wnd\CChengzhongWnd.h">
       <Filter>头文件</Filter>
     </ClInclude>
@@ -216,17 +198,35 @@
     <ClInclude Include="wnd\CGuadanWnd.h">
       <Filter>头文件</Filter>
     </ClInclude>
+    <ClInclude Include="helper\CComHelper.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="helper\CLewaimaiLog.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="helper\CLewaimaiTime.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="helper\CExceptionDmp.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="helper\CSerialPort.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="print\CPosPrinterData.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="print\CPosPrinterQueue.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
+    <ClInclude Include="print\CPosPrinter.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="pch\pch.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
-    <ClCompile Include="tool\CLewaimaiTime.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-    <ClCompile Include="tool\CLewaimaiLog.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
     <ClCompile Include="helper\CLewaimaiString.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
@@ -242,9 +242,6 @@
     <ClCompile Include="wnd\CLoginWnd.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
-    <ClCompile Include="tool\CPosPrinter.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
     <ClCompile Include="zhipuzi_pos_windows.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
@@ -275,12 +272,6 @@
     <ClCompile Include="helper\CBitmapHelper.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
-    <ClCompile Include="tool\CComHelper.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
-    <ClCompile Include="tool\CExceptionDmp.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
     <ClCompile Include="control\CDiandanFoodItemUI.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
@@ -383,9 +374,6 @@
     <ClCompile Include="wnd\CZidingyiShoukuanWnd.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
-    <ClCompile Include="tool\CSerialPort.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
     <ClCompile Include="wnd\CChengzhongWnd.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
@@ -395,6 +383,30 @@
     <ClCompile Include="wnd\CGuadanWnd.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="helper\CComHelper.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="helper\CLewaimaiLog.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="helper\CLewaimaiTime.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="helper\CExceptionDmp.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="helper\CSerialPort.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="print\CPosPrinterData.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="print\CPosPrinterQueue.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="print\CPosPrinter.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Image Include="resource\zhipuzi.ico">
@@ -409,4 +421,8 @@
   <ItemGroup>
     <None Include="resource\zhipuzi_pos_windows.aps" />
   </ItemGroup>
+  <ItemGroup>
+    <Text Include="helper\readme.txt" />
+    <Text Include="tool\readme.txt" />
+  </ItemGroup>
 </Project>