TOrderController.java 253 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409
  1. package com.szwl.controller;
  2. import cn.com.crbank.ommo.esUtil.BeanUtils;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import cn.hutool.core.util.RandomUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.alibaba.fastjson.JSON;
  7. import com.alibaba.fastjson.JSONArray;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  11. import com.google.zxing.BarcodeFormat;
  12. import com.google.zxing.EncodeHintType;
  13. import com.google.zxing.client.j2se.MatrixToImageWriter;
  14. import com.google.zxing.common.BitMatrix;
  15. import com.google.zxing.qrcode.QRCodeWriter;
  16. import com.szwl.constant.HuifuConstant;
  17. import com.szwl.constant.JoinpayConstant;
  18. import com.szwl.constant.ResponseCodesEnum;
  19. import com.szwl.exception.BizException;
  20. import com.szwl.feign.bean.OrderFeign;
  21. import com.szwl.feign.bean.SzwlFeign;
  22. import com.szwl.model.bo.JsonMessage;
  23. import com.szwl.model.bo.R;
  24. import com.szwl.model.bo.ResponseModel;
  25. import com.szwl.model.dto.OrderDetailsDTO;
  26. import com.szwl.model.entity.*;
  27. import com.szwl.model.utils.HttpClientSslUtils;
  28. import com.szwl.model.utils.HttpClientUtils;
  29. import com.szwl.model.utils.PushUtils;
  30. import com.szwl.model.utils.RSAUtil;
  31. import com.szwl.service.*;
  32. import com.szwl.service.es.EsTOrderService;
  33. import com.szwl.utils.HuifuUtils;
  34. import com.szwl.utils.IDGenerator;
  35. import io.swagger.annotations.ApiOperation;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.apache.commons.lang.StringUtils;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.web.bind.annotation.*;
  40. import org.springframework.web.servlet.view.RedirectView;
  41. import javax.servlet.http.HttpServletRequest;
  42. import javax.servlet.http.HttpServletResponse;
  43. import java.io.ByteArrayOutputStream;
  44. import java.io.IOException;
  45. import java.io.UnsupportedEncodingException;
  46. import java.math.BigDecimal;
  47. import java.math.RoundingMode;
  48. import java.net.URLDecoder;
  49. import java.net.URLEncoder;
  50. import java.text.ParseException;
  51. import java.text.SimpleDateFormat;
  52. import java.util.*;
  53. /**
  54. * <p>
  55. * 前端控制器
  56. * </p>
  57. *
  58. * @author wuhs
  59. * @since 2022-06-17
  60. */
  61. @Slf4j
  62. @RestController
  63. @RequestMapping("/tOrder")
  64. public class TOrderController {
  65. @Autowired
  66. SzwlFeign szwlFeign;
  67. @Autowired
  68. OrderFeign orderFeign;
  69. @Autowired
  70. TOrderService orderService;
  71. @Autowired
  72. TOrderTaskService orderTaskService;
  73. @Autowired
  74. TJoinpayMchService joinpayMchService;
  75. @Autowired
  76. TShandeMchService shandeMchService;
  77. @Autowired
  78. THuifuMchService huifuMchService;
  79. @Autowired
  80. TEquipmentService equipmentService;
  81. @Autowired
  82. EsTOrderService esTOrderService;
  83. @Autowired
  84. TSzsmWxService szsmWxService;
  85. @Autowired
  86. WechatPayInfoService wechatPayInfoService;
  87. @Autowired
  88. private THuifuTempOrderService huifuTempOrderService;
  89. @Autowired
  90. private TOrderDetailsService orderDetailsService;
  91. @ApiOperation(value = "测试feign")
  92. @GetMapping("/testFeign")
  93. public ResponseModel<?> testFeign(String id) {
  94. return szwlFeign.testGetAdmin(id);
  95. }
  96. /**
  97. * 合并付款接口,根据终端跳转微信或支付宝
  98. *
  99. * @param req
  100. * @param resp
  101. * @return
  102. * @throws Exception
  103. */
  104. @ApiOperation(value = "请求在线支付 主扫")
  105. @RequestMapping("/aliPay")
  106. public RedirectView alipayforward(String wx, String zfb, HttpServletRequest req, HttpServletResponse resp) throws Exception {
  107. String userAgent = req.getHeader("User-Agent");
  108. RedirectView redirectTarget = new RedirectView();
  109. redirectTarget.setContextRelative(true);
  110. if (userAgent.contains("MicroMessenger")) { // 微信
  111. redirectTarget.setUrl(wx);
  112. } else if (userAgent.contains("AlipayClient")) { // 支付宝
  113. redirectTarget.setUrl(zfb);
  114. } else {
  115. throw new BizException(ResponseCodesEnum.A0001, "请使用支付宝或微信扫码!");
  116. }
  117. return redirectTarget;
  118. }
  119. /**
  120. * 请求在线支付 主扫 优惠码 盲盒
  121. *
  122. * @param clientId 设备client id
  123. * @param productName 商品名称
  124. * @param frpCode 支付方式 支付宝:ALIPAY_NATIVE , 微信:WEIXIN_NATIVE
  125. * @param pri 有值代表是盲盒
  126. * @return
  127. */
  128. @ApiOperation(value = "请求在线支付 主扫")
  129. @GetMapping("/uniPay")
  130. public Object uniPay(String code, String clientId, String productName, String frpCode, String pri) {
  131. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  132. if (equipment == null || equipment.getId() == null) {
  133. return JsonMessage.error("找不到设备");
  134. }
  135. //验证优惠码 code=null 则不选用优惠码
  136. TPromoCode promoCode = new TPromoCode();
  137. if (StringUtils.isNotEmpty(code)) {
  138. //有优惠码,需要对优惠码进行验证
  139. ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
  140. TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
  141. promoCode = tPromoCode;
  142. if (tPromoCode == null || tPromoCode.getId() == null) {
  143. //不存在
  144. return JsonMessage.success("1");
  145. }
  146. if (promoCode.getId() == null) {
  147. //不存在
  148. return JsonMessage.success("1");
  149. }
  150. Date lastUseDate = null;
  151. if (promoCode != null && promoCode.getId() != null) {
  152. lastUseDate = promoCode.getLastUseDate();
  153. }
  154. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  155. promoCode.setIsUse("2");
  156. szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
  157. //过期
  158. return JsonMessage.success("4");
  159. }
  160. if (promoCode.getIsUse().equals("1")) {
  161. //被使用
  162. return JsonMessage.success("2");
  163. }
  164. if (!promoCode.getAdminId().equals("1")) {
  165. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  166. } else {
  167. //不是本机
  168. return JsonMessage.success("3");
  169. }
  170. }
  171. if (promoCode.getDiscount() == null) {
  172. //旧优惠码
  173. return JsonMessage.success("0");
  174. }
  175. if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  176. //0折
  177. return JsonMessage.success("0");
  178. }
  179. }
  180. // 支付方式
  181. if (!frpCode.equals("ALIPAY_NATIVE") && !frpCode.equals("WEIXIN_NATIVE")) {
  182. return JsonMessage.error("参数错误");
  183. }
  184. Long equipmentId = equipment.getId();
  185. // 查找商品
  186. ResponseModel<TProduct> product1 = szwlFeign.getProduct(String.valueOf(equipmentId), productName);
  187. TProduct product = product1.getData();
  188. if (product == null) {
  189. return JsonMessage.error("找不到商品");
  190. }
  191. BigDecimal price = product.getRmbPrice();
  192. if (StringUtils.isNotEmpty(pri)) {
  193. price = new BigDecimal(pri);
  194. }
  195. // 计算折扣后的价格
  196. if (StringUtils.isNotEmpty(code)) {
  197. BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
  198. if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
  199. if (price.compareTo(discount) > 0) {
  200. // 如果 price 大于 discount,从 price 中减去 discount
  201. price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
  202. } else {
  203. // 如果 price 小于等于 discount,将 price 设置为 0
  204. // price = BigDecimal.ZERO;
  205. return JsonMessage.success("0");
  206. }
  207. } else {
  208. price = product.getRmbPrice().multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  209. }
  210. }
  211. // 判断价格是否小于等于0
  212. if (BigDecimal.ZERO.compareTo(price) >= 0) {
  213. return JsonMessage.error("商品价格异常");
  214. }
  215. // 生成订单编号
  216. Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
  217. String sn = orderService.initSn(client6);
  218. // 获取关联设备的分销
  219. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  220. if (proportion == null || proportion.getId() == null) {
  221. return JsonMessage.error("设备商家未完成分销设置");
  222. }
  223. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  224. if (admin == null) {
  225. return JsonMessage.error("找不到设备商家");
  226. }
  227. // 支付方式:0或null为汇聚,1为汇付支付
  228. String payPlatform = admin.getPayPlatform();
  229. String companyType = admin.getCompanyType();
  230. // 汇聚分账参数
  231. JSONArray altInfo = new JSONArray();
  232. // 汇付分账明细参数
  233. JSONObject acctSplitBunch = new JSONObject();
  234. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  235. acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
  236. if (!(acctSplitBunch.size() > 0)) {
  237. return JsonMessage.error("设备商家未注册结算账号");
  238. }
  239. } else {
  240. altInfo = getAltInfo(proportion, price);
  241. if (!(altInfo.size() > 0)) {
  242. return JsonMessage.error("设备商家未注册结算账号");
  243. }
  244. }
  245. String orderNo = sn;
  246. BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
  247. String productDesc = "";
  248. String commonParameter = "";
  249. String returnUrl = null;
  250. String notifyUrl = JoinpayConstant.Notify_Url;
  251. String isShowPic = "1";
  252. String openId = null;
  253. String authCode = null;
  254. String appid = null;
  255. String transactionModel = null;
  256. String tradeMerchantNo = admin.getTradeMerchantNo();
  257. String buyerId = null;
  258. String isAlt = "1";
  259. String altType = "11";
  260. String altUrl = null;
  261. BigDecimal marketingAmount = null;
  262. if (StringUtils.isNotEmpty(pri)) {
  263. productName = "棉花糖";
  264. }
  265. Integer productNumber = 1;
  266. TOrder order = new TOrder();
  267. order.setId(IDGenerator.orderID());
  268. order.setCreateDate(new Date());
  269. order.setModifyDate(new Date());
  270. order.setAdminId(admin.getId());
  271. order.setSn(sn);
  272. order.setProductId(product.getId());
  273. order.setProductNo(product.getNo());
  274. order.setProductName(productName);
  275. order.setPrice(price);
  276. order.setClientId(equipment.getClientId());
  277. order.setEquipmentId(equipmentId);
  278. order.setFrpCode(frpCode);
  279. order.setAltInfo(altInfo.toString());
  280. order.setStatus(0);
  281. order.setType(admin.getType());
  282. order.setProductNumber(productNumber);
  283. order.setCompanyType(admin.getCompanyType());
  284. order.setMachineType(equipment.getMachineType());
  285. if (admin.getType() == 0) {
  286. order.setAdminProportion(proportion.getProportion());
  287. order.setAgencyProportion(proportion.getAgencyProportion());
  288. order.setAgencyId(proportion.getAgencyId());
  289. }
  290. if (admin.getType() == 1) {
  291. order.setAdminProportion(proportion.getProportion());
  292. order.setAgencyProportion(proportion.getAgencyProportion());
  293. order.setAgencyId(proportion.getAgencyId());
  294. order.setMerchantProportion(proportion.getMerchantProportion());
  295. order.setMerchantId(proportion.getMerchantId());
  296. }
  297. if (admin.getType() == 2) {
  298. order.setAdminProportion(proportion.getProportion());
  299. order.setAgencyProportion(proportion.getAgencyProportion());
  300. order.setAgencyId(proportion.getAgencyId());
  301. order.setMerchantProportion(proportion.getMerchantProportion());
  302. order.setMerchantId(proportion.getMerchantId());
  303. order.setPersonageProportion(proportion.getPersonageProportion());
  304. order.setPersonageId(proportion.getPersonageId());
  305. }
  306. order.setPayPlatform(payPlatform);
  307. // 订单明细表
  308. TOrderDetails orderDetails = new TOrderDetails();
  309. orderDetails.setId(HuifuUtils.initDetailsId());
  310. orderDetails.setAdminId(admin.getId());
  311. orderDetails.setEquipmentId(equipmentId);
  312. orderDetails.setCreateDate(new Date());
  313. orderDetails.setOrderSn(sn);
  314. orderDetails.setPrice(price);
  315. orderDetails.setProductName(productName);
  316. orderDetails.setProductNo(product.getNo());
  317. orderDetails.setProductNumber(productNumber);
  318. orderDetails.setAmount(price);
  319. orderDetails.setRefundStatus("0");
  320. orderDetails.setCompanyType(companyType);
  321. orderDetails.setMachineType(equipment.getMachineType());
  322. String productName1 = productName + "-" + equipment.getName() + "-" + client6;
  323. String result = null;
  324. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  325. // 汇付分账参数
  326. order.setAcctSplitBunch(acctSplitBunch.toString());
  327. if (frpCode.equals("WEIXIN_NATIVE")) {
  328. //添加到汇付临时表
  329. // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
  330. // String[] ignoreProperties = {"id"};
  331. // String id = HuifuUtils.inithuifuTempId();
  332. // tHuifuTempOrder.setId(id);
  333. // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
  334. // huifuTempOrderService.save(tHuifuTempOrder);
  335. // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  336. // result = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
  337. // } else {
  338. // result = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
  339. // }
  340. // log.info("返回链接:{}", result);
  341. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  342. result = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn;
  343. } else {
  344. result = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn;
  345. }
  346. String qrcode = toQrcode(result);
  347. JSONObject kindData = new JSONObject();
  348. kindData.put("sn", sn);
  349. kindData.put("rd_Pic", qrcode);
  350. orderService.save(order);
  351. orderDetailsService.save(orderDetails);
  352. return JsonMessage.success(kindData.toString());
  353. }
  354. // 汇付支付
  355. try {
  356. result = huifuMchService.uniPay(
  357. orderNo, amount, productName1, productDesc,
  358. notifyUrl, frpCode, openId, appid, acctSplitBunch, companyType
  359. );
  360. } catch (Exception e) {
  361. e.printStackTrace();
  362. return JsonMessage.error("申请支付失败");
  363. }
  364. if (StrUtil.isEmpty(result)) {
  365. return JsonMessage.error("找不到支付图片");
  366. }
  367. String qrcode = toQrcode(result);
  368. JSONObject kindData = new JSONObject();
  369. kindData.put("sn", sn);
  370. kindData.put("rd_Pic", qrcode);
  371. orderService.save(order);
  372. orderDetailsService.save(orderDetails);
  373. return JsonMessage.success(kindData.toString());
  374. } else {
  375. try {
  376. result = joinpayMchService.uniPay(
  377. orderNo, amount, productName1, productDesc,
  378. commonParameter, returnUrl, notifyUrl, frpCode,
  379. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  380. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  381. );
  382. } catch (UnsupportedEncodingException e) {
  383. e.printStackTrace();
  384. return JsonMessage.error("申请支付失败");
  385. }
  386. JSONObject resultJson = JSONObject.parseObject(result);
  387. // 汇聚支付支付申请返回支付二维码图片
  388. String rd_Pic = resultJson.getString("rd_Pic");
  389. if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
  390. return JsonMessage.error("找不到支付图片");
  391. }
  392. JSONObject kindData = new JSONObject();
  393. kindData.put("sn", sn);
  394. kindData.put("rd_Pic", rd_Pic);
  395. orderService.save(order);
  396. orderDetailsService.save(orderDetails);
  397. return JsonMessage.success(kindData.toString());
  398. }
  399. }
  400. /**
  401. * 被扫支付 + 优惠码 盲盒
  402. *
  403. * @param code 优惠码
  404. * @param clientId 设备client id
  405. * @param productName 商品名称
  406. * @param frpCode 支付方式 支付宝:ALIPAY_CARD , 微信:WEIXIN_CARD
  407. * @return
  408. */
  409. @ApiOperation(value = "请求在线支付 被扫支付")
  410. @GetMapping("/CardPay")
  411. public Object CardPay(String code, String clientId, String productName, String frpCode, String authCode, String pri) {
  412. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  413. if (equipment == null || equipment.getId() == null) {
  414. return JsonMessage.error("找不到设备");
  415. }
  416. //验证优惠码 code=null 则不选用优惠码
  417. TPromoCode promoCode = new TPromoCode();
  418. if (StringUtils.isEmpty(code)) {
  419. //没有优惠码
  420. } else {
  421. //有优惠码,需要对优惠码进行验证
  422. ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
  423. TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
  424. promoCode = tPromoCode;
  425. if (tPromoCode == null || tPromoCode.getId() == null) {
  426. //不存在
  427. return JsonMessage.success("1");
  428. }
  429. if (promoCode.getId() == null) {
  430. //不存在
  431. return JsonMessage.success("1");
  432. }
  433. Date lastUseDate = null;
  434. if (promoCode != null && promoCode.getId() != null) {
  435. lastUseDate = promoCode.getLastUseDate();
  436. }
  437. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  438. promoCode.setIsUse("2");
  439. szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
  440. //过期
  441. return JsonMessage.success("4");
  442. }
  443. if (promoCode.getIsUse().equals("1")) {
  444. //被使用
  445. return JsonMessage.success("2");
  446. }
  447. if (!promoCode.getAdminId().equals("1")) {
  448. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  449. } else {
  450. //不是本机
  451. return JsonMessage.success("3");
  452. }
  453. }
  454. if (promoCode.getDiscount() == null) {
  455. //旧优惠码
  456. return JsonMessage.success("0");
  457. }
  458. if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  459. //0折
  460. return JsonMessage.success("0");
  461. }
  462. }
  463. if (!frpCode.equals("ALIPAY_CARD") && !frpCode.equals("WEIXIN_CARD")) {
  464. return JsonMessage.error("参数错误");
  465. }
  466. if (equipment == null) {
  467. return JsonMessage.error("找不到设备");
  468. }
  469. Long equipmentId = equipment.getId();
  470. //查找商品
  471. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
  472. if (product == null) {
  473. return JsonMessage.error("找不到商品");
  474. }
  475. BigDecimal price = product.getRmbPrice();
  476. if (StringUtils.isNotEmpty(pri)) {
  477. price = new BigDecimal(pri);
  478. }
  479. if (StringUtils.isNotEmpty(code)) {
  480. BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
  481. if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
  482. if (price.compareTo(discount) > 0) {
  483. // 如果 price 大于 discount,从 price 中减去 discount
  484. price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
  485. } else {
  486. // 如果 price 小于等于 discount,将 price 设置为 0
  487. // price = BigDecimal.ZERO;
  488. return JsonMessage.success("0");
  489. }
  490. } else {
  491. price = product.getRmbPrice().multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  492. }
  493. }
  494. if (BigDecimal.ZERO.compareTo(price) >= 0) {
  495. return JsonMessage.error("商品价格异常");
  496. }
  497. Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
  498. String sn = orderService.initSn(client6);
  499. // 获取关联设备的分销
  500. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  501. if (proportion == null || proportion.getId() == null) {
  502. return JsonMessage.error("设备商家未完成分销设置");
  503. }
  504. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  505. if (admin == null) {
  506. return JsonMessage.error("找不到设备商家");
  507. }
  508. // 支付方式:0或null为汇聚,1为汇付支付
  509. String payPlatform = admin.getPayPlatform();
  510. String companyType = admin.getCompanyType();
  511. // 汇聚分账参数
  512. JSONArray altInfo = new JSONArray();
  513. // 汇付分账明细参数
  514. JSONObject acctSplitBunch = new JSONObject();
  515. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  516. acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
  517. if (!(acctSplitBunch.size() > 0)) {
  518. return JsonMessage.error("设备商家未注册结算账号");
  519. }
  520. } else {
  521. altInfo = getAltInfo(proportion, price);
  522. if (!(altInfo.size() > 0)) {
  523. return JsonMessage.error("设备商家未注册结算账号");
  524. }
  525. }
  526. String orderNo = sn;
  527. Integer productNumber = 1;
  528. BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
  529. String productDesc = "";
  530. String commonParameter = "";
  531. String returnUrl = null;
  532. String notifyUrl = JoinpayConstant.Notify_Url;
  533. String isShowPic = "1";
  534. String openId = null;
  535. String appid = null;
  536. String transactionModel = null;
  537. String tradeMerchantNo = admin.getTradeMerchantNo();
  538. String buyerId = null;
  539. String isAlt = "1";
  540. String altType = "11";
  541. String altUrl = null;
  542. if (StringUtils.isNotEmpty(pri)) {
  543. productName = "棉花糖";
  544. }
  545. BigDecimal marketingAmount = null;
  546. TOrder order = new TOrder();
  547. order.setId(IDGenerator.orderID());
  548. order.setCreateDate(new Date());
  549. order.setModifyDate(new Date());
  550. order.setAdminId(admin.getId());
  551. order.setSn(sn);
  552. order.setProductId(product.getId());
  553. order.setProductNo(product.getNo());
  554. order.setProductName(productName);
  555. order.setPrice(price);
  556. order.setClientId(equipment.getClientId());
  557. order.setEquipmentId(equipmentId);
  558. order.setFrpCode(frpCode);
  559. order.setAltInfo(altInfo.toString());
  560. order.setStatus(0);
  561. order.setType(admin.getType());
  562. order.setProductNumber(productNumber);
  563. order.setCompanyType(admin.getCompanyType());
  564. order.setMachineType(equipment.getMachineType());
  565. if (admin.getType() == 0) {
  566. order.setAdminProportion(proportion.getProportion());
  567. order.setAgencyProportion(proportion.getAgencyProportion());
  568. order.setAgencyId(proportion.getAgencyId());
  569. }
  570. if (admin.getType() == 1) {
  571. order.setAdminProportion(proportion.getProportion());
  572. order.setAgencyProportion(proportion.getAgencyProportion());
  573. order.setAgencyId(proportion.getAgencyId());
  574. order.setMerchantProportion(proportion.getMerchantProportion());
  575. order.setMerchantId(proportion.getMerchantId());
  576. }
  577. if (admin.getType() == 2) {
  578. order.setAdminProportion(proportion.getProportion());
  579. order.setAgencyProportion(proportion.getAgencyProportion());
  580. order.setAgencyId(proportion.getAgencyId());
  581. order.setMerchantProportion(proportion.getMerchantProportion());
  582. order.setMerchantId(proportion.getMerchantId());
  583. order.setPersonageProportion(proportion.getPersonageProportion());
  584. order.setPersonageId(proportion.getPersonageId());
  585. }
  586. order.setPayPlatform(payPlatform);
  587. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  588. order.setIsSettlement("0");
  589. }
  590. // 订单明细表
  591. TOrderDetails orderDetails = new TOrderDetails();
  592. orderDetails.setId(HuifuUtils.initDetailsId());
  593. orderDetails.setAdminId(admin.getId());
  594. orderDetails.setEquipmentId(equipmentId);
  595. orderDetails.setCreateDate(new Date());
  596. orderDetails.setOrderSn(sn);
  597. orderDetails.setPrice(price);
  598. orderDetails.setProductName(productName);
  599. orderDetails.setProductNo(product.getNo());
  600. orderDetails.setProductNumber(productNumber);
  601. orderDetails.setAmount(price);
  602. orderDetails.setRefundStatus("0");
  603. orderDetails.setCompanyType(companyType);
  604. orderDetails.setMachineType(equipment.getMachineType());
  605. // String client6 = clientId.substring(clientId.length() - 6);
  606. String productName1 = productName + "-" + equipment.getName() + "-" + client6;
  607. String result = null;
  608. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  609. order.setAcctSplitBunch(acctSplitBunch.toString());
  610. try {
  611. result = huifuMchService.cardPay(
  612. orderNo, amount, productName1, notifyUrl, authCode, acctSplitBunch, companyType
  613. );
  614. } catch (Exception e) {
  615. e.printStackTrace();
  616. return JsonMessage.error("申请支付失败");
  617. }
  618. if (result.equals(HuifuConstant.RESP_CODE_0)) {
  619. orderService.save(order);
  620. orderDetailsService.save(orderDetails);
  621. JSONObject kindData = new JSONObject();
  622. kindData.put("sn", sn);
  623. return JsonMessage.success(kindData.toString());
  624. } else {
  625. return JsonMessage.error("申请支付失败");
  626. }
  627. } else {
  628. try {
  629. result = joinpayMchService.uniPay(
  630. orderNo, amount, productName1, productDesc,
  631. commonParameter, returnUrl, notifyUrl, frpCode,
  632. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  633. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  634. );
  635. } catch (UnsupportedEncodingException e) {
  636. e.printStackTrace();
  637. return JsonMessage.error("申请支付失败");
  638. }
  639. JSONObject resultJson = JSONObject.parseObject(result);
  640. String raCode = resultJson.getString("ra_Code");
  641. if (raCode.equals("100") || raCode.equals("102")) {
  642. orderService.save(order);
  643. orderDetailsService.save(orderDetails);
  644. JSONObject kindData = new JSONObject();
  645. kindData.put("sn", sn);
  646. return JsonMessage.success(kindData.toString());
  647. } else {
  648. return JsonMessage.error("申请支付失败");
  649. }
  650. }
  651. }
  652. /**
  653. * 请求在线支付 主扫 优惠码 二码合一
  654. *
  655. * @param clientId 设备client id
  656. * @param productName 商品名称
  657. * @param pri DIY花型价格
  658. * @return
  659. */
  660. @ApiOperation(value = "请求在线支付 二码合一")
  661. @GetMapping("/twoPayCode")
  662. public Object twoPayCode(String code, String clientId, String productName, String pri) {
  663. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  664. if (equipment == null || equipment.getId() == null) {
  665. return JsonMessage.error("找不到设备");
  666. }
  667. //验证优惠码 code=null 则不选用优惠码
  668. TPromoCode promoCode = new TPromoCode();
  669. if (StringUtils.isEmpty(code)) {
  670. //没有优惠码
  671. } else {
  672. //有优惠码,需要对优惠码进行验证
  673. ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
  674. TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
  675. promoCode = tPromoCode;
  676. if (tPromoCode == null || tPromoCode.getId() == null) {
  677. //不存在
  678. return JsonMessage.success("1");
  679. }
  680. if (promoCode.getId() == null) {
  681. //不存在
  682. return JsonMessage.success("1");
  683. }
  684. Date lastUseDate = null;
  685. if (promoCode != null && promoCode.getId() != null) {
  686. lastUseDate = promoCode.getLastUseDate();
  687. }
  688. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  689. promoCode.setIsUse("2");
  690. szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
  691. //过期
  692. return JsonMessage.success("4");
  693. }
  694. if (promoCode.getIsUse().equals("1")) {
  695. //被使用
  696. return JsonMessage.success("2");
  697. }
  698. if (!promoCode.getAdminId().equals("1")) {
  699. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  700. } else {
  701. //不是本机
  702. return JsonMessage.success("3");
  703. }
  704. }
  705. if (promoCode.getDiscount() == null) {
  706. //旧优惠码
  707. return JsonMessage.success("0");
  708. }
  709. if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  710. //0折
  711. return JsonMessage.success("0");
  712. }
  713. }
  714. if (equipment == null) {
  715. return JsonMessage.error("找不到设备");
  716. }
  717. Long equipmentId = equipment.getId();
  718. //查找商品
  719. BigDecimal price;
  720. Long productId = null;
  721. // A99:DIY花型
  722. String productNo = "A99";
  723. if (StringUtils.isEmpty(pri)) {
  724. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
  725. if (product == null) {
  726. return JsonMessage.error("找不到商品");
  727. }
  728. price = product.getRmbPrice();
  729. productId = product.getId();
  730. productNo = product.getNo();
  731. } else {
  732. price = new BigDecimal(pri);
  733. }
  734. if (StringUtils.isNotEmpty(code)) {
  735. BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
  736. if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
  737. if (price.compareTo(discount) > 0) {
  738. // 如果 price 大于 discount,从 price 中减去 discount
  739. price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
  740. } else {
  741. // 如果 price 小于等于 discount,将 price 设置为 0
  742. // price = BigDecimal.ZERO;
  743. return JsonMessage.success("0");
  744. }
  745. } else {
  746. price = price.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  747. }
  748. }
  749. if (BigDecimal.ZERO.compareTo(price) >= 0) {
  750. return JsonMessage.error("商品价格异常");
  751. }
  752. Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
  753. String sn1 = orderService.initSn(client6);
  754. String sn2 = orderService.initSn(client6);
  755. // 获取关联设备的分销
  756. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  757. if (proportion == null || proportion.getId() == null) {
  758. return JsonMessage.error("设备商家未完成分销设置");
  759. }
  760. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  761. if (admin == null) {
  762. return JsonMessage.error("找不到设备商家");
  763. }
  764. // 支付方式:0或null为汇聚,1为汇付支付
  765. String payPlatform = admin.getPayPlatform();
  766. String companyType = admin.getCompanyType();
  767. // 汇聚分账参数
  768. JSONArray altInfo = new JSONArray();
  769. // 汇付分账明细参数
  770. JSONObject acctSplitBunch = new JSONObject();
  771. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  772. acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
  773. if (!(acctSplitBunch.size() > 0)) {
  774. return JsonMessage.error("设备商家未注册结算账号");
  775. }
  776. } else {
  777. altInfo = getAltInfo(proportion, price);
  778. if (!(altInfo.size() > 0)) {
  779. return JsonMessage.error("设备商家未注册结算账号");
  780. }
  781. }
  782. String orderNo1 = sn1;
  783. String orderNo2 = sn2;
  784. BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
  785. String productDesc = "";
  786. String commonParameter = "";
  787. String returnUrl = null;
  788. String notifyUrl = JoinpayConstant.Notify_Url;
  789. String isShowPic = "1";
  790. String openId = null;
  791. String authCode = null;
  792. String appid = null;
  793. String transactionModel = null;
  794. String tradeMerchantNo = admin.getTradeMerchantNo();
  795. String buyerId = null;
  796. String isAlt = "1";
  797. String altType = "11";
  798. String altUrl = null;
  799. BigDecimal marketingAmount = null;
  800. String frpCode1 = "WEIXIN_NATIVE";
  801. String frpCode2 = "ALIPAY_NATIVE";
  802. Integer productNumber = 1;
  803. TOrder order = new TOrder();
  804. order.setId(IDGenerator.orderID());
  805. order.setCreateDate(new Date());
  806. order.setModifyDate(new Date());
  807. order.setAdminId(admin.getId());
  808. order.setSn(sn1);
  809. order.setProductId(productId);
  810. order.setProductNo(productNo);
  811. order.setProductName(productName);
  812. order.setProductNumber(productNumber);
  813. order.setPrice(price);
  814. order.setClientId(equipment.getClientId());
  815. order.setEquipmentId(equipmentId);
  816. order.setFrpCode(frpCode1);
  817. order.setAltInfo(altInfo.toString());
  818. order.setStatus(0);
  819. order.setType(admin.getType());
  820. order.setCompanyType(companyType);
  821. order.setMachineType(equipment.getMachineType());
  822. if (admin.getType() == 0) {
  823. order.setAdminProportion(proportion.getProportion());
  824. order.setAgencyProportion(proportion.getAgencyProportion());
  825. order.setAgencyId(proportion.getAgencyId());
  826. }
  827. if (admin.getType() == 1) {
  828. order.setAdminProportion(proportion.getProportion());
  829. order.setAgencyProportion(proportion.getAgencyProportion());
  830. order.setAgencyId(proportion.getAgencyId());
  831. order.setMerchantProportion(proportion.getMerchantProportion());
  832. order.setMerchantId(proportion.getMerchantId());
  833. }
  834. if (admin.getType() == 2) {
  835. order.setAdminProportion(proportion.getProportion());
  836. order.setAgencyProportion(proportion.getAgencyProportion());
  837. order.setAgencyId(proportion.getAgencyId());
  838. order.setMerchantProportion(proportion.getMerchantProportion());
  839. order.setMerchantId(proportion.getMerchantId());
  840. order.setPersonageProportion(proportion.getPersonageProportion());
  841. order.setPersonageId(proportion.getPersonageId());
  842. }
  843. order.setPayPlatform(payPlatform);
  844. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  845. order.setIsSettlement("0");
  846. }
  847. TOrder order2 = new TOrder();
  848. order2.setId(IDGenerator.orderID());
  849. order2.setCreateDate(new Date());
  850. order2.setModifyDate(new Date());
  851. order2.setAdminId(admin.getId());
  852. order2.setSn(sn2);
  853. order2.setProductId(productId);
  854. order2.setProductNo(productNo);
  855. order2.setProductName(productName);
  856. order2.setProductNumber(productNumber);
  857. order2.setPrice(price);
  858. order2.setClientId(equipment.getClientId());
  859. order2.setEquipmentId(equipmentId);
  860. order2.setFrpCode(frpCode2);
  861. order2.setAltInfo(altInfo.toString());
  862. order2.setStatus(0);
  863. order2.setType(admin.getType());
  864. order2.setPayPlatform(payPlatform);
  865. order2.setCompanyType(companyType);
  866. order2.setMachineType(equipment.getMachineType());
  867. if (admin.getType() == 0) {
  868. order2.setAdminProportion(proportion.getProportion());
  869. order2.setAgencyProportion(proportion.getAgencyProportion());
  870. order2.setAgencyId(proportion.getAgencyId());
  871. }
  872. if (admin.getType() == 1) {
  873. order2.setAdminProportion(proportion.getProportion());
  874. order2.setAgencyProportion(proportion.getAgencyProportion());
  875. order2.setAgencyId(proportion.getAgencyId());
  876. order2.setMerchantProportion(proportion.getMerchantProportion());
  877. order2.setMerchantId(proportion.getMerchantId());
  878. }
  879. if (admin.getType() == 2) {
  880. order2.setAdminProportion(proportion.getProportion());
  881. order2.setAgencyProportion(proportion.getAgencyProportion());
  882. order2.setAgencyId(proportion.getAgencyId());
  883. order2.setMerchantProportion(proportion.getMerchantProportion());
  884. order2.setMerchantId(proportion.getMerchantId());
  885. order2.setPersonageProportion(proportion.getPersonageProportion());
  886. order2.setPersonageId(proportion.getPersonageId());
  887. }
  888. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  889. order2.setIsSettlement("0");
  890. }
  891. // 订单明细表
  892. TOrderDetails orderDetails = new TOrderDetails();
  893. orderDetails.setAdminId(admin.getId());
  894. orderDetails.setEquipmentId(equipmentId);
  895. orderDetails.setCreateDate(new Date());
  896. orderDetails.setPrice(price);
  897. orderDetails.setProductName(productName);
  898. orderDetails.setProductNo(productNo);
  899. orderDetails.setProductNumber(productNumber);
  900. orderDetails.setAmount(price);
  901. orderDetails.setCompanyType(companyType);
  902. orderDetails.setRefundStatus("0");
  903. orderDetails.setMachineType(equipment.getMachineType());
  904. // String client6 = clientId.substring(clientId.length() - 6);
  905. String productName1 = productName + "-" + equipment.getName() + "-" + client6;
  906. String result = null;
  907. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  908. // 汇付分账参数
  909. order.setAcctSplitBunch(acctSplitBunch.toString());
  910. order2.setAcctSplitBunch(acctSplitBunch.toString());
  911. //添加到汇付临时表,微信
  912. // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
  913. // String[] ignoreProperties = {"id"};
  914. // String id = HuifuUtils.inithuifuTempId();
  915. // tHuifuTempOrder.setId(id);
  916. // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
  917. // huifuTempOrderService.save(tHuifuTempOrder);
  918. // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  919. // result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
  920. // } else {
  921. // result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
  922. // }
  923. String result1 = "";
  924. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  925. result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  926. } else {
  927. result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  928. }
  929. // URL编码
  930. try {
  931. result1 = URLEncoder.encode(result1, "UTF-8");
  932. } catch (UnsupportedEncodingException e) {
  933. e.printStackTrace();
  934. }
  935. // 支付宝
  936. try {
  937. result = huifuMchService.uniPay(
  938. sn2, amount, productName1, productDesc,
  939. notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
  940. );
  941. } catch (Exception e) {
  942. e.printStackTrace();
  943. return JsonMessage.error("申请支付失败");
  944. }
  945. if (StrUtil.isEmpty(result)) {
  946. return JsonMessage.error("找不到支付图片");
  947. }
  948. // 汇聚支付支付申请返回支付二维码图片
  949. String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
  950. System.out.println(code1);
  951. String qrcode = toQrcode(code1);
  952. JSONObject kindData = new JSONObject();
  953. kindData.put("sn", sn1 + "-" + sn2);
  954. kindData.put("rd_Pic", qrcode);
  955. orderService.save(order);
  956. orderDetails.setOrderSn(sn1);
  957. orderDetails.setId(HuifuUtils.initDetailsId());
  958. orderDetailsService.save(orderDetails);
  959. orderDetails.setOrderSn(sn2);
  960. orderDetails.setId(HuifuUtils.initDetailsId());
  961. orderDetailsService.save(orderDetails);
  962. orderService.save(order2);
  963. return JsonMessage.success(kindData.toString());
  964. } else {
  965. try {
  966. result = joinpayMchService.uniPay(
  967. orderNo1, amount, productName1, productDesc,
  968. commonParameter, returnUrl, notifyUrl, frpCode1,
  969. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  970. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  971. );
  972. } catch (UnsupportedEncodingException e) {
  973. e.printStackTrace();
  974. return JsonMessage.error("申请支付失败");
  975. }
  976. JSONObject resultJson = JSONObject.parseObject(result);
  977. String rc_Result1 = resultJson.getString("rc_Result");
  978. String result1 = null;
  979. try {
  980. result1 = joinpayMchService.uniPay(
  981. orderNo2, amount, productName1, productDesc,
  982. commonParameter, returnUrl, notifyUrl, frpCode2,
  983. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  984. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  985. );
  986. } catch (UnsupportedEncodingException e) {
  987. e.printStackTrace();
  988. return JsonMessage.error("申请支付失败");
  989. }
  990. JSONObject resultJson1 = JSONObject.parseObject(result1);
  991. String rc_Result2 = resultJson1.getString("rc_Result");
  992. // 汇聚支付支付申请返回支付二维码图片
  993. String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/" + "aliPay?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
  994. String rd_Pic = toQrcode(code1);
  995. JSONObject kindData = new JSONObject();
  996. kindData.put("sn", sn1 + "-" + sn2);
  997. kindData.put("rd_Pic", rd_Pic);
  998. orderService.save(order);
  999. orderDetails.setOrderSn(sn1);
  1000. orderDetails.setId(HuifuUtils.initDetailsId());
  1001. orderDetailsService.save(orderDetails);
  1002. orderDetails.setOrderSn(sn2);
  1003. orderDetails.setId(HuifuUtils.initDetailsId());
  1004. orderDetailsService.save(orderDetails);
  1005. orderService.save(order2);
  1006. return JsonMessage.success(kindData.toString());
  1007. }
  1008. }
  1009. @ApiOperation(value = "购物车 请求在线支付 二码合一")
  1010. @PostMapping("/carsPay")
  1011. public Object carsPay(String clientId, @RequestBody Map<String, String> productNameMap) {
  1012. if (productNameMap == null) {
  1013. return JsonMessage.error("数据出错");
  1014. }
  1015. StringBuffer note = new StringBuffer();
  1016. StringBuffer productName = new StringBuffer();
  1017. String productNo = "";
  1018. Map<String, Integer> productMap = new HashMap<>();
  1019. Integer productNumber = 0;
  1020. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  1021. if (equipment == null || equipment.getId() == null) {
  1022. return JsonMessage.error("找不到设备");
  1023. }
  1024. BigDecimal price = new BigDecimal("0.00");
  1025. TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
  1026. if (equipmentDesc == null || equipmentDesc.getEquipmentId() == null || equipmentDesc.getPayType() == null || equipmentDesc.getPayType().equals("0")) {
  1027. // 1、type=0,原始设定,没有第二件半价
  1028. for (String key : productNameMap.keySet()) {
  1029. String entryValue = String.valueOf(productNameMap.get(key));
  1030. List<String> value = JSON.parseArray(entryValue, String.class);
  1031. boolean hasDuplicate = hasDuplicateValue(value);
  1032. if (hasDuplicate) {
  1033. return JsonMessage.error("优惠码输入重复,单个商品只能使用一个优惠码");
  1034. }
  1035. List<TPromoCode> promoCodeList = new ArrayList<>();
  1036. // 1、校验优惠码
  1037. if (value.size() > 0) {
  1038. for (String code : value) {
  1039. if (!code.equals("0")) {
  1040. TPromoCode promoCode;
  1041. ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
  1042. TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
  1043. promoCode = tPromoCode;
  1044. if (tPromoCode == null || tPromoCode.getId() == null) {
  1045. //不存在
  1046. return JsonMessage.success("1");
  1047. }
  1048. Date lastUseDate = null;
  1049. if (promoCode != null) {
  1050. lastUseDate = promoCode.getLastUseDate();
  1051. }
  1052. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  1053. promoCode.setIsUse("2");
  1054. szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
  1055. //过期
  1056. return JsonMessage.success("4");
  1057. }
  1058. if (promoCode.getId() == null) {
  1059. //不存在
  1060. return JsonMessage.success("1");
  1061. }
  1062. if (promoCode.getIsUse().equals("1")) {
  1063. //被使用
  1064. return JsonMessage.success("2");
  1065. }
  1066. if (!promoCode.getAdminId().equals("1")) {
  1067. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  1068. } else {
  1069. //不是本机
  1070. return JsonMessage.success("3");
  1071. }
  1072. }
  1073. if (promoCode.getDiscount() == null) {
  1074. //旧优惠码
  1075. return JsonMessage.success("0");
  1076. }
  1077. // if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  1078. // //0折
  1079. // return JsonMessage.success("0");
  1080. // }
  1081. promoCodeList.add(promoCode);
  1082. }
  1083. }
  1084. }
  1085. String[] productNum = key.split("-");
  1086. String productNamea = productNum[0];
  1087. String num = productNum[1];
  1088. productMap.put(productNamea, Integer.valueOf(num));
  1089. productNumber += Integer.valueOf(num);
  1090. productName.append(productNamea).append("x").append(num).append(",");
  1091. //确定价格,然后叠加
  1092. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
  1093. if (product == null) {
  1094. return JsonMessage.error("找不到商品");
  1095. }
  1096. // note.append(productNamea).append("-").append(product.getNo()).append(":");
  1097. BigDecimal productPrice = product.getRmbPrice();
  1098. productNo = product.getNo();
  1099. if (promoCodeList.size() > 0) {
  1100. //有优惠码
  1101. BigDecimal onePrice = new BigDecimal("0.00");
  1102. Map<BigDecimal, Integer> priceMap = new HashMap<>();
  1103. int i;
  1104. for (i = 0; i < promoCodeList.size(); i++) {
  1105. BigDecimal discount = BigDecimal.valueOf(promoCodeList.get(i).getDiscount()).setScale(2, RoundingMode.HALF_DOWN);
  1106. BigDecimal price1 = new BigDecimal(0.0);
  1107. TPromoCode tPromoCode = promoCodeList.get(i);
  1108. if (StringUtils.isNotEmpty(tPromoCode.getType()) && tPromoCode.getType().equals("1")) {
  1109. if (productPrice.compareTo(discount) > 0) {
  1110. // 如果 price 大于 discount,从 price 中减去 discount
  1111. price1 = productPrice.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
  1112. } else {
  1113. // 如果 price 小于等于 discount,将 price 设置为 0
  1114. price1 = BigDecimal.ZERO;
  1115. }
  1116. } else {
  1117. if (tPromoCode.getDiscount() == 0) {
  1118. price1 = BigDecimal.ZERO;
  1119. } else {
  1120. price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  1121. }
  1122. }
  1123. price = price.add(price1);
  1124. // onePrice = onePrice.add(price1);
  1125. if (priceMap.containsKey(price1)) {
  1126. priceMap.put(price1, priceMap.get(price1) + 1);
  1127. } else {
  1128. priceMap.put(price1, 1);
  1129. }
  1130. }
  1131. if (i < Integer.valueOf(num)) {
  1132. int a = Integer.valueOf(num) - i;
  1133. BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
  1134. price = price.add(price2);
  1135. // onePrice = onePrice.add(price2);
  1136. priceMap.put(price2, a);
  1137. }
  1138. for (BigDecimal priceKey : priceMap.keySet()) {
  1139. note.append(productNamea).append("-").append(product.getNo()).append("-").append(RandomUtil.randomNumbers(5)).append(":");
  1140. note.append(priceKey).append("-").append(priceMap.get(priceKey)).append(",");
  1141. }
  1142. } else {
  1143. //1,type=0,原始设定,没有第二件半价
  1144. int a = Integer.valueOf(num);
  1145. BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
  1146. price = price.add(price2);
  1147. note.append(productNamea).append("-").append(product.getNo()).append(":");
  1148. note.append(price2).append("-").append(num).append(",");
  1149. }
  1150. }
  1151. } else {
  1152. //2,type=1,第二件半价
  1153. //2.1 判定是否有第二件,有多少个第二件半价
  1154. for (String key : productNameMap.keySet()) {
  1155. String[] productNum = key.split("-");
  1156. String productNamea = productNum[0];
  1157. String num = productNum[1];
  1158. productMap.put(productNamea, Integer.valueOf(num));
  1159. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
  1160. productNo = product.getNo();
  1161. BigDecimal productPrice = product.getRmbPrice();
  1162. productName.append(productNamea).append("x").append(num).append(",");
  1163. note.append(productNamea).append("-").append(product.getNo()).append(":");
  1164. switch (num) {
  1165. case "1":
  1166. //1个 0个半价
  1167. price = price.add(productPrice);
  1168. note.append(price).append("-").append(num).append(",");
  1169. break;
  1170. case "2":
  1171. //2个 1个半价
  1172. price = price.add(productPrice);
  1173. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1174. note.append(price).append("-").append(num).append(",");
  1175. break;
  1176. case "3":
  1177. //3个 1个半价
  1178. price = price.add(productPrice);
  1179. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1180. price = price.add(productPrice);
  1181. note.append(price).append("-").append(num).append(",");
  1182. break;
  1183. case "4":
  1184. //4个 2个半价
  1185. price = price.add(productPrice);
  1186. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1187. price = price.add(productPrice);
  1188. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1189. note.append(price).append("-").append(num).append(",");
  1190. break;
  1191. case "5":
  1192. //5个 2个半价
  1193. price = price.add(productPrice);
  1194. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1195. price = price.add(productPrice);
  1196. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1197. price = price.add(productPrice);
  1198. note.append(price).append("-").append(num).append(",");
  1199. break;
  1200. }
  1201. }
  1202. }
  1203. if (equipment == null) {
  1204. return JsonMessage.error("找不到设备");
  1205. }
  1206. Long equipmentId = equipment.getId();
  1207. //查找商品
  1208. if (BigDecimal.ZERO.compareTo(price) == 0) {
  1209. return JsonMessage.success("0");
  1210. }
  1211. if (BigDecimal.ZERO.compareTo(price) > 0) {
  1212. return JsonMessage.error("商品价格异常");
  1213. }
  1214. Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
  1215. String sn1 = orderService.initSn(client6);
  1216. String sn2 = orderService.initSn(client6);
  1217. // 获取关联设备的分销
  1218. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  1219. if (proportion == null || proportion.getId() == null) {
  1220. return JsonMessage.error("设备商家未完成分销设置");
  1221. }
  1222. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  1223. if (admin == null) {
  1224. return JsonMessage.error("找不到设备商家");
  1225. }
  1226. // 支付方式:0或null为汇聚,1为汇付支付
  1227. String payPlatform = admin.getPayPlatform();
  1228. String companyType = admin.getCompanyType();
  1229. // 汇聚分账参数
  1230. JSONArray altInfo = new JSONArray();
  1231. // 汇付分账明细参数
  1232. JSONObject acctSplitBunch = new JSONObject();
  1233. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  1234. acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
  1235. if (!(acctSplitBunch.size() > 0)) {
  1236. return JsonMessage.error("设备商家未注册结算账号");
  1237. }
  1238. } else {
  1239. altInfo = getAltInfo(proportion, price);
  1240. if (!(altInfo.size() > 0)) {
  1241. return JsonMessage.error("设备商家未注册结算账号");
  1242. }
  1243. }
  1244. String orderNo1 = sn1;
  1245. String orderNo2 = sn2;
  1246. BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
  1247. String productDesc = "";
  1248. String commonParameter = "";
  1249. String returnUrl = null;
  1250. String notifyUrl = JoinpayConstant.Notify_Url;
  1251. String isShowPic = "1";
  1252. String openId = null;
  1253. String authCode = null;
  1254. String appid = null;
  1255. String transactionModel = null;
  1256. String tradeMerchantNo = admin.getTradeMerchantNo();
  1257. String buyerId = null;
  1258. String isAlt = "1";
  1259. String altType = "11";
  1260. String altUrl = null;
  1261. BigDecimal marketingAmount = null;
  1262. String frpCode1 = "WEIXIN_NATIVE";
  1263. String frpCode2 = "ALIPAY_NATIVE";
  1264. TOrder order = new TOrder();
  1265. order.setId(IDGenerator.orderID());
  1266. order.setCreateDate(new Date());
  1267. order.setModifyDate(new Date());
  1268. order.setAdminId(admin.getId());
  1269. order.setSn(sn1);
  1270. // 去掉后面的逗号
  1271. order.setProductNo(productNo);
  1272. if (productNumber == 1) {
  1273. productName.delete(productName.length() - 3, productName.length());
  1274. } else {
  1275. productName.deleteCharAt(productName.length() - 1);
  1276. }
  1277. order.setProductName(productName.toString());
  1278. order.setPrice(price);
  1279. order.setClientId(equipment.getClientId());
  1280. order.setEquipmentId(equipmentId);
  1281. order.setFrpCode(frpCode1);
  1282. order.setAltInfo(altInfo.toString());
  1283. order.setProductNumber(productNumber);
  1284. order.setStatus(0);
  1285. order.setType(admin.getType());
  1286. order.setCompanyType(companyType);
  1287. order.setMachineType(equipment.getMachineType());
  1288. if (admin.getType() == 0) {
  1289. order.setAdminProportion(proportion.getProportion());
  1290. order.setAgencyProportion(proportion.getAgencyProportion());
  1291. order.setAgencyId(proportion.getAgencyId());
  1292. }
  1293. if (admin.getType() == 1) {
  1294. order.setAdminProportion(proportion.getProportion());
  1295. order.setAgencyProportion(proportion.getAgencyProportion());
  1296. order.setAgencyId(proportion.getAgencyId());
  1297. order.setMerchantProportion(proportion.getMerchantProportion());
  1298. order.setMerchantId(proportion.getMerchantId());
  1299. }
  1300. if (admin.getType() == 2) {
  1301. order.setAdminProportion(proportion.getProportion());
  1302. order.setAgencyProportion(proportion.getAgencyProportion());
  1303. order.setAgencyId(proportion.getAgencyId());
  1304. order.setMerchantProportion(proportion.getMerchantProportion());
  1305. order.setMerchantId(proportion.getMerchantId());
  1306. order.setPersonageProportion(proportion.getPersonageProportion());
  1307. order.setPersonageId(proportion.getPersonageId());
  1308. }
  1309. order.setPayPlatform(payPlatform);
  1310. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  1311. order.setIsSettlement("0");
  1312. }
  1313. order.setNote(note.toString());
  1314. TOrder order2 = new TOrder();
  1315. order2.setId(IDGenerator.orderID());
  1316. order2.setCreateDate(new Date());
  1317. order2.setModifyDate(new Date());
  1318. order2.setAdminId(admin.getId());
  1319. order2.setSn(sn2);
  1320. order2.setProductName(productName.toString());
  1321. order2.setProductNo(productNo);
  1322. order2.setPrice(price);
  1323. order2.setClientId(equipment.getClientId());
  1324. order2.setEquipmentId(equipmentId);
  1325. order2.setFrpCode(frpCode2);
  1326. order2.setAltInfo(altInfo.toString());
  1327. order2.setStatus(0);
  1328. order2.setProductNumber(productNumber);
  1329. order2.setType(admin.getType());
  1330. order2.setCompanyType(companyType);
  1331. order2.setMachineType(equipment.getMachineType());
  1332. if (admin.getType() == 0) {
  1333. order2.setAdminProportion(proportion.getProportion());
  1334. order2.setAgencyProportion(proportion.getAgencyProportion());
  1335. order2.setAgencyId(proportion.getAgencyId());
  1336. }
  1337. if (admin.getType() == 1) {
  1338. order2.setAdminProportion(proportion.getProportion());
  1339. order2.setAgencyProportion(proportion.getAgencyProportion());
  1340. order2.setAgencyId(proportion.getAgencyId());
  1341. order2.setMerchantProportion(proportion.getMerchantProportion());
  1342. order2.setMerchantId(proportion.getMerchantId());
  1343. }
  1344. if (admin.getType() == 2) {
  1345. order2.setAdminProportion(proportion.getProportion());
  1346. order2.setAgencyProportion(proportion.getAgencyProportion());
  1347. order2.setAgencyId(proportion.getAgencyId());
  1348. order2.setMerchantProportion(proportion.getMerchantProportion());
  1349. order2.setMerchantId(proportion.getMerchantId());
  1350. order2.setPersonageProportion(proportion.getPersonageProportion());
  1351. order2.setPersonageId(proportion.getPersonageId());
  1352. }
  1353. order2.setPayPlatform(payPlatform);
  1354. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  1355. order2.setIsSettlement("0");
  1356. }
  1357. order2.setNote(note.toString());
  1358. // 订单明细表
  1359. TOrderDetails orderDetails = new TOrderDetails();
  1360. orderDetails.setAdminId(admin.getId());
  1361. orderDetails.setEquipmentId(equipmentId);
  1362. orderDetails.setCreateDate(new Date());
  1363. orderDetails.setCompanyType(companyType);
  1364. orderDetails.setRefundStatus("0");
  1365. orderDetails.setMachineType(equipment.getMachineType());
  1366. String productName1 = "";
  1367. if (productNumber > 1) {
  1368. if (equipment.getMachineType() == null || equipment.getMachineType().equals("0")) {
  1369. productName1 = "棉花糖-" + equipment.getName() + "-" + client6;
  1370. } else {
  1371. productName1 = "爆米花-" + equipment.getName() + "-" + client6;
  1372. }
  1373. } else {
  1374. productName1 = productName + "-" + equipment.getName() + "-" + client6;
  1375. }
  1376. Map<String, String> map = new HashMap<>();
  1377. String[] products = order.getNote().split(",");
  1378. for (String product : products) {
  1379. String[] parts = product.split(":");
  1380. // 商品名称-商品编号
  1381. String key = parts[0];
  1382. // 商品单价-商品数量
  1383. String value = parts[1];
  1384. map.put(key, value);
  1385. }
  1386. String result = null;
  1387. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  1388. // 汇付分账参数
  1389. order.setAcctSplitBunch(acctSplitBunch.toString());
  1390. order2.setAcctSplitBunch(acctSplitBunch.toString());
  1391. //添加到汇付临时表,微信
  1392. // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
  1393. // String[] ignoreProperties = {"id"};
  1394. // String id = HuifuUtils.inithuifuTempId();
  1395. // tHuifuTempOrder.setId(id);
  1396. // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
  1397. // huifuTempOrderService.save(tHuifuTempOrder);
  1398. // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  1399. // result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
  1400. // } else {
  1401. // result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
  1402. // }
  1403. String result1 = "";
  1404. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  1405. result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  1406. } else {
  1407. result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  1408. }
  1409. try {
  1410. result1 = URLEncoder.encode(result1, "UTF-8");
  1411. } catch (UnsupportedEncodingException e) {
  1412. e.printStackTrace();
  1413. }
  1414. // 支付宝
  1415. try {
  1416. result = huifuMchService.uniPay(
  1417. sn2, amount, productName1, productDesc,
  1418. notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
  1419. );
  1420. } catch (Exception e) {
  1421. e.printStackTrace();
  1422. return JsonMessage.error("申请支付失败");
  1423. }
  1424. if (StrUtil.isEmpty(result)) {
  1425. return JsonMessage.error("找不到支付图片");
  1426. }
  1427. // 汇聚支付支付申请返回支付二维码图片
  1428. String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
  1429. String qrcode = toQrcode(code1);
  1430. JSONObject kindData = new JSONObject();
  1431. kindData.put("sn", sn1 + "-" + sn2);
  1432. kindData.put("rd_Pic", qrcode);
  1433. for (String key : map.keySet()) {
  1434. // key:"玫瑰精灵-A01",value:"0.50-1"
  1435. String value = map.get(key);
  1436. String[] GoodsInfo = key.split("-");
  1437. String[] GoodsValue = value.split("-");
  1438. orderDetails.setId(HuifuUtils.initDetailsId());
  1439. orderDetails.setProductName(GoodsInfo[0]);
  1440. orderDetails.setProductNo(GoodsInfo[1]);
  1441. orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
  1442. orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
  1443. orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
  1444. orderDetails.setId(HuifuUtils.initDetailsId());
  1445. orderDetails.setOrderSn(sn1);
  1446. orderDetailsService.save(orderDetails);
  1447. orderDetails.setId(HuifuUtils.initDetailsId());
  1448. orderDetails.setOrderSn(sn2);
  1449. orderDetailsService.save(orderDetails);
  1450. }
  1451. orderService.save(order);
  1452. orderService.save(order2);
  1453. return JsonMessage.success(kindData.toString());
  1454. } else {
  1455. try {
  1456. result = joinpayMchService.uniPay(
  1457. orderNo1, amount, productName1, productDesc,
  1458. commonParameter, returnUrl, notifyUrl, frpCode1,
  1459. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  1460. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  1461. );
  1462. } catch (UnsupportedEncodingException e) {
  1463. e.printStackTrace();
  1464. return JsonMessage.error("申请支付失败");
  1465. }
  1466. JSONObject resultJson = JSONObject.parseObject(result);
  1467. String rc_Result1 = resultJson.getString("rc_Result");
  1468. String result1 = null;
  1469. try {
  1470. result1 = joinpayMchService.uniPay(
  1471. orderNo2, amount, productName1, productDesc,
  1472. commonParameter, returnUrl, notifyUrl, frpCode2,
  1473. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  1474. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  1475. );
  1476. } catch (UnsupportedEncodingException e) {
  1477. e.printStackTrace();
  1478. return JsonMessage.error("申请支付失败");
  1479. }
  1480. JSONObject resultJson1 = JSONObject.parseObject(result1);
  1481. String rc_Result2 = resultJson1.getString("rc_Result");
  1482. // 汇聚支付支付申请返回支付二维码图片
  1483. String code1 = "http://app.sunzee.com.cn/" + "/api/order/aliPay.htm?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
  1484. String rd_Pic = toQrcode(code1);
  1485. JSONObject kindData = new JSONObject();
  1486. kindData.put("sn", sn1 + "-" + sn2);
  1487. kindData.put("rd_Pic", rd_Pic);
  1488. for (String key : map.keySet()) {
  1489. // key:"玫瑰精灵-A01",value:"0.50-1"
  1490. String value = map.get(key);
  1491. String[] GoodsInfo = key.split("-");
  1492. String[] GoodsValue = value.split("-");
  1493. orderDetails.setId(HuifuUtils.initDetailsId());
  1494. orderDetails.setProductName(GoodsInfo[0]);
  1495. orderDetails.setProductNo(GoodsInfo[1]);
  1496. orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
  1497. orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
  1498. orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
  1499. orderDetails.setId(HuifuUtils.initDetailsId());
  1500. orderDetails.setOrderSn(sn1);
  1501. orderDetailsService.save(orderDetails);
  1502. orderDetails.setId(HuifuUtils.initDetailsId());
  1503. orderDetails.setOrderSn(sn2);
  1504. orderDetailsService.save(orderDetails);
  1505. }
  1506. orderService.save(order);
  1507. orderService.save(order2);
  1508. return JsonMessage.success(kindData.toString());
  1509. }
  1510. }
  1511. @ApiOperation(value = "购物车 微信小程序支付")
  1512. @PostMapping("/carsPayXCX")
  1513. public Object carsPayXCX(String clientId, String id, String coupons, @RequestBody Map<String, String> productNameMap) {
  1514. if (productNameMap == null) {
  1515. return JsonMessage.error("数据出错");
  1516. }
  1517. StringBuffer note = new StringBuffer();
  1518. StringBuffer productName = new StringBuffer();
  1519. String productNo = "";
  1520. Map<String, Integer> productMap = new HashMap<>();
  1521. Integer productNumber = 0;
  1522. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  1523. if (equipment == null || equipment.getId() == null) {
  1524. return JsonMessage.error("找不到设备");
  1525. }
  1526. BigDecimal price = new BigDecimal("0.00");
  1527. List<TPromoCode> promoCodeAll = new ArrayList<>();
  1528. TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
  1529. if (StringUtils.isNotEmpty(equipmentDesc.getStatus())) {
  1530. if (equipmentDesc.getStatus().equals("1")) {
  1531. return JsonMessage.error("设备在做糖,请稍后再进行支付");
  1532. }
  1533. }
  1534. if (equipmentDesc == null || equipmentDesc.getEquipmentId() == null || equipmentDesc.getPayType() == null || equipmentDesc.getPayType().equals("0")) {
  1535. //1,type=0,原始设定,没有第二件半价
  1536. for (String key : productNameMap.keySet()) {
  1537. String entryValue = String.valueOf(productNameMap.get(key));
  1538. List<String> value = JSON.parseArray(entryValue, String.class);
  1539. List<TPromoCode> promoCodeList = new ArrayList<>();
  1540. //1,校验优惠码
  1541. if (value.size() > 0) {
  1542. for (String code : value) {
  1543. if (!code.equals("0")) {
  1544. TPromoCode promoCode = new TPromoCode();
  1545. ResponseModel<TPromoCode> promoCode1 = szwlFeign.getPromoCode(code + "-" + equipment.getAdminId().toString());
  1546. TPromoCode tPromoCode = promoCode1.getData();
  1547. promoCode = tPromoCode;
  1548. if (tPromoCode == null || tPromoCode.getId() == null) {
  1549. //不存在
  1550. return JsonMessage.success("1");
  1551. }
  1552. //
  1553. Date lastUseDate = null;
  1554. if (promoCode != null) {
  1555. lastUseDate = promoCode.getLastUseDate();
  1556. }
  1557. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  1558. promoCode.setIsUse("2");
  1559. szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
  1560. //过期
  1561. return JsonMessage.success("4");
  1562. }
  1563. if (promoCode.getId() == null) {
  1564. //不存在
  1565. return JsonMessage.success("1");
  1566. }
  1567. if (promoCode.getIsUse().equals("1")) {
  1568. //被使用
  1569. return JsonMessage.success("2");
  1570. }
  1571. if (!promoCode.getAdminId().equals("1")) {
  1572. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  1573. } else {
  1574. //不是本机
  1575. return JsonMessage.success("3");
  1576. }
  1577. }
  1578. if (promoCode.getDiscount() == null) {
  1579. //旧优惠码
  1580. return JsonMessage.success("0");
  1581. }
  1582. if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  1583. //0折
  1584. return JsonMessage.success("0");
  1585. }
  1586. promoCodeList.add(promoCode);
  1587. promoCodeAll.add(promoCode);
  1588. }
  1589. }
  1590. }
  1591. String[] productNum = key.split("-");
  1592. String productNamea = productNum[0];
  1593. String num = productNum[1];
  1594. productMap.put(productNamea, Integer.valueOf(num));
  1595. productNumber += Integer.valueOf(num);
  1596. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
  1597. productNo = product.getNo();
  1598. if (product == null) {
  1599. return JsonMessage.error("找不到商品");
  1600. }
  1601. productName.append(productNamea).append("x").append(num).append(",");
  1602. String no = product.getNo();
  1603. if (StringUtils.isEmpty(no)) {
  1604. no = "A00";
  1605. }
  1606. note.append(no).append("-").append(productNamea).append("-").append(num).append(":");
  1607. //确定价格,然后叠加R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
  1608. BigDecimal productPrice = product.getRmbPrice();
  1609. if (promoCodeList.size() > 0) {
  1610. //有优惠码
  1611. BigDecimal onePrice = new BigDecimal("0.00");
  1612. int i;
  1613. for (i = 0; i < promoCodeList.size(); i++) {
  1614. TPromoCode tPromoCode = promoCodeList.get(i);
  1615. BigDecimal discount = BigDecimal.valueOf(tPromoCode.getDiscount()).setScale(2, RoundingMode.HALF_DOWN);
  1616. if (StringUtils.isEmpty(tPromoCode.getType()) || tPromoCode.getType().equals("0")) {
  1617. //折扣优惠码
  1618. BigDecimal price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  1619. price = price.add(price1);
  1620. onePrice = onePrice.add(price1);
  1621. } else {
  1622. //折扣价优惠码
  1623. BigDecimal price1 = productPrice.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
  1624. price = price.add(price1);
  1625. onePrice = onePrice.add(price1);
  1626. }
  1627. }
  1628. if (i < Integer.valueOf(num)) {
  1629. int a = Integer.valueOf(num) - i;
  1630. BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
  1631. price = price.add(price2);
  1632. onePrice = onePrice.add(price2);
  1633. }
  1634. note.append(onePrice).append(",");
  1635. } else {
  1636. //1,type=0,原始设定,没有第二件半价
  1637. int a = Integer.valueOf(num);
  1638. BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
  1639. price = price.add(price2);
  1640. note.append(price2).append(",");
  1641. }
  1642. }
  1643. } else {
  1644. //2,type=1,第二件半价
  1645. //2.1 判定是否有第二件,有多少个第二件半价
  1646. for (String key : productNameMap.keySet()) {
  1647. String entryValue = String.valueOf(productNameMap.get(key));
  1648. List<String> value = JSON.parseArray(entryValue, String.class);
  1649. String[] productNum = key.split("-");
  1650. String productNamea = productNum[0];
  1651. String num = productNum[1];
  1652. productMap.put(productNamea, Integer.valueOf(num));
  1653. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
  1654. productNo = product.getNo();
  1655. BigDecimal productPrice = product.getRmbPrice();
  1656. productName.append(productNamea).append("x").append(num).append(",");
  1657. note.append(productNamea).append(num).append(":");
  1658. switch (num) {
  1659. case "1":
  1660. //1个 0个半价
  1661. price = price.add(productPrice);
  1662. note.append(price).append(",");
  1663. break;
  1664. case "2":
  1665. //2个 1个半价
  1666. price = price.add(productPrice);
  1667. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1668. note.append(price).append(",");
  1669. break;
  1670. case "3":
  1671. //3个 1个半价
  1672. price = price.add(productPrice);
  1673. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1674. price = price.add(productPrice);
  1675. note.append(price).append(",");
  1676. break;
  1677. case "4":
  1678. //4个 2个半价
  1679. price = price.add(productPrice);
  1680. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1681. price = price.add(productPrice);
  1682. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1683. note.append(price).append(",");
  1684. break;
  1685. case "5":
  1686. //5个 2个半价
  1687. price = price.add(productPrice);
  1688. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1689. price = price.add(productPrice);
  1690. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  1691. price = price.add(productPrice);
  1692. note.append(price).append(",");
  1693. break;
  1694. }
  1695. }
  1696. }
  1697. if (equipment == null) {
  1698. return JsonMessage.error("找不到设备");
  1699. }
  1700. Long equipmentId = equipment.getId();
  1701. //查找商品
  1702. Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
  1703. String sn1 = orderService.initSn(client6);
  1704. // 获取关联设备的分销
  1705. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  1706. if (proportion == null || proportion.getId() == null) {
  1707. return JsonMessage.error("设备商家未完成分销设置");
  1708. }
  1709. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  1710. if (admin == null) {
  1711. return JsonMessage.error("找不到设备商家");
  1712. }
  1713. // 支付方式:0或null为汇聚,1为汇付支付
  1714. String payPlatform = admin.getPayPlatform();
  1715. String companyType = admin.getCompanyType();
  1716. // 汇聚分账参数
  1717. JSONArray altInfo = new JSONArray();
  1718. // 汇付分账明细参数
  1719. JSONObject acctSplitBunch = new JSONObject();
  1720. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  1721. acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
  1722. if (!(acctSplitBunch.size() > 0)) {
  1723. return JsonMessage.error("设备商家未注册结算账号");
  1724. }
  1725. } else {
  1726. altInfo = getAltInfo(proportion, price);
  1727. if (!(altInfo.size() > 0)) {
  1728. return JsonMessage.error("设备商家未注册结算账号");
  1729. }
  1730. }
  1731. String orderNo1 = sn1;
  1732. String productDesc = "";
  1733. String commonParameter = "";
  1734. String returnUrl = null;
  1735. String notifyUrl = JoinpayConstant.Notify_Url;
  1736. String isShowPic = "1";
  1737. TSzsmWx szsmWx = szsmWxService.getById(id);
  1738. String openId = szsmWx.getOpenId();
  1739. String authCode = null;
  1740. String appid = "wx5071443e63295c29";
  1741. String transactionModel = null;
  1742. String tradeMerchantNo = "777114600391409";
  1743. String buyerId = null;
  1744. String isAlt = "1";
  1745. String altType = "11";
  1746. String altUrl = null;
  1747. BigDecimal priceTemp = price.setScale(2, RoundingMode.HALF_DOWN);
  1748. List<TPromoCode> yhjList = new ArrayList<>();
  1749. if (StringUtils.isNotEmpty(coupons)) {
  1750. String[] cous = coupons.split(",");
  1751. if (cous.length > 0) {
  1752. for (int i = 0; i < cous.length; i++) {
  1753. if (StringUtils.isNotEmpty(cous[i])) {
  1754. TPromoCode yhj = R.getDataIfSuccess(szwlFeign.getYHJ(cous[i]));
  1755. if (yhj != null && yhj.getId() != null) {
  1756. String isUse = yhj.getIsUse();
  1757. if (isUse.equals("1")) {
  1758. return R.ok(yhj.getCode(), "优惠券已使用");
  1759. }
  1760. Date lastUseDate = yhj.getLastUseDate();
  1761. Date date = new Date();
  1762. if (date.getTime() > lastUseDate.getTime()) {
  1763. return R.ok(yhj.getCode(), "优惠券已过期");
  1764. }
  1765. yhjList.add(yhj);
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. List<String> couponList = new ArrayList<>();
  1772. //营销金额
  1773. BigDecimal marketingAmount = null;
  1774. if (yhjList.size() > 0) {
  1775. for (TPromoCode yhj : yhjList) {
  1776. if (yhj != null && yhj.getId() != null) {
  1777. if (marketingAmount == null) {
  1778. marketingAmount = new BigDecimal("0.00");
  1779. }
  1780. marketingAmount = marketingAmount.add(new BigDecimal(yhj.getDiscount()).setScale(2, RoundingMode.HALF_DOWN));
  1781. couponList.add(String.valueOf(yhj.getCode()));
  1782. if (marketingAmount.compareTo(price) >= 0) {
  1783. marketingAmount = priceTemp.subtract(new BigDecimal("0.01"));
  1784. price = new BigDecimal("0.01").setScale(2, RoundingMode.HALF_DOWN);
  1785. break;
  1786. } else {
  1787. price = price.subtract(marketingAmount);
  1788. }
  1789. }
  1790. }
  1791. }
  1792. String frpCode1 = "WEIXIN_XCX";
  1793. BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
  1794. TOrder order = new TOrder();
  1795. order.setId(IDGenerator.orderID());
  1796. order.setCreateDate(new Date());
  1797. order.setModifyDate(new Date());
  1798. order.setAdminId(admin.getId());
  1799. order.setSn(sn1);
  1800. order.setProductDesc(JSONArray.toJSONString(productNameMap));
  1801. // 去掉后面的逗号
  1802. order.setProductNo(productNo);
  1803. if (productNumber == 1) {
  1804. productName.delete(productName.length() - 3, productName.length());
  1805. } else {
  1806. productName.deleteCharAt(productName.length() - 1);
  1807. }
  1808. order.setProductName(productName.toString());
  1809. order.setPrice(price);
  1810. order.setClientId(equipment.getClientId());
  1811. order.setEquipmentId(equipmentId);
  1812. order.setFrpCode(frpCode1);
  1813. order.setAltInfo(altInfo.toString());
  1814. order.setStatus(0);
  1815. order.setType(admin.getType());
  1816. order.setMarketingAmount(marketingAmount);
  1817. order.setProductNumber(productNumber);
  1818. order.setCompanyType(companyType);
  1819. order.setMachineType(equipment.getMachineType());
  1820. if (couponList.size() > 0) {
  1821. order.setCoupons(couponList.toString());
  1822. }
  1823. if (admin.getType() == 0) {
  1824. order.setAdminProportion(proportion.getProportion());
  1825. order.setAgencyProportion(proportion.getAgencyProportion());
  1826. order.setAgencyId(proportion.getAgencyId());
  1827. }
  1828. if (admin.getType() == 1) {
  1829. order.setAdminProportion(proportion.getProportion());
  1830. order.setAgencyProportion(proportion.getAgencyProportion());
  1831. order.setAgencyId(proportion.getAgencyId());
  1832. order.setMerchantProportion(proportion.getMerchantProportion());
  1833. order.setMerchantId(proportion.getMerchantId());
  1834. }
  1835. if (admin.getType() == 2) {
  1836. order.setAdminProportion(proportion.getProportion());
  1837. order.setAgencyProportion(proportion.getAgencyProportion());
  1838. order.setAgencyId(proportion.getAgencyId());
  1839. order.setMerchantProportion(proportion.getMerchantProportion());
  1840. order.setMerchantId(proportion.getMerchantId());
  1841. order.setPersonageProportion(proportion.getPersonageProportion());
  1842. order.setPersonageId(proportion.getPersonageId());
  1843. }
  1844. order.setPayPlatform(payPlatform);
  1845. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  1846. order.setIsSettlement("0");
  1847. }
  1848. order.setNote(note.toString());
  1849. if (StringUtils.isNotEmpty(id)) {
  1850. order.setWxId(Long.valueOf(id));
  1851. }
  1852. if (BigDecimal.ZERO.compareTo(price) >= 0) {
  1853. order.setStatus(1);
  1854. orderService.updateById(order);
  1855. //修改优惠码状态
  1856. if (promoCodeAll.size() > 0) {
  1857. for (TPromoCode code : promoCodeAll) {
  1858. szwlFeign.updatePromoCode(String.valueOf(code.getId()), "2");
  1859. }
  1860. }
  1861. //发送远程命令到机器那边,让机器做糖
  1862. equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("cardPayXCX", String.valueOf(productNameMap)).toString());
  1863. return JsonMessage.success("支付成功");
  1864. }
  1865. // 订单明细表
  1866. TOrderDetails orderDetails = new TOrderDetails();
  1867. orderDetails.setAdminId(admin.getId());
  1868. orderDetails.setEquipmentId(equipmentId);
  1869. orderDetails.setCreateDate(new Date());
  1870. orderDetails.setCompanyType(companyType);
  1871. orderDetails.setRefundStatus("0");
  1872. orderDetails.setMachineType(equipment.getMachineType());
  1873. // String client6 = clientId.substring(clientId.length() - 6);
  1874. String productName1 = "";
  1875. if (productNumber > 1) {
  1876. if (equipment.getMachineType() == null || equipment.getMachineType().equals("0")) {
  1877. productName1 = "棉花糖-" + equipment.getName() + "-" + client6;
  1878. } else {
  1879. productName1 = "爆米花-" + equipment.getName() + "-" + client6;
  1880. }
  1881. } else {
  1882. productName1 = productName + "-" + equipment.getName() + "-" + client6;
  1883. }
  1884. String result = null;
  1885. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  1886. order.setAcctSplitBunch(acctSplitBunch.toString());
  1887. try {
  1888. result = huifuMchService.uniPay(
  1889. orderNo1, amount, productName1, productDesc,
  1890. notifyUrl, frpCode1, openId, appid, acctSplitBunch, companyType
  1891. );
  1892. } catch (Exception e) {
  1893. e.printStackTrace();
  1894. return JsonMessage.error("申请支付失败");
  1895. }
  1896. // 返回支付二维码图片
  1897. if (result == null || StringUtils.isBlank(result)) {
  1898. return JsonMessage.error("申请支付失败");
  1899. }
  1900. Map<String, String> map = new HashMap<>();
  1901. map.put("sn", sn1);
  1902. map.put("rc_Result", result);
  1903. for (String key : productMap.keySet()) {
  1904. Integer productNum = productMap.get(key);
  1905. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), key));
  1906. orderDetails.setId(HuifuUtils.initDetailsId());
  1907. orderDetails.setProductNo(product.getNo());
  1908. orderDetails.setProductName(key);
  1909. orderDetails.setPrice(product.getRmbPrice());
  1910. orderDetails.setProductNumber(productNum);
  1911. orderDetails.setAmount(product.getRmbPrice().multiply(new BigDecimal(productNum)));
  1912. orderDetails.setOrderSn(sn1);
  1913. orderDetailsService.save(orderDetails);
  1914. }
  1915. orderService.save(order);
  1916. return JsonMessage.success(map);
  1917. } else {
  1918. try {
  1919. result = joinpayMchService.uniPay(
  1920. orderNo1, amount, productName1, productDesc,
  1921. commonParameter, returnUrl, notifyUrl, frpCode1,
  1922. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  1923. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  1924. );
  1925. } catch (UnsupportedEncodingException e) {
  1926. e.printStackTrace();
  1927. return JsonMessage.error("申请支付失败");
  1928. }
  1929. JSONObject resultJson = JSONObject.parseObject(result);
  1930. // 汇聚支付支付申请返回支付二维码图片
  1931. String rc_Result = resultJson.getString("rc_Result");
  1932. if (resultJson == null || StringUtils.isBlank(rc_Result)) {
  1933. return JsonMessage.error("申请支付失败");
  1934. }
  1935. Map<String, String> map = new HashMap<>();
  1936. map.put("sn", sn1);
  1937. map.put("rc_Result", rc_Result);
  1938. for (String key : productMap.keySet()) {
  1939. Integer productNum = productMap.get(key);
  1940. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), key));
  1941. orderDetails.setId(HuifuUtils.initDetailsId());
  1942. orderDetails.setProductNo(product.getNo());
  1943. orderDetails.setProductName(key);
  1944. orderDetails.setPrice(product.getRmbPrice());
  1945. orderDetails.setProductNumber(productNum);
  1946. orderDetails.setAmount(product.getRmbPrice().multiply(new BigDecimal(productNum)));
  1947. orderDetails.setOrderSn(sn1);
  1948. orderDetailsService.save(orderDetails);
  1949. }
  1950. orderService.save(order);
  1951. return JsonMessage.success(map);
  1952. }
  1953. }
  1954. /**
  1955. * 冰淇淋请求在线支付 主扫 优惠码 二码合一
  1956. *
  1957. * @param clientId 设备唯一编号
  1958. * @param productName 商品名称:"冰淇淋-草莓酱,榛子碎"
  1959. * @return
  1960. */
  1961. @ApiOperation(value = "请求在线支付 二码合一")
  1962. @GetMapping("/iceCreamTwoPay")
  1963. public Object iceCreamTwoPay(String code, String clientId, String productName) {
  1964. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  1965. if (equipment == null || equipment.getId() == null) {
  1966. return JsonMessage.error("找不到设备");
  1967. }
  1968. //验证优惠码 code=null 则不选用优惠码
  1969. TPromoCode promoCode = new TPromoCode();
  1970. if (StringUtils.isEmpty(code)) {
  1971. //没有优惠码
  1972. } else {
  1973. //有优惠码,需要对优惠码进行验证
  1974. ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
  1975. TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
  1976. promoCode = tPromoCode;
  1977. if (tPromoCode == null || tPromoCode.getId() == null) {
  1978. //不存在
  1979. return JsonMessage.success("1");
  1980. }
  1981. if (promoCode.getId() == null) {
  1982. //不存在
  1983. return JsonMessage.success("1");
  1984. }
  1985. Date lastUseDate = null;
  1986. if (promoCode != null && promoCode.getId() != null) {
  1987. lastUseDate = promoCode.getLastUseDate();
  1988. }
  1989. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  1990. promoCode.setIsUse("2");
  1991. szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
  1992. //过期
  1993. return JsonMessage.success("4");
  1994. }
  1995. if (promoCode.getIsUse().equals("1")) {
  1996. //被使用
  1997. return JsonMessage.success("2");
  1998. }
  1999. if (!promoCode.getAdminId().equals("1")) {
  2000. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  2001. } else {
  2002. //不是本机
  2003. return JsonMessage.success("3");
  2004. }
  2005. }
  2006. if (promoCode.getDiscount() == null) {
  2007. //旧优惠码
  2008. return JsonMessage.success("0");
  2009. }
  2010. if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  2011. //0折
  2012. return JsonMessage.success("0");
  2013. }
  2014. }
  2015. if (equipment == null) {
  2016. return JsonMessage.error("找不到设备");
  2017. }
  2018. Long equipmentId = equipment.getId();
  2019. // 查找商品
  2020. String[] split = productName.split("-");
  2021. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), split[0]));
  2022. if (product == null) {
  2023. return JsonMessage.error("找不到商品");
  2024. }
  2025. // 处理后的商品名称
  2026. String newProductName = split[0];
  2027. // 冰淇淋价格
  2028. BigDecimal price = product.getRmbPrice();
  2029. // 商品ID
  2030. Long productId = product.getId();
  2031. // 冰淇淋编号
  2032. String productNo = product.getNo();
  2033. // 如果添加其他果酱和小料
  2034. if (split.length > 1) {
  2035. String[] split1 = split[1].split(",");
  2036. String tempName = "(";
  2037. for (String s : split1) {
  2038. TProduct product1 = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), s));
  2039. if (product1 == null) {
  2040. return JsonMessage.error("找不到商品");
  2041. }
  2042. tempName = tempName + s + "、";
  2043. price = price.add(product1.getRmbPrice());
  2044. }
  2045. tempName = tempName.substring(0, tempName.length() - 1) + ")";
  2046. newProductName += tempName;
  2047. }
  2048. if (StringUtils.isNotEmpty(code)) {
  2049. BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
  2050. if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
  2051. if (price.compareTo(discount) > 0) {
  2052. // 如果 price 大于 discount,从 price 中减去 discount
  2053. price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
  2054. } else {
  2055. // 如果 price 小于等于 discount,将 price 设置为 0
  2056. // price = BigDecimal.ZERO;
  2057. return JsonMessage.success("0");
  2058. }
  2059. } else {
  2060. price = price.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  2061. }
  2062. }
  2063. if (BigDecimal.ZERO.compareTo(price) >= 0) {
  2064. return JsonMessage.error("商品价格异常");
  2065. }
  2066. Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
  2067. String sn1 = orderService.initSn(client6);
  2068. String sn2 = orderService.initSn(client6);
  2069. // 获取关联设备的分销
  2070. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  2071. if (proportion == null || proportion.getId() == null) {
  2072. return JsonMessage.error("设备商家未完成分销设置");
  2073. }
  2074. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  2075. if (admin == null) {
  2076. return JsonMessage.error("找不到设备商家");
  2077. }
  2078. // 支付方式:0或null为汇聚,1为汇付支付
  2079. String payPlatform = admin.getPayPlatform();
  2080. String companyType = admin.getCompanyType();
  2081. // 汇聚分账参数
  2082. JSONArray altInfo = new JSONArray();
  2083. // 汇付分账明细参数
  2084. JSONObject acctSplitBunch = new JSONObject();
  2085. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  2086. acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
  2087. if (!(acctSplitBunch.size() > 0)) {
  2088. return JsonMessage.error("设备商家未注册结算账号");
  2089. }
  2090. } else {
  2091. altInfo = getAltInfo(proportion, price);
  2092. if (!(altInfo.size() > 0)) {
  2093. return JsonMessage.error("设备商家未注册结算账号");
  2094. }
  2095. }
  2096. String orderNo1 = sn1;
  2097. String orderNo2 = sn2;
  2098. BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
  2099. String productDesc = "";
  2100. String commonParameter = "";
  2101. String returnUrl = null;
  2102. String notifyUrl = JoinpayConstant.Notify_Url;
  2103. String isShowPic = "1";
  2104. String openId = null;
  2105. String authCode = null;
  2106. String appid = null;
  2107. String transactionModel = null;
  2108. String tradeMerchantNo = admin.getTradeMerchantNo();
  2109. String buyerId = null;
  2110. String isAlt = "1";
  2111. String altType = "11";
  2112. String altUrl = null;
  2113. BigDecimal marketingAmount = null;
  2114. String frpCode1 = "WEIXIN_NATIVE";
  2115. String frpCode2 = "ALIPAY_NATIVE";
  2116. Integer productNumber = 1;
  2117. TOrder order = new TOrder();
  2118. order.setId(IDGenerator.orderID());
  2119. order.setCreateDate(new Date());
  2120. order.setModifyDate(new Date());
  2121. order.setAdminId(admin.getId());
  2122. order.setSn(sn1);
  2123. order.setProductId(productId);
  2124. order.setProductNo(productNo);
  2125. order.setProductName(newProductName);
  2126. order.setProductNumber(productNumber);
  2127. order.setPrice(price);
  2128. order.setClientId(equipment.getClientId());
  2129. order.setEquipmentId(equipmentId);
  2130. order.setFrpCode(frpCode1);
  2131. order.setAltInfo(altInfo.toString());
  2132. order.setStatus(0);
  2133. order.setType(admin.getType());
  2134. order.setCompanyType(companyType);
  2135. order.setMachineType(equipment.getMachineType());
  2136. if (admin.getType() == 0) {
  2137. order.setAdminProportion(proportion.getProportion());
  2138. order.setAgencyProportion(proportion.getAgencyProportion());
  2139. order.setAgencyId(proportion.getAgencyId());
  2140. }
  2141. if (admin.getType() == 1) {
  2142. order.setAdminProportion(proportion.getProportion());
  2143. order.setAgencyProportion(proportion.getAgencyProportion());
  2144. order.setAgencyId(proportion.getAgencyId());
  2145. order.setMerchantProportion(proportion.getMerchantProportion());
  2146. order.setMerchantId(proportion.getMerchantId());
  2147. }
  2148. if (admin.getType() == 2) {
  2149. order.setAdminProportion(proportion.getProportion());
  2150. order.setAgencyProportion(proportion.getAgencyProportion());
  2151. order.setAgencyId(proportion.getAgencyId());
  2152. order.setMerchantProportion(proportion.getMerchantProportion());
  2153. order.setMerchantId(proportion.getMerchantId());
  2154. order.setPersonageProportion(proportion.getPersonageProportion());
  2155. order.setPersonageId(proportion.getPersonageId());
  2156. }
  2157. order.setPayPlatform(payPlatform);
  2158. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  2159. order.setIsSettlement("0");
  2160. }
  2161. TOrder order2 = new TOrder();
  2162. order2.setId(IDGenerator.orderID());
  2163. order2.setCreateDate(new Date());
  2164. order2.setModifyDate(new Date());
  2165. order2.setAdminId(admin.getId());
  2166. order2.setSn(sn2);
  2167. order2.setProductId(productId);
  2168. order2.setProductNo(productNo);
  2169. order2.setProductName(newProductName);
  2170. order2.setProductNumber(productNumber);
  2171. order2.setPrice(price);
  2172. order2.setClientId(equipment.getClientId());
  2173. order2.setEquipmentId(equipmentId);
  2174. order2.setFrpCode(frpCode2);
  2175. order2.setAltInfo(altInfo.toString());
  2176. order2.setStatus(0);
  2177. order2.setType(admin.getType());
  2178. order2.setPayPlatform(payPlatform);
  2179. order2.setCompanyType(companyType);
  2180. order2.setMachineType(equipment.getMachineType());
  2181. if (admin.getType() == 0) {
  2182. order2.setAdminProportion(proportion.getProportion());
  2183. order2.setAgencyProportion(proportion.getAgencyProportion());
  2184. order2.setAgencyId(proportion.getAgencyId());
  2185. }
  2186. if (admin.getType() == 1) {
  2187. order2.setAdminProportion(proportion.getProportion());
  2188. order2.setAgencyProportion(proportion.getAgencyProportion());
  2189. order2.setAgencyId(proportion.getAgencyId());
  2190. order2.setMerchantProportion(proportion.getMerchantProportion());
  2191. order2.setMerchantId(proportion.getMerchantId());
  2192. }
  2193. if (admin.getType() == 2) {
  2194. order2.setAdminProportion(proportion.getProportion());
  2195. order2.setAgencyProportion(proportion.getAgencyProportion());
  2196. order2.setAgencyId(proportion.getAgencyId());
  2197. order2.setMerchantProportion(proportion.getMerchantProportion());
  2198. order2.setMerchantId(proportion.getMerchantId());
  2199. order2.setPersonageProportion(proportion.getPersonageProportion());
  2200. order2.setPersonageId(proportion.getPersonageId());
  2201. }
  2202. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  2203. order2.setIsSettlement("0");
  2204. }
  2205. // 订单明细表
  2206. TOrderDetails orderDetails = new TOrderDetails();
  2207. orderDetails.setAdminId(admin.getId());
  2208. orderDetails.setEquipmentId(equipmentId);
  2209. orderDetails.setCreateDate(new Date());
  2210. orderDetails.setPrice(price);
  2211. orderDetails.setProductName(newProductName);
  2212. orderDetails.setProductNo(productNo);
  2213. orderDetails.setProductNumber(productNumber);
  2214. orderDetails.setAmount(price);
  2215. orderDetails.setCompanyType(companyType);
  2216. orderDetails.setRefundStatus("0");
  2217. orderDetails.setMachineType(equipment.getMachineType());
  2218. // String client6 = clientId.substring(clientId.length() - 6);
  2219. String productName1 = "雪糕" + "-" + equipment.getName() + "-" + client6;
  2220. String result = null;
  2221. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  2222. // 汇付分账参数
  2223. order.setAcctSplitBunch(acctSplitBunch.toString());
  2224. order2.setAcctSplitBunch(acctSplitBunch.toString());
  2225. //添加到汇付临时表,微信
  2226. // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
  2227. // String[] ignoreProperties = {"id"};
  2228. // String id = HuifuUtils.inithuifuTempId();
  2229. // tHuifuTempOrder.setId(id);
  2230. // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
  2231. // huifuTempOrderService.save(tHuifuTempOrder);
  2232. // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  2233. // result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
  2234. // } else {
  2235. // result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
  2236. // }
  2237. String result1 = "";
  2238. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  2239. result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  2240. } else {
  2241. result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  2242. }
  2243. try {
  2244. result1 = URLEncoder.encode(result1, "UTF-8");
  2245. } catch (UnsupportedEncodingException e) {
  2246. e.printStackTrace();
  2247. }
  2248. // 支付宝
  2249. try {
  2250. result = huifuMchService.uniPay(
  2251. sn2, amount, productName1, productDesc,
  2252. notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
  2253. );
  2254. } catch (Exception e) {
  2255. e.printStackTrace();
  2256. return JsonMessage.error("申请支付失败");
  2257. }
  2258. if (StrUtil.isEmpty(result)) {
  2259. return JsonMessage.error("找不到支付图片");
  2260. }
  2261. // 汇聚支付支付申请返回支付二维码图片
  2262. String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
  2263. String qrcode = toQrcode(code1);
  2264. JSONObject kindData = new JSONObject();
  2265. kindData.put("sn", sn1 + "-" + sn2);
  2266. kindData.put("rd_Pic", qrcode);
  2267. orderService.save(order);
  2268. orderDetails.setOrderSn(sn1);
  2269. orderDetails.setId(HuifuUtils.initDetailsId());
  2270. orderDetailsService.save(orderDetails);
  2271. orderDetails.setOrderSn(sn2);
  2272. orderDetails.setId(HuifuUtils.initDetailsId());
  2273. orderDetailsService.save(orderDetails);
  2274. orderService.save(order2);
  2275. return JsonMessage.success(kindData.toString());
  2276. } else {
  2277. try {
  2278. result = joinpayMchService.uniPay(
  2279. orderNo1, amount, productName1, productDesc,
  2280. commonParameter, returnUrl, notifyUrl, frpCode1,
  2281. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  2282. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  2283. );
  2284. } catch (UnsupportedEncodingException e) {
  2285. e.printStackTrace();
  2286. return JsonMessage.error("申请支付失败");
  2287. }
  2288. JSONObject resultJson = JSONObject.parseObject(result);
  2289. String rc_Result1 = resultJson.getString("rc_Result");
  2290. String result1 = null;
  2291. try {
  2292. result1 = joinpayMchService.uniPay(
  2293. orderNo2, amount, productName1, productDesc,
  2294. commonParameter, returnUrl, notifyUrl, frpCode2,
  2295. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  2296. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  2297. );
  2298. } catch (UnsupportedEncodingException e) {
  2299. e.printStackTrace();
  2300. return JsonMessage.error("申请支付失败");
  2301. }
  2302. JSONObject resultJson1 = JSONObject.parseObject(result1);
  2303. String rc_Result2 = resultJson1.getString("rc_Result");
  2304. // 汇聚支付支付申请返回支付二维码图片
  2305. String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/" + "aliPay?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
  2306. String rd_Pic = toQrcode(code1);
  2307. JSONObject kindData = new JSONObject();
  2308. kindData.put("sn", sn1 + "-" + sn2);
  2309. kindData.put("rd_Pic", rd_Pic);
  2310. orderService.save(order);
  2311. orderDetails.setOrderSn(sn1);
  2312. orderDetails.setId(HuifuUtils.initDetailsId());
  2313. orderDetailsService.save(orderDetails);
  2314. orderDetails.setOrderSn(sn2);
  2315. orderDetails.setId(HuifuUtils.initDetailsId());
  2316. orderDetailsService.save(orderDetails);
  2317. orderService.save(order2);
  2318. return JsonMessage.success(kindData.toString());
  2319. }
  2320. }
  2321. /**
  2322. * 冰淇淋购物车支付
  2323. *
  2324. * @param clientId 设备唯一编号
  2325. * @param productNameMap 商品信息:"冰淇淋-草莓酱,榛子碎-2": "[\"562278\",\"0\"]"
  2326. * @return
  2327. */
  2328. @ApiOperation(value = "购物车 请求在线支付 二码合一")
  2329. @PostMapping("/iceCreamCarsPay")
  2330. public Object iceCreamCarsPay(String clientId, @RequestBody Map<String, String> productNameMap) {
  2331. if (productNameMap == null) {
  2332. return JsonMessage.error("数据出错");
  2333. }
  2334. StringBuffer note = new StringBuffer();
  2335. StringBuffer productName = new StringBuffer();
  2336. String productNo = "";
  2337. Map<String, Integer> productMap = new HashMap<>();
  2338. Integer productNumber = 0;
  2339. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  2340. if (equipment == null || equipment.getId() == null) {
  2341. return JsonMessage.error("找不到设备");
  2342. }
  2343. BigDecimal price = new BigDecimal("0.00");
  2344. TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
  2345. if (equipmentDesc == null || equipmentDesc.getEquipmentId() == null || equipmentDesc.getPayType() == null || equipmentDesc.getPayType().equals("0")) {
  2346. // 1、type=0,原始设定,没有第二件半价
  2347. for (String key : productNameMap.keySet()) {
  2348. String entryValue = String.valueOf(productNameMap.get(key));
  2349. List<String> value = JSON.parseArray(entryValue, String.class);
  2350. boolean hasDuplicate = hasDuplicateValue(value);
  2351. if (hasDuplicate) {
  2352. return JsonMessage.error("优惠码输入重复,单个商品只能使用一个优惠码");
  2353. }
  2354. List<TPromoCode> promoCodeList = new ArrayList<>();
  2355. // 1、校验优惠码
  2356. if (value.size() > 0) {
  2357. for (String code : value) {
  2358. if (!code.equals("0")) {
  2359. TPromoCode promoCode;
  2360. ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
  2361. TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
  2362. promoCode = tPromoCode;
  2363. if (tPromoCode == null || tPromoCode.getId() == null) {
  2364. //不存在
  2365. return JsonMessage.success("1");
  2366. }
  2367. Date lastUseDate = null;
  2368. if (promoCode != null) {
  2369. lastUseDate = promoCode.getLastUseDate();
  2370. }
  2371. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  2372. promoCode.setIsUse("2");
  2373. szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
  2374. //过期
  2375. return JsonMessage.success("4");
  2376. }
  2377. if (promoCode.getId() == null) {
  2378. //不存在
  2379. return JsonMessage.success("1");
  2380. }
  2381. if (promoCode.getIsUse().equals("1")) {
  2382. //被使用
  2383. return JsonMessage.success("2");
  2384. }
  2385. if (!promoCode.getAdminId().equals("1")) {
  2386. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  2387. } else {
  2388. //不是本机
  2389. return JsonMessage.success("3");
  2390. }
  2391. }
  2392. if (promoCode.getDiscount() == null) {
  2393. //旧优惠码
  2394. return JsonMessage.success("0");
  2395. }
  2396. // if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
  2397. // //0折
  2398. // return JsonMessage.success("0");
  2399. // }
  2400. promoCodeList.add(promoCode);
  2401. }
  2402. }
  2403. }
  2404. String[] products = key.split("-");
  2405. String iceCreamName = products[0];
  2406. String num = products[1];
  2407. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), iceCreamName));
  2408. if (product == null) {
  2409. return JsonMessage.error("找不到商品");
  2410. }
  2411. productNo = product.getNo();
  2412. BigDecimal productPrice = product.getRmbPrice();
  2413. // 如果加了果酱或者小料
  2414. if (products.length > 2) {
  2415. // 商品数
  2416. num = products[2];
  2417. // 加料
  2418. String[] charge = products[1].split(",");
  2419. String tempName = "(";
  2420. for (String s : charge) {
  2421. TProduct product1 = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), s));
  2422. if (product1 == null) {
  2423. return JsonMessage.error("找不到商品");
  2424. }
  2425. tempName = tempName + s + "、";
  2426. productPrice = productPrice.add(product1.getRmbPrice());
  2427. }
  2428. tempName = tempName.substring(0, tempName.length() - 1) + ")";
  2429. iceCreamName += tempName;
  2430. }
  2431. productMap.put(iceCreamName + "-" + productPrice, Integer.valueOf(num));
  2432. productNumber += Integer.valueOf(num);
  2433. productName.append(iceCreamName).append("x").append(num).append(",");
  2434. //确定价格,然后叠加
  2435. note.append(iceCreamName).append("-").append(product.getNo()).append(":");
  2436. if (promoCodeList.size() > 0) {
  2437. //有优惠码
  2438. BigDecimal onePrice = new BigDecimal("0.00");
  2439. Map<BigDecimal, Integer> priceMap = new HashMap<>();
  2440. int i;
  2441. for (i = 0; i < promoCodeList.size(); i++) {
  2442. BigDecimal discount = BigDecimal.valueOf(promoCodeList.get(i).getDiscount()).setScale(2, RoundingMode.HALF_DOWN);
  2443. BigDecimal price1 = new BigDecimal(0.0);
  2444. TPromoCode tPromoCode = promoCodeList.get(i);
  2445. if (StringUtils.isNotEmpty(tPromoCode.getType()) && tPromoCode.getType().equals("1")) {
  2446. if (productPrice.compareTo(discount) > 0) {
  2447. // 如果 price 大于 discount,从 price 中减去 discount
  2448. price1 = productPrice.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
  2449. } else {
  2450. // 如果 price 小于等于 discount,将 price 设置为 0
  2451. price1 = BigDecimal.ZERO;
  2452. }
  2453. } else {
  2454. if (tPromoCode.getDiscount() == 0) {
  2455. price1 = BigDecimal.ZERO;
  2456. } else {
  2457. price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  2458. }
  2459. }
  2460. // BigDecimal price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  2461. price = price.add(price1);
  2462. onePrice = onePrice.add(price1);
  2463. }
  2464. if (i < Integer.valueOf(num)) {
  2465. int a = Integer.valueOf(num) - i;
  2466. BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
  2467. price = price.add(price2);
  2468. onePrice = onePrice.add(price2);
  2469. }
  2470. note.append(onePrice).append("-").append(num).append(",");
  2471. } else {
  2472. //1,type=0,原始设定,没有第二件半价
  2473. int a = Integer.valueOf(num);
  2474. BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
  2475. price = price.add(price2);
  2476. note.append(price2).append("-").append(num).append(",");
  2477. }
  2478. }
  2479. } else {
  2480. //2,type=1,第二件半价
  2481. //2.1 判定是否有第二件,有多少个第二件半价
  2482. for (String key : productNameMap.keySet()) {
  2483. String[] products = key.split("-");
  2484. String iceCreamName = products[0];
  2485. String num = products[1];
  2486. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), iceCreamName));
  2487. if (product == null) {
  2488. return JsonMessage.error("找不到商品");
  2489. }
  2490. productNo = product.getNo();
  2491. BigDecimal productPrice = product.getRmbPrice();
  2492. // 如果加了果酱或者小料
  2493. if (products.length > 2) {
  2494. // 商品数
  2495. num = products[2];
  2496. // 加料
  2497. String[] charge = products[1].split(",");
  2498. String tempName = "(";
  2499. for (String s : charge) {
  2500. TProduct product1 = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), s));
  2501. if (product1 == null) {
  2502. return JsonMessage.error("找不到商品");
  2503. }
  2504. tempName = tempName + s + "、";
  2505. productPrice = productPrice.add(product1.getRmbPrice());
  2506. }
  2507. tempName = tempName.substring(0, tempName.length() - 1) + ")";
  2508. iceCreamName += tempName;
  2509. }
  2510. productMap.put(iceCreamName + "-" + productPrice, Integer.valueOf(num));
  2511. productName.append(iceCreamName).append("x").append(num).append(",");
  2512. note.append(iceCreamName).append("-").append(product.getNo()).append(":");
  2513. switch (num) {
  2514. case "1":
  2515. //1个 0个半价
  2516. price = price.add(productPrice);
  2517. note.append(price).append("-").append(num).append(",");
  2518. break;
  2519. case "2":
  2520. //2个 1个半价
  2521. price = price.add(productPrice);
  2522. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  2523. note.append(price).append("-").append(num).append(",");
  2524. break;
  2525. case "3":
  2526. //3个 1个半价
  2527. price = price.add(productPrice);
  2528. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  2529. price = price.add(productPrice);
  2530. note.append(price).append("-").append(num).append(",");
  2531. break;
  2532. case "4":
  2533. //4个 2个半价
  2534. price = price.add(productPrice);
  2535. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  2536. price = price.add(productPrice);
  2537. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  2538. note.append(price).append("-").append(num).append(",");
  2539. break;
  2540. case "5":
  2541. //5个 2个半价
  2542. price = price.add(productPrice);
  2543. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  2544. price = price.add(productPrice);
  2545. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  2546. price = price.add(productPrice);
  2547. note.append(price).append("-").append(num).append(",");
  2548. break;
  2549. }
  2550. }
  2551. }
  2552. if (equipment == null) {
  2553. return JsonMessage.error("找不到设备");
  2554. }
  2555. Long equipmentId = equipment.getId();
  2556. //查找商品
  2557. if (BigDecimal.ZERO.compareTo(price) == 0) {
  2558. return JsonMessage.success("0");
  2559. }
  2560. if (BigDecimal.ZERO.compareTo(price) > 0) {
  2561. return JsonMessage.error("商品价格异常");
  2562. }
  2563. Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
  2564. String sn1 = orderService.initSn(client6);
  2565. String sn2 = orderService.initSn(client6);
  2566. // 获取关联设备的分销
  2567. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  2568. if (proportion == null || proportion.getId() == null) {
  2569. return JsonMessage.error("设备商家未完成分销设置");
  2570. }
  2571. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  2572. if (admin == null) {
  2573. return JsonMessage.error("找不到设备商家");
  2574. }
  2575. // 支付方式:0或null为汇聚,1为汇付支付
  2576. String payPlatform = admin.getPayPlatform();
  2577. String companyType = admin.getCompanyType();
  2578. // 汇聚分账参数
  2579. JSONArray altInfo = new JSONArray();
  2580. // 汇付分账明细参数
  2581. JSONObject acctSplitBunch = new JSONObject();
  2582. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  2583. acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
  2584. if (!(acctSplitBunch.size() > 0)) {
  2585. return JsonMessage.error("设备商家未注册结算账号");
  2586. }
  2587. } else {
  2588. altInfo = getAltInfo(proportion, price);
  2589. if (!(altInfo.size() > 0)) {
  2590. return JsonMessage.error("设备商家未注册结算账号");
  2591. }
  2592. }
  2593. String orderNo1 = sn1;
  2594. String orderNo2 = sn2;
  2595. BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
  2596. String productDesc = "";
  2597. String commonParameter = "";
  2598. String returnUrl = null;
  2599. String notifyUrl = JoinpayConstant.Notify_Url;
  2600. String isShowPic = "1";
  2601. String openId = null;
  2602. String authCode = null;
  2603. String appid = null;
  2604. String transactionModel = null;
  2605. String tradeMerchantNo = admin.getTradeMerchantNo();
  2606. String buyerId = null;
  2607. String isAlt = "1";
  2608. String altType = "11";
  2609. String altUrl = null;
  2610. BigDecimal marketingAmount = null;
  2611. String frpCode1 = "WEIXIN_NATIVE";
  2612. String frpCode2 = "ALIPAY_NATIVE";
  2613. TOrder order = new TOrder();
  2614. order.setId(IDGenerator.orderID());
  2615. order.setCreateDate(new Date());
  2616. order.setModifyDate(new Date());
  2617. order.setAdminId(admin.getId());
  2618. order.setSn(sn1);
  2619. // 去掉后面的逗号
  2620. order.setProductNo(productNo);
  2621. if (productNumber == 1) {
  2622. productName.delete(productName.length() - 3, productName.length());
  2623. } else {
  2624. productName.deleteCharAt(productName.length() - 1);
  2625. }
  2626. order.setProductName(productName.toString());
  2627. order.setPrice(price);
  2628. order.setClientId(equipment.getClientId());
  2629. order.setEquipmentId(equipmentId);
  2630. order.setFrpCode(frpCode1);
  2631. order.setAltInfo(altInfo.toString());
  2632. order.setProductNumber(productNumber);
  2633. order.setStatus(0);
  2634. order.setType(admin.getType());
  2635. order.setCompanyType(companyType);
  2636. order.setMachineType(equipment.getMachineType());
  2637. if (admin.getType() == 0) {
  2638. order.setAdminProportion(proportion.getProportion());
  2639. order.setAgencyProportion(proportion.getAgencyProportion());
  2640. order.setAgencyId(proportion.getAgencyId());
  2641. }
  2642. if (admin.getType() == 1) {
  2643. order.setAdminProportion(proportion.getProportion());
  2644. order.setAgencyProportion(proportion.getAgencyProportion());
  2645. order.setAgencyId(proportion.getAgencyId());
  2646. order.setMerchantProportion(proportion.getMerchantProportion());
  2647. order.setMerchantId(proportion.getMerchantId());
  2648. }
  2649. if (admin.getType() == 2) {
  2650. order.setAdminProportion(proportion.getProportion());
  2651. order.setAgencyProportion(proportion.getAgencyProportion());
  2652. order.setAgencyId(proportion.getAgencyId());
  2653. order.setMerchantProportion(proportion.getMerchantProportion());
  2654. order.setMerchantId(proportion.getMerchantId());
  2655. order.setPersonageProportion(proportion.getPersonageProportion());
  2656. order.setPersonageId(proportion.getPersonageId());
  2657. }
  2658. order.setPayPlatform(payPlatform);
  2659. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  2660. order.setIsSettlement("0");
  2661. }
  2662. order.setNote(note.toString());
  2663. TOrder order2 = new TOrder();
  2664. order2.setId(IDGenerator.orderID());
  2665. order2.setCreateDate(new Date());
  2666. order2.setModifyDate(new Date());
  2667. order2.setAdminId(admin.getId());
  2668. order2.setSn(sn2);
  2669. order2.setProductName(productName.toString());
  2670. order2.setProductNo(productNo);
  2671. order2.setPrice(price);
  2672. order2.setClientId(equipment.getClientId());
  2673. order2.setEquipmentId(equipmentId);
  2674. order2.setFrpCode(frpCode2);
  2675. order2.setAltInfo(altInfo.toString());
  2676. order2.setStatus(0);
  2677. order2.setProductNumber(productNumber);
  2678. order2.setType(admin.getType());
  2679. order2.setCompanyType(companyType);
  2680. order2.setMachineType(equipment.getMachineType());
  2681. if (admin.getType() == 0) {
  2682. order2.setAdminProportion(proportion.getProportion());
  2683. order2.setAgencyProportion(proportion.getAgencyProportion());
  2684. order2.setAgencyId(proportion.getAgencyId());
  2685. }
  2686. if (admin.getType() == 1) {
  2687. order2.setAdminProportion(proportion.getProportion());
  2688. order2.setAgencyProportion(proportion.getAgencyProportion());
  2689. order2.setAgencyId(proportion.getAgencyId());
  2690. order2.setMerchantProportion(proportion.getMerchantProportion());
  2691. order2.setMerchantId(proportion.getMerchantId());
  2692. }
  2693. if (admin.getType() == 2) {
  2694. order2.setAdminProportion(proportion.getProportion());
  2695. order2.setAgencyProportion(proportion.getAgencyProportion());
  2696. order2.setAgencyId(proportion.getAgencyId());
  2697. order2.setMerchantProportion(proportion.getMerchantProportion());
  2698. order2.setMerchantId(proportion.getMerchantId());
  2699. order2.setPersonageProportion(proportion.getPersonageProportion());
  2700. order2.setPersonageId(proportion.getPersonageId());
  2701. }
  2702. order2.setPayPlatform(payPlatform);
  2703. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  2704. order2.setIsSettlement("0");
  2705. }
  2706. order2.setNote(note.toString());
  2707. // 订单明细表
  2708. TOrderDetails orderDetails = new TOrderDetails();
  2709. orderDetails.setAdminId(admin.getId());
  2710. orderDetails.setEquipmentId(equipmentId);
  2711. orderDetails.setCreateDate(new Date());
  2712. orderDetails.setCompanyType(companyType);
  2713. orderDetails.setRefundStatus("0");
  2714. orderDetails.setMachineType(equipment.getMachineType());
  2715. String productName1 = "雪糕x" + productNumber + "-" + equipment.getName() + "-" + client6;
  2716. Map<String, String> map = new HashMap<>();
  2717. String[] products = order.getNote().split(",");
  2718. for (String product : products) {
  2719. String[] parts = product.split(":");
  2720. // 商品名称-商品编号
  2721. String key = parts[0];
  2722. // 商品单价-商品数量
  2723. String value = parts[1];
  2724. map.put(key, value);
  2725. }
  2726. String result = null;
  2727. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  2728. // 汇付分账参数
  2729. order.setAcctSplitBunch(acctSplitBunch.toString());
  2730. order2.setAcctSplitBunch(acctSplitBunch.toString());
  2731. //添加到汇付临时表,微信
  2732. // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
  2733. // String[] ignoreProperties = {"id"};
  2734. // String id = HuifuUtils.inithuifuTempId();
  2735. // tHuifuTempOrder.setId(id);
  2736. // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
  2737. // huifuTempOrderService.save(tHuifuTempOrder);
  2738. // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  2739. // result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
  2740. // } else {
  2741. // result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
  2742. // }
  2743. String result1 = "";
  2744. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  2745. result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  2746. } else {
  2747. result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  2748. }
  2749. try {
  2750. result1 = URLEncoder.encode(result1, "UTF-8");
  2751. } catch (UnsupportedEncodingException e) {
  2752. e.printStackTrace();
  2753. }
  2754. // 支付宝
  2755. try {
  2756. result = huifuMchService.uniPay(
  2757. sn2, amount, productName1, productDesc,
  2758. notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
  2759. );
  2760. } catch (Exception e) {
  2761. e.printStackTrace();
  2762. return JsonMessage.error("申请支付失败");
  2763. }
  2764. if (StrUtil.isEmpty(result)) {
  2765. return JsonMessage.error("找不到支付图片");
  2766. }
  2767. // 汇聚支付支付申请返回支付二维码图片
  2768. String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
  2769. String qrcode = toQrcode(code1);
  2770. JSONObject kindData = new JSONObject();
  2771. kindData.put("sn", sn1 + "-" + sn2);
  2772. kindData.put("rd_Pic", qrcode);
  2773. for (String key : map.keySet()) {
  2774. String value = map.get(key);
  2775. String[] GoodsInfo = key.split("-");
  2776. String[] GoodsValue = value.split("-");
  2777. orderDetails.setId(HuifuUtils.initDetailsId());
  2778. orderDetails.setProductName(GoodsInfo[0]);
  2779. orderDetails.setProductNo(GoodsInfo[1]);
  2780. orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
  2781. orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
  2782. orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
  2783. orderDetails.setId(HuifuUtils.initDetailsId());
  2784. orderDetails.setOrderSn(sn1);
  2785. orderDetailsService.save(orderDetails);
  2786. orderDetails.setId(HuifuUtils.initDetailsId());
  2787. orderDetails.setOrderSn(sn2);
  2788. orderDetailsService.save(orderDetails);
  2789. }
  2790. orderService.save(order);
  2791. orderService.save(order2);
  2792. return JsonMessage.success(kindData.toString());
  2793. } else {
  2794. try {
  2795. result = joinpayMchService.uniPay(
  2796. orderNo1, amount, productName1, productDesc,
  2797. commonParameter, returnUrl, notifyUrl, frpCode1,
  2798. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  2799. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  2800. );
  2801. } catch (UnsupportedEncodingException e) {
  2802. e.printStackTrace();
  2803. return JsonMessage.error("申请支付失败");
  2804. }
  2805. JSONObject resultJson = JSONObject.parseObject(result);
  2806. String rc_Result1 = resultJson.getString("rc_Result");
  2807. String result1 = null;
  2808. try {
  2809. result1 = joinpayMchService.uniPay(
  2810. orderNo2, amount, productName1, productDesc,
  2811. commonParameter, returnUrl, notifyUrl, frpCode2,
  2812. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  2813. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  2814. );
  2815. } catch (UnsupportedEncodingException e) {
  2816. e.printStackTrace();
  2817. return JsonMessage.error("申请支付失败");
  2818. }
  2819. JSONObject resultJson1 = JSONObject.parseObject(result1);
  2820. String rc_Result2 = resultJson1.getString("rc_Result");
  2821. // 汇聚支付支付申请返回支付二维码图片
  2822. String code1 = "http://app.sunzee.com.cn/" + "/api/order/aliPay.htm?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
  2823. String rd_Pic = toQrcode(code1);
  2824. JSONObject kindData = new JSONObject();
  2825. kindData.put("sn", sn1 + "-" + sn2);
  2826. kindData.put("rd_Pic", rd_Pic);
  2827. // 添加到订单明细表
  2828. for (String key : map.keySet()) {
  2829. // key:"玫瑰精灵-A01",value:"0.50-1"
  2830. String value = map.get(key);
  2831. String[] GoodsInfo = key.split("-");
  2832. String[] GoodsValue = value.split("-");
  2833. orderDetails.setId(HuifuUtils.initDetailsId());
  2834. orderDetails.setProductName(GoodsInfo[0]);
  2835. orderDetails.setProductNo(GoodsInfo[1]);
  2836. orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
  2837. orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
  2838. orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
  2839. orderDetails.setId(HuifuUtils.initDetailsId());
  2840. orderDetails.setOrderSn(sn1);
  2841. orderDetailsService.save(orderDetails);
  2842. orderDetails.setId(HuifuUtils.initDetailsId());
  2843. orderDetails.setOrderSn(sn2);
  2844. orderDetailsService.save(orderDetails);
  2845. }
  2846. orderService.save(order);
  2847. orderService.save(order2);
  2848. return JsonMessage.success(kindData.toString());
  2849. }
  2850. }
  2851. @ApiOperation(value = "汇付:获取code回调跳转到支付页面")
  2852. @GetMapping("/callback")
  2853. public void oauthCallback(HttpServletRequest request, HttpServletResponse response) throws IOException {
  2854. // 获取code
  2855. String code = request.getParameter("code");
  2856. String id = request.getParameter("state");
  2857. LambdaQueryWrapper<THuifuTempOrder> wrapper = new LambdaQueryWrapper<>();
  2858. wrapper.eq(THuifuTempOrder::getId, id);
  2859. THuifuTempOrder huifuTempOrder = huifuTempOrderService.getOne(wrapper);
  2860. // 从临时表中获取订单信息
  2861. String result = null;
  2862. if (huifuTempOrder != null) {
  2863. String companyType = huifuTempOrder.getCompanyType();
  2864. if (huifuTempOrder.getStatus() == 1) {
  2865. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  2866. result = HuifuConstant.SC_JUMP_URL + "/#/popPayment?status=1";
  2867. } else {
  2868. result = HuifuConstant.SZ_JUMP_URL + "/#/popPayment?status=1";
  2869. }
  2870. } else {
  2871. String openid;
  2872. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  2873. // 获取openid
  2874. try {
  2875. String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
  2876. "appid=" + HuifuConstant.SC_WX_SUB_APP_ID +
  2877. "&secret=" + HuifuConstant.SC_WX_APP_SECRET +
  2878. "&code=" + code +
  2879. "&grant_type=authorization_code";
  2880. log.info("获取openID:{}", openUrl);
  2881. org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
  2882. log.info("获取openID结果:{}", jsonObject);
  2883. openid = jsonObject.getString("openid");
  2884. result = huifuMchService.wetchatPay(huifuTempOrder, openid);
  2885. } catch (Exception e) {
  2886. e.printStackTrace();
  2887. }
  2888. } else {
  2889. // 获取openid
  2890. try {
  2891. String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
  2892. "appid=" + HuifuConstant.SZ_WX_SUB_APP_ID +
  2893. "&secret=" + HuifuConstant.SZ_WX_APP_SECRET +
  2894. "&code=" + code +
  2895. "&grant_type=authorization_code";
  2896. log.info("获取openID:{}", openUrl);
  2897. org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
  2898. log.info("获取openID结果:{}", jsonObject);
  2899. openid = jsonObject.getString("openid");
  2900. result = huifuMchService.wetchatPay(huifuTempOrder, openid);
  2901. } catch (Exception e) {
  2902. e.printStackTrace();
  2903. }
  2904. }
  2905. }
  2906. }
  2907. log.info("支付链接:{}", result);
  2908. response.sendRedirect(result);
  2909. }
  2910. /**
  2911. * 支付成功回调 汇付
  2912. */
  2913. @RequestMapping(value = "/huifuNotify", method = RequestMethod.POST)
  2914. @ResponseBody
  2915. public String huifuNotify(HttpServletRequest request) {
  2916. String respData = request.getParameter("resp_data");
  2917. try {
  2918. // 验签请参sign
  2919. String sign = request.getParameter("sign");
  2920. // 使用汇付公钥验签
  2921. if (!RSAUtil.verify(respData, HuifuConstant.HUIFU_PUBLIC_KEY, sign)) {
  2922. // 验签失败处理
  2923. log.info("验签失败");
  2924. return "";
  2925. }
  2926. JSONObject data = JSONObject.parseObject(respData);
  2927. String transStat = data.getString("trans_stat");
  2928. // 订单号
  2929. String sn = data.getString("req_seq_id");
  2930. if (StrUtil.hasEmpty(sn)) {
  2931. // return "R.fail(ResponseCodesEnum.A0001,"订单号为空!")";
  2932. log.info("返回参数订单编号为空");
  2933. return "";
  2934. }
  2935. // 查到指定订单
  2936. LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
  2937. wrapper.eq(TOrder::getSn, sn);
  2938. wrapper.eq(TOrder::getStatus, 0);
  2939. TOrder order = orderService.getOne(wrapper);
  2940. if (order == null) {
  2941. log.info("找不到订单");
  2942. return "";
  2943. }
  2944. if (HuifuConstant.TRANS_STAT_S.equals(transStat)) {
  2945. // 查到对应订单明细表
  2946. LambdaQueryWrapper<TOrderDetails> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  2947. lambdaQueryWrapper.eq(TOrderDetails::getOrderSn, sn);
  2948. List<TOrderDetails> orderDetails = orderDetailsService.list(lambdaQueryWrapper);
  2949. for (TOrderDetails orderDetail : orderDetails) {
  2950. // 修改状态订单明细状态
  2951. orderDetail.setRefundStatus("1");
  2952. orderDetailsService.updateById(orderDetail);
  2953. }
  2954. // 已支付
  2955. order.setStatus(1);
  2956. // 支付平台产生的全局流水号:hf_seq_id
  2957. // String hfSeqId = data.getString("hf_seq_id");
  2958. // 支付平台产生的全局流水号:party_order_id
  2959. String partyOrderId = data.getString("party_order_id");
  2960. order.setTrxNo(partyOrderId);
  2961. // 支付时间,格式:YYYY-MM-DD HH:mm:ss
  2962. String payTime = data.getString("end_time");
  2963. SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMddHHmmss");
  2964. SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2965. // 临时表修改支付状态
  2966. String id = data.getString("remark");
  2967. if (StrUtil.isNotEmpty(id)) {
  2968. LambdaQueryWrapper<THuifuTempOrder> queryWrapper = new LambdaQueryWrapper<>();
  2969. queryWrapper.eq(THuifuTempOrder::getId, id);
  2970. THuifuTempOrder huifuTempOrder = huifuTempOrderService.getOne(queryWrapper);
  2971. huifuTempOrder.setStatus(1);
  2972. huifuTempOrderService.updateById(huifuTempOrder);
  2973. }
  2974. try {
  2975. Date date = inputFormat.parse(URLDecoder.decode(payTime, "UTF-8"));
  2976. String formattedDate = outputFormat.format(date);
  2977. Date payDate = outputFormat.parse(URLDecoder.decode(formattedDate, "UTF-8"));
  2978. order.setPayDate(payDate);
  2979. } catch (ParseException e) {
  2980. e.printStackTrace();
  2981. } catch (UnsupportedEncodingException e) {
  2982. e.printStackTrace();
  2983. }
  2984. // 修改订单信息
  2985. orderService.updateById(order);
  2986. //
  2987. JSONObject kindData = new JSONObject();
  2988. kindData.put("sn", order.getSn());
  2989. kindData.put("productName", order.getProductName());
  2990. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  2991. if (order.getFrpCode().equals("WEIXIN_XCX")) {
  2992. JSONObject kindData1 = new JSONObject();
  2993. kindData1.put("sn", order.getSn());
  2994. kindData1.put("productDesc", order.getProductDesc());
  2995. String s = order.getId().toString();
  2996. if (s.length() > 6) {
  2997. s = s.substring(s.length() - 6, s.length());
  2998. }
  2999. kindData1.put("mealCode", s);
  3000. order.setOrderStatus("-1");
  3001. equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("cardPayXCX", kindData1.toString()).toString());
  3002. if (StringUtils.isNotEmpty(equipment.getApkVersion())) {
  3003. //发送两次mq
  3004. if (equipment.getApkVersion().equals("1.0.131-jz11") || equipment.getApkVersion().equals("1.0.131-jz12") || equipment.getApkVersion().equals("1.0.131-jz13") || equipment.getApkVersion().equals("1.0.131-jz14") || equipment.getApkVersion().equals("1.0.131-jz15")) {
  3005. sendMqTwo(equipment.getClientId(), kindData1.toString());
  3006. }
  3007. }
  3008. TSzsmWx szsmWx = szsmWxService.getById(order.getWxId());
  3009. BigDecimal integral = szsmWx.getIntegral();
  3010. if (integral != null) {
  3011. integral = order.getPrice().add(integral);
  3012. } else {
  3013. integral = order.getPrice();
  3014. }
  3015. szsmWx.setIntegral(integral);
  3016. szsmWxService.updateById(szsmWx);
  3017. if (StringUtils.isNotEmpty(order.getCoupons())) {
  3018. String coupons = order.getCoupons();
  3019. coupons = coupons.substring(1, coupons.length() - 1);
  3020. List<String> list1 = Arrays.asList(coupons);
  3021. if (list1.size() > 0) {
  3022. for (String code : list1) {
  3023. szwlFeign.useYHJ(code, String.valueOf(order.getAdminId()), order.getClientId());
  3024. }
  3025. }
  3026. }
  3027. } else {
  3028. if (!order.getIsNotified().equals("1")) {
  3029. String paySuccess = equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
  3030. if (paySuccess.equals("success")) {
  3031. order.setIsNotified("1");
  3032. // 推送微信订单
  3033. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
  3034. // 判断是否开启订单推送功能
  3035. if (admin != null && StringUtils.isNotEmpty(admin.getOrderNotice()) && admin.getOrderNotice().equals("1")) {
  3036. String openId = R.getDataIfSuccess(szwlFeign.getOpenId(order.getAdminId()));
  3037. // 获取openId
  3038. if (StringUtils.isNotEmpty(openId)) {
  3039. orderService.newSendWechatMessage(openId, equipment, order, admin.getCompanyType());
  3040. }
  3041. }
  3042. }
  3043. }
  3044. }
  3045. orderService.updateById(order);
  3046. try {
  3047. if (order.getProductNumber() == null || order.getProductNumber() == 0) {
  3048. order.setProductNumber(1);
  3049. }
  3050. orderFeign.saveToEs(order);
  3051. } catch (Exception e) {
  3052. e.printStackTrace();
  3053. }
  3054. try {
  3055. LambdaQueryWrapper<TOrderTask> queryWrapper = new LambdaQueryWrapper<>();
  3056. queryWrapper.eq(TOrderTask::getSn, sn);
  3057. TOrderTask oldOrderTask = orderTaskService.getOne(queryWrapper);
  3058. if (oldOrderTask == null) {
  3059. TOrderTask orderTask = new TOrderTask();
  3060. BeanUtils.copyPropertiesIgnoreNull(order, orderTask, true);
  3061. orderTask.setAgencyId(order.getId());
  3062. orderTaskService.save(orderTask);
  3063. }
  3064. } catch (Exception e) {
  3065. e.printStackTrace();
  3066. }
  3067. //传送数据
  3068. // sentJingZhun(order);
  3069. // return R.ok("支付成功");
  3070. log.info("支付成功");
  3071. } else {
  3072. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3073. String gtClientId = equipment.getGtClientId();
  3074. JSONObject kindData = new JSONObject();
  3075. kindData.put("sn", order.getSn());
  3076. if (!order.getIsNotified().equals("2")) {
  3077. String payFail = equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_faile", kindData.toString()).toString());
  3078. if (payFail.equals("success")) {
  3079. order.setIsNotified("2");
  3080. }
  3081. }
  3082. order.setNote(gtClientId + "支付失败");
  3083. orderService.updateById(order);
  3084. log.info("支付失败");
  3085. }
  3086. return "RECV_ORD_ID_" + sn;
  3087. } catch (Exception e) {
  3088. log.info("异步回调开始,参数,request={}", respData, e);
  3089. }
  3090. return "";
  3091. }
  3092. /**
  3093. * 支付成功回调 汇聚
  3094. *
  3095. * @return
  3096. */
  3097. @RequestMapping(value = "/notify", method = RequestMethod.GET)
  3098. @ResponseBody
  3099. public String notify(HttpServletRequest request) {
  3100. String r6_Status = request.getParameter("r6_Status");
  3101. // 订单号
  3102. String sn = request.getParameter("r2_OrderNo");
  3103. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  3104. query.eq(TOrder::getSn, sn);
  3105. query.eq(TOrder::getStatus, 0);
  3106. if (StringUtils.isEmpty(sn)) {
  3107. return "error";
  3108. }
  3109. TOrder order = orderService.getOne(query);
  3110. if (order == null) {
  3111. return "error";
  3112. }
  3113. if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
  3114. // 查到对应订单明细表
  3115. LambdaQueryWrapper<TOrderDetails> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  3116. lambdaQueryWrapper.eq(TOrderDetails::getOrderSn, sn);
  3117. List<TOrderDetails> orderDetails = orderDetailsService.list(lambdaQueryWrapper);
  3118. for (TOrderDetails orderDetail : orderDetails) {
  3119. // 修改状态订单明细状态
  3120. orderDetail.setRefundStatus("1");
  3121. orderDetailsService.updateById(orderDetail);
  3122. }
  3123. // 已支付
  3124. order.setStatus(1);
  3125. // 支付平台产生的流水号
  3126. String r7_TrxNo = request.getParameter("r7_TrxNo");
  3127. order.setTrxNo(r7_TrxNo);
  3128. // 格式:YYYY-MM-DD HH:mm:ss
  3129. String ra_PayTime = request.getParameter("ra_PayTime");
  3130. try {
  3131. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  3132. Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
  3133. order.setPayDate(payDate);
  3134. } catch (ParseException e) {
  3135. e.printStackTrace();
  3136. } catch (UnsupportedEncodingException e) {
  3137. e.printStackTrace();
  3138. }
  3139. orderService.updateById(order);
  3140. JSONObject kindData = new JSONObject();
  3141. kindData.put("sn", order.getSn());
  3142. kindData.put("productName", order.getProductName());
  3143. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3144. if (order.getFrpCode().equals("WEIXIN_XCX")) {
  3145. JSONObject kindData1 = new JSONObject();
  3146. kindData1.put("sn", order.getSn());
  3147. kindData1.put("productDesc", order.getProductDesc());
  3148. String s = order.getId().toString();
  3149. if (s.length() > 6) {
  3150. s = s.substring(s.length() - 6, s.length());
  3151. }
  3152. kindData1.put("mealCode", s);
  3153. order.setOrderStatus("-1");
  3154. equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("cardPayXCX", kindData1.toString()).toString());
  3155. if (StringUtils.isNotEmpty(equipment.getApkVersion())) {
  3156. //发送两次mq
  3157. if (equipment.getApkVersion().equals("1.0.131-jz11") || equipment.getApkVersion().equals("1.0.131-jz12") || equipment.getApkVersion().equals("1.0.131-jz13") || equipment.getApkVersion().equals("1.0.131-jz14") || equipment.getApkVersion().equals("1.0.131-jz15")) {
  3158. sendMqTwo(equipment.getClientId(), kindData1.toString());
  3159. }
  3160. }
  3161. TSzsmWx szsmWx = szsmWxService.getById(order.getWxId());
  3162. BigDecimal integral = szsmWx.getIntegral();
  3163. if (integral != null) {
  3164. integral = order.getPrice().add(integral);
  3165. } else {
  3166. integral = order.getPrice();
  3167. }
  3168. szsmWx.setIntegral(integral);
  3169. szsmWxService.updateById(szsmWx);
  3170. if (StringUtils.isNotEmpty(order.getCoupons())) {
  3171. String coupons = order.getCoupons();
  3172. coupons = coupons.substring(1, coupons.length() - 1);
  3173. List<String> list1 = Arrays.asList(coupons);
  3174. if (list1.size() > 0) {
  3175. for (String code : list1) {
  3176. szwlFeign.useYHJ(code, String.valueOf(order.getAdminId()), order.getClientId());
  3177. }
  3178. }
  3179. }
  3180. } else {
  3181. if (!order.getIsNotified().equals("1")) {
  3182. String paySuccess = equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
  3183. if (paySuccess.equals("success")) {
  3184. order.setIsNotified("1");
  3185. }
  3186. // 推送微信订单
  3187. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
  3188. // 判断是否开启订单推送功能
  3189. if (admin != null && StringUtils.isNotEmpty(admin.getOrderNotice()) && admin.getOrderNotice().equals("1")) {
  3190. String openId = R.getDataIfSuccess(szwlFeign.getOpenId(order.getAdminId()));
  3191. // 获取openId
  3192. if (StringUtils.isNotEmpty(openId)) {
  3193. orderService.newSendWechatMessage(openId, equipment, order, admin.getCompanyType());
  3194. }
  3195. }
  3196. }
  3197. }
  3198. orderService.updateById(order);
  3199. try {
  3200. if (order.getProductNumber() == null || order.getProductNumber() == 0) {
  3201. order.setProductNumber(1);
  3202. }
  3203. orderFeign.saveToEs(order);
  3204. } catch (Exception e) {
  3205. e.printStackTrace();
  3206. }
  3207. // try {
  3208. LambdaQueryWrapper<TOrderTask> queryWrapper = new LambdaQueryWrapper<>();
  3209. queryWrapper.eq(TOrderTask::getSn, sn);
  3210. TOrderTask oldOrderTask = orderTaskService.getOne(queryWrapper);
  3211. if (oldOrderTask == null) {
  3212. TOrderTask orderTask = new TOrderTask();
  3213. BeanUtils.copyPropertiesIgnoreNull(order, orderTask, true);
  3214. orderTask.setAgencyId(order.getId());
  3215. orderTaskService.save(orderTask);
  3216. }
  3217. //传送数据
  3218. sentJingZhun(order);
  3219. return "success";
  3220. } else {
  3221. TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3222. String gtClientId = byClientId.getGtClientId();
  3223. JSONObject kindData = new JSONObject();
  3224. kindData.put("sn", order.getSn());
  3225. if (!order.getIsNotified().equals("2")) {
  3226. String payFail = equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_faile", kindData.toString()).toString());
  3227. if (payFail.equals("success")) {
  3228. order.setIsNotified("2");
  3229. }
  3230. }
  3231. order.setNote(gtClientId + "支付失败");
  3232. orderService.updateById(order);
  3233. return "success";
  3234. }
  3235. }
  3236. //发送两次mq
  3237. private void sendMqTwo(String clientId, String kind) {
  3238. // 定时任务1
  3239. TimerTask timerTask = new TimerTask() {
  3240. @Override
  3241. public void run() {
  3242. equipmentService.sentMessage(clientId, PushUtils.buildJson("cardPayXCX", kind).toString());
  3243. System.out.println("运行定时任务1:" + clientId);
  3244. }
  3245. };
  3246. // 定时任务2
  3247. TimerTask timerTask1 = new TimerTask() {
  3248. @Override
  3249. public void run() {
  3250. equipmentService.sentMessage(clientId, PushUtils.buildJson("cardPayXCX", kind).toString());
  3251. System.out.println("运行定时任务1:" + clientId);
  3252. }
  3253. };
  3254. // 计时器
  3255. Timer timer = new Timer();
  3256. // 添加执行任务(延迟 5s 执行)
  3257. timer.schedule(timerTask, 5000);
  3258. Timer timer1 = new Timer();
  3259. timer1.schedule(timerTask1, 10000);
  3260. }
  3261. private void sentJingZhun(TOrder order) {
  3262. order = orderService.getById(order.getId());
  3263. int i = 0;
  3264. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
  3265. String adminId = admin.getId().toString();
  3266. String relationAdminId = admin.getRelationAdminId();
  3267. if ((StringUtils.isNotEmpty(adminId) && (adminId.equals("372") || adminId.equals("639") || adminId.equals("238")))
  3268. || (StringUtils.isNotEmpty(relationAdminId) && relationAdminId.equals("372"))) {
  3269. //发送数据到鲸准
  3270. String url = "http://47.106.13.109:3000/api/listen";
  3271. Map<String, String> map = new HashMap<>();
  3272. map.put("clientId", order.getClientId());
  3273. map.put("price", String.valueOf(order.getPrice()));
  3274. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  3275. map.put("pay_date", sdf.format(order.getPayDate()));
  3276. if (order.getWxId() != null) {
  3277. //小程序下单
  3278. TSzsmWx szsmWx = szsmWxService.getById(order.getWxId());
  3279. map.put("sourceChannel", "1");
  3280. map.put("phone", szsmWx.getPhone());
  3281. if (order.getMarketingAmount() != null) {
  3282. map.put("amount", order.getMarketingAmount().toString());
  3283. } else {
  3284. map.put("amount", "0");
  3285. }
  3286. map.put("nickName", "1");
  3287. map.put("uninoId", szsmWx.getOpenId());
  3288. } else {
  3289. //机器下单
  3290. map.put("sourceChannel", "0");
  3291. map.put("phone", "");
  3292. map.put("amount", "0");
  3293. map.put("nickName", "");
  3294. map.put("uninoId", "");
  3295. }
  3296. TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3297. map.put("latitude", String.valueOf(byClientId.getLatitude()));
  3298. map.put("longitude", String.valueOf(byClientId.getLongitude()));
  3299. String data = JSON.toJSONString(map);
  3300. try {
  3301. String s = HttpClientSslUtils.doPost(url, data);
  3302. System.out.println("发送鲸准:" + s);
  3303. } catch (Exception e) {
  3304. e.printStackTrace();
  3305. }
  3306. }
  3307. }
  3308. /**
  3309. * 支付成功回调 杉德
  3310. *
  3311. * @return
  3312. */
  3313. @RequestMapping(value = "/shandeRefund", method = RequestMethod.GET)
  3314. @ResponseBody
  3315. public Object shandeRefund(HttpServletRequest request) {
  3316. //订单号
  3317. String order_no = request.getParameter("out_order_no");
  3318. //交易状态
  3319. String trade_status = request.getParameter("trade_status");
  3320. String r6_Status = request.getParameter("r6_Status");
  3321. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  3322. query.eq(TOrder::getSn, order_no);
  3323. if (StringUtils.isEmpty(order_no)) {
  3324. return "error";
  3325. }
  3326. List<TOrder> list = orderService.list(query);
  3327. TOrder order = new TOrder();
  3328. if (list.size() > 0) {
  3329. order = list.get(0);
  3330. }
  3331. if (trade_status.equals("SUCCESS")) {
  3332. // 已支付
  3333. order.setStatus(1);
  3334. // 支付平台产生的流水号
  3335. String bank_order_no = request.getParameter("bank_order_no");
  3336. order.setTrxNo(bank_order_no);
  3337. // 格式:YYYY-MM-DD HH:mm:ss
  3338. String pay_success_time = request.getParameter("pay_success_time");
  3339. try {
  3340. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
  3341. Date payDate = sdf.parse(URLDecoder.decode(pay_success_time, "UTF-8"));
  3342. order.setPayDate(payDate);
  3343. } catch (ParseException e) {
  3344. e.printStackTrace();
  3345. } catch (UnsupportedEncodingException e) {
  3346. e.printStackTrace();
  3347. }
  3348. orderService.updateById(order);
  3349. JSONObject kindData = new JSONObject();
  3350. kindData.put("sn", order.getSn());
  3351. kindData.put("productName", order.getProductName());
  3352. TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3353. String gtClientId = byClientId.getGtClientId();
  3354. equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
  3355. // PushUtils.push(gtClientId, "支付成功", "您的订单支付成功", PushUtils.buildJson("pay_success", kindData.toString()).toString());
  3356. order.setNote(gtClientId + "已推送");
  3357. try {
  3358. if (order.getProductNumber() == null || order.getProductNumber() == 0) {
  3359. order.setProductNumber(1);
  3360. }
  3361. esTOrderService.insertData(order);
  3362. orderFeign.saveToEs(order);
  3363. } catch (Exception e) {
  3364. e.printStackTrace();
  3365. }
  3366. //对金额表的当日数额进行修改
  3367. //1,获取商家的等级
  3368. BigDecimal price = order.getPrice();
  3369. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(byClientId.getAdminId())));
  3370. //获取分销 关联设备
  3371. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(byClientId.getId())));
  3372. Integer type = proportion.getType();
  3373. switch (type) {
  3374. case 0:
  3375. BigDecimal agencyProportion = proportion.getProportion();
  3376. // 代理分销获得利润
  3377. BigDecimal agencyPrice = price.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  3378. //修改金额表的今日金额
  3379. TShandeMch shandeMch = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getId())));
  3380. BigDecimal todayBalance = shandeMch.getTodayBalance();
  3381. todayBalance = todayBalance.add(agencyPrice).setScale(2, RoundingMode.HALF_DOWN);
  3382. shandeMch.setTodayBalance(todayBalance);
  3383. szwlFeign.updateShandeMch(shandeMch);
  3384. break;
  3385. case 1:
  3386. BigDecimal agencyProportion1 = proportion.getAgencyProportion();
  3387. BigDecimal merchantProportion1 = proportion.getProportion();
  3388. // 代理分销获得利润
  3389. BigDecimal agencyPrice1 = price.multiply(agencyProportion1.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  3390. // 经销商分销获得利润
  3391. BigDecimal merchantAmount1 = price.multiply(merchantProportion1.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  3392. //修改代理金额表的今日金额
  3393. // ArrayList<Filter> filters1 = new ArrayList<>();
  3394. // filters1.add(Filter.eq("adminId", admin.getAgencyId()));
  3395. TShandeMch shandeMch2 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(proportion.getAgencyId())));
  3396. BigDecimal todayBalance2 = shandeMch2.getTodayBalance();
  3397. todayBalance2 = todayBalance2.add(agencyPrice1).setScale(2, RoundingMode.HALF_DOWN);
  3398. shandeMch2.setTodayBalance(todayBalance2);
  3399. szwlFeign.updateShandeMch(shandeMch2);
  3400. //修改经销商金额表的今日金额
  3401. // ArrayList<Filter> filters2 = new ArrayList<>();
  3402. // filters2.add(Filter.eq("adminId", admin.getId()));
  3403. TShandeMch shandeMch3 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getId())));
  3404. BigDecimal todayBalance3 = shandeMch3.getTodayBalance();
  3405. todayBalance3 = todayBalance3.add(merchantAmount1).setScale(2, RoundingMode.HALF_DOWN);
  3406. shandeMch3.setTodayBalance(todayBalance3);
  3407. szwlFeign.updateShandeMch(shandeMch3);
  3408. break;
  3409. case 2:
  3410. BigDecimal agencyProportion2 = proportion.getAgencyProportion();
  3411. BigDecimal merchantProportion2 = proportion.getMerchantProportion();
  3412. BigDecimal personageProportion2 = proportion.getProportion();
  3413. // 代理分销获得利润
  3414. BigDecimal agencyAmount = price.multiply(agencyProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  3415. // 经销商分销获得利润
  3416. BigDecimal merchantAmount = price.multiply(merchantProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  3417. // 经销商分销获得利润
  3418. BigDecimal personageAmount = price.multiply(personageProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  3419. //修改代理金额表的今日金额
  3420. // ArrayList<Filter> filters3 = new ArrayList<>();
  3421. // filters3.add(Filter.eq("adminId", admin.getAgencyId()));
  3422. // List<ShandeMch> list3 = shandeMchService.findList(null,filters3,null);
  3423. TShandeMch shandeMch4 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(proportion.getAgencyId())));
  3424. BigDecimal todayBalance4 = shandeMch4.getTodayBalance();
  3425. todayBalance4 = todayBalance4.add(agencyAmount).setScale(2, RoundingMode.HALF_DOWN);
  3426. shandeMch4.setTodayBalance(todayBalance4);
  3427. szwlFeign.updateShandeMch(shandeMch4);
  3428. //修改经销商金额表的今日金额
  3429. TShandeMch shandeMch5 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(proportion.getMerchantId())));
  3430. BigDecimal todayBalance5 = shandeMch5.getTodayBalance();
  3431. todayBalance5 = todayBalance5.add(merchantAmount).setScale(2, RoundingMode.HALF_DOWN);
  3432. shandeMch5.setTodayBalance(todayBalance5);
  3433. szwlFeign.updateShandeMch(shandeMch5);
  3434. //修改终端金额表的今日金额
  3435. TShandeMch shandeMch6 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getId())));
  3436. BigDecimal todayBalance6 = shandeMch6.getTodayBalance();
  3437. todayBalance6 = todayBalance6.add(personageAmount).setScale(2, RoundingMode.HALF_DOWN);
  3438. shandeMch6.setTodayBalance(todayBalance6);
  3439. szwlFeign.updateShandeMch(shandeMch6);
  3440. break;
  3441. }
  3442. return "SUCCESS";
  3443. } else {
  3444. TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3445. String gtClientId = byClientId.getGtClientId();
  3446. JSONObject kindData = new JSONObject();
  3447. kindData.put("sn", order.getSn());
  3448. equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_faile", kindData.toString()).toString());
  3449. // PushUtils.push(gtClientId, "支付成功", "您的订单支付成功", PushUtils.buildJson("pay_faile", kindData.toString()).toString());
  3450. order.setNote(gtClientId + "支付失败");
  3451. orderService.updateById(order);
  3452. }
  3453. return "SUCCESS";
  3454. }
  3455. /**
  3456. * MG280支付成功回调
  3457. *
  3458. * @return
  3459. */
  3460. @RequestMapping(value = "/mg280Notify", method = RequestMethod.GET)
  3461. @ResponseBody
  3462. public Object mg280Notify(HttpServletRequest request) {
  3463. String r6_Status = request.getParameter("r6_Status");
  3464. // 订单号
  3465. String sn = request.getParameter("r2_OrderNo");
  3466. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  3467. query.eq(TOrder::getSn, sn);
  3468. if (StringUtils.isEmpty(sn)) {
  3469. return "error";
  3470. }
  3471. List<TOrder> list = orderService.list(query);
  3472. TOrder order = list.get(0);
  3473. if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
  3474. // 已支付
  3475. order.setStatus(1);
  3476. // 支付平台产生的流水号
  3477. String r7_TrxNo = request.getParameter("r7_TrxNo");
  3478. order.setTrxNo(r7_TrxNo);
  3479. // 格式:YYYY-MM-DD HH:mm:ss
  3480. String ra_PayTime = request.getParameter("ra_PayTime");
  3481. try {
  3482. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  3483. Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
  3484. order.setPayDate(payDate);
  3485. } catch (ParseException e) {
  3486. e.printStackTrace();
  3487. } catch (UnsupportedEncodingException e) {
  3488. e.printStackTrace();
  3489. }
  3490. orderService.updateById(order);
  3491. JSONObject kindData = new JSONObject();
  3492. kindData.put("sn", order.getSn());
  3493. kindData.put("productName", order.getProductName());
  3494. TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3495. String gtClientId = byClientId.getGtClientId();
  3496. Date endDate = byClientId.getEndDate();
  3497. Date date = new Date();
  3498. Date time = null;
  3499. double price1Price = 0;
  3500. BigDecimal price = order.getPrice();
  3501. // List<Price> priceList = priceService.findAll();
  3502. // for (Price price1 : priceList) {
  3503. // if (price1.getName().equals("MG280")) {
  3504. // price1Price = price1.getPrice();
  3505. // }
  3506. // }
  3507. TPrice price1 = R.getDataIfSuccess(szwlFeign.getPrice("MG280"));
  3508. price1Price = price1.getPrice();
  3509. BigDecimal city = price.divide(BigDecimal.valueOf(price1Price));
  3510. int ci = city.intValue();
  3511. if (endDate.getTime() < date.getTime()) {
  3512. Calendar c = Calendar.getInstance();
  3513. c.setTime(date);
  3514. int i = c.get(Calendar.MONTH);
  3515. c.set(Calendar.MONTH, i - 1);
  3516. //上个月有多少天
  3517. int actualMaximum = c.getActualMaximum(Calendar.DAY_OF_MONTH);
  3518. long t = date.getTime() - endDate.getTime();
  3519. long m = actualMaximum * 1000 * 60 * 60 * 24l;
  3520. if (t <= m) {
  3521. Calendar calendar = Calendar.getInstance();
  3522. calendar.setTime(endDate);
  3523. calendar.set(Calendar.DAY_OF_MONTH, 10);
  3524. //将小时至0
  3525. calendar.set(Calendar.HOUR_OF_DAY, 0);
  3526. //将分钟至0
  3527. calendar.set(Calendar.MINUTE, 0);
  3528. //将秒至0
  3529. calendar.set(Calendar.SECOND, 0);
  3530. //将毫秒至0
  3531. calendar.set(Calendar.MILLISECOND, 0);
  3532. calendar.add(Calendar.MONTH, ci);
  3533. time = calendar.getTime();
  3534. }
  3535. if (t > m) {
  3536. Calendar calendar = Calendar.getInstance();
  3537. calendar.setTime(date);
  3538. calendar.set(Calendar.DAY_OF_MONTH, 10);
  3539. //将小时至0
  3540. calendar.set(Calendar.HOUR_OF_DAY, 0);
  3541. //将分钟至0
  3542. calendar.set(Calendar.MINUTE, 0);
  3543. //将秒至0
  3544. calendar.set(Calendar.SECOND, 0);
  3545. //将毫秒至0
  3546. calendar.set(Calendar.MILLISECOND, 0);
  3547. calendar.add(Calendar.MONTH, ci);
  3548. time = calendar.getTime();
  3549. }
  3550. } else {
  3551. Calendar calendar = Calendar.getInstance();
  3552. calendar.setTime(endDate);
  3553. calendar.set(Calendar.DAY_OF_MONTH, 10);
  3554. //将小时至0
  3555. calendar.set(Calendar.HOUR_OF_DAY, 0);
  3556. //将分钟至0
  3557. calendar.set(Calendar.MINUTE, 0);
  3558. //将秒至0
  3559. calendar.set(Calendar.SECOND, 0);
  3560. //将毫秒至0
  3561. calendar.set(Calendar.MILLISECOND, 0);
  3562. calendar.add(Calendar.MONTH, ci);
  3563. time = calendar.getTime();
  3564. }
  3565. byClientId.setEndDate(time);
  3566. //修改机器
  3567. szwlFeign.updateByEquipment(byClientId);
  3568. order.setNote(gtClientId + "已推送");
  3569. orderService.updateById(order);
  3570. equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("endDate", String.valueOf(byClientId.getEndDate().getTime())).toString());
  3571. // PushUtils.push(byClientId.getGtClientId(), "", "", PushUtils.buildJson("endDate", String.valueOf(byClientId.getEndDate().getTime())).toString());
  3572. return "success";
  3573. } else {
  3574. TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3575. String gtClientId = byClientId.getGtClientId();
  3576. JSONObject kindData = new JSONObject();
  3577. kindData.put("sn", order.getSn());
  3578. order.setNote(gtClientId + "支付失败");
  3579. orderService.updateById(order);
  3580. }
  3581. return "success";
  3582. }
  3583. //生成二维码,并返回base64格式
  3584. private String toQrcode(String code) {
  3585. String imgtext = null;
  3586. QRCodeWriter qrCodeWriter = new QRCodeWriter();
  3587. HashMap<EncodeHintType, Object> hints = new HashMap<>();
  3588. hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
  3589. BitMatrix bitMatrix = null;
  3590. try {
  3591. bitMatrix = qrCodeWriter.encode(code, BarcodeFormat.QR_CODE, 600, 600, hints);
  3592. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  3593. MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);
  3594. Base64.Encoder encoder = Base64.getEncoder();
  3595. String text = encoder.encodeToString(outputStream.toByteArray());
  3596. imgtext = "data:image/png;base64," + text;
  3597. } catch (Exception e) {
  3598. e.printStackTrace();
  3599. }
  3600. return imgtext;
  3601. }
  3602. @ApiOperation(value = "汇付退款成功回调")
  3603. @RequestMapping(value = "/refundNotify", method = RequestMethod.POST)
  3604. @ResponseBody
  3605. public String refundNotify(HttpServletRequest request) {
  3606. String result = orderService.huifuNotifyRefund(request);
  3607. return result;
  3608. }
  3609. @ApiOperation(value = "汇付退款成功回调")
  3610. @RequestMapping(value = "/notifyRefund", method = RequestMethod.GET)
  3611. @ResponseBody
  3612. public Object notifyRefund(HttpServletRequest request) {
  3613. String result = orderService.joinpayNotifyRefund(request);
  3614. // String r6_Status = request.getParameter("ra_Status");
  3615. //
  3616. // // 订单号
  3617. // String sn = request.getParameter("r2_OrderNo");
  3618. // // 退款订单号
  3619. //
  3620. // if(StringUtils.isEmpty(sn)){
  3621. // return "error";
  3622. // }
  3623. //
  3624. // LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  3625. // query.eq(TOrder::getSn,sn);
  3626. // TOrder order = orderService.getOne(query);
  3627. //
  3628. // if (order == null) {
  3629. // return "error";
  3630. // }
  3631. // if (order.getStatus() == 3) {
  3632. // return "success";
  3633. // }
  3634. // // 订单商品数量
  3635. // if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
  3636. // if(order.getRefundQuantity() < order.getProductNumber()) {
  3637. // order.setStatus(1);
  3638. // } else {
  3639. // order.setStatus(3);
  3640. // }
  3641. // // 更改订单明细表
  3642. // LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
  3643. // queryWrapper.eq(TOrderDetails::getOrderSn, sn);
  3644. // // 处理退款中状态的明细
  3645. // queryWrapper.eq(TOrderDetails::getRefundStatus, "4");
  3646. // List<TOrderDetails> tOrderDetails = orderDetailsService.list(queryWrapper);
  3647. // for (TOrderDetails tOrderDetail : tOrderDetails) {
  3648. // Integer refundQuantity = tOrderDetail.getRefundQuantity();
  3649. // Integer productNumber = tOrderDetail.getProductNumber();
  3650. // if(refundQuantity < productNumber) {
  3651. // // 部分退款
  3652. // tOrderDetail.setRefundStatus("2");
  3653. // orderDetailsService.updateById(tOrderDetail);
  3654. // } else {
  3655. // // 全部退款
  3656. // tOrderDetail.setRefundStatus("3");
  3657. // orderDetailsService.updateById(tOrderDetail);
  3658. // }
  3659. // }
  3660. // // r4_refundAmount: 退款金额
  3661. // BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
  3662. // if(order.getRefundMarketingAmount()!=null){
  3663. // r4_refundAmount =r4_refundAmount.add(order.getRefundMarketingAmount());
  3664. // }
  3665. // // price: 订单金额, refundAmount:已退款的金额
  3666. // BigDecimal price = order.getPrice();
  3667. // BigDecimal refundAmount = order.getRefundAmount();
  3668. // TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(order.getEquipmentId())));
  3669. // if(order.getRefundAmount() != null) {
  3670. // BigDecimal newRefundAmount = refundAmount.add(r4_refundAmount);
  3671. // order.setRefundAmount(refundAmount.add(r4_refundAmount));
  3672. // // 如果小于订单金额
  3673. // if(newRefundAmount.compareTo(price) < 0) {
  3674. // JSONArray altInfo = getAltInfo(proportion, price.subtract(newRefundAmount));
  3675. // order.setAltInfo(altInfo.toString());
  3676. // } else {
  3677. // JSONArray altInfo = getAltInfo(proportion, price);
  3678. // order.setAltInfo(altInfo.toString());
  3679. // }
  3680. // } else {
  3681. // order.setRefundAmount(r4_refundAmount);
  3682. // if(r4_refundAmount.compareTo(price) < 0) {
  3683. // JSONArray altInfo = getAltInfo(proportion, price.subtract(r4_refundAmount));
  3684. // order.setAltInfo(altInfo.toString());
  3685. // }
  3686. // }
  3687. //
  3688. // // 支付平台产生的退款流水号
  3689. // String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
  3690. // order.setRefundTrxNo(r5_RefundTrxNo);
  3691. // order.setRefundDate(new Date());
  3692. // order.setModifyDate(new Date());
  3693. // String orderStatus = order.getOrderStatus();
  3694. // if(StringUtils.isNotEmpty(orderStatus)&&orderStatus.equals("0")){
  3695. // if(order.getStatus().toString().equals("3")){
  3696. // TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  3697. // JSONObject kindData = new JSONObject();
  3698. // String s = order.getId().toString();
  3699. // if(s.length()>6){
  3700. // s = s.substring(s.length()-6,s.length());
  3701. // }
  3702. // kindData.put("mealCode", s);
  3703. // equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("refuse_success", kindData.toString()).toString());
  3704. //
  3705. // }
  3706. // }
  3707. // try {
  3708. // esTOrderService.updateDataById(order);
  3709. // }catch (Exception e) {
  3710. // e.printStackTrace();
  3711. // }finally {
  3712. // orderService.updateById(order);
  3713. // }
  3714. // return "success";
  3715. // }
  3716. return result;
  3717. }
  3718. @ApiOperation(value = "添加国内订单")
  3719. @PostMapping("/addOrder")
  3720. public ResponseModel<?> addOrder(@RequestBody TOrder order) {
  3721. boolean save = orderService.save(order);
  3722. return R.ok(save);
  3723. }
  3724. @ApiOperation(value = "修改订单")
  3725. @PostMapping("/updateOrder")
  3726. public ResponseModel<?> updateOrder(@RequestBody TOrder order) {
  3727. orderService.updateById(order);
  3728. LambdaQueryWrapper<TOrderTask> query = Wrappers.lambdaQuery();
  3729. query.eq(TOrderTask::getSn, order.getSn());
  3730. TOrderTask orderTask = orderTaskService.getOne(query);
  3731. orderTask.setStatus(order.getStatus());
  3732. orderTaskService.updateById(orderTask);
  3733. return R.ok();
  3734. }
  3735. @ApiOperation(value = "获取订单")
  3736. @GetMapping("/getOrder")
  3737. public ResponseModel<?> getOrder(@RequestParam String id) {
  3738. TOrder order = orderService.getById(id);
  3739. return R.ok(order);
  3740. }
  3741. @ApiOperation(value = "获取订单")
  3742. @GetMapping("/getOrderBySn")
  3743. public ResponseModel<?> getOrderBySn(@RequestParam String sn) {
  3744. LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
  3745. wrapper.eq(TOrder::getSn, sn);
  3746. TOrder order = orderService.getOne(wrapper);
  3747. LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
  3748. queryWrapper.eq(TOrderDetails::getOrderSn, sn);
  3749. List<TOrderDetails> orderDetails = orderDetailsService.list(queryWrapper);
  3750. OrderDetailsDTO orderDetailsDTO = new OrderDetailsDTO();
  3751. BeanUtil.copyProperties(order, orderDetailsDTO);
  3752. orderDetailsDTO.setOrderDetails(orderDetails);
  3753. return R.ok(orderDetailsDTO);
  3754. }
  3755. @ApiOperation(value = "优惠码支付成功回调")
  3756. @RequestMapping(value = "/promoCodeNotify", method = RequestMethod.GET)
  3757. @ResponseBody
  3758. public Object promoCoderefund(HttpServletRequest request) {
  3759. String r6_Status = request.getParameter("r6_Status");
  3760. // 订单号
  3761. String sn = request.getParameter("r2_OrderNo");
  3762. //价格
  3763. String price = request.getParameter("r3_Amount");
  3764. // 优惠码
  3765. String codeNum = request.getParameter("r5_Mp");
  3766. Double money = null;
  3767. TPrice tPrice = R.getDataIfSuccess(szwlFeign.getPrice("优惠码"));
  3768. money = tPrice.getPrice();
  3769. //生成优惠码的个数
  3770. double num = Double.parseDouble(price) / money;
  3771. int number = (int) num;
  3772. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  3773. query.eq(TOrder::getSn, sn);
  3774. List<TOrder> list = new ArrayList<>();
  3775. if (StringUtils.isNotEmpty(sn)) {
  3776. list = orderService.list(query);
  3777. }
  3778. TOrder order = list.get(0);
  3779. if (order.getStatus() != 0) {
  3780. return "success";
  3781. }
  3782. if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
  3783. // 已支付
  3784. order.setStatus(1);
  3785. // 支付平台产生的流水号
  3786. String r7_TrxNo = request.getParameter("r7_TrxNo");
  3787. order.setTrxNo(r7_TrxNo);
  3788. // 格式:YYYY-MM-DD HH:mm:ss
  3789. String ra_PayTime = request.getParameter("ra_PayTime");
  3790. try {
  3791. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  3792. Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
  3793. order.setPayDate(payDate);
  3794. } catch (ParseException e) {
  3795. e.printStackTrace();
  3796. } catch (UnsupportedEncodingException e) {
  3797. e.printStackTrace();
  3798. }
  3799. orderService.updateById(order);
  3800. JSONObject kindData = new JSONObject();
  3801. kindData.put("sn", order.getSn());
  3802. kindData.put("productName", order.getProductName());
  3803. String mont = order.getRefundTrxNo();
  3804. Long data = Calendar.getInstance().getTimeInMillis();
  3805. Float month = Float.valueOf(mont);
  3806. Float mm = month * 10;
  3807. String m = String.valueOf(mm);
  3808. String[] split = m.split("\\.");
  3809. String th = split[0];
  3810. Long t = Long.valueOf(th);
  3811. Long mon = 30L * 24L * 60L * 60L * 1000L;
  3812. Long d = data + ((mon * t) / 10);
  3813. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  3814. String sd = sdf.format(new Date(Long.parseLong(String.valueOf(d))));
  3815. Date lastUseDate = new Date(Long.parseLong(String.valueOf(d)));
  3816. szwlFeign.addPromoCode(String.valueOf(order.getAdminId()), lastUseDate, number, codeNum);
  3817. return "支付成功";
  3818. }
  3819. return "success";
  3820. }
  3821. @ApiOperation(value = "查询订单是否付款")
  3822. @RequestMapping(value = "/getOrderStatus", method = RequestMethod.GET)
  3823. @ResponseBody
  3824. public JsonMessage getOrderStatus(String sn) {
  3825. String sta = "";
  3826. if (sn.contains("-")) {
  3827. String[] sns = sn.split("-");
  3828. for (int i = 0; i < sns.length; i++) {
  3829. LambdaQueryWrapper<TOrder> query1 = Wrappers.lambdaQuery();
  3830. query1.eq(TOrder::getSn, sns[i]);
  3831. TOrder order = orderService.getOne(query1);
  3832. if (order != null) {
  3833. Integer status = order.getStatus();
  3834. sta = status.toString();
  3835. if (status == 1) {
  3836. sta = "pay";
  3837. }
  3838. }
  3839. }
  3840. } else {
  3841. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  3842. query.eq(TOrder::getSn, sn);
  3843. List<TOrder> list = orderService.list(query);
  3844. if (list.size() > 0) {
  3845. TOrder order = list.get(0);
  3846. Integer status = order.getStatus();
  3847. sta = status.toString();
  3848. if (status == 1) {
  3849. sta = "pay";
  3850. }
  3851. }
  3852. }
  3853. return JsonMessage.success(sta);
  3854. }
  3855. @ApiOperation(value = "上传订单的做糖状态")
  3856. @RequestMapping(value = "/sendOrderStatus", method = RequestMethod.GET)
  3857. @ResponseBody
  3858. public JsonMessage sendOrderStatus(String sn, String orderStatus) {
  3859. if (StringUtils.isEmpty(sn) || StringUtils.isEmpty(orderStatus)) {
  3860. return JsonMessage.error("数据有空");
  3861. }
  3862. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  3863. query.eq(TOrder::getSn, sn);
  3864. List<TOrder> list = orderService.list(query);
  3865. TOrder order = list.get(0);
  3866. order.setOrderStatus(orderStatus);
  3867. orderService.updateById(order);
  3868. if (orderStatus.equals("1")) {
  3869. String s = order.getId().toString();
  3870. String clientId = order.getClientId();
  3871. szsmWxService.subscribeMessage(order.getWxId(), s.substring(s.length() - 6, s.length()), clientId.substring(clientId.length() - 6, clientId.length()));
  3872. }
  3873. LambdaQueryWrapper<TOrderTask> query1 = Wrappers.lambdaQuery();
  3874. query1.eq(TOrderTask::getSn, sn);
  3875. TOrderTask orderTask = orderTaskService.getOne(query1);
  3876. orderTask.setOrderStatus(orderStatus);
  3877. orderTaskService.updateById(orderTask);
  3878. return JsonMessage.success("success");
  3879. }
  3880. @ApiOperation(value = "删除订单")
  3881. @RequestMapping(value = "/deleteOrder", method = RequestMethod.GET)
  3882. @ResponseBody
  3883. public JsonMessage deleteOrder(String sn) {
  3884. if (StringUtils.isEmpty(sn)) {
  3885. return JsonMessage.error(sn + "删除失败");
  3886. }
  3887. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  3888. query.eq(TOrder::getSn, sn);
  3889. List<TOrder> list = orderService.list(query);
  3890. TOrder order = list.get(0);
  3891. Integer status = order.getStatus();
  3892. String ss = status.toString();
  3893. if (status == 0) {
  3894. orderService.removeById(order.getId());
  3895. return JsonMessage.success(sn + "删除成功");
  3896. }
  3897. // return JsonMessage.success(sn + "删除失败");
  3898. return JsonMessage.success(sn + "删除成功");
  3899. }
  3900. /**
  3901. * 添加订单
  3902. *
  3903. * @param clientId 设备client id
  3904. * @param productName 商品名称
  3905. * @param
  3906. * @return
  3907. */
  3908. @RequestMapping(value = "/addOrder", method = RequestMethod.GET)
  3909. @ResponseBody
  3910. public Object addOrder(String clientId, String productName, String pri, String sn) {
  3911. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  3912. if (equipment == null) {
  3913. return JsonMessage.error("找不到设备");
  3914. }
  3915. Long equipmentId = equipment.getId();
  3916. BigDecimal price = new BigDecimal(pri);
  3917. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  3918. if (admin == null) {
  3919. return JsonMessage.error("找不到设备商家");
  3920. }
  3921. JSONArray altInfo = new JSONArray();
  3922. String orderType = null;
  3923. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipment.getId())));
  3924. Integer type = proportion.getType();
  3925. switch (type) {
  3926. case 0:
  3927. orderType = "1";
  3928. break;
  3929. case 1:
  3930. orderType = "2";
  3931. break;
  3932. case 2:
  3933. orderType = "3";
  3934. break;
  3935. }
  3936. TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
  3937. TOrder order = new TOrder();
  3938. order.setId(IDGenerator.orderID());
  3939. order.setCreateDate(new Date());
  3940. order.setModifyDate(new Date());
  3941. order.setAdminId(admin.getId());
  3942. order.setSn(sn);
  3943. order.setProductId(product.getId());
  3944. order.setProductNo(product.getNo());
  3945. order.setProductName(productName);
  3946. order.setPrice(price);
  3947. order.setClientId(equipment.getClientId());
  3948. order.setEquipmentId(equipmentId);
  3949. order.setAltInfo(altInfo.toString());
  3950. order.setStatus(1);
  3951. order.setType(type);
  3952. orderService.save(order);
  3953. try {
  3954. if (order.getProductNumber() == null || order.getProductNumber() == 0) {
  3955. order.setProductNumber(1);
  3956. }
  3957. esTOrderService.insertData(order);
  3958. orderFeign.saveToEs(order);
  3959. } catch (Exception e) {
  3960. e.printStackTrace();
  3961. }
  3962. return JsonMessage.success("success");
  3963. }
  3964. /**
  3965. * 汇聚分销明细
  3966. *
  3967. * @param proportion
  3968. * @param price
  3969. * @return
  3970. */
  3971. public JSONArray getAltInfo(TProportion proportion, BigDecimal price) {
  3972. // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
  3973. Integer type = proportion.getType();
  3974. // 汇聚分账参数
  3975. JSONArray altInfo = new JSONArray();
  3976. BigDecimal agencyProportion = null,
  3977. merchantProportion = null,
  3978. selfProportion = null;
  3979. BigDecimal agencyAmount = null;
  3980. BigDecimal merchantAmount = null;
  3981. BigDecimal selfAmount = null;
  3982. TJoinpayMch agencyMch = null;
  3983. TJoinpayMch merchantMch = null;
  3984. TJoinpayMch selfMch = null;
  3985. JSONObject agencyJson = null;
  3986. JSONObject merchantJson = null;
  3987. JSONObject selfJson = null;
  3988. //取消平台扣手续费
  3989. BigDecimal cutPrice = price.setScale(2, RoundingMode.HALF_UP);
  3990. BigDecimal refuseAmount = new BigDecimal(0.00);
  3991. switch (type) {
  3992. case 0:
  3993. // 商家自己的分销
  3994. selfProportion = proportion.getProportion();
  3995. // 商家分销获得利润
  3996. selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  3997. // 汇聚平台
  3998. selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
  3999. if (selfMch == null) {
  4000. return altInfo;
  4001. }
  4002. selfJson = new JSONObject();
  4003. selfJson.put("altMchNo", selfMch.getAltMchNo());
  4004. selfJson.put("altAmount", selfAmount.toString());
  4005. selfJson.put("isGuar", "12");
  4006. altInfo.add(selfJson);
  4007. break;
  4008. case 1:
  4009. // 商家自己的分销
  4010. selfProportion = proportion.getProportion();
  4011. // 一级分销
  4012. agencyProportion = proportion.getAgencyProportion();
  4013. // 商家分销获得利润
  4014. selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4015. // 汇聚平台
  4016. agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
  4017. selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
  4018. if (selfMch == null || agencyMch == null) {
  4019. return altInfo;
  4020. }
  4021. if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
  4022. // 一级分销获得利润
  4023. agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4024. agencyJson = new JSONObject();
  4025. agencyJson.put("altMchNo", agencyMch.getAltMchNo());
  4026. agencyJson.put("altAmount", agencyAmount.toString());
  4027. agencyJson.put("isGuar", "12");
  4028. altInfo.add(agencyJson);
  4029. }
  4030. // 商家自己分销获得利润
  4031. selfJson = new JSONObject();
  4032. selfJson.put("altMchNo", selfMch.getAltMchNo());
  4033. selfJson.put("altAmount", selfAmount.toString());
  4034. selfJson.put("isGuar", "12");
  4035. altInfo.add(selfJson);
  4036. break;
  4037. case 2:
  4038. // 商家自己的分销
  4039. selfProportion = proportion.getProportion();
  4040. // 一级分销
  4041. agencyProportion = proportion.getAgencyProportion();
  4042. // 二级分销
  4043. merchantProportion = proportion.getMerchantProportion();
  4044. // 三级分销
  4045. // personageProportion = proportion.getPersonageProportion();
  4046. // 商家分销获得利润
  4047. selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4048. // 汇聚
  4049. agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
  4050. merchantMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getMerchantId())));
  4051. selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
  4052. if (selfMch == null || agencyMch == null || merchantMch == null) {
  4053. return altInfo;
  4054. }
  4055. if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
  4056. // 代理分销获得利润
  4057. agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4058. agencyJson = new JSONObject();
  4059. agencyJson.put("altMchNo", agencyMch.getAltMchNo());
  4060. agencyJson.put("altAmount", agencyAmount.toString());
  4061. agencyJson.put("isGuar", "12");
  4062. altInfo.add(agencyJson);
  4063. }
  4064. if (!(merchantProportion.compareTo(refuseAmount) == 0 || merchantProportion == null)) {
  4065. // 经销商分销获得利润
  4066. merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4067. merchantJson = new JSONObject();
  4068. merchantJson.put("altMchNo", merchantMch.getAltMchNo());
  4069. merchantJson.put("altAmount", merchantAmount.toString());
  4070. merchantJson.put("isGuar", "12");
  4071. altInfo.add(merchantJson);
  4072. }
  4073. // 商家自己分销获得利润
  4074. merchantJson = new JSONObject();
  4075. merchantJson.put("altMchNo", selfMch.getAltMchNo());
  4076. merchantJson.put("altAmount", selfAmount.toString());
  4077. merchantJson.put("isGuar", "12");
  4078. altInfo.add(merchantJson);
  4079. break;
  4080. }
  4081. Iterator<Object> iterator = altInfo.iterator();
  4082. while (iterator.hasNext()) {
  4083. JSONObject jsonObject = (JSONObject) iterator.next();
  4084. String altAmount = jsonObject.getString("altAmount");
  4085. if (altAmount.equals("0.00")) {
  4086. iterator.remove();
  4087. }
  4088. }
  4089. return altInfo;
  4090. }
  4091. /**
  4092. * 汇付分销明细
  4093. *
  4094. * @param proportion
  4095. * @param price
  4096. * @return
  4097. */
  4098. public JSONObject getAcctSplitBunch(TProportion proportion, BigDecimal price, String companyType) {
  4099. // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
  4100. Integer type = proportion.getType();
  4101. // 汇付分账明细参数
  4102. JSONObject acctSplitBunch = new JSONObject();
  4103. JSONArray acctInfos = new JSONArray();
  4104. BigDecimal adminProportion = null,
  4105. agencyProportion = null,
  4106. merchantProportion = null,
  4107. selfProportion = null;
  4108. BigDecimal agencyAmount = null;
  4109. BigDecimal merchantAmount = null;
  4110. BigDecimal selfAmount = null;
  4111. BigDecimal adminAmount = null;
  4112. THuifuMch agencyHuifu = null;
  4113. THuifuMch merchantHuifu = null;
  4114. THuifuMch selfHuifu = null;
  4115. JSONObject agencyJson = null;
  4116. JSONObject merchantJson = null;
  4117. JSONObject selfJson = null;
  4118. JSONObject adminJson = null;
  4119. //取消平台扣手续费
  4120. BigDecimal cutPrice = price.setScale(2, RoundingMode.HALF_UP);
  4121. BigDecimal refuseAmount = new BigDecimal(0.00);
  4122. switch (type) {
  4123. case 0:
  4124. // 公司平台分销
  4125. adminProportion = proportion.getAdminProportion();
  4126. // 商家自己的分销
  4127. selfProportion = proportion.getProportion();
  4128. // 平台分销获得利润
  4129. adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
  4130. // 商家分销获得利润
  4131. selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4132. // 汇付平台
  4133. // 商家汇付信息:agencyHuifu
  4134. selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
  4135. if (selfHuifu == null) {
  4136. return acctSplitBunch;
  4137. }
  4138. // 公司平台分销
  4139. adminJson = new JSONObject();
  4140. adminJson.put("div_amt", adminAmount.toString());
  4141. // 判断为申泽还是七云
  4142. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  4143. adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
  4144. } else {
  4145. adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
  4146. }
  4147. acctInfos.add(adminJson);
  4148. // 商家分销获得利润
  4149. selfJson = new JSONObject();
  4150. selfJson.put("div_amt", selfAmount.toString());
  4151. selfJson.put("huifu_id", selfHuifu.getHuifuId());
  4152. acctInfos.add(selfJson);
  4153. break;
  4154. case 1:
  4155. // 公司平台分销
  4156. adminProportion = proportion.getAdminProportion();
  4157. // 商家自己的分销
  4158. selfProportion = proportion.getProportion();
  4159. // 一级分销
  4160. agencyProportion = proportion.getAgencyProportion();
  4161. // 平台分销获得利润
  4162. adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
  4163. // 商家分销获得利润
  4164. selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4165. // 汇付平台
  4166. selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
  4167. agencyHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAgencyId()));
  4168. if (selfHuifu == null || agencyHuifu == null) {
  4169. return acctSplitBunch;
  4170. }
  4171. // 公司平台分销
  4172. adminJson = new JSONObject();
  4173. adminJson.put("div_amt", adminAmount.toString());
  4174. // 判断为申泽还是七云
  4175. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  4176. adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
  4177. } else {
  4178. adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
  4179. }
  4180. acctInfos.add(adminJson);
  4181. // 商家分销获得利润
  4182. selfJson = new JSONObject();
  4183. selfJson.put("div_amt", selfAmount.toString());
  4184. selfJson.put("huifu_id", selfHuifu.getHuifuId());
  4185. acctInfos.add(selfJson);
  4186. if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
  4187. // 一级分销获得利润
  4188. agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4189. agencyJson = new JSONObject();
  4190. agencyJson.put("div_amt", agencyAmount.toString());
  4191. agencyJson.put("huifu_id", agencyHuifu.getHuifuId());
  4192. acctInfos.add(agencyJson);
  4193. }
  4194. break;
  4195. case 2:
  4196. // 公司平台分销
  4197. adminProportion = proportion.getAdminProportion();
  4198. // 商家自己的分销
  4199. selfProportion = proportion.getProportion();
  4200. // 一级分销
  4201. agencyProportion = proportion.getAgencyProportion();
  4202. // 二级分销
  4203. merchantProportion = proportion.getMerchantProportion();
  4204. // 平台分销获得利润
  4205. adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
  4206. // 商家分销获得利润
  4207. selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4208. selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
  4209. agencyHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAgencyId()));
  4210. merchantHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getMerchantId()));
  4211. if (selfHuifu == null || agencyHuifu == null || merchantHuifu == null) {
  4212. return acctSplitBunch;
  4213. }
  4214. // 公司平台分销
  4215. adminJson = new JSONObject();
  4216. adminJson.put("div_amt", adminAmount.toString());
  4217. // 判断为申泽还是七云
  4218. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  4219. adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
  4220. } else {
  4221. adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
  4222. }
  4223. acctInfos.add(adminJson);
  4224. // 商家分销获得利润
  4225. selfJson = new JSONObject();
  4226. selfJson.put("div_amt", selfAmount.toString());
  4227. selfJson.put("huifu_id", selfHuifu.getHuifuId());
  4228. acctInfos.add(selfJson);
  4229. if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
  4230. // 一级分销获得利润
  4231. agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4232. agencyJson = new JSONObject();
  4233. agencyJson.put("div_amt", agencyAmount.toString());
  4234. agencyJson.put("huifu_id", agencyHuifu.getHuifuId());
  4235. acctInfos.add(agencyJson);
  4236. }
  4237. if (!(merchantProportion.compareTo(refuseAmount) == 0 || merchantProportion == null)) {
  4238. // 二级分销获得利润
  4239. merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4240. merchantJson = new JSONObject();
  4241. merchantJson.put("div_amt", merchantAmount.toString());
  4242. merchantJson.put("huifu_id", merchantHuifu.getHuifuId());
  4243. acctInfos.add(merchantJson);
  4244. }
  4245. break;
  4246. }
  4247. // 计算div_amt的总和
  4248. BigDecimal totalAmount = BigDecimal.ZERO;
  4249. for (int i = 0; i < acctInfos.size(); i++) {
  4250. JSONObject jsonObject = acctInfos.getJSONObject(i);
  4251. BigDecimal divAmt = new BigDecimal(jsonObject.getString("div_amt"));
  4252. totalAmount = totalAmount.add(divAmt);
  4253. }
  4254. // 如果总和超过原本金额,调整div_amt
  4255. if (totalAmount.compareTo(price) > 0) {
  4256. BigDecimal diffAmount = totalAmount.subtract(price);
  4257. for (int i = 0; i < acctInfos.size(); i++) {
  4258. JSONObject jsonObject = acctInfos.getJSONObject(i);
  4259. String huifuId = jsonObject.getString("huifu_id");
  4260. if (huifuId.equals(HuifuConstant.SZ_DIV_HUIFU_ID) || huifuId.equals(HuifuConstant.SC_DIV_HUIFU_ID)) {
  4261. BigDecimal currentDivAmt = new BigDecimal(jsonObject.getString("div_amt"));
  4262. BigDecimal adjustedDivAmt = currentDivAmt.subtract(diffAmount).max(BigDecimal.ZERO);
  4263. jsonObject.put("div_amt", adjustedDivAmt.toString());
  4264. break;
  4265. }
  4266. }
  4267. }
  4268. acctSplitBunch.put("acct_infos", acctInfos);
  4269. return acctSplitBunch;
  4270. }
  4271. /**
  4272. * 旧版退款成功回调
  4273. *
  4274. * @param request
  4275. * @return
  4276. */
  4277. @RequestMapping(value = "/oldNotifyRefund", method = RequestMethod.GET)
  4278. @ResponseBody
  4279. public Object oldNotifyRefund(HttpServletRequest request) {
  4280. String r6_Status = request.getParameter("ra_Status");
  4281. // 订单号
  4282. String sn = request.getParameter("r2_OrderNo");
  4283. // 退款订单号
  4284. String refundSn = request.getParameter("r3_RefundOrderNo");
  4285. String num = refundSn.substring(refundSn.length() - 1);
  4286. Integer refundNumber = Integer.valueOf(num);
  4287. // LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  4288. LambdaQueryWrapper<TOrder> query = new LambdaQueryWrapper<>();
  4289. query.eq(TOrder::getSn, sn);
  4290. if (StringUtils.isEmpty(sn)) {
  4291. return "error";
  4292. }
  4293. // List<TOrder> list = orderService.list(query);
  4294. // TOrder order = list.get(0);
  4295. TOrder order = orderService.getOne(query);
  4296. if (order == null) {
  4297. return "success";
  4298. }
  4299. if (order.getStatus() == 3) {
  4300. return "success";
  4301. }
  4302. // 判断退款版本号是否存在
  4303. String refundOrderNo = order.getRefundOrderNo();
  4304. if (StringUtils.isNotEmpty(refundOrderNo)) {
  4305. if (refundSn.equals(refundOrderNo)) {
  4306. try {
  4307. esTOrderService.updateDataById(order);
  4308. } catch (Exception e) {
  4309. e.printStackTrace();
  4310. }
  4311. return "success";
  4312. }
  4313. }
  4314. // 订单商品数量
  4315. Integer productNumber = order.getProductNumber();
  4316. if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
  4317. // 设置退款版本号
  4318. order.setRefundOrderNo(refundSn);
  4319. // 已退款
  4320. if (productNumber >= refundNumber) {
  4321. productNumber -= refundNumber;
  4322. order.setProductNumber(productNumber);
  4323. }
  4324. // r4_refundAmount: 退款金额
  4325. BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
  4326. if (order.getRefundMarketingAmount() != null) {
  4327. r4_refundAmount = r4_refundAmount.add(order.getRefundMarketingAmount());
  4328. }
  4329. // price: 当前订单退完款剩余的金额
  4330. BigDecimal price = order.getPrice();
  4331. // 判断退款金额是否小于订单余额
  4332. if (r4_refundAmount.compareTo(price) == -1) {
  4333. // refundAmount: 已退款金额
  4334. BigDecimal refundAmount = order.getRefundAmount();
  4335. if (refundAmount != null) {
  4336. // 如果已退款金额不为空,则加上退款金额
  4337. order.setRefundAmount(refundAmount.add(r4_refundAmount));
  4338. } else {
  4339. // 已退款金额
  4340. order.setRefundAmount(r4_refundAmount);
  4341. }
  4342. // 订单设置为支付状态
  4343. order.setStatus(1);
  4344. // 改变订单的金额,原先金额减去退款金额
  4345. order.setPrice(price.subtract(r4_refundAmount));
  4346. // 重置分销
  4347. if (order.getAltInfo() != null) {
  4348. TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  4349. String altInfo = altInfoReset(tEquipment.getId(), price.subtract(r4_refundAmount));
  4350. order.setAltInfo(altInfo);
  4351. }
  4352. }
  4353. // 判断退款金额是否等于订单余额
  4354. if (r4_refundAmount.compareTo(price) == 0) {
  4355. BigDecimal refundAmount = order.getRefundAmount();
  4356. // order.setAltInfo("");
  4357. order.setProductNumber(1);
  4358. if (refundAmount != null) {
  4359. order.setRefundAmount(refundAmount.add(r4_refundAmount));
  4360. // 全部退完款重新加回已退款的金额
  4361. order.setPrice(order.getPrice().add(refundAmount));
  4362. } else {
  4363. // 退款金额
  4364. order.setRefundAmount(r4_refundAmount);
  4365. }
  4366. order.setStatus(3);
  4367. if (order.getAltInfo() != null) {
  4368. TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  4369. String altInfo = altInfoReset(tEquipment.getId(), order.getRefundAmount());
  4370. order.setAltInfo(altInfo);
  4371. }
  4372. }
  4373. // 支付平台产生的退款流水号
  4374. String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
  4375. order.setRefundTrxNo(r5_RefundTrxNo);
  4376. order.setRefundDate(new Date());
  4377. order.setModifyDate(new Date());
  4378. // orderService.updateById(order);
  4379. String orderStatus = order.getOrderStatus();
  4380. if (StringUtils.isNotEmpty(orderStatus) && orderStatus.equals("0")) {
  4381. if (order.getStatus().toString().equals("3")) {
  4382. TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
  4383. JSONObject kindData = new JSONObject();
  4384. String s = order.getId().toString();
  4385. if (s.length() > 6) {
  4386. s = s.substring(s.length() - 6, s.length());
  4387. }
  4388. kindData.put("mealCode", s);
  4389. equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("refuse_success", kindData.toString()).toString());
  4390. }
  4391. }
  4392. try {
  4393. esTOrderService.updateDataById(order);
  4394. } catch (Exception e) {
  4395. e.printStackTrace();
  4396. } finally {
  4397. orderService.updateById(order);
  4398. }
  4399. return "success";
  4400. }
  4401. return "success";
  4402. }
  4403. public String altInfoReset(Long equipmentId, BigDecimal price) {
  4404. //获取分销 关联设备
  4405. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  4406. Integer type = proportion.getType();
  4407. JSONArray altInfo = new JSONArray();
  4408. JSONArray altNewInfo = new JSONArray();
  4409. BigDecimal adminProportion = null, agencyProportion = null, merchantProportion = null, personageProportion = null, selfProportion = null;
  4410. Long agencyId = proportion.getAgencyId();
  4411. Long merchantId = proportion.getMerchantId();
  4412. Long personageId = proportion.getPersonageId();
  4413. String orderType = null;
  4414. BigDecimal agencyAmount = null;
  4415. BigDecimal merchantAmount = null;
  4416. BigDecimal personageAmount = null;
  4417. BigDecimal selfAmount = null;
  4418. TJoinpayMch agencyMch = null;
  4419. TJoinpayMch merchantMch = null;
  4420. TJoinpayMch personageMch = null;
  4421. TJoinpayMch selfMch = null;
  4422. JSONObject agencyJson = null;
  4423. JSONObject merchantJson = null;
  4424. JSONObject personageJson = null;
  4425. JSONObject selfJson = null;
  4426. // 砍掉千6手续费
  4427. // BigDecimal cutPrice = price.multiply(new BigDecimal(99.4)).divide(new BigDecimal(100));
  4428. //取消平台扣手续费
  4429. BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
  4430. switch (type) {
  4431. case 0:
  4432. agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
  4433. agencyProportion = proportion.getProportion();
  4434. adminProportion = proportion.getAdminProportion();
  4435. orderType = "1";
  4436. // 代理分销获得利润
  4437. agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4438. agencyJson = new JSONObject();
  4439. agencyJson.put("altMchNo", agencyMch.getAltMchNo());
  4440. agencyJson.put("altAmount", agencyAmount.toString());
  4441. agencyJson.put("isGuar", "12");
  4442. altInfo.add(agencyJson);
  4443. break;
  4444. case 1:
  4445. agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
  4446. selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
  4447. agencyProportion = proportion.getAgencyProportion();
  4448. adminProportion = proportion.getAdminProportion();
  4449. selfProportion = proportion.getProportion();
  4450. orderType = "2";
  4451. BigDecimal refuseAmount = new BigDecimal(0.00);
  4452. if (agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null) {
  4453. // System.out.println("a等于b");
  4454. } else {
  4455. // 一级分销获得利润
  4456. agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4457. agencyJson = new JSONObject();
  4458. agencyJson.put("altMchNo", agencyMch.getAltMchNo());
  4459. agencyJson.put("altAmount", agencyAmount.toString());
  4460. agencyJson.put("isGuar", "12");
  4461. altInfo.add(agencyJson);
  4462. }
  4463. // 商家自己分销获得利润
  4464. selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4465. merchantJson = new JSONObject();
  4466. merchantJson.put("altMchNo", selfMch.getAltMchNo());
  4467. merchantJson.put("altAmount", selfAmount.toString());
  4468. merchantJson.put("isGuar", "12");
  4469. altInfo.add(merchantJson);
  4470. break;
  4471. case 2:
  4472. agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
  4473. merchantMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getMerchantId())));
  4474. selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
  4475. agencyProportion = proportion.getAgencyProportion();
  4476. adminProportion = proportion.getAdminProportion();
  4477. merchantProportion = proportion.getMerchantProportion();
  4478. personageProportion = proportion.getPersonageProportion();
  4479. selfProportion = proportion.getProportion();
  4480. orderType = "3";
  4481. BigDecimal refuseAmount1 = new BigDecimal(0.00);
  4482. if (agencyProportion.compareTo(refuseAmount1) == 0 || agencyProportion == null) {
  4483. // System.out.println("a等于b");
  4484. } else {
  4485. // 代理分销获得利润
  4486. agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4487. agencyJson = new JSONObject();
  4488. agencyJson.put("altMchNo", agencyMch.getAltMchNo());
  4489. agencyJson.put("altAmount", agencyAmount.toString());
  4490. agencyJson.put("isGuar", "12");
  4491. altInfo.add(agencyJson);
  4492. }
  4493. if (merchantProportion.compareTo(refuseAmount1) == 0 || merchantProportion == null) {
  4494. // System.out.println("a等于b");
  4495. } else {
  4496. // 经销商分销获得利润
  4497. merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4498. merchantJson = new JSONObject();
  4499. merchantJson.put("altMchNo", merchantMch.getAltMchNo());
  4500. merchantJson.put("altAmount", merchantAmount.toString());
  4501. merchantJson.put("isGuar", "12");
  4502. altInfo.add(merchantJson);
  4503. }
  4504. // 商家自己分销获得利润
  4505. selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
  4506. merchantJson = new JSONObject();
  4507. merchantJson.put("altMchNo", selfMch.getAltMchNo());
  4508. merchantJson.put("altAmount", selfAmount.toString());
  4509. merchantJson.put("isGuar", "12");
  4510. altInfo.add(merchantJson);
  4511. break;
  4512. }
  4513. return altInfo.toString();
  4514. }
  4515. public boolean hasDuplicateValue(List<String> values) {
  4516. Set<String> uniqueValues = new HashSet<>();
  4517. for (String value : values) {
  4518. if (!value.equals("0") && !uniqueValues.add(value)) {
  4519. // 如果添加失败,说明已存在相同的值,返回 true
  4520. return true;
  4521. }
  4522. }
  4523. // 如果循环结束仍未找到相同的值,则返回 false
  4524. return false;
  4525. }
  4526. /**
  4527. * 汇聚查询退款更新订单状态
  4528. *
  4529. * @param sn 订单号
  4530. * @param refundTrxNo 退款流水号
  4531. * @return
  4532. */
  4533. @RequestMapping(value = "/queryRefund", method = RequestMethod.GET)
  4534. @ResponseBody
  4535. public Object queryRefund(String sn, String refundTrxNo) {
  4536. JSONObject resultJson = orderService.queryRefund(refundTrxNo);
  4537. String refundStatus = resultJson.getString("ra_Status");
  4538. BigDecimal r3RefundAmount = new BigDecimal(resultJson.getString("r3_RefundAmount"));
  4539. System.out.println("退款状态:" + refundStatus);
  4540. System.out.println("退款金额:" + r3RefundAmount);
  4541. LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
  4542. query.eq(TOrder::getSn, sn);
  4543. TOrder order = orderService.getOne(query);
  4544. if (order == null) {
  4545. return "error";
  4546. }
  4547. if (order.getStatus() == 3) {
  4548. return "success";
  4549. }
  4550. if (JoinpayConstant.r6_Status_100.equals(refundStatus)) {
  4551. if (order.getRefundQuantity() < order.getProductNumber()) {
  4552. order.setStatus(1);
  4553. } else {
  4554. order.setStatus(3);
  4555. }
  4556. // 更改订单明细表
  4557. LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
  4558. queryWrapper.eq(TOrderDetails::getOrderSn, sn);
  4559. // 处理退款中状态的明细
  4560. queryWrapper.eq(TOrderDetails::getRefundStatus, "4");
  4561. List<TOrderDetails> tOrderDetails = orderDetailsService.list(queryWrapper);
  4562. for (TOrderDetails tOrderDetail : tOrderDetails) {
  4563. Integer refundQuantity = tOrderDetail.getRefundQuantity();
  4564. Integer productNumber = tOrderDetail.getProductNumber();
  4565. if (refundQuantity < productNumber) {
  4566. // 部分退款
  4567. tOrderDetail.setRefundStatus("2");
  4568. orderDetailsService.updateById(tOrderDetail);
  4569. } else {
  4570. // 全部退款
  4571. tOrderDetail.setRefundStatus("3");
  4572. orderDetailsService.updateById(tOrderDetail);
  4573. }
  4574. }
  4575. // r4_refundAmount: 退款金额
  4576. BigDecimal r4_refundAmount = new BigDecimal(resultJson.getString("r3_RefundAmount"));
  4577. if (order.getRefundMarketingAmount() != null) {
  4578. r4_refundAmount = r4_refundAmount.add(order.getRefundMarketingAmount());
  4579. }
  4580. // price: 订单金额, refundAmount:已退款的金额
  4581. BigDecimal price = order.getPrice();
  4582. BigDecimal refundAmount = order.getRefundAmount();
  4583. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(order.getEquipmentId())));
  4584. if (r3RefundAmount.compareTo(price) == 0) {
  4585. JSONArray altInfo = getAltInfo(proportion, price);
  4586. order.setAltInfo(altInfo.toString());
  4587. order.setRefundAmount(r3RefundAmount);
  4588. } else {
  4589. if (refundAmount != null) {
  4590. BigDecimal newRefundAmount = refundAmount.add(r4_refundAmount);
  4591. // 如果小于订单金额
  4592. if (newRefundAmount.compareTo(price) < 0) {
  4593. JSONArray altInfo = getAltInfo(proportion, price.subtract(newRefundAmount));
  4594. order.setAltInfo(altInfo.toString());
  4595. } else {
  4596. JSONArray altInfo = getAltInfo(proportion, price);
  4597. order.setAltInfo(altInfo.toString());
  4598. }
  4599. } else {
  4600. order.setRefundAmount(r4_refundAmount);
  4601. if (r4_refundAmount.compareTo(price) < 0) {
  4602. JSONArray altInfo = getAltInfo(proportion, price.subtract(r4_refundAmount));
  4603. order.setAltInfo(altInfo.toString());
  4604. }
  4605. }
  4606. }
  4607. try {
  4608. esTOrderService.updateDataById(order);
  4609. } catch (Exception e) {
  4610. e.printStackTrace();
  4611. } finally {
  4612. orderService.updateById(order);
  4613. }
  4614. return "success";
  4615. }
  4616. return "success";
  4617. }
  4618. @ApiOperation("收钱吧反扫购物车支付")
  4619. @PostMapping("/sqbCardPay")
  4620. @ResponseBody
  4621. public Object sqbCardPay(String authCode, String frpCode, String clientId, String ip, @RequestBody Map<String, String> productNameMap) {
  4622. return orderService.sqbCardPay(authCode, frpCode, clientId, ip, productNameMap);
  4623. }
  4624. @ApiOperation("收钱吧发起退款")
  4625. @PostMapping("/sqbRefund")
  4626. public ResponseModel<?> sqbRefund(@RequestBody TOrder torder) {
  4627. return orderService.sqbRefund(torder);
  4628. }
  4629. /**
  4630. * 请求在线支付 主扫 优惠码 盲盒
  4631. *
  4632. * @param clientId 设备client id
  4633. * @param productName 商品名称
  4634. * @param frpCode 支付方式 支付宝:ALIPAY_NATIVE , 微信:WEIXIN_NATIVE
  4635. * @param pri 有值代表是盲盒
  4636. */
  4637. @ApiOperation(value = "优化汇付支付")
  4638. @GetMapping("/testUniPay")
  4639. public Object testUniPay(String code, String clientId, String productName, String frpCode, String pri) {
  4640. return orderService.scanpay(code, clientId, productName, frpCode, pri);
  4641. }
  4642. @ApiOperation("汇付微信预下单")
  4643. @GetMapping("/huifuPayCreate")
  4644. public Object huifuPayCreate(String sn, String openid) {
  4645. return orderService.huifuPayCreate(sn, openid);
  4646. }
  4647. @ApiOperation("汇付查询订单交易结果")
  4648. @GetMapping("/huifuPayQuery")
  4649. public Object huifuPayQuery(String queryId, String sn, String companyType) {
  4650. return orderService.huifuPayQuery(queryId, sn, companyType);
  4651. }
  4652. @ApiOperation(value = "购物车 请求在线支付 二码合一")
  4653. @PostMapping("/newCarsPay")
  4654. public Object newCarsPay(String clientId, @RequestBody Map<String, String> productNameMap) {
  4655. if (productNameMap == null) {
  4656. return JsonMessage.error("数据出错");
  4657. }
  4658. StringBuffer note = new StringBuffer();
  4659. StringBuffer productName = new StringBuffer();
  4660. String productNo = "";
  4661. Map<String, Integer> productMap = new HashMap<>();
  4662. Integer productNumber = 0;
  4663. TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
  4664. if (equipment == null || equipment.getId() == null) {
  4665. return JsonMessage.error("找不到设备");
  4666. }
  4667. BigDecimal price = new BigDecimal("0.00");
  4668. TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
  4669. if (equipmentDesc == null || equipmentDesc.getEquipmentId() == null || equipmentDesc.getPayType() == null || equipmentDesc.getPayType().equals("0")) {
  4670. // 1、type=0,原始设定,没有第二件半价
  4671. for (String key : productNameMap.keySet()) {
  4672. String entryValue = String.valueOf(productNameMap.get(key));
  4673. List<String> value = JSON.parseArray(entryValue, String.class);
  4674. boolean hasDuplicate = hasDuplicateValue(value);
  4675. if (hasDuplicate) {
  4676. return JsonMessage.error("优惠码输入重复,单个商品只能使用一个优惠码");
  4677. }
  4678. List<TPromoCode> promoCodeList = new ArrayList<>();
  4679. // 1、校验优惠码
  4680. if (value.size() > 0) {
  4681. for (String code : value) {
  4682. if (!code.equals("0")) {
  4683. TPromoCode promoCode;
  4684. ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
  4685. TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
  4686. promoCode = tPromoCode;
  4687. if (tPromoCode == null || tPromoCode.getId() == null) {
  4688. //不存在
  4689. return JsonMessage.success("1");
  4690. }
  4691. Date lastUseDate = null;
  4692. if (promoCode != null) {
  4693. lastUseDate = promoCode.getLastUseDate();
  4694. }
  4695. if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
  4696. promoCode.setIsUse("2");
  4697. szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
  4698. //过期
  4699. return JsonMessage.success("4");
  4700. }
  4701. if (promoCode.getId() == null) {
  4702. //不存在
  4703. return JsonMessage.success("1");
  4704. }
  4705. if (promoCode.getIsUse().equals("1")) {
  4706. //被使用
  4707. return JsonMessage.success("2");
  4708. }
  4709. if (!promoCode.getAdminId().equals("1")) {
  4710. if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
  4711. } else {
  4712. //不是本机
  4713. return JsonMessage.success("3");
  4714. }
  4715. }
  4716. if (promoCode.getDiscount() == null) {
  4717. //旧优惠码
  4718. return JsonMessage.success("0");
  4719. }
  4720. promoCodeList.add(promoCode);
  4721. }
  4722. }
  4723. }
  4724. String[] productInfo = key.split("-");
  4725. String no = productInfo[0];
  4726. String num = productInfo[1];
  4727. //确定价格,然后叠加
  4728. TProduct product = R.getDataIfSuccess(szwlFeign.getProductByNo(no, String.valueOf(equipment.getId())));
  4729. if (product == null) {
  4730. return JsonMessage.error("找不到商品");
  4731. }
  4732. String goodsName = product.getProductName();
  4733. productMap.put(goodsName, Integer.valueOf(num));
  4734. productNumber += Integer.valueOf(num);
  4735. productName.append(goodsName).append("x").append(num).append(",");
  4736. BigDecimal productPrice = product.getRmbPrice();
  4737. productNo = product.getNo();
  4738. if (promoCodeList.size() > 0) {
  4739. //有优惠码
  4740. BigDecimal onePrice = new BigDecimal("0.00");
  4741. Map<BigDecimal, Integer> priceMap = new HashMap<>();
  4742. int i;
  4743. for (i = 0; i < promoCodeList.size(); i++) {
  4744. BigDecimal discount = BigDecimal.valueOf(promoCodeList.get(i).getDiscount()).setScale(2, RoundingMode.HALF_DOWN);
  4745. BigDecimal price1 = new BigDecimal(0.0);
  4746. TPromoCode tPromoCode = promoCodeList.get(i);
  4747. if (StringUtils.isNotEmpty(tPromoCode.getType()) && tPromoCode.getType().equals("1")) {
  4748. if (productPrice.compareTo(discount) > 0) {
  4749. // 如果 price 大于 discount,从 price 中减去 discount
  4750. price1 = productPrice.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
  4751. } else {
  4752. // 如果 price 小于等于 discount,将 price 设置为 0
  4753. price1 = BigDecimal.ZERO;
  4754. }
  4755. } else {
  4756. if (tPromoCode.getDiscount() == 0) {
  4757. price1 = BigDecimal.ZERO;
  4758. } else {
  4759. price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
  4760. }
  4761. }
  4762. price = price.add(price1);
  4763. if (priceMap.containsKey(price1)) {
  4764. priceMap.put(price1, priceMap.get(price1) + 1);
  4765. } else {
  4766. priceMap.put(price1, 1);
  4767. }
  4768. }
  4769. if (i < Integer.valueOf(num)) {
  4770. int a = Integer.valueOf(num) - i;
  4771. BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
  4772. price = price.add(price2);
  4773. priceMap.put(price2, a);
  4774. }
  4775. for (BigDecimal priceKey : priceMap.keySet()) {
  4776. note.append(goodsName).append("-").append(product.getNo()).append("-").append(RandomUtil.randomNumbers(5)).append(":");
  4777. note.append(priceKey).append("-").append(priceMap.get(priceKey)).append(",");
  4778. }
  4779. } else {
  4780. //1,type=0,原始设定,没有第二件半价
  4781. int a = Integer.valueOf(num);
  4782. BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
  4783. price = price.add(price2);
  4784. note.append(goodsName).append("-").append(product.getNo()).append(":");
  4785. note.append(price2).append("-").append(num).append(",");
  4786. }
  4787. }
  4788. } else {
  4789. //2,type=1,第二件半价
  4790. //2.1 判定是否有第二件,有多少个第二件半价
  4791. for (String key : productNameMap.keySet()) {
  4792. String[] productInfo = key.split("-");
  4793. String no = productInfo[0];
  4794. String num = productInfo[1];
  4795. //确定价格,然后叠加
  4796. TProduct product = R.getDataIfSuccess(szwlFeign.getProductByNo(no, String.valueOf(equipment.getId())));
  4797. if (product == null) {
  4798. return JsonMessage.error("找不到商品");
  4799. }
  4800. String goodsName = product.getProductName();
  4801. BigDecimal productPrice = product.getRmbPrice();
  4802. productName.append(goodsName).append("x").append(num).append(",");
  4803. note.append(goodsName).append("-").append(product.getNo()).append(":");
  4804. productNo = product.getNo();
  4805. switch (num) {
  4806. case "1":
  4807. //1个 0个半价
  4808. price = price.add(productPrice);
  4809. note.append(price).append("-").append(num).append(",");
  4810. break;
  4811. case "2":
  4812. //2个 1个半价
  4813. price = price.add(productPrice);
  4814. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  4815. note.append(price).append("-").append(num).append(",");
  4816. break;
  4817. case "3":
  4818. //3个 1个半价
  4819. price = price.add(productPrice);
  4820. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  4821. price = price.add(productPrice);
  4822. note.append(price).append("-").append(num).append(",");
  4823. break;
  4824. case "4":
  4825. //4个 2个半价
  4826. price = price.add(productPrice);
  4827. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  4828. price = price.add(productPrice);
  4829. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  4830. note.append(price).append("-").append(num).append(",");
  4831. break;
  4832. case "5":
  4833. //5个 2个半价
  4834. price = price.add(productPrice);
  4835. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  4836. price = price.add(productPrice);
  4837. price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
  4838. price = price.add(productPrice);
  4839. note.append(price).append("-").append(num).append(",");
  4840. break;
  4841. }
  4842. }
  4843. }
  4844. if (equipment == null) {
  4845. return JsonMessage.error("找不到设备");
  4846. }
  4847. Long equipmentId = equipment.getId();
  4848. //查找商品
  4849. if (BigDecimal.ZERO.compareTo(price) == 0) {
  4850. return JsonMessage.success("0");
  4851. }
  4852. if (BigDecimal.ZERO.compareTo(price) > 0) {
  4853. return JsonMessage.error("商品价格异常");
  4854. }
  4855. Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
  4856. String sn1 = orderService.initSn(client6);
  4857. String sn2 = orderService.initSn(client6);
  4858. // 获取关联设备的分销
  4859. TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
  4860. if (proportion == null || proportion.getId() == null) {
  4861. return JsonMessage.error("设备商家未完成分销设置");
  4862. }
  4863. TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
  4864. if (admin == null) {
  4865. return JsonMessage.error("找不到设备商家");
  4866. }
  4867. // 支付方式:0或null为汇聚,1为汇付支付
  4868. String payPlatform = admin.getPayPlatform();
  4869. String companyType = admin.getCompanyType();
  4870. // 汇聚分账参数
  4871. JSONArray altInfo = new JSONArray();
  4872. // 汇付分账明细参数
  4873. JSONObject acctSplitBunch = new JSONObject();
  4874. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  4875. acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
  4876. if (!(acctSplitBunch.size() > 0)) {
  4877. return JsonMessage.error("设备商家未注册结算账号");
  4878. }
  4879. } else {
  4880. altInfo = getAltInfo(proportion, price);
  4881. if (!(altInfo.size() > 0)) {
  4882. return JsonMessage.error("设备商家未注册结算账号");
  4883. }
  4884. }
  4885. String orderNo1 = sn1;
  4886. String orderNo2 = sn2;
  4887. BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
  4888. String productDesc = "";
  4889. String commonParameter = "";
  4890. String returnUrl = null;
  4891. String notifyUrl = JoinpayConstant.Notify_Url;
  4892. String isShowPic = "1";
  4893. String openId = null;
  4894. String authCode = null;
  4895. String appid = null;
  4896. String transactionModel = null;
  4897. String tradeMerchantNo = admin.getTradeMerchantNo();
  4898. String buyerId = null;
  4899. String isAlt = "1";
  4900. String altType = "11";
  4901. String altUrl = null;
  4902. BigDecimal marketingAmount = null;
  4903. String frpCode1 = "WEIXIN_NATIVE";
  4904. String frpCode2 = "ALIPAY_NATIVE";
  4905. TOrder order = new TOrder();
  4906. order.setId(IDGenerator.orderID());
  4907. order.setCreateDate(new Date());
  4908. order.setModifyDate(new Date());
  4909. order.setAdminId(admin.getId());
  4910. order.setSn(sn1);
  4911. order.setProductNo(productNo);
  4912. // 去掉后面的逗号
  4913. if (productNumber == 1) {
  4914. productName.delete(productName.length() - 3, productName.length());
  4915. } else {
  4916. productName.deleteCharAt(productName.length() - 1);
  4917. }
  4918. order.setProductName(productName.toString());
  4919. order.setPrice(price);
  4920. order.setClientId(equipment.getClientId());
  4921. order.setEquipmentId(equipmentId);
  4922. order.setFrpCode(frpCode1);
  4923. order.setAltInfo(altInfo.toString());
  4924. order.setProductNumber(productNumber);
  4925. order.setStatus(0);
  4926. order.setType(admin.getType());
  4927. order.setCompanyType(companyType);
  4928. order.setMachineType(equipment.getMachineType());
  4929. if (admin.getType() == 0) {
  4930. order.setAdminProportion(proportion.getProportion());
  4931. order.setAgencyProportion(proportion.getAgencyProportion());
  4932. order.setAgencyId(proportion.getAgencyId());
  4933. }
  4934. if (admin.getType() == 1) {
  4935. order.setAdminProportion(proportion.getProportion());
  4936. order.setAgencyProportion(proportion.getAgencyProportion());
  4937. order.setAgencyId(proportion.getAgencyId());
  4938. order.setMerchantProportion(proportion.getMerchantProportion());
  4939. order.setMerchantId(proportion.getMerchantId());
  4940. }
  4941. if (admin.getType() == 2) {
  4942. order.setAdminProportion(proportion.getProportion());
  4943. order.setAgencyProportion(proportion.getAgencyProportion());
  4944. order.setAgencyId(proportion.getAgencyId());
  4945. order.setMerchantProportion(proportion.getMerchantProportion());
  4946. order.setMerchantId(proportion.getMerchantId());
  4947. order.setPersonageProportion(proportion.getPersonageProportion());
  4948. order.setPersonageId(proportion.getPersonageId());
  4949. }
  4950. order.setPayPlatform(payPlatform);
  4951. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  4952. order.setIsSettlement("0");
  4953. }
  4954. order.setNote(note.toString());
  4955. TOrder order2 = new TOrder();
  4956. order2.setId(IDGenerator.orderID());
  4957. order2.setCreateDate(new Date());
  4958. order2.setModifyDate(new Date());
  4959. order2.setAdminId(admin.getId());
  4960. order2.setSn(sn2);
  4961. order2.setProductName(productName.toString());
  4962. order2.setProductNo(productNo);
  4963. order2.setPrice(price);
  4964. order2.setClientId(equipment.getClientId());
  4965. order2.setEquipmentId(equipmentId);
  4966. order2.setFrpCode(frpCode2);
  4967. order2.setAltInfo(altInfo.toString());
  4968. order2.setStatus(0);
  4969. order2.setProductNumber(productNumber);
  4970. order2.setType(admin.getType());
  4971. order2.setCompanyType(companyType);
  4972. order2.setMachineType(equipment.getMachineType());
  4973. if (admin.getType() == 0) {
  4974. order2.setAdminProportion(proportion.getProportion());
  4975. order2.setAgencyProportion(proportion.getAgencyProportion());
  4976. order2.setAgencyId(proportion.getAgencyId());
  4977. }
  4978. if (admin.getType() == 1) {
  4979. order2.setAdminProportion(proportion.getProportion());
  4980. order2.setAgencyProportion(proportion.getAgencyProportion());
  4981. order2.setAgencyId(proportion.getAgencyId());
  4982. order2.setMerchantProportion(proportion.getMerchantProportion());
  4983. order2.setMerchantId(proportion.getMerchantId());
  4984. }
  4985. if (admin.getType() == 2) {
  4986. order2.setAdminProportion(proportion.getProportion());
  4987. order2.setAgencyProportion(proportion.getAgencyProportion());
  4988. order2.setAgencyId(proportion.getAgencyId());
  4989. order2.setMerchantProportion(proportion.getMerchantProportion());
  4990. order2.setMerchantId(proportion.getMerchantId());
  4991. order2.setPersonageProportion(proportion.getPersonageProportion());
  4992. order2.setPersonageId(proportion.getPersonageId());
  4993. }
  4994. order2.setPayPlatform(payPlatform);
  4995. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  4996. order2.setIsSettlement("0");
  4997. }
  4998. order2.setNote(note.toString());
  4999. // 订单明细表
  5000. TOrderDetails orderDetails = new TOrderDetails();
  5001. orderDetails.setAdminId(admin.getId());
  5002. orderDetails.setEquipmentId(equipmentId);
  5003. orderDetails.setCreateDate(new Date());
  5004. orderDetails.setCompanyType(companyType);
  5005. orderDetails.setRefundStatus("0");
  5006. orderDetails.setMachineType(equipment.getMachineType());
  5007. String productName1 = "";
  5008. if (productNumber > 1) {
  5009. if (equipment.getMachineType() == null || equipment.getMachineType().equals("0")) {
  5010. productName1 = "棉花糖-" + equipment.getName() + "-" + client6;
  5011. } else {
  5012. productName1 = "爆米花-" + equipment.getName() + "-" + client6;
  5013. }
  5014. } else {
  5015. productName1 = productName + "-" + equipment.getName() + "-" + client6;
  5016. }
  5017. Map<String, String> map = new HashMap<>();
  5018. String[] products = order.getNote().split(",");
  5019. for (String product : products) {
  5020. String[] parts = product.split(":");
  5021. // 商品名称-商品编号
  5022. String key = parts[0];
  5023. // 商品单价-商品数量
  5024. String value = parts[1];
  5025. map.put(key, value);
  5026. }
  5027. String result = null;
  5028. if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
  5029. // 汇付分账参数
  5030. order.setAcctSplitBunch(acctSplitBunch.toString());
  5031. order2.setAcctSplitBunch(acctSplitBunch.toString());
  5032. String result1 = "";
  5033. if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
  5034. result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  5035. } else {
  5036. result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
  5037. }
  5038. try {
  5039. result1 = URLEncoder.encode(result1, "UTF-8");
  5040. } catch (UnsupportedEncodingException e) {
  5041. e.printStackTrace();
  5042. }
  5043. // 支付宝
  5044. try {
  5045. result = huifuMchService.uniPay(
  5046. sn2, amount, productName1, productDesc,
  5047. notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
  5048. );
  5049. } catch (Exception e) {
  5050. e.printStackTrace();
  5051. return JsonMessage.error("申请支付失败");
  5052. }
  5053. if (StrUtil.isEmpty(result)) {
  5054. return JsonMessage.error("找不到支付图片");
  5055. }
  5056. // 汇聚支付支付申请返回支付二维码图片
  5057. String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
  5058. String qrcode = toQrcode(code1);
  5059. JSONObject kindData = new JSONObject();
  5060. kindData.put("sn", sn1 + "-" + sn2);
  5061. kindData.put("rd_Pic", qrcode);
  5062. for (String key : map.keySet()) {
  5063. // key:"玫瑰精灵-A01",value:"0.50-1"
  5064. String value = map.get(key);
  5065. String[] GoodsInfo = key.split("-");
  5066. String[] GoodsValue = value.split("-");
  5067. orderDetails.setId(HuifuUtils.initDetailsId());
  5068. orderDetails.setProductName(GoodsInfo[0]);
  5069. orderDetails.setProductNo(GoodsInfo[1]);
  5070. orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
  5071. orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
  5072. orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
  5073. orderDetails.setId(HuifuUtils.initDetailsId());
  5074. orderDetails.setOrderSn(sn1);
  5075. orderDetailsService.save(orderDetails);
  5076. orderDetails.setId(HuifuUtils.initDetailsId());
  5077. orderDetails.setOrderSn(sn2);
  5078. orderDetailsService.save(orderDetails);
  5079. }
  5080. orderService.save(order);
  5081. orderService.save(order2);
  5082. return JsonMessage.success(kindData.toString());
  5083. } else {
  5084. try {
  5085. result = joinpayMchService.uniPay(
  5086. orderNo1, amount, productName1, productDesc,
  5087. commonParameter, returnUrl, notifyUrl, frpCode1,
  5088. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  5089. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  5090. );
  5091. } catch (UnsupportedEncodingException e) {
  5092. e.printStackTrace();
  5093. return JsonMessage.error("申请支付失败");
  5094. }
  5095. JSONObject resultJson = JSONObject.parseObject(result);
  5096. String rc_Result1 = resultJson.getString("rc_Result");
  5097. String result1 = null;
  5098. try {
  5099. result1 = joinpayMchService.uniPay(
  5100. orderNo2, amount, productName1, productDesc,
  5101. commonParameter, returnUrl, notifyUrl, frpCode2,
  5102. isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
  5103. buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
  5104. );
  5105. } catch (UnsupportedEncodingException e) {
  5106. e.printStackTrace();
  5107. return JsonMessage.error("申请支付失败");
  5108. }
  5109. JSONObject resultJson1 = JSONObject.parseObject(result1);
  5110. String rc_Result2 = resultJson1.getString("rc_Result");
  5111. // 汇聚支付支付申请返回支付二维码图片
  5112. String code1 = "http://app.sunzee.com.cn/" + "/api/order/aliPay.htm?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
  5113. String rd_Pic = toQrcode(code1);
  5114. JSONObject kindData = new JSONObject();
  5115. kindData.put("sn", sn1 + "-" + sn2);
  5116. kindData.put("rd_Pic", rd_Pic);
  5117. for (String key : map.keySet()) {
  5118. // key:"玫瑰精灵-A01",value:"0.50-1"
  5119. String value = map.get(key);
  5120. String[] GoodsInfo = key.split("-");
  5121. String[] GoodsValue = value.split("-");
  5122. orderDetails.setId(HuifuUtils.initDetailsId());
  5123. orderDetails.setProductName(GoodsInfo[0]);
  5124. orderDetails.setProductNo(GoodsInfo[1]);
  5125. orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
  5126. orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
  5127. orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
  5128. orderDetails.setId(HuifuUtils.initDetailsId());
  5129. orderDetails.setOrderSn(sn1);
  5130. orderDetailsService.save(orderDetails);
  5131. orderDetails.setId(HuifuUtils.initDetailsId());
  5132. orderDetails.setOrderSn(sn2);
  5133. orderDetailsService.save(orderDetails);
  5134. }
  5135. orderService.save(order);
  5136. orderService.save(order2);
  5137. return JsonMessage.success(kindData.toString());
  5138. }
  5139. }
  5140. }