|
@@ -6,35 +6,22 @@
|
|
|
|
|
|
|
|
using boost::asio::ip::tcp;
|
|
using boost::asio::ip::tcp;
|
|
|
|
|
|
|
|
-CPosPrinter::CPosPrinter(int print_type): m_socket(m_io)
|
|
|
|
|
|
|
+CPosPrinter::CPosPrinter(): m_socket(m_io)
|
|
|
{
|
|
{
|
|
|
- m_type = print_type;
|
|
|
|
|
|
|
|
|
|
- if(print_type == 1)
|
|
|
|
|
- {
|
|
|
|
|
- Init();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- InitChufang();
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
CPosPrinter::~CPosPrinter()
|
|
CPosPrinter::~CPosPrinter()
|
|
|
{
|
|
{
|
|
|
- if (m_type == 2)
|
|
|
|
|
- {
|
|
|
|
|
- m_socket.close();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CPosPrinter::Init()
|
|
|
|
|
|
|
+bool CPosPrinter::InitShouyin()
|
|
|
{
|
|
{
|
|
|
//遍历USB设备,找到POS打印机路径
|
|
//遍历USB设备,找到POS打印机路径
|
|
|
//设备路径
|
|
//设备路径
|
|
|
- TCHAR * szDevicePath[MAX_DEVICE];
|
|
|
|
|
|
|
+ TCHAR* szDevicePath[MAX_DEVICE];
|
|
|
//设置中文字符
|
|
//设置中文字符
|
|
|
setlocale(LC_CTYPE, "chs");
|
|
setlocale(LC_CTYPE, "chs");
|
|
|
TCHAR* Port = NULL;
|
|
TCHAR* Port = NULL;
|
|
@@ -69,37 +56,26 @@ bool CPosPrinter::Init()
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool CPosPrinter::InitChufang()
|
|
|
|
|
|
|
+void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
{
|
|
{
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string("192.168.10.47"), 9100);
|
|
|
|
|
- m_socket.connect(ep);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //设置模式,后面输出数据不会错
|
|
|
|
|
+ m_type = 1;
|
|
|
|
|
|
|
|
- catch(std::exception& e)
|
|
|
|
|
|
|
+ //初始化收银打印机的链接
|
|
|
|
|
+ bool ret = InitShouyin();
|
|
|
|
|
+ if(ret == false)
|
|
|
{
|
|
{
|
|
|
- std::cout << e.what() << std::endl;
|
|
|
|
|
|
|
+ LOG_INFO("打开收银打印机端口失败!");
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return true;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void CPosPrinter::PrintWaimaiOrder(string order_id, std::string order_no)
|
|
|
|
|
-{
|
|
|
|
|
- CWaimaiOrder order;
|
|
|
|
|
- order.InitData(order_id, order_no);
|
|
|
|
|
-
|
|
|
|
|
- PrintWaimaiOrder(order);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-void CPosPrinter::PrintWaimaiOrder(CWaimaiOrder& order)
|
|
|
|
|
-{
|
|
|
|
|
|
|
+ //读取当前收银打印机的设置
|
|
|
std::string guige = CSetting::GetParam("setting_printer_guige");
|
|
std::string guige = CSetting::GetParam("setting_printer_guige");
|
|
|
- std::string lianshu = CSetting::GetParam("setting_printer_lianshu");
|
|
|
|
|
|
|
|
|
|
|
|
+ std::string lianshu = CSetting::GetParam("setting_printer_lianshu");
|
|
|
int n_lianshu = atoi(lianshu.c_str());
|
|
int n_lianshu = atoi(lianshu.c_str());
|
|
|
|
|
|
|
|
|
|
+ //正式开始打印
|
|
|
for(int i = 0; i < n_lianshu; i++)
|
|
for(int i = 0; i < n_lianshu; i++)
|
|
|
{
|
|
{
|
|
|
POS_Reset();
|
|
POS_Reset();
|
|
@@ -392,6 +368,289 @@ void CPosPrinter::PrintWaimaiOrder(CWaimaiOrder& order)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
|
|
|
|
|
+{
|
|
|
|
|
+ //设置模式,后面输出数据不会错
|
|
|
|
|
+ m_type = 2;
|
|
|
|
|
+
|
|
|
|
|
+ //读取厨房打印机信息
|
|
|
|
|
+ std::vector<ChufangPrinter> total_printers = CSetting::getChufangPrints();
|
|
|
|
|
+
|
|
|
|
|
+ for(std::vector<ChufangPrinter>::iterator it = total_printers.begin(); it != total_printers.end(); it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ 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());
|
|
|
|
|
+
|
|
|
|
|
+ //连接失败了,处理下一个厨房打印机
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ std::string guige = printer.guige;
|
|
|
|
|
+ std::string fendan = printer.fendan;
|
|
|
|
|
+ std::string fenlei = printer.fenlei;
|
|
|
|
|
+ std::string fenlei_ids = printer.fenlei_ids;
|
|
|
|
|
+
|
|
|
|
|
+ std::vector<CWaimaiOrderItem> cur_printer_use;
|
|
|
|
|
+ if(fenlei == "0")
|
|
|
|
|
+ {
|
|
|
|
|
+ cur_printer_use = order.m_order_items;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //如果开启了分类打印,就要比对了
|
|
|
|
|
+ std::map<string, bool> ids_map;
|
|
|
|
|
+ std::vector<string> ids = CLewaimaiString::Split(fenlei_ids, ",");
|
|
|
|
|
+ for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ ids_map[(*it)] = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for(std::vector<CWaimaiOrderItem>::iterator it = order.m_order_items.begin(); it != order.m_order_items.end(); it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(ids_map.find((*it).m_type_id) != ids_map.end())
|
|
|
|
|
+ {
|
|
|
|
|
+ //如果当前商品的分类,在厨房打印机设置的分类里面,才加入
|
|
|
|
|
+ cur_printer_use.push_back(*it);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(fendan == "0")
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_Reset();
|
|
|
|
|
+
|
|
|
|
|
+ POS_TextOut("派工单", true, 1);
|
|
|
|
|
+
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ //预设选项
|
|
|
|
|
+ if(order.m_order_field.size() > 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ for(std::vector<CWaimaiOrderField>::iterator it = order.m_order_field.begin(); it != order.m_order_field.end() - 1; it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ string order_field = CLewaimaiString::UTF8ToANSI((*it).name) + ":" + CLewaimaiString::UTF8ToANSI((*it).value);
|
|
|
|
|
+ POS_TextOut(order_field, false, 0);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //准备开始打印商品详情
|
|
|
|
|
+ string lines;
|
|
|
|
|
+
|
|
|
|
|
+ if(guige == "58")
|
|
|
|
|
+ {
|
|
|
|
|
+ lines = "--------------------------------";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ lines = "------------------------------------------------";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ POS_TextOut(lines);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ //商品标题
|
|
|
|
|
+ if(guige == "58")
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_TextOut("商品 单价 数量 金额");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_TextOut("商品 单价 数量 金额");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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;
|
|
|
|
|
+
|
|
|
|
|
+ if(guige == "58")
|
|
|
|
|
+ {
|
|
|
|
|
+ m_names = HandleFoodname(food_name, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ m_names = HandleFoodname(food_name, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ std::string firstLine = m_names[0];
|
|
|
|
|
+ std::string priceShow = HandleFoodItemPrice(food_price, 2);
|
|
|
|
|
+ std::string quantityShow = HandleFoodQuantity(quantity, 2);
|
|
|
|
|
+ std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, 2);
|
|
|
|
|
+
|
|
|
|
|
+ std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
|
|
|
|
|
+
|
|
|
|
|
+ POS_TextOut(firstLineShow, false, 0);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ for(std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_TextOut((*it), false, 0);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //判断是否有备注
|
|
|
|
|
+ if(order.m_memo.length() > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ string address = "顾客备注:" + CLewaimaiString::UTF8ToANSI(order.m_memo);
|
|
|
|
|
+ POS_TextOut(address, false, 0);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //结束商品详情打印
|
|
|
|
|
+ POS_TextOut(lines);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ POS_CutPaper();
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_Reset();
|
|
|
|
|
+
|
|
|
|
|
+ //分单模式下,每个商品打印一张单
|
|
|
|
|
+ for(std::vector<CWaimaiOrderItem>::iterator it = cur_printer_use.begin(); it != cur_printer_use.end(); it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_TextOut("派工单", true, 1);
|
|
|
|
|
+
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ //预设选项
|
|
|
|
|
+ if(order.m_order_field.size() > 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ for(std::vector<CWaimaiOrderField>::iterator it = order.m_order_field.begin(); it != order.m_order_field.end() - 1; it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ string order_field = CLewaimaiString::UTF8ToANSI((*it).name) + ":" + CLewaimaiString::UTF8ToANSI((*it).value);
|
|
|
|
|
+ POS_TextOut(order_field, false, 0);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //准备开始打印商品详情
|
|
|
|
|
+ string lines;
|
|
|
|
|
+
|
|
|
|
|
+ if(guige == "58")
|
|
|
|
|
+ {
|
|
|
|
|
+ lines = "--------------------------------";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ lines = "------------------------------------------------";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ POS_TextOut(lines);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ //商品标题
|
|
|
|
|
+ if(guige == "58")
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_TextOut("商品 单价 数量 金额");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_TextOut("商品 单价 数量 金额");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ 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 firstLine = m_names[0];
|
|
|
|
|
+ std::string priceShow = HandleFoodItemPrice(food_price, 2);
|
|
|
|
|
+ std::string quantityShow = HandleFoodQuantity(quantity, 2);
|
|
|
|
|
+ std::string priceTotalShow = HandleFoodTotalPrice(food_total_price, 2);
|
|
|
|
|
+
|
|
|
|
|
+ std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
|
|
|
|
|
+
|
|
|
|
|
+ POS_TextOut(firstLineShow, false, 0);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ for(std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_TextOut((*it), false, 0);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //判断是否有备注
|
|
|
|
|
+ if(order.m_memo.length() > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ string address = "顾客备注:" + CLewaimaiString::UTF8ToANSI(order.m_memo);
|
|
|
|
|
+ POS_TextOut(address, false, 0);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //结束商品详情打印
|
|
|
|
|
+ POS_TextOut(lines);
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ POS_FeedLine();
|
|
|
|
|
+
|
|
|
|
|
+ POS_CutPaper();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ m_socket.close();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
//获取CreateFile的USB端口号
|
|
//获取CreateFile的USB端口号
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
@@ -532,7 +791,7 @@ int CPosPrinter::WriteData(string msg)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int CPosPrinter::WriteBuf(char *buf, int len)
|
|
|
|
|
|
|
+int CPosPrinter::WriteBuf(char* buf, int len)
|
|
|
{
|
|
{
|
|
|
if(m_type == 1)
|
|
if(m_type == 1)
|
|
|
{
|
|
{
|