CPosPrinter.cpp 18 KB

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