返回售后申请退款金额

This commit is contained in:
hupeng
2023-12-06 18:37:28 +08:00
parent fc871ea4af
commit aad5a92307
3 changed files with 67 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -46,6 +47,13 @@ public class StoreAfterSalesController {
@Autowired
private YxExpressService yxExpressService;
@AuthCheck
@PostMapping("/getRefundAmount")
@ApiOperation(value = "获取退款价格", notes = "获取退款价格")
public ApiResult<BigDecimal> getRefundAmount(@RequestBody StoreAfterSalesParam storeAfterSalesParam) {
return ApiResult.ok(storeAfterSalesService.getRefundAmount(storeAfterSalesParam));
}
@AuthCheck
@PostMapping("/applyForAfterSales")
@ApiOperation(value = "申请售后", notes = "申请售后")

View File

@ -11,6 +11,7 @@ import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -19,6 +20,8 @@ import java.util.Map;
*/
public interface StoreAfterSalesService extends BaseService<StoreAfterSales> {
BigDecimal getRefundAmount(StoreAfterSalesParam storeAfterSalesParam);
/**
* 创建售后订单
*

View File

@ -68,6 +68,58 @@ public class StoreAfterSalesServiceImpl extends BaseServiceImpl<StoreAfterSalesM
private final IGenerator generator;
private final RedisUtils redisUtils;
@Override
public BigDecimal getRefundAmount(StoreAfterSalesParam storeAfterSalesParam) {
YxStoreOrder yxStoreOrder = storeOrderMapper.selectOne(Wrappers.<YxStoreOrder>lambdaQuery().eq(YxStoreOrder::getOrderId, storeAfterSalesParam.getOrderCode()));
//商品除去优惠后的总价格
BigDecimal totalPrice = BigDecimal.ZERO;
//拿到所有的商品
List<YxStoreOrderCartInfo> yxStoreOrderCartInfos = storeOrderCartInfoMapper.selectList(Wrappers.<YxStoreOrderCartInfo>lambdaQuery().eq(YxStoreOrderCartInfo::getOid, yxStoreOrder.getId()));
for (YxStoreOrderCartInfo yxStoreOrderCartInfo : yxStoreOrderCartInfos) {
YxStoreCartQueryVo cartInfo = JSONObject.parseObject(yxStoreOrderCartInfo.getCartInfo(), YxStoreCartQueryVo.class);
ProsuctParam prosuctParam = storeAfterSalesParam.getProductParamList().stream().filter(item -> item.getProductId().equals(yxStoreOrderCartInfo.getProductId())).findFirst().orElse(new ProsuctParam());
if (prosuctParam.getProductId() != null) {
//商品优惠前总金额
BigDecimal totalAmountOfGoods = NumberUtil.mul(cartInfo.getTruePrice(), cartInfo.getCartNum());
//商品优惠总金额
// BigDecimal commodityDiscountAmount = NumberUtil.mul(NumberUtil.div(totalAmountOfGoods, NumberUtil.sub(yxStoreOrder.getTotalPrice(), yxStoreOrder.getPayPostage())), yxStoreOrder.getCouponPrice());
BigDecimal totalPriceMinusPostage = NumberUtil.sub(yxStoreOrder.getTotalPrice(), yxStoreOrder.getPayPostage());
BigDecimal commodityDiscountAmount;
if (totalPriceMinusPostage.compareTo(BigDecimal.ZERO) != 0) {
commodityDiscountAmount = NumberUtil.mul(NumberUtil.div(totalAmountOfGoods, totalPriceMinusPostage), yxStoreOrder.getCouponPrice());
} else {
// 处理除数为零的情况,返回默认值
commodityDiscountAmount = BigDecimal.ZERO;
}
//商品优惠后总金额
totalPrice = NumberUtil.add(totalPrice, NumberUtil.sub(totalAmountOfGoods, commodityDiscountAmount));
// todo 根据自己的业务逻辑修改,是否退运费,默认退运费
totalPrice = NumberUtil.add(totalPrice, yxStoreOrder.getPayPostage());
}
}
//更新订单状态
// yxStoreOrder.setStatus(OrderInfoEnum.STATUS_NE1.getValue());
// yxStoreOrder.setRefundStatus(OrderInfoEnum.REFUND_STATUS_1.getValue());
// yxStoreOrder.setRefundReasonWap(storeAfterSalesParam.getReasonForApplication());
// yxStoreOrder.setRefundReasonWapExplain(storeAfterSalesParam.getApplicationInstructions());
// yxStoreOrder.setRefundReasonTime(new Date());
// storeOrderMapper.updateById(yxStoreOrder);
// //生成售后订单
// StoreAfterSales storeAfterSales = new StoreAfterSales();
// storeAfterSales.setOrderCode(storeAfterSalesParam.getOrderCode());
//此处需要对比原来订单的支付价格
if(totalPrice.compareTo(yxStoreOrder.getPayPrice()) > 0){
return yxStoreOrder.getPayPrice();
}else{
return totalPrice;
}
}
@Override
public void applyForAfterSales(Long userId, String nickname, StoreAfterSalesParam storeAfterSalesParam) {
@ -157,8 +209,9 @@ public class StoreAfterSalesServiceImpl extends BaseServiceImpl<StoreAfterSalesM
@Override
public List<YxStoreOrderCartInfoVo> checkOrderDetails(String key) {
List<YxStoreOrderCartInfo> yxStoreOrderCartInfos = storeOrderCartInfoMapper.selectList(Wrappers.<YxStoreOrderCartInfo>lambdaQuery().eq(YxStoreOrderCartInfo::getOid, key));
YxStoreOrder yxStoreOrder = storeOrderMapper.selectById(key);
YxStoreOrder yxStoreOrder = storeOrderMapper.selectOne(Wrappers.<YxStoreOrder>lambdaQuery().eq(YxStoreOrder::getOrderId,key));
List<YxStoreOrderCartInfo> yxStoreOrderCartInfos = storeOrderCartInfoMapper.selectList(Wrappers.<YxStoreOrderCartInfo>lambdaQuery().eq(YxStoreOrderCartInfo::getOid, yxStoreOrder.getId()));
// YxStoreOrder yxStoreOrder = storeOrderMapper.selectById(key);
//查询 售后信息
StoreAfterSales storeAfterSales = baseMapper.selectOne(Wrappers.<StoreAfterSales>lambdaQuery().eq(StoreAfterSales::getOrderCode, yxStoreOrder.getOrderId()));
List<YxStoreOrderCartInfoVo> yxStoreOrderCartInfoVos = new ArrayList<>();
@ -181,7 +234,7 @@ public class StoreAfterSalesServiceImpl extends BaseServiceImpl<StoreAfterSalesM
yxStoreOrderCartInfoVo.setRefundablePrice(NumberUtil.sub(totalAmountOfGoods, commodityDiscountAmount));
yxStoreOrderCartInfoVo.setReasons(storeAfterSales.getReasons());
//yxStoreOrderCartInfoVo.setReasons(storeAfterSales.getReasons());
yxStoreOrderCartInfoVos.add(yxStoreOrderCartInfoVo);
}