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