Explorar el Código

增加mqtt去重处理。

增加口袋打印
张洋 hace 1 año
padre
commit
ff367b686a

BIN
bin/Win32/Release/setup/lewaimai_pos_windows_setup_1.0.5.3.exe


+ 1 - 1
bin/Win32/Release/setup/乐外卖接单软件安装脚本.nsi

@@ -2,7 +2,7 @@
 
 ; HM NIS Edit Wizard helper defines
 !define PRODUCT_NAME "乐外卖接单软件"
-!define PRODUCT_VERSION "1.0.5.3"
+!define PRODUCT_VERSION "1.0.5.4"
 !define PRODUCT_PUBLISHER "深圳市迅享科技有限公司"
 !define PRODUCT_WEB_SITE "https://www.lewaimai.com"
 !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe"

+ 63 - 14
lewaimai_pos_windows/control/CWaimaiOrderInfoUI.cpp

@@ -20,25 +20,74 @@ void CWaimaiOrderInfoUI::Refresh(CWaimaiOrder& order)
 	CListUI* pFoodList = static_cast<CListUI*>(this->FindSubControl(_T("waimai_order_info_page_foodlist")));
 	pFoodList->RemoveAll();
 
-	for (std::vector<CWaimaiOrderItem>::iterator it = order.m_order_items.begin(); it != order.m_order_items.end(); it++)
+	for (std::map<std::string, std::vector<CWaimaiOrderItem>>::iterator itMap = order.m_order_koudai_items.begin(); itMap != order.m_order_koudai_items.end(); itMap++)
 	{
-		std::string food_name = (*it).m_food_name;
-		std::string food_price = (*it).m_item_price;
-		std::string quantity = (*it).m_quantity;
+		std::string koudai_id = itMap->first;
 
-		CDialogBuilder builder;
-		CListContainerElementUI* pEle = static_cast<CListContainerElementUI *>(builder.Create(_T("waimai_order_info_page_listitem.xml"), (UINT)0, NULL, m_pManager));
+		//接下来插入口袋信息
+		{
+			std::string food_name = CLewaimaiString::UnicodeToUTF8(L"*口袋") + koudai_id;
+			std::string food_price = "";
+			std::string quantity = "";
 
-		CLabelUI *pName = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_foodname")));
-		pName->SetText(CLewaimaiString::UTF8ToUnicode(food_name).c_str());
+			CDialogBuilder builder;
+			CListContainerElementUI* pEle = static_cast<CListContainerElementUI *>(builder.Create(_T("waimai_order_info_page_listitem.xml"), (UINT)0, NULL, m_pManager));
 
-		CLabelUI *pQuantity = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_quantity")));
-		pQuantity->SetText(CLewaimaiString::UTF8ToUnicode(quantity).c_str());
+			CLabelUI *pName = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_foodname")));
+			pName->SetText(CLewaimaiString::UTF8ToUnicode(food_name).c_str());
 
-		CLabelUI *pPrice = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_price")));
-		pPrice->SetText(CLewaimaiString::UTF8ToUnicode(food_price).c_str());
+			CLabelUI *pQuantity = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_quantity")));
+			pQuantity->SetText(CLewaimaiString::UTF8ToUnicode(quantity).c_str());
 
-		pFoodList->Add(pEle);
+			CLabelUI *pPrice = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_price")));
+			pPrice->SetText(CLewaimaiString::UTF8ToUnicode(food_price).c_str());
+
+			pFoodList->Add(pEle);
+		}
+
+		std::vector<CWaimaiOrderItem> koudai_items = itMap->second;
+
+		for (std::vector<CWaimaiOrderItem>::iterator it = koudai_items.begin(); it != koudai_items.end(); it++)
+		{
+			std::string food_name = (*it).m_food_name;
+			std::string food_price = (*it).m_item_price;
+			std::string quantity = (*it).m_quantity;
+
+			CDialogBuilder builder;
+			CListContainerElementUI* pEle = static_cast<CListContainerElementUI *>(builder.Create(_T("waimai_order_info_page_listitem.xml"), (UINT)0, NULL, m_pManager));
+
+			CLabelUI *pName = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_foodname")));
+			pName->SetText(CLewaimaiString::UTF8ToUnicode(food_name).c_str());
+
+			CLabelUI *pQuantity = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_quantity")));
+			pQuantity->SetText(CLewaimaiString::UTF8ToUnicode(quantity).c_str());
+
+			CLabelUI *pPrice = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_price")));
+			pPrice->SetText(CLewaimaiString::UTF8ToUnicode(food_price).c_str());
+
+			pFoodList->Add(pEle);
+		}
+
+		//插入空行
+		{
+			std::string food_name = "";
+			std::string food_price = "";
+			std::string quantity = "";
+
+			CDialogBuilder builder;
+			CListContainerElementUI* pEle = static_cast<CListContainerElementUI *>(builder.Create(_T("waimai_order_info_page_listitem.xml"), (UINT)0, NULL, m_pManager));
+
+			CLabelUI *pName = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_foodname")));
+			pName->SetText(CLewaimaiString::UTF8ToUnicode(food_name).c_str());
+
+			CLabelUI *pQuantity = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_quantity")));
+			pQuantity->SetText(CLewaimaiString::UTF8ToUnicode(quantity).c_str());
+
+			CLabelUI *pPrice = static_cast<CLabelUI *>(pEle->FindSubControl(_T("waimai_order_info_page_listitem_price")));
+			pPrice->SetText(CLewaimaiString::UTF8ToUnicode(food_price).c_str());
+
+			pFoodList->Add(pEle);
+		}
 	}
 
 	if (order.m_manzeng_name.length() > 0)
