123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409 |
- package com.szwl.controller;
- import cn.com.crbank.ommo.esUtil.BeanUtils;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.util.RandomUtil;
- import cn.hutool.core.util.StrUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.google.zxing.BarcodeFormat;
- import com.google.zxing.EncodeHintType;
- import com.google.zxing.client.j2se.MatrixToImageWriter;
- import com.google.zxing.common.BitMatrix;
- import com.google.zxing.qrcode.QRCodeWriter;
- import com.szwl.constant.HuifuConstant;
- import com.szwl.constant.JoinpayConstant;
- import com.szwl.constant.ResponseCodesEnum;
- import com.szwl.exception.BizException;
- import com.szwl.feign.bean.OrderFeign;
- import com.szwl.feign.bean.SzwlFeign;
- import com.szwl.model.bo.JsonMessage;
- import com.szwl.model.bo.R;
- import com.szwl.model.bo.ResponseModel;
- import com.szwl.model.dto.OrderDetailsDTO;
- import com.szwl.model.entity.*;
- import com.szwl.model.utils.HttpClientSslUtils;
- import com.szwl.model.utils.HttpClientUtils;
- import com.szwl.model.utils.PushUtils;
- import com.szwl.model.utils.RSAUtil;
- import com.szwl.service.*;
- import com.szwl.service.es.EsTOrderService;
- import com.szwl.utils.HuifuUtils;
- import com.szwl.utils.IDGenerator;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.servlet.view.RedirectView;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author wuhs
- * @since 2022-06-17
- */
- @Slf4j
- @RestController
- @RequestMapping("/tOrder")
- public class TOrderController {
- @Autowired
- SzwlFeign szwlFeign;
- @Autowired
- OrderFeign orderFeign;
- @Autowired
- TOrderService orderService;
- @Autowired
- TOrderTaskService orderTaskService;
- @Autowired
- TJoinpayMchService joinpayMchService;
- @Autowired
- TShandeMchService shandeMchService;
- @Autowired
- THuifuMchService huifuMchService;
- @Autowired
- TEquipmentService equipmentService;
- @Autowired
- EsTOrderService esTOrderService;
- @Autowired
- TSzsmWxService szsmWxService;
- @Autowired
- WechatPayInfoService wechatPayInfoService;
- @Autowired
- private THuifuTempOrderService huifuTempOrderService;
- @Autowired
- private TOrderDetailsService orderDetailsService;
- @ApiOperation(value = "测试feign")
- @GetMapping("/testFeign")
- public ResponseModel<?> testFeign(String id) {
- return szwlFeign.testGetAdmin(id);
- }
- /**
- * 合并付款接口,根据终端跳转微信或支付宝
- *
- * @param req
- * @param resp
- * @return
- * @throws Exception
- */
- @ApiOperation(value = "请求在线支付 主扫")
- @RequestMapping("/aliPay")
- public RedirectView alipayforward(String wx, String zfb, HttpServletRequest req, HttpServletResponse resp) throws Exception {
- String userAgent = req.getHeader("User-Agent");
- RedirectView redirectTarget = new RedirectView();
- redirectTarget.setContextRelative(true);
- if (userAgent.contains("MicroMessenger")) { // 微信
- redirectTarget.setUrl(wx);
- } else if (userAgent.contains("AlipayClient")) { // 支付宝
- redirectTarget.setUrl(zfb);
- } else {
- throw new BizException(ResponseCodesEnum.A0001, "请使用支付宝或微信扫码!");
- }
- return redirectTarget;
- }
- /**
- * 请求在线支付 主扫 优惠码 盲盒
- *
- * @param clientId 设备client id
- * @param productName 商品名称
- * @param frpCode 支付方式 支付宝:ALIPAY_NATIVE , 微信:WEIXIN_NATIVE
- * @param pri 有值代表是盲盒
- * @return
- */
- @ApiOperation(value = "请求在线支付 主扫")
- @GetMapping("/uniPay")
- public Object uniPay(String code, String clientId, String productName, String frpCode, String pri) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null || equipment.getId() == null) {
- return JsonMessage.error("找不到设备");
- }
- //验证优惠码 code=null 则不选用优惠码
- TPromoCode promoCode = new TPromoCode();
- if (StringUtils.isNotEmpty(code)) {
- //有优惠码,需要对优惠码进行验证
- ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- promoCode = tPromoCode;
- if (tPromoCode == null || tPromoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- if (promoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- Date lastUseDate = null;
- if (promoCode != null && promoCode.getId() != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
- //过期
- return JsonMessage.success("4");
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return JsonMessage.success("2");
- }
- if (!promoCode.getAdminId().equals("1")) {
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return JsonMessage.success("3");
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return JsonMessage.success("0");
- }
- if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- //0折
- return JsonMessage.success("0");
- }
- }
- // 支付方式
- if (!frpCode.equals("ALIPAY_NATIVE") && !frpCode.equals("WEIXIN_NATIVE")) {
- return JsonMessage.error("参数错误");
- }
- Long equipmentId = equipment.getId();
- // 查找商品
- ResponseModel<TProduct> product1 = szwlFeign.getProduct(String.valueOf(equipmentId), productName);
- TProduct product = product1.getData();
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- BigDecimal price = product.getRmbPrice();
- if (StringUtils.isNotEmpty(pri)) {
- price = new BigDecimal(pri);
- }
- // 计算折扣后的价格
- if (StringUtils.isNotEmpty(code)) {
- BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
- if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
- if (price.compareTo(discount) > 0) {
- // 如果 price 大于 discount,从 price 中减去 discount
- price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
- } else {
- // 如果 price 小于等于 discount,将 price 设置为 0
- // price = BigDecimal.ZERO;
- return JsonMessage.success("0");
- }
- } else {
- price = product.getRmbPrice().multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- }
- // 判断价格是否小于等于0
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- return JsonMessage.error("商品价格异常");
- }
- // 生成订单编号
- Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
- String sn = orderService.initSn(client6);
- // 获取关联设备的分销
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- if (proportion == null || proportion.getId() == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- // 支付方式:0或null为汇聚,1为汇付支付
- String payPlatform = admin.getPayPlatform();
- String companyType = admin.getCompanyType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
- if (!(acctSplitBunch.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- } else {
- altInfo = getAltInfo(proportion, price);
- if (!(altInfo.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- }
- String orderNo = sn;
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- String productDesc = "";
- String commonParameter = "";
- String returnUrl = null;
- String notifyUrl = JoinpayConstant.Notify_Url;
- String isShowPic = "1";
- String openId = null;
- String authCode = null;
- String appid = null;
- String transactionModel = null;
- String tradeMerchantNo = admin.getTradeMerchantNo();
- String buyerId = null;
- String isAlt = "1";
- String altType = "11";
- String altUrl = null;
- BigDecimal marketingAmount = null;
- if (StringUtils.isNotEmpty(pri)) {
- productName = "棉花糖";
- }
- Integer productNumber = 1;
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn);
- order.setProductId(product.getId());
- order.setProductNo(product.getNo());
- order.setProductName(productName);
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode);
- order.setAltInfo(altInfo.toString());
- order.setStatus(0);
- order.setType(admin.getType());
- order.setProductNumber(productNumber);
- order.setCompanyType(admin.getCompanyType());
- order.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- order.setPersonageProportion(proportion.getPersonageProportion());
- order.setPersonageId(proportion.getPersonageId());
- }
- order.setPayPlatform(payPlatform);
- // 订单明细表
- TOrderDetails orderDetails = new TOrderDetails();
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setAdminId(admin.getId());
- orderDetails.setEquipmentId(equipmentId);
- orderDetails.setCreateDate(new Date());
- orderDetails.setOrderSn(sn);
- orderDetails.setPrice(price);
- orderDetails.setProductName(productName);
- orderDetails.setProductNo(product.getNo());
- orderDetails.setProductNumber(productNumber);
- orderDetails.setAmount(price);
- orderDetails.setRefundStatus("0");
- orderDetails.setCompanyType(companyType);
- orderDetails.setMachineType(equipment.getMachineType());
- String productName1 = productName + "-" + equipment.getName() + "-" + client6;
- String result = null;
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- // 汇付分账参数
- order.setAcctSplitBunch(acctSplitBunch.toString());
- if (frpCode.equals("WEIXIN_NATIVE")) {
- //添加到汇付临时表
- // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
- // String[] ignoreProperties = {"id"};
- // String id = HuifuUtils.inithuifuTempId();
- // tHuifuTempOrder.setId(id);
- // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
- // huifuTempOrderService.save(tHuifuTempOrder);
- // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- // result = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
- // } else {
- // result = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
- // }
- // log.info("返回链接:{}", result);
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- result = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn;
- } else {
- result = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn;
- }
- String qrcode = toQrcode(result);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn);
- kindData.put("rd_Pic", qrcode);
- orderService.save(order);
- orderDetailsService.save(orderDetails);
- return JsonMessage.success(kindData.toString());
- }
- // 汇付支付
- try {
- result = huifuMchService.uniPay(
- orderNo, amount, productName1, productDesc,
- notifyUrl, frpCode, openId, appid, acctSplitBunch, companyType
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- if (StrUtil.isEmpty(result)) {
- return JsonMessage.error("找不到支付图片");
- }
- String qrcode = toQrcode(result);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn);
- kindData.put("rd_Pic", qrcode);
- orderService.save(order);
- orderDetailsService.save(orderDetails);
- return JsonMessage.success(kindData.toString());
- } else {
- try {
- result = joinpayMchService.uniPay(
- orderNo, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- // 汇聚支付支付申请返回支付二维码图片
- String rd_Pic = resultJson.getString("rd_Pic");
- if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
- return JsonMessage.error("找不到支付图片");
- }
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn);
- kindData.put("rd_Pic", rd_Pic);
- orderService.save(order);
- orderDetailsService.save(orderDetails);
- return JsonMessage.success(kindData.toString());
- }
- }
- /**
- * 被扫支付 + 优惠码 盲盒
- *
- * @param code 优惠码
- * @param clientId 设备client id
- * @param productName 商品名称
- * @param frpCode 支付方式 支付宝:ALIPAY_CARD , 微信:WEIXIN_CARD
- * @return
- */
- @ApiOperation(value = "请求在线支付 被扫支付")
- @GetMapping("/CardPay")
- public Object CardPay(String code, String clientId, String productName, String frpCode, String authCode, String pri) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null || equipment.getId() == null) {
- return JsonMessage.error("找不到设备");
- }
- //验证优惠码 code=null 则不选用优惠码
- TPromoCode promoCode = new TPromoCode();
- if (StringUtils.isEmpty(code)) {
- //没有优惠码
- } else {
- //有优惠码,需要对优惠码进行验证
- ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- promoCode = tPromoCode;
- if (tPromoCode == null || tPromoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- if (promoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- Date lastUseDate = null;
- if (promoCode != null && promoCode.getId() != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
- //过期
- return JsonMessage.success("4");
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return JsonMessage.success("2");
- }
- if (!promoCode.getAdminId().equals("1")) {
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return JsonMessage.success("3");
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return JsonMessage.success("0");
- }
- if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- //0折
- return JsonMessage.success("0");
- }
- }
- if (!frpCode.equals("ALIPAY_CARD") && !frpCode.equals("WEIXIN_CARD")) {
- return JsonMessage.error("参数错误");
- }
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- //查找商品
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- BigDecimal price = product.getRmbPrice();
- if (StringUtils.isNotEmpty(pri)) {
- price = new BigDecimal(pri);
- }
- if (StringUtils.isNotEmpty(code)) {
- BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
- if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
- if (price.compareTo(discount) > 0) {
- // 如果 price 大于 discount,从 price 中减去 discount
- price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
- } else {
- // 如果 price 小于等于 discount,将 price 设置为 0
- // price = BigDecimal.ZERO;
- return JsonMessage.success("0");
- }
- } else {
- price = product.getRmbPrice().multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- }
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- return JsonMessage.error("商品价格异常");
- }
- Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
- String sn = orderService.initSn(client6);
- // 获取关联设备的分销
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- if (proportion == null || proportion.getId() == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- // 支付方式:0或null为汇聚,1为汇付支付
- String payPlatform = admin.getPayPlatform();
- String companyType = admin.getCompanyType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
- if (!(acctSplitBunch.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- } else {
- altInfo = getAltInfo(proportion, price);
- if (!(altInfo.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- }
- String orderNo = sn;
- Integer productNumber = 1;
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- String productDesc = "";
- String commonParameter = "";
- String returnUrl = null;
- String notifyUrl = JoinpayConstant.Notify_Url;
- String isShowPic = "1";
- String openId = null;
- String appid = null;
- String transactionModel = null;
- String tradeMerchantNo = admin.getTradeMerchantNo();
- String buyerId = null;
- String isAlt = "1";
- String altType = "11";
- String altUrl = null;
- if (StringUtils.isNotEmpty(pri)) {
- productName = "棉花糖";
- }
- BigDecimal marketingAmount = null;
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn);
- order.setProductId(product.getId());
- order.setProductNo(product.getNo());
- order.setProductName(productName);
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode);
- order.setAltInfo(altInfo.toString());
- order.setStatus(0);
- order.setType(admin.getType());
- order.setProductNumber(productNumber);
- order.setCompanyType(admin.getCompanyType());
- order.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- order.setPersonageProportion(proportion.getPersonageProportion());
- order.setPersonageId(proportion.getPersonageId());
- }
- order.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setIsSettlement("0");
- }
- // 订单明细表
- TOrderDetails orderDetails = new TOrderDetails();
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setAdminId(admin.getId());
- orderDetails.setEquipmentId(equipmentId);
- orderDetails.setCreateDate(new Date());
- orderDetails.setOrderSn(sn);
- orderDetails.setPrice(price);
- orderDetails.setProductName(productName);
- orderDetails.setProductNo(product.getNo());
- orderDetails.setProductNumber(productNumber);
- orderDetails.setAmount(price);
- orderDetails.setRefundStatus("0");
- orderDetails.setCompanyType(companyType);
- orderDetails.setMachineType(equipment.getMachineType());
- // String client6 = clientId.substring(clientId.length() - 6);
- String productName1 = productName + "-" + equipment.getName() + "-" + client6;
- String result = null;
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setAcctSplitBunch(acctSplitBunch.toString());
- try {
- result = huifuMchService.cardPay(
- orderNo, amount, productName1, notifyUrl, authCode, acctSplitBunch, companyType
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- if (result.equals(HuifuConstant.RESP_CODE_0)) {
- orderService.save(order);
- orderDetailsService.save(orderDetails);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn);
- return JsonMessage.success(kindData.toString());
- } else {
- return JsonMessage.error("申请支付失败");
- }
- } else {
- try {
- result = joinpayMchService.uniPay(
- orderNo, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- String raCode = resultJson.getString("ra_Code");
- if (raCode.equals("100") || raCode.equals("102")) {
- orderService.save(order);
- orderDetailsService.save(orderDetails);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn);
- return JsonMessage.success(kindData.toString());
- } else {
- return JsonMessage.error("申请支付失败");
- }
- }
- }
- /**
- * 请求在线支付 主扫 优惠码 二码合一
- *
- * @param clientId 设备client id
- * @param productName 商品名称
- * @param pri DIY花型价格
- * @return
- */
- @ApiOperation(value = "请求在线支付 二码合一")
- @GetMapping("/twoPayCode")
- public Object twoPayCode(String code, String clientId, String productName, String pri) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null || equipment.getId() == null) {
- return JsonMessage.error("找不到设备");
- }
- //验证优惠码 code=null 则不选用优惠码
- TPromoCode promoCode = new TPromoCode();
- if (StringUtils.isEmpty(code)) {
- //没有优惠码
- } else {
- //有优惠码,需要对优惠码进行验证
- ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- promoCode = tPromoCode;
- if (tPromoCode == null || tPromoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- if (promoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- Date lastUseDate = null;
- if (promoCode != null && promoCode.getId() != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
- //过期
- return JsonMessage.success("4");
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return JsonMessage.success("2");
- }
- if (!promoCode.getAdminId().equals("1")) {
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return JsonMessage.success("3");
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return JsonMessage.success("0");
- }
- if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- //0折
- return JsonMessage.success("0");
- }
- }
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- //查找商品
- BigDecimal price;
- Long productId = null;
- // A99:DIY花型
- String productNo = "A99";
- if (StringUtils.isEmpty(pri)) {
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- price = product.getRmbPrice();
- productId = product.getId();
- productNo = product.getNo();
- } else {
- price = new BigDecimal(pri);
- }
- if (StringUtils.isNotEmpty(code)) {
- BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
- if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
- if (price.compareTo(discount) > 0) {
- // 如果 price 大于 discount,从 price 中减去 discount
- price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
- } else {
- // 如果 price 小于等于 discount,将 price 设置为 0
- // price = BigDecimal.ZERO;
- return JsonMessage.success("0");
- }
- } else {
- price = price.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- }
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- return JsonMessage.error("商品价格异常");
- }
- Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
- String sn1 = orderService.initSn(client6);
- String sn2 = orderService.initSn(client6);
- // 获取关联设备的分销
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- if (proportion == null || proportion.getId() == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- // 支付方式:0或null为汇聚,1为汇付支付
- String payPlatform = admin.getPayPlatform();
- String companyType = admin.getCompanyType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
- if (!(acctSplitBunch.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- } else {
- altInfo = getAltInfo(proportion, price);
- if (!(altInfo.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- }
- String orderNo1 = sn1;
- String orderNo2 = sn2;
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- String productDesc = "";
- String commonParameter = "";
- String returnUrl = null;
- String notifyUrl = JoinpayConstant.Notify_Url;
- String isShowPic = "1";
- String openId = null;
- String authCode = null;
- String appid = null;
- String transactionModel = null;
- String tradeMerchantNo = admin.getTradeMerchantNo();
- String buyerId = null;
- String isAlt = "1";
- String altType = "11";
- String altUrl = null;
- BigDecimal marketingAmount = null;
- String frpCode1 = "WEIXIN_NATIVE";
- String frpCode2 = "ALIPAY_NATIVE";
- Integer productNumber = 1;
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- order.setProductId(productId);
- order.setProductNo(productNo);
- order.setProductName(productName);
- order.setProductNumber(productNumber);
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode1);
- order.setAltInfo(altInfo.toString());
- order.setStatus(0);
- order.setType(admin.getType());
- order.setCompanyType(companyType);
- order.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- order.setPersonageProportion(proportion.getPersonageProportion());
- order.setPersonageId(proportion.getPersonageId());
- }
- order.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setIsSettlement("0");
- }
- TOrder order2 = new TOrder();
- order2.setId(IDGenerator.orderID());
- order2.setCreateDate(new Date());
- order2.setModifyDate(new Date());
- order2.setAdminId(admin.getId());
- order2.setSn(sn2);
- order2.setProductId(productId);
- order2.setProductNo(productNo);
- order2.setProductName(productName);
- order2.setProductNumber(productNumber);
- order2.setPrice(price);
- order2.setClientId(equipment.getClientId());
- order2.setEquipmentId(equipmentId);
- order2.setFrpCode(frpCode2);
- order2.setAltInfo(altInfo.toString());
- order2.setStatus(0);
- order2.setType(admin.getType());
- order2.setPayPlatform(payPlatform);
- order2.setCompanyType(companyType);
- order2.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- order2.setPersonageProportion(proportion.getPersonageProportion());
- order2.setPersonageId(proportion.getPersonageId());
- }
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order2.setIsSettlement("0");
- }
- // 订单明细表
- TOrderDetails orderDetails = new TOrderDetails();
- orderDetails.setAdminId(admin.getId());
- orderDetails.setEquipmentId(equipmentId);
- orderDetails.setCreateDate(new Date());
- orderDetails.setPrice(price);
- orderDetails.setProductName(productName);
- orderDetails.setProductNo(productNo);
- orderDetails.setProductNumber(productNumber);
- orderDetails.setAmount(price);
- orderDetails.setCompanyType(companyType);
- orderDetails.setRefundStatus("0");
- orderDetails.setMachineType(equipment.getMachineType());
- // String client6 = clientId.substring(clientId.length() - 6);
- String productName1 = productName + "-" + equipment.getName() + "-" + client6;
- String result = null;
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- // 汇付分账参数
- order.setAcctSplitBunch(acctSplitBunch.toString());
- order2.setAcctSplitBunch(acctSplitBunch.toString());
- //添加到汇付临时表,微信
- // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
- // String[] ignoreProperties = {"id"};
- // String id = HuifuUtils.inithuifuTempId();
- // tHuifuTempOrder.setId(id);
- // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
- // huifuTempOrderService.save(tHuifuTempOrder);
- // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- // result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
- // } else {
- // result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
- // }
- String result1 = "";
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- } else {
- result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- }
- // URL编码
- try {
- result1 = URLEncoder.encode(result1, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- // 支付宝
- try {
- result = huifuMchService.uniPay(
- sn2, amount, productName1, productDesc,
- notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- if (StrUtil.isEmpty(result)) {
- return JsonMessage.error("找不到支付图片");
- }
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
- System.out.println(code1);
- String qrcode = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", qrcode);
- orderService.save(order);
- orderDetails.setOrderSn(sn1);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetailsService.save(orderDetails);
- orderDetails.setOrderSn(sn2);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetailsService.save(orderDetails);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- } else {
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode1,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- String rc_Result1 = resultJson.getString("rc_Result");
- String result1 = null;
- try {
- result1 = joinpayMchService.uniPay(
- orderNo2, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode2,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson1 = JSONObject.parseObject(result1);
- String rc_Result2 = resultJson1.getString("rc_Result");
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/" + "aliPay?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
- String rd_Pic = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", rd_Pic);
- orderService.save(order);
- orderDetails.setOrderSn(sn1);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetailsService.save(orderDetails);
- orderDetails.setOrderSn(sn2);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetailsService.save(orderDetails);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- }
- }
- @ApiOperation(value = "购物车 请求在线支付 二码合一")
- @PostMapping("/carsPay")
- public Object carsPay(String clientId, @RequestBody Map<String, String> productNameMap) {
- if (productNameMap == null) {
- return JsonMessage.error("数据出错");
- }
- StringBuffer note = new StringBuffer();
- StringBuffer productName = new StringBuffer();
- String productNo = "";
- Map<String, Integer> productMap = new HashMap<>();
- Integer productNumber = 0;
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null || equipment.getId() == null) {
- return JsonMessage.error("找不到设备");
- }
- BigDecimal price = new BigDecimal("0.00");
- TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
- if (equipmentDesc == null || equipmentDesc.getEquipmentId() == null || equipmentDesc.getPayType() == null || equipmentDesc.getPayType().equals("0")) {
- // 1、type=0,原始设定,没有第二件半价
- for (String key : productNameMap.keySet()) {
- String entryValue = String.valueOf(productNameMap.get(key));
- List<String> value = JSON.parseArray(entryValue, String.class);
- boolean hasDuplicate = hasDuplicateValue(value);
- if (hasDuplicate) {
- return JsonMessage.error("优惠码输入重复,单个商品只能使用一个优惠码");
- }
- List<TPromoCode> promoCodeList = new ArrayList<>();
- // 1、校验优惠码
- if (value.size() > 0) {
- for (String code : value) {
- if (!code.equals("0")) {
- TPromoCode promoCode;
- ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- promoCode = tPromoCode;
- if (tPromoCode == null || tPromoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- Date lastUseDate = null;
- if (promoCode != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
- //过期
- return JsonMessage.success("4");
- }
- if (promoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return JsonMessage.success("2");
- }
- if (!promoCode.getAdminId().equals("1")) {
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return JsonMessage.success("3");
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return JsonMessage.success("0");
- }
- // if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- // //0折
- // return JsonMessage.success("0");
- // }
- promoCodeList.add(promoCode);
- }
- }
- }
- String[] productNum = key.split("-");
- String productNamea = productNum[0];
- String num = productNum[1];
- productMap.put(productNamea, Integer.valueOf(num));
- productNumber += Integer.valueOf(num);
- productName.append(productNamea).append("x").append(num).append(",");
- //确定价格,然后叠加
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- // note.append(productNamea).append("-").append(product.getNo()).append(":");
- BigDecimal productPrice = product.getRmbPrice();
- productNo = product.getNo();
- if (promoCodeList.size() > 0) {
- //有优惠码
- BigDecimal onePrice = new BigDecimal("0.00");
- Map<BigDecimal, Integer> priceMap = new HashMap<>();
- int i;
- for (i = 0; i < promoCodeList.size(); i++) {
- BigDecimal discount = BigDecimal.valueOf(promoCodeList.get(i).getDiscount()).setScale(2, RoundingMode.HALF_DOWN);
- BigDecimal price1 = new BigDecimal(0.0);
- TPromoCode tPromoCode = promoCodeList.get(i);
- if (StringUtils.isNotEmpty(tPromoCode.getType()) && tPromoCode.getType().equals("1")) {
- if (productPrice.compareTo(discount) > 0) {
- // 如果 price 大于 discount,从 price 中减去 discount
- price1 = productPrice.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
- } else {
- // 如果 price 小于等于 discount,将 price 设置为 0
- price1 = BigDecimal.ZERO;
- }
- } else {
- if (tPromoCode.getDiscount() == 0) {
- price1 = BigDecimal.ZERO;
- } else {
- price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- }
- price = price.add(price1);
- // onePrice = onePrice.add(price1);
- if (priceMap.containsKey(price1)) {
- priceMap.put(price1, priceMap.get(price1) + 1);
- } else {
- priceMap.put(price1, 1);
- }
- }
- if (i < Integer.valueOf(num)) {
- int a = Integer.valueOf(num) - i;
- BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price2);
- // onePrice = onePrice.add(price2);
- priceMap.put(price2, a);
- }
- for (BigDecimal priceKey : priceMap.keySet()) {
- note.append(productNamea).append("-").append(product.getNo()).append("-").append(RandomUtil.randomNumbers(5)).append(":");
- note.append(priceKey).append("-").append(priceMap.get(priceKey)).append(",");
- }
- } else {
- //1,type=0,原始设定,没有第二件半价
- int a = Integer.valueOf(num);
- BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price2);
- note.append(productNamea).append("-").append(product.getNo()).append(":");
- note.append(price2).append("-").append(num).append(",");
- }
- }
- } else {
- //2,type=1,第二件半价
- //2.1 判定是否有第二件,有多少个第二件半价
- for (String key : productNameMap.keySet()) {
- String[] productNum = key.split("-");
- String productNamea = productNum[0];
- String num = productNum[1];
- productMap.put(productNamea, Integer.valueOf(num));
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
- productNo = product.getNo();
- BigDecimal productPrice = product.getRmbPrice();
- productName.append(productNamea).append("x").append(num).append(",");
- note.append(productNamea).append("-").append(product.getNo()).append(":");
- switch (num) {
- case "1":
- //1个 0个半价
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- case "2":
- //2个 1个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- note.append(price).append("-").append(num).append(",");
- break;
- case "3":
- //3个 1个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- case "4":
- //4个 2个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- note.append(price).append("-").append(num).append(",");
- break;
- case "5":
- //5个 2个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- }
- }
- }
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- //查找商品
- if (BigDecimal.ZERO.compareTo(price) == 0) {
- return JsonMessage.success("0");
- }
- if (BigDecimal.ZERO.compareTo(price) > 0) {
- return JsonMessage.error("商品价格异常");
- }
- Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
- String sn1 = orderService.initSn(client6);
- String sn2 = orderService.initSn(client6);
- // 获取关联设备的分销
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- if (proportion == null || proportion.getId() == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- // 支付方式:0或null为汇聚,1为汇付支付
- String payPlatform = admin.getPayPlatform();
- String companyType = admin.getCompanyType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
- if (!(acctSplitBunch.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- } else {
- altInfo = getAltInfo(proportion, price);
- if (!(altInfo.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- }
- String orderNo1 = sn1;
- String orderNo2 = sn2;
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- String productDesc = "";
- String commonParameter = "";
- String returnUrl = null;
- String notifyUrl = JoinpayConstant.Notify_Url;
- String isShowPic = "1";
- String openId = null;
- String authCode = null;
- String appid = null;
- String transactionModel = null;
- String tradeMerchantNo = admin.getTradeMerchantNo();
- String buyerId = null;
- String isAlt = "1";
- String altType = "11";
- String altUrl = null;
- BigDecimal marketingAmount = null;
- String frpCode1 = "WEIXIN_NATIVE";
- String frpCode2 = "ALIPAY_NATIVE";
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- // 去掉后面的逗号
- order.setProductNo(productNo);
- if (productNumber == 1) {
- productName.delete(productName.length() - 3, productName.length());
- } else {
- productName.deleteCharAt(productName.length() - 1);
- }
- order.setProductName(productName.toString());
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode1);
- order.setAltInfo(altInfo.toString());
- order.setProductNumber(productNumber);
- order.setStatus(0);
- order.setType(admin.getType());
- order.setCompanyType(companyType);
- order.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- order.setPersonageProportion(proportion.getPersonageProportion());
- order.setPersonageId(proportion.getPersonageId());
- }
- order.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setIsSettlement("0");
- }
- order.setNote(note.toString());
- TOrder order2 = new TOrder();
- order2.setId(IDGenerator.orderID());
- order2.setCreateDate(new Date());
- order2.setModifyDate(new Date());
- order2.setAdminId(admin.getId());
- order2.setSn(sn2);
- order2.setProductName(productName.toString());
- order2.setProductNo(productNo);
- order2.setPrice(price);
- order2.setClientId(equipment.getClientId());
- order2.setEquipmentId(equipmentId);
- order2.setFrpCode(frpCode2);
- order2.setAltInfo(altInfo.toString());
- order2.setStatus(0);
- order2.setProductNumber(productNumber);
- order2.setType(admin.getType());
- order2.setCompanyType(companyType);
- order2.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- order2.setPersonageProportion(proportion.getPersonageProportion());
- order2.setPersonageId(proportion.getPersonageId());
- }
- order2.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order2.setIsSettlement("0");
- }
- order2.setNote(note.toString());
- // 订单明细表
- TOrderDetails orderDetails = new TOrderDetails();
- orderDetails.setAdminId(admin.getId());
- orderDetails.setEquipmentId(equipmentId);
- orderDetails.setCreateDate(new Date());
- orderDetails.setCompanyType(companyType);
- orderDetails.setRefundStatus("0");
- orderDetails.setMachineType(equipment.getMachineType());
- String productName1 = "";
- if (productNumber > 1) {
- if (equipment.getMachineType() == null || equipment.getMachineType().equals("0")) {
- productName1 = "棉花糖-" + equipment.getName() + "-" + client6;
- } else {
- productName1 = "爆米花-" + equipment.getName() + "-" + client6;
- }
- } else {
- productName1 = productName + "-" + equipment.getName() + "-" + client6;
- }
- Map<String, String> map = new HashMap<>();
- String[] products = order.getNote().split(",");
- for (String product : products) {
- String[] parts = product.split(":");
- // 商品名称-商品编号
- String key = parts[0];
- // 商品单价-商品数量
- String value = parts[1];
- map.put(key, value);
- }
- String result = null;
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- // 汇付分账参数
- order.setAcctSplitBunch(acctSplitBunch.toString());
- order2.setAcctSplitBunch(acctSplitBunch.toString());
- //添加到汇付临时表,微信
- // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
- // String[] ignoreProperties = {"id"};
- // String id = HuifuUtils.inithuifuTempId();
- // tHuifuTempOrder.setId(id);
- // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
- // huifuTempOrderService.save(tHuifuTempOrder);
- // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- // result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
- // } else {
- // result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
- // }
- String result1 = "";
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- } else {
- result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- }
- try {
- result1 = URLEncoder.encode(result1, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- // 支付宝
- try {
- result = huifuMchService.uniPay(
- sn2, amount, productName1, productDesc,
- notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- if (StrUtil.isEmpty(result)) {
- return JsonMessage.error("找不到支付图片");
- }
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
- String qrcode = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", qrcode);
- for (String key : map.keySet()) {
- // key:"玫瑰精灵-A01",value:"0.50-1"
- String value = map.get(key);
- String[] GoodsInfo = key.split("-");
- String[] GoodsValue = value.split("-");
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setProductName(GoodsInfo[0]);
- orderDetails.setProductNo(GoodsInfo[1]);
- orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
- orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
- orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn1);
- orderDetailsService.save(orderDetails);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn2);
- orderDetailsService.save(orderDetails);
- }
- orderService.save(order);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- } else {
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode1,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- String rc_Result1 = resultJson.getString("rc_Result");
- String result1 = null;
- try {
- result1 = joinpayMchService.uniPay(
- orderNo2, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode2,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson1 = JSONObject.parseObject(result1);
- String rc_Result2 = resultJson1.getString("rc_Result");
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://app.sunzee.com.cn/" + "/api/order/aliPay.htm?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
- String rd_Pic = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", rd_Pic);
- for (String key : map.keySet()) {
- // key:"玫瑰精灵-A01",value:"0.50-1"
- String value = map.get(key);
- String[] GoodsInfo = key.split("-");
- String[] GoodsValue = value.split("-");
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setProductName(GoodsInfo[0]);
- orderDetails.setProductNo(GoodsInfo[1]);
- orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
- orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
- orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn1);
- orderDetailsService.save(orderDetails);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn2);
- orderDetailsService.save(orderDetails);
- }
- orderService.save(order);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- }
- }
- @ApiOperation(value = "购物车 微信小程序支付")
- @PostMapping("/carsPayXCX")
- public Object carsPayXCX(String clientId, String id, String coupons, @RequestBody Map<String, String> productNameMap) {
- if (productNameMap == null) {
- return JsonMessage.error("数据出错");
- }
- StringBuffer note = new StringBuffer();
- StringBuffer productName = new StringBuffer();
- String productNo = "";
- Map<String, Integer> productMap = new HashMap<>();
- Integer productNumber = 0;
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null || equipment.getId() == null) {
- return JsonMessage.error("找不到设备");
- }
- BigDecimal price = new BigDecimal("0.00");
- List<TPromoCode> promoCodeAll = new ArrayList<>();
- TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
- if (StringUtils.isNotEmpty(equipmentDesc.getStatus())) {
- if (equipmentDesc.getStatus().equals("1")) {
- return JsonMessage.error("设备在做糖,请稍后再进行支付");
- }
- }
- if (equipmentDesc == null || equipmentDesc.getEquipmentId() == null || equipmentDesc.getPayType() == null || equipmentDesc.getPayType().equals("0")) {
- //1,type=0,原始设定,没有第二件半价
- for (String key : productNameMap.keySet()) {
- String entryValue = String.valueOf(productNameMap.get(key));
- List<String> value = JSON.parseArray(entryValue, String.class);
- List<TPromoCode> promoCodeList = new ArrayList<>();
- //1,校验优惠码
- if (value.size() > 0) {
- for (String code : value) {
- if (!code.equals("0")) {
- TPromoCode promoCode = new TPromoCode();
- ResponseModel<TPromoCode> promoCode1 = szwlFeign.getPromoCode(code + "-" + equipment.getAdminId().toString());
- TPromoCode tPromoCode = promoCode1.getData();
- promoCode = tPromoCode;
- if (tPromoCode == null || tPromoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- //
- Date lastUseDate = null;
- if (promoCode != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
- //过期
- return JsonMessage.success("4");
- }
- if (promoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return JsonMessage.success("2");
- }
- if (!promoCode.getAdminId().equals("1")) {
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return JsonMessage.success("3");
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return JsonMessage.success("0");
- }
- if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- //0折
- return JsonMessage.success("0");
- }
- promoCodeList.add(promoCode);
- promoCodeAll.add(promoCode);
- }
- }
- }
- String[] productNum = key.split("-");
- String productNamea = productNum[0];
- String num = productNum[1];
- productMap.put(productNamea, Integer.valueOf(num));
- productNumber += Integer.valueOf(num);
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
- productNo = product.getNo();
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- productName.append(productNamea).append("x").append(num).append(",");
- String no = product.getNo();
- if (StringUtils.isEmpty(no)) {
- no = "A00";
- }
- note.append(no).append("-").append(productNamea).append("-").append(num).append(":");
- //确定价格,然后叠加R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
- BigDecimal productPrice = product.getRmbPrice();
- if (promoCodeList.size() > 0) {
- //有优惠码
- BigDecimal onePrice = new BigDecimal("0.00");
- int i;
- for (i = 0; i < promoCodeList.size(); i++) {
- TPromoCode tPromoCode = promoCodeList.get(i);
- BigDecimal discount = BigDecimal.valueOf(tPromoCode.getDiscount()).setScale(2, RoundingMode.HALF_DOWN);
- if (StringUtils.isEmpty(tPromoCode.getType()) || tPromoCode.getType().equals("0")) {
- //折扣优惠码
- BigDecimal price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price1);
- onePrice = onePrice.add(price1);
- } else {
- //折扣价优惠码
- BigDecimal price1 = productPrice.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price1);
- onePrice = onePrice.add(price1);
- }
- }
- if (i < Integer.valueOf(num)) {
- int a = Integer.valueOf(num) - i;
- BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price2);
- onePrice = onePrice.add(price2);
- }
- note.append(onePrice).append(",");
- } else {
- //1,type=0,原始设定,没有第二件半价
- int a = Integer.valueOf(num);
- BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price2);
- note.append(price2).append(",");
- }
- }
- } else {
- //2,type=1,第二件半价
- //2.1 判定是否有第二件,有多少个第二件半价
- for (String key : productNameMap.keySet()) {
- String entryValue = String.valueOf(productNameMap.get(key));
- List<String> value = JSON.parseArray(entryValue, String.class);
- String[] productNum = key.split("-");
- String productNamea = productNum[0];
- String num = productNum[1];
- productMap.put(productNamea, Integer.valueOf(num));
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
- productNo = product.getNo();
- BigDecimal productPrice = product.getRmbPrice();
- productName.append(productNamea).append("x").append(num).append(",");
- note.append(productNamea).append(num).append(":");
- switch (num) {
- case "1":
- //1个 0个半价
- price = price.add(productPrice);
- note.append(price).append(",");
- break;
- case "2":
- //2个 1个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- note.append(price).append(",");
- break;
- case "3":
- //3个 1个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- note.append(price).append(",");
- break;
- case "4":
- //4个 2个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- note.append(price).append(",");
- break;
- case "5":
- //5个 2个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- note.append(price).append(",");
- break;
- }
- }
- }
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- //查找商品
- Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
- String sn1 = orderService.initSn(client6);
- // 获取关联设备的分销
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- if (proportion == null || proportion.getId() == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- // 支付方式:0或null为汇聚,1为汇付支付
- String payPlatform = admin.getPayPlatform();
- String companyType = admin.getCompanyType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
- if (!(acctSplitBunch.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- } else {
- altInfo = getAltInfo(proportion, price);
- if (!(altInfo.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- }
- String orderNo1 = sn1;
- String productDesc = "";
- String commonParameter = "";
- String returnUrl = null;
- String notifyUrl = JoinpayConstant.Notify_Url;
- String isShowPic = "1";
- TSzsmWx szsmWx = szsmWxService.getById(id);
- String openId = szsmWx.getOpenId();
- String authCode = null;
- String appid = "wx5071443e63295c29";
- String transactionModel = null;
- String tradeMerchantNo = "777114600391409";
- String buyerId = null;
- String isAlt = "1";
- String altType = "11";
- String altUrl = null;
- BigDecimal priceTemp = price.setScale(2, RoundingMode.HALF_DOWN);
- List<TPromoCode> yhjList = new ArrayList<>();
- if (StringUtils.isNotEmpty(coupons)) {
- String[] cous = coupons.split(",");
- if (cous.length > 0) {
- for (int i = 0; i < cous.length; i++) {
- if (StringUtils.isNotEmpty(cous[i])) {
- TPromoCode yhj = R.getDataIfSuccess(szwlFeign.getYHJ(cous[i]));
- if (yhj != null && yhj.getId() != null) {
- String isUse = yhj.getIsUse();
- if (isUse.equals("1")) {
- return R.ok(yhj.getCode(), "优惠券已使用");
- }
- Date lastUseDate = yhj.getLastUseDate();
- Date date = new Date();
- if (date.getTime() > lastUseDate.getTime()) {
- return R.ok(yhj.getCode(), "优惠券已过期");
- }
- yhjList.add(yhj);
- }
- }
- }
- }
- }
- List<String> couponList = new ArrayList<>();
- //营销金额
- BigDecimal marketingAmount = null;
- if (yhjList.size() > 0) {
- for (TPromoCode yhj : yhjList) {
- if (yhj != null && yhj.getId() != null) {
- if (marketingAmount == null) {
- marketingAmount = new BigDecimal("0.00");
- }
- marketingAmount = marketingAmount.add(new BigDecimal(yhj.getDiscount()).setScale(2, RoundingMode.HALF_DOWN));
- couponList.add(String.valueOf(yhj.getCode()));
- if (marketingAmount.compareTo(price) >= 0) {
- marketingAmount = priceTemp.subtract(new BigDecimal("0.01"));
- price = new BigDecimal("0.01").setScale(2, RoundingMode.HALF_DOWN);
- break;
- } else {
- price = price.subtract(marketingAmount);
- }
- }
- }
- }
- String frpCode1 = "WEIXIN_XCX";
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- order.setProductDesc(JSONArray.toJSONString(productNameMap));
- // 去掉后面的逗号
- order.setProductNo(productNo);
- if (productNumber == 1) {
- productName.delete(productName.length() - 3, productName.length());
- } else {
- productName.deleteCharAt(productName.length() - 1);
- }
- order.setProductName(productName.toString());
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode1);
- order.setAltInfo(altInfo.toString());
- order.setStatus(0);
- order.setType(admin.getType());
- order.setMarketingAmount(marketingAmount);
- order.setProductNumber(productNumber);
- order.setCompanyType(companyType);
- order.setMachineType(equipment.getMachineType());
- if (couponList.size() > 0) {
- order.setCoupons(couponList.toString());
- }
- if (admin.getType() == 0) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- order.setPersonageProportion(proportion.getPersonageProportion());
- order.setPersonageId(proportion.getPersonageId());
- }
- order.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setIsSettlement("0");
- }
- order.setNote(note.toString());
- if (StringUtils.isNotEmpty(id)) {
- order.setWxId(Long.valueOf(id));
- }
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- order.setStatus(1);
- orderService.updateById(order);
- //修改优惠码状态
- if (promoCodeAll.size() > 0) {
- for (TPromoCode code : promoCodeAll) {
- szwlFeign.updatePromoCode(String.valueOf(code.getId()), "2");
- }
- }
- //发送远程命令到机器那边,让机器做糖
- equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("cardPayXCX", String.valueOf(productNameMap)).toString());
- return JsonMessage.success("支付成功");
- }
- // 订单明细表
- TOrderDetails orderDetails = new TOrderDetails();
- orderDetails.setAdminId(admin.getId());
- orderDetails.setEquipmentId(equipmentId);
- orderDetails.setCreateDate(new Date());
- orderDetails.setCompanyType(companyType);
- orderDetails.setRefundStatus("0");
- orderDetails.setMachineType(equipment.getMachineType());
- // String client6 = clientId.substring(clientId.length() - 6);
- String productName1 = "";
- if (productNumber > 1) {
- if (equipment.getMachineType() == null || equipment.getMachineType().equals("0")) {
- productName1 = "棉花糖-" + equipment.getName() + "-" + client6;
- } else {
- productName1 = "爆米花-" + equipment.getName() + "-" + client6;
- }
- } else {
- productName1 = productName + "-" + equipment.getName() + "-" + client6;
- }
- String result = null;
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setAcctSplitBunch(acctSplitBunch.toString());
- try {
- result = huifuMchService.uniPay(
- orderNo1, amount, productName1, productDesc,
- notifyUrl, frpCode1, openId, appid, acctSplitBunch, companyType
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- // 返回支付二维码图片
- if (result == null || StringUtils.isBlank(result)) {
- return JsonMessage.error("申请支付失败");
- }
- Map<String, String> map = new HashMap<>();
- map.put("sn", sn1);
- map.put("rc_Result", result);
- for (String key : productMap.keySet()) {
- Integer productNum = productMap.get(key);
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), key));
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setProductNo(product.getNo());
- orderDetails.setProductName(key);
- orderDetails.setPrice(product.getRmbPrice());
- orderDetails.setProductNumber(productNum);
- orderDetails.setAmount(product.getRmbPrice().multiply(new BigDecimal(productNum)));
- orderDetails.setOrderSn(sn1);
- orderDetailsService.save(orderDetails);
- }
- orderService.save(order);
- return JsonMessage.success(map);
- } else {
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode1,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- // 汇聚支付支付申请返回支付二维码图片
- String rc_Result = resultJson.getString("rc_Result");
- if (resultJson == null || StringUtils.isBlank(rc_Result)) {
- return JsonMessage.error("申请支付失败");
- }
- Map<String, String> map = new HashMap<>();
- map.put("sn", sn1);
- map.put("rc_Result", rc_Result);
- for (String key : productMap.keySet()) {
- Integer productNum = productMap.get(key);
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), key));
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setProductNo(product.getNo());
- orderDetails.setProductName(key);
- orderDetails.setPrice(product.getRmbPrice());
- orderDetails.setProductNumber(productNum);
- orderDetails.setAmount(product.getRmbPrice().multiply(new BigDecimal(productNum)));
- orderDetails.setOrderSn(sn1);
- orderDetailsService.save(orderDetails);
- }
- orderService.save(order);
- return JsonMessage.success(map);
- }
- }
- /**
- * 冰淇淋请求在线支付 主扫 优惠码 二码合一
- *
- * @param clientId 设备唯一编号
- * @param productName 商品名称:"冰淇淋-草莓酱,榛子碎"
- * @return
- */
- @ApiOperation(value = "请求在线支付 二码合一")
- @GetMapping("/iceCreamTwoPay")
- public Object iceCreamTwoPay(String code, String clientId, String productName) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null || equipment.getId() == null) {
- return JsonMessage.error("找不到设备");
- }
- //验证优惠码 code=null 则不选用优惠码
- TPromoCode promoCode = new TPromoCode();
- if (StringUtils.isEmpty(code)) {
- //没有优惠码
- } else {
- //有优惠码,需要对优惠码进行验证
- ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- promoCode = tPromoCode;
- if (tPromoCode == null || tPromoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- if (promoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- Date lastUseDate = null;
- if (promoCode != null && promoCode.getId() != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
- //过期
- return JsonMessage.success("4");
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return JsonMessage.success("2");
- }
- if (!promoCode.getAdminId().equals("1")) {
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return JsonMessage.success("3");
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return JsonMessage.success("0");
- }
- if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- //0折
- return JsonMessage.success("0");
- }
- }
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- // 查找商品
- String[] split = productName.split("-");
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), split[0]));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- // 处理后的商品名称
- String newProductName = split[0];
- // 冰淇淋价格
- BigDecimal price = product.getRmbPrice();
- // 商品ID
- Long productId = product.getId();
- // 冰淇淋编号
- String productNo = product.getNo();
- // 如果添加其他果酱和小料
- if (split.length > 1) {
- String[] split1 = split[1].split(",");
- String tempName = "(";
- for (String s : split1) {
- TProduct product1 = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), s));
- if (product1 == null) {
- return JsonMessage.error("找不到商品");
- }
- tempName = tempName + s + "、";
- price = price.add(product1.getRmbPrice());
- }
- tempName = tempName.substring(0, tempName.length() - 1) + ")";
- newProductName += tempName;
- }
- if (StringUtils.isNotEmpty(code)) {
- BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
- if (StringUtils.isNotEmpty(promoCode.getType()) && promoCode.getType().equals("1")) {
- if (price.compareTo(discount) > 0) {
- // 如果 price 大于 discount,从 price 中减去 discount
- price = price.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
- } else {
- // 如果 price 小于等于 discount,将 price 设置为 0
- // price = BigDecimal.ZERO;
- return JsonMessage.success("0");
- }
- } else {
- price = price.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- }
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- return JsonMessage.error("商品价格异常");
- }
- Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
- String sn1 = orderService.initSn(client6);
- String sn2 = orderService.initSn(client6);
- // 获取关联设备的分销
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- if (proportion == null || proportion.getId() == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- // 支付方式:0或null为汇聚,1为汇付支付
- String payPlatform = admin.getPayPlatform();
- String companyType = admin.getCompanyType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
- if (!(acctSplitBunch.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- } else {
- altInfo = getAltInfo(proportion, price);
- if (!(altInfo.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- }
- String orderNo1 = sn1;
- String orderNo2 = sn2;
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- String productDesc = "";
- String commonParameter = "";
- String returnUrl = null;
- String notifyUrl = JoinpayConstant.Notify_Url;
- String isShowPic = "1";
- String openId = null;
- String authCode = null;
- String appid = null;
- String transactionModel = null;
- String tradeMerchantNo = admin.getTradeMerchantNo();
- String buyerId = null;
- String isAlt = "1";
- String altType = "11";
- String altUrl = null;
- BigDecimal marketingAmount = null;
- String frpCode1 = "WEIXIN_NATIVE";
- String frpCode2 = "ALIPAY_NATIVE";
- Integer productNumber = 1;
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- order.setProductId(productId);
- order.setProductNo(productNo);
- order.setProductName(newProductName);
- order.setProductNumber(productNumber);
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode1);
- order.setAltInfo(altInfo.toString());
- order.setStatus(0);
- order.setType(admin.getType());
- order.setCompanyType(companyType);
- order.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- order.setPersonageProportion(proportion.getPersonageProportion());
- order.setPersonageId(proportion.getPersonageId());
- }
- order.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setIsSettlement("0");
- }
- TOrder order2 = new TOrder();
- order2.setId(IDGenerator.orderID());
- order2.setCreateDate(new Date());
- order2.setModifyDate(new Date());
- order2.setAdminId(admin.getId());
- order2.setSn(sn2);
- order2.setProductId(productId);
- order2.setProductNo(productNo);
- order2.setProductName(newProductName);
- order2.setProductNumber(productNumber);
- order2.setPrice(price);
- order2.setClientId(equipment.getClientId());
- order2.setEquipmentId(equipmentId);
- order2.setFrpCode(frpCode2);
- order2.setAltInfo(altInfo.toString());
- order2.setStatus(0);
- order2.setType(admin.getType());
- order2.setPayPlatform(payPlatform);
- order2.setCompanyType(companyType);
- order2.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- order2.setPersonageProportion(proportion.getPersonageProportion());
- order2.setPersonageId(proportion.getPersonageId());
- }
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order2.setIsSettlement("0");
- }
- // 订单明细表
- TOrderDetails orderDetails = new TOrderDetails();
- orderDetails.setAdminId(admin.getId());
- orderDetails.setEquipmentId(equipmentId);
- orderDetails.setCreateDate(new Date());
- orderDetails.setPrice(price);
- orderDetails.setProductName(newProductName);
- orderDetails.setProductNo(productNo);
- orderDetails.setProductNumber(productNumber);
- orderDetails.setAmount(price);
- orderDetails.setCompanyType(companyType);
- orderDetails.setRefundStatus("0");
- orderDetails.setMachineType(equipment.getMachineType());
- // String client6 = clientId.substring(clientId.length() - 6);
- String productName1 = "雪糕" + "-" + equipment.getName() + "-" + client6;
- String result = null;
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- // 汇付分账参数
- order.setAcctSplitBunch(acctSplitBunch.toString());
- order2.setAcctSplitBunch(acctSplitBunch.toString());
- //添加到汇付临时表,微信
- // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
- // String[] ignoreProperties = {"id"};
- // String id = HuifuUtils.inithuifuTempId();
- // tHuifuTempOrder.setId(id);
- // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
- // huifuTempOrderService.save(tHuifuTempOrder);
- // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- // result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
- // } else {
- // result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
- // }
- String result1 = "";
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- } else {
- result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- }
- try {
- result1 = URLEncoder.encode(result1, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- // 支付宝
- try {
- result = huifuMchService.uniPay(
- sn2, amount, productName1, productDesc,
- notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- if (StrUtil.isEmpty(result)) {
- return JsonMessage.error("找不到支付图片");
- }
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
- String qrcode = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", qrcode);
- orderService.save(order);
- orderDetails.setOrderSn(sn1);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetailsService.save(orderDetails);
- orderDetails.setOrderSn(sn2);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetailsService.save(orderDetails);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- } else {
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode1,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- String rc_Result1 = resultJson.getString("rc_Result");
- String result1 = null;
- try {
- result1 = joinpayMchService.uniPay(
- orderNo2, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode2,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson1 = JSONObject.parseObject(result1);
- String rc_Result2 = resultJson1.getString("rc_Result");
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/" + "aliPay?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
- String rd_Pic = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", rd_Pic);
- orderService.save(order);
- orderDetails.setOrderSn(sn1);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetailsService.save(orderDetails);
- orderDetails.setOrderSn(sn2);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetailsService.save(orderDetails);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- }
- }
- /**
- * 冰淇淋购物车支付
- *
- * @param clientId 设备唯一编号
- * @param productNameMap 商品信息:"冰淇淋-草莓酱,榛子碎-2": "[\"562278\",\"0\"]"
- * @return
- */
- @ApiOperation(value = "购物车 请求在线支付 二码合一")
- @PostMapping("/iceCreamCarsPay")
- public Object iceCreamCarsPay(String clientId, @RequestBody Map<String, String> productNameMap) {
- if (productNameMap == null) {
- return JsonMessage.error("数据出错");
- }
- StringBuffer note = new StringBuffer();
- StringBuffer productName = new StringBuffer();
- String productNo = "";
- Map<String, Integer> productMap = new HashMap<>();
- Integer productNumber = 0;
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null || equipment.getId() == null) {
- return JsonMessage.error("找不到设备");
- }
- BigDecimal price = new BigDecimal("0.00");
- TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
- if (equipmentDesc == null || equipmentDesc.getEquipmentId() == null || equipmentDesc.getPayType() == null || equipmentDesc.getPayType().equals("0")) {
- // 1、type=0,原始设定,没有第二件半价
- for (String key : productNameMap.keySet()) {
- String entryValue = String.valueOf(productNameMap.get(key));
- List<String> value = JSON.parseArray(entryValue, String.class);
- boolean hasDuplicate = hasDuplicateValue(value);
- if (hasDuplicate) {
- return JsonMessage.error("优惠码输入重复,单个商品只能使用一个优惠码");
- }
- List<TPromoCode> promoCodeList = new ArrayList<>();
- // 1、校验优惠码
- if (value.size() > 0) {
- for (String code : value) {
- if (!code.equals("0")) {
- TPromoCode promoCode;
- ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- promoCode = tPromoCode;
- if (tPromoCode == null || tPromoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- Date lastUseDate = null;
- if (promoCode != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
- //过期
- return JsonMessage.success("4");
- }
- if (promoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return JsonMessage.success("2");
- }
- if (!promoCode.getAdminId().equals("1")) {
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return JsonMessage.success("3");
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return JsonMessage.success("0");
- }
- // if (promoCode.getDiscount() != null && promoCode.getDiscount() == 0) {
- // //0折
- // return JsonMessage.success("0");
- // }
- promoCodeList.add(promoCode);
- }
- }
- }
- String[] products = key.split("-");
- String iceCreamName = products[0];
- String num = products[1];
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), iceCreamName));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- productNo = product.getNo();
- BigDecimal productPrice = product.getRmbPrice();
- // 如果加了果酱或者小料
- if (products.length > 2) {
- // 商品数
- num = products[2];
- // 加料
- String[] charge = products[1].split(",");
- String tempName = "(";
- for (String s : charge) {
- TProduct product1 = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), s));
- if (product1 == null) {
- return JsonMessage.error("找不到商品");
- }
- tempName = tempName + s + "、";
- productPrice = productPrice.add(product1.getRmbPrice());
- }
- tempName = tempName.substring(0, tempName.length() - 1) + ")";
- iceCreamName += tempName;
- }
- productMap.put(iceCreamName + "-" + productPrice, Integer.valueOf(num));
- productNumber += Integer.valueOf(num);
- productName.append(iceCreamName).append("x").append(num).append(",");
- //确定价格,然后叠加
- note.append(iceCreamName).append("-").append(product.getNo()).append(":");
- if (promoCodeList.size() > 0) {
- //有优惠码
- BigDecimal onePrice = new BigDecimal("0.00");
- Map<BigDecimal, Integer> priceMap = new HashMap<>();
- int i;
- for (i = 0; i < promoCodeList.size(); i++) {
- BigDecimal discount = BigDecimal.valueOf(promoCodeList.get(i).getDiscount()).setScale(2, RoundingMode.HALF_DOWN);
- BigDecimal price1 = new BigDecimal(0.0);
- TPromoCode tPromoCode = promoCodeList.get(i);
- if (StringUtils.isNotEmpty(tPromoCode.getType()) && tPromoCode.getType().equals("1")) {
- if (productPrice.compareTo(discount) > 0) {
- // 如果 price 大于 discount,从 price 中减去 discount
- price1 = productPrice.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
- } else {
- // 如果 price 小于等于 discount,将 price 设置为 0
- price1 = BigDecimal.ZERO;
- }
- } else {
- if (tPromoCode.getDiscount() == 0) {
- price1 = BigDecimal.ZERO;
- } else {
- price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- }
- // BigDecimal price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price1);
- onePrice = onePrice.add(price1);
- }
- if (i < Integer.valueOf(num)) {
- int a = Integer.valueOf(num) - i;
- BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price2);
- onePrice = onePrice.add(price2);
- }
- note.append(onePrice).append("-").append(num).append(",");
- } else {
- //1,type=0,原始设定,没有第二件半价
- int a = Integer.valueOf(num);
- BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price2);
- note.append(price2).append("-").append(num).append(",");
- }
- }
- } else {
- //2,type=1,第二件半价
- //2.1 判定是否有第二件,有多少个第二件半价
- for (String key : productNameMap.keySet()) {
- String[] products = key.split("-");
- String iceCreamName = products[0];
- String num = products[1];
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), iceCreamName));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- productNo = product.getNo();
- BigDecimal productPrice = product.getRmbPrice();
- // 如果加了果酱或者小料
- if (products.length > 2) {
- // 商品数
- num = products[2];
- // 加料
- String[] charge = products[1].split(",");
- String tempName = "(";
- for (String s : charge) {
- TProduct product1 = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), s));
- if (product1 == null) {
- return JsonMessage.error("找不到商品");
- }
- tempName = tempName + s + "、";
- productPrice = productPrice.add(product1.getRmbPrice());
- }
- tempName = tempName.substring(0, tempName.length() - 1) + ")";
- iceCreamName += tempName;
- }
- productMap.put(iceCreamName + "-" + productPrice, Integer.valueOf(num));
- productName.append(iceCreamName).append("x").append(num).append(",");
- note.append(iceCreamName).append("-").append(product.getNo()).append(":");
- switch (num) {
- case "1":
- //1个 0个半价
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- case "2":
- //2个 1个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- note.append(price).append("-").append(num).append(",");
- break;
- case "3":
- //3个 1个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- case "4":
- //4个 2个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- note.append(price).append("-").append(num).append(",");
- break;
- case "5":
- //5个 2个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- }
- }
- }
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- //查找商品
- if (BigDecimal.ZERO.compareTo(price) == 0) {
- return JsonMessage.success("0");
- }
- if (BigDecimal.ZERO.compareTo(price) > 0) {
- return JsonMessage.error("商品价格异常");
- }
- Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
- String sn1 = orderService.initSn(client6);
- String sn2 = orderService.initSn(client6);
- // 获取关联设备的分销
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- if (proportion == null || proportion.getId() == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- // 支付方式:0或null为汇聚,1为汇付支付
- String payPlatform = admin.getPayPlatform();
- String companyType = admin.getCompanyType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
- if (!(acctSplitBunch.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- } else {
- altInfo = getAltInfo(proportion, price);
- if (!(altInfo.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- }
- String orderNo1 = sn1;
- String orderNo2 = sn2;
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- String productDesc = "";
- String commonParameter = "";
- String returnUrl = null;
- String notifyUrl = JoinpayConstant.Notify_Url;
- String isShowPic = "1";
- String openId = null;
- String authCode = null;
- String appid = null;
- String transactionModel = null;
- String tradeMerchantNo = admin.getTradeMerchantNo();
- String buyerId = null;
- String isAlt = "1";
- String altType = "11";
- String altUrl = null;
- BigDecimal marketingAmount = null;
- String frpCode1 = "WEIXIN_NATIVE";
- String frpCode2 = "ALIPAY_NATIVE";
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- // 去掉后面的逗号
- order.setProductNo(productNo);
- if (productNumber == 1) {
- productName.delete(productName.length() - 3, productName.length());
- } else {
- productName.deleteCharAt(productName.length() - 1);
- }
- order.setProductName(productName.toString());
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode1);
- order.setAltInfo(altInfo.toString());
- order.setProductNumber(productNumber);
- order.setStatus(0);
- order.setType(admin.getType());
- order.setCompanyType(companyType);
- order.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- order.setPersonageProportion(proportion.getPersonageProportion());
- order.setPersonageId(proportion.getPersonageId());
- }
- order.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setIsSettlement("0");
- }
- order.setNote(note.toString());
- TOrder order2 = new TOrder();
- order2.setId(IDGenerator.orderID());
- order2.setCreateDate(new Date());
- order2.setModifyDate(new Date());
- order2.setAdminId(admin.getId());
- order2.setSn(sn2);
- order2.setProductName(productName.toString());
- order2.setProductNo(productNo);
- order2.setPrice(price);
- order2.setClientId(equipment.getClientId());
- order2.setEquipmentId(equipmentId);
- order2.setFrpCode(frpCode2);
- order2.setAltInfo(altInfo.toString());
- order2.setStatus(0);
- order2.setProductNumber(productNumber);
- order2.setType(admin.getType());
- order2.setCompanyType(companyType);
- order2.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- order2.setPersonageProportion(proportion.getPersonageProportion());
- order2.setPersonageId(proportion.getPersonageId());
- }
- order2.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order2.setIsSettlement("0");
- }
- order2.setNote(note.toString());
- // 订单明细表
- TOrderDetails orderDetails = new TOrderDetails();
- orderDetails.setAdminId(admin.getId());
- orderDetails.setEquipmentId(equipmentId);
- orderDetails.setCreateDate(new Date());
- orderDetails.setCompanyType(companyType);
- orderDetails.setRefundStatus("0");
- orderDetails.setMachineType(equipment.getMachineType());
- String productName1 = "雪糕x" + productNumber + "-" + equipment.getName() + "-" + client6;
- Map<String, String> map = new HashMap<>();
- String[] products = order.getNote().split(",");
- for (String product : products) {
- String[] parts = product.split(":");
- // 商品名称-商品编号
- String key = parts[0];
- // 商品单价-商品数量
- String value = parts[1];
- map.put(key, value);
- }
- String result = null;
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- // 汇付分账参数
- order.setAcctSplitBunch(acctSplitBunch.toString());
- order2.setAcctSplitBunch(acctSplitBunch.toString());
- //添加到汇付临时表,微信
- // THuifuTempOrder tHuifuTempOrder = new THuifuTempOrder();
- // String[] ignoreProperties = {"id"};
- // String id = HuifuUtils.inithuifuTempId();
- // tHuifuTempOrder.setId(id);
- // BeanUtil.copyProperties(order, tHuifuTempOrder, ignoreProperties);
- // huifuTempOrderService.save(tHuifuTempOrder);
- // if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- // result1 = HuifuConstant.SC_JUMP_URL + "/#/weChatPay?id=" + id;
- // } else {
- // result1 = HuifuConstant.SZ_JUMP_URL + "/#/weChatPay?id=" + id;
- // }
- String result1 = "";
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- } else {
- result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- }
- try {
- result1 = URLEncoder.encode(result1, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- // 支付宝
- try {
- result = huifuMchService.uniPay(
- sn2, amount, productName1, productDesc,
- notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- if (StrUtil.isEmpty(result)) {
- return JsonMessage.error("找不到支付图片");
- }
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
- String qrcode = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", qrcode);
- for (String key : map.keySet()) {
- String value = map.get(key);
- String[] GoodsInfo = key.split("-");
- String[] GoodsValue = value.split("-");
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setProductName(GoodsInfo[0]);
- orderDetails.setProductNo(GoodsInfo[1]);
- orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
- orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
- orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn1);
- orderDetailsService.save(orderDetails);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn2);
- orderDetailsService.save(orderDetails);
- }
- orderService.save(order);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- } else {
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode1,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- String rc_Result1 = resultJson.getString("rc_Result");
- String result1 = null;
- try {
- result1 = joinpayMchService.uniPay(
- orderNo2, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode2,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson1 = JSONObject.parseObject(result1);
- String rc_Result2 = resultJson1.getString("rc_Result");
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://app.sunzee.com.cn/" + "/api/order/aliPay.htm?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
- String rd_Pic = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", rd_Pic);
- // 添加到订单明细表
- for (String key : map.keySet()) {
- // key:"玫瑰精灵-A01",value:"0.50-1"
- String value = map.get(key);
- String[] GoodsInfo = key.split("-");
- String[] GoodsValue = value.split("-");
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setProductName(GoodsInfo[0]);
- orderDetails.setProductNo(GoodsInfo[1]);
- orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
- orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
- orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn1);
- orderDetailsService.save(orderDetails);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn2);
- orderDetailsService.save(orderDetails);
- }
- orderService.save(order);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- }
- }
- @ApiOperation(value = "汇付:获取code回调跳转到支付页面")
- @GetMapping("/callback")
- public void oauthCallback(HttpServletRequest request, HttpServletResponse response) throws IOException {
- // 获取code
- String code = request.getParameter("code");
- String id = request.getParameter("state");
- LambdaQueryWrapper<THuifuTempOrder> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(THuifuTempOrder::getId, id);
- THuifuTempOrder huifuTempOrder = huifuTempOrderService.getOne(wrapper);
- // 从临时表中获取订单信息
- String result = null;
- if (huifuTempOrder != null) {
- String companyType = huifuTempOrder.getCompanyType();
- if (huifuTempOrder.getStatus() == 1) {
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- result = HuifuConstant.SC_JUMP_URL + "/#/popPayment?status=1";
- } else {
- result = HuifuConstant.SZ_JUMP_URL + "/#/popPayment?status=1";
- }
- } else {
- String openid;
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- // 获取openid
- try {
- String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
- "appid=" + HuifuConstant.SC_WX_SUB_APP_ID +
- "&secret=" + HuifuConstant.SC_WX_APP_SECRET +
- "&code=" + code +
- "&grant_type=authorization_code";
- log.info("获取openID:{}", openUrl);
- org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
- log.info("获取openID结果:{}", jsonObject);
- openid = jsonObject.getString("openid");
- result = huifuMchService.wetchatPay(huifuTempOrder, openid);
- } catch (Exception e) {
- e.printStackTrace();
- }
- } else {
- // 获取openid
- try {
- String openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?" +
- "appid=" + HuifuConstant.SZ_WX_SUB_APP_ID +
- "&secret=" + HuifuConstant.SZ_WX_APP_SECRET +
- "&code=" + code +
- "&grant_type=authorization_code";
- log.info("获取openID:{}", openUrl);
- org.json.JSONObject jsonObject = HttpClientUtils.get(openUrl);
- log.info("获取openID结果:{}", jsonObject);
- openid = jsonObject.getString("openid");
- result = huifuMchService.wetchatPay(huifuTempOrder, openid);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- log.info("支付链接:{}", result);
- response.sendRedirect(result);
- }
- /**
- * 支付成功回调 汇付
- */
- @RequestMapping(value = "/huifuNotify", method = RequestMethod.POST)
- @ResponseBody
- public String huifuNotify(HttpServletRequest request) {
- String respData = request.getParameter("resp_data");
- try {
- // 验签请参sign
- String sign = request.getParameter("sign");
- // 使用汇付公钥验签
- if (!RSAUtil.verify(respData, HuifuConstant.HUIFU_PUBLIC_KEY, sign)) {
- // 验签失败处理
- log.info("验签失败");
- return "";
- }
- JSONObject data = JSONObject.parseObject(respData);
- String transStat = data.getString("trans_stat");
- // 订单号
- String sn = data.getString("req_seq_id");
- if (StrUtil.hasEmpty(sn)) {
- // return "R.fail(ResponseCodesEnum.A0001,"订单号为空!")";
- log.info("返回参数订单编号为空");
- return "";
- }
- // 查到指定订单
- LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(TOrder::getSn, sn);
- wrapper.eq(TOrder::getStatus, 0);
- TOrder order = orderService.getOne(wrapper);
- if (order == null) {
- log.info("找不到订单");
- return "";
- }
- if (HuifuConstant.TRANS_STAT_S.equals(transStat)) {
- // 查到对应订单明细表
- LambdaQueryWrapper<TOrderDetails> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- lambdaQueryWrapper.eq(TOrderDetails::getOrderSn, sn);
- List<TOrderDetails> orderDetails = orderDetailsService.list(lambdaQueryWrapper);
- for (TOrderDetails orderDetail : orderDetails) {
- // 修改状态订单明细状态
- orderDetail.setRefundStatus("1");
- orderDetailsService.updateById(orderDetail);
- }
- // 已支付
- order.setStatus(1);
- // 支付平台产生的全局流水号:hf_seq_id
- // String hfSeqId = data.getString("hf_seq_id");
- // 支付平台产生的全局流水号:party_order_id
- String partyOrderId = data.getString("party_order_id");
- order.setTrxNo(partyOrderId);
- // 支付时间,格式:YYYY-MM-DD HH:mm:ss
- String payTime = data.getString("end_time");
- SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMddHHmmss");
- SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- // 临时表修改支付状态
- String id = data.getString("remark");
- if (StrUtil.isNotEmpty(id)) {
- LambdaQueryWrapper<THuifuTempOrder> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(THuifuTempOrder::getId, id);
- THuifuTempOrder huifuTempOrder = huifuTempOrderService.getOne(queryWrapper);
- huifuTempOrder.setStatus(1);
- huifuTempOrderService.updateById(huifuTempOrder);
- }
- try {
- Date date = inputFormat.parse(URLDecoder.decode(payTime, "UTF-8"));
- String formattedDate = outputFormat.format(date);
- Date payDate = outputFormat.parse(URLDecoder.decode(formattedDate, "UTF-8"));
- order.setPayDate(payDate);
- } catch (ParseException e) {
- e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- // 修改订单信息
- orderService.updateById(order);
- //
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- kindData.put("productName", order.getProductName());
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- if (order.getFrpCode().equals("WEIXIN_XCX")) {
- JSONObject kindData1 = new JSONObject();
- kindData1.put("sn", order.getSn());
- kindData1.put("productDesc", order.getProductDesc());
- String s = order.getId().toString();
- if (s.length() > 6) {
- s = s.substring(s.length() - 6, s.length());
- }
- kindData1.put("mealCode", s);
- order.setOrderStatus("-1");
- equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("cardPayXCX", kindData1.toString()).toString());
- if (StringUtils.isNotEmpty(equipment.getApkVersion())) {
- //发送两次mq
- 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")) {
- sendMqTwo(equipment.getClientId(), kindData1.toString());
- }
- }
- TSzsmWx szsmWx = szsmWxService.getById(order.getWxId());
- BigDecimal integral = szsmWx.getIntegral();
- if (integral != null) {
- integral = order.getPrice().add(integral);
- } else {
- integral = order.getPrice();
- }
- szsmWx.setIntegral(integral);
- szsmWxService.updateById(szsmWx);
- if (StringUtils.isNotEmpty(order.getCoupons())) {
- String coupons = order.getCoupons();
- coupons = coupons.substring(1, coupons.length() - 1);
- List<String> list1 = Arrays.asList(coupons);
- if (list1.size() > 0) {
- for (String code : list1) {
- szwlFeign.useYHJ(code, String.valueOf(order.getAdminId()), order.getClientId());
- }
- }
- }
- } else {
- if (!order.getIsNotified().equals("1")) {
- String paySuccess = equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
- if (paySuccess.equals("success")) {
- order.setIsNotified("1");
- // 推送微信订单
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
- // 判断是否开启订单推送功能
- if (admin != null && StringUtils.isNotEmpty(admin.getOrderNotice()) && admin.getOrderNotice().equals("1")) {
- String openId = R.getDataIfSuccess(szwlFeign.getOpenId(order.getAdminId()));
- // 获取openId
- if (StringUtils.isNotEmpty(openId)) {
- orderService.newSendWechatMessage(openId, equipment, order, admin.getCompanyType());
- }
- }
- }
- }
- }
- orderService.updateById(order);
- try {
- if (order.getProductNumber() == null || order.getProductNumber() == 0) {
- order.setProductNumber(1);
- }
- orderFeign.saveToEs(order);
- } catch (Exception e) {
- e.printStackTrace();
- }
- try {
- LambdaQueryWrapper<TOrderTask> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(TOrderTask::getSn, sn);
- TOrderTask oldOrderTask = orderTaskService.getOne(queryWrapper);
- if (oldOrderTask == null) {
- TOrderTask orderTask = new TOrderTask();
- BeanUtils.copyPropertiesIgnoreNull(order, orderTask, true);
- orderTask.setAgencyId(order.getId());
- orderTaskService.save(orderTask);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- //传送数据
- // sentJingZhun(order);
- // return R.ok("支付成功");
- log.info("支付成功");
- } else {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- String gtClientId = equipment.getGtClientId();
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- if (!order.getIsNotified().equals("2")) {
- String payFail = equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_faile", kindData.toString()).toString());
- if (payFail.equals("success")) {
- order.setIsNotified("2");
- }
- }
- order.setNote(gtClientId + "支付失败");
- orderService.updateById(order);
- log.info("支付失败");
- }
- return "RECV_ORD_ID_" + sn;
- } catch (Exception e) {
- log.info("异步回调开始,参数,request={}", respData, e);
- }
- return "";
- }
- /**
- * 支付成功回调 汇聚
- *
- * @return
- */
- @RequestMapping(value = "/notify", method = RequestMethod.GET)
- @ResponseBody
- public String notify(HttpServletRequest request) {
- String r6_Status = request.getParameter("r6_Status");
- // 订单号
- String sn = request.getParameter("r2_OrderNo");
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, sn);
- query.eq(TOrder::getStatus, 0);
- if (StringUtils.isEmpty(sn)) {
- return "error";
- }
- TOrder order = orderService.getOne(query);
- if (order == null) {
- return "error";
- }
- if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
- // 查到对应订单明细表
- LambdaQueryWrapper<TOrderDetails> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- lambdaQueryWrapper.eq(TOrderDetails::getOrderSn, sn);
- List<TOrderDetails> orderDetails = orderDetailsService.list(lambdaQueryWrapper);
- for (TOrderDetails orderDetail : orderDetails) {
- // 修改状态订单明细状态
- orderDetail.setRefundStatus("1");
- orderDetailsService.updateById(orderDetail);
- }
- // 已支付
- order.setStatus(1);
- // 支付平台产生的流水号
- String r7_TrxNo = request.getParameter("r7_TrxNo");
- order.setTrxNo(r7_TrxNo);
- // 格式:YYYY-MM-DD HH:mm:ss
- String ra_PayTime = request.getParameter("ra_PayTime");
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
- order.setPayDate(payDate);
- } catch (ParseException e) {
- e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- orderService.updateById(order);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- kindData.put("productName", order.getProductName());
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- if (order.getFrpCode().equals("WEIXIN_XCX")) {
- JSONObject kindData1 = new JSONObject();
- kindData1.put("sn", order.getSn());
- kindData1.put("productDesc", order.getProductDesc());
- String s = order.getId().toString();
- if (s.length() > 6) {
- s = s.substring(s.length() - 6, s.length());
- }
- kindData1.put("mealCode", s);
- order.setOrderStatus("-1");
- equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("cardPayXCX", kindData1.toString()).toString());
- if (StringUtils.isNotEmpty(equipment.getApkVersion())) {
- //发送两次mq
- 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")) {
- sendMqTwo(equipment.getClientId(), kindData1.toString());
- }
- }
- TSzsmWx szsmWx = szsmWxService.getById(order.getWxId());
- BigDecimal integral = szsmWx.getIntegral();
- if (integral != null) {
- integral = order.getPrice().add(integral);
- } else {
- integral = order.getPrice();
- }
- szsmWx.setIntegral(integral);
- szsmWxService.updateById(szsmWx);
- if (StringUtils.isNotEmpty(order.getCoupons())) {
- String coupons = order.getCoupons();
- coupons = coupons.substring(1, coupons.length() - 1);
- List<String> list1 = Arrays.asList(coupons);
- if (list1.size() > 0) {
- for (String code : list1) {
- szwlFeign.useYHJ(code, String.valueOf(order.getAdminId()), order.getClientId());
- }
- }
- }
- } else {
- if (!order.getIsNotified().equals("1")) {
- String paySuccess = equipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
- if (paySuccess.equals("success")) {
- order.setIsNotified("1");
- }
- // 推送微信订单
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
- // 判断是否开启订单推送功能
- if (admin != null && StringUtils.isNotEmpty(admin.getOrderNotice()) && admin.getOrderNotice().equals("1")) {
- String openId = R.getDataIfSuccess(szwlFeign.getOpenId(order.getAdminId()));
- // 获取openId
- if (StringUtils.isNotEmpty(openId)) {
- orderService.newSendWechatMessage(openId, equipment, order, admin.getCompanyType());
- }
- }
- }
- }
- orderService.updateById(order);
- try {
- if (order.getProductNumber() == null || order.getProductNumber() == 0) {
- order.setProductNumber(1);
- }
- orderFeign.saveToEs(order);
- } catch (Exception e) {
- e.printStackTrace();
- }
- // try {
- LambdaQueryWrapper<TOrderTask> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(TOrderTask::getSn, sn);
- TOrderTask oldOrderTask = orderTaskService.getOne(queryWrapper);
- if (oldOrderTask == null) {
- TOrderTask orderTask = new TOrderTask();
- BeanUtils.copyPropertiesIgnoreNull(order, orderTask, true);
- orderTask.setAgencyId(order.getId());
- orderTaskService.save(orderTask);
- }
- //传送数据
- sentJingZhun(order);
- return "success";
- } else {
- TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- String gtClientId = byClientId.getGtClientId();
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- if (!order.getIsNotified().equals("2")) {
- String payFail = equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_faile", kindData.toString()).toString());
- if (payFail.equals("success")) {
- order.setIsNotified("2");
- }
- }
- order.setNote(gtClientId + "支付失败");
- orderService.updateById(order);
- return "success";
- }
- }
- //发送两次mq
- private void sendMqTwo(String clientId, String kind) {
- // 定时任务1
- TimerTask timerTask = new TimerTask() {
- @Override
- public void run() {
- equipmentService.sentMessage(clientId, PushUtils.buildJson("cardPayXCX", kind).toString());
- System.out.println("运行定时任务1:" + clientId);
- }
- };
- // 定时任务2
- TimerTask timerTask1 = new TimerTask() {
- @Override
- public void run() {
- equipmentService.sentMessage(clientId, PushUtils.buildJson("cardPayXCX", kind).toString());
- System.out.println("运行定时任务1:" + clientId);
- }
- };
- // 计时器
- Timer timer = new Timer();
- // 添加执行任务(延迟 5s 执行)
- timer.schedule(timerTask, 5000);
- Timer timer1 = new Timer();
- timer1.schedule(timerTask1, 10000);
- }
- private void sentJingZhun(TOrder order) {
- order = orderService.getById(order.getId());
- int i = 0;
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
- String adminId = admin.getId().toString();
- String relationAdminId = admin.getRelationAdminId();
- if ((StringUtils.isNotEmpty(adminId) && (adminId.equals("372") || adminId.equals("639") || adminId.equals("238")))
- || (StringUtils.isNotEmpty(relationAdminId) && relationAdminId.equals("372"))) {
- //发送数据到鲸准
- String url = "http://47.106.13.109:3000/api/listen";
- Map<String, String> map = new HashMap<>();
- map.put("clientId", order.getClientId());
- map.put("price", String.valueOf(order.getPrice()));
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- map.put("pay_date", sdf.format(order.getPayDate()));
- if (order.getWxId() != null) {
- //小程序下单
- TSzsmWx szsmWx = szsmWxService.getById(order.getWxId());
- map.put("sourceChannel", "1");
- map.put("phone", szsmWx.getPhone());
- if (order.getMarketingAmount() != null) {
- map.put("amount", order.getMarketingAmount().toString());
- } else {
- map.put("amount", "0");
- }
- map.put("nickName", "1");
- map.put("uninoId", szsmWx.getOpenId());
- } else {
- //机器下单
- map.put("sourceChannel", "0");
- map.put("phone", "");
- map.put("amount", "0");
- map.put("nickName", "");
- map.put("uninoId", "");
- }
- TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- map.put("latitude", String.valueOf(byClientId.getLatitude()));
- map.put("longitude", String.valueOf(byClientId.getLongitude()));
- String data = JSON.toJSONString(map);
- try {
- String s = HttpClientSslUtils.doPost(url, data);
- System.out.println("发送鲸准:" + s);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * 支付成功回调 杉德
- *
- * @return
- */
- @RequestMapping(value = "/shandeRefund", method = RequestMethod.GET)
- @ResponseBody
- public Object shandeRefund(HttpServletRequest request) {
- //订单号
- String order_no = request.getParameter("out_order_no");
- //交易状态
- String trade_status = request.getParameter("trade_status");
- String r6_Status = request.getParameter("r6_Status");
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, order_no);
- if (StringUtils.isEmpty(order_no)) {
- return "error";
- }
- List<TOrder> list = orderService.list(query);
- TOrder order = new TOrder();
- if (list.size() > 0) {
- order = list.get(0);
- }
- if (trade_status.equals("SUCCESS")) {
- // 已支付
- order.setStatus(1);
- // 支付平台产生的流水号
- String bank_order_no = request.getParameter("bank_order_no");
- order.setTrxNo(bank_order_no);
- // 格式:YYYY-MM-DD HH:mm:ss
- String pay_success_time = request.getParameter("pay_success_time");
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
- Date payDate = sdf.parse(URLDecoder.decode(pay_success_time, "UTF-8"));
- order.setPayDate(payDate);
- } catch (ParseException e) {
- e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- orderService.updateById(order);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- kindData.put("productName", order.getProductName());
- TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- String gtClientId = byClientId.getGtClientId();
- equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_success", kindData.toString()).toString());
- // PushUtils.push(gtClientId, "支付成功", "您的订单支付成功", PushUtils.buildJson("pay_success", kindData.toString()).toString());
- order.setNote(gtClientId + "已推送");
- try {
- if (order.getProductNumber() == null || order.getProductNumber() == 0) {
- order.setProductNumber(1);
- }
- esTOrderService.insertData(order);
- orderFeign.saveToEs(order);
- } catch (Exception e) {
- e.printStackTrace();
- }
- //对金额表的当日数额进行修改
- //1,获取商家的等级
- BigDecimal price = order.getPrice();
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(byClientId.getAdminId())));
- //获取分销 关联设备
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(byClientId.getId())));
- Integer type = proportion.getType();
- switch (type) {
- case 0:
- BigDecimal agencyProportion = proportion.getProportion();
- // 代理分销获得利润
- BigDecimal agencyPrice = price.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- //修改金额表的今日金额
- TShandeMch shandeMch = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getId())));
- BigDecimal todayBalance = shandeMch.getTodayBalance();
- todayBalance = todayBalance.add(agencyPrice).setScale(2, RoundingMode.HALF_DOWN);
- shandeMch.setTodayBalance(todayBalance);
- szwlFeign.updateShandeMch(shandeMch);
- break;
- case 1:
- BigDecimal agencyProportion1 = proportion.getAgencyProportion();
- BigDecimal merchantProportion1 = proportion.getProportion();
- // 代理分销获得利润
- BigDecimal agencyPrice1 = price.multiply(agencyProportion1.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // 经销商分销获得利润
- BigDecimal merchantAmount1 = price.multiply(merchantProportion1.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- //修改代理金额表的今日金额
- // ArrayList<Filter> filters1 = new ArrayList<>();
- // filters1.add(Filter.eq("adminId", admin.getAgencyId()));
- TShandeMch shandeMch2 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(proportion.getAgencyId())));
- BigDecimal todayBalance2 = shandeMch2.getTodayBalance();
- todayBalance2 = todayBalance2.add(agencyPrice1).setScale(2, RoundingMode.HALF_DOWN);
- shandeMch2.setTodayBalance(todayBalance2);
- szwlFeign.updateShandeMch(shandeMch2);
- //修改经销商金额表的今日金额
- // ArrayList<Filter> filters2 = new ArrayList<>();
- // filters2.add(Filter.eq("adminId", admin.getId()));
- TShandeMch shandeMch3 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getId())));
- BigDecimal todayBalance3 = shandeMch3.getTodayBalance();
- todayBalance3 = todayBalance3.add(merchantAmount1).setScale(2, RoundingMode.HALF_DOWN);
- shandeMch3.setTodayBalance(todayBalance3);
- szwlFeign.updateShandeMch(shandeMch3);
- break;
- case 2:
- BigDecimal agencyProportion2 = proportion.getAgencyProportion();
- BigDecimal merchantProportion2 = proportion.getMerchantProportion();
- BigDecimal personageProportion2 = proportion.getProportion();
- // 代理分销获得利润
- BigDecimal agencyAmount = price.multiply(agencyProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // 经销商分销获得利润
- BigDecimal merchantAmount = price.multiply(merchantProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // 经销商分销获得利润
- BigDecimal personageAmount = price.multiply(personageProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- //修改代理金额表的今日金额
- // ArrayList<Filter> filters3 = new ArrayList<>();
- // filters3.add(Filter.eq("adminId", admin.getAgencyId()));
- // List<ShandeMch> list3 = shandeMchService.findList(null,filters3,null);
- TShandeMch shandeMch4 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(proportion.getAgencyId())));
- BigDecimal todayBalance4 = shandeMch4.getTodayBalance();
- todayBalance4 = todayBalance4.add(agencyAmount).setScale(2, RoundingMode.HALF_DOWN);
- shandeMch4.setTodayBalance(todayBalance4);
- szwlFeign.updateShandeMch(shandeMch4);
- //修改经销商金额表的今日金额
- TShandeMch shandeMch5 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(proportion.getMerchantId())));
- BigDecimal todayBalance5 = shandeMch5.getTodayBalance();
- todayBalance5 = todayBalance5.add(merchantAmount).setScale(2, RoundingMode.HALF_DOWN);
- shandeMch5.setTodayBalance(todayBalance5);
- szwlFeign.updateShandeMch(shandeMch5);
- //修改终端金额表的今日金额
- TShandeMch shandeMch6 = R.getDataIfSuccess(szwlFeign.getShandeMch(String.valueOf(admin.getId())));
- BigDecimal todayBalance6 = shandeMch6.getTodayBalance();
- todayBalance6 = todayBalance6.add(personageAmount).setScale(2, RoundingMode.HALF_DOWN);
- shandeMch6.setTodayBalance(todayBalance6);
- szwlFeign.updateShandeMch(shandeMch6);
- break;
- }
- return "SUCCESS";
- } else {
- TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- String gtClientId = byClientId.getGtClientId();
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("pay_faile", kindData.toString()).toString());
- // PushUtils.push(gtClientId, "支付成功", "您的订单支付成功", PushUtils.buildJson("pay_faile", kindData.toString()).toString());
- order.setNote(gtClientId + "支付失败");
- orderService.updateById(order);
- }
- return "SUCCESS";
- }
- /**
- * MG280支付成功回调
- *
- * @return
- */
- @RequestMapping(value = "/mg280Notify", method = RequestMethod.GET)
- @ResponseBody
- public Object mg280Notify(HttpServletRequest request) {
- String r6_Status = request.getParameter("r6_Status");
- // 订单号
- String sn = request.getParameter("r2_OrderNo");
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, sn);
- if (StringUtils.isEmpty(sn)) {
- return "error";
- }
- List<TOrder> list = orderService.list(query);
- TOrder order = list.get(0);
- if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
- // 已支付
- order.setStatus(1);
- // 支付平台产生的流水号
- String r7_TrxNo = request.getParameter("r7_TrxNo");
- order.setTrxNo(r7_TrxNo);
- // 格式:YYYY-MM-DD HH:mm:ss
- String ra_PayTime = request.getParameter("ra_PayTime");
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
- order.setPayDate(payDate);
- } catch (ParseException e) {
- e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- orderService.updateById(order);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- kindData.put("productName", order.getProductName());
- TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- String gtClientId = byClientId.getGtClientId();
- Date endDate = byClientId.getEndDate();
- Date date = new Date();
- Date time = null;
- double price1Price = 0;
- BigDecimal price = order.getPrice();
- // List<Price> priceList = priceService.findAll();
- // for (Price price1 : priceList) {
- // if (price1.getName().equals("MG280")) {
- // price1Price = price1.getPrice();
- // }
- // }
- TPrice price1 = R.getDataIfSuccess(szwlFeign.getPrice("MG280"));
- price1Price = price1.getPrice();
- BigDecimal city = price.divide(BigDecimal.valueOf(price1Price));
- int ci = city.intValue();
- if (endDate.getTime() < date.getTime()) {
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- int i = c.get(Calendar.MONTH);
- c.set(Calendar.MONTH, i - 1);
- //上个月有多少天
- int actualMaximum = c.getActualMaximum(Calendar.DAY_OF_MONTH);
- long t = date.getTime() - endDate.getTime();
- long m = actualMaximum * 1000 * 60 * 60 * 24l;
- if (t <= m) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(endDate);
- calendar.set(Calendar.DAY_OF_MONTH, 10);
- //将小时至0
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- //将分钟至0
- calendar.set(Calendar.MINUTE, 0);
- //将秒至0
- calendar.set(Calendar.SECOND, 0);
- //将毫秒至0
- calendar.set(Calendar.MILLISECOND, 0);
- calendar.add(Calendar.MONTH, ci);
- time = calendar.getTime();
- }
- if (t > m) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- calendar.set(Calendar.DAY_OF_MONTH, 10);
- //将小时至0
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- //将分钟至0
- calendar.set(Calendar.MINUTE, 0);
- //将秒至0
- calendar.set(Calendar.SECOND, 0);
- //将毫秒至0
- calendar.set(Calendar.MILLISECOND, 0);
- calendar.add(Calendar.MONTH, ci);
- time = calendar.getTime();
- }
- } else {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(endDate);
- calendar.set(Calendar.DAY_OF_MONTH, 10);
- //将小时至0
- calendar.set(Calendar.HOUR_OF_DAY, 0);
- //将分钟至0
- calendar.set(Calendar.MINUTE, 0);
- //将秒至0
- calendar.set(Calendar.SECOND, 0);
- //将毫秒至0
- calendar.set(Calendar.MILLISECOND, 0);
- calendar.add(Calendar.MONTH, ci);
- time = calendar.getTime();
- }
- byClientId.setEndDate(time);
- //修改机器
- szwlFeign.updateByEquipment(byClientId);
- order.setNote(gtClientId + "已推送");
- orderService.updateById(order);
- equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("endDate", String.valueOf(byClientId.getEndDate().getTime())).toString());
- // PushUtils.push(byClientId.getGtClientId(), "", "", PushUtils.buildJson("endDate", String.valueOf(byClientId.getEndDate().getTime())).toString());
- return "success";
- } else {
- TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- String gtClientId = byClientId.getGtClientId();
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- order.setNote(gtClientId + "支付失败");
- orderService.updateById(order);
- }
- return "success";
- }
- //生成二维码,并返回base64格式
- private String toQrcode(String code) {
- String imgtext = null;
- QRCodeWriter qrCodeWriter = new QRCodeWriter();
- HashMap<EncodeHintType, Object> hints = new HashMap<>();
- hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
- BitMatrix bitMatrix = null;
- try {
- bitMatrix = qrCodeWriter.encode(code, BarcodeFormat.QR_CODE, 600, 600, hints);
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);
- Base64.Encoder encoder = Base64.getEncoder();
- String text = encoder.encodeToString(outputStream.toByteArray());
- imgtext = "data:image/png;base64," + text;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return imgtext;
- }
- @ApiOperation(value = "汇付退款成功回调")
- @RequestMapping(value = "/refundNotify", method = RequestMethod.POST)
- @ResponseBody
- public String refundNotify(HttpServletRequest request) {
- String result = orderService.huifuNotifyRefund(request);
- return result;
- }
- @ApiOperation(value = "汇付退款成功回调")
- @RequestMapping(value = "/notifyRefund", method = RequestMethod.GET)
- @ResponseBody
- public Object notifyRefund(HttpServletRequest request) {
- String result = orderService.joinpayNotifyRefund(request);
- // String r6_Status = request.getParameter("ra_Status");
- //
- // // 订单号
- // String sn = request.getParameter("r2_OrderNo");
- // // 退款订单号
- //
- // if(StringUtils.isEmpty(sn)){
- // return "error";
- // }
- //
- // LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- // query.eq(TOrder::getSn,sn);
- // TOrder order = orderService.getOne(query);
- //
- // if (order == null) {
- // return "error";
- // }
- // if (order.getStatus() == 3) {
- // return "success";
- // }
- // // 订单商品数量
- // if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
- // if(order.getRefundQuantity() < order.getProductNumber()) {
- // order.setStatus(1);
- // } else {
- // order.setStatus(3);
- // }
- // // 更改订单明细表
- // LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
- // queryWrapper.eq(TOrderDetails::getOrderSn, sn);
- // // 处理退款中状态的明细
- // queryWrapper.eq(TOrderDetails::getRefundStatus, "4");
- // List<TOrderDetails> tOrderDetails = orderDetailsService.list(queryWrapper);
- // for (TOrderDetails tOrderDetail : tOrderDetails) {
- // Integer refundQuantity = tOrderDetail.getRefundQuantity();
- // Integer productNumber = tOrderDetail.getProductNumber();
- // if(refundQuantity < productNumber) {
- // // 部分退款
- // tOrderDetail.setRefundStatus("2");
- // orderDetailsService.updateById(tOrderDetail);
- // } else {
- // // 全部退款
- // tOrderDetail.setRefundStatus("3");
- // orderDetailsService.updateById(tOrderDetail);
- // }
- // }
- // // r4_refundAmount: 退款金额
- // BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
- // if(order.getRefundMarketingAmount()!=null){
- // r4_refundAmount =r4_refundAmount.add(order.getRefundMarketingAmount());
- // }
- // // price: 订单金额, refundAmount:已退款的金额
- // BigDecimal price = order.getPrice();
- // BigDecimal refundAmount = order.getRefundAmount();
- // TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(order.getEquipmentId())));
- // if(order.getRefundAmount() != null) {
- // BigDecimal newRefundAmount = refundAmount.add(r4_refundAmount);
- // order.setRefundAmount(refundAmount.add(r4_refundAmount));
- // // 如果小于订单金额
- // if(newRefundAmount.compareTo(price) < 0) {
- // JSONArray altInfo = getAltInfo(proportion, price.subtract(newRefundAmount));
- // order.setAltInfo(altInfo.toString());
- // } else {
- // JSONArray altInfo = getAltInfo(proportion, price);
- // order.setAltInfo(altInfo.toString());
- // }
- // } else {
- // order.setRefundAmount(r4_refundAmount);
- // if(r4_refundAmount.compareTo(price) < 0) {
- // JSONArray altInfo = getAltInfo(proportion, price.subtract(r4_refundAmount));
- // order.setAltInfo(altInfo.toString());
- // }
- // }
- //
- // // 支付平台产生的退款流水号
- // String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
- // order.setRefundTrxNo(r5_RefundTrxNo);
- // order.setRefundDate(new Date());
- // order.setModifyDate(new Date());
- // String orderStatus = order.getOrderStatus();
- // if(StringUtils.isNotEmpty(orderStatus)&&orderStatus.equals("0")){
- // if(order.getStatus().toString().equals("3")){
- // TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- // JSONObject kindData = new JSONObject();
- // String s = order.getId().toString();
- // if(s.length()>6){
- // s = s.substring(s.length()-6,s.length());
- // }
- // kindData.put("mealCode", s);
- // equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("refuse_success", kindData.toString()).toString());
- //
- // }
- // }
- // try {
- // esTOrderService.updateDataById(order);
- // }catch (Exception e) {
- // e.printStackTrace();
- // }finally {
- // orderService.updateById(order);
- // }
- // return "success";
- // }
- return result;
- }
- @ApiOperation(value = "添加国内订单")
- @PostMapping("/addOrder")
- public ResponseModel<?> addOrder(@RequestBody TOrder order) {
- boolean save = orderService.save(order);
- return R.ok(save);
- }
- @ApiOperation(value = "修改订单")
- @PostMapping("/updateOrder")
- public ResponseModel<?> updateOrder(@RequestBody TOrder order) {
- orderService.updateById(order);
- LambdaQueryWrapper<TOrderTask> query = Wrappers.lambdaQuery();
- query.eq(TOrderTask::getSn, order.getSn());
- TOrderTask orderTask = orderTaskService.getOne(query);
- orderTask.setStatus(order.getStatus());
- orderTaskService.updateById(orderTask);
- return R.ok();
- }
- @ApiOperation(value = "获取订单")
- @GetMapping("/getOrder")
- public ResponseModel<?> getOrder(@RequestParam String id) {
- TOrder order = orderService.getById(id);
- return R.ok(order);
- }
- @ApiOperation(value = "获取订单")
- @GetMapping("/getOrderBySn")
- public ResponseModel<?> getOrderBySn(@RequestParam String sn) {
- LambdaQueryWrapper<TOrder> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(TOrder::getSn, sn);
- TOrder order = orderService.getOne(wrapper);
- LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(TOrderDetails::getOrderSn, sn);
- List<TOrderDetails> orderDetails = orderDetailsService.list(queryWrapper);
- OrderDetailsDTO orderDetailsDTO = new OrderDetailsDTO();
- BeanUtil.copyProperties(order, orderDetailsDTO);
- orderDetailsDTO.setOrderDetails(orderDetails);
- return R.ok(orderDetailsDTO);
- }
- @ApiOperation(value = "优惠码支付成功回调")
- @RequestMapping(value = "/promoCodeNotify", method = RequestMethod.GET)
- @ResponseBody
- public Object promoCoderefund(HttpServletRequest request) {
- String r6_Status = request.getParameter("r6_Status");
- // 订单号
- String sn = request.getParameter("r2_OrderNo");
- //价格
- String price = request.getParameter("r3_Amount");
- // 优惠码
- String codeNum = request.getParameter("r5_Mp");
- Double money = null;
- TPrice tPrice = R.getDataIfSuccess(szwlFeign.getPrice("优惠码"));
- money = tPrice.getPrice();
- //生成优惠码的个数
- double num = Double.parseDouble(price) / money;
- int number = (int) num;
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, sn);
- List<TOrder> list = new ArrayList<>();
- if (StringUtils.isNotEmpty(sn)) {
- list = orderService.list(query);
- }
- TOrder order = list.get(0);
- if (order.getStatus() != 0) {
- return "success";
- }
- if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
- // 已支付
- order.setStatus(1);
- // 支付平台产生的流水号
- String r7_TrxNo = request.getParameter("r7_TrxNo");
- order.setTrxNo(r7_TrxNo);
- // 格式:YYYY-MM-DD HH:mm:ss
- String ra_PayTime = request.getParameter("ra_PayTime");
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date payDate = sdf.parse(URLDecoder.decode(ra_PayTime, "UTF-8"));
- order.setPayDate(payDate);
- } catch (ParseException e) {
- e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- orderService.updateById(order);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- kindData.put("productName", order.getProductName());
- String mont = order.getRefundTrxNo();
- Long data = Calendar.getInstance().getTimeInMillis();
- Float month = Float.valueOf(mont);
- Float mm = month * 10;
- String m = String.valueOf(mm);
- String[] split = m.split("\\.");
- String th = split[0];
- Long t = Long.valueOf(th);
- Long mon = 30L * 24L * 60L * 60L * 1000L;
- Long d = data + ((mon * t) / 10);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String sd = sdf.format(new Date(Long.parseLong(String.valueOf(d))));
- Date lastUseDate = new Date(Long.parseLong(String.valueOf(d)));
- szwlFeign.addPromoCode(String.valueOf(order.getAdminId()), lastUseDate, number, codeNum);
- return "支付成功";
- }
- return "success";
- }
- @ApiOperation(value = "查询订单是否付款")
- @RequestMapping(value = "/getOrderStatus", method = RequestMethod.GET)
- @ResponseBody
- public JsonMessage getOrderStatus(String sn) {
- String sta = "";
- if (sn.contains("-")) {
- String[] sns = sn.split("-");
- for (int i = 0; i < sns.length; i++) {
- LambdaQueryWrapper<TOrder> query1 = Wrappers.lambdaQuery();
- query1.eq(TOrder::getSn, sns[i]);
- TOrder order = orderService.getOne(query1);
- if (order != null) {
- Integer status = order.getStatus();
- sta = status.toString();
- if (status == 1) {
- sta = "pay";
- }
- }
- }
- } else {
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, sn);
- List<TOrder> list = orderService.list(query);
- if (list.size() > 0) {
- TOrder order = list.get(0);
- Integer status = order.getStatus();
- sta = status.toString();
- if (status == 1) {
- sta = "pay";
- }
- }
- }
- return JsonMessage.success(sta);
- }
- @ApiOperation(value = "上传订单的做糖状态")
- @RequestMapping(value = "/sendOrderStatus", method = RequestMethod.GET)
- @ResponseBody
- public JsonMessage sendOrderStatus(String sn, String orderStatus) {
- if (StringUtils.isEmpty(sn) || StringUtils.isEmpty(orderStatus)) {
- return JsonMessage.error("数据有空");
- }
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, sn);
- List<TOrder> list = orderService.list(query);
- TOrder order = list.get(0);
- order.setOrderStatus(orderStatus);
- orderService.updateById(order);
- if (orderStatus.equals("1")) {
- String s = order.getId().toString();
- String clientId = order.getClientId();
- szsmWxService.subscribeMessage(order.getWxId(), s.substring(s.length() - 6, s.length()), clientId.substring(clientId.length() - 6, clientId.length()));
- }
- LambdaQueryWrapper<TOrderTask> query1 = Wrappers.lambdaQuery();
- query1.eq(TOrderTask::getSn, sn);
- TOrderTask orderTask = orderTaskService.getOne(query1);
- orderTask.setOrderStatus(orderStatus);
- orderTaskService.updateById(orderTask);
- return JsonMessage.success("success");
- }
- @ApiOperation(value = "删除订单")
- @RequestMapping(value = "/deleteOrder", method = RequestMethod.GET)
- @ResponseBody
- public JsonMessage deleteOrder(String sn) {
- if (StringUtils.isEmpty(sn)) {
- return JsonMessage.error(sn + "删除失败");
- }
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, sn);
- List<TOrder> list = orderService.list(query);
- TOrder order = list.get(0);
- Integer status = order.getStatus();
- String ss = status.toString();
- if (status == 0) {
- orderService.removeById(order.getId());
- return JsonMessage.success(sn + "删除成功");
- }
- // return JsonMessage.success(sn + "删除失败");
- return JsonMessage.success(sn + "删除成功");
- }
- /**
- * 添加订单
- *
- * @param clientId 设备client id
- * @param productName 商品名称
- * @param
- * @return
- */
- @RequestMapping(value = "/addOrder", method = RequestMethod.GET)
- @ResponseBody
- public Object addOrder(String clientId, String productName, String pri, String sn) {
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- BigDecimal price = new BigDecimal(pri);
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- JSONArray altInfo = new JSONArray();
- String orderType = null;
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipment.getId())));
- Integer type = proportion.getType();
- switch (type) {
- case 0:
- orderType = "1";
- break;
- case 1:
- orderType = "2";
- break;
- case 2:
- orderType = "3";
- break;
- }
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn);
- order.setProductId(product.getId());
- order.setProductNo(product.getNo());
- order.setProductName(productName);
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setAltInfo(altInfo.toString());
- order.setStatus(1);
- order.setType(type);
- orderService.save(order);
- try {
- if (order.getProductNumber() == null || order.getProductNumber() == 0) {
- order.setProductNumber(1);
- }
- esTOrderService.insertData(order);
- orderFeign.saveToEs(order);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return JsonMessage.success("success");
- }
- /**
- * 汇聚分销明细
- *
- * @param proportion
- * @param price
- * @return
- */
- public JSONArray getAltInfo(TProportion proportion, BigDecimal price) {
- // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
- Integer type = proportion.getType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- BigDecimal agencyProportion = null,
- merchantProportion = null,
- selfProportion = null;
- BigDecimal agencyAmount = null;
- BigDecimal merchantAmount = null;
- BigDecimal selfAmount = null;
- TJoinpayMch agencyMch = null;
- TJoinpayMch merchantMch = null;
- TJoinpayMch selfMch = null;
- JSONObject agencyJson = null;
- JSONObject merchantJson = null;
- JSONObject selfJson = null;
- //取消平台扣手续费
- BigDecimal cutPrice = price.setScale(2, RoundingMode.HALF_UP);
- BigDecimal refuseAmount = new BigDecimal(0.00);
- switch (type) {
- case 0:
- // 商家自己的分销
- selfProportion = proportion.getProportion();
- // 商家分销获得利润
- selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // 汇聚平台
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- if (selfMch == null) {
- return altInfo;
- }
- selfJson = new JSONObject();
- selfJson.put("altMchNo", selfMch.getAltMchNo());
- selfJson.put("altAmount", selfAmount.toString());
- selfJson.put("isGuar", "12");
- altInfo.add(selfJson);
- break;
- case 1:
- // 商家自己的分销
- selfProportion = proportion.getProportion();
- // 一级分销
- agencyProportion = proportion.getAgencyProportion();
- // 商家分销获得利润
- selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // 汇聚平台
- agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- if (selfMch == null || agencyMch == null) {
- return altInfo;
- }
- if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
- // 一级分销获得利润
- agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- agencyJson = new JSONObject();
- agencyJson.put("altMchNo", agencyMch.getAltMchNo());
- agencyJson.put("altAmount", agencyAmount.toString());
- agencyJson.put("isGuar", "12");
- altInfo.add(agencyJson);
- }
- // 商家自己分销获得利润
- selfJson = new JSONObject();
- selfJson.put("altMchNo", selfMch.getAltMchNo());
- selfJson.put("altAmount", selfAmount.toString());
- selfJson.put("isGuar", "12");
- altInfo.add(selfJson);
- break;
- case 2:
- // 商家自己的分销
- selfProportion = proportion.getProportion();
- // 一级分销
- agencyProportion = proportion.getAgencyProportion();
- // 二级分销
- merchantProportion = proportion.getMerchantProportion();
- // 三级分销
- // personageProportion = proportion.getPersonageProportion();
- // 商家分销获得利润
- selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // 汇聚
- agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
- merchantMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getMerchantId())));
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- if (selfMch == null || agencyMch == null || merchantMch == null) {
- return altInfo;
- }
- if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
- // 代理分销获得利润
- agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- agencyJson = new JSONObject();
- agencyJson.put("altMchNo", agencyMch.getAltMchNo());
- agencyJson.put("altAmount", agencyAmount.toString());
- agencyJson.put("isGuar", "12");
- altInfo.add(agencyJson);
- }
- if (!(merchantProportion.compareTo(refuseAmount) == 0 || merchantProportion == null)) {
- // 经销商分销获得利润
- merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- merchantJson = new JSONObject();
- merchantJson.put("altMchNo", merchantMch.getAltMchNo());
- merchantJson.put("altAmount", merchantAmount.toString());
- merchantJson.put("isGuar", "12");
- altInfo.add(merchantJson);
- }
- // 商家自己分销获得利润
- merchantJson = new JSONObject();
- merchantJson.put("altMchNo", selfMch.getAltMchNo());
- merchantJson.put("altAmount", selfAmount.toString());
- merchantJson.put("isGuar", "12");
- altInfo.add(merchantJson);
- break;
- }
- Iterator<Object> iterator = altInfo.iterator();
- while (iterator.hasNext()) {
- JSONObject jsonObject = (JSONObject) iterator.next();
- String altAmount = jsonObject.getString("altAmount");
- if (altAmount.equals("0.00")) {
- iterator.remove();
- }
- }
- return altInfo;
- }
- /**
- * 汇付分销明细
- *
- * @param proportion
- * @param price
- * @return
- */
- public JSONObject getAcctSplitBunch(TProportion proportion, BigDecimal price, String companyType) {
- // 获取分账有几方:0:分账方2个,1:分账方3个,2:分账方4个,3:分账方超4个
- Integer type = proportion.getType();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- JSONArray acctInfos = new JSONArray();
- BigDecimal adminProportion = null,
- agencyProportion = null,
- merchantProportion = null,
- selfProportion = null;
- BigDecimal agencyAmount = null;
- BigDecimal merchantAmount = null;
- BigDecimal selfAmount = null;
- BigDecimal adminAmount = null;
- THuifuMch agencyHuifu = null;
- THuifuMch merchantHuifu = null;
- THuifuMch selfHuifu = null;
- JSONObject agencyJson = null;
- JSONObject merchantJson = null;
- JSONObject selfJson = null;
- JSONObject adminJson = null;
- //取消平台扣手续费
- BigDecimal cutPrice = price.setScale(2, RoundingMode.HALF_UP);
- BigDecimal refuseAmount = new BigDecimal(0.00);
- switch (type) {
- case 0:
- // 公司平台分销
- adminProportion = proportion.getAdminProportion();
- // 商家自己的分销
- selfProportion = proportion.getProportion();
- // 平台分销获得利润
- adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
- // 商家分销获得利润
- selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // 汇付平台
- // 商家汇付信息:agencyHuifu
- selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
- if (selfHuifu == null) {
- return acctSplitBunch;
- }
- // 公司平台分销
- adminJson = new JSONObject();
- adminJson.put("div_amt", adminAmount.toString());
- // 判断为申泽还是七云
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
- } else {
- adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
- }
- acctInfos.add(adminJson);
- // 商家分销获得利润
- selfJson = new JSONObject();
- selfJson.put("div_amt", selfAmount.toString());
- selfJson.put("huifu_id", selfHuifu.getHuifuId());
- acctInfos.add(selfJson);
- break;
- case 1:
- // 公司平台分销
- adminProportion = proportion.getAdminProportion();
- // 商家自己的分销
- selfProportion = proportion.getProportion();
- // 一级分销
- agencyProportion = proportion.getAgencyProportion();
- // 平台分销获得利润
- adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
- // 商家分销获得利润
- selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // 汇付平台
- selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
- agencyHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAgencyId()));
- if (selfHuifu == null || agencyHuifu == null) {
- return acctSplitBunch;
- }
- // 公司平台分销
- adminJson = new JSONObject();
- adminJson.put("div_amt", adminAmount.toString());
- // 判断为申泽还是七云
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
- } else {
- adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
- }
- acctInfos.add(adminJson);
- // 商家分销获得利润
- selfJson = new JSONObject();
- selfJson.put("div_amt", selfAmount.toString());
- selfJson.put("huifu_id", selfHuifu.getHuifuId());
- acctInfos.add(selfJson);
- if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
- // 一级分销获得利润
- agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- agencyJson = new JSONObject();
- agencyJson.put("div_amt", agencyAmount.toString());
- agencyJson.put("huifu_id", agencyHuifu.getHuifuId());
- acctInfos.add(agencyJson);
- }
- break;
- case 2:
- // 公司平台分销
- adminProportion = proportion.getAdminProportion();
- // 商家自己的分销
- selfProportion = proportion.getProportion();
- // 一级分销
- agencyProportion = proportion.getAgencyProportion();
- // 二级分销
- merchantProportion = proportion.getMerchantProportion();
- // 平台分销获得利润
- adminAmount = cutPrice.multiply(adminProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_UP);
- // 商家分销获得利润
- selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- selfHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAdminId()));
- agencyHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getAgencyId()));
- merchantHuifu = R.getDataIfSuccess(szwlFeign.getHuifuId(proportion.getMerchantId()));
- if (selfHuifu == null || agencyHuifu == null || merchantHuifu == null) {
- return acctSplitBunch;
- }
- // 公司平台分销
- adminJson = new JSONObject();
- adminJson.put("div_amt", adminAmount.toString());
- // 判断为申泽还是七云
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- adminJson.put("huifu_id", HuifuConstant.SC_DIV_HUIFU_ID);
- } else {
- adminJson.put("huifu_id", HuifuConstant.SZ_DIV_HUIFU_ID);
- }
- acctInfos.add(adminJson);
- // 商家分销获得利润
- selfJson = new JSONObject();
- selfJson.put("div_amt", selfAmount.toString());
- selfJson.put("huifu_id", selfHuifu.getHuifuId());
- acctInfos.add(selfJson);
- if (!(agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null)) {
- // 一级分销获得利润
- agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- agencyJson = new JSONObject();
- agencyJson.put("div_amt", agencyAmount.toString());
- agencyJson.put("huifu_id", agencyHuifu.getHuifuId());
- acctInfos.add(agencyJson);
- }
- if (!(merchantProportion.compareTo(refuseAmount) == 0 || merchantProportion == null)) {
- // 二级分销获得利润
- merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- merchantJson = new JSONObject();
- merchantJson.put("div_amt", merchantAmount.toString());
- merchantJson.put("huifu_id", merchantHuifu.getHuifuId());
- acctInfos.add(merchantJson);
- }
- break;
- }
- // 计算div_amt的总和
- BigDecimal totalAmount = BigDecimal.ZERO;
- for (int i = 0; i < acctInfos.size(); i++) {
- JSONObject jsonObject = acctInfos.getJSONObject(i);
- BigDecimal divAmt = new BigDecimal(jsonObject.getString("div_amt"));
- totalAmount = totalAmount.add(divAmt);
- }
- // 如果总和超过原本金额,调整div_amt
- if (totalAmount.compareTo(price) > 0) {
- BigDecimal diffAmount = totalAmount.subtract(price);
- for (int i = 0; i < acctInfos.size(); i++) {
- JSONObject jsonObject = acctInfos.getJSONObject(i);
- String huifuId = jsonObject.getString("huifu_id");
- if (huifuId.equals(HuifuConstant.SZ_DIV_HUIFU_ID) || huifuId.equals(HuifuConstant.SC_DIV_HUIFU_ID)) {
- BigDecimal currentDivAmt = new BigDecimal(jsonObject.getString("div_amt"));
- BigDecimal adjustedDivAmt = currentDivAmt.subtract(diffAmount).max(BigDecimal.ZERO);
- jsonObject.put("div_amt", adjustedDivAmt.toString());
- break;
- }
- }
- }
- acctSplitBunch.put("acct_infos", acctInfos);
- return acctSplitBunch;
- }
- /**
- * 旧版退款成功回调
- *
- * @param request
- * @return
- */
- @RequestMapping(value = "/oldNotifyRefund", method = RequestMethod.GET)
- @ResponseBody
- public Object oldNotifyRefund(HttpServletRequest request) {
- String r6_Status = request.getParameter("ra_Status");
- // 订单号
- String sn = request.getParameter("r2_OrderNo");
- // 退款订单号
- String refundSn = request.getParameter("r3_RefundOrderNo");
- String num = refundSn.substring(refundSn.length() - 1);
- Integer refundNumber = Integer.valueOf(num);
- // LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- LambdaQueryWrapper<TOrder> query = new LambdaQueryWrapper<>();
- query.eq(TOrder::getSn, sn);
- if (StringUtils.isEmpty(sn)) {
- return "error";
- }
- // List<TOrder> list = orderService.list(query);
- // TOrder order = list.get(0);
- TOrder order = orderService.getOne(query);
- if (order == null) {
- return "success";
- }
- if (order.getStatus() == 3) {
- return "success";
- }
- // 判断退款版本号是否存在
- String refundOrderNo = order.getRefundOrderNo();
- if (StringUtils.isNotEmpty(refundOrderNo)) {
- if (refundSn.equals(refundOrderNo)) {
- try {
- esTOrderService.updateDataById(order);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "success";
- }
- }
- // 订单商品数量
- Integer productNumber = order.getProductNumber();
- if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
- // 设置退款版本号
- order.setRefundOrderNo(refundSn);
- // 已退款
- if (productNumber >= refundNumber) {
- productNumber -= refundNumber;
- order.setProductNumber(productNumber);
- }
- // r4_refundAmount: 退款金额
- BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
- if (order.getRefundMarketingAmount() != null) {
- r4_refundAmount = r4_refundAmount.add(order.getRefundMarketingAmount());
- }
- // price: 当前订单退完款剩余的金额
- BigDecimal price = order.getPrice();
- // 判断退款金额是否小于订单余额
- if (r4_refundAmount.compareTo(price) == -1) {
- // refundAmount: 已退款金额
- BigDecimal refundAmount = order.getRefundAmount();
- if (refundAmount != null) {
- // 如果已退款金额不为空,则加上退款金额
- order.setRefundAmount(refundAmount.add(r4_refundAmount));
- } else {
- // 已退款金额
- order.setRefundAmount(r4_refundAmount);
- }
- // 订单设置为支付状态
- order.setStatus(1);
- // 改变订单的金额,原先金额减去退款金额
- order.setPrice(price.subtract(r4_refundAmount));
- // 重置分销
- if (order.getAltInfo() != null) {
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- String altInfo = altInfoReset(tEquipment.getId(), price.subtract(r4_refundAmount));
- order.setAltInfo(altInfo);
- }
- }
- // 判断退款金额是否等于订单余额
- if (r4_refundAmount.compareTo(price) == 0) {
- BigDecimal refundAmount = order.getRefundAmount();
- // order.setAltInfo("");
- order.setProductNumber(1);
- if (refundAmount != null) {
- order.setRefundAmount(refundAmount.add(r4_refundAmount));
- // 全部退完款重新加回已退款的金额
- order.setPrice(order.getPrice().add(refundAmount));
- } else {
- // 退款金额
- order.setRefundAmount(r4_refundAmount);
- }
- order.setStatus(3);
- if (order.getAltInfo() != null) {
- TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- String altInfo = altInfoReset(tEquipment.getId(), order.getRefundAmount());
- order.setAltInfo(altInfo);
- }
- }
- // 支付平台产生的退款流水号
- String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
- order.setRefundTrxNo(r5_RefundTrxNo);
- order.setRefundDate(new Date());
- order.setModifyDate(new Date());
- // orderService.updateById(order);
- String orderStatus = order.getOrderStatus();
- if (StringUtils.isNotEmpty(orderStatus) && orderStatus.equals("0")) {
- if (order.getStatus().toString().equals("3")) {
- TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
- JSONObject kindData = new JSONObject();
- String s = order.getId().toString();
- if (s.length() > 6) {
- s = s.substring(s.length() - 6, s.length());
- }
- kindData.put("mealCode", s);
- equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("refuse_success", kindData.toString()).toString());
- }
- }
- try {
- esTOrderService.updateDataById(order);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- orderService.updateById(order);
- }
- return "success";
- }
- return "success";
- }
- public String altInfoReset(Long equipmentId, BigDecimal price) {
- //获取分销 关联设备
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- Integer type = proportion.getType();
- JSONArray altInfo = new JSONArray();
- JSONArray altNewInfo = new JSONArray();
- BigDecimal adminProportion = null, agencyProportion = null, merchantProportion = null, personageProportion = null, selfProportion = null;
- Long agencyId = proportion.getAgencyId();
- Long merchantId = proportion.getMerchantId();
- Long personageId = proportion.getPersonageId();
- String orderType = null;
- BigDecimal agencyAmount = null;
- BigDecimal merchantAmount = null;
- BigDecimal personageAmount = null;
- BigDecimal selfAmount = null;
- TJoinpayMch agencyMch = null;
- TJoinpayMch merchantMch = null;
- TJoinpayMch personageMch = null;
- TJoinpayMch selfMch = null;
- JSONObject agencyJson = null;
- JSONObject merchantJson = null;
- JSONObject personageJson = null;
- JSONObject selfJson = null;
- // 砍掉千6手续费
- // BigDecimal cutPrice = price.multiply(new BigDecimal(99.4)).divide(new BigDecimal(100));
- //取消平台扣手续费
- BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
- switch (type) {
- case 0:
- agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- agencyProportion = proportion.getProportion();
- adminProportion = proportion.getAdminProportion();
- orderType = "1";
- // 代理分销获得利润
- agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- agencyJson = new JSONObject();
- agencyJson.put("altMchNo", agencyMch.getAltMchNo());
- agencyJson.put("altAmount", agencyAmount.toString());
- agencyJson.put("isGuar", "12");
- altInfo.add(agencyJson);
- break;
- case 1:
- agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- agencyProportion = proportion.getAgencyProportion();
- adminProportion = proportion.getAdminProportion();
- selfProportion = proportion.getProportion();
- orderType = "2";
- BigDecimal refuseAmount = new BigDecimal(0.00);
- if (agencyProportion.compareTo(refuseAmount) == 0 || agencyProportion == null) {
- // System.out.println("a等于b");
- } else {
- // 一级分销获得利润
- agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- agencyJson = new JSONObject();
- agencyJson.put("altMchNo", agencyMch.getAltMchNo());
- agencyJson.put("altAmount", agencyAmount.toString());
- agencyJson.put("isGuar", "12");
- altInfo.add(agencyJson);
- }
- // 商家自己分销获得利润
- selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- merchantJson = new JSONObject();
- merchantJson.put("altMchNo", selfMch.getAltMchNo());
- merchantJson.put("altAmount", selfAmount.toString());
- merchantJson.put("isGuar", "12");
- altInfo.add(merchantJson);
- break;
- case 2:
- agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
- merchantMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getMerchantId())));
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- agencyProportion = proportion.getAgencyProportion();
- adminProportion = proportion.getAdminProportion();
- merchantProportion = proportion.getMerchantProportion();
- personageProportion = proportion.getPersonageProportion();
- selfProportion = proportion.getProportion();
- orderType = "3";
- BigDecimal refuseAmount1 = new BigDecimal(0.00);
- if (agencyProportion.compareTo(refuseAmount1) == 0 || agencyProportion == null) {
- // System.out.println("a等于b");
- } else {
- // 代理分销获得利润
- agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- agencyJson = new JSONObject();
- agencyJson.put("altMchNo", agencyMch.getAltMchNo());
- agencyJson.put("altAmount", agencyAmount.toString());
- agencyJson.put("isGuar", "12");
- altInfo.add(agencyJson);
- }
- if (merchantProportion.compareTo(refuseAmount1) == 0 || merchantProportion == null) {
- // System.out.println("a等于b");
- } else {
- // 经销商分销获得利润
- merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- merchantJson = new JSONObject();
- merchantJson.put("altMchNo", merchantMch.getAltMchNo());
- merchantJson.put("altAmount", merchantAmount.toString());
- merchantJson.put("isGuar", "12");
- altInfo.add(merchantJson);
- }
- // 商家自己分销获得利润
- selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- merchantJson = new JSONObject();
- merchantJson.put("altMchNo", selfMch.getAltMchNo());
- merchantJson.put("altAmount", selfAmount.toString());
- merchantJson.put("isGuar", "12");
- altInfo.add(merchantJson);
- break;
- }
- return altInfo.toString();
- }
- public boolean hasDuplicateValue(List<String> values) {
- Set<String> uniqueValues = new HashSet<>();
- for (String value : values) {
- if (!value.equals("0") && !uniqueValues.add(value)) {
- // 如果添加失败,说明已存在相同的值,返回 true
- return true;
- }
- }
- // 如果循环结束仍未找到相同的值,则返回 false
- return false;
- }
- /**
- * 汇聚查询退款更新订单状态
- *
- * @param sn 订单号
- * @param refundTrxNo 退款流水号
- * @return
- */
- @RequestMapping(value = "/queryRefund", method = RequestMethod.GET)
- @ResponseBody
- public Object queryRefund(String sn, String refundTrxNo) {
- JSONObject resultJson = orderService.queryRefund(refundTrxNo);
- String refundStatus = resultJson.getString("ra_Status");
- BigDecimal r3RefundAmount = new BigDecimal(resultJson.getString("r3_RefundAmount"));
- System.out.println("退款状态:" + refundStatus);
- System.out.println("退款金额:" + r3RefundAmount);
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn, sn);
- TOrder order = orderService.getOne(query);
- if (order == null) {
- return "error";
- }
- if (order.getStatus() == 3) {
- return "success";
- }
- if (JoinpayConstant.r6_Status_100.equals(refundStatus)) {
- if (order.getRefundQuantity() < order.getProductNumber()) {
- order.setStatus(1);
- } else {
- order.setStatus(3);
- }
- // 更改订单明细表
- LambdaQueryWrapper<TOrderDetails> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(TOrderDetails::getOrderSn, sn);
- // 处理退款中状态的明细
- queryWrapper.eq(TOrderDetails::getRefundStatus, "4");
- List<TOrderDetails> tOrderDetails = orderDetailsService.list(queryWrapper);
- for (TOrderDetails tOrderDetail : tOrderDetails) {
- Integer refundQuantity = tOrderDetail.getRefundQuantity();
- Integer productNumber = tOrderDetail.getProductNumber();
- if (refundQuantity < productNumber) {
- // 部分退款
- tOrderDetail.setRefundStatus("2");
- orderDetailsService.updateById(tOrderDetail);
- } else {
- // 全部退款
- tOrderDetail.setRefundStatus("3");
- orderDetailsService.updateById(tOrderDetail);
- }
- }
- // r4_refundAmount: 退款金额
- BigDecimal r4_refundAmount = new BigDecimal(resultJson.getString("r3_RefundAmount"));
- if (order.getRefundMarketingAmount() != null) {
- r4_refundAmount = r4_refundAmount.add(order.getRefundMarketingAmount());
- }
- // price: 订单金额, refundAmount:已退款的金额
- BigDecimal price = order.getPrice();
- BigDecimal refundAmount = order.getRefundAmount();
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(order.getEquipmentId())));
- if (r3RefundAmount.compareTo(price) == 0) {
- JSONArray altInfo = getAltInfo(proportion, price);
- order.setAltInfo(altInfo.toString());
- order.setRefundAmount(r3RefundAmount);
- } else {
- if (refundAmount != null) {
- BigDecimal newRefundAmount = refundAmount.add(r4_refundAmount);
- // 如果小于订单金额
- if (newRefundAmount.compareTo(price) < 0) {
- JSONArray altInfo = getAltInfo(proportion, price.subtract(newRefundAmount));
- order.setAltInfo(altInfo.toString());
- } else {
- JSONArray altInfo = getAltInfo(proportion, price);
- order.setAltInfo(altInfo.toString());
- }
- } else {
- order.setRefundAmount(r4_refundAmount);
- if (r4_refundAmount.compareTo(price) < 0) {
- JSONArray altInfo = getAltInfo(proportion, price.subtract(r4_refundAmount));
- order.setAltInfo(altInfo.toString());
- }
- }
- }
- try {
- esTOrderService.updateDataById(order);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- orderService.updateById(order);
- }
- return "success";
- }
- return "success";
- }
- @ApiOperation("收钱吧反扫购物车支付")
- @PostMapping("/sqbCardPay")
- @ResponseBody
- public Object sqbCardPay(String authCode, String frpCode, String clientId, String ip, @RequestBody Map<String, String> productNameMap) {
- return orderService.sqbCardPay(authCode, frpCode, clientId, ip, productNameMap);
- }
- @ApiOperation("收钱吧发起退款")
- @PostMapping("/sqbRefund")
- public ResponseModel<?> sqbRefund(@RequestBody TOrder torder) {
- return orderService.sqbRefund(torder);
- }
- /**
- * 请求在线支付 主扫 优惠码 盲盒
- *
- * @param clientId 设备client id
- * @param productName 商品名称
- * @param frpCode 支付方式 支付宝:ALIPAY_NATIVE , 微信:WEIXIN_NATIVE
- * @param pri 有值代表是盲盒
- */
- @ApiOperation(value = "优化汇付支付")
- @GetMapping("/testUniPay")
- public Object testUniPay(String code, String clientId, String productName, String frpCode, String pri) {
- return orderService.scanpay(code, clientId, productName, frpCode, pri);
- }
- @ApiOperation("汇付微信预下单")
- @GetMapping("/huifuPayCreate")
- public Object huifuPayCreate(String sn, String openid) {
- return orderService.huifuPayCreate(sn, openid);
- }
- @ApiOperation("汇付查询订单交易结果")
- @GetMapping("/huifuPayQuery")
- public Object huifuPayQuery(String queryId, String sn, String companyType) {
- return orderService.huifuPayQuery(queryId, sn, companyType);
- }
- @ApiOperation(value = "购物车 请求在线支付 二码合一")
- @PostMapping("/newCarsPay")
- public Object newCarsPay(String clientId, @RequestBody Map<String, String> productNameMap) {
- if (productNameMap == null) {
- return JsonMessage.error("数据出错");
- }
- StringBuffer note = new StringBuffer();
- StringBuffer productName = new StringBuffer();
- String productNo = "";
- Map<String, Integer> productMap = new HashMap<>();
- Integer productNumber = 0;
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if (equipment == null || equipment.getId() == null) {
- return JsonMessage.error("找不到设备");
- }
- BigDecimal price = new BigDecimal("0.00");
- TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
- if (equipmentDesc == null || equipmentDesc.getEquipmentId() == null || equipmentDesc.getPayType() == null || equipmentDesc.getPayType().equals("0")) {
- // 1、type=0,原始设定,没有第二件半价
- for (String key : productNameMap.keySet()) {
- String entryValue = String.valueOf(productNameMap.get(key));
- List<String> value = JSON.parseArray(entryValue, String.class);
- boolean hasDuplicate = hasDuplicateValue(value);
- if (hasDuplicate) {
- return JsonMessage.error("优惠码输入重复,单个商品只能使用一个优惠码");
- }
- List<TPromoCode> promoCodeList = new ArrayList<>();
- // 1、校验优惠码
- if (value.size() > 0) {
- for (String code : value) {
- if (!code.equals("0")) {
- TPromoCode promoCode;
- ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- promoCode = tPromoCode;
- if (tPromoCode == null || tPromoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- Date lastUseDate = null;
- if (promoCode != null) {
- lastUseDate = promoCode.getLastUseDate();
- }
- if (lastUseDate != null && lastUseDate.getTime() < ((new Date()).getTime())) {
- promoCode.setIsUse("2");
- szwlFeign.updatePromoCode(String.valueOf(promoCode.getId()), "2");
- //过期
- return JsonMessage.success("4");
- }
- if (promoCode.getId() == null) {
- //不存在
- return JsonMessage.success("1");
- }
- if (promoCode.getIsUse().equals("1")) {
- //被使用
- return JsonMessage.success("2");
- }
- if (!promoCode.getAdminId().equals("1")) {
- if (String.valueOf(equipment.getAdminId()).equals(promoCode.getAdminId())) {
- } else {
- //不是本机
- return JsonMessage.success("3");
- }
- }
- if (promoCode.getDiscount() == null) {
- //旧优惠码
- return JsonMessage.success("0");
- }
- promoCodeList.add(promoCode);
- }
- }
- }
- String[] productInfo = key.split("-");
- String no = productInfo[0];
- String num = productInfo[1];
- //确定价格,然后叠加
- TProduct product = R.getDataIfSuccess(szwlFeign.getProductByNo(no, String.valueOf(equipment.getId())));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- String goodsName = product.getProductName();
- productMap.put(goodsName, Integer.valueOf(num));
- productNumber += Integer.valueOf(num);
- productName.append(goodsName).append("x").append(num).append(",");
- BigDecimal productPrice = product.getRmbPrice();
- productNo = product.getNo();
- if (promoCodeList.size() > 0) {
- //有优惠码
- BigDecimal onePrice = new BigDecimal("0.00");
- Map<BigDecimal, Integer> priceMap = new HashMap<>();
- int i;
- for (i = 0; i < promoCodeList.size(); i++) {
- BigDecimal discount = BigDecimal.valueOf(promoCodeList.get(i).getDiscount()).setScale(2, RoundingMode.HALF_DOWN);
- BigDecimal price1 = new BigDecimal(0.0);
- TPromoCode tPromoCode = promoCodeList.get(i);
- if (StringUtils.isNotEmpty(tPromoCode.getType()) && tPromoCode.getType().equals("1")) {
- if (productPrice.compareTo(discount) > 0) {
- // 如果 price 大于 discount,从 price 中减去 discount
- price1 = productPrice.subtract(discount).setScale(2, RoundingMode.HALF_DOWN);
- } else {
- // 如果 price 小于等于 discount,将 price 设置为 0
- price1 = BigDecimal.ZERO;
- }
- } else {
- if (tPromoCode.getDiscount() == 0) {
- price1 = BigDecimal.ZERO;
- } else {
- price1 = productPrice.multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- }
- price = price.add(price1);
- if (priceMap.containsKey(price1)) {
- priceMap.put(price1, priceMap.get(price1) + 1);
- } else {
- priceMap.put(price1, 1);
- }
- }
- if (i < Integer.valueOf(num)) {
- int a = Integer.valueOf(num) - i;
- BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price2);
- priceMap.put(price2, a);
- }
- for (BigDecimal priceKey : priceMap.keySet()) {
- note.append(goodsName).append("-").append(product.getNo()).append("-").append(RandomUtil.randomNumbers(5)).append(":");
- note.append(priceKey).append("-").append(priceMap.get(priceKey)).append(",");
- }
- } else {
- //1,type=0,原始设定,没有第二件半价
- int a = Integer.valueOf(num);
- BigDecimal price2 = productPrice.multiply(new BigDecimal(a)).setScale(2, RoundingMode.HALF_DOWN);
- price = price.add(price2);
- note.append(goodsName).append("-").append(product.getNo()).append(":");
- note.append(price2).append("-").append(num).append(",");
- }
- }
- } else {
- //2,type=1,第二件半价
- //2.1 判定是否有第二件,有多少个第二件半价
- for (String key : productNameMap.keySet()) {
- String[] productInfo = key.split("-");
- String no = productInfo[0];
- String num = productInfo[1];
- //确定价格,然后叠加
- TProduct product = R.getDataIfSuccess(szwlFeign.getProductByNo(no, String.valueOf(equipment.getId())));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- String goodsName = product.getProductName();
- BigDecimal productPrice = product.getRmbPrice();
- productName.append(goodsName).append("x").append(num).append(",");
- note.append(goodsName).append("-").append(product.getNo()).append(":");
- productNo = product.getNo();
- switch (num) {
- case "1":
- //1个 0个半价
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- case "2":
- //2个 1个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- note.append(price).append("-").append(num).append(",");
- break;
- case "3":
- //3个 1个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- case "4":
- //4个 2个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- note.append(price).append("-").append(num).append(",");
- break;
- case "5":
- //5个 2个半价
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- price = price.add(productPrice.multiply(new BigDecimal(5)).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN));
- price = price.add(productPrice);
- note.append(price).append("-").append(num).append(",");
- break;
- }
- }
- }
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- //查找商品
- if (BigDecimal.ZERO.compareTo(price) == 0) {
- return JsonMessage.success("0");
- }
- if (BigDecimal.ZERO.compareTo(price) > 0) {
- return JsonMessage.error("商品价格异常");
- }
- Long client6 = Long.parseLong(clientId.substring(clientId.length() - 6));
- String sn1 = orderService.initSn(client6);
- String sn2 = orderService.initSn(client6);
- // 获取关联设备的分销
- TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
- if (proportion == null || proportion.getId() == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- // 支付方式:0或null为汇聚,1为汇付支付
- String payPlatform = admin.getPayPlatform();
- String companyType = admin.getCompanyType();
- // 汇聚分账参数
- JSONArray altInfo = new JSONArray();
- // 汇付分账明细参数
- JSONObject acctSplitBunch = new JSONObject();
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- acctSplitBunch = getAcctSplitBunch(proportion, price, companyType);
- if (!(acctSplitBunch.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- } else {
- altInfo = getAltInfo(proportion, price);
- if (!(altInfo.size() > 0)) {
- return JsonMessage.error("设备商家未注册结算账号");
- }
- }
- String orderNo1 = sn1;
- String orderNo2 = sn2;
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- String productDesc = "";
- String commonParameter = "";
- String returnUrl = null;
- String notifyUrl = JoinpayConstant.Notify_Url;
- String isShowPic = "1";
- String openId = null;
- String authCode = null;
- String appid = null;
- String transactionModel = null;
- String tradeMerchantNo = admin.getTradeMerchantNo();
- String buyerId = null;
- String isAlt = "1";
- String altType = "11";
- String altUrl = null;
- BigDecimal marketingAmount = null;
- String frpCode1 = "WEIXIN_NATIVE";
- String frpCode2 = "ALIPAY_NATIVE";
- TOrder order = new TOrder();
- order.setId(IDGenerator.orderID());
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- order.setProductNo(productNo);
- // 去掉后面的逗号
- if (productNumber == 1) {
- productName.delete(productName.length() - 3, productName.length());
- } else {
- productName.deleteCharAt(productName.length() - 1);
- }
- order.setProductName(productName.toString());
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode1);
- order.setAltInfo(altInfo.toString());
- order.setProductNumber(productNumber);
- order.setStatus(0);
- order.setType(admin.getType());
- order.setCompanyType(companyType);
- order.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order.setAdminProportion(proportion.getProportion());
- order.setAgencyProportion(proportion.getAgencyProportion());
- order.setAgencyId(proportion.getAgencyId());
- order.setMerchantProportion(proportion.getMerchantProportion());
- order.setMerchantId(proportion.getMerchantId());
- order.setPersonageProportion(proportion.getPersonageProportion());
- order.setPersonageId(proportion.getPersonageId());
- }
- order.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order.setIsSettlement("0");
- }
- order.setNote(note.toString());
- TOrder order2 = new TOrder();
- order2.setId(IDGenerator.orderID());
- order2.setCreateDate(new Date());
- order2.setModifyDate(new Date());
- order2.setAdminId(admin.getId());
- order2.setSn(sn2);
- order2.setProductName(productName.toString());
- order2.setProductNo(productNo);
- order2.setPrice(price);
- order2.setClientId(equipment.getClientId());
- order2.setEquipmentId(equipmentId);
- order2.setFrpCode(frpCode2);
- order2.setAltInfo(altInfo.toString());
- order2.setStatus(0);
- order2.setProductNumber(productNumber);
- order2.setType(admin.getType());
- order2.setCompanyType(companyType);
- order2.setMachineType(equipment.getMachineType());
- if (admin.getType() == 0) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- }
- if (admin.getType() == 1) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- }
- if (admin.getType() == 2) {
- order2.setAdminProportion(proportion.getProportion());
- order2.setAgencyProportion(proportion.getAgencyProportion());
- order2.setAgencyId(proportion.getAgencyId());
- order2.setMerchantProportion(proportion.getMerchantProportion());
- order2.setMerchantId(proportion.getMerchantId());
- order2.setPersonageProportion(proportion.getPersonageProportion());
- order2.setPersonageId(proportion.getPersonageId());
- }
- order2.setPayPlatform(payPlatform);
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- order2.setIsSettlement("0");
- }
- order2.setNote(note.toString());
- // 订单明细表
- TOrderDetails orderDetails = new TOrderDetails();
- orderDetails.setAdminId(admin.getId());
- orderDetails.setEquipmentId(equipmentId);
- orderDetails.setCreateDate(new Date());
- orderDetails.setCompanyType(companyType);
- orderDetails.setRefundStatus("0");
- orderDetails.setMachineType(equipment.getMachineType());
- String productName1 = "";
- if (productNumber > 1) {
- if (equipment.getMachineType() == null || equipment.getMachineType().equals("0")) {
- productName1 = "棉花糖-" + equipment.getName() + "-" + client6;
- } else {
- productName1 = "爆米花-" + equipment.getName() + "-" + client6;
- }
- } else {
- productName1 = productName + "-" + equipment.getName() + "-" + client6;
- }
- Map<String, String> map = new HashMap<>();
- String[] products = order.getNote().split(",");
- for (String product : products) {
- String[] parts = product.split(":");
- // 商品名称-商品编号
- String key = parts[0];
- // 商品单价-商品数量
- String value = parts[1];
- map.put(key, value);
- }
- String result = null;
- if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
- // 汇付分账参数
- order.setAcctSplitBunch(acctSplitBunch.toString());
- order2.setAcctSplitBunch(acctSplitBunch.toString());
- String result1 = "";
- if (StrUtil.isNotEmpty(companyType) && companyType.equals("1")) {
- result1 = HuifuConstant.SC_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- } else {
- result1 = HuifuConstant.SZ_WECHAT_URL + "?price=" + price + "&sn=" + sn1;
- }
- try {
- result1 = URLEncoder.encode(result1, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- // 支付宝
- try {
- result = huifuMchService.uniPay(
- sn2, amount, productName1, productDesc,
- notifyUrl, frpCode2, openId, appid, acctSplitBunch, companyType
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- if (StrUtil.isEmpty(result)) {
- return JsonMessage.error("找不到支付图片");
- }
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://sz.sunzee.com.cn/PAY-SERVER/tOrder/aliPay?zfb=" + result + "&wx=" + result1;
- String qrcode = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", qrcode);
- for (String key : map.keySet()) {
- // key:"玫瑰精灵-A01",value:"0.50-1"
- String value = map.get(key);
- String[] GoodsInfo = key.split("-");
- String[] GoodsValue = value.split("-");
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setProductName(GoodsInfo[0]);
- orderDetails.setProductNo(GoodsInfo[1]);
- orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
- orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
- orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn1);
- orderDetailsService.save(orderDetails);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn2);
- orderDetailsService.save(orderDetails);
- }
- orderService.save(order);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- } else {
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode1,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- String rc_Result1 = resultJson.getString("rc_Result");
- String result1 = null;
- try {
- result1 = joinpayMchService.uniPay(
- orderNo2, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode2,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson1 = JSONObject.parseObject(result1);
- String rc_Result2 = resultJson1.getString("rc_Result");
- // 汇聚支付支付申请返回支付二维码图片
- String code1 = "http://app.sunzee.com.cn/" + "/api/order/aliPay.htm?wx=" + rc_Result1 + "&zfb=" + rc_Result2;
- String rd_Pic = toQrcode(code1);
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1 + "-" + sn2);
- kindData.put("rd_Pic", rd_Pic);
- for (String key : map.keySet()) {
- // key:"玫瑰精灵-A01",value:"0.50-1"
- String value = map.get(key);
- String[] GoodsInfo = key.split("-");
- String[] GoodsValue = value.split("-");
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setProductName(GoodsInfo[0]);
- orderDetails.setProductNo(GoodsInfo[1]);
- orderDetails.setPrice(new BigDecimal(GoodsValue[0]).divide(new BigDecimal(GoodsValue[1])).setScale(2));
- orderDetails.setProductNumber(Integer.valueOf(GoodsValue[1]));
- orderDetails.setAmount(new BigDecimal(GoodsValue[0]).setScale(2));
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn1);
- orderDetailsService.save(orderDetails);
- orderDetails.setId(HuifuUtils.initDetailsId());
- orderDetails.setOrderSn(sn2);
- orderDetailsService.save(orderDetails);
- }
- orderService.save(order);
- orderService.save(order2);
- return JsonMessage.success(kindData.toString());
- }
- }
- }
|