| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663 |
- #include "../pch/pch.h"
- #include "CPosPrinter.h"
- #include <winioctl.h>
- #include <setupapi.h>
- using boost::asio::ip::tcp;
- CPosPrinter::CPosPrinter() : m_socket(m_io)
- {
- }
- CPosPrinter::~CPosPrinter()
- {
- }
- void CPosPrinter::InitUsb()
- {
- //设置中文字符
- setlocale(LC_CTYPE, "chs");
- //取设备路径
- int nDevice = GetDevicePath((LPGUID)&USB_GUID);
- LOG_INFO("可用的USB打印机数量:" << nDevice);
- //添加usb端口
- int i = 0;
- while(i < nDevice)
- {
- 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 | FILE_FLAG_OVERLAPPED, NULL);
- if(hPort == INVALID_HANDLE_VALUE)
- {
- // 打开端口失败
- 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++;
- }
- }
- void CPosPrinter::InitOneUsb(wstring usb_path)
- {
- HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
- if(hPort == INVALID_HANDLE_VALUE)
- {
- // 打开端口失败
- DWORD error = GetLastError();
- if(error == 2)
- {
- //没有指定的文件
- LOG_INFO("没有找对对应的usb端口");
- }
- else if(error == 5)
- {
- LOG_INFO("usb端口被占用!");
- }
- }
- 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);
- }
- }
- void CPosPrinter::InitBingkou()
- {
- std::wstring LptStr = L"lpt1";
- HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
- if(hPort == INVALID_HANDLE_VALUE)
- {
- DWORD error = GetLastError();
- if(error == 2)
- {
- //没有指定的文件
- LOG_INFO("本机器没有并口!");
- }
- else if(error == 5)
- {
- LOG_INFO("并口被占用!");
- }
- }
- 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);
- }
- }
- }
- void CPosPrinter::InitCom()
- {
- int comNum = 10;
- for(int i = 1; i <= 10; i++)
- {
- std::wstring com2Str = L"com" + CLewaimaiString::ANSIToUnicode(to_string(i));
- 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、并口、串口3个类型,注意这里不包含网口
- **/
- void CPosPrinter::InitShouyin()
- {
- //开始添加usb
- InitUsb();
- //开始添加并口的端口
- InitBingkou();
- //开始添加串口
- InitCom();
- }
- /*
- *获取CreateFile的USB端口号
- **/
- int CPosPrinter::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());
- if(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:标签打印机
- **/
- int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
- {
- if(vid == L"6868" && pid == L"0500")
- {
- //佳博标签打印机
- return 2;
- }
- return 1;
- }
- /*
- *打印收银小票
- **/
- void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
- {
- //设置模式,后面输出数据不会错
- 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);
- InitOneUsb(ws_printer_usb);
- }
- else if(printer_leixing == "bingkou")
- {
- InitBingkou();
- }
- 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());
- }
- }
- //读取当前收银打印机的设置
- std::string guige = CSetting::GetParam("setting_printer_guige");
- std::string lianshu = CSetting::GetParam("setting_printer_lianshu");
- int n_lianshu = atoi(lianshu.c_str());
- //正式开始打印
- for(int i = 0; i < n_lianshu; i++)
- {
- POS_Reset();
- string shop_name = "#" + order.m_restaurant_number + " " + CLewaimaiString::UTF8ToANSI(order.m_shop_name);
- POS_TextOut(shop_name, true, true, 1);
- POS_FeedLine();
- POS_FeedLine();
- bool setting_printer_quhuo_big = false;
- if(CSetting::GetParam("setting_printer_quhuo_big") == "1")
- {
- setting_printer_quhuo_big = true;
- }
- if(order.m_is_selftake == "1")
- {
- POS_TextOut("到店自取订单", false, setting_printer_quhuo_big, 1);
- POS_FeedLine();
- POS_FeedLine();
- POS_TextOut("取餐号:" + CLewaimaiString::UTF8ToANSI(order.m_take_food_code), true, 1);
- POS_FeedLine();
- }
- else
- {
- POS_TextOut("外卖订单", false, setting_printer_quhuo_big, 1);
- POS_FeedLine();
- }
- POS_FeedLine();
- //订单来源
- string from_type = "订单来源:" + CLewaimaiString::UTF8ToANSI(order.m_from_type);
- POS_TextOut(from_type);
- POS_FeedLine();
- //订单号
- bool setting_printer_dingdanhao_big = false;
- if(CSetting::GetParam("setting_printer_dingdanhao_big") == "1")
- {
- setting_printer_dingdanhao_big = true;
- }
- string order_num = "订 单 号:" + CLewaimaiString::UTF8ToANSI(order.m_order_num);
- POS_TextOut(order_num, false, setting_printer_dingdanhao_big);
- POS_FeedLine();
- //下单时间
- bool setting_printer_xiadanshijian_big = false;
- if(CSetting::GetParam("setting_printer_xiadanshijian_big") == "1")
- {
- setting_printer_xiadanshijian_big = true;
- }
- string order_date = "下单时间:" + CLewaimaiString::UTF8ToANSI(order.m_order_date);
- POS_TextOut(order_date, false, setting_printer_xiadanshijian_big);
- POS_FeedLine();
- //配送时间
- bool setting_printer_peisongshijian_big = false;
- if(CSetting::GetParam("setting_printer_peisongshijian_big") == "1")
- {
- setting_printer_peisongshijian_big = true;
- }
- if(order.m_is_selftake == "1")
- {
- string date = "自取时间:" + CLewaimaiString::UTF8ToANSI(order.m_delivery_date);
- POS_TextOut(date, false, setting_printer_peisongshijian_big);
- POS_FeedLine();
- }
- else
- {
- string date = "配送时间:" + CLewaimaiString::UTF8ToANSI(order.m_delivery_date);
- POS_TextOut(date, false, setting_printer_peisongshijian_big);
- POS_FeedLine();
- }
- //姓名
- bool setting_printer_name_big = false;
- if(CSetting::GetParam("setting_printer_name_big") == "1")
- {
- setting_printer_name_big = true;
- }
- if(order.m_is_selftake != "1")
- {
- string name = "姓名:" + CLewaimaiString::UTF8ToANSI(order.m_customer_name);
- POS_TextOut(name, false, setting_printer_name_big);
- POS_FeedLine();
- }
- //电话
- bool setting_printer_phone_big = false;
- if(CSetting::GetParam("setting_printer_phone_big") == "1")
- {
- setting_printer_phone_big = true;
- }
- string phone = "电话:" + CLewaimaiString::UTF8ToANSI(order.m_phone);
- POS_TextOut(phone, false, setting_printer_phone_big);
- POS_FeedLine();
- //地址
- bool setting_printer_address_big = false;
- if(CSetting::GetParam("setting_printer_address_big") == "1")
- {
- setting_printer_address_big = true;
- }
- if(order.m_is_selftake != "1")
- {
- string address = "地址:" + CLewaimaiString::UTF8ToANSI(order.m_address);
- POS_TextOut(address, false, setting_printer_address_big);
- 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, false, 0);
- POS_FeedLine();
- }
- }
- //准备开始打印商品详情
- string lines;
- if(guige == "58")
- {
- lines = "--------------------------------";
- }
- else
- {
- lines = "------------------------------------------------";
- }
- POS_TextOut(lines);
- POS_FeedLine();
- //商品标题
- bool setting_printer_shangpin_big = false;
- if(CSetting::GetParam("setting_printer_shangpin_big") == "1")
- {
- setting_printer_shangpin_big = true;
- }
- if(guige == "58")
- {
- POS_TextOut("商品 单价 数量 金额", false, setting_printer_shangpin_big);
- }
- else
- {
- POS_TextOut("商品 单价 数量 金额", false, setting_printer_shangpin_big);
- }
- POS_FeedLine();
- //商品内容
- 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;
- //计算总价
- 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];
- int nGuige;
- 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, 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)
- {
- bool setting_printer_memo_big = false;
- if(CSetting::GetParam("setting_printer_memo_big") == "1")
- {
- setting_printer_memo_big = true;
- }
- POS_FeedLine();
- string address = "顾客备注:" + CLewaimaiString::UTF8ToANSI(order.m_memo);
- POS_TextOut(address, false, setting_printer_memo_big);
- POS_FeedLine();
- }
- //结束商品详情打印
- POS_TextOut(lines);
- POS_FeedLine();
- //开始打印其他的费用
- bool is_other_money = false;
- bool setting_printer_price_big = false;
- if(CSetting::GetParam("setting_printer_price_big") == "1")
- {
- setting_printer_price_big = true;
- }
- if(order.m_delivery > 0)
- {
- string delivery = "配送费:" + CLewaimaiString::DoubleToString((double)order.m_delivery, 2);
- POS_TextOut(delivery, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- if(order.m_is_dabao == "1")
- {
- string dabao = "打包费:" + CLewaimaiString::UTF8ToANSI(order.m_dabao_money);
- POS_TextOut(dabao, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- //开始显示增值服务费
- if(order.m_addservie.size() > 0)
- {
- for(std::vector<CWaimaiOrderField>::iterator it = order.m_addservie.begin(); it != order.m_addservie.end(); it++)
- {
- string addservice = CLewaimaiString::UTF8ToANSI((*it).name) + ":" + CLewaimaiString::DoubleToString((double)atof((*it).value.c_str()), 2);
- POS_TextOut(addservice, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- is_other_money = true;
- }
- if(order.m_discount < 10)
- {
- string discount = "打折:" + CLewaimaiString::DoubleToString((double)order.m_discount, 2) + "折";
- POS_TextOut(discount, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- if(order.m_is_member_discount == "1")
- {
- string member_discount = "会员优惠:-" + order.m_member_discount;
- POS_TextOut(member_discount, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- if(order.m_is_firstcut == "1")
- {
- string firstcut = "首单优惠:-" + order.m_firstcut_value;
- POS_TextOut(firstcut, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- //满减
- string::size_type position = order.m_promotion.find(":");
- if(position != order.m_promotion.npos)
- {
- string promotion_value;
- promotion_value.assign(order.m_promotion, position + 1);
- string promotion = "满减优惠:-" + CLewaimaiString::DoubleToString((double)(atof(promotion_value.c_str())), 2);
- POS_TextOut(promotion, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- if(order.m_coupon > 0)
- {
- string coupon = "优惠券:-" + CLewaimaiString::DoubleToString((double)order.m_coupon, 2);
- POS_TextOut(coupon, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- if(atof(order.m_goods_coupon_value.c_str()) > 0.0001)
- {
- string coupon = "商品券:-" + order.m_goods_coupon_value;
- POS_TextOut(coupon, false, setting_printer_price_big);
- POS_FeedLine();
- is_other_money = true;
- }
- if(is_other_money)
- {
- POS_TextOut(lines);
- POS_FeedLine();
- }
- //最后显示总价
- POS_TextOut("总计:¥" + CLewaimaiString::DoubleToString(order.m_price, 2), false, setting_printer_price_big, 2);
- POS_FeedLine();
- //显示付款方式
- bool setting_printer_pay_big = false;
- if(CSetting::GetParam("setting_printer_pay_big") == "1")
- {
- setting_printer_pay_big = true;
- }
- POS_TextOut("支付方式:" + CLewaimaiString::UTF8ToANSI(order.m_pay_type), false, setting_printer_pay_big, 2);
- POS_FeedLine();
- //走纸几行再切
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_CutPaper();
- }
- //还原打印机初始设置,有些傻逼收银设备居然不是自动调用,比如哗啦啦
- POS_Reset();
- //关闭设备
- for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
- {
- CloseHandle((*it).hPort);
- }
- }
- 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, true, 1);
- POS_FeedLine();
- POS_FeedLine();
- string order_type = "#" + order.m_restaurant_number + " ";
- if(order.m_is_selftake == "1")
- {
- POS_TextOut(order_type + "到店自取订单", false, false, 1);
- POS_FeedLine();
- POS_FeedLine();
- }
- else
- {
- POS_TextOut(order_type + "外卖订单", false, false, 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, 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];
- int nGuige;
- 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, false, 0);
- POS_FeedLine();
- for(std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
- {
- POS_TextOut((*it), false, false, 0);
- POS_FeedLine();
- }
- }
- //判断是否有备注
- if(order.m_memo.length() > 0)
- {
- POS_FeedLine();
- string address = "顾客备注:" + CLewaimaiString::UTF8ToANSI(order.m_memo);
- POS_TextOut(address, false, false, 0);
- POS_FeedLine();
- }
- //结束商品详情打印
- POS_TextOut(lines);
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_CutPaper();
- //还原打印机初始设置,有些傻逼收银设备居然不是自动调用,比如哗啦啦
- POS_Reset();
- }
- else
- {
- POS_Reset();
- //分单模式下,每个商品打印一张单
- for(std::vector<CWaimaiOrderItem>::iterator it = cur_printer_use.begin(); it != cur_printer_use.end(); it++)
- {
- POS_TextOut("派工单", true, true, 1);
- POS_FeedLine();
- POS_FeedLine();
- string order_type = "#" + order.m_restaurant_number + " ";
- if(order.m_is_selftake == "1")
- {
- POS_TextOut(order_type + "到店自取订单", false, false, 1);
- POS_FeedLine();
- POS_FeedLine();
- }
- else
- {
- POS_TextOut(order_type + "外卖订单", false, false, 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, 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, false, 0);
- POS_FeedLine();
- for(std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
- {
- POS_TextOut((*it), false, false, 0);
- POS_FeedLine();
- }
- //判断是否有备注
- if(order.m_memo.length() > 0)
- {
- POS_FeedLine();
- string address = "顾客备注:" + CLewaimaiString::UTF8ToANSI(order.m_memo);
- POS_TextOut(address, false, false, 0);
- POS_FeedLine();
- }
- //结束商品详情打印
- POS_TextOut(lines);
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_FeedLine();
- POS_CutPaper();
- }
- //还原打印机初始设置,有些傻逼收银设备居然不是自动调用,比如哗啦啦
- POS_Reset();
- }
- m_socket.close();
- }
- }
- std::vector<std::wstring> CPosPrinter::getUsbDevices()
- {
- return m_usb_devices;
- }
- int CPosPrinter::WriteData(string msg)
- {
- return WriteBuf(msg.c_str(), msg.length());
- }
- int CPosPrinter::WriteBuf(const char* buf, int len)
- {
- if(m_type == 1)
- {
- DWORD dwWrite;
- for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
- {
- HANDLE hPort = (*it).hPort;
- if((*it).type == 3)
- {
- //串口,同步写数据
- //LOG_INFO("before com writefile handle:" << hPort);
- WriteFile(hPort, buf, len, &dwWrite, NULL);
- //LOG_INFO("after com writefile handle:" << hPort);
- }
- else
- {
- //usb和并口,异步写数据
- OVERLAPPED overlap;
- memset(&overlap, 0, sizeof(overlap));
- BOOL rc = WriteFile(hPort, buf, len, &dwWrite, &overlap);
- if(rc)
- {
- //LOG_INFO("writefile success immediately, handle:" << hPort);
- }
- else
- {
- if(GetLastError() == ERROR_IO_PENDING)
- {
- //LOG_INFO("Request queued, waiting... handle:" << hPort);
- WaitForSingleObject(hPort, 1000);
- //LOG_INFO("Request completed, handle:" << hPort);
- //计算写入了多少字节的数据
- DWORD numread;
- rc = GetOverlappedResult(
- hPort,
- &overlap,
- &numread,
- FALSE
- );
- }
- }
- }
- }
- return 1;
- }
- else
- {
- try
- {
- m_socket.write_some(boost::asio::buffer(buf, len));
- }
- catch(const std::exception& e)
- {
- LOG_INFO(e.what());
- }
- return 0;
- }
- }
- /*
- *测试打印机是否连接
- **/
- bool CPosPrinter::PortTest(HANDLE hPort)
- {
- //标签打印机的查询状态指令
- char chInitCode[2] = { 0x1b, 0x40 };
- DWORD dwWrite;
- OVERLAPPED overlap;
- memset(&overlap, 0, sizeof(overlap));
- BOOL rc = WriteFile(hPort, chInitCode, 2, &dwWrite, &overlap);
- if(rc)
- {
- LOG_INFO("writefile success immediately, handle:" << hPort);
- return true;
- }
- else
- {
- if(GetLastError() == ERROR_IO_PENDING)
- {
- DWORD ret = WaitForSingleObject(hPort, 1000);
- if(ret == 0)
- {
- LOG_INFO("printer is connect, handle:" << hPort);
- return true;
- }
- else
- {
- LOG_INFO("printer is not connect, handle:" << hPort);
- }
- }
- }
- return false;
- }
- int CPosPrinter::POS_Reset(void)
- {
- char s[2] = { 0x1B, 0x40 };
- WriteBuf(s, 2);
- return 0;
- }
- int CPosPrinter::POS_FeedLine(void)
- {
- char s[1] = { 0x0A };
- WriteBuf(s, 1);
- return 0;
- }
- int CPosPrinter::POS_Feed(void)
- {
- char s[3] = { 0x1B, 0x4A, 0x00 };
- WriteBuf(s, 3);
- return 0;
- }
- int CPosPrinter::POS_SetMotionUnit(int x, int y)
- {
- string s;
- s = "\x1D\x50\xB4\xB4";
- WriteData(s);
- s = "\x1B\x53";
- WriteData(s);
- return 0;
- }
- int CPosPrinter::POS_SET_MOVE_X()
- {
- char s2[6] = { 0x1B, 0x44, 0x0C, 0x0E, 0x17, 0x00 };
- WriteBuf(s2, 6);
- return 0;
- }
- int CPosPrinter::POS_MOVE_X()
- {
- char s[1] = { 0x09 };
- WriteBuf(s, 1);
- return 0;
- }
- int CPosPrinter::POS_SET_ABS_X(int x, int y)
- {
- char cx = (char)(x);
- char cy = (char)(y);
- char s1[4] = { 0x1B, 0x24, cx, cy };
- WriteBuf(s1, 4);
- return 0;
- }
- int CPosPrinter::POS_SET_PRINT_AREA(int x, int y)
- {
- char cx = (char)(x);
- char cy = (char)(y);
- char s1[4] = { 0x1D, 0x57, cx, cy };
- WriteBuf(s1, 4);
- return 0;
- }
- /*
- *align_type:0 左对齐 1 居中对齐 2右对齐
- **/
- int CPosPrinter::POS_TextOut(string abc, bool is_double_width, bool is_double_height, int align_type)
- {
- if(is_double_width && is_double_height)
- {
- char s1[3] = { 0x1B, 0x21, 0x30 };
- WriteBuf(s1, 3);
- char s2[3] = { 0x1C, 0x21, 0x0c };
- WriteBuf(s2, 3);
- }
- else if(is_double_width && !is_double_height)
- {
- char s1[3] = { 0x1B, 0x21, 0x20 };
- WriteBuf(s1, 3);
- char s2[3] = { 0x1C, 0x21, 0x04 };
- WriteBuf(s2, 3);
- }
- else if(!is_double_width && is_double_height)
- {
- char s1[3] = { 0x1B, 0x21, 0x10 };
- WriteBuf(s1, 3);
- char s2[3] = { 0x1C, 0x21, 0x08 };
- WriteBuf(s2, 3);
- }
- else
- {
- char s1[3] = { 0x1B, 0x21, 0x00 };
- WriteBuf(s1, 3);
- char s2[3] = { 0x1C, 0x57, 0x00 };
- WriteBuf(s2, 3);
- }
- if(align_type == 0)
- {
- char s1[3] = { 0x1B, 0x61, 0x00 };
- WriteBuf(s1, 3);
- }
- else if(align_type == 1)
- {
- char s1[3] = { 0x1B, 0x61, 0x01 };
- WriteBuf(s1, 3);
- }
- else if(align_type == 2)
- {
- char s1[3] = { 0x1B, 0x61, 0x02 };
- WriteBuf(s1, 3);
- }
- else
- {
- }
- WriteData(abc);
- return 0;
- }
- /*
- *打印机切纸,直接切不走纸
- **/
- int CPosPrinter::POS_CutPaper()
- {
- char s[4] = { 0x1D, 0x56, 0x01 };
- WriteBuf(s, 3);
- return 0;
- }
- int CPosPrinter::POS_OutQRCode()
- {
- char QRCode1[8] = { 0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x05 };
- char QRCode2[16] = { 0x1d, 0x28, 0x6b, 0x0b, 0x00, 0x31, 0x50, 0x30, 0x47, 0x70, 0x72, 0x69,
- 0x6e, 0x74, 0x65, 0x72
- };
- char QRCode3[8] = { 0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30 };
- WriteBuf(QRCode1, 8);
- WriteBuf(QRCode2, 16);
- WriteBuf(QRCode3, 8);
- return 0;
- }
- void CPosPrinter::CalWord(string s, int& nHanzi, int& nZimu)
- {
- nHanzi = 0;
- nZimu = 0;
- const char* buffer = s.c_str();
- while(*buffer != '\0')
- {
- if(!(*buffer >= 0 && *buffer <= 127))
- {
- //汉字
- buffer++;
- buffer++;
- nHanzi++;
- }
- else
- {
- //字母
- buffer++;
- nZimu++;
- }
- }
- }
- /*
- *规格 1:58mm 2:80mm
- **/
- std::vector<std::string>CPosPrinter::HandleFoodname(std::string oldname, int guige)
- {
- std::vector<std::string> newnameArray;
- int nHanzi, nZimu;
- CalWord(oldname, nHanzi, nZimu);
- int nWidth = nHanzi * 2 + nZimu;
- int maxWidth;
- if(guige == 1)
- {
- maxWidth = 15;
- }
- else
- {
- maxWidth = 28;
- }
- if(nWidth <= maxWidth)
- {
- //对于nWidth补空格
- for(int i = 0; i < maxWidth - nWidth; i++)
- {
- oldname += " ";
- }
- newnameArray.push_back(oldname);
- return newnameArray;
- }
- //宽度大于15的情况,如果超过了,就要进行换行截取
- const char* s = oldname.c_str();
- int nTmp = 0;
- int nTotal = 0;
- while(*s != '\0')
- {
- if(!(*s >= 0 && *s <= 127))
- {
- //汉字的情况
- s++;
- nTmp++;
- nTotal++;
- s++;
- nTmp++;
- nTotal++;
- }
- else
- {
- //字母的情况
- s++;
- nTmp++;
- nTotal++;
- }
- if(nTmp == maxWidth)
- {
- //这里开始要换行了
- string newnameItem;
- newnameItem.assign(oldname, nTotal - nTmp, nTmp);
- newnameArray.push_back(newnameItem);
- nTmp = 0;
- }
- else if(nTmp == maxWidth - 1)
- {
- //如果是第14个了,判断下一个是不是中文,如果是的话也要换行
- if(!(*(s + 1) >= 0 && *(s + 1) <= 127))
- {
- //下一个是中文,也要换行了,补齐一个空格
- string newnameItem;
- newnameItem.assign(oldname, nTotal - nTmp, nTmp);
- newnameItem += " ";
- newnameArray.push_back(newnameItem);
- nTmp = 0;
- }
- }
- }
- if(nTmp > 0)
- {
- //处理分隔后的最后一行
- string newnameItem;
- newnameItem.assign(oldname, nTotal - nTmp, nTmp);
- for(int i = 0; i < maxWidth - nTmp; i++)
- {
- newnameItem += " ";
- }
- newnameArray.push_back(newnameItem);
- }
- return newnameArray;
- }
- std::string CPosPrinter::HandleFoodItemPrice(std::string oldprice, int guige)
- {
- double price = atof(oldprice.c_str());
- if(price < 10.00)
- {
- //单位数
- if(guige == 1)
- {
- return " " + oldprice;
- }
- else
- {
- return " " + oldprice;
- }
- }
- else if(price > 9.99 && price < 100.00)
- {
- //双位数
- if(guige == 1)
- {
- return " " + oldprice;
- }
- else
- {
- return " " + oldprice;
- }
- }
- else if(price > 99.99 && price < 1000.00)
- {
- //三位数
- if(guige == 1)
- {
- return " " + oldprice;
- }
- else
- {
- return " " + oldprice;
- }
- }
- else
- {
- //四位数
- if(guige == 1)
- {
- return " " + oldprice;
- }
- else
- {
- return " " + oldprice;
- }
- }
- }
- std::string CPosPrinter::HandleFoodQuantity(std::string oldquantity, int guige)
- {
- int n = atoi(oldquantity.c_str());
- if(n < 10)
- {
- if(guige == 1)
- {
- return " " + oldquantity;
- }
- else
- {
- return " " + oldquantity;
- }
- }
- else if(n >= 10 && n <= 99)
- {
- if(guige == 1)
- {
- return " " + oldquantity;
- }
- else
- {
- return " " + oldquantity;
- }
- }
- else
- {
- if(guige == 1)
- {
- return "" + oldquantity;
- }
- else
- {
- return " " + oldquantity;
- }
- }
- }
- std::string CPosPrinter::HandleFoodTotalPrice(std::string oldprice, int guige)
- {
- double price = atof(oldprice.c_str());
- if(price < 10.00)
- {
- //单位数
- if(guige == 1)
- {
- return " " + oldprice;
- }
- else
- {
- return " " + oldprice;
- }
- }
- else if(price > 9.99 && price < 100.00)
- {
- //双位数
- if(guige == 1)
- {
- return " " + oldprice;
- }
- else
- {
- return " " + oldprice;
- }
- }
- else if(price > 99.99 && price < 1000.00)
- {
- //三位数
- if(guige == 1)
- {
- return " " + oldprice;
- }
- else
- {
- return " " + oldprice;
- }
- }
- else
- {
- //四位数
- if(guige == 1)
- {
- return " " + oldprice;
- }
- else
- {
- return " " + oldprice;
- }
- }
- }
|