This commit is contained in:
zengtao01
2024-10-09 15:02:54 +08:00
parent 5f8f85b3df
commit a1ac698daf
6 changed files with 88 additions and 2 deletions

View File

@ -78,7 +78,7 @@ public interface ErrorCodeConstants {
ErrorCode DINING_PLATES_ALREADY_BIND = new ErrorCode(1_004_099_001, "餐盘已被绑定");
ErrorCode CARD_NOT_BIND = new ErrorCode(1_004_099_002, "请先绑定餐卡");
ErrorCode DINING_PLATES_NOT_BIND = new ErrorCode(1_004_099_003, "餐盘未绑定");
ErrorCode ORDER_ALREADY_COMPLETE = new ErrorCode(1_004_099_004, "餐盘订单已完成,请重新绑定餐盘");
ErrorCode ORDER_ALREADY_COMPLETE = new ErrorCode(1_004_099_004, "餐盘未绑定");
ErrorCode FACE_NOT_BIND_USER = new ErrorCode(1_004_099_005, "人脸未绑定");
ErrorCode CARD_NOT_BIND_USER = new ErrorCode(1_004_099_006, "该卡未绑定用户");
ErrorCode INSUFFICIENT_BALANCE = new ErrorCode(1_004_099_007, "余额不足15元,请充值");

View File

@ -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);
}
}

View File

@ -84,7 +84,11 @@ public class BalanceDeductionJob implements JobHandler {
if (total.compareTo(BigDecimal.ZERO) > 0) {
reductionAmount = userService.getReductionAmount(userId, total, dishOrderDO.getCreateTime());
}
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) {

View File

@ -121,4 +121,6 @@ public interface OrderService {
Map<String,Object> getMoneyAndPeople(Long storeId);
void reduction(Long orderId,BigDecimal money);
}

View File

@ -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);
}
}

View File

@ -759,6 +759,7 @@ public class DivideServiceImpl implements DivideService {
cardDO.setMoney(oldMoney.subtract(changeMoney).setScale(2, BigDecimal.ROUND_HALF_UP));
cardDO.setWxAmount(wxOldMoney.subtract(changeMoney).setScale(2, BigDecimal.ROUND_HALF_UP));
cardDO.setGiftAmount(lastCardDO.getGiftAmount());
cardDO.setCashAmount(lastCardDO.getCashAmount());
divideCardMapper.insert(cardDO);
}