CZhengcanDiandanPageUI.cpp 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476
  1. #include "../pch/pch.h"
  2. #include "CZhengcanDiandanPageUI.h"
  3. #include "../control/ControlEx.h"
  4. #include "../tool/CSqlite3.h"
  5. #include "../wnd/CDiandanNatureWnd.h"
  6. #include "../wnd/CMemoWnd.h"
  7. #include "../wnd/CYouhuiShowWnd.h"
  8. #include "../wnd/CMemberLoginWnd.h"
  9. #include "../wnd/CZhekouWnd.h"
  10. #include "../wnd/CRengongYouhuiWnd.h"
  11. #include "../wnd/CJiajiaWnd.h"
  12. #include "../wnd/CSaomaYouhuiquanWnd.h"
  13. #include "../wnd/CSaomaShangpinquanWnd.h"
  14. #include "../wnd/CSaomaCikaWnd.h"
  15. #include "../wnd/CSaomaQuanyikaWnd.h"
  16. #include "../wnd/CCanpaiWnd.h"
  17. #include "../wnd/CWeixinzhifuShoukuanWnd.h"
  18. #include "../wnd/CHuiyuanShoukuanWnd.h"
  19. #include "../wnd/CXianjinShoukuanWnd.h"
  20. #include "../wnd/CFulikaShoukuanWnd.h"
  21. #include "../wnd/CZidingyiShoukuanWnd.h"
  22. #include "../wnd/CChengzhongWnd.h"
  23. #include "../wnd/CGuadanWnd.h"
  24. #include "../wnd/CZhengcanRenshuWnd.h"
  25. #include "../print/CPosPrinter.h"
  26. #include "../tool/CShuangpingTool.h"
  27. CZhengcanDiandanPageUI::CZhengcanDiandanPageUI()
  28. {
  29. }
  30. CZhengcanDiandanPageUI::~CZhengcanDiandanPageUI()
  31. {
  32. }
  33. //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
  34. void CZhengcanDiandanPageUI::InitShow()
  35. {
  36. //先清空旧的订单信息,如果该桌子有订单关联后面会重新获取
  37. m_cur_diandan_order.RefreshDiandanInfo();
  38. //初始化显示,先清空所有的购物车商品,然后清空活动,初始化价格展示,等后面获取到订单数据再重新刷新渲染
  39. this->UpdateShopcartShow();
  40. //先检查桌子状态,获取桌子信息
  41. GetTableInfo();
  42. }
  43. void CZhengcanDiandanPageUI::InitTableShow()
  44. {
  45. //开始执行这个函数,说明如果订单之前下过单,也已经获取到数据了,需要进行渲染
  46. //先初始化商品分类
  47. this->InitFoodtypeShow();
  48. //再初始化商品显示
  49. this->InitFoodShow();
  50. //初始化结算页面相关的展示,把所有活动清零
  51. this->InitJiesuanShow();
  52. //渲染左侧购物车(包含了调用UpdateJiesuanInfo重新计算价格)
  53. this->UpdateShopcartShow();
  54. if (m_order_id == "0")
  55. {
  56. //说明还没下单,那么默认显示选购页面
  57. this->ShowXuangouPage();
  58. }
  59. else
  60. {
  61. //说明已经下过单了,那么默认显示结算页面
  62. this->ShowJiesuanPage();
  63. }
  64. if (m_is_zidingyizhifu_init == false)
  65. {
  66. //初始化结算页面的支付方式
  67. this->InitJiesuanZhifu();
  68. m_is_zidingyizhifu_init = true;
  69. }
  70. }
  71. void CZhengcanDiandanPageUI::GetTableInfo()
  72. {
  73. //开始转菊花
  74. CVerticalLayoutUI* pLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("page_layout")));
  75. pLayout->SetVisible(false);
  76. this->FindSubControl(_T("loading"))->SetVisible(true);
  77. //启动一个线程,进行网络请求操作
  78. std::thread t(&CZhengcanDiandanPageUI::DoGetTableInfo, this);
  79. t.detach();
  80. }
  81. void CZhengcanDiandanPageUI::DoGetTableInfo()
  82. {
  83. std::map<string, string> params;
  84. params["table_id"] = m_table_id;
  85. std::string response;
  86. std::string url = "/dinnercash/getonetableinfo";
  87. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
  88. if (ret == false)
  89. {
  90. return;
  91. }
  92. rapidjson::Document document;
  93. document.Parse(response.c_str());
  94. if (document.HasParseError())
  95. {
  96. LOG_INFO("parse response error!");
  97. return;
  98. }
  99. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  100. {
  101. LOG_INFO("json error!");
  102. return;
  103. }
  104. rapidjson::Value& v_errcode = document["errcode"];
  105. int errcode = v_errcode.GetInt();
  106. if (errcode != 0)
  107. {
  108. return;
  109. }
  110. if (!document.HasMember("data"))
  111. {
  112. return;
  113. }
  114. rapidjson::Value& data = document["data"];
  115. std::string status = CLewaimaiJson::ToString(data["status"]);
  116. if (status == "0")
  117. {
  118. //还没开台,说明桌子在别的地方被清台了
  119. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  120. this->m_pMainWnd->ShowToast(L"该桌子已被清台,请重新选择");
  121. }
  122. else
  123. {
  124. //桌子开台中,那么开始获取订单信息
  125. std::string order_id = CLewaimaiJson::ToString(data["order_id"]);
  126. m_table_name = CLewaimaiJson::ToString(data["name"]);
  127. CLabelUI* nameLabel = static_cast<CLabelUI*>(this->FindSubControl(L"diandan_page_table_name"));
  128. nameLabel->SetText(CLewaimaiString::UTF8ToUnicode(m_table_name).c_str());
  129. std::string open_table_fee = CLewaimaiJson::ToString(data["open_table_fee"]);
  130. std::string table_fee = CLewaimaiJson::ToString(data["table_fee"]);
  131. if (open_table_fee == "1")
  132. {
  133. m_kaitai = atof(table_fee.c_str());
  134. }
  135. else
  136. {
  137. m_kaitai = 0;
  138. }
  139. //这里不需要计算实际的茶位费,实际的茶位费是在算总价的时候根据人数一起算
  140. std::string open_tea_fee = CLewaimaiJson::ToString(data["open_tea_fee"]);
  141. std::string tea_fee = CLewaimaiJson::ToString(data["tea_fee"]);
  142. if (open_tea_fee == "1")
  143. {
  144. m_tea_fee = atof(tea_fee.c_str());
  145. }
  146. else
  147. {
  148. m_tea_fee = 0;
  149. }
  150. m_renshu = CLewaimaiJson::ToString(data["person_num"]);
  151. CButtonUI* pCanpaiEdit = static_cast<CButtonUI*>(this->FindSubControl(_T("btn_diandan_canpaihao")));
  152. pCanpaiEdit->SetText((L"人数 " + CLewaimaiString::UTF8ToUnicode(m_renshu)).c_str());
  153. if (order_id == "" || order_id == "0")
  154. {
  155. m_order_id = "0";
  156. //这个说明是只开台了,还没下单那么直接显示点餐页面就行
  157. this->InitTableShow();
  158. }
  159. else
  160. {
  161. m_order_id = order_id;
  162. //这个说明是开过台,也下过单了,那么要先获取当前的订单信息
  163. m_cur_diandan_order.InitData(order_id);
  164. //然后刷新已点菜的显示,再显示点餐页面的其他信息
  165. this->InitTableShow();
  166. }
  167. CVerticalLayoutUI* pLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("page_layout")));
  168. pLayout->SetVisible(true);
  169. this->FindSubControl(_T("loading"))->SetVisible(false);
  170. }
  171. }
  172. void CZhengcanDiandanPageUI::InitFoodtypeShow()
  173. {
  174. //初始化商品渲染相关的信息
  175. m_foodtypeLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_fenlei_layout")));
  176. m_foodtypeLayout->RemoveAll();
  177. CSqlite3 sqlite;
  178. m_nFoodpackageNum = sqlite.GetFoodpackageNum();
  179. m_types = sqlite.GetFoodtypes(); //只包含收银机显示的分类
  180. if (m_nFoodpackageNum > 0)
  181. {
  182. //默认选中的分类是商品套餐
  183. m_cur_type_id = "taocan";
  184. }
  185. else
  186. {
  187. //没有套餐,默认选中第一个商品分类
  188. if (m_types.size() > 0)
  189. {
  190. m_cur_type_id = m_types[0].id;
  191. }
  192. }
  193. m_curFoodtypeOption = NULL;
  194. //先判断有没有套餐分类
  195. if (m_nFoodpackageNum > 0)
  196. {
  197. CDialogBuilder builder;
  198. CDialogBuilderCallbackEx cb;
  199. CFoodtypeOptionUI* pItem = static_cast<CFoodtypeOptionUI*>(builder.Create(_T("foodtype_option.xml"), (UINT)0, &cb, m_pManager));
  200. pItem->SetName(L"商品套餐");
  201. pItem->SetTypeId("taocan");
  202. pItem->SetTaocan();
  203. pItem->SetGroup(L"diandan_foodtype");
  204. m_foodtypeLayout->Add(pItem);
  205. if (m_cur_type_id == "taocan")
  206. {
  207. m_curFoodtypeOption = pItem;
  208. }
  209. }
  210. //接下来开始处理商品分类
  211. for (std::vector<CFoodType>::iterator it = m_types.begin(); it != m_types.end(); it++)
  212. {
  213. CFoodType type = *it;
  214. CDialogBuilder builder;
  215. CDialogBuilderCallbackEx cb;
  216. CFoodtypeOptionUI* pItem = static_cast<CFoodtypeOptionUI*>(builder.Create(_T("foodtype_option.xml"), (UINT)0, &cb, m_pManager));
  217. pItem->SetName(CLewaimaiString::UTF8ToUnicode(type.name));
  218. pItem->SetTypeId(type.id);
  219. pItem->SetGroup(L"diandan_foodtype");
  220. m_foodtypeLayout->Add(pItem);
  221. if (m_cur_type_id == type.id)
  222. {
  223. m_curFoodtypeOption = pItem;
  224. }
  225. }
  226. if (m_curFoodtypeOption != NULL)
  227. {
  228. m_curFoodtypeOption->SetBkColor(0xFF3CB371);
  229. }
  230. //如果不是一个分类都没有,选中第一个分类
  231. if (m_cur_type_id != "")
  232. {
  233. CFoodtypeOptionUI* curTypeUI = static_cast<CFoodtypeOptionUI*>(m_foodtypeLayout->GetItemAt(0));
  234. curTypeUI->Selected(true, false);
  235. }
  236. UpdateFoodtypePos();
  237. }
  238. void CZhengcanDiandanPageUI::UpdateFoodtypePos()
  239. {
  240. int nFoodtypeNum = m_types.size();
  241. if (m_nFoodpackageNum > 0)
  242. {
  243. nFoodtypeNum++;
  244. }
  245. //添加支付方式
  246. int nWidth = m_nPageWidth;
  247. if (nWidth == 0)
  248. {
  249. return;
  250. }
  251. //根据宽度计算每行显示的数量
  252. int nMeihangNum = (nWidth - 491) / 135;
  253. int num = 0;
  254. CHorizontalLayoutUI* pFenleiLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_fenlei_layout")));
  255. for (int i = 0; i < nFoodtypeNum; i++)
  256. {
  257. CButtonUI* curItem = static_cast<CButtonUI*>(pFenleiLayout->GetItemAt(i));
  258. int curRow = num / nMeihangNum + 1;
  259. int curCol = num % nMeihangNum + 1;
  260. RECT rect;
  261. rect.left = (curCol - 1) * 135 + 15;
  262. rect.right = rect.left + 120;
  263. rect.top = (curRow - 1) * 61 + 19;
  264. rect.bottom = rect.top + 42;
  265. curItem->SetFloat(true);
  266. curItem->SetPos(rect);
  267. num++;
  268. }
  269. //调整区域高度
  270. int lastRow = (num - 1) / nMeihangNum + 1;
  271. pFenleiLayout->SetFixedHeight(lastRow * 61 + 19);
  272. //处理滚动条问题
  273. CVerticalLayoutUI* pFenleiScrollLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("diandan_fenlei_layout_scrolllayout")));
  274. if (lastRow > 2)
  275. {
  276. lastRow = 2;
  277. }
  278. pFenleiScrollLayout->SetFixedHeight(lastRow * 61 + 19);
  279. SIZE size;
  280. size.cx = 0;
  281. size.cy = 0;
  282. pFenleiScrollLayout->SetScrollPos(size);
  283. }
  284. void CZhengcanDiandanPageUI::InitFoodShow()
  285. {
  286. bool is_youtu;
  287. if (CSetting::GetInstance()->GetParam("setting_xianshi_is_youtu") == "1")
  288. {
  289. is_youtu = true;
  290. }
  291. else
  292. {
  293. is_youtu = false;
  294. }
  295. m_foodLayout = static_cast<CTileLayoutUI*>(this->FindSubControl(_T("diandan_foodlist")));
  296. m_foodLayout->RemoveAll();
  297. std::wstring xml_name;
  298. if (is_youtu)
  299. {
  300. SIZE itemsize;
  301. itemsize.cx = 160;
  302. itemsize.cy = 250;
  303. m_foodLayout->SetItemSize(itemsize);
  304. xml_name = _T("diandan_fooditem.xml");
  305. }
  306. else
  307. {
  308. SIZE itemsize;
  309. itemsize.cx = 160;
  310. itemsize.cy = 105;
  311. m_foodLayout->SetItemSize(itemsize);
  312. xml_name = _T("diandan_fooditem_wutu.xml");
  313. }
  314. //如果当前一个分类都没有,那么就不处理了
  315. if (m_cur_type_id == "")
  316. {
  317. return;
  318. }
  319. else if (m_cur_type_id == "taocan")
  320. {
  321. //选择的是套餐分类
  322. CSqlite3 sqlite;
  323. std::vector<CFoodpackage> foodlist = sqlite.GetFoodpackages(true);
  324. for (std::vector<CFoodpackage>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
  325. {
  326. CFoodpackage food = *it;
  327. CDialogBuilder builder;
  328. CDialogBuilderCallbackEx cb;
  329. CDiandanFoodItemUI* pItem = static_cast<CDiandanFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
  330. pItem->SetYoutuModel(is_youtu);
  331. pItem->SetFoodpackageInfo(food);
  332. pItem->UpdateShow();
  333. m_foodLayout->Add(pItem);
  334. }
  335. }
  336. else if (m_cur_type_id == "sousuo")
  337. {
  338. //展示的是商品搜索的结果
  339. CSqlite3 sqlite;
  340. std::vector<CFood> foodlist = sqlite.GetFoodByFoodname(m_sousuo_foodname);
  341. for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
  342. {
  343. CFood food = *it;
  344. CDialogBuilder builder;
  345. CDialogBuilderCallbackEx cb;
  346. CDiandanFoodItemUI* pItem = static_cast<CDiandanFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
  347. pItem->SetYoutuModel(is_youtu);
  348. pItem->SetFoodInfo(food);
  349. pItem->UpdateShow();
  350. m_foodLayout->Add(pItem);
  351. }
  352. }
  353. else
  354. {
  355. //选择的是普通商品分类
  356. CSqlite3 sqlite;
  357. std::vector<CFood> foodlist = sqlite.GetFoodByTypeid(m_cur_type_id);
  358. for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
  359. {
  360. CFood food = *it;
  361. CDialogBuilder builder;
  362. CDialogBuilderCallbackEx cb;
  363. CDiandanFoodItemUI* pItem = static_cast<CDiandanFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
  364. pItem->SetYoutuModel(is_youtu);
  365. pItem->SetFoodInfo(food);
  366. pItem->UpdateShow();
  367. m_foodLayout->Add(pItem);
  368. }
  369. }
  370. }
  371. //仅仅初始化结算相关的显示(比如折扣、优惠、价格等)
  372. void CZhengcanDiandanPageUI::InitJiesuanShow()
  373. {
  374. //先清空会员登录状态
  375. m_is_member = false;
  376. CButtonUI* pMemberLoginBtn = static_cast<CButtonUI*>(this->FindSubControl(_T("btn_diandan_member_login")));
  377. pMemberLoginBtn->SetVisible(true);
  378. CLabelUI* pMemberInfo = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_page_member_info")));
  379. pMemberInfo->SetVisible(false);
  380. m_is_member_zhekou = false;
  381. m_member_zhekou_value = 10;
  382. //整单备注
  383. CLabelUI* pLabel = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_page_label_zhengdanbeizhu")));
  384. pLabel->SetText(L"整单备注:");
  385. //先初始化折扣值
  386. CEditUI* pZhekouEdit = static_cast<CEditUI*>(this->FindSubControl(_T("diandan_jiesuan_zhekou_value")));
  387. pZhekouEdit->SetText(L"100");
  388. //再初始化加价
  389. m_jiajia = 0;
  390. CEditUI* pJiajiaEdit = static_cast<CEditUI*>(this->FindSubControl(_T("diandan_jiesuan_jiajia_value")));
  391. pJiajiaEdit->SetText(L"0");
  392. //初始化优惠
  393. m_rengong_youhui = 0;
  394. CEditUI* pYouhuiEdit = static_cast<CEditUI*>(this->FindSubControl(_T("diandan_jiesuan_youhui_value")));
  395. pYouhuiEdit->SetText(L"0");
  396. //优惠券
  397. m_is_youhuiquan = false;
  398. CLabelUI* pYouhuiquanEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_youhuiquan_status")));
  399. pYouhuiquanEdit->SetText(L"未使用");
  400. CButtonUI* pYouhuiquanCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_youhuiquan_btn_cancel")));
  401. pYouhuiquanCancel->SetVisible(false);
  402. //商品券
  403. m_is_shangpinquan = false;
  404. CLabelUI* pShangpinEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_shangpinquan_status")));
  405. pShangpinEdit->SetText(L"未使用");
  406. CButtonUI* pShangpinquanCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_shangpinquan_btn_cancel")));
  407. pShangpinquanCancel->SetVisible(false);
  408. //次卡
  409. m_is_cika = false;
  410. CLabelUI* pCikaEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_cika_status")));
  411. pCikaEdit->SetText(L"未使用");
  412. CButtonUI* pCikaCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_cika_btn_cancel")));
  413. pCikaCancel->SetVisible(false);
  414. //权益卡
  415. m_is_quanyika = false;
  416. CLabelUI* pQuanyikaEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_quanyika_status")));
  417. pQuanyikaEdit->SetText(L"未使用");
  418. CButtonUI* pQuanyikaCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_quanyika_btn_cancel")));
  419. pQuanyikaCancel->SetVisible(false);
  420. //抹零
  421. std::string diandan_moling_type = CSetting::GetInstance()->GetParam("diandan_moling_type");
  422. m_moling_type = atoi(diandan_moling_type.c_str());
  423. if (m_moling_type == 0)
  424. {
  425. CCheckBoxUI* pMolingCheck = static_cast<CCheckBoxUI*>(this->FindSubControl(_T("diandan_jiesuan_moling_bumoling")));
  426. pMolingCheck->Selected(true, false);
  427. }
  428. else if (m_moling_type == 1)
  429. {
  430. CCheckBoxUI* pMolingCheck = static_cast<CCheckBoxUI*>(this->FindSubControl(_T("diandan_jiesuan_moling_molingdaojiao")));
  431. pMolingCheck->Selected(true, false);
  432. }
  433. else if (m_moling_type == 2)
  434. {
  435. CCheckBoxUI* pMolingCheck = static_cast<CCheckBoxUI*>(this->FindSubControl(_T("diandan_jiesuan_moling_molingdaoyuan")));
  436. pMolingCheck->Selected(true, false);
  437. }
  438. }
  439. void CZhengcanDiandanPageUI::InitJiesuanZhifu()
  440. {
  441. CHorizontalLayoutUI* pZhifufangshiLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhifufangshi_layout")));
  442. int num = 0;
  443. CHorizontalLayoutUI* pWeixinLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhifufangshi_weixinzhifu")));
  444. if (CShopinfo::GetInstance()->m_is_online_pay_open == "1")
  445. {
  446. //展示微信支付,并且调整位置
  447. pWeixinLayout->SetVisible(true);
  448. num++;
  449. }
  450. else
  451. {
  452. pZhifufangshiLayout->RemoveAt(num);
  453. }
  454. //会员支付
  455. CHorizontalLayoutUI* pHuiyuanLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhifufangshi_huiyuan")));
  456. if (CShopinfo::GetInstance()->m_is_vip_pay_open == "1")
  457. {
  458. pHuiyuanLayout->SetVisible(true);
  459. num++;
  460. }
  461. else
  462. {
  463. pZhifufangshiLayout->RemoveAt(num);
  464. }
  465. //现金支付
  466. CHorizontalLayoutUI* pXianjinLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhifufangshi_xianjin")));
  467. if (CShopinfo::GetInstance()->m_is_cash_pay_open == "1")
  468. {
  469. pXianjinLayout->SetVisible(true);
  470. num++;
  471. }
  472. else
  473. {
  474. pZhifufangshiLayout->RemoveAt(num);
  475. }
  476. /*
  477. //购物卡
  478. CHorizontalLayoutUI* pGouwukaLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhifufangshi_gouwuka")));
  479. if (CShopinfo::GetInstance()->m_is_giftcard_pay_open == "1")
  480. {
  481. pGouwukaLayout->SetVisible(true);
  482. num++;
  483. }
  484. else
  485. {
  486. pGouwukaLayout->SetVisible(false);
  487. }
  488. //美食城临时卡
  489. CHorizontalLayoutUI* pMeishichengLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhifufangshi_meishicheng")));
  490. if (CShopinfo::GetInstance()->m_is_food_town_card_pay_open == "1")
  491. {
  492. pMeishichengLayout->SetVisible(true);
  493. num++;
  494. }
  495. else
  496. {
  497. pMeishichengLayout->SetVisible(false);
  498. }
  499. */
  500. //福利卡
  501. CHorizontalLayoutUI* pFulikaLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhifufangshi_fulika")));
  502. if (CShopinfo::GetInstance()->m_is_open_fulika_pay == "1")
  503. {
  504. pFulikaLayout->SetVisible(true);
  505. num++;
  506. }
  507. else
  508. {
  509. pZhifufangshiLayout->RemoveAt(num);
  510. }
  511. //接着添加自定义支付的
  512. for (std::vector<SelfPay>::iterator it = CShopinfo::GetInstance()->m_self_pay.begin(); it != CShopinfo::GetInstance()->m_self_pay.end(); it++)
  513. {
  514. SelfPay selfpay = *it;
  515. if (selfpay.is_open == "1")
  516. {
  517. CButtonUI* newButton = new CButtonUI();
  518. newButton->SetFixedWidth(120);
  519. newButton->SetFixedHeight(80);
  520. newButton->SetText(CLewaimaiString::UTF8ToUnicode(selfpay.name).c_str());
  521. newButton->SetBorderSize(1);
  522. newButton->SetBorderColor(0xFFC1C1C1);
  523. newButton->SetBkColor(0xFFF7F7F7);
  524. //设置定义属性,在点击按钮的时候好区分
  525. newButton->SetAttribute(L"name", L"diandan_jiesuan_zhifufangshi_zidingyi_btn");
  526. newButton->AddCustomAttribute(L"selfpay_id", CLewaimaiString::UTF8ToUnicode(selfpay.id).c_str());
  527. newButton->SetAttribute(L"float", L"true");
  528. //必须先Add,才能调用下面的SetPos,否则无效
  529. pZhifufangshiLayout->Add(newButton);
  530. num++;
  531. }
  532. }
  533. m_nZhiufuNum = num;
  534. }
  535. void CZhengcanDiandanPageUI::UpdateJiesuanZhifuPos()
  536. {
  537. //添加支付方式
  538. int nWidth = m_nPageWidth;
  539. if (nWidth == 0)
  540. {
  541. return;
  542. }
  543. int nZhangdanWidth = nWidth - 491 - 391 - 5;
  544. if (nZhangdanWidth < 290)
  545. {
  546. nZhangdanWidth = 290;
  547. }
  548. CVerticalLayoutUI* pZhangdanLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(L"diandan_page_jiesuan_zhangdan_layout"));
  549. pZhangdanLayout->SetFixedWidth(nZhangdanWidth);
  550. //根据宽度计算每行显示的数量
  551. int nMeihangNum = (nZhangdanWidth) / 144;
  552. if (nMeihangNum < 1)
  553. {
  554. nMeihangNum = 1;
  555. }
  556. int num = 0;
  557. CHorizontalLayoutUI* pZhifufangshiLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhifufangshi_layout")));
  558. for (int i = 0; i < m_nZhiufuNum; i++)
  559. {
  560. CButtonUI* curItem = static_cast<CButtonUI*>(pZhifufangshiLayout->GetItemAt(i));
  561. int curRow = num / nMeihangNum + 1;
  562. int curCol = num % nMeihangNum + 1;
  563. RECT rect;
  564. rect.left = (curCol - 1) * 140 + 20;
  565. rect.right = rect.left + 120;
  566. rect.top = (curRow - 1) * 100 + 20;
  567. rect.bottom = rect.top + 80;
  568. curItem->SetPos(rect);
  569. num++;
  570. }
  571. //调整区域高度
  572. int lastRow = (num - 1) / nMeihangNum + 1;
  573. pZhifufangshiLayout->SetFixedHeight(lastRow * 105);
  574. }
  575. //展示结算页面,隐藏选购页面
  576. void CZhengcanDiandanPageUI::ShowJiesuanPage()
  577. {
  578. //先隐藏商品页面
  579. CVerticalLayoutUI* pFoodLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("diandan_food_layout")));
  580. pFoodLayout->SetVisible(false);
  581. //隐藏结算区域
  582. CHorizontalLayoutUI* pPayLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_pay_layout")));
  583. pPayLayout->SetVisible(false);
  584. //再展示结算页面
  585. CHorizontalLayoutUI* pJiesuanLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_layout")));
  586. pJiesuanLayout->SetVisible(true);
  587. //展示继续加菜的区域
  588. CHorizontalLayoutUI* pJiesuanPayLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("jiesuan_pay_layout")));
  589. pJiesuanPayLayout->SetVisible(true);
  590. //处理一些按钮的显示与隐藏
  591. CButtonUI* jiaBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_jia"));
  592. jiaBtn->SetVisible(false);
  593. CButtonUI* jianBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_jian"));
  594. jianBtn->SetVisible(false);
  595. CButtonUI* shanchuBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_shanchu"));
  596. shanchuBtn->SetVisible(false);
  597. CButtonUI* guigeBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_guige"));
  598. guigeBtn->SetVisible(false);
  599. CButtonUI* tuicaiBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_tuicai"));
  600. tuicaiBtn->SetVisible(true);
  601. CButtonUI* dabaoBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_dabao"));
  602. dabaoBtn->SetVisible(false);
  603. CButtonUI* chetaiBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_chetai"));
  604. chetaiBtn->SetVisible(false);
  605. CButtonUI* huantaiBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_huantai"));
  606. huantaiBtn->SetVisible(true);
  607. //把购物车的商品,进行展示处理
  608. for (std::vector<CListContainerElementUI*>::iterator it = m_history_cart_item.begin(); it != m_history_cart_item.end(); it++)
  609. {
  610. CListContainerElementUI* pEle = *it;
  611. pEle->SetEnabled(true);
  612. CLabelUI * pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  613. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  614. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  615. pName->SetTextColor(0xFF000000);
  616. pNum->SetTextColor(0xFF000000);
  617. pPrice->SetTextColor(0xFF000000);
  618. }
  619. //更新结算按钮位置
  620. UpdateJiesuanZhifuPos();
  621. }
  622. //展示选购页面,隐藏结算页面
  623. void CZhengcanDiandanPageUI::ShowXuangouPage()
  624. {
  625. //先展示商品页面
  626. CVerticalLayoutUI* pFoodLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("diandan_food_layout")));
  627. pFoodLayout->SetVisible(true);
  628. //展示结算按钮
  629. CHorizontalLayoutUI* pPayLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_pay_layout")));
  630. pPayLayout->SetVisible(true);
  631. //再隐藏结算页面
  632. CHorizontalLayoutUI* pJiesuanLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_layout")));
  633. pJiesuanLayout->SetVisible(false);
  634. //隐藏继续加菜的区域
  635. CHorizontalLayoutUI* pJiesuanPayLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("jiesuan_pay_layout")));
  636. pJiesuanPayLayout->SetVisible(false);
  637. //处理一些按钮的显示与隐藏
  638. CButtonUI* jiaBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_jia"));
  639. jiaBtn->SetVisible(true);
  640. CButtonUI* jianBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_jian"));
  641. jianBtn->SetVisible(true);
  642. CButtonUI* shanchuBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_shanchu"));
  643. shanchuBtn->SetVisible(true);
  644. CButtonUI* guigeBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_guige"));
  645. guigeBtn->SetVisible(true);
  646. CButtonUI* tuicaiBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_tuicai"));
  647. tuicaiBtn->SetVisible(false);
  648. CButtonUI* dabaoBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_dabao"));
  649. dabaoBtn->SetVisible(true);
  650. CButtonUI* chetaiBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_chetai"));
  651. if (m_order_id == "0")
  652. {
  653. //还没下单,才显示撤台
  654. chetaiBtn->SetVisible(true);
  655. }
  656. else
  657. {
  658. chetaiBtn->SetVisible(false);
  659. }
  660. CButtonUI* huantaiBtn = static_cast<CButtonUI*>(this->FindSubControl(L"btn_diandan_huantai"));
  661. huantaiBtn->SetVisible(true);
  662. //把购物车的商品,进行展示处理
  663. for (std::vector<CListContainerElementUI*>::iterator it = m_history_cart_item.begin(); it != m_history_cart_item.end(); it++)
  664. {
  665. CListContainerElementUI* pEle = *it;
  666. pEle->SetEnabled(false);
  667. CLabelUI * pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  668. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  669. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  670. pName->SetTextColor(0xFFBBBBBB);
  671. pNum->SetTextColor(0xFFBBBBBB);
  672. pPrice->SetTextColor(0xFFBBBBBB);
  673. }
  674. }
  675. //处理按钮点击类事件
  676. void CZhengcanDiandanPageUI::HandleClickMsg(TNotifyUI& msg)
  677. {
  678. CDuiString name = msg.pSender->GetName();
  679. if (name == L"diandan_page_return")
  680. {
  681. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  682. }
  683. else if (name == L"diandan_fooditem")
  684. {
  685. CDiandanFoodItemUI* fooditemUI = static_cast<CDiandanFoodItemUI*>(msg.pSender);
  686. m_cur_click_food_item = fooditemUI;
  687. this->ClickFoodAction();
  688. }
  689. else if (name == L"btn_diandan_jia")
  690. {
  691. this->ClickAdd();
  692. }
  693. else if (name == L"btn_diandan_jian")
  694. {
  695. this->ClickDel();
  696. }
  697. else if (name == L"btn_diandan_shanchu")
  698. {
  699. this->ClickRemove();
  700. }
  701. else if (name == L"btn_diandan_guige")
  702. {
  703. this->ClickGuige();
  704. }
  705. else if (name == L"btn_diandan_qingkong")
  706. {
  707. this->ClickQingkong();
  708. }
  709. else if (name == L"btn_diandan_zhengdanbeizhu")
  710. {
  711. this->ClickZhengdanMemo();
  712. }
  713. else if (name == L"btn_diandan_chetai")
  714. {
  715. this->ClickChetai();
  716. }
  717. else if (name == L"btn_diandan_huantai")
  718. {
  719. this->ClickHuantai();
  720. }
  721. else if (name == L"btn_diandan_tuicai")
  722. {
  723. this->ClickTuicai();
  724. }
  725. else if (name == L"btn_diandan_xiadan")
  726. {
  727. //点击更多支付
  728. this->ClickXidanBtn();
  729. }
  730. else if (name == L"btn_diandan_pay")
  731. {
  732. //点击更多支付
  733. this->ClickPayBtn();
  734. }
  735. else if (name == L"btn_diandan_jixujiacai")
  736. {
  737. //点击继续加菜
  738. this->ShowXuangouPage();
  739. }
  740. else if (name == L"btn_diandan_chakanyouhui")
  741. {
  742. //点击查看优惠
  743. this->ClickChakanYouhui();
  744. }
  745. else if (name == L"btn_diandan_dabao")
  746. {
  747. //点击打包
  748. this->ClickDabao();
  749. }
  750. else if (name == L"btn_diandan_member_login")
  751. {
  752. //点击会员登录
  753. this->ClickMemberLogin();
  754. }
  755. else if (name == L"diandan_jiesuan_zhekou_value")
  756. {
  757. //点击整单折扣
  758. this->ClickZhekou();
  759. }
  760. else if (name == L"diandan_jiesuan_jiajia_value")
  761. {
  762. //点击加价
  763. this->ClickJiajia();
  764. }
  765. else if (name == L"diandan_jiesuan_youhui_value")
  766. {
  767. //点击人工优惠
  768. this->ClickRengongyouhui();
  769. }
  770. else if (name == L"diandan_jiesuan_youhuiquan_btn")
  771. {
  772. //点击扫码优惠券
  773. this->ClickSaomaYouhuiquan();
  774. }
  775. else if (name == L"diandan_jiesuan_shangpinquan_btn")
  776. {
  777. //点击扫码商品券
  778. this->ClickSaomaShangpinquan();
  779. }
  780. else if (name == L"diandan_jiesuan_cika_btn")
  781. {
  782. //点击扫码次卡
  783. this->ClickSaomaCika();
  784. }
  785. else if (name == L"diandan_jiesuan_quanyika_btn")
  786. {
  787. //点击扫码权益卡
  788. this->ClickSaomaQuanyika();
  789. }
  790. else if (name == L"btn_diandan_canpaihao")
  791. {
  792. //点击人数
  793. this->ClickRenshu();
  794. }
  795. else if (name == L"btn_diandan_weixinzhifu_pay" || name == L"diandan_jiesuan_zhifufangshi_weixinzhifu_btn")
  796. {
  797. //点击微信支付
  798. this->StartWeixinzhifuShoukuan();
  799. }
  800. else if (name == L"btn_diandan_huiyuanzhifu_pay" || name == L"diandan_jiesuan_zhifufangshi_huiyuan_btn")
  801. {
  802. //点击会员收款
  803. this->StartHuiyuanShoukuan();
  804. }
  805. else if (name == L"btn_diandan_xianjinzhifu_pay" || name == L"diandan_jiesuan_zhifufangshi_xianjin_btn")
  806. {
  807. //点击现金收款
  808. this->StartXianjinShoukuan();
  809. }
  810. else if (name == L"diandan_jiesuan_zhifufangshi_fulika_btn")
  811. {
  812. //福利卡收款
  813. this->StartFulikaShoukuan();
  814. }
  815. else if (name == L"diandan_jiesuan_zhifufangshi_zidingyi_btn")
  816. {
  817. //自定义支付
  818. std::wstring name = msg.pSender->GetText();
  819. std::wstring selfpay_id = msg.pSender->GetCustomAttribute(L"selfpay_id");
  820. this->StartZidingyiShoukuan(name, selfpay_id);
  821. }
  822. else if (name == L"diandan_food_search_clear")
  823. {
  824. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("diandan_food_search_edit")));
  825. m_pEdit->SetText(L"");
  826. StopSerachFood();
  827. }
  828. else if (name == L"btn_diandan_qianxiang")
  829. {
  830. CPosPrinter printer;
  831. printer.OpenQianxiang();
  832. }
  833. else if (name == L"diandan_jiesuan_youhuiquan_btn_cancel")
  834. {
  835. this->ClickQuxiaoYouhuiquan();
  836. }
  837. else if (name == L"diandan_jiesuan_shangpinquan_btn_cancel")
  838. {
  839. this->ClickQuxiaoShangpinquan();
  840. }
  841. else if (name == L"diandan_jiesuan_quanyika_btn_cancel")
  842. {
  843. this->ClickQuxiaoQuanyika();
  844. }
  845. else if (name == L"diandan_jiesuan_cika_btn_cancel")
  846. {
  847. this->ClickQuxiaoCika();
  848. }
  849. }
  850. //处理option切换事件
  851. void CZhengcanDiandanPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
  852. {
  853. CDuiString name = msg.pSender->GetName();
  854. COptionUI* curOption = static_cast<COptionUI*>(msg.pSender);
  855. std::wstring groupname = curOption->GetGroup();
  856. if (groupname == L"diandan_foodtype")
  857. {
  858. //商品分类切换
  859. CFoodtypeOptionUI* typeUI = static_cast<CFoodtypeOptionUI*>(curOption);
  860. std::string id = typeUI->GetTypeId();
  861. if (m_cur_type_id != id)
  862. {
  863. //切换了商品分类
  864. m_curFoodtypeOption->SetBkColor(0xFFECECEC);
  865. msg.pSender->SetBkColor(0xFF3CB371);
  866. m_curFoodtypeOption = static_cast<CControlUI*>(msg.pSender);
  867. m_cur_type_id = id;
  868. this->InitFoodShow();
  869. return;
  870. }
  871. }
  872. else if (groupname == L"diandan_jiesuan_moling")
  873. {
  874. if (name == _T("diandan_jiesuan_moling_bumoling"))
  875. {
  876. m_moling_type = 0;
  877. CSetting::GetInstance()->SetParam("diandan_moling_type", "0");
  878. UpdateJiesuanInfo();
  879. }
  880. else if (name == _T("diandan_jiesuan_moling_molingdaojiao"))
  881. {
  882. m_moling_type = 1;
  883. CSetting::GetInstance()->SetParam("diandan_moling_type", "1");
  884. UpdateJiesuanInfo();
  885. }
  886. else if (name == _T("diandan_jiesuan_moling_molingdaoyuan"))
  887. {
  888. m_moling_type = 2;
  889. CSetting::GetInstance()->SetParam("diandan_moling_type", "2");
  890. UpdateJiesuanInfo();
  891. }
  892. }
  893. }
  894. //处理下拉框、radio的切换事件
  895. void CZhengcanDiandanPageUI::HandleItemSelectMsg(TNotifyUI& msg)
  896. {
  897. }
  898. //处理编辑框输入内容改变事件
  899. void CZhengcanDiandanPageUI::HandleTextChangedMsg(TNotifyUI& msg)
  900. {
  901. CDuiString name = msg.pSender->GetName();
  902. if (name == L"diandan_food_search_edit")
  903. {
  904. //商品搜索框的输入事件
  905. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("diandan_food_search_edit")));
  906. wstring ws_Value = m_pEdit->GetText();
  907. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  908. if (strValue.length() == 0)
  909. {
  910. //搜索词被清空了,退出搜索
  911. this->StopSerachFood();
  912. }
  913. else
  914. {
  915. //搜索词没清空,进入搜索
  916. this->StartSearchFood(strValue);
  917. }
  918. }
  919. }
  920. //处理扫码枪捕捉到的扫码信息
  921. void CZhengcanDiandanPageUI::HandleTextCapture(std::string content)
  922. {
  923. if (m_is_show_modal_wnd == true)
  924. {
  925. m_curModalWnd->HandleTextCapture(content);
  926. return;
  927. }
  928. //没有任何弹框,那么就是按扫描商品条码来处理
  929. bool ret = this->SaomiaoBarcode(content);
  930. if (ret == true)
  931. {
  932. //已经找到了条码,那么就处理完了
  933. return;
  934. }
  935. if (content.length() != 12 && content.length() != 13 && content.length() != 17 && content.length() != 18)
  936. {
  937. //位数不对,那肯定不是称重条码
  938. }
  939. else
  940. {
  941. //如果没有找到条码,就找一下是不是称重的标签秤的码,这个时候要对码进行各种分析了
  942. ret = this->BiaoqianchengSaomaBarcode(content);
  943. if (ret == true)
  944. {
  945. return;
  946. }
  947. }
  948. //代码走到这里,肯定不是条码了,也不是称重码,判断是不是付款码
  949. std::string s_Fukuanma = content;
  950. int length = s_Fukuanma.size();
  951. if (length != 18 && length != 19)
  952. {
  953. //肯定不是付款码
  954. m_pMainWnd->ShowToast(L"无效的条码!");
  955. return;
  956. }
  957. for (int i = 0; i < length; i++)
  958. {
  959. char c = *(s_Fukuanma.c_str() + i);
  960. if (isdigit(c) == 0)
  961. {
  962. //不是数字
  963. m_pMainWnd->ShowToast(L"无效的条码!");
  964. return;
  965. }
  966. }
  967. if (s_Fukuanma.find("10") == 0 \
  968. || s_Fukuanma.find("11") == 0 \
  969. || s_Fukuanma.find("12") == 0 \
  970. || s_Fukuanma.find("13") == 0 \
  971. || s_Fukuanma.find("14") == 0 \
  972. || s_Fukuanma.find("15") == 0)
  973. {
  974. //微信付款码
  975. }
  976. else if (s_Fukuanma.find("25") == 0 \
  977. || s_Fukuanma.find("26") == 0 \
  978. || s_Fukuanma.find("27") == 0 \
  979. || s_Fukuanma.find("28") == 0 \
  980. || s_Fukuanma.find("29") == 0 \
  981. || s_Fukuanma.find("30") == 0)
  982. {
  983. //支付宝付款码
  984. }
  985. else if (s_Fukuanma.find("62") == 0)
  986. {
  987. //云闪付付款码
  988. }
  989. else
  990. {
  991. m_pMainWnd->ShowToast(L"无效的条码!");
  992. return;
  993. }
  994. //代码能走到这里,说明肯定就是付款码了,默认唤起支付
  995. this->StartWeixinzhifuShoukuan(content);
  996. }
  997. void CZhengcanDiandanPageUI::UpdateShopcartShow()
  998. {
  999. //先保留选中
  1000. CListUI* pList = static_cast<CListUI*>(this->FindSubControl(_T("list_diandan_cart")));
  1001. int nIndex = pList->GetCurSel();
  1002. //先清空
  1003. pList->RemoveAll();
  1004. int nItemNum = m_cur_diandan_order.getItemNum();
  1005. for (int i = 0; i < nItemNum; i++)
  1006. {
  1007. CZhengcanOrderItem item = m_cur_diandan_order.getDiandanOrderItem(i);
  1008. CDialogBuilder builder;
  1009. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("diandan_cart_item.xml"), (UINT)0, NULL, m_pManager));
  1010. pList->Add(pEle);
  1011. if (item.m_is_taocan)
  1012. {
  1013. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  1014. pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
  1015. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  1016. pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
  1017. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  1018. pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
  1019. CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
  1020. pEle->SetFixedHeight(84);
  1021. pNature->SetVisible(true);
  1022. pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
  1023. }
  1024. else
  1025. {
  1026. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  1027. pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
  1028. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  1029. pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
  1030. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  1031. pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
  1032. CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
  1033. if (item.is_nature)
  1034. {
  1035. pEle->SetFixedHeight(84);
  1036. pNature->SetVisible(true);
  1037. pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
  1038. }
  1039. else
  1040. {
  1041. pEle->SetFixedHeight(42);
  1042. pNature->SetVisible(false);
  1043. }
  1044. }
  1045. }
  1046. //保留选中
  1047. if (nIndex != -1 && pList->GetCount() > 0)
  1048. {
  1049. if (nIndex <= pList->GetCount() - 1)
  1050. {
  1051. pList->SelectItem(nIndex, false);
  1052. }
  1053. else
  1054. {
  1055. pList->SelectItem(pList->GetCount() - 1, false);
  1056. }
  1057. }
  1058. int xiadan_cishu = m_cur_diandan_order.m_order_history_array.size();
  1059. m_history_cart_item.clear();
  1060. //开始处理历史的订单数据渲染
  1061. for (int i = xiadan_cishu - 1; i >= 0 ; i--)
  1062. {
  1063. CLabelUI* attention = new CLabelUI();
  1064. attention->SetText((L"--------------------- 第" + to_wstring(m_cur_diandan_order.m_order_history_array[i].xiadanNum + 1) + L"次下单 --------------------").c_str());
  1065. attention->SetTextColor(0xFFBBBBBB);
  1066. pList->Add(attention);
  1067. for (std::vector<CZhengcanOrderItem>::iterator it1 = m_cur_diandan_order.m_order_history_array[i].m_items.begin(); it1 != m_cur_diandan_order.m_order_history_array[i].m_items.end(); it1++)
  1068. {
  1069. //添加item
  1070. CDialogBuilder builder;
  1071. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("diandan_cart_item.xml"), (UINT)0, NULL, m_pManager));
  1072. pEle->SetEnabled(false);
  1073. pList->Add(pEle);
  1074. CZhengcanOrderItem item = *it1;
  1075. //保存item_id,后面选中点击退菜的时候有用
  1076. pEle->AddCustomAttribute(L"item_id", CLewaimaiString::UTF8ToUnicode(item.item_id).c_str());
  1077. CLabelUI * pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  1078. if (item.is_tuicai == "1")
  1079. {
  1080. pName->SetText((L"【退菜】" + CLewaimaiString::UTF8ToUnicode(item.getNameShow())).c_str());
  1081. pEle->AddCustomAttribute(L"is_tuicai", L"1");
  1082. }
  1083. else
  1084. {
  1085. pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
  1086. pEle->AddCustomAttribute(L"is_tuicai", L"0");
  1087. }
  1088. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  1089. pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
  1090. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  1091. pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
  1092. pName->SetTextColor(0xFFBBBBBB);
  1093. pNum->SetTextColor(0xFFBBBBBB);
  1094. pPrice->SetTextColor(0xFFBBBBBB);
  1095. if (item.m_is_taocan)
  1096. {
  1097. CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
  1098. pEle->SetFixedHeight(84);
  1099. pNature->SetVisible(true);
  1100. pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getHistoryNatureShow()).c_str());
  1101. pNature->SetTextColor(0xFFBBBBBB);
  1102. }
  1103. else
  1104. {
  1105. pEle->SetFixedHeight(42);
  1106. }
  1107. m_history_cart_item.push_back(pEle);
  1108. }
  1109. }
  1110. //更新结算信息
  1111. UpdateJiesuanInfo();
  1112. }
  1113. void CZhengcanDiandanPageUI::UpdateJiesuanInfo()
  1114. {
  1115. //先按所有的价格公式规则,计算一次价格
  1116. //(基础商品价格+属性价格-商品券-次卡(抵扣金额、抵扣商品)-会员商品优惠)*店铺折扣*分等级会员折扣*权益卡折扣*次卡折扣-满减优惠-次卡满减-优惠券+加价-优惠-抹零+开台费+打包费+茶位费
  1117. //先计算基础商品价格(不包含任何优惠活动等情况下的实际金额,已包含商品属性价格)
  1118. double jichu_price = m_cur_diandan_order.getTotalPrice();
  1119. //这个是临时变量,表示每次优惠过后的实时价格
  1120. double cur_price = jichu_price;
  1121. double total_youhui = 0;
  1122. //判断是否有商品券,如果有的话把金额抵扣掉
  1123. m_shangpinquan_youhui = 0;
  1124. if (m_is_shangpinquan)
  1125. {
  1126. //判断当前购物车商品,是否有满足对应商品券使用要求的
  1127. bool ret = m_cur_diandan_order.UseShangpinquan(m_shangpinquan_foodid, m_shangpinquan_youhui);
  1128. total_youhui += m_shangpinquan_youhui;
  1129. }
  1130. //判断次卡
  1131. m_cika_youhui = 0;
  1132. if (m_is_cika)
  1133. {
  1134. //对次卡进行处理
  1135. if (m_cika_deduct_type == "0")
  1136. {
  1137. }
  1138. else if (m_cika_deduct_type == "1")
  1139. {
  1140. }
  1141. else if (m_cika_deduct_type == "2")
  1142. {
  1143. m_cika_youhui = atof(m_cika_offer_value.c_str());
  1144. }
  1145. else if (m_cika_deduct_type == "3")
  1146. {
  1147. //这种情况是次卡跟商品券一样抵扣商品\
  1148. bool ret;
  1149. if (m_is_shangpinquan && m_shangpinquan_foodid == m_cika_bind_foods_id)
  1150. {
  1151. ret = m_cur_diandan_order.UseCikaDikou(m_cika_bind_foods_id, m_cika_youhui, true);
  1152. }
  1153. else
  1154. {
  1155. ret = m_cur_diandan_order.UseCikaDikou(m_cika_bind_foods_id, m_cika_youhui, false);
  1156. }
  1157. }
  1158. total_youhui += m_cika_youhui;
  1159. }
  1160. //判断会员商品优惠
  1161. m_total_member_youhui = 0;
  1162. if (m_is_member)
  1163. {
  1164. m_total_member_youhui = m_cur_diandan_order.getTotalMemberYouhui(m_member_level);
  1165. }
  1166. total_youhui += m_total_member_youhui;
  1167. cur_price = jichu_price - total_youhui;
  1168. //再判断整单折扣
  1169. CEditUI* pZhekouEdit = static_cast<CEditUI*>(this->FindSubControl(_T("diandan_jiesuan_zhekou_value")));
  1170. wstring ws_zhekou = pZhekouEdit->GetText();
  1171. int zhekouValue = atoi(CLewaimaiString::UnicodeToUTF8(ws_zhekou).c_str());
  1172. m_zhekou_value = zhekouValue;
  1173. if (zhekouValue == 100)
  1174. {
  1175. m_zhekou_youhui = 0;
  1176. }
  1177. else
  1178. {
  1179. m_zhekou_youhui = (100 - zhekouValue) * cur_price / 100.00;
  1180. total_youhui += m_zhekou_youhui;
  1181. cur_price = cur_price - m_zhekou_youhui;
  1182. }
  1183. //再判断分等级会员折扣
  1184. m_member_zhekou_youhui = 0;
  1185. std::vector<DiscountInfo> member_discount_info = CShopinfo::GetInstance()->m_discount_info;
  1186. for (std::vector<DiscountInfo>::iterator it = member_discount_info.begin(); it != member_discount_info.end(); it++)
  1187. {
  1188. DiscountInfo info = *it;
  1189. if (info.member_level == m_member_level)
  1190. {
  1191. if (info.is_discount == "1")
  1192. {
  1193. m_is_member_zhekou = true;
  1194. m_member_zhekou_value = info.discount_value;
  1195. double member_discount = atof(info.discount_value.c_str());
  1196. if (abs(member_discount - 10) < 0.0001)
  1197. {
  1198. m_member_zhekou_youhui = 0;
  1199. }
  1200. else
  1201. {
  1202. m_member_zhekou_youhui = (10 - member_discount) * cur_price / 10.00;
  1203. total_youhui += m_member_zhekou_youhui;
  1204. cur_price -= m_member_zhekou_youhui;
  1205. }
  1206. break;
  1207. }
  1208. }
  1209. }
  1210. //再判断权益卡折扣
  1211. m_quanyika_youhui = 0;
  1212. if (m_is_quanyika == true)
  1213. {
  1214. double quanyika_zhekou = atof(m_quanyika_discount.c_str());
  1215. if (abs(quanyika_zhekou - 10) < 0.0001)
  1216. {
  1217. m_quanyika_youhui = 0;
  1218. }
  1219. else
  1220. {
  1221. m_quanyika_youhui = (10 - quanyika_zhekou) * cur_price / 10.00;
  1222. total_youhui += m_quanyika_youhui;
  1223. cur_price -= m_quanyika_youhui;
  1224. }
  1225. }
  1226. //次卡折扣
  1227. if (m_is_cika)
  1228. {
  1229. //对次卡进行处理
  1230. if (m_cika_deduct_type == "0")
  1231. {
  1232. double cika_zhekou = atof(m_cika_discount_value.c_str());
  1233. if (abs(cika_zhekou - 10) < 0.0001)
  1234. {
  1235. m_cika_youhui = 0;
  1236. }
  1237. else
  1238. {
  1239. m_cika_youhui = (10 - cika_zhekou) * cur_price / 10.00;
  1240. total_youhui += m_cika_youhui;
  1241. cur_price -= m_cika_youhui;
  1242. }
  1243. }
  1244. }
  1245. //满减优惠
  1246. m_manjian_youhui = 0;
  1247. if (CShopinfo::GetInstance()->m_open_promotion == "1")
  1248. {
  1249. //开启了满减,进行判断
  1250. std::vector<Promotion> promotion = CShopinfo::GetInstance()->m_promotion;
  1251. for (std::vector<Promotion>::iterator it = promotion.begin(); it != promotion.end(); it++)
  1252. {
  1253. Promotion cur = *it;
  1254. if (jichu_price >= cur.amount)
  1255. {
  1256. m_manjian_youhui = cur.discount;
  1257. total_youhui += m_manjian_youhui;
  1258. cur_price -= m_manjian_youhui;
  1259. break;
  1260. }
  1261. }
  1262. }
  1263. //次卡满减
  1264. if (m_is_cika)
  1265. {
  1266. //对次卡进行处理
  1267. if (m_cika_deduct_type == "1")
  1268. {
  1269. std::vector<std::string> manjian = CLewaimaiString::Split(m_cika_full_reduce_value, ",");
  1270. double amount = atof(manjian[0].c_str());
  1271. double value = atof(manjian[1].c_str());
  1272. if (jichu_price >= amount)
  1273. {
  1274. m_cika_youhui = value;
  1275. total_youhui += m_cika_youhui;
  1276. cur_price -= m_cika_youhui;
  1277. }
  1278. }
  1279. }
  1280. //优惠券
  1281. m_youhuiquan_youhui = 0;
  1282. if (m_is_youhuiquan)
  1283. {
  1284. time_t deadline = CLewaimaiTime::StringToDatetime(m_coupon_deadline);
  1285. time_t now = time(NULL);
  1286. if (deadline > now)
  1287. {
  1288. if (jichu_price >= atof(m_coupon_basic_price.c_str()))
  1289. {
  1290. m_youhuiquan_youhui = atof(m_coupon_value.c_str());
  1291. total_youhui += m_youhuiquan_youhui;
  1292. cur_price -= m_youhuiquan_youhui;
  1293. }
  1294. }
  1295. }
  1296. //加价
  1297. m_jiajia = 0;
  1298. CEditUI* pJiajiaEdit = static_cast<CEditUI*>(this->FindSubControl(_T("diandan_jiesuan_jiajia_value")));
  1299. wstring ws_jiajia = pJiajiaEdit->GetText();
  1300. m_jiajia = atof(CLewaimaiString::UnicodeToUTF8(ws_jiajia).c_str());
  1301. cur_price += m_jiajia;
  1302. //人工优惠
  1303. m_rengong_youhui = 0;
  1304. CEditUI* pYouhuiEdit = static_cast<CEditUI*>(this->FindSubControl(_T("diandan_jiesuan_youhui_value")));
  1305. wstring ws_rengong_youhui = pYouhuiEdit->GetText();
  1306. m_rengong_youhui = atof(CLewaimaiString::UnicodeToUTF8(ws_rengong_youhui).c_str());
  1307. total_youhui += m_rengong_youhui;
  1308. cur_price -= m_rengong_youhui;
  1309. //打包费
  1310. m_dabao = m_cur_diandan_order.getDabaoMoney();
  1311. cur_price += m_dabao;
  1312. //开台费
  1313. cur_price += m_kaitai;
  1314. //茶位费
  1315. m_chawei = m_tea_fee * atoi(m_renshu.c_str());
  1316. cur_price += m_chawei;
  1317. //抹零
  1318. m_moling_youhui = 0;
  1319. if (m_moling_type == 0)
  1320. {
  1321. }
  1322. else if (m_moling_type == 1)
  1323. {
  1324. double new_price = (int)(cur_price * 10) / 10.0;
  1325. m_moling_youhui = cur_price - new_price;
  1326. total_youhui += m_moling_youhui;
  1327. cur_price = new_price;
  1328. }
  1329. else if (m_moling_type == 2)
  1330. {
  1331. double new_price = (int)(cur_price);
  1332. m_moling_youhui = cur_price - new_price;
  1333. total_youhui += m_moling_youhui;
  1334. cur_price = new_price;
  1335. }
  1336. if (cur_price < 0)
  1337. {
  1338. cur_price = 0;
  1339. }
  1340. m_cur_total_price = cur_price;
  1341. m_total_youhui = total_youhui;
  1342. //至此优惠全部处理完了,开始刷新各个地方的展示
  1343. //先刷新优惠展示
  1344. CHorizontalLayoutUI* pYouhuiLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_page_youhui_tishi_layout")));
  1345. CLabelUI* pYouhuiLabel = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_page_youhui_tishi")));
  1346. if (total_youhui > 0)
  1347. {
  1348. wstring youhuilabel = L"已优惠 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_youhui, 2)) + L" 元";
  1349. pYouhuiLabel->SetText(youhuilabel.c_str());
  1350. pYouhuiLayout->SetVisible(true);
  1351. }
  1352. else
  1353. {
  1354. pYouhuiLayout->SetVisible(false);
  1355. }
  1356. //再刷新打包费展示
  1357. CLabelUI* pOtherPriceLabel = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_page_otherprice")));
  1358. std::wstring otherPrice = L"";
  1359. if (m_dabao > 0)
  1360. {
  1361. std::wstring ws_dabaofei = L"打包费 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_dabao, 2)) + L" 元 ";
  1362. otherPrice += ws_dabaofei;
  1363. }
  1364. //开台费
  1365. if (m_kaitai > 0)
  1366. {
  1367. std::wstring ws_kaitaifei = L"开台费 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_kaitai, 2)) + L" 元 ";
  1368. otherPrice += ws_kaitaifei;
  1369. }
  1370. //茶位费
  1371. if (m_chawei > 0)
  1372. {
  1373. std::wstring ws_chaweifei = L"茶位费 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_chawei, 2)) + L" 元 ";
  1374. otherPrice += ws_chaweifei;
  1375. }
  1376. pOtherPriceLabel->SetText(otherPrice.c_str());
  1377. //再刷新总价展示
  1378. CLabelUI* pTotalPrice = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_page_totalprice")));
  1379. pTotalPrice->SetText((L"总价:¥" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(cur_price, 2))).c_str());
  1380. //再刷新账单明细展示
  1381. CVerticalLayoutUI* pmingxiLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("diandan_jiesuan_zhangdanmingxi_jiage_layout")));
  1382. pmingxiLayout->RemoveAll();
  1383. int item_num = 0;
  1384. //先显示基础价格
  1385. if (true)
  1386. {
  1387. CDialogBuilder builder;
  1388. CDialogBuilderCallbackEx cb;
  1389. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1390. pmingxiLayout->Add(pItem);
  1391. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1392. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1393. pName->SetText(L"商品原价:");
  1394. pValue->SetText((CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(jichu_price, 2)) + L"元").c_str());
  1395. item_num++;
  1396. }
  1397. //开始展示各种优惠
  1398. if (m_shangpinquan_youhui > 0)
  1399. {
  1400. CDialogBuilder builder;
  1401. CDialogBuilderCallbackEx cb;
  1402. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1403. pmingxiLayout->Add(pItem);
  1404. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1405. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1406. pName->SetText(L"商品券优惠:");
  1407. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_shangpinquan_youhui, 2)) + L"元").c_str());
  1408. item_num++;
  1409. }
  1410. if (m_cika_youhui > 0)
  1411. {
  1412. CDialogBuilder builder;
  1413. CDialogBuilderCallbackEx cb;
  1414. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1415. pmingxiLayout->Add(pItem);
  1416. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1417. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1418. pName->SetText(L"次卡优惠:");
  1419. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_cika_youhui, 2)) + L"元").c_str());
  1420. item_num++;
  1421. }
  1422. if (m_total_member_youhui > 0)
  1423. {
  1424. CDialogBuilder builder;
  1425. CDialogBuilderCallbackEx cb;
  1426. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1427. pmingxiLayout->Add(pItem);
  1428. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1429. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1430. pName->SetText(L"商品会员价优惠:");
  1431. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_total_member_youhui, 2)) + L"元").c_str());
  1432. item_num++;
  1433. }
  1434. if (m_zhekou_youhui > 0)
  1435. {
  1436. CDialogBuilder builder;
  1437. CDialogBuilderCallbackEx cb;
  1438. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1439. pmingxiLayout->Add(pItem);
  1440. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1441. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1442. pName->SetText(L"整单折扣优惠:");
  1443. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_zhekou_youhui, 2)) + L"元").c_str());
  1444. item_num++;
  1445. }
  1446. if (m_member_zhekou_youhui > 0)
  1447. {
  1448. CDialogBuilder builder;
  1449. CDialogBuilderCallbackEx cb;
  1450. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1451. pmingxiLayout->Add(pItem);
  1452. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1453. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1454. pName->SetText(L"会员整单折扣优惠:");
  1455. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_member_zhekou_youhui, 2)) + L"元").c_str());
  1456. item_num++;
  1457. }
  1458. if (m_quanyika_youhui > 0)
  1459. {
  1460. CDialogBuilder builder;
  1461. CDialogBuilderCallbackEx cb;
  1462. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1463. pmingxiLayout->Add(pItem);
  1464. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1465. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1466. pName->SetText(L"权益卡优惠:");
  1467. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_quanyika_youhui, 2)) + L"元").c_str());
  1468. item_num++;
  1469. }
  1470. if (m_manjian_youhui > 0)
  1471. {
  1472. CDialogBuilder builder;
  1473. CDialogBuilderCallbackEx cb;
  1474. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1475. pmingxiLayout->Add(pItem);
  1476. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1477. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1478. pName->SetText(L"满减优惠:");
  1479. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_manjian_youhui, 2)) + L"元").c_str());
  1480. item_num++;
  1481. }
  1482. if (m_youhuiquan_youhui > 0)
  1483. {
  1484. CDialogBuilder builder;
  1485. CDialogBuilderCallbackEx cb;
  1486. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1487. pmingxiLayout->Add(pItem);
  1488. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1489. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1490. pName->SetText(L"优惠券优惠:");
  1491. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_youhuiquan_youhui, 2)) + L"元").c_str());
  1492. item_num++;
  1493. }
  1494. if (m_rengong_youhui > 0)
  1495. {
  1496. CDialogBuilder builder;
  1497. CDialogBuilderCallbackEx cb;
  1498. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1499. pmingxiLayout->Add(pItem);
  1500. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1501. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1502. pName->SetText(L"人工优惠:");
  1503. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_rengong_youhui, 2)) + L"元").c_str());
  1504. item_num++;
  1505. }
  1506. if (m_moling_youhui > 0)
  1507. {
  1508. CDialogBuilder builder;
  1509. CDialogBuilderCallbackEx cb;
  1510. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1511. pmingxiLayout->Add(pItem);
  1512. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1513. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1514. pName->SetText(L"抹零优惠:");
  1515. pValue->SetText((L"-" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_moling_youhui, 2)) + L"元").c_str());
  1516. item_num++;
  1517. }
  1518. //然后处理加价的各种
  1519. if (m_dabao > 0)
  1520. {
  1521. CDialogBuilder builder;
  1522. CDialogBuilderCallbackEx cb;
  1523. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1524. pmingxiLayout->Add(pItem);
  1525. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1526. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1527. pName->SetText(L"打包费:");
  1528. pValue->SetText((L"+" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_dabao, 2)) + L"元").c_str());
  1529. item_num++;
  1530. }
  1531. if (m_kaitai > 0)
  1532. {
  1533. CDialogBuilder builder;
  1534. CDialogBuilderCallbackEx cb;
  1535. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1536. pmingxiLayout->Add(pItem);
  1537. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1538. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1539. pName->SetText(L"开台费:");
  1540. pValue->SetText((L"+" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_kaitai, 2)) + L"元").c_str());
  1541. item_num++;
  1542. }
  1543. if (m_chawei > 0)
  1544. {
  1545. CDialogBuilder builder;
  1546. CDialogBuilderCallbackEx cb;
  1547. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1548. pmingxiLayout->Add(pItem);
  1549. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1550. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1551. pName->SetText(L"茶位费:");
  1552. pValue->SetText((L"+" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_chawei, 2)) + L"元").c_str());
  1553. item_num++;
  1554. }
  1555. if (m_jiajia > 0)
  1556. {
  1557. CDialogBuilder builder;
  1558. CDialogBuilderCallbackEx cb;
  1559. CHorizontalLayoutUI* pItem = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("diandan_zhangdanmingxi_item.xml"), (UINT)0, &cb, m_pManager));
  1560. pmingxiLayout->Add(pItem);
  1561. CLabelUI* pName = static_cast<CLabelUI*>(pItem->FindSubControl(_T("name")));
  1562. CLabelUI* pValue = static_cast<CLabelUI*>(pItem->FindSubControl(_T("value")));
  1563. pName->SetText(L"人工加价:");
  1564. pValue->SetText((L"+" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(m_jiajia, 2)) + L"元").c_str());
  1565. item_num++;
  1566. }
  1567. pmingxiLayout->SetFixedHeight(item_num * 40);
  1568. CLabelUI* pYingshou = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_total_yingshou")));
  1569. pYingshou->SetText((L"应收金额:" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(cur_price, 2)) + L"元").c_str());
  1570. //同步更新副屏的显示内容
  1571. CShuangpingTool::GetInstance()->UpdateShow(m_cur_diandan_order, total_youhui, cur_price, m_dabao);
  1572. }
  1573. void CZhengcanDiandanPageUI::ClickFoodAction()
  1574. {
  1575. bool is_taocan = m_cur_click_food_item->GetIsTaocan();
  1576. if (is_taocan)
  1577. {
  1578. //点击套餐之后的处理逻辑
  1579. CFoodpackage foodpackageinfo = m_cur_click_food_item->GetFoodpackageInfo();
  1580. CZhengcanOrderItem clickItem;
  1581. clickItem.foodpackage_id = foodpackageinfo.id;
  1582. clickItem.foodpackage_name = foodpackageinfo.name;
  1583. clickItem.price = foodpackageinfo.price;
  1584. clickItem.is_dabao = false;
  1585. clickItem.dabao_money = foodpackageinfo.dabao_money;
  1586. clickItem.num = "1";
  1587. //把当前点击商品的信息,保存到orderitem里面,方便后面修改规格的时候使用
  1588. clickItem.SetFoodpackageInfo(m_cur_click_food_item->GetFoodpackageInfo());
  1589. clickItem.SetIsTaocan(true);
  1590. if (m_is_show_modal_wnd == true)
  1591. {
  1592. return;
  1593. }
  1594. //先弹框进行选择属性
  1595. CDiandanNatureWnd* pNatureFrame = new CDiandanNatureWnd(1);
  1596. pNatureFrame->SetFoodItemUI(m_cur_click_food_item);
  1597. if (pNatureFrame != NULL)
  1598. {
  1599. m_is_show_modal_wnd = true;
  1600. m_curModalWnd = pNatureFrame;
  1601. pNatureFrame->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  1602. pNatureFrame->SetIcon(IDI_ICON_DUILIB);
  1603. pNatureFrame->CenterWindow();
  1604. UINT ret = pNatureFrame->ShowModal();
  1605. if (ret == IDOK)
  1606. {
  1607. //保存选择的属性
  1608. std::vector<FoodNatureSelectValue> natureSelectedArray = pNatureFrame->GetNatureSelectedArray();
  1609. clickItem.natureSelectedArray = natureSelectedArray;
  1610. m_is_show_modal_wnd = false;
  1611. delete pNatureFrame;
  1612. }
  1613. else
  1614. {
  1615. m_is_show_modal_wnd = false;
  1616. delete pNatureFrame;
  1617. return;
  1618. }
  1619. }
  1620. //商品没有商品属性
  1621. bool is_add_new = false;
  1622. int index = m_cur_diandan_order.AddItem(clickItem, is_add_new);
  1623. this->UpdateShopcartShow();
  1624. }
  1625. else
  1626. {
  1627. //点击普通商品之后的处理逻辑
  1628. CFood foodinfo = m_cur_click_food_item->GetFoodInfo();
  1629. if (foodinfo.stockvalid == "1" && atof(foodinfo.stock.c_str()) < 0.001)
  1630. {
  1631. //库存为0了,不做任何处理
  1632. m_pMainWnd->ShowToast(L"该商品已售完");
  1633. return;
  1634. }
  1635. CZhengcanOrderItem clickItem;
  1636. clickItem.food_id = foodinfo.id;
  1637. clickItem.food_name = foodinfo.name;
  1638. clickItem.type_id = foodinfo.type_id;
  1639. clickItem.price = foodinfo.price;
  1640. clickItem.is_dabao = false;
  1641. clickItem.dabao_money = foodinfo.dabao_money;
  1642. clickItem.num = "1";
  1643. if (foodinfo.member_price_used == "1")
  1644. {
  1645. clickItem.is_member_price_used = true;
  1646. }
  1647. else
  1648. {
  1649. clickItem.is_member_price_used = false;
  1650. }
  1651. //处理会员价的json
  1652. std::string member_price_json = foodinfo.member_price_json;
  1653. rapidjson::Document document;
  1654. document.Parse(member_price_json.c_str());
  1655. rapidjson::Value& member_price = document;
  1656. for (rapidjson::SizeType i = 0; i < member_price.Size(); ++i)
  1657. {
  1658. rapidjson::Value& member_price_info = member_price[i];
  1659. MemberPrice newPirce;
  1660. newPirce.id = CLewaimaiJson::ToString(member_price_info["id"]);
  1661. newPirce.level = CLewaimaiJson::ToString(member_price_info["level"]);
  1662. if (member_price_info["price"].IsString())
  1663. {
  1664. newPirce.price = member_price_info["price"].GetString();
  1665. }
  1666. else
  1667. {
  1668. newPirce.price = to_string(member_price_info["price"].GetDouble());
  1669. }
  1670. clickItem.m_member_price.push_back(newPirce);
  1671. }
  1672. //把当前点击商品的信息,保存到orderitem里面,方便后面修改规格的时候使用
  1673. clickItem.SetFoodInfo(m_cur_click_food_item->GetFoodInfo());
  1674. clickItem.SetIsTaocan(false);
  1675. if (foodinfo.is_weight == "1")
  1676. {
  1677. clickItem.is_weight = true;
  1678. if (m_is_show_modal_wnd == true)
  1679. {
  1680. return;
  1681. }
  1682. //这里要弹出称重框,不弹属性框
  1683. CChengzhongWnd* pChengzhongFrame = new CChengzhongWnd();
  1684. if (pChengzhongFrame != NULL)
  1685. {
  1686. m_is_show_modal_wnd = true;
  1687. m_curModalWnd = pChengzhongFrame;
  1688. pChengzhongFrame->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  1689. pChengzhongFrame->SetIcon(IDI_ICON_DUILIB);
  1690. pChengzhongFrame->CenterWindow();
  1691. pChengzhongFrame->SetTitle(CLewaimaiString::UTF8ToUnicode(foodinfo.name));
  1692. UINT ret = pChengzhongFrame->ShowModal();
  1693. if (ret == IDOK)
  1694. {
  1695. std::string weight = pChengzhongFrame->m_weight;
  1696. if (atof(weight.c_str()) < 0.001)
  1697. {
  1698. return;
  1699. }
  1700. clickItem.num = weight;
  1701. m_is_show_modal_wnd = false;
  1702. delete pChengzhongFrame;
  1703. }
  1704. else
  1705. {
  1706. m_is_show_modal_wnd = false;
  1707. delete pChengzhongFrame;
  1708. return;
  1709. }
  1710. }
  1711. }
  1712. else
  1713. {
  1714. clickItem.is_weight = false;
  1715. if (foodinfo.is_nature == "1")
  1716. {
  1717. //商品有商品属性
  1718. clickItem.is_nature = true;
  1719. if (m_is_show_modal_wnd == true)
  1720. {
  1721. return;
  1722. }
  1723. //先弹框进行选择属性
  1724. CDiandanNatureWnd* pNatureFrame = new CDiandanNatureWnd(1);
  1725. pNatureFrame->SetFoodItemUI(m_cur_click_food_item);
  1726. if (pNatureFrame != NULL)
  1727. {
  1728. m_is_show_modal_wnd = true;
  1729. m_curModalWnd = pNatureFrame;
  1730. pNatureFrame->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  1731. pNatureFrame->SetIcon(IDI_ICON_DUILIB);
  1732. pNatureFrame->CenterWindow();
  1733. UINT ret = pNatureFrame->ShowModal();
  1734. if (ret == IDOK)
  1735. {
  1736. //保存选择的属性
  1737. std::vector<FoodNatureSelectValue> natureSelectedArray = pNatureFrame->GetNatureSelectedArray();
  1738. clickItem.natureSelectedArray = natureSelectedArray;
  1739. m_is_show_modal_wnd = false;
  1740. delete pNatureFrame;
  1741. }
  1742. else
  1743. {
  1744. m_is_show_modal_wnd = false;
  1745. delete pNatureFrame;
  1746. return;
  1747. }
  1748. }
  1749. }
  1750. }
  1751. //商品没有商品属性
  1752. bool is_add_new = false;
  1753. int index = m_cur_diandan_order.AddItem(clickItem, is_add_new);
  1754. UpdateShopcartShow();
  1755. return;
  1756. }
  1757. }
  1758. void CZhengcanDiandanPageUI::ClickAdd()
  1759. {
  1760. CListUI* pList = static_cast<CListUI*>(this->FindSubControl(_T("list_diandan_cart")));
  1761. int nIndex = pList->GetCurSel();
  1762. if (nIndex == -1)
  1763. {
  1764. return;
  1765. }
  1766. if (nIndex > m_cur_diandan_order.getItemNum() - 1)
  1767. {
  1768. //说明点击的是历史订单的
  1769. return;
  1770. }
  1771. m_cur_diandan_order.AddNum(nIndex);
  1772. //没有新增,而是修改了一项
  1773. this->UpdateShopcartShow();
  1774. }
  1775. void CZhengcanDiandanPageUI::ClickDel()
  1776. {
  1777. CListUI* pList = static_cast<CListUI*>(this->FindSubControl(_T("list_diandan_cart")));
  1778. int nIndex = pList->GetCurSel();
  1779. if (nIndex == -1)
  1780. {
  1781. return;
  1782. }
  1783. if (nIndex > m_cur_diandan_order.getItemNum() - 1)
  1784. {
  1785. //说明点击的是历史订单的
  1786. return;
  1787. }
  1788. bool is_del = m_cur_diandan_order.DelNum(nIndex);
  1789. //如果是删掉了,那么就刷新显示
  1790. this->UpdateShopcartShow();
  1791. if (m_cur_diandan_order.getItemNum() == 0)
  1792. {
  1793. ShowXuangouPage();
  1794. }
  1795. }
  1796. void CZhengcanDiandanPageUI::ClickRemove()
  1797. {
  1798. CListUI* pList = static_cast<CListUI*>(this->FindSubControl(_T("list_diandan_cart")));
  1799. int nIndex = pList->GetCurSel();
  1800. if (nIndex == -1)
  1801. {
  1802. return;
  1803. }
  1804. if (nIndex > m_cur_diandan_order.getItemNum() - 1)
  1805. {
  1806. //说明点击的是历史订单的
  1807. return;
  1808. }
  1809. m_cur_diandan_order.Remove(nIndex);
  1810. this->UpdateShopcartShow();
  1811. if (m_cur_diandan_order.getItemNum() == 0)
  1812. {
  1813. ShowXuangouPage();
  1814. }
  1815. }
  1816. void CZhengcanDiandanPageUI::ClickGuige()
  1817. {
  1818. CListUI* pList = static_cast<CListUI*>(this->FindSubControl(_T("list_diandan_cart")));
  1819. int nIndex = pList->GetCurSel();
  1820. if (nIndex == -1)
  1821. {
  1822. return;
  1823. }
  1824. if (nIndex > m_cur_diandan_order.getItemNum() - 1)
  1825. {
  1826. //说明点击的是历史订单的
  1827. return;
  1828. }
  1829. bool is_taocan = m_cur_diandan_order.getDiandanOrderItem(nIndex).m_is_taocan;
  1830. if (is_taocan)
  1831. {
  1832. if (m_is_show_modal_wnd == true)
  1833. {
  1834. return;
  1835. }
  1836. //弹出属性框,开始重新选择属性
  1837. CDiandanNatureWnd* pNatureFrame = new CDiandanNatureWnd(2);
  1838. pNatureFrame->SetZhengcanOrderItem(m_cur_diandan_order.getDiandanOrderItem(nIndex));
  1839. if (pNatureFrame != NULL)
  1840. {
  1841. m_is_show_modal_wnd = true;
  1842. m_curModalWnd = pNatureFrame;
  1843. pNatureFrame->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  1844. pNatureFrame->SetIcon(IDI_ICON_DUILIB);
  1845. pNatureFrame->CenterWindow();
  1846. UINT ret = pNatureFrame->ShowModal();
  1847. if (ret == IDOK)
  1848. {
  1849. //保存选择的属性
  1850. std::vector<FoodNatureSelectValue> natureSelectedArray = pNatureFrame->GetNatureSelectedArray();
  1851. m_cur_diandan_order.UpdateItemGuige(nIndex, natureSelectedArray);
  1852. m_is_show_modal_wnd = false;
  1853. delete pNatureFrame;
  1854. //然后要刷新这个item的显示
  1855. this->UpdateShopcartShow();
  1856. }
  1857. else
  1858. {
  1859. m_is_show_modal_wnd = false;
  1860. delete pNatureFrame;
  1861. return;
  1862. }
  1863. }
  1864. }
  1865. else
  1866. {
  1867. bool is_nature = m_cur_diandan_order.getDiandanOrderItem(nIndex).is_nature;
  1868. if (!is_nature)
  1869. {
  1870. //当前商品没有商品属性
  1871. return;
  1872. }
  1873. //弹出属性框,开始重新选择属性
  1874. CDiandanNatureWnd* pNatureFrame = new CDiandanNatureWnd(2);
  1875. pNatureFrame->SetZhengcanOrderItem(m_cur_diandan_order.getDiandanOrderItem(nIndex));
  1876. if (pNatureFrame != NULL)
  1877. {
  1878. pNatureFrame->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  1879. pNatureFrame->SetIcon(IDI_ICON_DUILIB);
  1880. pNatureFrame->CenterWindow();
  1881. UINT ret = pNatureFrame->ShowModal();
  1882. if (ret == IDOK)
  1883. {
  1884. //保存选择的属性
  1885. std::vector<FoodNatureSelectValue> natureSelectedArray = pNatureFrame->GetNatureSelectedArray();
  1886. m_cur_diandan_order.UpdateItemGuige(nIndex, natureSelectedArray);
  1887. delete pNatureFrame;
  1888. //然后要刷新这个item的显示
  1889. this->UpdateShopcartShow();
  1890. }
  1891. else
  1892. {
  1893. return;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. void CZhengcanDiandanPageUI::ClickDabao()
  1899. {
  1900. CListUI* pList = static_cast<CListUI*>(this->FindSubControl(_T("list_diandan_cart")));
  1901. int nIndex = pList->GetCurSel();
  1902. if (nIndex == -1)
  1903. {
  1904. return;
  1905. }
  1906. if (nIndex > m_cur_diandan_order.getItemNum() - 1)
  1907. {
  1908. //说明点击的是历史订单的
  1909. return;
  1910. }
  1911. m_cur_diandan_order.SetDabao(nIndex);
  1912. //没有新增,而是修改了一项
  1913. this->UpdateShopcartShow();
  1914. }
  1915. void CZhengcanDiandanPageUI::ClickQingkong()
  1916. {
  1917. m_cur_diandan_order.Clear();
  1918. this->UpdateShopcartShow();
  1919. ShowXuangouPage();
  1920. }
  1921. void CZhengcanDiandanPageUI::ClickZhengdanMemo()
  1922. {
  1923. if (m_is_show_modal_wnd == true)
  1924. {
  1925. return;
  1926. }
  1927. CMemoWnd* pMemoDlg = new CMemoWnd();
  1928. if (pMemoDlg != NULL)
  1929. {
  1930. m_is_show_modal_wnd = true;
  1931. m_curModalWnd = pMemoDlg;
  1932. pMemoDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  1933. pMemoDlg->SetIcon(IDI_ICON_DUILIB);
  1934. pMemoDlg->CenterWindow();
  1935. pMemoDlg->SetTitle(L"整单备注");
  1936. UINT ret = pMemoDlg->ShowModal();
  1937. if (ret == IDOK)
  1938. {
  1939. //保存选择的属性
  1940. std::string sMemo = pMemoDlg->getContent();
  1941. //渲染整单备注的展示
  1942. CLabelUI* pLabel = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_page_label_zhengdanbeizhu")));
  1943. pLabel->SetText((L"整单备注:" + CLewaimaiString::UTF8ToUnicode(sMemo)).c_str());
  1944. //保存备注,提交订单的时候用
  1945. m_cur_diandan_order.SetMemo(sMemo);
  1946. m_is_show_modal_wnd = false;
  1947. delete pMemoDlg;
  1948. }
  1949. else
  1950. {
  1951. m_is_show_modal_wnd = false;
  1952. delete pMemoDlg;
  1953. return;
  1954. }
  1955. }
  1956. }
  1957. void CZhengcanDiandanPageUI::ClickChetai()
  1958. {
  1959. std::map<string, string> params;
  1960. params["table_id"] = m_table_id;
  1961. std::string response;
  1962. std::string url = "/dinnercash/chetai";
  1963. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
  1964. if (ret == false)
  1965. {
  1966. return;
  1967. }
  1968. rapidjson::Document document;
  1969. document.Parse(response.c_str());
  1970. if (document.HasParseError())
  1971. {
  1972. LOG_INFO("parse response error!");
  1973. return;
  1974. }
  1975. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  1976. {
  1977. LOG_INFO("json error!");
  1978. return;
  1979. }
  1980. rapidjson::Value& v_errcode = document["errcode"];
  1981. int errcode = v_errcode.GetInt();
  1982. if (errcode != 0)
  1983. {
  1984. return;
  1985. }
  1986. if (!document.HasMember("data"))
  1987. {
  1988. return;
  1989. }
  1990. rapidjson::Value& data = document["data"];
  1991. //如果走到这里说明撤台成功了
  1992. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  1993. }
  1994. void CZhengcanDiandanPageUI::ClickHuantai()
  1995. {
  1996. CZhengcanPageUI* zhengcanPage = static_cast<CZhengcanPageUI*>(m_pMainWnd->GetPage(CMainWnd::ZHENGCAN));
  1997. //先切换到换台模式
  1998. zhengcanPage->SetModel(2);
  1999. //设置转出的桌子ID
  2000. zhengcanPage->SetHuantaiTableId(m_table_id);
  2001. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  2002. }
  2003. /**
  2004. * 退菜功能,注意如果是套餐要把套餐本身的item的id和套餐商品记录的item的id一起传给服务器
  2005. */
  2006. void CZhengcanDiandanPageUI::ClickTuicai()
  2007. {
  2008. CListUI* pList = static_cast<CListUI*>(this->FindSubControl(_T("list_diandan_cart")));
  2009. int nIndex = pList->GetCurSel();
  2010. if (nIndex == -1)
  2011. {
  2012. return;
  2013. }
  2014. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(pList->GetItemAt(nIndex));
  2015. std::string item_id = CLewaimaiString::UnicodeToUTF8(pEle->GetCustomAttribute(L"item_id"));
  2016. std::string is_tuicai = CLewaimaiString::UnicodeToUTF8(pEle->GetCustomAttribute(L"is_tuicai"));
  2017. if (is_tuicai == "1")
  2018. {
  2019. //已经是退菜了
  2020. return;
  2021. }
  2022. std::map<string, string> params;
  2023. params["order_id"] = m_order_id;
  2024. std::vector<std::map<string, string>> paramArray;
  2025. //先添加当前item的退菜参数
  2026. std::map<string, string> map_tmp;
  2027. map_tmp["id"] = item_id;
  2028. map_tmp["quantity"] = "1";
  2029. paramArray.push_back(map_tmp);
  2030. //再看看是不是套餐,如果是套餐还要添加套餐的
  2031. CZhengcanOrderItem curItem;
  2032. bool res = m_cur_diandan_order.GetHistoryItemById(item_id, curItem);
  2033. if (res == false)
  2034. {
  2035. //这个是异常情况
  2036. LOG_INFO("异常情况,退菜的item_id不存在");
  2037. return;
  2038. }
  2039. if (curItem.m_is_taocan == true)
  2040. {
  2041. for (std::vector<CZhengcanOrderItem>::iterator it = curItem.m_taocan_items.begin(); it != curItem.m_taocan_items.end(); it++)
  2042. {
  2043. std::map<string, string> map_tmp;
  2044. map_tmp["id"] = it->item_id;
  2045. map_tmp["quantity"] = "1";
  2046. paramArray.push_back(map_tmp);
  2047. }
  2048. }
  2049. std::string item_json_string = CLewaimaiJson::ParamArrayToJsonstring(paramArray);
  2050. params["item"] = item_json_string;
  2051. std::string response;
  2052. std::string url = "/dinnercash/retreatfood";
  2053. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
  2054. if (ret == false)
  2055. {
  2056. return;
  2057. }
  2058. rapidjson::Document document;
  2059. document.Parse(response.c_str());
  2060. if (document.HasParseError())
  2061. {
  2062. LOG_INFO("parse response error!");
  2063. return;
  2064. }
  2065. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  2066. {
  2067. LOG_INFO("json error!");
  2068. return;
  2069. }
  2070. rapidjson::Value& v_errcode = document["errcode"];
  2071. int errcode = v_errcode.GetInt();
  2072. if (errcode != 0)
  2073. {
  2074. return;
  2075. }
  2076. if (!document.HasMember("data"))
  2077. {
  2078. return;
  2079. }
  2080. rapidjson::Value& data = document["data"];
  2081. Value& stock = data["stock"];
  2082. std::string kucun_string = CLewaimaiJson::JsonToString(stock);
  2083. this->StartWorkAfterTuicai(kucun_string, curItem, 1);
  2084. }
  2085. void CZhengcanDiandanPageUI::ClickXidanBtn()
  2086. {
  2087. if (m_cur_diandan_order.getItemNum() == 0)
  2088. {
  2089. m_pMainWnd->ShowToast(L"请先选择菜品再下单");
  2090. return;
  2091. }
  2092. //对各个CZhengcanOrderItem的is_jaicai进行处理
  2093. bool is_jiacai = false;
  2094. if (m_cur_diandan_order.m_order_history_array.size() > 0)
  2095. {
  2096. is_jiacai = true;
  2097. }
  2098. for (std::vector<CZhengcanOrderItem>::iterator it = m_cur_diandan_order.m_items.begin(); it != m_cur_diandan_order.m_items.end(); it++)
  2099. {
  2100. if (is_jiacai)
  2101. {
  2102. it->is_jiacai = "1";
  2103. }
  2104. else
  2105. {
  2106. it->is_jiacai = "0";
  2107. }
  2108. }
  2109. //处理下单加菜逻辑
  2110. std::map<string, string> params;
  2111. params["order_id"] = m_order_id;
  2112. params["order_no"] = CRandomHelper::GetRandString(20);
  2113. //构建food_list参数
  2114. params["food_list"] = m_cur_diandan_order.getDiandanFoodlistParam();
  2115. params["foodpackage_array"] = m_cur_diandan_order.getDiandanTaocanParam();
  2116. params["persion_num"] = "1";
  2117. params["note"] = m_cur_diandan_order.GetMemo();
  2118. params["table_id"] = m_table_id;
  2119. std::string response;
  2120. std::string url = "/dinnercash/sendorder";
  2121. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
  2122. if (ret == false)
  2123. {
  2124. return;
  2125. }
  2126. rapidjson::Document document;
  2127. document.Parse(response.c_str());
  2128. if (document.HasParseError())
  2129. {
  2130. LOG_INFO("parse response error!");
  2131. return;
  2132. }
  2133. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  2134. {
  2135. LOG_INFO("json error!");
  2136. return;
  2137. }
  2138. rapidjson::Value& v_errcode = document["errcode"];
  2139. int errcode = v_errcode.GetInt();
  2140. if (errcode != 0)
  2141. {
  2142. return;
  2143. }
  2144. if (!document.HasMember("data"))
  2145. {
  2146. return;
  2147. }
  2148. rapidjson::Value& data = document["data"];
  2149. std::string status = CLewaimaiJson::ToString(data["status"]);
  2150. if (status == "success")
  2151. {
  2152. std::string show_trade_no = CLewaimaiJson::ToString(data["show_trade_no"]);
  2153. std::string id = CLewaimaiJson::ToString(data["id"]);
  2154. Value& stock = data["stock"];
  2155. std::string kucun_string = CLewaimaiJson::JsonToString(stock);
  2156. this->StartWorkAfterXiadan(kucun_string, show_trade_no);
  2157. }
  2158. }
  2159. void CZhengcanDiandanPageUI::ClickPayBtn()
  2160. {
  2161. if (m_cur_diandan_order.getItemNum() > 0)
  2162. {
  2163. m_pMainWnd->ShowToast(L"您还有未下单的商品,请先下单再结账");
  2164. return;
  2165. }
  2166. if (m_cur_diandan_order.m_order_history_array.size() == 0)
  2167. {
  2168. m_pMainWnd->ShowToast(L"您还没有下单,请先下单再结账");
  2169. return;
  2170. }
  2171. ShowJiesuanPage();
  2172. }
  2173. void CZhengcanDiandanPageUI::ClickChakanYouhui()
  2174. {
  2175. if (m_is_show_modal_wnd == true)
  2176. {
  2177. return;
  2178. }
  2179. //弹框展示所有的优惠
  2180. CYouhuiShowWnd* pYouhuiDlg = new CYouhuiShowWnd();
  2181. if (pYouhuiDlg != NULL)
  2182. {
  2183. m_is_show_modal_wnd = true;
  2184. m_curModalWnd = pYouhuiDlg;
  2185. pYouhuiDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2186. pYouhuiDlg->SetIcon(IDI_ICON_DUILIB);
  2187. pYouhuiDlg->CenterWindow();
  2188. pYouhuiDlg->SetYouhuiValue(m_shangpinquan_youhui, m_cika_youhui, m_total_member_youhui, m_zhekou_youhui, m_member_zhekou_youhui, m_quanyika_youhui, m_manjian_youhui, m_youhuiquan_youhui, m_rengong_youhui, m_moling_youhui);
  2189. UINT ret = pYouhuiDlg->ShowModal();
  2190. if (ret == IDOK)
  2191. {
  2192. m_is_show_modal_wnd = false;
  2193. delete pYouhuiDlg;
  2194. }
  2195. else
  2196. {
  2197. m_is_show_modal_wnd = false;
  2198. delete pYouhuiDlg;
  2199. return;
  2200. }
  2201. }
  2202. }
  2203. void CZhengcanDiandanPageUI::ClickMemberLogin()
  2204. {
  2205. if (m_is_show_modal_wnd == true)
  2206. {
  2207. return;
  2208. }
  2209. CMemberLoginWnd* pMemberLoginDlg = new CMemberLoginWnd();
  2210. if (pMemberLoginDlg != NULL)
  2211. {
  2212. m_is_show_modal_wnd = true;
  2213. m_curModalWnd = pMemberLoginDlg;
  2214. pMemberLoginDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2215. pMemberLoginDlg->SetIcon(IDI_ICON_DUILIB);
  2216. pMemberLoginDlg->CenterWindow();
  2217. pMemberLoginDlg->SetTitle(L"会员登录");
  2218. UINT ret = pMemberLoginDlg->ShowModal();
  2219. if (ret == IDOK)
  2220. {
  2221. //这说明会员登录成功了
  2222. m_is_member = true;
  2223. m_member_name = pMemberLoginDlg->m_member_name;
  2224. m_member_level = pMemberLoginDlg->m_member_level;
  2225. m_member_level_name = pMemberLoginDlg->m_member_level_name;
  2226. CButtonUI* pMemberLoginBtn = static_cast<CButtonUI*>(this->FindSubControl(_T("btn_diandan_member_login")));
  2227. pMemberLoginBtn->SetVisible(false);
  2228. CLabelUI* pMemberInfo = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_page_member_info")));
  2229. std::wstring memberInfo = CLewaimaiString::UTF8ToUnicode(m_member_name) + L"【" + CLewaimaiString::UTF8ToUnicode(m_member_level_name) + L"】";
  2230. pMemberInfo->SetText(memberInfo.c_str());
  2231. pMemberInfo->SetVisible(true);
  2232. this->UpdateJiesuanInfo();
  2233. m_is_show_modal_wnd = false;
  2234. delete pMemberLoginDlg;
  2235. }
  2236. else
  2237. {
  2238. m_is_show_modal_wnd = false;
  2239. delete pMemberLoginDlg;
  2240. return;
  2241. }
  2242. }
  2243. }
  2244. void CZhengcanDiandanPageUI::ClickZhekou()
  2245. {
  2246. if (m_is_show_modal_wnd == true)
  2247. {
  2248. return;
  2249. }
  2250. CZhekouWnd* pZhekouDlg = new CZhekouWnd();
  2251. if (pZhekouDlg != NULL)
  2252. {
  2253. m_is_show_modal_wnd = true;
  2254. m_curModalWnd = pZhekouDlg;
  2255. pZhekouDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2256. pZhekouDlg->SetIcon(IDI_ICON_DUILIB);
  2257. pZhekouDlg->CenterWindow();
  2258. pZhekouDlg->SetTitle(L"输入折扣值");
  2259. UINT ret = pZhekouDlg->ShowModal();
  2260. if (ret == IDOK)
  2261. {
  2262. //这说明折扣输入了
  2263. std::string zhekou = pZhekouDlg->getContent();
  2264. CButtonUI* pZhekouEdit = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_zhekou_value")));
  2265. pZhekouEdit->SetText(CLewaimaiString::UTF8ToUnicode(zhekou).c_str());
  2266. this->UpdateJiesuanInfo();
  2267. m_is_show_modal_wnd = false;
  2268. delete pZhekouDlg;
  2269. }
  2270. else
  2271. {
  2272. m_is_show_modal_wnd = false;
  2273. delete pZhekouDlg;
  2274. return;
  2275. }
  2276. }
  2277. }
  2278. void CZhengcanDiandanPageUI::ClickJiajia()
  2279. {
  2280. if (m_is_show_modal_wnd == true)
  2281. {
  2282. return;
  2283. }
  2284. CjiajiaWnd* pJiajiaDlg = new CjiajiaWnd();
  2285. if (pJiajiaDlg != NULL)
  2286. {
  2287. m_is_show_modal_wnd = true;
  2288. m_curModalWnd = pJiajiaDlg;
  2289. pJiajiaDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2290. pJiajiaDlg->SetIcon(IDI_ICON_DUILIB);
  2291. pJiajiaDlg->CenterWindow();
  2292. pJiajiaDlg->SetTitle(L"输入加价金额");
  2293. UINT ret = pJiajiaDlg->ShowModal();
  2294. if (ret == IDOK)
  2295. {
  2296. //这说明折扣输入了
  2297. std::string jiajia = pJiajiaDlg->getContent();
  2298. CButtonUI* pJiajiaEdit = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_jiajia_value")));
  2299. pJiajiaEdit->SetText(CLewaimaiString::UTF8ToUnicode(jiajia).c_str());
  2300. this->UpdateJiesuanInfo();
  2301. m_is_show_modal_wnd = false;
  2302. delete pJiajiaDlg;
  2303. }
  2304. else
  2305. {
  2306. m_is_show_modal_wnd = false;
  2307. delete pJiajiaDlg;
  2308. return;
  2309. }
  2310. }
  2311. }
  2312. void CZhengcanDiandanPageUI::ClickRengongyouhui()
  2313. {
  2314. if (m_is_show_modal_wnd == true)
  2315. {
  2316. return;
  2317. }
  2318. CRengongYouhuiWnd* pYouhuiDlg = new CRengongYouhuiWnd();
  2319. if (pYouhuiDlg != NULL)
  2320. {
  2321. m_is_show_modal_wnd = true;
  2322. m_curModalWnd = pYouhuiDlg;
  2323. pYouhuiDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2324. pYouhuiDlg->SetIcon(IDI_ICON_DUILIB);
  2325. pYouhuiDlg->CenterWindow();
  2326. pYouhuiDlg->SetTitle(L"输入优惠金额");
  2327. UINT ret = pYouhuiDlg->ShowModal();
  2328. if (ret == IDOK)
  2329. {
  2330. //这说明折扣输入了
  2331. std::string youhui = pYouhuiDlg->getContent();
  2332. CButtonUI* pYouhuiEdit = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_youhui_value")));
  2333. pYouhuiEdit->SetText(CLewaimaiString::UTF8ToUnicode(youhui).c_str());
  2334. this->UpdateJiesuanInfo();
  2335. m_is_show_modal_wnd = false;
  2336. delete pYouhuiDlg;
  2337. }
  2338. else
  2339. {
  2340. m_is_show_modal_wnd = false;
  2341. delete pYouhuiDlg;
  2342. return;
  2343. }
  2344. }
  2345. }
  2346. void CZhengcanDiandanPageUI::ClickSaomaYouhuiquan()
  2347. {
  2348. if (m_is_show_modal_wnd == true)
  2349. {
  2350. return;
  2351. }
  2352. CSaomaYouhuiquanWnd* pSaomaYouhuiquanDlg = new CSaomaYouhuiquanWnd();
  2353. if (pSaomaYouhuiquanDlg != NULL)
  2354. {
  2355. m_is_show_modal_wnd = true;
  2356. m_curModalWnd = pSaomaYouhuiquanDlg;
  2357. pSaomaYouhuiquanDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2358. pSaomaYouhuiquanDlg->SetIcon(IDI_ICON_DUILIB);
  2359. pSaomaYouhuiquanDlg->CenterWindow();
  2360. pSaomaYouhuiquanDlg->SetTitle(L"扫码使用优惠券");
  2361. UINT ret = pSaomaYouhuiquanDlg->ShowModal();
  2362. if (ret == IDOK)
  2363. {
  2364. //这说明优惠券核销成功了
  2365. m_is_youhuiquan = true;
  2366. m_youhuiquan_id = pSaomaYouhuiquanDlg->m_coupon_id;
  2367. m_coupon_basic_price = pSaomaYouhuiquanDlg->m_coupon_basic_price;
  2368. m_coupon_deadline = pSaomaYouhuiquanDlg->m_coupon_deadline;
  2369. m_coupon_value = pSaomaYouhuiquanDlg->m_coupon_value;
  2370. CLabelUI* pYouhuiEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_youhuiquan_status")));
  2371. pYouhuiEdit->SetText(L"已使用");
  2372. CButtonUI* pYouhuiquanCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_youhuiquan_btn_cancel")));
  2373. pYouhuiquanCancel->SetVisible(true);
  2374. this->UpdateJiesuanInfo();
  2375. m_is_show_modal_wnd = false;
  2376. delete pSaomaYouhuiquanDlg;
  2377. }
  2378. else
  2379. {
  2380. m_is_show_modal_wnd = false;
  2381. delete pSaomaYouhuiquanDlg;
  2382. return;
  2383. }
  2384. }
  2385. }
  2386. //点击扫码商品券
  2387. void CZhengcanDiandanPageUI::ClickSaomaShangpinquan()
  2388. {
  2389. if (m_is_show_modal_wnd == true)
  2390. {
  2391. return;
  2392. }
  2393. CSaomaShangpinquanWnd* pSaomaShangpinquanDlg = new CSaomaShangpinquanWnd();
  2394. if (pSaomaShangpinquanDlg != NULL)
  2395. {
  2396. m_is_show_modal_wnd = true;
  2397. m_curModalWnd = pSaomaShangpinquanDlg;
  2398. pSaomaShangpinquanDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2399. pSaomaShangpinquanDlg->SetIcon(IDI_ICON_DUILIB);
  2400. pSaomaShangpinquanDlg->CenterWindow();
  2401. pSaomaShangpinquanDlg->SetTitle(L"扫码使用商品券");
  2402. UINT ret = pSaomaShangpinquanDlg->ShowModal();
  2403. if (ret == IDOK)
  2404. {
  2405. //这说明商品券核销成功了
  2406. m_is_shangpinquan = true;
  2407. m_shangpinquan_lewaimai_customer_id = pSaomaShangpinquanDlg->m_lewaimai_customer_id;
  2408. m_shangpinquan_id = pSaomaShangpinquanDlg->m_goodscoupon_id;
  2409. m_shangpinquan_name = pSaomaShangpinquanDlg->m_goods_coupon_name;
  2410. m_shangpinquan_foodid = pSaomaShangpinquanDlg->m_bind_foods_id;
  2411. CLabelUI* pYouhuiEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_shangpinquan_status")));
  2412. pYouhuiEdit->SetText(L"已使用");
  2413. CButtonUI* pShangpinquanCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_shangpinquan_btn_cancel")));
  2414. pShangpinquanCancel->SetVisible(true);
  2415. this->UpdateJiesuanInfo();
  2416. m_is_show_modal_wnd = false;
  2417. delete pSaomaShangpinquanDlg;
  2418. }
  2419. else
  2420. {
  2421. m_is_show_modal_wnd = false;
  2422. delete pSaomaShangpinquanDlg;
  2423. return;
  2424. }
  2425. }
  2426. }
  2427. //点击扫码权益卡
  2428. void CZhengcanDiandanPageUI::ClickSaomaQuanyika()
  2429. {
  2430. if (m_is_show_modal_wnd == true)
  2431. {
  2432. return;
  2433. }
  2434. CSaomaQuanyikaWnd* pSaomaQuanyikaDlg = new CSaomaQuanyikaWnd();
  2435. if (pSaomaQuanyikaDlg != NULL)
  2436. {
  2437. m_is_show_modal_wnd = true;
  2438. m_curModalWnd = pSaomaQuanyikaDlg;
  2439. pSaomaQuanyikaDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2440. pSaomaQuanyikaDlg->SetIcon(IDI_ICON_DUILIB);
  2441. pSaomaQuanyikaDlg->CenterWindow();
  2442. pSaomaQuanyikaDlg->SetTitle(L"扫码使用权益卡");
  2443. UINT ret = pSaomaQuanyikaDlg->ShowModal();
  2444. if (ret == IDOK)
  2445. {
  2446. //这说明权益卡核销成功了
  2447. m_is_quanyika = true;
  2448. m_quanyika_discount = pSaomaQuanyikaDlg->m_discount;
  2449. CLabelUI* pYouhuiEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_quanyika_status")));
  2450. pYouhuiEdit->SetText(L"已使用");
  2451. CButtonUI* pQuanyikaCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_quanyika_btn_cancel")));
  2452. pQuanyikaCancel->SetVisible(true);
  2453. this->UpdateJiesuanInfo();
  2454. m_is_show_modal_wnd = false;
  2455. delete pSaomaQuanyikaDlg;
  2456. }
  2457. else
  2458. {
  2459. m_is_show_modal_wnd = false;
  2460. delete pSaomaQuanyikaDlg;
  2461. return;
  2462. }
  2463. }
  2464. }
  2465. //点击取消使用优惠券
  2466. void CZhengcanDiandanPageUI::ClickQuxiaoYouhuiquan()
  2467. {
  2468. m_is_youhuiquan = false;
  2469. CLabelUI* pYouhuiEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_youhuiquan_status")));
  2470. pYouhuiEdit->SetText(L"未使用");
  2471. CButtonUI* pYouhuiquanCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_youhuiquan_btn_cancel")));
  2472. pYouhuiquanCancel->SetVisible(false);
  2473. }
  2474. //点击取消商品券
  2475. void CZhengcanDiandanPageUI::ClickQuxiaoShangpinquan()
  2476. {
  2477. m_is_shangpinquan = false;
  2478. CLabelUI* pYouhuiEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_shangpinquan_status")));
  2479. pYouhuiEdit->SetText(L"未使用");
  2480. CButtonUI* pShangpinquanCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_shangpinquan_btn_cancel")));
  2481. pShangpinquanCancel->SetVisible(false);
  2482. }
  2483. //点击取消权益卡
  2484. void CZhengcanDiandanPageUI::ClickQuxiaoQuanyika()
  2485. {
  2486. m_is_quanyika = false;
  2487. CLabelUI* pYouhuiEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_quanyika_status")));
  2488. pYouhuiEdit->SetText(L"未使用");
  2489. CButtonUI* pQuanyikaCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_quanyika_btn_cancel")));
  2490. pQuanyikaCancel->SetVisible(false);
  2491. }
  2492. //点击取消次卡
  2493. void CZhengcanDiandanPageUI::ClickQuxiaoCika()
  2494. {
  2495. m_is_cika = false;
  2496. CLabelUI* pYouhuiEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_cika_status")));
  2497. pYouhuiEdit->SetText(L"未使用");
  2498. CButtonUI* pCikaCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_cika_btn_cancel")));
  2499. pCikaCancel->SetVisible(false);
  2500. }
  2501. //点击扫码次卡
  2502. void CZhengcanDiandanPageUI::ClickSaomaCika()
  2503. {
  2504. if (m_is_show_modal_wnd == true)
  2505. {
  2506. return;
  2507. }
  2508. CSaomaCikaWnd* pSaomaCikaDlg = new CSaomaCikaWnd();
  2509. if (pSaomaCikaDlg != NULL)
  2510. {
  2511. m_is_show_modal_wnd = true;
  2512. m_curModalWnd = pSaomaCikaDlg;
  2513. pSaomaCikaDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2514. pSaomaCikaDlg->SetIcon(IDI_ICON_DUILIB);
  2515. pSaomaCikaDlg->CenterWindow();
  2516. pSaomaCikaDlg->SetTitle(L"扫码使用次卡");
  2517. UINT ret = pSaomaCikaDlg->ShowModal();
  2518. if (ret == IDOK)
  2519. {
  2520. //这说明商品券核销成功了
  2521. m_is_cika = true;
  2522. m_cika_lewaimai_customer_id = pSaomaCikaDlg->m_cika_lewaimai_customer_id;
  2523. m_cika_id = pSaomaCikaDlg->m_timescoupon_id;
  2524. m_cika_deduct_type = pSaomaCikaDlg->m_deduct_type;
  2525. m_cika_discount = pSaomaCikaDlg->m_discount;
  2526. m_cika_discount_value = pSaomaCikaDlg->m_discount_value;
  2527. m_cika_full_reduce = pSaomaCikaDlg->m_full_reduce;
  2528. m_cika_full_reduce_value = pSaomaCikaDlg->m_full_reduce_value;
  2529. m_cika_offer = pSaomaCikaDlg->m_offer;
  2530. m_cika_offer_value = pSaomaCikaDlg->m_offer_value;
  2531. m_cika_bind_foods_id = pSaomaCikaDlg->m_bind_foods_id;
  2532. CLabelUI* pYouhuiEdit = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_jiesuan_cika_status")));
  2533. pYouhuiEdit->SetText(L"已使用");
  2534. CButtonUI* pCikaCancel = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_jiesuan_cika_btn_cancel")));
  2535. pCikaCancel->SetVisible(true);
  2536. this->UpdateJiesuanInfo();
  2537. m_is_show_modal_wnd = false;
  2538. delete pSaomaCikaDlg;
  2539. }
  2540. else
  2541. {
  2542. m_is_show_modal_wnd = false;
  2543. delete pSaomaCikaDlg;
  2544. return;
  2545. }
  2546. }
  2547. }
  2548. void CZhengcanDiandanPageUI::ClickRenshu()
  2549. {
  2550. if (m_is_show_modal_wnd == true)
  2551. {
  2552. return;
  2553. }
  2554. CZhengcanRenshuWnd* pCanpaiDlg = new CZhengcanRenshuWnd();
  2555. if (pCanpaiDlg != NULL)
  2556. {
  2557. m_is_show_modal_wnd = true;
  2558. m_curModalWnd = pCanpaiDlg;
  2559. pCanpaiDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  2560. pCanpaiDlg->SetIcon(IDI_ICON_DUILIB);
  2561. pCanpaiDlg->CenterWindow();
  2562. pCanpaiDlg->SetTitle(L"请输入用餐人数");
  2563. pCanpaiDlg->SetTableId(m_table_id);
  2564. UINT ret = pCanpaiDlg->ShowModal();
  2565. if (ret == IDOK)
  2566. {
  2567. //这说明人数输入了
  2568. std::string canpai = pCanpaiDlg->getContent();
  2569. m_renshu = canpai;
  2570. CButtonUI* pCanpaiEdit = static_cast<CButtonUI*>(this->FindSubControl(_T("btn_diandan_canpaihao")));
  2571. pCanpaiEdit->SetText((L"人数 " + CLewaimaiString::UTF8ToUnicode(canpai)).c_str());
  2572. //人数变更之后,要重新修改价格信息
  2573. this->UpdateJiesuanInfo();
  2574. m_is_show_modal_wnd = false;
  2575. delete pCanpaiDlg;
  2576. }
  2577. else
  2578. {
  2579. m_is_show_modal_wnd = false;
  2580. delete pCanpaiDlg;
  2581. return;
  2582. }
  2583. }
  2584. }
  2585. //获取通用参数,任何支付方式都要用到的参数,个性化参数在弹框里面处理
  2586. //参考文档 http://apidoc.zhipuzi.com/index.php/home/item/show?item_id=4
  2587. std::map<string, string> CZhengcanDiandanPageUI::GetSendorderParams()
  2588. {
  2589. std::map<string, string> params;
  2590. params["order_no"] = CRandomHelper::GetRandString(20);
  2591. params["order_id"] = m_order_id;
  2592. params["table_id"] = m_table_id;
  2593. params["is_clear"] = "1";
  2594. //构建food_list参数
  2595. params["food_list"] = m_cur_diandan_order.getDiandanFoodlistParam();
  2596. params["foodpackage_array"] = m_cur_diandan_order.getDiandanTaocanParam();
  2597. params["person_num"] = m_renshu;
  2598. params["table_name"] = m_table_name;
  2599. params["note"] = m_cur_diandan_order.GetMemo();
  2600. params["cover_charge"] = CLewaimaiString::DoubleToString(m_chawei, 2); //茶位费
  2601. params["activation_fee"] = CLewaimaiString::DoubleToString(m_kaitai, 2); //开台费
  2602. params["dabao_price"] = CLewaimaiString::DoubleToString(m_dabao, 2);
  2603. params["food_price"] = CLewaimaiString::DoubleToString(m_cur_diandan_order.getTotalPrice(), 2);
  2604. params["total_price"] = CLewaimaiString::DoubleToString(m_cur_diandan_order.getTotalPrice() + m_dabao, 2);
  2605. CEditUI* pZhekouEdit = static_cast<CEditUI*>(this->FindSubControl(_T("diandan_jiesuan_zhekou_value")));
  2606. wstring ws_zhekou = pZhekouEdit->GetText();
  2607. params["discount"] = CLewaimaiString::UnicodeToUTF8(ws_zhekou);
  2608. params["coupon"] = CLewaimaiString::DoubleToString(m_rengong_youhui, 2);
  2609. params["price_plus"] = CLewaimaiString::DoubleToString(m_jiajia, 2);
  2610. params["price_moling"] = CLewaimaiString::DoubleToString(m_moling_youhui, 2);
  2611. params["yingshou_value"] = CLewaimaiString::DoubleToString(m_cur_total_price, 2);
  2612. params["shishou_value"] = CLewaimaiString::DoubleToString(m_cur_total_price, 2);
  2613. params["zhaoling_value"] = "0";
  2614. params["zhifu_type"] = "";
  2615. if (m_is_youhuiquan)
  2616. {
  2617. params["coupon_id"] = m_youhuiquan_id;
  2618. }
  2619. if (m_is_cika)
  2620. {
  2621. params["timescoupon_id"] = m_cika_id;
  2622. params["lewaimai_customer_id"] = m_cika_lewaimai_customer_id;
  2623. }
  2624. if (m_is_shangpinquan)
  2625. {
  2626. params["goodscoupon_id"] = m_shangpinquan_id;
  2627. }
  2628. if (m_is_quanyika)
  2629. {
  2630. params["is_eq_card_discount"] = "1";
  2631. params["eq_card_discount_value"] = m_quanyika_discount;
  2632. }
  2633. else
  2634. {
  2635. params["is_eq_card_discount"] = "0";
  2636. }
  2637. if (m_is_member)
  2638. {
  2639. params["member_level"] = m_member_level;
  2640. if (m_is_member_zhekou)
  2641. {
  2642. params["member_level_value"] = m_member_zhekou_value;
  2643. }
  2644. else
  2645. {
  2646. params["member_level_value"] = 10;
  2647. }
  2648. }
  2649. if (m_is_cika == true)
  2650. {
  2651. params["time_coupon_type"] = m_cika_deduct_type;
  2652. params["time_coupon_discount_value"] = m_cika_discount_value;
  2653. params["time_coupon_full_reduce_value"] = m_cika_full_reduce_value;
  2654. params["time_coupon_offer_value"] = m_cika_offer_value;
  2655. params["time_coupon_band_food_value"] = CLewaimaiString::DoubleToString(m_cika_youhui, 2);
  2656. }
  2657. if (m_is_shangpinquan)
  2658. {
  2659. params["goods_coupon_band_food_value"] = CLewaimaiString::DoubleToString(m_shangpinquan_youhui, 2);
  2660. }
  2661. if (m_manjian_youhui > 0)
  2662. {
  2663. params["promotion_value"] = CLewaimaiString::DoubleToString(m_manjian_youhui, 2);
  2664. }
  2665. if (m_youhuiquan_youhui > 0)
  2666. {
  2667. params["coupon_value"] = CLewaimaiString::DoubleToString(m_youhuiquan_youhui, 2);
  2668. }
  2669. if (m_total_member_youhui > 0)
  2670. {
  2671. params["member_delete"] = CLewaimaiString::DoubleToString(m_total_member_youhui, 2);
  2672. }
  2673. else
  2674. {
  2675. params["member_delete"] = "0";
  2676. }
  2677. if (m_member_zhekou_youhui > 0)
  2678. {
  2679. params["member_discount_money"] = CLewaimaiString::DoubleToString(m_member_zhekou_youhui, 2);
  2680. }
  2681. if (m_zhekou_youhui > 0)
  2682. {
  2683. params["shop_discount_money"] = CLewaimaiString::DoubleToString(m_zhekou_youhui, 2);
  2684. }
  2685. if (m_cika_youhui > 0)
  2686. {
  2687. params["timescoupon_discount_money"] = CLewaimaiString::DoubleToString(m_cika_youhui, 2);
  2688. }
  2689. if (m_quanyika_youhui > 0)
  2690. {
  2691. params["eq_card_discount_money"] = CLewaimaiString::DoubleToString(m_quanyika_youhui, 2);
  2692. }
  2693. params["total_delete_money"] = CLewaimaiString::DoubleToString(m_total_youhui, 2);
  2694. return params;
  2695. }
  2696. void CZhengcanDiandanPageUI::StartWeixinzhifuShoukuan(std::string fukuanma)
  2697. {
  2698. if (m_is_show_modal_wnd == true)
  2699. {
  2700. return;
  2701. }
  2702. if (m_cur_diandan_order.m_order_history_array.size() == 0)
  2703. {
  2704. m_pMainWnd->ShowToast(L"您还没有下单,请先下单再结账");
  2705. return;
  2706. }
  2707. CWeixinzhifuShoukuanWnd* pShoukuanWnd = new CWeixinzhifuShoukuanWnd;
  2708. if (pShoukuanWnd != NULL)
  2709. {
  2710. m_is_show_modal_wnd = true;
  2711. m_curModalWnd = pShoukuanWnd;
  2712. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  2713. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  2714. pShoukuanWnd->CenterWindow();
  2715. std::string format_string = CLewaimaiString::DoubleToString(m_cur_total_price, 2);
  2716. std::wstring watchValue = CLewaimaiString::UTF8ToUnicode(format_string);
  2717. pShoukuanWnd->InitMoney(watchValue);
  2718. //这里要对提交订单的参数进行组装,然后方便请求
  2719. pShoukuanWnd->SetCommonParams(GetSendorderParams());
  2720. pShoukuanWnd->SetType(2);
  2721. if (fukuanma != "")
  2722. {
  2723. pShoukuanWnd->InitFukuanma(fukuanma);
  2724. }
  2725. UINT ret = pShoukuanWnd->ShowModal();
  2726. if (ret == IDOK)
  2727. {
  2728. int fukuanma_type = pShoukuanWnd->m_fukuanma_type;
  2729. std::string zhifu_type;
  2730. if (fukuanma_type == 1)
  2731. {
  2732. zhifu_type = "weixinzhifu";
  2733. }
  2734. else if (fukuanma_type == 2)
  2735. {
  2736. zhifu_type = "zhifubao";
  2737. }
  2738. else if (fukuanma_type == 3)
  2739. {
  2740. zhifu_type = "yunshanfu";
  2741. }
  2742. //说明收款成功了,需要进行一些后续的处理
  2743. this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, pShoukuanWnd->m_take_food_code, pShoukuanWnd->m_show_trade_no, zhifu_type);
  2744. m_pMainWnd->ShowToast(L"收款成功!");
  2745. //收款成功后返回桌台
  2746. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  2747. }
  2748. m_is_show_modal_wnd = false;
  2749. delete pShoukuanWnd;
  2750. }
  2751. }
  2752. void CZhengcanDiandanPageUI::StartHuiyuanShoukuan()
  2753. {
  2754. if (m_is_show_modal_wnd == true)
  2755. {
  2756. return;
  2757. }
  2758. if (m_cur_diandan_order.m_order_history_array.size() == 0)
  2759. {
  2760. m_pMainWnd->ShowToast(L"您还没有下单,请先下单再结账");
  2761. return;
  2762. }
  2763. CHuiyuanShoukuanWnd* pShoukuanWnd = new CHuiyuanShoukuanWnd();
  2764. if (pShoukuanWnd != NULL)
  2765. {
  2766. m_is_show_modal_wnd = true;
  2767. m_curModalWnd = pShoukuanWnd;
  2768. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  2769. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  2770. pShoukuanWnd->CenterWindow();
  2771. std::string format_string = CLewaimaiString::DoubleToString(m_cur_total_price, 2);
  2772. std::wstring watchValue = CLewaimaiString::UTF8ToUnicode(format_string);
  2773. pShoukuanWnd->InitMoney(watchValue);
  2774. //这里要对提交订单的参数进行组装,然后方便请求
  2775. pShoukuanWnd->SetCommonParams(GetSendorderParams());
  2776. pShoukuanWnd->SetType(2);
  2777. /*
  2778. if (m_is_start_catch && m_catch_string.length() == 18)
  2779. {
  2780. pShoukuanWnd->InitFukuanma(m_catch_string);
  2781. }
  2782. }*/
  2783. UINT ret = pShoukuanWnd->ShowModal();
  2784. if (ret == IDOK)
  2785. {
  2786. std::string balance = pShoukuanWnd->m_balance;
  2787. std::string member_number = pShoukuanWnd->m_member_number;
  2788. //说明收款成功了,需要进行一些后续的处理
  2789. this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, pShoukuanWnd->m_take_food_code, pShoukuanWnd->m_show_trade_no, "huiyuanzhifu", balance, member_number);
  2790. m_pMainWnd->ShowToast(L"收款成功!");
  2791. //收款成功后返回桌台
  2792. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  2793. }
  2794. m_is_show_modal_wnd = false;
  2795. delete pShoukuanWnd;
  2796. }
  2797. }
  2798. //开始进行现金收款
  2799. void CZhengcanDiandanPageUI::StartXianjinShoukuan()
  2800. {
  2801. if (m_is_show_modal_wnd == true)
  2802. {
  2803. return;
  2804. }
  2805. if (m_cur_diandan_order.m_order_history_array.size() == 0)
  2806. {
  2807. m_pMainWnd->ShowToast(L"您还没有下单,请先下单再结账");
  2808. return;
  2809. }
  2810. CXianjinShoukuanWnd* pShoukuanWnd = new CXianjinShoukuanWnd();
  2811. if (pShoukuanWnd != NULL)
  2812. {
  2813. m_is_show_modal_wnd = true;
  2814. m_curModalWnd = pShoukuanWnd;
  2815. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  2816. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  2817. pShoukuanWnd->CenterWindow();
  2818. std::string format_string = CLewaimaiString::DoubleToString(m_cur_total_price, 2);
  2819. std::wstring watchValue = CLewaimaiString::UTF8ToUnicode(format_string);
  2820. pShoukuanWnd->InitMoney(watchValue);
  2821. //这里要对提交订单的参数进行组装,然后方便请求
  2822. pShoukuanWnd->SetCommonParams(GetSendorderParams());
  2823. pShoukuanWnd->SetType(2);
  2824. /*
  2825. if (m_is_start_catch && m_catch_string.length() == 18)
  2826. {
  2827. pShoukuanWnd->InitFukuanma(m_catch_string);
  2828. }
  2829. }*/
  2830. UINT ret = pShoukuanWnd->ShowModal();
  2831. if (ret == IDOK)
  2832. {
  2833. m_shishou_value = pShoukuanWnd->m_shishou;
  2834. m_zhaoling_value = pShoukuanWnd->m_zhaoling;
  2835. //说明收款成功了,需要进行一些后续的处理
  2836. this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, pShoukuanWnd->m_take_food_code, pShoukuanWnd->m_show_trade_no, "xianjinzhifu");
  2837. m_pMainWnd->ShowToast(L"收款成功!");
  2838. //收款成功后返回桌台
  2839. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  2840. }
  2841. m_is_show_modal_wnd = false;
  2842. delete pShoukuanWnd;
  2843. }
  2844. }
  2845. void CZhengcanDiandanPageUI::StartFulikaShoukuan()
  2846. {
  2847. if (m_is_show_modal_wnd == true)
  2848. {
  2849. return;
  2850. }
  2851. if (m_cur_diandan_order.m_order_history_array.size() == 0)
  2852. {
  2853. m_pMainWnd->ShowToast(L"您还没有下单,请先下单再结账");
  2854. return;
  2855. }
  2856. CFulikaShoukuanWnd* pShoukuanWnd = new CFulikaShoukuanWnd();
  2857. if (pShoukuanWnd != NULL)
  2858. {
  2859. m_is_show_modal_wnd = true;
  2860. m_curModalWnd = pShoukuanWnd;
  2861. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  2862. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  2863. pShoukuanWnd->CenterWindow();
  2864. std::string format_string = CLewaimaiString::DoubleToString(m_cur_total_price, 2);
  2865. std::wstring watchValue = CLewaimaiString::UTF8ToUnicode(format_string);
  2866. pShoukuanWnd->InitMoney(watchValue);
  2867. //这里要对提交订单的参数进行组装,然后方便请求
  2868. pShoukuanWnd->SetCommonParams(GetSendorderParams());
  2869. pShoukuanWnd->SetType(2);
  2870. /*
  2871. if (m_is_start_catch && m_catch_string.length() == 18)
  2872. {
  2873. pShoukuanWnd->InitFukuanma(m_catch_string);
  2874. }
  2875. }*/
  2876. UINT ret = pShoukuanWnd->ShowModal();
  2877. if (ret == IDOK)
  2878. {
  2879. //说明收款成功了,需要进行一些后续的处理
  2880. this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, pShoukuanWnd->m_take_food_code, pShoukuanWnd->m_show_trade_no, "fulikazhifu");
  2881. m_pMainWnd->ShowToast(L"收款成功!");
  2882. //收款成功后返回桌台
  2883. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  2884. }
  2885. m_is_show_modal_wnd = false;
  2886. delete pShoukuanWnd;
  2887. }
  2888. }
  2889. void CZhengcanDiandanPageUI::StartZidingyiShoukuan(std::wstring name, std::wstring selfpay_id)
  2890. {
  2891. if (m_is_show_modal_wnd == true)
  2892. {
  2893. return;
  2894. }
  2895. if (m_cur_diandan_order.m_order_history_array.size() == 0)
  2896. {
  2897. m_pMainWnd->ShowToast(L"您还没有下单,请先下单再结账");
  2898. return;
  2899. }
  2900. CZidingyiShoukuanWnd* pShoukuanWnd = new CZidingyiShoukuanWnd();
  2901. if (pShoukuanWnd != NULL)
  2902. {
  2903. m_is_show_modal_wnd = true;
  2904. m_curModalWnd = pShoukuanWnd;
  2905. pShoukuanWnd->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
  2906. pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
  2907. pShoukuanWnd->CenterWindow();
  2908. std::string format_string = CLewaimaiString::DoubleToString(m_cur_total_price, 2);
  2909. std::wstring watchValue = CLewaimaiString::UTF8ToUnicode(format_string);
  2910. pShoukuanWnd->InitMoney(watchValue);
  2911. //这里要对提交订单的参数进行组装,然后方便请求
  2912. pShoukuanWnd->SetCommonParams(GetSendorderParams());
  2913. pShoukuanWnd->SetType(2);
  2914. /*
  2915. if (m_is_start_catch && m_catch_string.length() == 18)
  2916. {
  2917. pShoukuanWnd->InitFukuanma(m_catch_string);
  2918. }
  2919. }*/
  2920. pShoukuanWnd->SetZidingyiName(name);
  2921. pShoukuanWnd->SetZidingyiId(selfpay_id);
  2922. UINT ret = pShoukuanWnd->ShowModal();
  2923. if (ret == IDOK)
  2924. {
  2925. //说明收款成功了,需要进行一些后续的处理
  2926. this->StartWorkAfterShoukuan(pShoukuanWnd->m_kucun_string, pShoukuanWnd->m_take_food_code, pShoukuanWnd->m_show_trade_no, "zidingyizhifu");
  2927. m_pMainWnd->ShowToast(L"收款成功!");
  2928. //收款成功后返回桌台
  2929. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  2930. }
  2931. m_is_show_modal_wnd = false;
  2932. delete pShoukuanWnd;
  2933. }
  2934. }
  2935. void CZhengcanDiandanPageUI::UpdateFoodStock(std::string food_stock)
  2936. {
  2937. rapidjson::Document doc;
  2938. rapidjson::Document::AllocatorType &allocator = doc.GetAllocator(); //获取分配器
  2939. Value& data = CLewaimaiJson::StringToJson(food_stock, allocator);
  2940. for (rapidjson::SizeType i = 0; i < data.Size(); ++i)
  2941. {
  2942. std::string food_id = CLewaimaiJson::ToString(data[i]["food_id"]);
  2943. std::string stock = CLewaimaiJson::ToString(data[i]["stock"]);
  2944. CSqlite3 sqlite;
  2945. sqlite.UpdateFoodStock(food_id, stock);
  2946. }
  2947. }
  2948. //扫描了商品条码的逻辑处理
  2949. bool CZhengcanDiandanPageUI::SaomiaoBarcode(std::string barcode)
  2950. {
  2951. CSqlite3 sqlite;
  2952. CFood foodinfo;
  2953. bool ret = sqlite.GetFoodByBarcode(barcode, foodinfo);
  2954. if (ret == false)
  2955. {
  2956. //说明没找到对应的商品条码
  2957. return false;
  2958. }
  2959. //这里说明找到了,那么处理添加购物车逻辑,扫码的情况下,这里不管有没有属性,都按没属性处理,不管有没有称重都按没称重处理(以后标签秤可能会修改)
  2960. if (foodinfo.stockvalid == "1" && atof(foodinfo.stock.c_str()) < 1)
  2961. {
  2962. //库存为0了,不做任何处理
  2963. m_pMainWnd->ShowToast(L"该商品已售完");
  2964. //只要找到了就返回true
  2965. return true;
  2966. }
  2967. CZhengcanOrderItem clickItem;
  2968. clickItem.food_id = foodinfo.id;
  2969. clickItem.food_name = foodinfo.name;
  2970. clickItem.type_id = foodinfo.type_id;
  2971. clickItem.price = foodinfo.price;
  2972. clickItem.is_dabao = false;
  2973. clickItem.dabao_money = foodinfo.dabao_money;
  2974. clickItem.num = "1";
  2975. if (foodinfo.member_price_used == "1")
  2976. {
  2977. clickItem.is_member_price_used = true;
  2978. }
  2979. else
  2980. {
  2981. clickItem.is_member_price_used = false;
  2982. }
  2983. //处理会员价的json
  2984. std::string member_price_json = foodinfo.member_price_json;
  2985. rapidjson::Document document;
  2986. document.Parse(member_price_json.c_str());
  2987. rapidjson::Value& member_price = document;
  2988. for (rapidjson::SizeType i = 0; i < member_price.Size(); ++i)
  2989. {
  2990. rapidjson::Value& member_price_info = member_price[i];
  2991. MemberPrice newPirce;
  2992. newPirce.id = CLewaimaiJson::ToString(member_price_info["id"]);
  2993. newPirce.level = CLewaimaiJson::ToString(member_price_info["level"]);
  2994. newPirce.price = CLewaimaiJson::ToString(member_price_info["price"]);
  2995. clickItem.m_member_price.push_back(newPirce);
  2996. }
  2997. //把当前点击商品的信息,保存到orderitem里面,方便后面修改规格的时候使用
  2998. clickItem.SetFoodInfo(foodinfo);
  2999. clickItem.SetIsTaocan(false);
  3000. clickItem.is_weight = false;
  3001. clickItem.is_nature = false;
  3002. //商品没有商品属性
  3003. bool is_add_new = false;
  3004. int index = m_cur_diandan_order.AddItem(clickItem, is_add_new);
  3005. this->UpdateShopcartShow();
  3006. return true;
  3007. }
  3008. bool CZhengcanDiandanPageUI::BiaoqianchengSaomaBarcode(std::string barcode)
  3009. {
  3010. //先根据设置,分辨条码格式
  3011. std::string bianma;
  3012. std::string money;
  3013. std::string weight;
  3014. std::string jiaoyan;
  3015. std::string setting_tiaomacheng_geshi = CSetting::GetInstance()->GetParam("setting_tiaomacheng_geshi");
  3016. if (setting_tiaomacheng_geshi == "1")
  3017. {
  3018. if (barcode.length() != 12 && barcode.length() != 13)
  3019. {
  3020. //与该模式长度不匹配
  3021. return false;
  3022. }
  3023. if (barcode.length() == 12)
  3024. {
  3025. barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
  3026. }
  3027. //13位【FWWWWWWEEEEEC】
  3028. bianma = barcode.substr(1, 6);
  3029. money = barcode.substr(7, 5);
  3030. jiaoyan = barcode.substr(12, 1);
  3031. }
  3032. else if (setting_tiaomacheng_geshi == "2")
  3033. {
  3034. if (barcode.length() != 12 && barcode.length() != 13)
  3035. {
  3036. //与该模式长度不匹配
  3037. return false;
  3038. }
  3039. if (barcode.length() == 12)
  3040. {
  3041. barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
  3042. }
  3043. //13位【FWWWWWWNNNNNC】
  3044. bianma = barcode.substr(1, 6);
  3045. weight = barcode.substr(7, 5);
  3046. jiaoyan = barcode.substr(12, 1);
  3047. }
  3048. else if (setting_tiaomacheng_geshi == "3")
  3049. {
  3050. if (barcode.length() != 12 && barcode.length() != 13)
  3051. {
  3052. //与该模式长度不匹配
  3053. return false;
  3054. }
  3055. if (barcode.length() == 12)
  3056. {
  3057. barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
  3058. }
  3059. //13位【FFWWWWWEEEEEC】
  3060. bianma = barcode.substr(2, 5);
  3061. money = barcode.substr(7, 5);
  3062. jiaoyan = barcode.substr(12, 1);
  3063. }
  3064. else if (setting_tiaomacheng_geshi == "4")
  3065. {
  3066. if (barcode.length() != 12 && barcode.length() != 13)
  3067. {
  3068. //与该模式长度不匹配
  3069. return false;
  3070. }
  3071. if (barcode.length() == 12)
  3072. {
  3073. barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
  3074. }
  3075. //13位【FFWWWWWNNNNNC】
  3076. bianma = barcode.substr(2, 5);
  3077. weight = barcode.substr(7, 5);
  3078. jiaoyan = barcode.substr(12, 1);
  3079. }
  3080. else if (setting_tiaomacheng_geshi == "5")
  3081. {
  3082. if (barcode.length() != 17 && barcode.length() != 18)
  3083. {
  3084. //与该模式长度不匹配
  3085. return false;
  3086. }
  3087. if (barcode.length() == 17)
  3088. {
  3089. barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
  3090. }
  3091. //18位【FWWWWWWEEEEENNNNNC】
  3092. bianma = barcode.substr(1, 6);
  3093. money = barcode.substr(7, 5);
  3094. weight = barcode.substr(12, 5);
  3095. jiaoyan = barcode.substr(17, 1);
  3096. }
  3097. else if (setting_tiaomacheng_geshi == "6")
  3098. {
  3099. if (barcode.length() != 17 && barcode.length() != 18)
  3100. {
  3101. //与该模式长度不匹配
  3102. return false;
  3103. }
  3104. if (barcode.length() == 17)
  3105. {
  3106. barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
  3107. }
  3108. //18位【FWWWWWWNNNNNEEEEEC】
  3109. bianma = barcode.substr(1, 6);
  3110. weight = barcode.substr(7, 5);
  3111. money = barcode.substr(12, 5);
  3112. jiaoyan = barcode.substr(17, 1);
  3113. }
  3114. else if (setting_tiaomacheng_geshi == "7")
  3115. {
  3116. if (barcode.length() != 17 && barcode.length() != 18)
  3117. {
  3118. //与该模式长度不匹配
  3119. return false;
  3120. }
  3121. if (barcode.length() == 17)
  3122. {
  3123. barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
  3124. }
  3125. //18位【FFWWWWWEEEEENNNNNC】
  3126. bianma = barcode.substr(2, 5);
  3127. money = barcode.substr(7, 5);
  3128. weight = barcode.substr(12, 5);
  3129. jiaoyan = barcode.substr(17, 1);
  3130. }
  3131. else if (setting_tiaomacheng_geshi == "8")
  3132. {
  3133. if (barcode.length() != 17 && barcode.length() != 18)
  3134. {
  3135. //与该模式长度不匹配
  3136. return false;
  3137. }
  3138. if (barcode.length() == 17)
  3139. {
  3140. barcode = CLewaimaiString::BuZifuLeft(barcode, 1, '0');
  3141. }
  3142. //18位【FFWWWWWNNNNNEEEEEC】
  3143. bianma = barcode.substr(2, 5);
  3144. weight = barcode.substr(7, 5);
  3145. money = barcode.substr(12, 5);
  3146. jiaoyan = barcode.substr(17, 1);
  3147. }
  3148. //先检查编码是否存在,如果编码不存在直接返回false
  3149. int i_bianma = atoi(bianma.c_str());
  3150. if (i_bianma < 1)
  3151. {
  3152. return false;
  3153. }
  3154. CFood foodinfo;
  3155. CSqlite3 sqlite;
  3156. bool ret = sqlite.GetFoodByPluBianma(to_string(i_bianma), foodinfo);
  3157. if (ret == false)
  3158. {
  3159. //没找到这个商品
  3160. return false;
  3161. }
  3162. //走到这里是找到商品了,那么就开始计算价格和重量
  3163. double d_money = 0;
  3164. double d_weight = 0;
  3165. //如果有价格,优先用价格
  3166. if (money.length() > 0)
  3167. {
  3168. //这个出来的单位是分,要把单位转成员
  3169. d_money = atof(money.c_str());
  3170. d_money = d_money / 100;
  3171. //根据价格计算重量
  3172. d_weight = d_money / atof(foodinfo.price.c_str());
  3173. }
  3174. else if (weight.length() > 0)
  3175. {
  3176. //这个单位是克,要转化成千克
  3177. d_weight = atof(weight.c_str());
  3178. d_weight = d_weight / 1000;
  3179. //有重量了,其实不需要计算价格,价格加到购物车的时候会自己计算
  3180. }
  3181. else
  3182. {
  3183. //价格和重量都没有,这是异常情况
  3184. return false;
  3185. }
  3186. if (foodinfo.stockvalid == "1" && atof(foodinfo.stock.c_str()) < d_weight)
  3187. {
  3188. //库存为0了,不做任何处理
  3189. m_pMainWnd->ShowToast(L"该商品已售完");
  3190. //只要找到了就返回true
  3191. return true;
  3192. }
  3193. CZhengcanOrderItem clickItem;
  3194. clickItem.food_id = foodinfo.id;
  3195. clickItem.food_name = foodinfo.name;
  3196. clickItem.type_id = foodinfo.type_id;
  3197. clickItem.price = foodinfo.price;
  3198. clickItem.is_dabao = false;
  3199. clickItem.dabao_money = foodinfo.dabao_money;
  3200. clickItem.num = CLewaimaiString::DoubleToString(d_weight, 3); //重量保留3位小数
  3201. if (foodinfo.member_price_used == "1")
  3202. {
  3203. clickItem.is_member_price_used = true;
  3204. }
  3205. else
  3206. {
  3207. clickItem.is_member_price_used = false;
  3208. }
  3209. //处理会员价的json
  3210. std::string member_price_json = foodinfo.member_price_json;
  3211. rapidjson::Document document;
  3212. document.Parse(member_price_json.c_str());
  3213. rapidjson::Value& member_price = document;
  3214. for (rapidjson::SizeType i = 0; i < member_price.Size(); ++i)
  3215. {
  3216. rapidjson::Value& member_price_info = member_price[i];
  3217. MemberPrice newPirce;
  3218. newPirce.id = member_price_info["id"].GetString();
  3219. newPirce.level = member_price_info["level"].GetString();
  3220. newPirce.price = member_price_info["price"].GetString();
  3221. clickItem.m_member_price.push_back(newPirce);
  3222. }
  3223. //把当前点击商品的信息,保存到orderitem里面,方便后面修改规格的时候使用
  3224. clickItem.SetFoodInfo(foodinfo);
  3225. clickItem.SetIsTaocan(false);
  3226. clickItem.is_weight = true;
  3227. clickItem.is_nature = false;
  3228. //商品没有商品属性
  3229. bool is_add_new = false;
  3230. int index = m_cur_diandan_order.AddItem(clickItem, is_add_new);
  3231. this->UpdateShopcartShow();
  3232. return true;
  3233. }
  3234. //开始搜索某个商品名字
  3235. void CZhengcanDiandanPageUI::StartSearchFood(std::string foodname)
  3236. {
  3237. //展示删除按钮
  3238. CButtonUI* pClear = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_food_search_clear")));
  3239. pClear->SetVisible(true);
  3240. //隐藏商品分类展示
  3241. CHorizontalLayoutUI* pFoodtype = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_fenlei_layout")));
  3242. pFoodtype->SetVisible(false);
  3243. if (m_cur_type_id != "sousuo")
  3244. {
  3245. m_type_id_before_sousuo = m_cur_type_id;
  3246. }
  3247. m_cur_type_id = "sousuo";
  3248. m_sousuo_foodname = foodname;
  3249. CLabelUI* pTishi = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_food_search_tishi")));
  3250. pTishi->SetVisible(false);
  3251. this->InitFoodShow();
  3252. }
  3253. //停止搜索商品
  3254. void CZhengcanDiandanPageUI::StopSerachFood()
  3255. {
  3256. //隐藏删除按钮
  3257. CButtonUI* pClear = static_cast<CButtonUI*>(this->FindSubControl(_T("diandan_food_search_clear")));
  3258. pClear->SetVisible(false);
  3259. //展示商品分类展示
  3260. CHorizontalLayoutUI* pFoodtype = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("diandan_fenlei_layout")));
  3261. pFoodtype->SetVisible(true);
  3262. m_cur_type_id = m_type_id_before_sousuo;
  3263. CLabelUI* pTishi = static_cast<CLabelUI*>(this->FindSubControl(_T("diandan_food_search_tishi")));
  3264. pTishi->SetVisible(true);
  3265. this->InitFoodShow();
  3266. }
  3267. void CZhengcanDiandanPageUI::StartWorkAfterTuicai(std::string kucunstring, CZhengcanOrderItem tuicaiItem, int tuicai_num)
  3268. {
  3269. //更新商品库存
  3270. this->UpdateFoodStock(kucunstring);
  3271. //处理打印
  3272. CZhengcanOrder order = this->GetPrintOrderinfoTuicai(tuicaiItem, tuicai_num);
  3273. CPosPrinter printer;
  3274. printer.PrintZhengcanOrderXiadan(order);
  3275. //如果走到这里说明退菜成功了,这个时候刷新显示
  3276. this->InitShow();
  3277. }
  3278. //执行下单成功后的所有操作逻辑
  3279. void CZhengcanDiandanPageUI::StartWorkAfterXiadan(std::string kucunstring, std::string show_trade_no)
  3280. {
  3281. //更新商品库存
  3282. this->UpdateFoodStock(kucunstring);
  3283. //处理打印
  3284. CZhengcanOrder order = this->GetPrintOrderinfoXiadan(show_trade_no);
  3285. CPosPrinter printer;
  3286. printer.PrintZhengcanOrderXiadan(order);
  3287. //下单成功了,返回到桌子列表
  3288. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  3289. }
  3290. void CZhengcanDiandanPageUI::StartWorkAfterShoukuan(std::string kucunstring, std::string take_food_code, std::string show_trade_no, std::string shoukuan_type, std::string balance, std::string member_number)
  3291. {
  3292. //针对现金收款成功,单独做一个打开钱箱的判断处理
  3293. if (shoukuan_type == "xianjinzhifu")
  3294. {
  3295. std::string setting_is_diannei_xianjin_qianxiang = CSetting::GetInstance()->GetParam("setting_is_diannei_xianjin_qianxiang");
  3296. if (setting_is_diannei_xianjin_qianxiang == "1")
  3297. {
  3298. //打开钱箱
  3299. CPosPrinter printer;
  3300. printer.OpenQianxiang();
  3301. }
  3302. }
  3303. //更新商品库存
  3304. this->UpdateFoodStock(kucunstring);
  3305. //处理打印
  3306. CZhengcanOrder order = this->GetPrintOrderinfo(take_food_code, show_trade_no, shoukuan_type, balance, member_number);
  3307. CPosPrinter printer;
  3308. printer.PrintZhengcanOrderXiadan(order);
  3309. //结账成功了,返回到桌子列表
  3310. m_pMainWnd->SwitchPage(CMainWnd::ZHENGCAN);
  3311. }
  3312. CZhengcanOrder CZhengcanDiandanPageUI::GetPrintOrderinfoXiadan(std::string show_trade_no)
  3313. {
  3314. m_cur_diandan_order.shopname = CShopinfo::GetInstance()->m_shop_name;
  3315. m_cur_diandan_order.show_trade_no = show_trade_no;
  3316. m_cur_diandan_order.table_name = m_table_name;
  3317. m_cur_diandan_order.order_from = 1;
  3318. m_cur_diandan_order.init_time = CLewaimaiTime::DatetimeToString(time(NULL));
  3319. //清空之前的打印记录
  3320. m_cur_diandan_order.m_items_print.clear();
  3321. for (std::vector<CZhengcanOrderItem>::iterator it = m_cur_diandan_order.m_items.begin(); it != m_cur_diandan_order.m_items.end(); it++)
  3322. {
  3323. CZhengcanOrderItemPrint itemPrint;
  3324. itemPrint.m_food_name = it->getNameWanzhengShow();
  3325. itemPrint.m_quantity = it->num;
  3326. itemPrint.m_item_price = it->getSinglePrice();
  3327. itemPrint.m_type_id = it->type_id;
  3328. if (it->m_is_taocan == true)
  3329. {
  3330. itemPrint.is_taocan = true;
  3331. }
  3332. m_cur_diandan_order.m_items_print.push_back(itemPrint);
  3333. if (it->m_is_taocan == true)
  3334. {
  3335. //开始保存套餐里面的商品详情,主要用于厨房打印
  3336. CFoodpackage foodpackageinfo;
  3337. foodpackageinfo = it->GetFoodpackageInfo();
  3338. std::string nature = foodpackageinfo.nature;
  3339. rapidjson::Document document;
  3340. document.Parse(nature.c_str());
  3341. if (document.HasParseError())
  3342. {
  3343. //属性json报错,直接不处理了
  3344. continue;
  3345. }
  3346. rapidjson::Value& data = document;
  3347. //接下来要把这个套餐的详情也保存下来
  3348. for (std::vector<FoodNatureSelectValue>::iterator it_2 = it->natureSelectedArray.begin(); it_2 != it->natureSelectedArray.end(); it_2++)
  3349. {
  3350. std::string food_id = data[it_2->nNameIndex]["value"][it_2->nature_select_index].GetString();
  3351. //要根据商品ID找出商品的名字
  3352. CFood foodinfo;
  3353. CSqlite3 sqlite;
  3354. bool is_found = sqlite.GetFoodById(food_id, foodinfo);
  3355. if (!is_found)
  3356. {
  3357. continue;
  3358. }
  3359. CZhengcanOrderItemPrint foodpackageitemPrint;
  3360. foodpackageitemPrint.m_food_name = foodinfo.name;
  3361. foodpackageitemPrint.m_quantity = it->num;
  3362. foodpackageitemPrint.m_item_price = foodinfo.price;
  3363. foodpackageitemPrint.m_type_id = foodinfo.type_id;
  3364. foodpackageitemPrint.is_taocan = false;
  3365. foodpackageitemPrint.is_taocan_item = true;
  3366. m_cur_diandan_order.m_items_print.push_back(foodpackageitemPrint);
  3367. }
  3368. }
  3369. }
  3370. return m_cur_diandan_order;
  3371. }
  3372. CZhengcanOrder CZhengcanDiandanPageUI::GetPrintOrderinfoTuicai(CZhengcanOrderItem tuicaiItem, int tuicai_num)
  3373. {
  3374. m_cur_diandan_order.shopname = CShopinfo::GetInstance()->m_shop_name;
  3375. m_cur_diandan_order.table_name = m_table_name;
  3376. m_cur_diandan_order.init_time = CLewaimaiTime::DatetimeToString(time(NULL));
  3377. //清空之前的打印记录
  3378. m_cur_diandan_order.m_items_print.clear();
  3379. CZhengcanOrderItemPrint itemPrint;
  3380. itemPrint.m_quantity = tuicai_num;
  3381. itemPrint.m_item_price = tuicaiItem.price;
  3382. itemPrint.m_type_id = tuicaiItem.type_id;
  3383. if (tuicaiItem.m_is_taocan == true)
  3384. {
  3385. itemPrint.is_taocan = true;
  3386. itemPrint.m_food_name = tuicaiItem.foodpackage_name; //不带属性商品
  3387. }
  3388. else
  3389. {
  3390. itemPrint.m_food_name = tuicaiItem.food_name; //带属性值
  3391. }
  3392. m_cur_diandan_order.m_items_print.push_back(itemPrint);
  3393. if (tuicaiItem.m_is_taocan == true)
  3394. {
  3395. //开始保存套餐里面的商品详情,主要用于厨房打印
  3396. //接下来要把这个套餐的详情也保存下来
  3397. for (std::vector<CZhengcanOrderItem>::iterator it = tuicaiItem.m_taocan_items.begin(); it != tuicaiItem.m_taocan_items.end(); it++)
  3398. {
  3399. std::string food_id = it->food_id;
  3400. //要根据商品ID找出商品的名字
  3401. CFood foodinfo;
  3402. CSqlite3 sqlite;
  3403. bool is_found = sqlite.GetFoodById(food_id, foodinfo);
  3404. if (!is_found)
  3405. {
  3406. continue;
  3407. }
  3408. CZhengcanOrderItemPrint foodpackageitemPrint;
  3409. foodpackageitemPrint.m_food_name = foodinfo.name;
  3410. foodpackageitemPrint.m_quantity = tuicai_num;
  3411. foodpackageitemPrint.m_item_price = foodinfo.price;
  3412. foodpackageitemPrint.m_type_id = foodinfo.type_id;
  3413. foodpackageitemPrint.is_taocan = false;
  3414. foodpackageitemPrint.is_taocan_item = true;
  3415. m_cur_diandan_order.m_items_print.push_back(foodpackageitemPrint);
  3416. }
  3417. }
  3418. return m_cur_diandan_order;
  3419. }
  3420. CZhengcanOrder CZhengcanDiandanPageUI::GetPrintOrderinfo(std::string take_food_code, std::string show_trade_no, std::string shoukuan_type, std::string balance, std::string member_number)
  3421. {
  3422. m_cur_diandan_order.shopname = CShopinfo::GetInstance()->m_shop_name;
  3423. m_cur_diandan_order.show_trade_no = show_trade_no;
  3424. m_cur_diandan_order.balance = balance;
  3425. m_cur_diandan_order.member_number = member_number;
  3426. if (shoukuan_type == "weixinzhifu")
  3427. {
  3428. m_cur_diandan_order.shoukuan_type = CLewaimaiString::UnicodeToUTF8(L"微信支付");
  3429. }
  3430. else if (shoukuan_type == "zhifubao")
  3431. {
  3432. m_cur_diandan_order.shoukuan_type = CLewaimaiString::UnicodeToUTF8(L"支付宝");
  3433. }
  3434. else if (shoukuan_type == "yunshanfu")
  3435. {
  3436. m_cur_diandan_order.shoukuan_type = CLewaimaiString::UnicodeToUTF8(L"云闪付");
  3437. }
  3438. else if (shoukuan_type == "huiyuanzhifu")
  3439. {
  3440. m_cur_diandan_order.shoukuan_type = CLewaimaiString::UnicodeToUTF8(L"会员支付");
  3441. }
  3442. else if (shoukuan_type == "xianjinzhifu")
  3443. {
  3444. m_cur_diandan_order.shoukuan_type = CLewaimaiString::UnicodeToUTF8(L"现金支付");
  3445. }
  3446. else if (shoukuan_type == "fulikazhifu")
  3447. {
  3448. m_cur_diandan_order.shoukuan_type = CLewaimaiString::UnicodeToUTF8(L"福利卡支付");
  3449. }
  3450. else if (shoukuan_type == "zidingyizhifu")
  3451. {
  3452. m_cur_diandan_order.shoukuan_type = CLewaimaiString::UnicodeToUTF8(L"自定义支付");
  3453. }
  3454. m_cur_diandan_order.order_from = 1;
  3455. m_cur_diandan_order.init_time = CLewaimaiTime::DatetimeToString(time(NULL));
  3456. m_cur_diandan_order.m_shangpinquan_youhui = CLewaimaiString::DoubleToString(m_shangpinquan_youhui, 2);
  3457. m_cur_diandan_order.m_cika_youhui = CLewaimaiString::DoubleToString(m_cika_youhui, 2);
  3458. m_cur_diandan_order.m_total_member_youhui = CLewaimaiString::DoubleToString(m_total_member_youhui, 2);
  3459. m_cur_diandan_order.m_zhekou_youhui = CLewaimaiString::DoubleToString(m_zhekou_youhui, 2);
  3460. m_cur_diandan_order.m_member_zhekou_youhui = CLewaimaiString::DoubleToString(m_member_zhekou_youhui, 2);
  3461. m_cur_diandan_order.m_quanyika_youhui = CLewaimaiString::DoubleToString(m_quanyika_youhui, 2);
  3462. m_cur_diandan_order.m_manjian_youhui = CLewaimaiString::DoubleToString(m_manjian_youhui, 2);
  3463. m_cur_diandan_order.m_youhuiquan_youhui = CLewaimaiString::DoubleToString(m_youhuiquan_youhui, 2);
  3464. m_cur_diandan_order.m_rengong_youhui = CLewaimaiString::DoubleToString(m_rengong_youhui, 2);
  3465. m_cur_diandan_order.m_moling_youhui = CLewaimaiString::DoubleToString(m_moling_youhui, 2);
  3466. m_cur_diandan_order.m_jiajia = CLewaimaiString::DoubleToString(m_jiajia, 2);
  3467. m_cur_diandan_order.m_shishou_value = m_shishou_value;
  3468. m_cur_diandan_order.m_zhaoling_value = m_zhaoling_value;
  3469. m_cur_diandan_order.m_zhekou_value = m_zhekou_value;
  3470. m_cur_diandan_order.m_dabao_money = CLewaimaiString::DoubleToString(m_cur_diandan_order.getDabaoMoney(), 2);
  3471. m_cur_diandan_order.m_total_price = CLewaimaiString::DoubleToString(m_cur_total_price, 2);
  3472. for (std::vector<CZhengcanOrderItem>::iterator it = m_cur_diandan_order.m_items.begin(); it != m_cur_diandan_order.m_items.end(); it++)
  3473. {
  3474. CZhengcanOrderItemPrint itemPrint;
  3475. itemPrint.m_food_name = it->getNameWanzhengShow();
  3476. itemPrint.m_quantity = it->num;
  3477. itemPrint.m_item_price = it->getSinglePrice();
  3478. itemPrint.m_type_id = it->type_id;
  3479. if (it->m_is_taocan == true)
  3480. {
  3481. itemPrint.is_taocan = true;
  3482. }
  3483. m_cur_diandan_order.m_items_print.push_back(itemPrint);
  3484. if (it->m_is_taocan == true)
  3485. {
  3486. //开始保存套餐里面的商品详情,主要用于厨房打印
  3487. CFoodpackage foodpackageinfo;
  3488. foodpackageinfo = it->GetFoodpackageInfo();
  3489. std::string nature = foodpackageinfo.nature;
  3490. rapidjson::Document document;
  3491. document.Parse(nature.c_str());
  3492. if (document.HasParseError())
  3493. {
  3494. //属性json报错,直接不处理了
  3495. continue;
  3496. }
  3497. rapidjson::Value& data = document;
  3498. //接下来要把这个套餐的详情也保存下来
  3499. for (std::vector<FoodNatureSelectValue>::iterator it_2 = it->natureSelectedArray.begin(); it_2 != it->natureSelectedArray.end(); it_2++)
  3500. {
  3501. std::string food_id = data[it_2->nNameIndex]["value"][it_2->nature_select_index].GetString();
  3502. //要根据商品ID找出商品的名字
  3503. CFood foodinfo;
  3504. CSqlite3 sqlite;
  3505. bool is_found = sqlite.GetFoodById(food_id, foodinfo);
  3506. if (!is_found)
  3507. {
  3508. continue;
  3509. }
  3510. CZhengcanOrderItemPrint foodpackageitemPrint;
  3511. foodpackageitemPrint.m_food_name = foodinfo.name;
  3512. foodpackageitemPrint.m_quantity = it->num;
  3513. foodpackageitemPrint.m_item_price = foodinfo.price;
  3514. foodpackageitemPrint.m_type_id = foodinfo.type_id;
  3515. foodpackageitemPrint.is_taocan = false;
  3516. foodpackageitemPrint.is_taocan_item = true;
  3517. m_cur_diandan_order.m_items_print.push_back(foodpackageitemPrint);
  3518. }
  3519. }
  3520. }
  3521. return m_cur_diandan_order;
  3522. }
  3523. void CZhengcanDiandanPageUI::SetPos(RECT rc, bool bNeedInvalidate)
  3524. {
  3525. m_nPageWidth = rc.right - rc.left;
  3526. //拖动窗口的时候,更新位置
  3527. UpdateJiesuanZhifuPos();
  3528. //更新分类位置
  3529. UpdateFoodtypePos();
  3530. CContainerUI::SetPos(rc, bNeedInvalidate);
  3531. }
  3532. void CZhengcanDiandanPageUI::SetTableId(std::string table_id)
  3533. {
  3534. m_table_id = table_id;
  3535. }