oying-system/src/main/java/com/oying/modules/hwc/service/impl/CallbackServiceImpl.java
@@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.Map; /** @@ -39,18 +40,19 @@ @Override @Transactional(rollbackFor = Exception.class) public void alipayCallback(HttpServletRequest request, HttpServletResponse response) { Map<String, String> map = new HashMap<>(); try { String resString = XmlUtils.parseRequest(request); String respString = "error"; if (!resString.isEmpty()) { Map<String, String> map = XmlUtils.toMap(resString.getBytes(), "utf-8"); map = XmlUtils.toMap(resString.getBytes(), "utf-8"); String sign_type = map.get("sign_type"); String reSign = map.get("sign"); if (map.containsKey("sign")) { OrderResponse order = orderService.getByOrderNum(map.get("out_trade_no")); PayTypeEnum status = PayTypeEnum.find(order.getOrder().getPayType()); if (SignUtil.verifySign(reSign, sign_type, map, properties, status)) { log.error("验证签名错误!:{}", map.toString()); log.error("汇旺财支付验证签名错误!:{}", map.toString()); } else { if ("0".equals(map.get("status"))) { if ("0".equals(map.get("result_code"))) { @@ -75,6 +77,7 @@ } response.getWriter().write(respString); } catch (Exception e) { log.error("汇旺财支付回调失败:{}", map.toString()); throw new BadRequestException("操作失败,原因:" + e.getMessage()); } } @@ -82,18 +85,19 @@ @Override @Transactional(rollbackFor = Exception.class) public void returnNotify(HttpServletRequest request, HttpServletResponse response) { Map<String, String> map = new HashMap<>(); try { String resString = XmlUtils.parseRequest(request); String respString = "error"; if (!resString.isEmpty()) { Map<String, String> map = XmlUtils.toMap(resString.getBytes(), "utf-8"); map = XmlUtils.toMap(resString.getBytes(), "utf-8"); String sign_type = map.get("sign_type"); String reSign = map.get("sign"); if (map.containsKey("sign")) { OrderReturn order = returnService.getByReturnNum(map.get("out_refund_no")); PayTypeEnum status = PayTypeEnum.find(order.getPayType()); if (SignUtil.verifySign(reSign, sign_type, map, properties, status)) { log.error("验证签名错误!:{}", map.toString()); log.error("汇旺财退款验证签名错误!:{}", map.toString()); } else { if ("0".equals(map.get("status"))) { if ("0".equals(map.get("result_code"))) { @@ -109,6 +113,7 @@ } response.getWriter().write(respString); } catch (Exception e) { log.error("汇旺财退款回调失败:{}", map.toString()); System.out.println("操作失败,原因:" + e.getMessage()); } } oying-system/src/main/java/com/oying/modules/sh/domain/vo/OrderInfo.java
@@ -1,5 +1,6 @@ package com.oying.modules.sh.domain.vo; import com.oying.modules.pc.store.domain.Store; import com.oying.modules.sh.domain.UserAddress; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; @@ -17,6 +18,8 @@ @Setter public class OrderInfo { @ApiModelProperty(value = "门店信息") private Store store; @ApiModelProperty(value = "商品信息列") private List<ProductInfo> products; @ApiModelProperty(value = "用户地址信息") oying-system/src/main/java/com/oying/modules/sh/rest/OrderController.java
@@ -100,11 +100,11 @@ return new ResponseEntity<>(R.success(), HttpStatus.OK); } @Log("关闭订单") @ApiOperation("关闭订单") @PostMapping(value = "/closeOrder") public ResponseEntity<Object> closeOrder(@RequestParam String orderNum) { orderService.closeOrder(orderNum); @Log("用户取消订单") @ApiOperation("用户取消订单") @PostMapping(value = "/cancel") public ResponseEntity<Object> cancel(@RequestParam String orderNum) { orderService.cancel(orderNum); return new ResponseEntity<>(R.success(), HttpStatus.OK); } oying-system/src/main/java/com/oying/modules/sh/service/OrderService.java
@@ -83,7 +83,7 @@ */ void download(List<Order> all, HttpServletResponse response) throws IOException; void closeOrder(String orderNum); void cancel(String orderNum); void statusOrder(StatusOrder statusOrder); } oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderOperationLogServiceImpl.java
@@ -54,6 +54,7 @@ @Transactional(rollbackFor = Exception.class) public void create(OrderResponse response, OrderStatusEnum statusEnum, String cardName) { String userType = ConstantsKey.BUYER; String username = null; switch (statusEnum) { case ZERO: case ONE: @@ -62,6 +63,7 @@ userType = ConstantsKey.BUYER; break; case TWO: username = response.getOrder().getUsername(); case FOUR: userType = ConstantsKey.MERCHANT; break; @@ -74,7 +76,9 @@ break; default: } String username = SecurityUtils.getCurrentUsername(); if (username == null) { username = SecurityUtils.getCurrentUsername(); } Timestamp time = new Timestamp(System.currentTimeMillis()); OrderOperationLog resources = new OrderOperationLog(); resources.setOrderNum(response.getOrder().getOrderNum()); oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java
@@ -8,6 +8,7 @@ import com.oying.modules.pc.product.domain.enums.ProductStatusEnum; import com.oying.modules.pc.product.service.ProductService; import com.oying.modules.pc.store.domain.Store; import com.oying.modules.pc.store.domain.enums.StoreStatusEnum; import com.oying.modules.pc.store.service.StoreService; import com.oying.modules.sh.domain.*; import com.oying.modules.sh.domain.request.GeneratorOrder; @@ -78,13 +79,21 @@ default: throw new BadRequestException("支付类型暂未开放"); } String orderNum = redisUtils.generateOrderSn(GenerateEnum.ORDER.getKey()); // 总金额 BigDecimal amount = BigDecimal.ZERO; GeneratorOrder generator = new GeneratorOrder(); generator.setProducts(submit.getProducts()); generator.setStoreId(submit.getStoreId()); OrderInfo info = generatorOrder(generator); Store store = info.getStore(); UserAddress address = userAddressService.getById(submit.getAddressId(), store.getLongitude(), store.getLatitude()); if (address == null) { throw new BadRequestException("没找到用户地址"); } if (!(address.getDistance().compareTo(BigDecimal.valueOf(store.getRadius())) <= 0)) { throw new BadRequestException("超出配送范围"); } String orderNum = redisUtils.generateOrderSn(GenerateEnum.ORDER.getKey()); // 总金额 BigDecimal amount = BigDecimal.ZERO; // 商品快照 List<OrderProductSnapshot> snapshots = new ArrayList<>(); for (ProductInfo productInfo : info.getProducts()) { @@ -115,12 +124,6 @@ String openid = SecurityUtils.getCurrentOpenid(); if (openid == null || openid.isEmpty()) { throw new BadRequestException("OPENID错误"); } // 门店信息 Store store = storeService.getById(submit.getStoreId()); if (amount.compareTo(store.getDeliveryMinimum()) >= 0) { throw new BadRequestException("起送金额:" + store.getDeliveryMinimum()); } // 订单信息 Order order = new Order(); @@ -167,7 +170,7 @@ order.setPayMessage(PayStateEnum.SUCCESS.getValue()); order.setPayTime(DateUtil.localDateTimeFormat(now.toLocalDateTime(), DateUtil.SDF_YMDHMS)); } UserAddress address = userAddressService.getById(submit.getAddressId()); OrderAddressSnapshot addressSnapshot = getOrderAddressSnapshot(orderNum, address); @@ -202,6 +205,11 @@ @Override @Transactional(rollbackFor = Exception.class) public synchronized OrderInfo generatorOrder(GeneratorOrder criteria) { // 门店信息 Store store = storeService.getById(criteria.getStoreId()); if (!store.getBusinessStatus().equals(StoreStatusEnum.OPEN.getValue())) { throw new BadRequestException("停止营业"); } List<ProductInfo> products = new ArrayList<>(); BigDecimal amount = BigDecimal.ZERO; for (ProductOrder productOrder : criteria.getProducts()) { @@ -229,12 +237,16 @@ products.add(info); amount = BigDecimalUtils.add(amount, BigDecimalUtils.multiply(product.getPrice(), productOrder.getCount())); } if (!(amount.compareTo(store.getDeliveryMinimum()) >= 0)) { throw new BadRequestException("起送金额:" + store.getDeliveryMinimum()); } OrderInfo info = new OrderInfo(); info.setStore(store); info.setProducts(products); info.setAmount(amount); info.setPayAmount(amount); info.setPromotionAmount(BigDecimal.ZERO); info.setUserAddresses(userAddressService.queryUserAddress()); info.setUserAddresses(userAddressService.queryUserAddress(store.getLongitude(), store.getLatitude())); return info; } @@ -266,7 +278,7 @@ @Override @Transactional(rollbackFor = Exception.class) public void closeOrder(String orderNum) { public void cancel(String orderNum) { OrderResponse response = getByOrderNum(orderNum); Order order = response.getOrder(); if (order == null) { @@ -331,7 +343,7 @@ map.put("消息", order.getPayMessage()); map.put("支付类型", order.getPayType()); map.put("支付时间", order.getPayTime()); map.put("订单失效时间RFC3339", order.getExpireTime()); map.put("订单失效时间", order.getExpireTime()); map.put("openid", order.getOpenid()); map.put("APPID", order.getAppId()); map.put("创建人", order.getCreateBy());