diff --git a/order/src/main/java/com/order/controller/OrderAfterSalesApplyController.java b/order/src/main/java/com/order/controller/OrderAfterSalesApplyController.java index c64d1b3..ee8a6db 100644 --- a/order/src/main/java/com/order/controller/OrderAfterSalesApplyController.java +++ b/order/src/main/java/com/order/controller/OrderAfterSalesApplyController.java @@ -30,6 +30,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; @@ -52,6 +53,43 @@ public class OrderAfterSalesApplyController { @Resource private BsOrderChildService orderChildService; + @RequestMapping(value="/calculate",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "计算预计退款金额") + public ResponseData calculate(@RequestParam(value = "childOrderNo" , required = true) String childOrderNo, + @RequestParam(value = "productCount" , required = true) Integer productCount) { + try { + // 查询子订单 + OrderChildModel orderChild = orderChildService.getDetail(childOrderNo); + if (orderChild == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商品订单"); + } + if (productCount > orderChild.getSurplusRefundCount()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "数量超过子订单可退数量"); + } + Map param = new HashMap<>(); + if (orderChild.getSurplusRefundCount().equals(productCount)) { + // 全部退款 + param.put("refundPrice", orderChild.getSurplusRefundPrice()); + param.put("refundIntegral", orderChild.getSurplusRefundIntegral()); + } else { + // 部分退款 + // 计算单价 + BigDecimal unitPrice = orderChild.getSurplusRefundPrice().divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); + BigDecimal unitPriceIntegral = new BigDecimal(orderChild.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100")) + .divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); + param.put("refundPrice", unitPrice.multiply(new BigDecimal(productCount.toString()))); + param.put("refundIntegral", unitPriceIntegral.multiply(new BigDecimal("100")).longValue()); + } + return ResponseMsgUtil.success(param); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/apply",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "申请") diff --git a/order/src/main/java/com/order/controller/OrderController.java b/order/src/main/java/com/order/controller/OrderController.java index 72c87fd..615426f 100644 --- a/order/src/main/java/com/order/controller/OrderController.java +++ b/order/src/main/java/com/order/controller/OrderController.java @@ -7,6 +7,7 @@ import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.security.UserCenter; +import com.hfkj.common.utils.PageUtil; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.entity.BsOrder; import com.hfkj.model.ResponseData; @@ -29,6 +30,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -143,7 +145,14 @@ public class OrderController { param.put("orderStatus", orderStatus); PageHelper.startPage(pageNum, pageSize); - return ResponseMsgUtil.success(new PageInfo<>(orderService.getUserOrderList(param))); + PageInfo pageInfo = new PageInfo<>(orderService.getOrderList(param)); + PageInfo objectPageInfo = PageUtil.PageInfo2PageInfoVo(pageInfo); + List orderModelList = new ArrayList<>(); + for (BsOrder order : pageInfo.getList()) { + orderModelList.add(orderService.getDetail(order.getOrderNo())); + } + objectPageInfo.setList(orderModelList); + return ResponseMsgUtil.success(objectPageInfo); } catch (Exception e) { log.error("error!",e); diff --git a/service/src/main/java/com/hfkj/common/utils/PageUtil.java b/service/src/main/java/com/hfkj/common/utils/PageUtil.java index 248ddc7..6202dd9 100644 --- a/service/src/main/java/com/hfkj/common/utils/PageUtil.java +++ b/service/src/main/java/com/hfkj/common/utils/PageUtil.java @@ -1,5 +1,6 @@ package com.hfkj.common.utils; +import com.github.pagehelper.Page; import com.github.pagehelper.PageInfo; import java.util.List; @@ -95,4 +96,12 @@ public class PageUtil { return pageInfo; } + + public static PageInfo PageInfo2PageInfoVo(PageInfo

pageInfoPo) { + // 创建Page对象,实际上是⼀个ArrayList类型的集合 + Page page = new Page<>(pageInfoPo.getPageNum(), pageInfoPo.getPageSize()); + page.setTotal(pageInfoPo.getTotal()); + return new PageInfo<>(page); + } + } diff --git a/service/src/main/java/com/hfkj/service/order/BsOrderService.java b/service/src/main/java/com/hfkj/service/order/BsOrderService.java index c5a4fb9..f4082de 100644 --- a/service/src/main/java/com/hfkj/service/order/BsOrderService.java +++ b/service/src/main/java/com/hfkj/service/order/BsOrderService.java @@ -76,11 +76,4 @@ public interface BsOrderService { */ List getOrderList(Map param); - /** - * 查询用户订单列表 - * @param param - * @return - */ - List getUserOrderList(Map param); - } diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java index 33d7da8..2dc66cf 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.java @@ -161,9 +161,9 @@ public class BsOrderRefundServiceImpl implements BsOrderRefundService { } else { // 部分退款 // 计算单价 - BigDecimal unitPrice = orderChild.getSurplusRefundPrice().divide(new BigDecimal(productCount.toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); + BigDecimal unitPrice = orderChild.getSurplusRefundPrice().divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); BigDecimal unitPriceIntegral = new BigDecimal(orderChild.getSurplusRefundIntegral().toString()).divide(new BigDecimal("100")) - .divide(new BigDecimal(productCount.toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); + .divide(new BigDecimal(orderChild.getProductCount().toString()), 2, BigDecimal.ROUND_DOWN).setScale(2); orderRefund.setRefundPrice(unitPrice.multiply(new BigDecimal(productCount.toString()))); orderRefund.setRefundIntegral(unitPriceIntegral.multiply(new BigDecimal("100")).longValue()); diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java index fd04117..2cbba4d 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java @@ -425,8 +425,11 @@ public class BsOrderServiceImpl implements BsOrderService { BsOrderExample example = new BsOrderExample(); BsOrderExample.Criteria criteria = example.createCriteria(); - if (StringUtils.isNotBlank(MapUtils.getString(param, "order"))) { - criteria.andOrderNoLike("%"+MapUtils.getString(param, "order")+"%"); + if (MapUtils.getLong(param, "userId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(param, "userId")); + } + if (StringUtils.isNotBlank(MapUtils.getString(param, "orderNo"))) { + criteria.andOrderNoLike("%"+MapUtils.getString(param, "orderNo")+"%"); } if (StringUtils.isNotBlank(MapUtils.getString(param, "userPhone"))) { criteria.andUserPhoneLike("%"+MapUtils.getString(param, "userPhone")+"%"); @@ -469,21 +472,4 @@ public class BsOrderServiceImpl implements BsOrderService { return orderMapper.selectByExample(example); } - @Override - public List getUserOrderList(Map param) { - BsOrderExample example = new BsOrderExample(); - BsOrderExample.Criteria criteria = example.createCriteria(); - - if (StringUtils.isNotBlank(MapUtils.getString(param, "order"))) { - criteria.andOrderNoLike("%"+MapUtils.getString(param, "order")+"%"); - } - - example.setOrderByClause("create_time desc"); - List orderModelList = new ArrayList<>(); - List orderList = orderMapper.selectByExample(example); - for (BsOrder order : orderList) { - orderModelList.add(getDetail(order.getOrderNo())); - } - return orderModelList; - } }