@@ -64,7 +113,7 @@ void CWaimaiOrderInfoUI::Refresh(CWaimaiOrder& order)
 	}
 
 	//重设商品列表的高度
-	int order_item_height = (order.m_order_items.size() + 1) * 30;
+	int order_item_height = (order.m_order_items.size() + order.m_order_koudai_items.size()*2 + 1) * 30;
 
 	if (order.m_manzeng_name.length() > 0)
 	{

+ 12 - 0
lewaimai_pos_windows/network/CMqttClient.cpp

@@ -25,6 +25,9 @@ void CMqttClient::Start()
 
     m_nStopNum = 0;
 
+	//先清空消息缓存
+	m_message_map.clear();
+
     //处理Mqtt消息接收
     std::thread(&CMqttClient::Run, this).detach();
 
@@ -300,6 +303,15 @@ void CMqttClient::HandleMessage(std::string message)
         return;
     }
 
+	//对消息重复进行判断,有时候mqtt会重复推送同一条消息
+	std::string message_id = CLewaimaiJson::ToString(document["message_id"]);
+	if (m_message_map.find(message_id) != m_message_map.end())
+	{
+		//说明消息重复了
+		return;
+	}
+	m_message_map[message_id] = "1";
+
 	//这个可以到时候用来判断是否消息过期,暂时不处理
 	std::string timestamp = CLewaimaiJson::ToString(document["timestamp"]);
 

+ 3 - 0
lewaimai_pos_windows/network/CMqttClient.h

@@ -88,6 +88,9 @@ private:
 
     HWND m_hwnd;
 
+	//ÓÃÀ´È¥ÖصÄ
+	std::map<std::string, std::string> m_message_map;
+
 public:
     CMqttClient(HWND hwnd);
 

+ 37 - 0
lewaimai_pos_windows/order/CWaimaiOrder.cpp

@@ -124,10 +124,13 @@ bool CWaimaiOrder::InitData(std::string order_id, std::string order_no)
 				newItem.m_type_id = CLewaimaiJson::ToString(v_row_i["type_id"]);
 				newItem.m_foodpackage_id = CLewaimaiJson::ToString(v_row_i["foodpackage_id"]);
 				newItem.m_is_foodpackage = CLewaimaiJson::ToString(v_row_i["is_foodpackage"]);
+				newItem.m_pocket_id = CLewaimaiJson::ToString(v_row_i["pocket_id"]);
 
 				m_order_items.push_back(newItem);
 			}
 
+			this->UpdateKoudaiItems();
+
 			//开始保存预设选项
 			v_rows = data["order_field"];
 
@@ -422,4 +425,38 @@ bool CWaimaiOrder::Refund(std::string order_id)
 	order_id = CLewaimaiJson::ToString(data["order_id"]);
 
 	return true;
+}
+
+void CWaimaiOrder::UpdateKoudaiItems()
+{
+	m_order_koudai_items.clear();
+
+	m_order_koudai_items = this->UpdateKoudaiItems(m_order_items);
+}
+
+std::map<std::string, std::vector<CWaimaiOrderItem>> CWaimaiOrder::UpdateKoudaiItems(std::vector<CWaimaiOrderItem> order_items)
+{
+	std::map<std::string, std::vector<CWaimaiOrderItem>> order_koudai_items;
+	order_koudai_items.clear();
+
+	for (std::vector<CWaimaiOrderItem>::iterator it = order_items.begin(); it != order_items.end(); it++)
+	{
+		std::string koudai_id = it->m_pocket_id;
+
+		if (order_koudai_items.find(koudai_id) == order_koudai_items.end())
+		{
+			//说明还没这个口袋ID
+			std::vector<CWaimaiOrderItem> newItemVector;
+			newItemVector.push_back(*it);
+
+			order_koudai_items[koudai_id] = newItemVector;
+		}
+		else
+		{
+			//说明已经有过这个口袋ID了
+			order_koudai_items[koudai_id].push_back(*it);
+		}
+	}
+
+	return order_koudai_items;
 }

