TOrderController.java 225 KB

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