CPosPrinter.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. #include "../pch/pch.h"
  2. #include "CPosPrinter.h"
  3. #include <winioctl.h>
  4. #include <setupapi.h>
  5. CPosPrinter::CPosPrinter()
  6. {
  7. Init();
  8. }
  9. CPosPrinter::~CPosPrinter()
  10. {
  11. }
  12. bool CPosPrinter::Init()
  13. {
  14. //遍历USB设备,找到POS打印机路径
  15. //设备路径
  16. TCHAR * szDevicePath[MAX_DEVICE];
  17. //设置中文字符
  18. setlocale(LC_CTYPE, "chs");
  19. TCHAR* Port = NULL;
  20. //分配需要的空间
  21. for(int i = 0; i < MAX_DEVICE; i++)
  22. {
  23. szDevicePath[i] = new TCHAR[256];
  24. }
  25. //取设备路径
  26. int nDevice = GetDevicePath((LPGUID)&USB_GUID, szDevicePath);
  27. int i = 0;
  28. while(i < nDevice)
  29. {
  30. Port = szDevicePath[i++];
  31. LOG_INFO("device.Port = " << Port);
  32. }
  33. m_hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE,
  34. 0, NULL,
  35. OPEN_EXISTING,
  36. FILE_ATTRIBUTE_NORMAL, NULL);
  37. if(m_hPort == INVALID_HANDLE_VALUE)
  38. {
  39. // 打开端口失败
  40. return false;
  41. }
  42. return true;
  43. }
  44. void CPosPrinter::PrintWaimaiOrder(CWaimaiOrder& order)
  45. {
  46. POS_Reset();
  47. string shop_name = "#" + order.m_restaurant_number + " " + CLewaimaiString::UTF8ToANSI(order.m_shop_name);
  48. POS_TextOut(shop_name, true);
  49. POS_FeedLine();
  50. POS_FeedLine();
  51. if (order.m_is_selftake == "1")
  52. {
  53. POS_TextOut("到店自取订单", false, 1);
  54. POS_FeedLine();
  55. POS_FeedLine();
  56. POS_TextOut("取餐号:" + CLewaimaiString::UTF8ToANSI(order.m_take_food_code), true, 1);
  57. POS_FeedLine();
  58. }
  59. else
  60. {
  61. POS_TextOut("外卖订单", false, 1);
  62. POS_FeedLine();
  63. }
  64. POS_FeedLine();
  65. if(order.m_is_selftake == "1")
  66. {
  67. //自取订单,打印自取信息
  68. }
  69. //订单来源
  70. string from_type = "订单来源:" + CLewaimaiString::UTF8ToANSI(order.m_from_type);
  71. POS_TextOut(from_type);
  72. POS_FeedLine();
  73. //订单号
  74. string order_no = "订单号:" + CLewaimaiString::UTF8ToANSI(order.m_order_no);
  75. POS_TextOut(order_no);
  76. POS_FeedLine();
  77. //姓名
  78. if (order.m_is_selftake != "1")
  79. {
  80. string name = "姓名:" + CLewaimaiString::UTF8ToANSI(order.m_customer_name);
  81. POS_TextOut(name);
  82. POS_FeedLine();
  83. }
  84. //电话
  85. string phone = "电话:" + CLewaimaiString::UTF8ToANSI(order.m_phone);
  86. POS_TextOut(phone);
  87. POS_FeedLine();
  88. //地址
  89. if (order.m_is_selftake != "1")
  90. {
  91. string address = "地址:" + CLewaimaiString::UTF8ToANSI(order.m_address);
  92. POS_TextOut(address);
  93. POS_FeedLine();
  94. }
  95. //预设选项
  96. if (order.m_order_field.size() > 1)
  97. {
  98. for (std::vector<CWaimaiOrderField>::iterator it = order.m_order_field.begin(); it != order.m_order_field.end() - 1; it++)
  99. {
  100. string order_field = CLewaimaiString::UTF8ToANSI((*it).name) + ":" + CLewaimaiString::UTF8ToANSI((*it).value);
  101. POS_TextOut(order_field, false, 0);
  102. POS_FeedLine();
  103. }
  104. }
  105. //下单时间
  106. string order_date = "下单时间:" + CLewaimaiString::UTF8ToANSI(order.m_order_date);
  107. POS_TextOut(order_date);
  108. POS_FeedLine();
  109. //配送时间
  110. if (order.m_is_selftake == "1")
  111. {
  112. string date = "自取时间:" + CLewaimaiString::UTF8ToANSI(order.m_delivery_date);
  113. POS_TextOut(date);
  114. POS_FeedLine();
  115. }
  116. else
  117. {
  118. string date = "配送时间:" + CLewaimaiString::UTF8ToANSI(order.m_delivery_date);
  119. POS_TextOut(date);
  120. POS_FeedLine();
  121. }
  122. //准备开始打印商品详情
  123. string lines = "--------------------------------";
  124. POS_TextOut(lines);
  125. POS_FeedLine();
  126. //商品标题
  127. POS_TextOut("商品 单价 数量 金额");
  128. POS_FeedLine();
  129. //商品内容
  130. for(std::vector<CWaimaiOrderItem>::iterator it = order.m_order_items.begin(); it != order.m_order_items.end(); it++)
  131. {
  132. std::string food_name = (*it).m_food_name;
  133. std::string food_price = (*it).m_item_price;
  134. std::string quantity = (*it).m_quantity;
  135. //计算总价
  136. double item_price = atof(food_price.c_str()) * atof(quantity.c_str());
  137. std::string food_total_price = CLewaimaiString::DoubleToString(item_price, 2);
  138. food_name = CLewaimaiString::UTF8ToANSI(food_name);
  139. //先输出商品名字
  140. std::vector<string> m_names = HandleFoodname(food_name);
  141. std::string firstLine = m_names[0];
  142. std::string priceShow = HandleFoodItemPrice(food_price);
  143. std::string quantityShow = HandleFoodQuantity(quantity);
  144. std::string priceTotalShow = HandleFoodTotalPrice(food_total_price);
  145. std::string firstLineShow = firstLine + priceShow + quantityShow + priceTotalShow;
  146. POS_TextOut(firstLineShow, false, 0);
  147. POS_FeedLine();
  148. for (std::vector<string>::iterator it = m_names.begin() + 1; it != m_names.end(); it++)
  149. {
  150. POS_TextOut((*it), false, 0);
  151. POS_FeedLine();
  152. }
  153. }
  154. //判断是否有备注
  155. if (order.m_memo.length() > 0)
  156. {
  157. POS_FeedLine();
  158. string address = "顾客备注:" + CLewaimaiString::UTF8ToANSI(order.m_memo);
  159. POS_TextOut(address, false, 0);
  160. POS_FeedLine();
  161. }
  162. //结束商品详情打印
  163. POS_TextOut(lines);
  164. POS_FeedLine();
  165. //开始打印其他的费用
  166. bool is_other_money = false;
  167. if (order.m_delivery > 0)
  168. {
  169. string delivery = "配送费:" + CLewaimaiString::DoubleToString((double)order.m_delivery, 2);
  170. POS_TextOut(delivery, false, 0);
  171. POS_FeedLine();
  172. is_other_money = true;
  173. }
  174. if (order.m_is_dabao == "1")
  175. {
  176. string dabao = "打包费:" + CLewaimaiString::UTF8ToANSI(order.m_dabao_money);
  177. POS_TextOut(dabao, false, 0);
  178. POS_FeedLine();
  179. is_other_money = true;
  180. }
  181. //开始显示增值服务费
  182. if (order.m_addservie.size() > 0)
  183. {
  184. for (std::vector<CWaimaiOrderField>::iterator it = order.m_addservie.begin(); it != order.m_addservie.end(); it++)
  185. {
  186. string addservice = CLewaimaiString::UTF8ToANSI((*it).name) + ":" + CLewaimaiString::DoubleToString((double)atof((*it).value.c_str()), 2);
  187. POS_TextOut(addservice, false, 0);
  188. POS_FeedLine();
  189. is_other_money = true;
  190. }
  191. is_other_money = true;
  192. }
  193. if (order.m_discount < 10)
  194. {
  195. string discount = "打折:" + CLewaimaiString::DoubleToString((double)order.m_discount, 2) + "折";
  196. POS_TextOut(discount, false, 0);
  197. POS_FeedLine();
  198. is_other_money = true;
  199. }
  200. if (order.m_is_member_discount == "1")
  201. {
  202. string member_discount = "会员优惠:-" + order.m_member_discount;
  203. POS_TextOut(member_discount, false, 0);
  204. POS_FeedLine();
  205. is_other_money = true;
  206. }
  207. if (order.m_is_firstcut == "1")
  208. {
  209. string firstcut = "首单优惠:-" + order.m_firstcut_value;
  210. POS_TextOut(firstcut, false, 0);
  211. POS_FeedLine();
  212. is_other_money = true;
  213. }
  214. //满减
  215. string::size_type position = order.m_promotion.find(":");
  216. if (position != order.m_promotion.npos)
  217. {
  218. string promotion_value;
  219. promotion_value.assign(order.m_promotion, position + 1);
  220. string coupon = "满减优惠:-" + CLewaimaiString::DoubleToString((double)(atof(promotion_value.c_str())), 2);
  221. POS_TextOut(coupon, false, 0);
  222. POS_FeedLine();
  223. is_other_money = true;
  224. }
  225. if (order.m_coupon> 0)
  226. {
  227. string coupon = "优惠券:-" + CLewaimaiString::DoubleToString((double)order.m_coupon, 2);
  228. POS_TextOut(coupon, false, 0);
  229. POS_FeedLine();
  230. is_other_money = true;
  231. }
  232. if (atof(order.m_goods_coupon_value.c_str()) > 0.0001)
  233. {
  234. string coupon = "商品券:-" + order.m_goods_coupon_value;
  235. POS_TextOut(coupon, false, 0);
  236. POS_FeedLine();
  237. is_other_money = true;
  238. }
  239. if (is_other_money)
  240. {
  241. POS_TextOut(lines);
  242. POS_FeedLine();
  243. }
  244. //最后显示总价
  245. POS_TextOut("总计:¥" + CLewaimaiString::DoubleToString(order.m_price, 2), false, 2);
  246. POS_FeedLine();
  247. //显示付款方式
  248. POS_TextOut("支付方式:" + CLewaimaiString::UTF8ToANSI(order.m_pay_type), false, 2);
  249. POS_FeedLine();
  250. POS_FeedLine();
  251. POS_CutPaper();
  252. }
  253. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  254. //获取CreateFile的USB端口号
  255. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  256. // 根据GUID获得设备路径
  257. // lpGuid: GUID指针
  258. // pszDevicePath: 设备路径指针的指针,用于返回找到的路径
  259. // 返回: 成功得到的设备路径个数,可能不止1个
  260. int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
  261. {
  262. HDEVINFO hDevInfoSet;
  263. SP_DEVINFO_DATA spDevInfoData;
  264. SP_DEVICE_INTERFACE_DATA ifData;
  265. PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;
  266. int nCount;
  267. int nTotle;
  268. BOOL bResult;
  269. wstring strUSBPrint = TEXT("USB 打印支持");
  270. // 取得一个该GUID相关的设备信息集句柄
  271. hDevInfoSet = ::SetupDiGetClassDevs(lpGuid, // class GUID
  272. NULL, // 无关键字
  273. NULL, // 不指定父窗口句柄
  274. DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); // 目前存在的设备
  275. // 失败...
  276. if(hDevInfoSet == INVALID_HANDLE_VALUE)
  277. {
  278. printf("failed \r\n");
  279. return 0;
  280. }
  281. // 申请设备接口数据空间
  282. pDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)::GlobalAlloc(LMEM_ZEROINIT, INTERFACE_DETAIL_SIZE);
  283. pDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
  284. nTotle = -1;
  285. nCount = 0;
  286. bResult = TRUE;
  287. // 设备序号=0,1,2... 逐一测试设备接口,到失败为止
  288. while(bResult)
  289. {
  290. nTotle++;
  291. spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  292. // 枚举符合该GUID的设备接口
  293. bResult = ::SetupDiEnumDeviceInfo(
  294. hDevInfoSet, // 设备信息集句柄
  295. (ULONG)nTotle, // 设备信息集里的设备序号
  296. &spDevInfoData); // 设备接口信息
  297. if(bResult)
  298. {
  299. DWORD DataT;
  300. TCHAR buf[MAX_PATH];
  301. DWORD nSize = 0;
  302. // get Friendly Name or Device Description
  303. if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
  304. SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
  305. {
  306. }
  307. else if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
  308. SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
  309. {
  310. }
  311. else
  312. {
  313. lstrcpy(buf, _T("Unknown"));
  314. }
  315. _tprintf(_T("buf = %s \r\n"), buf);
  316. //是否是要找的设备类型
  317. if(_tcscmp(buf, strUSBPrint.c_str()) != 0)
  318. {
  319. continue;
  320. }
  321. _tprintf(_T("OK\r\n"));
  322. ifData.cbSize = sizeof(ifData);
  323. // 枚舉符合該GUID的設備接口
  324. bResult = ::SetupDiEnumDeviceInterfaces(
  325. hDevInfoSet, // 設備信息集句柄
  326. NULL, // 不需額外的設備描述
  327. lpGuid, // GUID
  328. (ULONG)nTotle, // 設備信息集里的設備序號
  329. &ifData); // 設備接口信息
  330. if(bResult)
  331. {
  332. // 取得该设备接口的细节(设备路径)
  333. bResult = SetupDiGetInterfaceDeviceDetail(
  334. hDevInfoSet, // 设备信息集句柄
  335. &ifData, // 设备接口信息
  336. pDetail, // 设备接口细节(设备路径)
  337. INTERFACE_DETAIL_SIZE, // 输出缓冲区大小
  338. NULL, // 不需计算输出缓冲区大小(直接用设定值)
  339. NULL); // 不需额外的设备描述
  340. if(bResult)
  341. {
  342. // 复制设备路径到输出缓冲区
  343. ::_tcscpy_s(pszDevicePath[nCount], 256, pDetail->DevicePath);
  344. // 调整计数值
  345. nCount++;
  346. _tprintf(_T("Cnt = %d,pDetail->DevicePath =%s\r\n"), nCount, pDetail->DevicePath);
  347. }
  348. }
  349. }
  350. }
  351. // 释放设备接口数据空间
  352. ::GlobalFree(pDetail);
  353. // 关闭设备信息集句柄
  354. ::SetupDiDestroyDeviceInfoList(hDevInfoSet);
  355. return nCount;
  356. }
  357. int CPosPrinter::WriteData(string msg)
  358. {
  359. DWORD dwWrite;
  360. return WriteFile(m_hPort, msg.c_str(), (DWORD)msg.length(), &dwWrite, NULL);
  361. }
  362. int CPosPrinter::WriteBuf(char *buf, int len)
  363. {
  364. DWORD dwWrite;
  365. return WriteFile(m_hPort, buf, len, &dwWrite, NULL);
  366. }
  367. int CPosPrinter::POS_Reset(void)
  368. {
  369. char s[2] = {0x1B, 0x40};
  370. WriteBuf(s, 2);
  371. return 0;
  372. }
  373. int CPosPrinter::POS_FeedLine(void)
  374. {
  375. char s[1] = {0x0A};
  376. WriteBuf(s, 1);
  377. return 0;
  378. }
  379. int CPosPrinter::POS_Feed(void)
  380. {
  381. char s[3] = { 0x1B, 0x4A, 0x00 };
  382. WriteBuf(s, 3);
  383. return 0;
  384. }
  385. int CPosPrinter::POS_SetMotionUnit(int x, int y)
  386. {
  387. string s;
  388. s = "\x1D\x50\xB4\xB4";
  389. WriteData(s);
  390. s = "\x1B\x53";
  391. WriteData(s);
  392. return 0;
  393. }
  394. int CPosPrinter::POS_SET_MOVE_X()
  395. {
  396. char s2[6] = { 0x1B, 0x44, 0x0C, 0x0E, 0x17, 0x00};
  397. WriteBuf(s2, 6);
  398. return 0;
  399. }
  400. int CPosPrinter::POS_MOVE_X()
  401. {
  402. char s[1] = { 0x09 };
  403. WriteBuf(s, 1);
  404. return 0;
  405. }
  406. int CPosPrinter::POS_SET_ABS_X(int x, int y)
  407. {
  408. char cx = (char)(x);
  409. char cy = (char)(y);
  410. char s1[4] = { 0x1B, 0x24, cx, cy };
  411. WriteBuf(s1, 4);
  412. return 0;
  413. }
  414. int CPosPrinter::POS_SET_PRINT_AREA(int x, int y)
  415. {
  416. char cx = (char)(x);
  417. char cy = (char)(y);
  418. char s1[4] = { 0x1D, 0x57, cx, cy };
  419. WriteBuf(s1, 4);
  420. return 0;
  421. }
  422. /*
  423. *align_type:0 左对齐 1 居中对齐 2右对齐
  424. **/
  425. int CPosPrinter::POS_TextOut(string abc, bool is_double, int align_type)
  426. {
  427. if(is_double)
  428. {
  429. char s1[3] = { 0x1B, 0x21, 0x30 };
  430. WriteBuf(s1, 3);
  431. char s2[3] = { 0x1C, 0x21, 0x0c };
  432. WriteBuf(s2, 3);
  433. }
  434. else
  435. {
  436. char s1[3] = { 0x1B, 0x21, 0x00 };
  437. WriteBuf(s1, 3);
  438. char s2[3] = { 0x1C, 0x57, 0x00 };
  439. WriteBuf(s2, 3);
  440. }
  441. if(align_type == 0)
  442. {
  443. char s1[3] = { 0x1B, 0x61, 0x00 };
  444. WriteBuf(s1, 3);
  445. }
  446. else if(align_type == 1)
  447. {
  448. char s1[3] = { 0x1B, 0x61, 0x01 };
  449. WriteBuf(s1, 3);
  450. }
  451. else if(align_type == 2)
  452. {
  453. char s1[3] = { 0x1B, 0x61, 0x02 };
  454. WriteBuf(s1, 3);
  455. }
  456. else
  457. {
  458. }
  459. WriteData(abc);
  460. return 0;
  461. }
  462. int CPosPrinter::POS_CutPaper()
  463. {
  464. char s[4] = { 0x1D, 0x56, 0x41, 0x00 };
  465. WriteBuf(s, 4);
  466. return 0;
  467. }
  468. int CPosPrinter::POS_OutQRCode()
  469. {
  470. char QRCode1[8] = { 0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x43, 0x05 };
  471. char QRCode2[16] = { 0x1d, 0x28, 0x6b, 0x0b, 0x00, 0x31, 0x50, 0x30, 0x47, 0x70, 0x72, 0x69,
  472. 0x6e, 0x74, 0x65, 0x72
  473. };
  474. char QRCode3[8] = { 0x1d, 0x28, 0x6b, 0x03, 0x00, 0x31, 0x51, 0x30 };
  475. WriteBuf(QRCode1, 8);
  476. WriteBuf(QRCode2, 16);
  477. WriteBuf(QRCode3, 8);
  478. return 0;
  479. }
  480. void CPosPrinter::CalWord(string s, int& nHanzi, int& nZimu)
  481. {
  482. nHanzi = 0;
  483. nZimu = 0;
  484. const char* buffer = s.c_str();
  485. while(*buffer++ != '\0')
  486. {
  487. if(!(*buffer >= 0 && *buffer <= 127))
  488. {
  489. //汉字
  490. buffer++;
  491. nHanzi++;
  492. }
  493. else
  494. {
  495. //字母
  496. nZimu++;
  497. }
  498. }
  499. }
  500. std::vector<std::string>CPosPrinter::HandleFoodname(std::string oldname)
  501. {
  502. std::vector<std::string> newnameArray;
  503. int nHanzi, nZimu;
  504. CalWord(oldname, nHanzi, nZimu);
  505. int nWidth = nHanzi * 2 + nZimu;
  506. if(nWidth <= 15)
  507. {
  508. //对于nWidth补空格
  509. for (int i = 0; i < 15 - nWidth; i++)
  510. {
  511. oldname += " ";
  512. }
  513. newnameArray.push_back(oldname);
  514. return newnameArray;
  515. }
  516. //宽度大于15的情况,如果超过了,就要进行换行截取
  517. const char* s = oldname.c_str();
  518. int nTmp = 0;
  519. int nTotal = 0;
  520. while (*s++ != '\0')
  521. {
  522. nTmp++;
  523. nTotal++;
  524. if (!(*(s) >= 0 && *(s) <= 127))
  525. {
  526. //汉字的情况
  527. s++;
  528. nTmp++;
  529. nTotal++;
  530. }
  531. if (nTmp == 15)
  532. {
  533. //这里开始要换行了
  534. string newnameItem;
  535. newnameItem.assign(oldname, nTotal - nTmp, nTmp);
  536. newnameArray.push_back(newnameItem);
  537. nTmp = 0;
  538. }
  539. else if (nTmp == 14)
  540. {
  541. //如果是第14个了,判断下一个是不是中文,如果是的话也要换行
  542. if (!(*(s + 1) >= 0 && *(s + 1) <= 127))
  543. {
  544. //下一个是中文,也要换行了,补齐一个空格
  545. string newnameItem;
  546. newnameItem.assign(oldname, nTotal - nTmp, nTmp);
  547. newnameItem += " ";
  548. newnameArray.push_back(newnameItem);
  549. nTmp = 0;
  550. }
  551. }
  552. }
  553. if (nTmp > 0)
  554. {
  555. //处理分隔后的最后一行
  556. string newnameItem;
  557. newnameItem.assign(oldname, nTotal - nTmp, nTmp);
  558. for (int i = 0; i < 15 - nTmp; i++)
  559. {
  560. newnameItem += " ";
  561. }
  562. newnameArray.push_back(newnameItem);
  563. }
  564. return newnameArray;
  565. }
  566. std::string CPosPrinter::HandleFoodItemPrice(std::string oldprice)
  567. {
  568. double price = atof(oldprice.c_str());
  569. if (price < 10.00)
  570. {
  571. //单位数
  572. return " " + oldprice;
  573. }
  574. else if (price > 9.99 && price < 100.00)
  575. {
  576. //双位数
  577. return " " + oldprice;
  578. }
  579. else
  580. {
  581. return " " + oldprice;
  582. }
  583. }
  584. std::string CPosPrinter::HandleFoodQuantity(std::string oldquantity)
  585. {
  586. int n = atoi(oldquantity.c_str());
  587. if (n < 10)
  588. {
  589. return " " + oldquantity;
  590. }
  591. else
  592. {
  593. return " " + oldquantity;
  594. }
  595. }
  596. std::string CPosPrinter::HandleFoodTotalPrice(std::string oldprice)
  597. {
  598. double price = atof(oldprice.c_str());
  599. if (price < 10.00)
  600. {
  601. //单位数
  602. return " " + oldprice;
  603. }
  604. else if (price > 9.99 && price < 100.00)
  605. {
  606. //双位数
  607. return " " + oldprice;
  608. }
  609. else
  610. {
  611. return " " + oldprice;
  612. }
  613. }