Commit 61dc935d by guanghui.cui

外卖小票打印

parent 92146f81
...@@ -52,4 +52,5 @@ storeId=pos_bft_SH002 ...@@ -52,4 +52,5 @@ storeId=pos_bft_SH002
operatorId=001 operatorId=001
[POSServer] [POSServer]
serverIp=192.168.0.102 serverIp=192.168.0.102
\ No newline at end of file storeName=避风塘(金玉兰店)
\ No newline at end of file
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonParseError> #include <QJsonParseError>
#include <QTextCodec>
#include <QDebug> #include <QDebug>
IniDataManger &IniDataManger::Instance() IniDataManger &IniDataManger::Instance()
...@@ -252,6 +253,7 @@ IniDataManger::IniDataManger() ...@@ -252,6 +253,7 @@ IniDataManger::IniDataManger()
QLOG_WARN() << QString("can't find ini file![%1]").arg(iniPath); QLOG_WARN() << QString("can't find ini file![%1]").arg(iniPath);
} }
m_set = new QSettings(iniPath, QSettings::IniFormat); m_set = new QSettings(iniPath, QSettings::IniFormat);
m_set->setIniCodec(QTextCodec::codecForName("UTF-8"));
iniPath = QString("%1/%2").arg(QApplication::applicationDirPath()).arg(USERINI_FILE_NAME); iniPath = QString("%1/%2").arg(QApplication::applicationDirPath()).arg(USERINI_FILE_NAME);
if(!QFile(iniPath).exists()) if(!QFile(iniPath).exists())
...@@ -298,3 +300,8 @@ QString IniDataManger::GetPOSServerIP() ...@@ -298,3 +300,8 @@ QString IniDataManger::GetPOSServerIP()
{ {
return m_set->value("POSServer/serverIp", "").toString(); return m_set->value("POSServer/serverIp", "").toString();
} }
QString IniDataManger::GetPOSStoreName()
{
return m_set->value("POSServer/storeName", "").toString();
}
...@@ -71,6 +71,7 @@ public: ...@@ -71,6 +71,7 @@ public:
QJsonObject GetStoreJson(); QJsonObject GetStoreJson();
QString GetTillFile(); QString GetTillFile();
QString GetPOSServerIP(); QString GetPOSServerIP();
QString GetPOSStoreName();
bool GetShowCancel(); bool GetShowCancel();
QString GetStoreIdPrefix(); QString GetStoreIdPrefix();
......
...@@ -39,24 +39,39 @@ WBillControl::WBillControl() ...@@ -39,24 +39,39 @@ WBillControl::WBillControl()
g_thread.start(); g_thread.start();
GetPosMenu(); GetPosMenu();
//test print //test print
//QString strTitle=IniDataManger::Instance().GetPOSStoreName();
OrderObject obj; OrderObject obj;
obj.channelName="美团外卖"; obj.channelName="美团外卖";
obj.order_id="3014384743591261407"; obj.order_id="3014384743591261407";
obj.order_index=56; obj.address="上海金巢铂瑞阁公寓合宝路18号金巢大厦金巢铂瑞阁公寓1116室";
obj.customer="钱多多";
obj.phone="15600833522";
obj.order_index=1;
obj.package_fee=600;
obj.send_fee=500;
obj.discount_fee=1300;
obj.user_fee=14701;
obj.channel="mtwm";
obj.pay_type="在线支付";
obj.create_time=1508640524;
ComdObject comd1; ComdObject comd1;
comd1.pid="061301"; comd1.pid="061301";
comd1.productAmount=4; comd1.productAmount=4;
comd1.price=123;
obj.proList.push_back(&comd1); obj.proList.push_back(&comd1);
ComdObject comd2; ComdObject comd2;
comd2.pid="006114"; comd2.pid="006114";
comd2.productAmount=1; comd2.productAmount=1;
comd2.price=45678;
obj.proList.push_back(&comd2); obj.proList.push_back(&comd2);
ComdObject comd3; ComdObject comd3;
comd3.pid="009091"; comd3.pid="009091";
comd3.productAmount=1; comd3.productAmount=1;
comd3.price=789;
obj.proList.push_back(&comd3); obj.proList.push_back(&comd3);
//PrintLable(&obj); //PrintLable(&obj);
printMenu(&obj); //printMenu(&obj);
printTakeout(&obj);
// printCook(&obj,"061301",4); // printCook(&obj,"061301",4);
// printCook(&obj,"006114",2); // printCook(&obj,"006114",2);
// printCook(&obj,"002561",4); // printCook(&obj,"002561",4);
...@@ -373,7 +388,7 @@ void WBillControl::printCook(const OrderObject *obj,const QString& menuId,int nu ...@@ -373,7 +388,7 @@ void WBillControl::printCook(const OrderObject *obj,const QString& menuId,int nu
strDesk+=obj->channelName; strDesk+=obj->channelName;
strDesk+=QString::number(obj->order_index); strDesk+=QString::number(obj->order_index);
std::string stdDesk=strDesk.toStdString(); std::string stdDesk=strDesk.toStdString();
print(charset_u2g(stdDesk).data(),6); print(charset_u2g(stdDesk).data(),8);
QString order="单据:"; QString order="单据:";
order+=obj->order_id; order+=obj->order_id;
...@@ -403,15 +418,112 @@ void WBillControl::printCook(const OrderObject *obj,const QString& menuId,int nu ...@@ -403,15 +418,112 @@ void WBillControl::printCook(const OrderObject *obj,const QString& menuId,int nu
} }
//外卖单打印 //外卖单打印
void WBillControl::printTakeout() void WBillControl::printTakeout(const OrderObject *obj)
{ {
#ifdef Q_OS_LINUX
int fd=-1;
for(int i=0; i < obj->proList.size(); i++)
{
QString pid=obj->proList.at(i)->pid;
int num = obj->proList.at(i)->productAmount;
int price =obj->proList.at(i)->price;
for(PrinterMenu menu:vecMenu){
if(menu.strMenuId==pid){
//订单头 打印
if(0==i){
fd = open_port("/dev/ttyS1");
set_port(fd,19200);
QString str=getPrintTitle(obj->channel,obj->order_index);
std::string title = str.toStdString();
print(charset_u2g(title).data(),3);
//QString strTitle=" 避风塘(金玉兰店)";
QString strTitle=" ";
strTitle+=IniDataManger::Instance().GetPOSStoreName();
std::string stdTitle=strTitle.toStdString();
print(charset_u2g(stdTitle).data(),3);
print("",1);
QString strPayType=" —";
strPayType+=obj->pay_type;
strPayType+="—";
std::string stdPaytype=strPayType.toStdString();
print(charset_u2g(stdPaytype).data(),3);
print("",1);
print("-----------------------------------------------",1);
QString strOrderTime= QDateTime::fromTime_t(1508640524).toString("下单时间:MM-dd hh:mm");
std::string stdOrderTime=strOrderTime.toStdString();
print(charset_u2g(stdOrderTime).data(),3);
print("-----------------------------------------------",1);
}
QByteArray menuName=QString("%1").arg(menu.strMenuName,-36).toLatin1();
menuName.append("x");
menuName.append(QString::number(num).toLatin1());
menuName.append(" ");
menuName.append(QString("%1").arg(QString::number(price/100.00,'f',2),6).toLatin1());
print(menuName.data(),5);
break;
}
}
}
if(-1!=fd){
print("-----------------------------------------------",1);
QString strPakage="餐盒 x1 ";
strPakage+=QString("%1").arg(QString::number(obj->package_fee/100.00,'f',2),6);
std::string stdPakage=strPakage.toStdString();
print(charset_u2g(stdPakage).data(),3);
print("-----------------------------------------------",1);
QString strDiscount="优惠 ";
strDiscount+=QString("%1").arg(QString::number(obj->discount_fee/100.00,'f',2),6);
std::string stdDiscount=strDiscount.toStdString();
print(charset_u2g(stdDiscount).data(),3);
QString strSend="配送费 ";
strSend+=QString("%1").arg(QString::number(obj->send_fee/100.00,'f',2),6);
std::string stdSend=strSend.toStdString();
print(charset_u2g(stdSend).data(),3);
print("-----------------------------------------------",1);
QString strUser="已付 ";
strUser+=QString("%1").arg(QString::number(obj->user_fee/100.00,'f',2),6);
std::string stdUser=strUser.toStdString();
print(charset_u2g(stdUser).data(),3);
print("-----------------------------------------------",1);
std::string stdAddress=obj->address.toStdString();
print(charset_u2g(stdAddress).data(),3);
std::string stdName=obj->customer.toStdString();
print(charset_u2g(stdName).data(),3);
std::string stdPhone=obj->phone.toStdString();
print(charset_u2g(stdPhone).data(),3);
QString strId="订单号:";
strId+=obj->order_id;
std::string stdId=strId.toStdString();
print(charset_u2g(stdId).data(),3);
//为空时换行
print("",1);
QString end="*********";
end+=QString("%1").arg("#"+QString::number(obj->order_index),4);
end+="完";
end+="********";
std::string strEnd=end.toStdString();
print(charset_u2g(strEnd).data(),3);
cut_paper();
}
#endif
} }
//上菜单打印 //上菜单打印
void WBillControl::printMenu(const OrderObject *obj) void WBillControl::printMenu(const OrderObject *obj)
{ {
//#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
int fd=-1; int fd=-1;
for(int i=0; i < obj->proList.size(); i++) for(int i=0; i < obj->proList.size(); i++)
{ {
...@@ -427,7 +539,7 @@ void WBillControl::printMenu(const OrderObject *obj) ...@@ -427,7 +539,7 @@ void WBillControl::printMenu(const OrderObject *obj)
print(menu.strOrderTitle.toLatin1().data(),3); print(menu.strOrderTitle.toLatin1().data(),3);
QString strDesk=" 台号:"; QString strDesk=" 台号:";
strDesk+=obj->channelName; strDesk+=obj->channelName;
strDesk+=QString::number(obj->order_index); strDesk+=QString::number(obj->order_index);
std::string stdDesk=strDesk.toStdString(); std::string stdDesk=strDesk.toStdString();
...@@ -460,9 +572,57 @@ void WBillControl::printMenu(const OrderObject *obj) ...@@ -460,9 +572,57 @@ void WBillControl::printMenu(const OrderObject *obj)
cut_paper(); cut_paper();
} }
//#endif #endif
} }
QString WBillControl::getPrintTitle(const QString& channel,int index)
{
QString title;
if("eleme"==channel){
title="****";
title+=QString("%1").arg("#"+QString::number(index),4);
title+="饿了么外卖单";
title+="****";
}
else if("mtwm"==channel){
title="*****";
title+=QString("%1").arg("#"+QString::number(index),4);
title+="美团外卖单";
title+="*****";
}
else if("bdwm"==channel){
title="*****";
title+=QString("%1").arg("#"+QString::number(index),4);
title+="百度外卖单";
title+="*****";
}
else if("jdwm"==channel){
title="******";
title+=QString("%1").arg("#"+QString::number(index),4);
title+="京东到家";
title+="******";
}
else if("sdg"==channel){
title="*******";
title+=QString("%1").arg("#"+QString::number(index),4);
title+="闪电购";
title+="*******";
}
else if("fmwd"==channel){
title="******";
title+=QString("%1").arg("#"+QString::number(index),4);
title+="非码微店";
title+="******";
}
else if("mall"==channel){
title="******";
title+=QString("%1").arg("#"+QString::number(index),4);
title+="非码Mall";
title+="******";
}
return title;
}
int WBillControl::charset_convert(const char* charset_from, const char* charset_to int WBillControl::charset_convert(const char* charset_from, const char* charset_to
, const std::string& string_from, std::string& string_to) , const std::string& string_from, std::string& string_to)
......
...@@ -106,11 +106,14 @@ private: ...@@ -106,11 +106,14 @@ private:
void printCook(const OrderObject *obj,const QString& menuId,int num); void printCook(const OrderObject *obj,const QString& menuId,int num);
//外卖单打印 //外卖单打印
void printTakeout(); void printTakeout(const OrderObject *obj);
//上菜单打印 //上菜单打印
void printMenu(const OrderObject *obj); void printMenu(const OrderObject *obj);
//上菜单打印
QString getPrintTitle(const QString& channel,int index);
public: public:
QVector<PrinterMenu> vecMenu; QVector<PrinterMenu> vecMenu;
QMap<QString,QVector<SetMenuItem>> mapSetMenu; QMap<QString,QVector<SetMenuItem>> mapSetMenu;
......
...@@ -13,8 +13,10 @@ void cut_paper(); ...@@ -13,8 +13,10 @@ void cut_paper();
// 2、标准加粗 // 2、标准加粗
// 3、两倍宽高 // 3、两倍宽高
// 4、两倍宽高,加粗 // 4、两倍宽高,加粗
// 5、三倍宽高 // 5、两倍高
// 6、三倍宽高,加粗,红色 // 6、两倍高,加粗
// 7、三倍宽高
// 8、三倍宽高,加粗,红色
//--------------------------------------------- //---------------------------------------------
void print(const char *data,int type); void print(const char *data,int type);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment