| | |
| | | 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.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.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | 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.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private IBillService billService; |
| | | |
| | | @Autowired |
| | | private IRevenueService revenueService; |
| | | |
| | | @Autowired |
| | | private IDriverService driverService; |
| | | |
| | | @Autowired |
| | | private IRechargeRecordService rechargeRecordService; |
| | | |
| | | @Autowired |
| | | private IAccountChangeDetailService accountChangeDetailService; |
| | | |
| | | @Autowired |
| | | private IDivisionRecordService divisionRecordService; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | @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")); |
| | | } |
| | |
| | | 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(); |
| | |
| | | |
| | | /** |
| | | * 订单微信支付回调处理 |
| | | * @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 = accountChangeDetail.getOldData() - accountChangeDetail.getNewData(); |
| | | AppUser appUser1 = appUserService.selectById(order.getUserId()); |
| | | appUser1.setAccountBalance(appUser1.getAccountBalance() + m); |
| | | 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){ |
| | | System.err.println("转账失败"); |
| | | 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{ |
| | | System.err.println("转账失败:" + 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){ |
| | | System.err.println("异步分账回调异常"); |
| | | return; |
| | | } |
| | | String merOrderId = jsonObject.getString("merOrderId"); |
| | | String divisionRecordId = jsonObject.getString("parameter1"); |
| | | //确认收货 |
| | | new Timer().schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | DivisionRecord divisionRecord = divisionRecordService.selectById(divisionRecordId); |
| | | Receive receive = new Receive();//确认收货 |
| | | receive.setOriginalMerOrderId(merOrderId); |
| | | receive.setRcvAmount(String.valueOf(Double.valueOf(divisionRecord.getAmount() * 100).intValue())); |
| | | List<ReceiveUser> splitList = new ArrayList<>(); |
| | | ReceiveUser receiveUser = new ReceiveUser(); |
| | | receiveUser.setSplitUserId(divisionRecord.getMerchantNumber()); |
| | | receiveUser.setRcvSplitAmount(String.valueOf(Double.valueOf(divisionRecord.getAmount() * 100).intValue())); |
| | | splitList.add(receiveUser); |
| | | receive.setSplitList(splitList); |
| | | TrhRequest<Receive> request1 = new TrhRequest(); |
| | | InterfaceResponse execute = request1.execute(receive, Receive.SERVICE_CODE); |
| | | if(!"0000".equals(execute.getCode())){ |
| | | System.err.println("确认收货" + execute.getMsg()); |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.getResult()); |
| | | String status = jsonObject.getString("status"); |
| | | if("2".equals(status)){ |
| | | System.err.println("确认收货失败"); |
| | | } |
| | | if("0".equals(status)){ |
| | | System.err.println("确认收货处理中"); |
| | | } |
| | | } |
| | | }, 15000); |
| | | 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(); |
| | |
| | | return new ResponseWarpper(500, e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |