自定义订单

This commit is contained in:
seesaw
2024-10-31 11:24:45 +08:00
parent 709db0a1b7
commit ac31e708ef
12 changed files with 189 additions and 45 deletions

View File

@ -12,6 +12,6 @@ public class StatisticsVo {
private BigDecimal reduceMoney;
private Long carteenId;
private LocalDateTime time;
private int order_sum;
private int orderSum;
}

View File

@ -133,4 +133,11 @@ public class OrderController {
orderService.reduction(orderId,money);
return CommonResult.success(true);
}
@GetMapping("/customize")
@Operation(summary = "自定义")
public CommonResult<Boolean> customize(String mobile, BigDecimal money,Long carteenId,String type){
orderService.customize(mobile,money,carteenId,type);
return CommonResult.success(true);
}
}

View File

@ -36,7 +36,7 @@ public class StoreOrderDetailDO extends BaseDO {
*/
private Integer goodsId;
private Integer goodsName;
private String goodsName;
/**
* 单价
*/

View File

@ -12,7 +12,7 @@ public interface DeductionService {
void deduction(DishOrderDO dishOrderDO);
/**
* 现金扣款
* 现金提现
*/
void cashDraw(Long userId, BigDecimal money,String type);
@ -35,4 +35,13 @@ public interface DeductionService {
* 超市扣款
*/
BigDecimal storeDeduction(BigDecimal total, Long userId);
/**
* 扣款
*/
void deduct(Long userId, BigDecimal money,String type);
}

View File

@ -23,6 +23,8 @@ import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.CASH_AMOUNT_NOT_ENOUGH;
@ -48,6 +50,8 @@ public class DeductionServiceImpl implements DeductionService {
@Resource
private BusinessService businessService;
private static final List<String> CHECK_LIST = Arrays.asList(CostTypeEnum.SHOPPING.getCode());
@Override
public void deduction(DishOrderDO dishOrderDO) {
Long userId = dishOrderDO.getUserId();
@ -170,7 +174,7 @@ public class DeductionServiceImpl implements DeductionService {
StatisticsVo statisticsVo = new StatisticsVo();
statisticsVo.setCarteenId(dishOrderDO.getStoreId());
statisticsVo.setTotalMoney(dishOrderDO.getTotalMoney());
statisticsVo.setOrder_sum(1);
statisticsVo.setOrderSum(1);
statisticsVo.setReduceMoney(dishOrderDO.getReductionAmount());
statisticsVo.setTime(dishOrderDO.getCreateTime());
statisticsVo.setOrderId(dishOrderDO.getId());
@ -446,5 +450,67 @@ public class DeductionServiceImpl implements DeductionService {
appUserInfoCardVO.setMoney(newMoney);
deductionRedisTemplate.opsForValue().set(redisKey, JSONUtil.toJsonStr(appUserInfoCardVO));
}
@Override
public void deduct(Long userId, BigDecimal money, String type) {
BigDecimal newMoney;
BigDecimal wxNewMoney;
BigDecimal giftNewMoney;
BigDecimal cashNewMoney;
String name;
synchronized (getUserLock(userId)) {
MemberUserDO user = userService.getUser(userId);
if (user.getMoney().compareTo(money) < 0) {
if (CHECK_LIST.contains(type)) {
throw exception(CASH_AMOUNT_NOT_ENOUGH);
}
user.setWxAmount(BigDecimal.ZERO);
user.setCashAmount(BigDecimal.ZERO);
user.setGiftAmount(BigDecimal.ZERO);
}else {
BigDecimal wxAmount = user.getWxAmount();
BigDecimal giftAmount = user.getGiftAmount();
BigDecimal cashAmount = user.getCashAmount();
//计算金额
if (money.compareTo(cashAmount) <= 0) {
user.setCashAmount(cashAmount.subtract(money));
} else {
user.setCashAmount(BigDecimal.ZERO);
BigDecimal total1 = money.subtract(cashAmount);
if (total1.compareTo(giftAmount) <= 0) {
user.setGiftAmount(giftAmount.subtract(total1));
} else {
user.setGiftAmount(BigDecimal.ZERO);
BigDecimal total2 = total1.subtract(giftAmount);
user.setWxAmount(wxAmount.subtract(total2));
}
}
}
user.setMoney(user.getMoney().subtract(money));
userService.updateById(user);
newMoney = user.getMoney();
wxNewMoney = user.getWxAmount();
giftNewMoney = user.getGiftAmount();
cashNewMoney = user.getCashAmount();
name = user.getNickname();
}
CardDO cardDO = new CardDO();
cardDO.setUserId(userId);
cardDO.setFlag(CardDO.MINUS);
cardDO.setChangeMoney(money);
cardDO.setType(type);
cardDO.setWxAmount(wxNewMoney);
cardDO.setGiftAmount(giftNewMoney);
cardDO.setMoney(newMoney);
cardDO.setCashAmount(cashNewMoney);
cardService.insertOne(cardDO);
//更新redis
updateRedis(userId,name,newMoney);
}
}

View File

@ -9,6 +9,7 @@ public class LockManager {
private static final ConcurrentHashMap<Long, Object> storeLocks = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<Long, Object> supermarketLocks = new ConcurrentHashMap<>();
public static Object getUserLock(Long userId) {
// 从 Map 中获取 WeakReference 对象
@ -19,5 +20,10 @@ public class LockManager {
// 对每个 userId 生成独立的锁对象,并发地存储在 ConcurrentHashMap 中
return storeLocks.computeIfAbsent(storeId, k -> new Object());
}
public static Object getSupermarketLock(Long storeId) {
// 对每个 userId 生成独立的锁对象,并发地存储在 ConcurrentHashMap 中
return storeLocks.computeIfAbsent(storeId, k -> new Object());
}
}

View File

@ -131,7 +131,7 @@ public class BusinessServiceImpl implements BusinessService {
}
}
//订单数
businessDO.setOrderSum(businessDO.getOrderSum() + vo.getOrder_sum());
businessDO.setOrderSum(businessDO.getOrderSum() + vo.getOrderSum());
//营业额
if(ObjectUtil.isNotEmpty(vo.getTotalMoney())){
@ -154,13 +154,13 @@ public class BusinessServiceImpl implements BusinessService {
if(timePeriod.equals(CostTypeEnum.MORNING.getCode())){
businessDO.setBreakfast(businessDO.getBreakfast().add(vo.getTotalMoney()));
businessDO.setBreakfastNum(businessDO.getBreakfastNum() + vo.getOrder_sum());
businessDO.setBreakfastNum(businessDO.getBreakfastNum() + vo.getOrderSum());
}else if (timePeriod.equals(CostTypeEnum.NOON.getCode())){
businessDO.setLunch(businessDO.getLunch().add(vo.getTotalMoney()));
businessDO.setLunchNum(businessDO.getLunchNum() + vo.getOrder_sum());
businessDO.setLunchNum(businessDO.getLunchNum() + vo.getOrderSum());
}else if (timePeriod.equals(CostTypeEnum.NIGHT.getCode())){
businessDO.setDinner(businessDO.getDinner().add(vo.getTotalMoney()));
businessDO.setDinnerNum(businessDO.getDinnerNum() + vo.getOrder_sum());
businessDO.setDinnerNum(businessDO.getDinnerNum() + vo.getOrderSum());
}
}

View File

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

View File

@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.member.controller.app.order.vo.AppPageVo;
import cn.iocoder.yudao.module.member.controller.app.orderdetail.vo.AppOrderDetailRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO;
import cn.iocoder.yudao.module.member.dal.dataobject.order.DishOrderDO;
import cn.iocoder.yudao.module.member.dal.dataobject.orderdetail.OrderDetailDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.mysql.card.CardMapper;
import cn.iocoder.yudao.module.member.dal.mysql.group.MemberGroupMapper;
@ -38,7 +39,6 @@ import cn.iocoder.yudao.module.system.api.carteen.dto.CarteenRespDto;
import cn.iocoder.yudao.module.system.api.deviceInfo.DeviceInfoApi;
import cn.iocoder.yudao.module.system.api.deviceInfo.dto.DeviceInfoDto;
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;
@ -53,8 +53,7 @@ import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ORDER_NOT_COMPLETE;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.ORDER_NOT_EXISTS;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
/**
* 会员订单 Service 实现类
@ -180,24 +179,27 @@ public class OrderServiceImpl implements OrderService {
List<AppOrderRespVO> list = appOrderRespVOPageResult.getList();
for (AppOrderRespVO dishOrderDO : list) {
List<AppOrderDetailRespVO> appOrderDetailRespVOS = orderDetailService.selectListByOrderId(dishOrderDO.getId());
if (CollectionUtil.isNotEmpty(appOrderDetailRespVOS)) {
List<Long> dishIds = appOrderDetailRespVOS.stream().map(AppOrderDetailRespVO::getDishesId).collect(Collectors.toList());
List<DishesRespDto> dishInfo = dishesApi.getDishInfo(dishIds);
Map<Long, DishesRespDto> dishMap = dishInfo.stream().collect(Collectors.toMap(DishesRespDto::getId, DishesRespDto -> DishesRespDto));
appOrderDetailRespVOS.forEach(respVo -> {
DishesRespDto dishesRespDto = dishMap.get(respVo.getDishesId());
if (ObjectUtil.isNotEmpty(dishesRespDto)) {
respVo.setDishesBasePrice(dishesRespDto.getDishesBasePrice())
.setDishesSumPrice(ObjectUtil.isNotEmpty(respVo.getUnitPrice())?respVo.getUnitPrice():dishesRespDto.getDishesSumPrice())
.setDishesNumber(dishesRespDto.getDishesNumber());
// if (CollectionUtil.isNotEmpty(appOrderDetailRespVOS)) {
// List<Long> dishIds = appOrderDetailRespVOS.stream().map(AppOrderDetailRespVO::getDishesId).collect(Collectors.toList());
//
// List<DishesRespDto> dishInfo = dishesApi.getDishInfo(dishIds);
// Map<Long, DishesRespDto> dishMap = dishInfo.stream().collect(Collectors.toMap(DishesRespDto::getId, DishesRespDto -> DishesRespDto));
//
// appOrderDetailRespVOS.forEach(respVo -> {
// DishesRespDto dishesRespDto = dishMap.get(respVo.getDishesId());
// if (ObjectUtil.isNotEmpty(dishesRespDto)) {
// respVo.setDishesBasePrice(dishesRespDto.getDishesBasePrice())
// .setDishesSumPrice(ObjectUtil.isNotEmpty(respVo.getUnitPrice())?respVo.getUnitPrice():dishesRespDto.getDishesSumPrice())
// .setDishesNumber(dishesRespDto.getDishesNumber());
// }
//
// });
//
// }
for (AppOrderDetailRespVO respVo : appOrderDetailRespVOS) {
respVo.setDishesSumPrice(respVo.getUnitPrice());
}
});
dishOrderDO.setRefundStatus(refundService.getRefundStatus(dishOrderDO.getId()));
}
dishOrderDO.setDetailList(appOrderDetailRespVOS);
dishOrderDO.setMoney(cardMapper.getMoneyByUsr(dishOrderDO.getUserId()));
@ -467,7 +469,7 @@ public class OrderServiceImpl implements OrderService {
StatisticsVo statisticsVo = new StatisticsVo();
statisticsVo.setCarteenId(dishOrderDO.getStoreId());
statisticsVo.setTotalMoney(money.negate());
statisticsVo.setOrder_sum(0);
statisticsVo.setOrderSum(0);
statisticsVo.setReduceMoney(money);
statisticsVo.setTime(dishOrderDO.getCreateTime());
businessService.updateStatistics(statisticsVo);
@ -479,4 +481,43 @@ public class OrderServiceImpl implements OrderService {
dishOrderMapper.updateById(dishOrderDO);
}
@Override
public void customize(String mobile, BigDecimal money, Long carteenId, String type) {
//订单处理
MemberUserDO memberUserDO = memberUserMapper.selectOne(Wrappers.<MemberUserDO>lambdaQuery().eq(MemberUserDO::getMobile, mobile));
if (memberUserDO == null) {
throw exception(USER_NOT_EXISTS);
}
DishOrderDO dishOrderDO = new DishOrderDO();
dishOrderDO.setStoreId(carteenId);
dishOrderDO.setOrderStatus(DishOrderDO.COMPLETE);
dishOrderDO.setTotalMoney(money);
dishOrderDO.setUserId(memberUserDO.getId());
dishOrderDO.setPayMethods(type);
dishOrderDO.setDiningPlatesNum("000001");
dishOrderDO.setCashAmount(money);
dishOrderDO.setRefundAmount(money);
dishOrderMapper.insert(dishOrderDO);
//订单详情处理
OrderDetailDO orderDetailDO = new OrderDetailDO();
orderDetailDO.setOrderId(dishOrderDO.getId());
orderDetailDO.setDishesName("自定义");
orderDetailDO.setPrice(money);
orderDetailDO.setDishesId(-1L);
orderDetailService.insertOne(orderDetailDO);
//扣费处理
deductionService.deduct(memberUserDO.getId(), money, type);
//更新营业数据
StatisticsVo statisticsVo = new StatisticsVo();
statisticsVo.setCarteenId(dishOrderDO.getStoreId());
statisticsVo.setTotalMoney(dishOrderDO.getTotalMoney());
statisticsVo.setOrderSum(1);
statisticsVo.setReduceMoney(dishOrderDO.getReductionAmount());
statisticsVo.setTime(dishOrderDO.getCreateTime());
statisticsVo.setOrderId(dishOrderDO.getId());
businessService.updateStatistics(statisticsVo);
}
}

View File

@ -60,4 +60,6 @@ public interface OrderDetailService {
List<OrderDetailDO> selectListByOrderIds(List<Long> orderIds);
List<DishVO> selectDishSale(Long storeId);
void insertOne(OrderDetailDO orderDetailDO);
}

View File

@ -161,4 +161,8 @@ public class OrderDetailServiceImpl implements OrderDetailService {
}
@Override
public void insertOne(OrderDetailDO orderDetailDO) {
orderDetailMapper.insert(orderDetailDO);
}
}

View File

@ -595,7 +595,14 @@ public class MemberUserServiceImpl implements MemberUserService {
//获取今天购买的菜品id
List<OrderDetailDO> orderDetailDOS = orderDetailMapper.selectList(new LambdaQueryWrapperX<OrderDetailDO>()
.inIfPresent(OrderDetailDO::getOrderId, collect));
Map<Long, List<OrderDetailDO>> collect2 = orderDetailDOS.stream().collect(Collectors.groupingBy(OrderDetailDO::getDishesId));
if(ObjectUtil.isEmpty(orderDetailDOS)){
return Collections.emptyList();
}
List<OrderDetailDO> collect3 = orderDetailDOS.stream().filter(a -> a.getDishesId() != null).collect(Collectors.toList());
if(ObjectUtil.isEmpty(collect3)){
return Collections.emptyList();
}
Map<Long, List<OrderDetailDO>> collect2 = collect3.stream().collect(Collectors.groupingBy(OrderDetailDO::getDishesId));
//热量求和统计方便 科学膳食小建议
double sum = orderDetailDOS
.stream().filter(vo->vo!=null && vo.getHeat()!=null)