From 19fa90abbc2043b73bef3992428d912d011fc8c5 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期三, 30 八月 2023 09:59:49 +0800 Subject: [PATCH] 合并代码 --- user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java | 257 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 230 insertions(+), 27 deletions(-) diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java index 53d9271..10c71f4 100644 --- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java +++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/OrderController.java @@ -1,31 +1,36 @@ package com.supersavedriving.user.modular.api; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.supersavedriving.user.core.common.annotion.ServiceLog; import com.supersavedriving.user.core.util.ToolUtil; -import com.supersavedriving.user.modular.system.model.AppUser; -import com.supersavedriving.user.modular.system.model.Order; -import com.supersavedriving.user.modular.system.service.IAppUserService; -import com.supersavedriving.user.modular.system.service.IBillService; -import com.supersavedriving.user.modular.system.service.IOrderService; +import com.supersavedriving.user.modular.system.model.*; +import com.supersavedriving.user.modular.system.service.*; +import com.supersavedriving.user.modular.system.util.GaoDe.MapUtil; +import com.supersavedriving.user.modular.system.util.GaoDe.model.District; +import com.supersavedriving.user.modular.system.util.MallBook.model.InterfaceResponse; +import com.supersavedriving.user.modular.system.util.MallBook.model.Receive; +import com.supersavedriving.user.modular.system.util.MallBook.model.ReceiveUser; +import com.supersavedriving.user.modular.system.util.MallBook.util.RSASignature; +import com.supersavedriving.user.modular.system.util.MallBook.util.TrhRequest; import com.supersavedriving.user.modular.system.util.PayMoneyUtil; import com.supersavedriving.user.modular.system.util.ResultUtil; import com.supersavedriving.user.modular.system.warpper.*; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.PrintWriter; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; import java.util.stream.Collectors; /** @@ -36,6 +41,8 @@ @RestController @RequestMapping("") public class OrderController { + + Logger logger = LoggerFactory.getLogger(OrderController.class); @Autowired private IOrderService orderService; @@ -48,6 +55,76 @@ @Autowired private IBillService billService; + + @Autowired + private IRevenueService revenueService; + + @Autowired + private IDriverService driverService; + + @Autowired + private IBranchOfficeService branchOfficeService; + + @Autowired + private ISystemConfigService systemConfigService; + + @Autowired + private IRechargeRecordService rechargeRecordService; + + @Autowired + private IAccountChangeDetailService accountChangeDetailService; + + @Autowired + private IDivisionRecordService divisionRecordService; + + + + + + @ResponseBody + @PostMapping("/api/order/queryServerPrice") +// @ServiceLog(name = "获取正在进行中的订单id", url = "/api/order/queryServerOrder") + @ApiOperation(value = "根据定位获取恶劣天气+节假日信息", tags = {"用户端-首页"}, notes = "") + @ApiImplicitParams({ + @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), + @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "String"), + @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "String"), + }) + public ResponseWarpper<Integer> queryServerPrice(String lat,String lon){ + try { + Integer i =0; // 0为不能接单 1为恶劣天气 2为节假日 3为恶劣+节假日 + District geocode = MapUtil.geocode(lon, lat); + String districtCode = geocode.getDistrictCode(); + List<BranchOffice> districtCode1 = branchOfficeService.selectList(new EntityWrapper<BranchOffice>().eq("districtCode", districtCode).eq("status",1)); + if(districtCode1.size()>0){ + BranchOffice branchOffice = districtCode1.get(0); + Integer id = branchOffice.getId(); + SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8).eq("companyId", id)); + if(systemConfig!=null){ + String content = systemConfig.getContent(); + JSONObject jsonObject = JSONObject.parseObject(content); + String num1 = jsonObject.get("num1").toString(); + String num9 = jsonObject.get("num3").toString(); + if("1".equals(num1)){ + i=1; + } + if("1".equals(num9)){ + i=2; + } + if("1".equals(num1)&&"1".equals(num9)){ + i=3; + } + } + if(i == 0){ + i = 4; + } + } + return ResponseWarpper.success(i); + }catch (Exception e){ + e.printStackTrace(); + return new ResponseWarpper(500, e.getMessage()); + } + } @@ -76,6 +153,7 @@ return new ResponseWarpper(500, e.getMessage()); } } + @@ -230,13 +308,13 @@ @ResponseBody @PostMapping("/api/order/queryOrderPrice") -// @ServiceLog(name = "获取待支付页面订单费用明细", url = "/api/order/queryOrderPrice") - @ApiOperation(value = "获取待支付页面订单费用明细", tags = {"用户端-首页"}, notes = "") +// @ServiceLog(name = "获取订单费用明细", url = "/api/order/queryOrderPrice") + @ApiOperation(value = "获取订单费用明细", tags = {"用户端-首页"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"), @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) - public ResponseWarpper<OrderPriceWarpper> queryOrderPrice(Long orderId){ + public ResponseWarpper<OrderPriceInfoWarpper> queryOrderPrice(Long orderId){ if(null == orderId){ return ResponseWarpper.success(ResultUtil.paranErr("orderId")); } @@ -245,7 +323,7 @@ if(null == uid){ return ResponseWarpper.success(ResultUtil.tokenErr()); } - OrderPriceWarpper orderPriceWarpper = orderService.queryOrderPrice(uid, orderId); + OrderPriceInfoWarpper orderPriceWarpper = orderService.queryOrderPrice(uid, orderId); return ResponseWarpper.success(orderPriceWarpper); }catch (Exception e){ e.printStackTrace(); @@ -338,26 +416,147 @@ /** * 订单微信支付回调处理 - * @param request * @param response */ @ResponseBody @PostMapping("/base/order/orderPayCallback") - public void orderPayCallback(HttpServletRequest request, HttpServletResponse response){ + public void orderPayCallback(@RequestBody InterfaceResponse interfaceResponse, HttpServletResponse response){ try { - Map<String, String> map = payMoneyUtil.weixinpayCallback(request); - if(null != map){ - String out_trade_no = map.get("out_trade_no"); - String transaction_id = map.get("transaction_id"); - String result = map.get("result"); - String orderId = out_trade_no.substring(17); - ResultUtil resultUtil = orderService.orderPayCallback(orderId, transaction_id); - if(resultUtil.getCode() == 10000){ + // 验签 + boolean verify = RSASignature.validate(interfaceResponse.content(), interfaceResponse.getSign()); + if (verify) {//验签成功业务处理逻辑 + if("0000".equals(interfaceResponse.getCode())){ + JSONObject jsonObject = JSON.parseObject(interfaceResponse.getResult()); + Integer status = jsonObject.getInteger("status"); + String orderId = jsonObject.getString("parameter1"); + String parameter2 = jsonObject.getString("parameter2"); + if(2 == status){ + Order order = orderService.selectById(orderId); + AccountChangeDetail accountChangeDetail = accountChangeDetailService.selectById(parameter2); + Double m = new BigDecimal(accountChangeDetail.getOldData()).subtract(new BigDecimal(accountChangeDetail.getNewData())).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); + AppUser appUser1 = appUserService.selectById(order.getUserId()); + appUser1.setAccountBalance(new BigDecimal(appUser1.getAccountBalance()).add(new BigDecimal(m)).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); + appUserService.updateById(appUser1); + accountChangeDetailService.deleteById(accountChangeDetail.getId()); + System.err.println("支付失败"); + } + if(1 == status){ + String merOrderId = jsonObject.getString("merOrderId"); + ResultUtil resultUtil = orderService.orderPayCallback(orderId, merOrderId); + if(resultUtil.getCode() == 10000){ + response.setStatus(200); + PrintWriter out = response.getWriter(); + out.print("OK"); + out.flush(); + out.close(); + } + } + } + } else {//验签失败业务处理逻辑 + System.err.println("支付回调验签失败"); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + + /** + * 转账回调 + * @param execute + * @param response + */ + @ResponseBody + @PostMapping("/base/order/zhaunzhangCallback") + public void zhaunzhangCallback(@RequestBody InterfaceResponse execute, HttpServletResponse response){ + try { + if("0000".equals(execute.getCode())){ + JSONObject jsonObject = JSON.parseObject(execute.getResult()); + Integer status = jsonObject.getInteger("status");//0:待处理;1:成功;2:失败 + if(2 == status){ + logger.warn("转账失败"); + return; + } + String parameter1 = jsonObject.getString("parameter1"); + RechargeRecord rechargeRecord = rechargeRecordService.selectById(parameter1); + + + response.setStatus(200); + PrintWriter out = response.getWriter(); + out.print("OK"); + out.flush(); + out.close(); + }else{ + logger.warn("转账失败:" + execute.getMsg()); + return; + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + + + /** + * 异步分账回调 + */ + @ResponseBody + @PostMapping("/base/order/ledgerCallback") + public void ledgerCallback(@RequestBody InterfaceResponse execute, HttpServletResponse response){ + try{ + // 验签 + boolean verify = RSASignature.validate(execute.content(), execute.getSign()); + if (verify) {//验签成功业务处理逻辑 + if("0000".equals(execute.getCode())){ + JSONObject jsonObject = JSON.parseObject(execute.getResult()); + Integer status = jsonObject.getInteger("status"); + if(2 == status){ + logger.warn("异步分账回调异常"); + return; + } + String merOrderId = jsonObject.getString("merOrderId"); + String divisionRecordId = jsonObject.getString("parameter1"); + DivisionRecord divisionRecord = divisionRecordService.selectById(divisionRecordId); + if(divisionRecord.getState() == 2){ + + } + + //确认收货 + new Timer().schedule(new TimerTask() { + @Override + public void run() { + Receive receive = new Receive();//确认收货 + receive.setOriginalMerOrderId(merOrderId); + receive.setRcvAmount(new BigDecimal(divisionRecord.getAmount()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); + List<ReceiveUser> splitList = new ArrayList<>(); + ReceiveUser receiveUser = new ReceiveUser(); + receiveUser.setSplitUserId(divisionRecord.getMerchantNumber()); + receiveUser.setRcvSplitAmount(new BigDecimal(divisionRecord.getAmount()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); + splitList.add(receiveUser); + receive.setSplitList(splitList); + TrhRequest<Receive> request1 = new TrhRequest(); + InterfaceResponse execute = request1.execute(receive, Receive.SERVICE_CODE); + if(!"0000".equals(execute.getCode())){ + logger.warn("确认收货" + execute.getMsg()); + } + JSONObject jsonObject = JSON.parseObject(execute.getResult()); + String status = jsonObject.getString("status"); + if("2".equals(status)){ + logger.warn("确认收货失败"); + } + if("0".equals(status)){ + logger.warn("确认收货处理中"); + } + } + }, 60000); + response.setStatus(200); PrintWriter out = response.getWriter(); - out.print(result); + out.print("OK"); out.flush(); out.close(); } + } else {//验签失败业务处理逻辑 + System.err.println("支付回调验签失败"); } }catch (Exception e){ e.printStackTrace(); @@ -495,4 +694,8 @@ return new ResponseWarpper(500, e.getMessage()); } } + + + + } -- Gitblit v1.7.1