+ 11 - 0
lewaimai_pos_windows/order/CWaimaiOrder.h

@@ -12,6 +12,7 @@ public:
 	std::string m_type_id;
 	std::string m_foodpackage_id;
 	std::string m_is_foodpackage;
+	std::string m_pocket_id; //口袋ID
 };
 
 class CWaimaiOrderField
@@ -38,6 +39,11 @@ public:
 
 	bool Refund(std::string order_id);
 
+	//根据原始订单详情,更新口袋的订单详情
+	void UpdateKoudaiItems();
+
+	std::map<std::string, std::vector<CWaimaiOrderItem>> UpdateKoudaiItems(std::vector<CWaimaiOrderItem> order_items);
+
 public:
 	std::string m_order_id;
 	std::string m_shop_id;
@@ -102,7 +108,12 @@ public:
 
 	std::string m_is_book;
 
+	//原始订单详情
 	std::vector<CWaimaiOrderItem> m_order_items;
+
+	//这个是按照口袋重组的订单详情,每个口袋的详情单独放一个数组
+	std::map<std::string, std::vector<CWaimaiOrderItem>> m_order_koudai_items;
+
 	std::vector<CWaimaiOrderField> m_order_field;
 	std::vector<CWaimaiOrderField> m_addservie;
 

BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.aps


BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.rc


+ 110 - 87
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -743,62 +743,73 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 		}
 
         //商品内容
-        for(std::vector<CWaimaiOrderItem>::iterator it = order.m_order_items.begin(); it != order.m_order_items.end(); it++)
-        {
-            std::string food_name = (*it).m_food_name;
-            std::string food_price = (*it).m_item_price;
-            std::string quantity = (*it).m_quantity;
+		for (std::map<std::string, std::vector<CWaimaiOrderItem>>::iterator itMap = order.m_order_koudai_items.begin(); itMap != order.m_order_koudai_items.end(); itMap++)
+		{
+			std::string koudai_id = itMap->first;
+
+			std::string koudai_content = "*口袋" + CLewaimaiString::UTF8ToANSI(koudai_id) + "";
+			POS_TextOut(koudai_content, true, true, 0);
+			POS_FeedLine();
 
-            //计算总价
-            double item_price = atof(food_price.c_str()) * atof(quantity.c_str());
-            std::string food_total_price = CLewaimaiString::DoubleToString(item_price, 2);
+			std::vector<CWaimaiOrderItem> koudai_items = itMap->second;
 
-			if (food_total_price == "0.00")
+			for (std::vector<CWaimaiOrderItem>::iterator it = koudai_items.begin(); it != koudai_items.end(); it++)
 			{
-				//这里是特殊处理满赠的展示
-				food_total_price = "";
-			}
+				std::string food_name = (*it).m_food_name;
+				std::string food_price = (*it).m_item_price;
+				std::string quantity = (*it).m_quantity;
 
-            food_name = CLewaimaiString::UTF8ToANSI(food_name);
+				//计算总价
+				double item_price = atof(food_price.c_str()) * atof(quantity.c_str());
+				std::string food_total_price = CLewaimaiString::DoubleToString(item_price, 2);
 
-            //先输出商品名字
-            std::vector<string> m_names;
+				if (food_total_price == "0.00")
+				{
+					//这里是特殊处理满赠的展示
+					food_total_price = "";
+				}
 
-            if(guige == "58")
-            {
-                m_names = HandleFoodname(food_name, 1);
-            }
-            else
-            {
-                m_names = HandleFoodname(food_name, 2);
-            }
+				food_name = CLewaimaiString::UTF8ToANSI(food_name);
 
-            std::string firstLine = m_names[0];
-            int nGuige;
+				//先输出商品名字
+				std::vector<string> m_names;
 
-            if(guige == "58")
-            {
-                nGuige = 1;
-            }
-            else
-            {
-                nGuige = 2;
-            }
+				if (guige == "58")
+				{
+					m_names = HandleFoodname(food_name, 1);
+				}
+				else
+				{
+					m_names = HandleFoodname(food_name, 2);
+				}
 
-            std::string priceShow = HandleFoodItemPrice(food_price, nGuige);
-            std::string quantityShow = HandleFoodQuantity(quantity, nGuige);
-            std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, nGuige);
-            std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
+				std::string firstLine = m_names[0];
+				int nGuige;
 
-            POS_TextOut(firstLineShow, false, setting_printer_shangpin_big);
-            POS_FeedLine();
+				if (guige == "58")
+				{
+					nGuige = 1;
+				}
+				else
+				{
+					nGuige = 2;
+				}
 
-            for(std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
-            {
-                POS_TextOut((*it), false, setting_printer_shangpin_big);
-                POS_FeedLine();
-            }
-        }
+				std::string priceShow = HandleFoodItemPrice(food_price, nGuige);
+				std::string quantityShow = HandleFoodQuantity(quantity, nGuige);
+				std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, nGuige);
+				std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
+
+				POS_TextOut(firstLineShow, false, setting_printer_shangpin_big);
+				POS_FeedLine();
+
+				for (std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
+				{
+					POS_TextOut((*it), false, setting_printer_shangpin_big);
+					POS_FeedLine();
+				}
+			}
+		}
 
         //判断是否有备注
         if(order.m_memo.length() > 0)
