1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298 |
- package com.szwl.controller;
- 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.metadata.IPage;
- 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.ResponseCodesEnum;
- import com.szwl.exception.BizException;
- 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.entity.*;
- import com.szwl.model.query.TAdminParam;
- import com.szwl.model.utils.*;
- import com.szwl.service.*;
- import com.szwl.service.es.EsTOrderService;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.ResponseEntity;
- 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.UnsupportedEncodingException;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.net.URLDecoder;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import static com.szwl.constant.ResponseCodesEnum.A0002;
- import static com.szwl.model.utils.DateUtils.PATTERN_yyyy_MM_dd_HH_mm_ss;
- /**
- * <p>
- * 前端控制器
- * </p>
- *
- * @author wuhs
- * @since 2022-06-17
- */
- @RestController
- @RequestMapping("/tOrder")
- public class TOrderController {
- @Autowired
- SzwlFeign szwlFeign;
- @Autowired
- TOrderService orderService;
- @Autowired
- TJoinpayMchService joinpayMchService;
- @Autowired
- TShandeMchService shandeMchService;
- @Autowired
- TEquipmentService equipmentService;
- @Autowired
- EsTOrderService esTOrderService;
- @Autowired
- TSzsmWxService szsmWxService;
- @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) {
- // IPage<?> iPage = R.getDataIfSuccess(szwlFeign.testPay("1"));
- // productName = "玫瑰精灵";
- String productName1 = 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 {
- //有优惠码,需要对优惠码进行验证
- // IPage<TPromoCode> pagePromoCode = R.getDataIfSuccess(szwlFeign.getTPromoCode(code));
- ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- // TPromoCode tPromoCode = R.getDataIfSuccess(szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString()));
- promoCode = tPromoCode;
- if (tPromoCode == null||tPromoCode.getId()==null) {
- //不存在
- return JsonMessage.success("1");
- }
- // List<TPromoCode> codeList = pagePromoCode.getRecords();
- // if (codeList.size() == 0) {
- // //不存在
- // return JsonMessage.success("1");
- // }
- // for (TPromoCode cod : codeList) {
- // if(!cod.getAdminId().equals("1")){
- // String adminId = cod.getAdminId();
- // String adminId1 = String.valueOf(equipment.getAdminId());
- // if (adminId.equals(adminId1)) {
- // promoCode = cod;
- // }
- // }else{
- // promoCode = cod;
- // }
- // }
- 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("参数错误");
- }
- if (equipment == null) {
- return JsonMessage.error("找不到设备");
- }
- Long equipmentId = equipment.getId();
- //查找商品
- ResponseModel<TProduct> product1 = szwlFeign.getProduct(String.valueOf(equipmentId), productName);
- TProduct product = product1.getData();
- // 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());
- price = product.getRmbPrice().multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- return JsonMessage.error("商品价格异常");
- }
- String sn = orderService.initSn(equipmentId);
- //获取分销 关联设备
- ResponseModel<TProportion> proportion1 = szwlFeign.getProportion(String.valueOf(equipmentId));
- TProportion proportion = proportion1.getData();
- // 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("找不到设备商家");
- }
- 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;
- if (type == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- 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())));
- // agencyMch = mchService.getUniqueness(admin.getAgencyId());
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (selfMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- agencyProportion = proportion.getAgencyProportion();
- adminProportion = proportion.getAdminProportion();
- selfProportion = proportion.getProportion();
- orderType = "2";
- // if(totalMoney.compareTo(refuseAmount) == 0){
- //// System.out.println("a等于b");
- // }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (merchantMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (selfMch == null) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- 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);
- }
- // 自己分销获得利润
- // personageAmount = cutPrice.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // personageJson = new JSONObject();
- // personageJson.put("altMchNo", personageMch.getAltMchNo());
- // personageJson.put("altAmount", personageAmount.toString());
- // personageJson.put("isGuar", "12");
- // altInfo.add(personageJson);
- // 商家自己分销获得利润
- 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;
- }
- 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 ="棉花糖";
- productName1 ="棉花糖";
- }
- TOrder order = new TOrder();
- 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(type);
- if(type==0){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(admin.getId());
- }
- if(type==1){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(admin.getId());
- }
- if(type==2){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(merchantId);
- order.setPersonageProportion(personageProportion);
- order.setPersonageId(admin.getId());
- }
- String payPlatform = admin.getPayPlatform();
- order.setPayPlatform(payPlatform);
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- order.setIsSettlement("0");
- }
- orderService.save(order);
- 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();
- }
- }
- String client6 = clientId.substring(clientId.length() - 6, clientId.length());
- productName = productName + "-" + equipment.getName() + "-" + client6;
- String result = null;
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- try {
- result = shandeMchService.uniPay(
- orderNo, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- // 返回支付二维码图片
- String rd_Pic = resultJson.getString("qr_code");
- String qrcode = toQrcode(rd_Pic);
- if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
- return JsonMessage.error("找不到支付图片");
- }
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn);
- kindData.put("rd_Pic", qrcode);
- return JsonMessage.success(kindData.toString());
- }else{
- try {
- result = joinpayMchService.uniPay(
- orderNo, amount, productName, 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);
- 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) {
- // IPage<?> iPage = R.getDataIfSuccess(szwlFeign.testPay("1"));
- // productName = "玫瑰精灵";
- String productName1 = 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();
- // TPromoCode tPromoCode = R.getDataIfSuccess(szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString()));
- promoCode = tPromoCode;
- if (tPromoCode == null||tPromoCode.getId()==null) {
- //不存在
- return JsonMessage.success("1");
- }
- // IPage<TPromoCode> pagePromoCode = R.getDataIfSuccess(szwlFeign.getTPromoCode(code));
- // List<TPromoCode> codeList = pagePromoCode.getRecords();
- // if (codeList.size() == 0) {
- // //不存在
- // return JsonMessage.success("1");
- // }
- // for (TPromoCode cod : codeList) {
- // if(!cod.getAdminId().equals("1")){
- // String adminId = cod.getAdminId();
- // String adminId1 = String.valueOf(equipment.getAdminId());
- // if (adminId.equals(adminId1)) {
- // promoCode = cod;
- // }
- // }else{
- // promoCode = cod;
- // }
- // }
- 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());
- price = product.getRmbPrice().multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- return JsonMessage.error("商品价格异常");
- }
- String sn = orderService.initSn(equipmentId);
- //获取分销 关联设备
- 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("找不到设备商家");
- }
- 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;
- if (type == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- 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())));
- // agencyMch = mchService.getUniqueness(admin.getAgencyId());
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (selfMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- agencyProportion = proportion.getAgencyProportion();
- adminProportion = proportion.getAdminProportion();
- selfProportion = proportion.getProportion();
- orderType = "2";
- // if(totalMoney.compareTo(refuseAmount) == 0){
- //// System.out.println("a等于b");
- // }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (merchantMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (selfMch == null) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- 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);
- }
- // 自己分销获得利润
- // personageAmount = cutPrice.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // personageJson = new JSONObject();
- // personageJson.put("altMchNo", personageMch.getAltMchNo());
- // personageJson.put("altAmount", personageAmount.toString());
- // personageJson.put("isGuar", "12");
- // altInfo.add(personageJson);
- // 商家自己分销获得利润
- 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;
- }
- 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 = authCode;
- 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 ="棉花糖";
- productName1 ="棉花糖";
- }
- BigDecimal marketingAmount = null;
- TOrder order = new TOrder();
- 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(type);
- if(type==0){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(admin.getId());
- }
- if(type==1){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(admin.getId());
- }
- if(type==2){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(merchantId);
- order.setPersonageProportion(personageProportion);
- order.setPersonageId(admin.getId());
- }
- String payPlatform = admin.getPayPlatform();
- order.setPayPlatform(payPlatform);
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- order.setIsSettlement("0");
- }
- orderService.save(order);
- 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();
- }
- }
- String client6 = clientId.substring(clientId.length() - 6, clientId.length());
- productName = productName + "-" + equipment.getName() + "-" + client6;
- String result = null;
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- try {
- result = shandeMchService.cardPay(
- orderNo, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, frpCode,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- // 返回支付二维码图片
- // String rd_Pic = resultJson.getString("qr_code");
- // String qrcode = toQrcode(rd_Pic);
- // if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
- // return JsonMessage.error("找不到支付图片");
- // }
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn);
- return JsonMessage.success(kindData.toString());
- }else{
- try {
- result = joinpayMchService.uniPay(
- orderNo, amount, productName, 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("找不到支付图片");
- // }
- if(resultJson.getString("ra_Code").equals("100")){
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn);
- return JsonMessage.success(kindData.toString());
- }else {
- return JsonMessage.error("申请支付失败");
- }
- }
- }
- /**
- * 请求在线支付 主扫 优惠码 二码合一
- *
- * @param clientId 设备client id
- * @param productName 商品名称
- * @param
- * @return
- */
- @ApiOperation(value = "请求在线支付 二码合一")
- @GetMapping("/twoPayCode")
- public Object twoPayCode(String code, String clientId, String productName) {
- // IPage<?> iPage = R.getDataIfSuccess(szwlFeign.testPay("1"));
- // productName = "玫瑰精灵";
- String productName1 = 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();
- // TPromoCode tPromoCode = R.getDataIfSuccess(szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString()));
- promoCode = tPromoCode;
- if (tPromoCode == null||tPromoCode.getId()==null) {
- //不存在
- return JsonMessage.success("1");
- }
- // IPage<TPromoCode> pagePromoCode = R.getDataIfSuccess(szwlFeign.getTPromoCode(code));
- // List<TPromoCode> codeList = pagePromoCode.getRecords();
- // if (codeList.size() == 0) {
- // //不存在
- // return JsonMessage.success("1");
- // }
- // for (TPromoCode cod : codeList) {
- // if(!cod.getAdminId().equals("1")){
- // String adminId = cod.getAdminId();
- // String adminId1 = String.valueOf(equipment.getAdminId());
- // if (adminId.equals(adminId1)) {
- // promoCode = cod;
- // }
- // }else{
- // promoCode = cod;
- // }
- // }
- 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();
- //查找商品
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- BigDecimal price = product.getRmbPrice();
- if(StringUtils.isNotEmpty(code)){
- BigDecimal discount = BigDecimal.valueOf(promoCode.getDiscount());
- price = product.getRmbPrice().multiply(discount).divide(new BigDecimal(10)).setScale(2, RoundingMode.HALF_DOWN);
- }
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- return JsonMessage.error("商品价格异常");
- }
- String sn1 = orderService.initSn(equipmentId);
- String sn2 = orderService.initSn(equipmentId);
- //获取分销 关联设备
- 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("找不到设备商家");
- }
- 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;
- if (type == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- 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())));
- // agencyMch = mchService.getUniqueness(admin.getAgencyId());
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (selfMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- agencyProportion = proportion.getAgencyProportion();
- adminProportion = proportion.getAdminProportion();
- selfProportion = proportion.getProportion();
- orderType = "2";
- // if(totalMoney.compareTo(refuseAmount) == 0){
- //// System.out.println("a等于b");
- // }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (merchantMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (selfMch == null) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- 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);
- }
- // 自己分销获得利润
- // personageAmount = cutPrice.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // personageJson = new JSONObject();
- // personageJson.put("altMchNo", personageMch.getAltMchNo());
- // personageJson.put("altAmount", personageAmount.toString());
- // personageJson.put("isGuar", "12");
- // altInfo.add(personageJson);
- // 商家自己分销获得利润
- 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;
- }
- 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.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- order.setProductId(product.getId());
- order.setProductNo(product.getNo());
- order.setProductName(productName);
- order.setPrice(price);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode1);
- order.setAltInfo(altInfo.toString());
- order.setStatus(0);
- order.setType(type);
- if(type==0){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(admin.getId());
- }
- if(type==1){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(admin.getId());
- }
- if(type==2){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(merchantId);
- order.setPersonageProportion(personageProportion);
- order.setPersonageId(admin.getId());
- }
- String payPlatform = admin.getPayPlatform();
- order.setPayPlatform(payPlatform);
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- order.setIsSettlement("0");
- }
- orderService.save(order);
- TOrder order2 = new TOrder();
- order2.setCreateDate(new Date());
- order2.setModifyDate(new Date());
- order2.setAdminId(admin.getId());
- order2.setSn(sn2);
- order2.setProductId(product.getId());
- order2.setProductNo(product.getNo());
- order2.setProductName(productName);
- order2.setPrice(price);
- order2.setClientId(equipment.getClientId());
- order2.setEquipmentId(equipmentId);
- order2.setFrpCode(frpCode1);
- order2.setAltInfo(altInfo.toString());
- order2.setStatus(0);
- order2.setPayPlatform(payPlatform);
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- order2.setIsSettlement("0");
- }
- orderService.save(order2);
- 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();
- }
- }
- String client6 = clientId.substring(clientId.length() - 6, clientId.length());
- productName = productName + "-" + equipment.getName() + "-" + client6;
- String result = null;
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- try {
- result = shandeMchService.uniPay(
- orderNo1, amount, productName1, productDesc,
- commonParameter, returnUrl, notifyUrl, null,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- // 返回支付二维码图片
- String rd_Pic = resultJson.getString("qr_code");
- String qrcode = toQrcode(rd_Pic);
- if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
- return JsonMessage.error("找不到支付图片");
- }
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1);
- kindData.put("rd_Pic", qrcode);
- return JsonMessage.success(kindData.toString());
- }else{
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName, 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, productName, 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 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);
- return JsonMessage.success(kindData.toString());
- }
- }
- @ApiOperation(value = "购物车 请求在线支付 二码合一")
- @PostMapping("/carsPay")
- public Object carsPay(String clientId, @RequestBody Map<String,String> productNameMap) {
- // IPage<?> iPage = R.getDataIfSuccess(szwlFeign.testPay("1"));
- // productName = "玫瑰精灵";
- if(productNameMap==null){
- return JsonMessage.error("数据出错");
- }
- StringBuffer productName1 = new StringBuffer();
- StringBuffer note = new StringBuffer();
- StringBuffer productName = new StringBuffer();
- TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
- if(equipment==null||equipment.getId()==null){
- return JsonMessage.error("找不到设备");
- }
- BigDecimal price = new BigDecimal("0.00");
- // JSONObject mapList = JSON.parseObject(productNameMap);
- 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()) {
- // System.out.println("key= "+ key + " and value= " + productNameMap.get(key));
- String entryValue = String.valueOf(productNameMap.get(key));
- // String key = String.valueOf(entry.getKey());
- // String entryValue = String.valueOf(entry.getValue());
- 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> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- // TPromoCode tPromoCode = R.getDataIfSuccess(szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString()));
- promoCode = tPromoCode;
- if (tPromoCode == null||tPromoCode.getId()==null) {
- //不存在
- return JsonMessage.success("1");
- }
- // IPage<TPromoCode> pagePromoCode = R.getDataIfSuccess(szwlFeign.getTPromoCode(code));
- // List<TPromoCode> codeList = pagePromoCode.getRecords();
- //
- // if (codeList.size() == 0) {
- // //不存在
- // return JsonMessage.success("1");
- // }
- // for (TPromoCode cod : codeList) {
- // if(!cod.getAdminId().equals("1")){
- // String adminId = cod.getAdminId();
- // String adminId1 = String.valueOf(equipment.getAdminId());
- // if (adminId.equals(adminId1)) {
- // promoCode = cod;
- // }
- // }else{
- // promoCode = cod;
- // }
- // }
- 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];
- productName.append(productNamea).append(num);
- note.append(productNamea).append(num).append(":");
- productName1.append(productNamea).append(num);
- //确定价格,然后叠加R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- BigDecimal productPrice = product.getRmbPrice();
- if(promoCodeList.size()>0){
- //有优惠码
- BigDecimal onePrice = new BigDecimal("0.00");
- int i;
- for( i = 0;i<promoCodeList.size();i++){
- BigDecimal discount = BigDecimal.valueOf(promoCodeList.get(i).getDiscount()).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(",");
- }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()) {
- // System.out.println("key= "+ key + " and value= " + productNameMap.get(key));
- 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];
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
- BigDecimal productPrice = product.getRmbPrice();
- productName.append(productNamea).append(num);
- productName1.append(productNamea).append(num);
- 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();
- //查找商品
- // TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName.toString()));
- // if (product == null) {
- // return JsonMessage.error("找不到商品");
- // }
- if (BigDecimal.ZERO.compareTo(price) >= 0) {
- return JsonMessage.error("商品价格异常");
- }
- String sn1 = orderService.initSn(equipmentId);
- String sn2 = orderService.initSn(equipmentId);
- //获取分销 关联设备
- 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("找不到设备商家");
- }
- 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;
- if (type == null) {
- return JsonMessage.error("设备商家未完成分销设置");
- }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- 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())));
- // agencyMch = mchService.getUniqueness(admin.getAgencyId());
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (selfMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- agencyProportion = proportion.getAgencyProportion();
- adminProportion = proportion.getAdminProportion();
- selfProportion = proportion.getProportion();
- orderType = "2";
- // if(totalMoney.compareTo(refuseAmount) == 0){
- //// System.out.println("a等于b");
- // }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (merchantMch == null ) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- if (selfMch == null) {
- return JsonMessage.error("设备商家未注册提现账户");
- }
- agencyProportion = proportion.getAgencyProportion();
- adminProportion = proportion.getAdminProportion();
- merchantProportion = proportion.getMerchantProportion();
- personageProportion = proportion.getPersonageProportion();
- 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);
- }
- // 自己分销获得利润
- // personageAmount = cutPrice.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // personageJson = new JSONObject();
- // personageJson.put("altMchNo", personageMch.getAltMchNo());
- // personageJson.put("altAmount", personageAmount.toString());
- // personageJson.put("isGuar", "12");
- // altInfo.add(personageJson);
- // 商家自己分销获得利润
- 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;
- }
- 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.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- // order.setProductId(product.getId());
- // order.setProductNo(product.getNo());
- 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(type);
- if(type==0){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(admin.getId());
- }
- if(type==1){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(admin.getId());
- }
- if(type==2){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(merchantId);
- order.setPersonageProportion(personageProportion);
- order.setPersonageId(admin.getId());
- }
- String payPlatform = admin.getPayPlatform();
- order.setPayPlatform(payPlatform);
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- order.setIsSettlement("0");
- }
- order.setNote(note.toString());
- orderService.save(order);
- TOrder order2 = new TOrder();
- order2.setCreateDate(new Date());
- order2.setModifyDate(new Date());
- order2.setAdminId(admin.getId());
- order2.setSn(sn2);
- // order2.setProductId(product.getId());
- // order2.setProductNo(product.getNo());
- order2.setProductName(productName.toString());
- order2.setPrice(price);
- order2.setClientId(equipment.getClientId());
- order2.setEquipmentId(equipmentId);
- order2.setFrpCode(frpCode1);
- order2.setAltInfo(altInfo.toString());
- order2.setStatus(0);
- order2.setType(type);
- if(type==0){
- order2.setAdminProportion(adminProportion);
- order2.setAgencyProportion(agencyProportion);
- order2.setAgencyId(admin.getId());
- }
- if(type==1){
- order2.setAdminProportion(adminProportion);
- order2.setAgencyProportion(agencyProportion);
- order2.setAgencyId(agencyId);
- order2.setMerchantProportion(merchantProportion);
- order2.setMerchantId(admin.getId());
- }
- if(type==2){
- order2.setAdminProportion(adminProportion);
- order2.setAgencyProportion(agencyProportion);
- order2.setAgencyId(agencyId);
- order2.setMerchantProportion(merchantProportion);
- order2.setMerchantId(merchantId);
- order2.setPersonageProportion(personageProportion);
- order2.setPersonageId(admin.getId());
- }
- order2.setPayPlatform(payPlatform);
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- order2.setIsSettlement("0");
- }
- order2.setNote(note.toString());
- orderService.save(order2);
- 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();
- }
- }
- String result = null;
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- try {
- result = shandeMchService.uniPay(
- orderNo1, amount, productName1.toString(), productDesc,
- commonParameter, returnUrl, notifyUrl, null,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- // 返回支付二维码图片
- String rd_Pic = resultJson.getString("qr_code");
- String qrcode = toQrcode(rd_Pic);
- if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
- return JsonMessage.error("找不到支付图片");
- }
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1);
- kindData.put("rd_Pic", qrcode);
- return JsonMessage.success(kindData.toString());
- }else{
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName.toString(), 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, productName.toString(), 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);
- 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 productName1 = new StringBuffer();
- StringBuffer note = new StringBuffer();
- StringBuffer productName = new StringBuffer();
- 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> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
- // TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
- // TPromoCode tPromoCode = R.getDataIfSuccess(szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString()));
- 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];
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
- if (product == null) {
- return JsonMessage.error("找不到商品");
- }
- productName.append(productNamea).append(num);
- String no = product.getNo();
- if(StringUtils.isEmpty(no)){
- no="A00";
- }
- note.append(no).append("-").append(productNamea).append("-").append(num).append(":");
- productName1.append(productNamea).append(num);
- //确定价格,然后叠加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()) {
- // System.out.println("key= "+ key + " and value= " + productNameMap.get(key));
- 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];
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
- BigDecimal productPrice = product.getRmbPrice();
- productName.append(productNamea).append(num);
- productName1.append(productNamea).append(num);
- 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();
- //查找商品
- // TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName.toString()));
- // if (product == null) {
- // return JsonMessage.error("找不到商品");
- // }
- // if (BigDecimal.ZERO.compareTo(price) >= 0) {
- // return JsonMessage.error("商品价格异常");
- // }
- String sn1 = orderService.initSn(equipmentId);
- // String sn2 = orderService.initSn(equipmentId);
- //获取分销 关联设备
- 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("找不到设备商家");
- }
- 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;
- if (type == null) {
- return JsonMessage.error("设备未完成分销设置");
- }
- 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())));
- if (agencyMch == null ) {
- return JsonMessage.error("1商家未注册提现账户");
- }
- 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())));
- // agencyMch = mchService.getUniqueness(admin.getAgencyId());
- selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
- if (agencyMch == null && proportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))>0) {
- return JsonMessage.error("1备商家未注册提现账户");
- }
- if (selfMch == null ) {
- return JsonMessage.error("商家未注册提现账户");
- }
- agencyProportion = proportion.getAgencyProportion();
- adminProportion = proportion.getAdminProportion();
- selfProportion = proportion.getProportion();
- orderType = "2";
- // if(totalMoney.compareTo(refuseAmount) == 0){
- //// System.out.println("a等于b");
- // }
- 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())));
- if (agencyMch == null && proportion.getAgencyProportion().compareTo(new BigDecimal("0.00"))>0) {
- return JsonMessage.error("1商家未注册提现账户");
- }
- if (merchantMch == null && proportion.getMerchantProportion().compareTo(new BigDecimal("0.00"))>0) {
- return JsonMessage.error("2商家未注册提现账户");
- }
- if (selfMch == null) {
- return JsonMessage.error("商家未注册提现账户");
- }
- 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);
- }
- // 自己分销获得利润
- // personageAmount = cutPrice.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
- // personageJson = new JSONObject();
- // personageJson.put("altMchNo", personageMch.getAltMchNo());
- // personageJson.put("altAmount", personageAmount.toString());
- // personageJson.put("isGuar", "12");
- // altInfo.add(personageJson);
- // 商家自己分销获得利润
- 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;
- }
- 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";
- // String frpCode2 = "ALIPAY_NATIVE";
- BigDecimal amount = price.setScale(2, RoundingMode.HALF_DOWN);
- TOrder order = new TOrder();
- order.setCreateDate(new Date());
- order.setModifyDate(new Date());
- order.setAdminId(admin.getId());
- order.setSn(sn1);
- // order.setProductDesc(String.valueOf(productNameMap));
- order.setProductDesc(JSONArray.toJSONString(productNameMap));
- // order.setProductId(product.getId());
- // order.setProductNo(product.getNo());
- order.setProductName(productName.toString());
- order.setPrice(cutPrice);
- order.setClientId(equipment.getClientId());
- order.setEquipmentId(equipmentId);
- order.setFrpCode(frpCode1);
- order.setAltInfo(altInfo.toString());
- order.setStatus(0);
- order.setType(type);
- order.setMarketingAmount(marketingAmount);
- if(couponList.size()>0){
- order.setCoupons(couponList.toString());
- }
- if(type==0){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(admin.getId());
- }
- if(type==1){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(admin.getId());
- }
- if(type==2){
- order.setAdminProportion(adminProportion);
- order.setAgencyProportion(agencyProportion);
- order.setAgencyId(agencyId);
- order.setMerchantProportion(merchantProportion);
- order.setMerchantId(merchantId);
- order.setPersonageProportion(personageProportion);
- order.setPersonageId(admin.getId());
- }
- String payPlatform = admin.getPayPlatform();
- 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));
- }
- orderService.save(order);
- 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("支付成功");
- }
- 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();
- }
- }
- String result = null;
- if(StringUtils.isNotEmpty(payPlatform)&&payPlatform.equals("1")){
- try {
- result = shandeMchService.uniPay(
- orderNo1, amount, productName1.toString(), productDesc,
- commonParameter, returnUrl, notifyUrl, null,
- isShowPic, openId, authCode, appid, transactionModel, tradeMerchantNo,
- buyerId, isAlt, altType, altInfo, altUrl, marketingAmount
- );
- } catch (Exception e) {
- e.printStackTrace();
- return JsonMessage.error("申请支付失败");
- }
- JSONObject resultJson = JSONObject.parseObject(result);
- // 返回支付二维码图片
- String rd_Pic = resultJson.getString("qr_code");
- String qrcode = toQrcode(rd_Pic);
- if (resultJson == null || StringUtils.isBlank(rd_Pic)) {
- return JsonMessage.error("找不到支付图片");
- }
- JSONObject kindData = new JSONObject();
- kindData.put("sn", sn1);
- kindData.put("rd_Pic", qrcode);
- return JsonMessage.success(kindData.toString());
- }else{
- try {
- result = joinpayMchService.uniPay(
- orderNo1, amount, productName.toString(), 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("申请支付失败");
- }
- // JSONObject kindData = new JSONObject();
- // kindData.put("sn", sn1);
- // kindData.put("rc_Result", rc_Result);
- Map<String,String> map = new HashMap<>();
- map.put("sn", sn1);
- map.put("rc_Result", rc_Result);
- return JsonMessage.success(map);
- }
- }
- /**
- * 支付成功回调 汇聚
- *
- * @return
- */
- @RequestMapping(value = "/notify", method = RequestMethod.GET)
- @ResponseBody
- public Object refund(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);
- List<TOrder> list = orderService.list(query);
- TOrder order = new TOrder();
- if(list.size()>0){
- order = list.get(0);
- }
- // if (order.getStatus() != TOrder.Status.unpay) {
- // 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);
- //传送数据
- sentJingZhun(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();
- 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("0");
- equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("cardPayXCX", kindData1.toString()).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 {
- 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 {
- esTOrderService.insertData(order);
- orderService.updateById(order);
- }catch (Exception e) {
- e.printStackTrace();
- }
- 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";
- }
- // @RequestMapping(value = "/sentJingZhun", method = RequestMethod.POST)
- // @ResponseBody
- private void sentJingZhun( TOrder order) {
- order = orderService.getById(order.getId());
- int i = 0;
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
- if(admin.getId().toString().equals("372")||admin.getRelationAdminId().equals("372")||admin.getId().toString().equals("639")||admin.getId().toString().equals("238")){
- //发送数据到鲸准
- 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());
- map.put("amount",order.getMarketingAmount().toString());
- 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);
- List<TOrder> list = orderService.list();
- 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 {
- esTOrderService.insertData(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);
- List<TOrder> list = orderService.list();
- TOrder order = new TOrder();
- 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;
- }
- /**
- * 退款成功回调
- *
- * @param request
- * @return
- */
- @RequestMapping(value = "/notifyRefund", method = RequestMethod.GET)
- @ResponseBody
- public Object notifyRefund(HttpServletRequest request) {
- String r6_Status = request.getParameter("ra_Status");
- // 订单号
- String sn = request.getParameter("r2_OrderNo");
- LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
- query.eq(TOrder::getSn,sn);
- List<TOrder> list = orderService.list(query);
- TOrder order = list.get(0);
- if (order == null) {
- return "success";
- }
- if (order.getStatus() == 3) {
- return "success";
- }
- if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
- // 已退款
- order.setStatus(3);
- BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
- if(order.getRefundMarketingAmount()!=null){
- r4_refundAmount =r4_refundAmount.add(order.getRefundMarketingAmount());
- }
- BigDecimal price = order.getPrice();
- if(r4_refundAmount.compareTo(price)==-1){
- 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(r4_refundAmount.compareTo(price)==0){
- BigDecimal refundAmount = order.getRefundAmount();
- if(refundAmount!=null){
- order.setRefundAmount(refundAmount.add(r4_refundAmount));
- order.setPrice(order.getPrice().add(r4_refundAmount));
- }else {
- // 退款金额
- order.setRefundAmount(r4_refundAmount);
- }
- }
- // 退款金额
- // order.setRefundAmount(new BigDecimal(request.getParameter("r4_RefundAmount_str")));
- // 支付平台产生的退款流水号
- 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();
- }
- return "success";
- }
- return "success";
- }
- @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);
- return R.ok();
- }
- @ApiOperation(value = "获取订单")
- @GetMapping("/getOrder")
- public ResponseModel<?> getOrder(@RequestParam String id) {
- TOrder order = orderService.getById(id);
- return R.ok(order);
- }
- /**
- * 优惠码支付成功回调
- *
- * @return
- */
- @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");
- 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 = orderService.list();
- 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);
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
- JSONObject kindData = new JSONObject();
- kindData.put("sn", order.getSn());
- kindData.put("productName", order.getProductName());
- // List<String> codes = new ArrayList<>();
- // for (int i = 0; i < number; i++) {
- // String code = orderService.initSn(order.getEquipmentId());
- // StringBuffer str = new StringBuffer();
- // str.append(code.substring(0, 6));
- // codes.add(str.toString());
- // }
- String mont = order.getRefundTrxNo();
- Long data = Calendar.getInstance().getTimeInMillis();
- // Long month = 30L * 24L * 60L * 60L * 1000L;
- // Long d = data + month;
- 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);
- // for (String code : codes) {
- // TPromoCode promoCode = new TPromoCode();
- // promoCode.setCode(Long.parseLong(code));
- // promoCode.setAdminId(String.valueOf(order.getAdminId()));
- // promoCode.setIsUse("0");
- // promoCode.setDiscount(0f);
- // promoCode.setLastUseDate(lastUseDate);
- // promoCode.setCreateDate(new Date());
- // promoCode.setUserName(admin.getUsername());
- // promoCodeService.save(promoCode);
- // }
- return "支付成功";
- }
- return "success";
- }
- /**
- * 查询订单是否付款
- *
- * @param
- * @param
- * @return
- */
- @RequestMapping(value = "/getOrderStatus", method = RequestMethod.GET)
- @ResponseBody
- public JsonMessage getOrderStatus(String 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 sta = status.toString();
- if(status==1){
- sta="pay";
- }
- return JsonMessage.success(sta);
- }
- /**
- * 上传订单的做糖状态
- *
- * @param
- * @param
- * @return
- */
- @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()));
- }
- return JsonMessage.success("success");
- }
- /**
- * 删除订单
- *
- * @param
- * @param
- * @return
- */
- @RequestMapping(value = "/deleteOrder", method = RequestMethod.GET)
- @ResponseBody
- public JsonMessage deleteOrder(String 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 = adminService.find(equipment.getAdminId());
- TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
- if (admin == null) {
- return JsonMessage.error("找不到设备商家");
- }
- JSONArray altInfo = new JSONArray();
- // Long agencyId = admin.getAgencyId();
- // Long merchantId = admin.getMerchantId();
- // Long personageId = admin.getPersonageId();
- // Admin.Type type = admin.getType();
- // Order.Type orderType = null;
- 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;
- }
- // TOrder order = new TOrder(sn, null, productName, price, equipment.getClientId(), equipmentId,
- // orderType, admin.getId(), agencyId, merchantId, personageId,
- // null, altInfo.toString(), null, null, null, null, Order.Status.pay);
- TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
- TOrder order = new TOrder();
- 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 {
- esTOrderService.insertData(order);
- }catch (Exception e) {
- e.printStackTrace();
- }
- return JsonMessage.success("success");
- }
- }
|