优化
This commit is contained in:
		| @ -24,6 +24,7 @@ import javax.annotation.Resource; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import javax.validation.Valid; | ||||
| import java.io.IOException; | ||||
| import java.math.BigDecimal; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||||
| @ -125,4 +126,11 @@ public class OrderController { | ||||
|     public CommonResult<OrderMoneyRespVO> getUserMeney(@RequestParam("userId")Long userId){ | ||||
|         return CommonResult.success(orderService.getUserMeney(userId)); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/reduction") | ||||
|     @Operation(summary = "根据会员编号,获得会员余额,充值金额,消费金额") | ||||
|     public CommonResult<Boolean> reduction(Long orderId, BigDecimal money){ | ||||
|         orderService.reduction(orderId,money); | ||||
|         return CommonResult.success(true); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -84,7 +84,11 @@ public class BalanceDeductionJob implements JobHandler { | ||||
|                 if (total.compareTo(BigDecimal.ZERO) > 0) { | ||||
|                     reductionAmount = userService.getReductionAmount(userId, total, dishOrderDO.getCreateTime()); | ||||
|                 } | ||||
|                 dishOrderDO.setReductionAmount(reductionAmount); | ||||
|                 if(dishOrderDO.getReductionAmount().compareTo(BigDecimal.ZERO) > 0){ | ||||
|                     dishOrderDO.setReductionAmount(reductionAmount.add(dishOrderDO.getReductionAmount())); | ||||
|                 }else { | ||||
|                     dishOrderDO.setReductionAmount(reductionAmount); | ||||
|                 } | ||||
|                 dishOrderDO.setReductionState(reductionAmount.compareTo(BigDecimal.ZERO) > 0 ? "1" : "0"); | ||||
|  | ||||
|                 //计算减免后的总价 | ||||
| @ -116,6 +120,9 @@ public class BalanceDeductionJob implements JobHandler { | ||||
|                     dishOrderDO.setCashAmount(cashAmount); | ||||
|                     dishOrderDO.setGiftAmount(giftAmount); | ||||
|                 } else { | ||||
|                     cardDO.setWxAmount(wxAmount); | ||||
|                     cardDO.setCashAmount(cashAmount); | ||||
|                     cardDO.setGiftAmount(giftAmount); | ||||
|                     dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE); | ||||
|                     //计算金额 | ||||
|                     if (total.compareTo(cashAmount) <= 0) { | ||||
|  | ||||
| @ -121,4 +121,6 @@ public interface OrderService { | ||||
|  | ||||
|  | ||||
|     Map<String,Object> getMoneyAndPeople(Long storeId); | ||||
|  | ||||
|     void reduction(Long orderId,BigDecimal money); | ||||
| } | ||||
| @ -37,6 +37,7 @@ import cn.iocoder.yudao.module.system.api.dish.DishesApi; | ||||
| import cn.iocoder.yudao.module.system.api.dish.dto.DishesRespDto; | ||||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| @ -401,4 +402,71 @@ public class OrderServiceImpl implements OrderService { | ||||
|         map.put("size", size); | ||||
|         return map; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     @Transactional(rollbackFor = Exception.class) | ||||
|     public void reduction(Long orderId,BigDecimal money) { | ||||
|         DishOrderDO dishOrderDO = dishOrderMapper.selectById(orderId); | ||||
|         dishOrderDO.setReductionState("1"); | ||||
|         if(dishOrderDO.getOrderStatus().equals("1")){ | ||||
|             dishOrderDO.setReductionAmount(dishOrderDO.getReductionAmount().add(money)); | ||||
|             //更改订单 | ||||
|             BigDecimal wxAmount = BigDecimal.ZERO; | ||||
|             BigDecimal cashAmount = BigDecimal.ZERO; | ||||
|             BigDecimal giftAmount = BigDecimal.ZERO; | ||||
|  | ||||
|             dishOrderDO.setTotalMoney(dishOrderDO.getTotalMoney().subtract(money)); | ||||
|             if(dishOrderDO.getWxAmount().compareTo(money)>=0){ | ||||
|                 dishOrderDO.setWxAmount(dishOrderDO.getWxAmount().subtract(money)); | ||||
|                 wxAmount = wxAmount.add(money); | ||||
|             }else { | ||||
|                 BigDecimal leftMoney = money.subtract(dishOrderDO.getWxAmount()); | ||||
|                 wxAmount = wxAmount.add(dishOrderDO.getWxAmount()); | ||||
|                 dishOrderDO.setWxAmount(BigDecimal.ZERO); | ||||
|                 if(dishOrderDO.getCashAmount().compareTo(leftMoney)>0){ | ||||
|                     dishOrderDO.setCashAmount(dishOrderDO.getCashAmount().subtract(leftMoney)); | ||||
|                     cashAmount = cashAmount.add(leftMoney); | ||||
|                 }else { | ||||
|                     BigDecimal leftMoney1 = leftMoney.subtract(dishOrderDO.getCashAmount()); | ||||
|                     cashAmount = cashAmount.add(dishOrderDO.getCashAmount()); | ||||
|                     dishOrderDO.setCashAmount(BigDecimal.ZERO); | ||||
|  | ||||
|                     dishOrderDO.setGiftAmount(dishOrderDO.getGiftAmount().subtract(leftMoney1)); | ||||
|                     giftAmount = giftAmount.add(leftMoney1); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             //退款 | ||||
|             CardDO lastCardDO = cardMapper.selectOne(Wrappers.<CardDO>lambdaQuery() | ||||
|                     .eq(CardDO::getUserId, dishOrderDO.getUserId()) | ||||
|                     .orderByDesc(CardDO::getCreateTime) | ||||
|                     .orderByDesc(CardDO::getId) | ||||
|                     .last(MemberConstants.LIMIT_ONE)); | ||||
|             CardDO cardDO = new CardDO(); | ||||
|             cardDO.setUserId(dishOrderDO.getUserId()); | ||||
|             cardDO.setFlag(CardDO.ADD); | ||||
|             cardDO.setChangeMoney(money); | ||||
|             cardDO.setType(CostTypeEnum.REFUND.getCode()); | ||||
|  | ||||
|             BigDecimal oldMoney = BigDecimal.ZERO; | ||||
|             if (ObjectUtil.isNotEmpty(lastCardDO) && lastCardDO.getMoney() != null) { | ||||
|                 oldMoney = lastCardDO.getMoney(); | ||||
|             } | ||||
|             cardDO.setMoney(oldMoney.add(money).setScale(2, BigDecimal.ROUND_HALF_UP)); | ||||
|  | ||||
|             BigDecimal oldWxAmount = lastCardDO.getWxAmount(); | ||||
|             BigDecimal oldCashAmount = lastCardDO.getCashAmount(); | ||||
|             BigDecimal oldGiftAmount = lastCardDO.getGiftAmount(); | ||||
|  | ||||
|             cardDO.setGiftAmount(oldWxAmount.add(wxAmount)); | ||||
|             cardDO.setWxAmount(oldCashAmount.add(cashAmount)); | ||||
|             cardDO.setWxAmount(oldGiftAmount.add(giftAmount)); | ||||
|             cardMapper.insert(cardDO); | ||||
|  | ||||
|         }else{ | ||||
|             dishOrderDO.setReductionAmount(dishOrderDO.getReductionAmount().add(money)); | ||||
|         } | ||||
|         dishOrderMapper.updateById(dishOrderDO); | ||||
|  | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 zengtao01
					zengtao01