@@ -1412,53 +1423,65 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
 
             POS_FeedLine();
 
-            //商品内容
-            for(std::vector<CWaimaiOrderItem>::iterator it = cur_printer_use.begin(); it != cur_printer_use.end(); it++)
-            {
-                std::string food_name = (*it).m_food_name;
-                std::string food_price = (*it).m_item_price;
-                std::string quantity = (*it).m_quantity;
-                //计算总价
-                double item_price = atof(food_price.c_str()) * atof(quantity.c_str());
-                std::string food_total_price = CLewaimaiString::DoubleToString(item_price, 2);
-                food_name = CLewaimaiString::UTF8ToANSI(food_name);
-                //先输出商品名字
-                std::vector<string> m_names;
+			//商品内容(厨房打印不分单的情况下,打印口袋信息)
+			std::map<std::string, std::vector<CWaimaiOrderItem>> cur_order_koudai_items = order.UpdateKoudaiItems(cur_printer_use);
+			for (std::map<std::string, std::vector<CWaimaiOrderItem>>::iterator itMap = cur_order_koudai_items.begin(); itMap != cur_order_koudai_items.end(); itMap++)
+			{
+				std::string koudai_id = itMap->first;
 
-                if(guige == "58")
-                {
-                    m_names = HandleFoodname(food_name, 1);
-                }
-                else
-                {
-                    m_names = HandleFoodname(food_name, 2);
-                }
+				std::string koudai_content = "*口袋" + CLewaimaiString::UTF8ToANSI(koudai_id) + "";
+				POS_TextOut(koudai_content, true, true, 0);
+				POS_FeedLine();
 
-                std::string firstLine = m_names[0];
-                int nGuige;
+				std::vector<CWaimaiOrderItem> koudai_items = itMap->second;
 
-                if(guige == "58")
-                {
-                    nGuige = 1;
-                }
-                else
-                {
-                    nGuige = 2;
-                }
+				for (std::vector<CWaimaiOrderItem>::iterator it = koudai_items.begin(); it != koudai_items.end(); it++)
+				{
+					std::string food_name = (*it).m_food_name;
+					std::string food_price = (*it).m_item_price;
+					std::string quantity = (*it).m_quantity;
+					//计算总价
+					double item_price = atof(food_price.c_str()) * atof(quantity.c_str());
+					std::string food_total_price = CLewaimaiString::DoubleToString(item_price, 2);
+					food_name = CLewaimaiString::UTF8ToANSI(food_name);
+					//先输出商品名字
+					std::vector<string> m_names;
+
+					if (guige == "58")
+					{
+						m_names = HandleFoodname(food_name, 1);
+					}
+					else
+					{
+						m_names = HandleFoodname(food_name, 2);
+					}
 
-                std::string priceShow = HandleFoodItemPrice(food_price, nGuige);
-                std::string quantityShow = HandleFoodQuantity(quantity, nGuige);
-                std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, nGuige);
-                std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
-                POS_TextOut(firstLineShow, false, true, 0);
-                POS_FeedLine();
+					std::string firstLine = m_names[0];
+					int nGuige;
 
-                for(std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
-                {
-                    POS_TextOut((*it), false, true, 0);
-                    POS_FeedLine();
-                }
-            }
+					if (guige == "58")
+					{
+						nGuige = 1;
+					}
+					else
+					{
+						nGuige = 2;
+					}
+
+					std::string priceShow = HandleFoodItemPrice(food_price, nGuige);
+					std::string quantityShow = HandleFoodQuantity(quantity, nGuige);
+					std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, nGuige);
+					std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
+					POS_TextOut(firstLineShow, false, true, 0);
+					POS_FeedLine();
+
+					for (std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
+					{
+						POS_TextOut((*it), false, true, 0);
+						POS_FeedLine();
+					}
+				}
+			}
 
             //判断是否有备注
             if(order.m_memo.length() > 0)