金额修改

This commit is contained in:
zt
2025-02-10 11:37:02 +08:00
parent 884971eaac
commit 7732751e52
13 changed files with 158 additions and 144 deletions

View File

@ -56,6 +56,14 @@ public class OrderDetailsRespVO {
@ExcelProperty("金额") @ExcelProperty("金额")
private BigDecimal totalMoney; private BigDecimal totalMoney;
@Schema(description = "现金金额")
@ExcelProperty("现金金额")
private BigDecimal cashAmount;
@Schema(description = "微信金额")
@ExcelProperty("微信金额")
private BigDecimal wxAmount;
@Schema(description = "支付方式", example = "钱包") @Schema(description = "支付方式", example = "钱包")
private String payMethods; private String payMethods;

View File

@ -63,15 +63,10 @@ public class AppMemberUserController {
UserExpandDO userExpandByuserId = userExpandService.getUserExpandByuserId(getLoginUserId()); UserExpandDO userExpandByuserId = userExpandService.getUserExpandByuserId(getLoginUserId());
AppMemberUserInfoRespVO convert = MemberUserConvert.INSTANCE.convert(user, level); AppMemberUserInfoRespVO convert = MemberUserConvert.INSTANCE.convert(user, level);
convert.setUserExpandDO(userExpandByuserId); convert.setUserExpandDO(userExpandByuserId);
if(carteenId!=null){ convert.setCashAmount(user.getCashAmount());
MoneyDO moneyDO = moneyService.getMoney(user.getId(), carteenId); convert.setDebtAmount(BigDecimal.ZERO);
if(ObjectUtil.isNotEmpty(moneyDO)){ if(user.getMoney().compareTo(BigDecimal.ZERO) < 0 ){
convert.setCashAmount(moneyDO.getCashAmount()); convert.setDebtAmount(user.getMoney());
convert.setDebtAmount(moneyDO.getDebtAmount());
}else {
convert.setCashAmount(BigDecimal.ZERO);
convert.setDebtAmount(BigDecimal.ZERO);
}
} }
return success(convert); return success(convert);

View File

@ -49,6 +49,8 @@ public class OrderStatusConverter implements Converter<String> {
value = "待付款"; value = "待付款";
} else if ("1".equals(value)) { } else if ("1".equals(value)) {
value = "已完成"; value = "已完成";
}else {
value = "未完成";
} }
return new WriteCellData<>(value); return new WriteCellData<>(value);

View File

@ -6,8 +6,10 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessPageReqVO; import cn.iocoder.yudao.module.member.controller.admin.business.vo.BusinessPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO; import cn.iocoder.yudao.module.member.dal.dataobject.business.BusinessDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -39,4 +41,8 @@ public interface BusinessMapper extends BaseMapperX<BusinessDO> {
@Select("select id from t_carteen where deleted = false") @Select("select id from t_carteen where deleted = false")
List<Long> getAllStoreId(); List<Long> getAllStoreId();
@Select("select * from t_business where carteen_id = #{carteenId} and create_time between #{startOfDay} and #{endOfDay} limit 1 for update")
BusinessDO getTodayBusiness(@Param("carteenId") Long carteenId, @Param("startOfDay") LocalDateTime startOfDay, @Param("endOfDay") LocalDateTime endOfDay);
} }

View File

@ -62,8 +62,10 @@ public interface CardMapper extends BaseMapperX<CardDO> {
@Select("select IFNULL(sum(change_money),0) as money,count(*) as count FROM member_card where user_id = #{userId} and flag = #{flag} and create_time BETWEEN #{startTime} and #{endTime}") @Select("select IFNULL(sum(change_money),0) as money,count(*) as count FROM member_card where user_id = #{userId} and flag = #{flag} and create_time BETWEEN #{startTime} and #{endTime}")
AppCardMonthVO selectMonth(@Param("userId") Long userId,@Param("flag") String flag, @Param("startTime") LocalDateTime startTime, @Param("endTime")LocalDateTime endTime); AppCardMonthVO selectMonth(@Param("userId") Long userId,@Param("flag") String flag, @Param("startTime") LocalDateTime startTime, @Param("endTime")LocalDateTime endTime);
@Select("select SUM(change_money) from member_card where user_id= #{userId} and flag= #{flag} and carteen_id = #{carteenId}") @Select("select SUM(change_money) from member_card where user_id= #{userId} and flag= #{flag} and type= '5'")
BigDecimal selectAddMoney(@Param("userId") Long userId,@Param("flag") String flag,@Param("carteenId") Long carteenId); BigDecimal selectAddMoney(@Param("userId") Long userId,@Param("flag") String flag);
@Select("select SUM(change_money) from member_card where user_id= #{userId} and flag= #{flag}")
BigDecimal selectReduceMoney(@Param("userId") Long userId,@Param("flag") String flag);
@Select("select sum(change_money) from member_card where user_id= #{userId} and type= '1'") @Select("select sum(change_money) from member_card where user_id= #{userId} and type= '1'")
BigDecimal selectWxMoney(@Param("userId") Long userId); BigDecimal selectWxMoney(@Param("userId") Long userId);

View File

@ -21,6 +21,7 @@ public enum CostTypeEnum {
WITHDRAW("7","微信提现"), WITHDRAW("7","微信提现"),
CASH_WITHDRAW("8","现金提现"), CASH_WITHDRAW("8","现金提现"),
SHOPPING("9","购物"), SHOPPING("9","购物"),
SPACE("10","太空舱"),
; ;
/** /**

View File

@ -91,10 +91,11 @@ public class CashRechargeServiceImpl implements CashRechargeService {
memberUserDO.setCashAmount(memberUserDO.getCashAmount().add(money)); memberUserDO.setCashAmount(memberUserDO.getCashAmount().add(money));
} }
} }
userMapper.updateById(memberUserDO);
wxNewMoney = memberUserDO.getWxAmount(); wxNewMoney = memberUserDO.getWxAmount();
cashNewAmount = memberUserDO.getCashAmount(); cashNewAmount = memberUserDO.getCashAmount();
name = memberUserDO.getNickname(); name = memberUserDO.getNickname();
} }
//记录明细 //记录明细
@ -107,6 +108,7 @@ public class CashRechargeServiceImpl implements CashRechargeService {
add.setWxAmount(wxNewMoney); add.setWxAmount(wxNewMoney);
add.setCarteenId(storeId); add.setCarteenId(storeId);
add.setGroupId(groupId); add.setGroupId(groupId);
add.setMoney(newMoney);
add.setGroupName(ObjectUtil.isNotEmpty(memberGroupDO)?memberGroupDO.getName():null); add.setGroupName(ObjectUtil.isNotEmpty(memberGroupDO)?memberGroupDO.getName():null);
addList.add(add); addList.add(add);

View File

@ -176,6 +176,7 @@ public class DeductionServiceImpl implements DeductionService {
cardDO.setCashAmount(cashNewMoney); cardDO.setCashAmount(cashNewMoney);
cardDO.setWxAmount(wxNewMoney); cardDO.setWxAmount(wxNewMoney);
cardDO.setCarteenId(dishOrderDO.getStoreId()); cardDO.setCarteenId(dishOrderDO.getStoreId());
cardDO.setMoney(newMoney);
cardService.insertOne(cardDO); cardService.insertOne(cardDO);
@ -233,6 +234,7 @@ public class DeductionServiceImpl implements DeductionService {
cardDO.setWxAmount(wxNewMoney); cardDO.setWxAmount(wxNewMoney);
cardDO.setCashAmount(cashNewMoney); cardDO.setCashAmount(cashNewMoney);
cardDO.setCarteenId(storeId); cardDO.setCarteenId(storeId);
cardDO.setMoney(newMoney);
cardService.insertOne(cardDO); cardService.insertOne(cardDO);
//更新redis //更新redis
@ -269,6 +271,7 @@ public class DeductionServiceImpl implements DeductionService {
cardDO.setType("7"); cardDO.setType("7");
cardDO.setWxAmount(wxNewMoney); cardDO.setWxAmount(wxNewMoney);
cardDO.setCashAmount(cashNewMoney); cardDO.setCashAmount(cashNewMoney);
cardDO.setMoney(newMoney);
cardService.insertOne(cardDO); cardService.insertOne(cardDO);
//更新redis //更新redis
@ -335,6 +338,7 @@ public class DeductionServiceImpl implements DeductionService {
cardDO.setWxAmount(wxNewMoney); cardDO.setWxAmount(wxNewMoney);
cardDO.setCashAmount(cashNewMoney); cardDO.setCashAmount(cashNewMoney);
cardDO.setCarteenId(dishOrderDO.getStoreId()); cardDO.setCarteenId(dishOrderDO.getStoreId());
cardDO.setMoney(newTotalMoney);
cardService.insertOne(cardDO); cardService.insertOne(cardDO);
//更新redis //更新redis
@ -370,6 +374,7 @@ public class DeductionServiceImpl implements DeductionService {
cardDO.setWxAmount(wxNewAmount); cardDO.setWxAmount(wxNewAmount);
cardDO.setCashAmount(cashNewAmount); cardDO.setCashAmount(cashNewAmount);
cardDO.setCarteenId(storeId); cardDO.setCarteenId(storeId);
cardDO.setMoney(newAmount);
cardService.insertOne(cardDO); cardService.insertOne(cardDO);
//更新redis //更新redis
@ -403,8 +408,8 @@ public class DeductionServiceImpl implements DeductionService {
} }
//扣除金额 //扣除金额
user.setMoney(money.subtract(total));
if (judge) { if (judge) {
user.setMoney(money.subtract(total));
user.setWxAmount(wxAmount.subtract(total)); user.setWxAmount(wxAmount.subtract(total));
} else { } else {
if (total.compareTo(cashAmount) <= 0) { if (total.compareTo(cashAmount) <= 0) {
@ -432,6 +437,7 @@ public class DeductionServiceImpl implements DeductionService {
cardDO.setWxAmount(wxNewMoney); cardDO.setWxAmount(wxNewMoney);
cardDO.setCashAmount(cashNewMoney); cardDO.setCashAmount(cashNewMoney);
cardDO.setCarteenId(storeId); cardDO.setCarteenId(storeId);
cardDO.setMoney(newMoney);
cardService.insertOne(cardDO); cardService.insertOne(cardDO);
@ -504,6 +510,7 @@ public class DeductionServiceImpl implements DeductionService {
cardDO.setWxAmount(wxNewMoney); cardDO.setWxAmount(wxNewMoney);
cardDO.setCashAmount(cashNewMoney); cardDO.setCashAmount(cashNewMoney);
cardDO.setCarteenId(storeId); cardDO.setCarteenId(storeId);
cardDO.setMoney(newMoney);
cardService.insertOne(cardDO); cardService.insertOne(cardDO);
//更新redis //更新redis
@ -551,7 +558,7 @@ public class DeductionServiceImpl implements DeductionService {
userService.updateById(user); userService.updateById(user);
wxNewMoney = user.getWxAmount(); wxNewMoney = user.getWxAmount();
newMoney = user.getGiftAmount(); newMoney = user.getMoney();
cashNewMoney = user.getCashAmount(); cashNewMoney = user.getCashAmount();
name = user.getNickname(); name = user.getNickname();
} }
@ -564,6 +571,7 @@ public class DeductionServiceImpl implements DeductionService {
cardDO.setWxAmount(wxNewMoney); cardDO.setWxAmount(wxNewMoney);
cardDO.setCashAmount(cashNewMoney); cardDO.setCashAmount(cashNewMoney);
cardDO.setCarteenId(storeId); cardDO.setCarteenId(storeId);
cardDO.setMoney(newMoney);
cardService.insertOne(cardDO); cardService.insertOne(cardDO);
//更新redis //更新redis

View File

@ -62,6 +62,7 @@ public class WxRechargeServiceImpl implements WxRechargeService {
BigDecimal wxNewMoney; BigDecimal wxNewMoney;
BigDecimal cashNewMoney;
BigDecimal newMoney; BigDecimal newMoney;
String name; String name;
@ -88,6 +89,7 @@ public class WxRechargeServiceImpl implements WxRechargeService {
wxNewMoney = memberUserDO.getWxAmount(); wxNewMoney = memberUserDO.getWxAmount();
name = memberUserDO.getNickname(); name = memberUserDO.getNickname();
cashNewMoney = memberUserDO.getCashAmount();
} }
@ -98,6 +100,8 @@ public class WxRechargeServiceImpl implements WxRechargeService {
cardDO.setChangeMoney(money); cardDO.setChangeMoney(money);
cardDO.setType(CostTypeEnum.WX_PAY.getCode()); cardDO.setType(CostTypeEnum.WX_PAY.getCode());
cardDO.setWxAmount(wxNewMoney); cardDO.setWxAmount(wxNewMoney);
cardDO.setCashAmount(cashNewMoney);
cardDO.setMoney(newMoney);
cardMapper.insert(cardDO); cardMapper.insert(cardDO);

View File

@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -109,81 +110,77 @@ public class BusinessServiceImpl implements BusinessService {
} }
@Override @Override
public void updateStatistics(StatisticsVo vo) { @Transactional
synchronized(getStoreLock(vo.getCarteenId())){ public void updateStatistics(StatisticsVo vo) {
LocalDate now = LocalDate.now();
if(vo.getTime()!=null){ LocalDate now = LocalDate.now();
now = vo.getTime().toLocalDate(); if (vo.getTime() != null) {
now = vo.getTime().toLocalDate();
}
// 获取今天的开始时间
LocalDateTime startOfDay = now.atStartOfDay();
// 获取今天的结束时间 (23:59:59.999)
LocalDateTime endOfDay = LocalDateTime.of(now, LocalTime.MAX);
BusinessDO businessDO = businessMapper.getTodayBusiness(vo.getCarteenId(), startOfDay, endOfDay);
if (ObjectUtil.isNotEmpty(businessDO)) {
//重量
if (ObjectUtil.isNotEmpty(vo.getOrderId())) {
List<OrderDetailDO> orderDetailDOS = orderDetailMapper.selectList(Wrappers.<OrderDetailDO>lambdaQuery().eq(OrderDetailDO::getOrderId, vo.getOrderId()));
if (CollectionUtil.isNotEmpty(orderDetailDOS)) {
BigDecimal reduce = orderDetailDOS.stream().map(OrderDetailDO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add);
businessDO.setWeigh(businessDO.getWeigh().add(reduce));
}
} }
// 获取今天的开始时间 //订单数
LocalDateTime startOfDay =now.atStartOfDay(); businessDO.setOrderSum(businessDO.getOrderSum() + vo.getOrderSum());
// 获取今天的结束时间 (23:59:59.999)
LocalDateTime endOfDay = LocalDateTime.of(now, LocalTime.MAX);
List<BusinessDO> businessDOS = businessMapper.selectList(Wrappers.<BusinessDO>lambdaQuery() //营业额
.between(BusinessDO::getCreateTime, startOfDay, endOfDay) if (ObjectUtil.isNotEmpty(vo.getTotalMoney())) {
.eq(BusinessDO::getCarteenId, vo.getCarteenId())); businessDO.setTurnover(businessDO.getTurnover().add(vo.getTotalMoney()));
if (CollectionUtil.isNotEmpty(businessDOS)) {
BusinessDO businessDO = businessDOS.get(0);
//重量
if(ObjectUtil.isNotEmpty(vo.getOrderId())){
List<OrderDetailDO> orderDetailDOS = orderDetailMapper.selectList(Wrappers.<OrderDetailDO>lambdaQuery().eq(OrderDetailDO::getOrderId, vo.getOrderId()));
if (CollectionUtil.isNotEmpty(orderDetailDOS)) {
BigDecimal reduce = orderDetailDOS.stream().map(OrderDetailDO::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add);
businessDO.setWeigh(businessDO.getWeigh().add(reduce));
}
}
//订单数
businessDO.setOrderSum(businessDO.getOrderSum() + vo.getOrderSum());
//营业额
if(ObjectUtil.isNotEmpty(vo.getTotalMoney())){
businessDO.setTurnover(businessDO.getTurnover().add(vo.getTotalMoney()));
}
//客单价
if(businessDO.getOrderSum() != 0){
businessDO.setPriceAvg(businessDO.getTurnover().divide(new BigDecimal(businessDO.getOrderSum()), 2, RoundingMode.HALF_UP));
}else{
businessDO.setPriceAvg(BigDecimal.ZERO);
}
//减免金额
if(ObjectUtil.isNotEmpty(vo.getReduceMoney())){
businessDO.setReduce(businessDO.getReduce().add(vo.getReduceMoney()));
}
//早中晚金额
if(ObjectUtil.isNotEmpty(vo.getTime())){
String timePeriod = TimePeriodEnum.getTimePeriod(vo.getTime());
if(timePeriod.equals(CostTypeEnum.MORNING.getCode())){
businessDO.setBreakfast(businessDO.getBreakfast().add(vo.getTotalMoney()));
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.getOrderSum());
}else if (timePeriod.equals(CostTypeEnum.NIGHT.getCode())){
businessDO.setDinner(businessDO.getDinner().add(vo.getTotalMoney()));
businessDO.setDinnerNum(businessDO.getDinnerNum() + vo.getOrderSum());
}
}
//补贴金额
if(ObjectUtil.isNotEmpty(vo.getSubsidyPurse())){
businessDO.setSubsidyPurse(businessDO.getSubsidyPurse().add(vo.getSubsidyPurse()));
}
businessMapper.updateById(businessDO);
} }
//客单价
if (businessDO.getOrderSum() != 0) {
businessDO.setPriceAvg(businessDO.getTurnover().divide(new BigDecimal(businessDO.getOrderSum()), 2, RoundingMode.HALF_UP));
} else {
businessDO.setPriceAvg(BigDecimal.ZERO);
}
//减免金额
if (ObjectUtil.isNotEmpty(vo.getReduceMoney())) {
businessDO.setReduce(businessDO.getReduce().add(vo.getReduceMoney()));
}
//早中晚金额
if (ObjectUtil.isNotEmpty(vo.getTime())) {
String timePeriod = TimePeriodEnum.getTimePeriod(vo.getTime());
if (timePeriod.equals(CostTypeEnum.MORNING.getCode())) {
businessDO.setBreakfast(businessDO.getBreakfast().add(vo.getTotalMoney()));
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.getOrderSum());
} else if (timePeriod.equals(CostTypeEnum.NIGHT.getCode())) {
businessDO.setDinner(businessDO.getDinner().add(vo.getTotalMoney()));
businessDO.setDinnerNum(businessDO.getDinnerNum() + vo.getOrderSum());
}
}
//补贴金额
if (ObjectUtil.isNotEmpty(vo.getSubsidyPurse())) {
businessDO.setSubsidyPurse(businessDO.getSubsidyPurse().add(vo.getSubsidyPurse()));
}
businessMapper.updateById(businessDO);
} }
} }
@Override @Override
public BusinessDataVO getDay(String time,Long carteenId) { public BusinessDataVO getDay(String time, Long carteenId) {
Integer nowDay = MemberTimeUtils.getDay(time); Integer nowDay = MemberTimeUtils.getDay(time);
time = MemberTimeUtils.getYearMonth(time); time = MemberTimeUtils.getYearMonth(time);
@ -191,7 +188,7 @@ public class BusinessServiceImpl implements BusinessService {
BusinessDataVO businessDataVO = new BusinessDataVO(); BusinessDataVO businessDataVO = new BusinessDataVO();
LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BusinessDO::getCarteenId,carteenId); wrapper.eq(BusinessDO::getCarteenId, carteenId);
wrapper.orderByAsc(BusinessDO::getCreateTime); wrapper.orderByAsc(BusinessDO::getCreateTime);
wrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", time); wrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", time);
List<BusinessDO> businessDOS = businessMapper.selectList(wrapper); List<BusinessDO> businessDOS = businessMapper.selectList(wrapper);
@ -224,33 +221,33 @@ public class BusinessServiceImpl implements BusinessService {
LambdaQueryWrapper<BusinessDO> previousWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BusinessDO> previousWrapper = new LambdaQueryWrapper<>();
previousWrapper.eq(BusinessDO::getCarteenId,carteenId); previousWrapper.eq(BusinessDO::getCarteenId, carteenId);
previousWrapper.orderByAsc(BusinessDO::getCreateTime); previousWrapper.orderByAsc(BusinessDO::getCreateTime);
previousWrapper.apply("DATE_FORMAT(create_time, '%Y-%m-%d') = {0}", formattedDate); previousWrapper.apply("DATE_FORMAT(create_time, '%Y-%m-%d') = {0}", formattedDate);
List<BusinessDO> previousList = businessMapper.selectList(previousWrapper); List<BusinessDO> previousList = businessMapper.selectList(previousWrapper);
BusinessRespVO old = new BusinessRespVO(); BusinessRespVO old = new BusinessRespVO();
if(CollectionUtil.isNotEmpty(previousList)){ if (CollectionUtil.isNotEmpty(previousList)) {
BeanUtil.copyProperties(previousList.get(0), old); BeanUtil.copyProperties(previousList.get(0), old);
}else { } else {
old = getInitBusinessRespVO(); old = getInitBusinessRespVO();
} }
// 循环遍历该月的每一天 // 循环遍历该月的每一天
for (int day = 1; day <= daysInMonth; day++) { for (int day = 1; day <= daysInMonth; day++) {
BusinessRespVO bean = new BusinessRespVO(); BusinessRespVO bean = new BusinessRespVO();
if(map.get(day) == null){ if (map.get(day) == null) {
bean = getInitBusinessRespVO().setTime(String.valueOf(day)); bean = getInitBusinessRespVO().setTime(String.valueOf(day));
}else { } else {
bean = BeanUtils.toBean(map.get(day), BusinessRespVO.class); bean = BeanUtils.toBean(map.get(day), BusinessRespVO.class);
bean.setTime(String.valueOf(day)); bean.setTime(String.valueOf(day));
} }
//计算差额 //计算差额
if(day == 1){ if (day == 1) {
compare(bean,old); compare(bean, old);
}else { } else {
compare(bean,monthData.get(day-1)); compare(bean, monthData.get(day - 1));
} }
monthData.put(day,bean); monthData.put(day, bean);
} }
businessDataVO.setNow(monthData.get(nowDay)); businessDataVO.setNow(monthData.get(nowDay));
@ -259,22 +256,22 @@ public class BusinessServiceImpl implements BusinessService {
} }
@Override @Override
public BusinessDataVO getWeek(String time,Long carteenId) { public BusinessDataVO getWeek(String time, Long carteenId) {
BusinessDataVO businessDataVO = new BusinessDataVO(); BusinessDataVO businessDataVO = new BusinessDataVO();
LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BusinessDO::getCarteenId,carteenId); wrapper.eq(BusinessDO::getCarteenId, carteenId);
wrapper.orderByAsc(BusinessDO::getCreateTime); wrapper.orderByAsc(BusinessDO::getCreateTime);
wrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", time); wrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", time);
List<BusinessDO> businessDOS = businessMapper.selectList(wrapper); List<BusinessDO> businessDOS = businessMapper.selectList(wrapper);
Map<Integer,BusinessRespVO> map = new HashMap<>(); Map<Integer, BusinessRespVO> map = new HashMap<>();
int totalWeeksOfMonth = MemberTimeUtils.getTotalWeeksOfMonth(time); int totalWeeksOfMonth = MemberTimeUtils.getTotalWeeksOfMonth(time);
for (int i = 1; i <= totalWeeksOfMonth; i++) { for (int i = 1; i <= totalWeeksOfMonth; i++) {
BusinessRespVO bean = getInitBusinessRespVO().setTime(String.valueOf(i)); BusinessRespVO bean = getInitBusinessRespVO().setTime(String.valueOf(i));
map.put(i,bean); map.put(i, bean);
} }
for (BusinessDO businessDO : businessDOS) { for (BusinessDO businessDO : businessDOS) {
@ -287,7 +284,7 @@ public class BusinessServiceImpl implements BusinessService {
// 使用weekFields获取当前日期属于当月的第几周 // 使用weekFields获取当前日期属于当月的第几周
int i = date.get(weekFields.weekOfMonth()); int i = date.get(weekFields.weekOfMonth());
BusinessRespVO businessRespVO = map.get(i); BusinessRespVO businessRespVO = map.get(i);
handleBusiness(businessDO,businessRespVO); handleBusiness(businessDO, businessRespVO);
} }
@ -296,7 +293,7 @@ public class BusinessServiceImpl implements BusinessService {
} }
@Override @Override
public BusinessDataVO getMonth(String time,Long carteenId) { public BusinessDataVO getMonth(String time, Long carteenId) {
time = MemberTimeUtils.getYearMonth(time); time = MemberTimeUtils.getYearMonth(time);
BusinessDataVO businessDataVO = new BusinessDataVO(); BusinessDataVO businessDataVO = new BusinessDataVO();
@ -304,17 +301,17 @@ public class BusinessServiceImpl implements BusinessService {
int year = MemberTimeUtils.getYearFromYearMonthString(time); int year = MemberTimeUtils.getYearFromYearMonthString(time);
LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BusinessDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BusinessDO::getCarteenId,carteenId); wrapper.eq(BusinessDO::getCarteenId, carteenId);
wrapper.orderByAsc(BusinessDO::getCreateTime); wrapper.orderByAsc(BusinessDO::getCreateTime);
wrapper.apply("DATE_FORMAT(create_time, '%Y') = {0}", year); wrapper.apply("DATE_FORMAT(create_time, '%Y') = {0}", year);
List<BusinessDO> businessDOS = businessMapper.selectList(wrapper); List<BusinessDO> businessDOS = businessMapper.selectList(wrapper);
Map<Integer,BusinessRespVO> map = new HashMap<>(); Map<Integer, BusinessRespVO> map = new HashMap<>();
//时间处理 //时间处理
for (int i = 1; i <= 12; i++) { for (int i = 1; i <= 12; i++) {
BusinessRespVO bean = getInitBusinessRespVO(); BusinessRespVO bean = getInitBusinessRespVO();
bean.setTime(String.valueOf(i)); bean.setTime(String.valueOf(i));
map.put(i,bean); map.put(i, bean);
} }
//数据统计 //数据统计
for (BusinessDO businessDO : businessDOS) { for (BusinessDO businessDO : businessDOS) {
@ -324,26 +321,26 @@ public class BusinessServiceImpl implements BusinessService {
// 当前日期属于哪月 // 当前日期属于哪月
int i = date.getMonthValue(); int i = date.getMonthValue();
BusinessRespVO businessRespVO = map.get(i); BusinessRespVO businessRespVO = map.get(i);
handleBusiness(businessDO,businessRespVO); handleBusiness(businessDO, businessRespVO);
} }
//上一年最后一月 //上一年最后一月
int previousYear = year - 1; int previousYear = year - 1;
LambdaQueryWrapper<BusinessDO> previousWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BusinessDO> previousWrapper = new LambdaQueryWrapper<>();
previousWrapper.eq(BusinessDO::getCarteenId,carteenId); previousWrapper.eq(BusinessDO::getCarteenId, carteenId);
previousWrapper.orderByAsc(BusinessDO::getCreateTime); previousWrapper.orderByAsc(BusinessDO::getCreateTime);
previousWrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", previousYear+"-12"); previousWrapper.apply("DATE_FORMAT(create_time, '%Y-%m') = {0}", previousYear + "-12");
List<BusinessDO> previousList = businessMapper.selectList(previousWrapper); List<BusinessDO> previousList = businessMapper.selectList(previousWrapper);
BusinessRespVO previousVO = getInitBusinessRespVO(); BusinessRespVO previousVO = getInitBusinessRespVO();
for (BusinessDO businessDO : previousList) { for (BusinessDO businessDO : previousList) {
handleBusiness(businessDO,previousVO); handleBusiness(businessDO, previousVO);
} }
//差额统计 //差额统计
for (int i = 1; i <= 12; i++) { for (int i = 1; i <= 12; i++) {
if(i == 1){ if (i == 1) {
compare(map.get(i),previousVO); compare(map.get(i), previousVO);
}else { } else {
compare(map.get(i),map.get(i-1)); compare(map.get(i), map.get(i - 1));
} }
} }
@ -359,9 +356,9 @@ public class BusinessServiceImpl implements BusinessService {
//营业额 //营业额
businessRespVO.setTurnover(businessRespVO.getTurnover().add(businessDO.getTurnover())); businessRespVO.setTurnover(businessRespVO.getTurnover().add(businessDO.getTurnover()));
//订单数 //订单数
businessRespVO.setOrderSum(businessRespVO.getOrderSum()+businessDO.getOrderSum()); businessRespVO.setOrderSum(businessRespVO.getOrderSum() + businessDO.getOrderSum());
//均单价 //均单价
if(businessRespVO.getOrderSum()!=0){ if (businessRespVO.getOrderSum() != 0) {
businessRespVO.setPriceAvg(businessRespVO.getTurnover().divide(new BigDecimal(businessRespVO.getOrderSum().toString()), 2, RoundingMode.HALF_UP)); businessRespVO.setPriceAvg(businessRespVO.getTurnover().divide(new BigDecimal(businessRespVO.getOrderSum().toString()), 2, RoundingMode.HALF_UP));
} }
//减免金额 //减免金额
@ -370,20 +367,20 @@ public class BusinessServiceImpl implements BusinessService {
businessRespVO.setWeigh(businessRespVO.getWeigh().add(businessDO.getWeigh())); businessRespVO.setWeigh(businessRespVO.getWeigh().add(businessDO.getWeigh()));
//早 //早
businessRespVO.setBreakfast(businessRespVO.getBreakfast().add(businessDO.getBreakfast())); businessRespVO.setBreakfast(businessRespVO.getBreakfast().add(businessDO.getBreakfast()));
businessRespVO.setBreakfastNum(businessRespVO.getBreakfastNum()+businessDO.getBreakfastNum()); businessRespVO.setBreakfastNum(businessRespVO.getBreakfastNum() + businessDO.getBreakfastNum());
//中 //中
businessRespVO.setLunch(businessRespVO.getLunch().add(businessDO.getLunch())); businessRespVO.setLunch(businessRespVO.getLunch().add(businessDO.getLunch()));
businessRespVO.setLunchNum(businessRespVO.getLunchNum()+businessDO.getLunchNum()); businessRespVO.setLunchNum(businessRespVO.getLunchNum() + businessDO.getLunchNum());
//晚 //晚
businessRespVO.setDinner(businessRespVO.getDinner().add(businessDO.getDinner())); businessRespVO.setDinner(businessRespVO.getDinner().add(businessDO.getDinner()));
businessRespVO.setDinnerNum(businessRespVO.getDinnerNum()+businessDO.getDinnerNum()); businessRespVO.setDinnerNum(businessRespVO.getDinnerNum() + businessDO.getDinnerNum());
//门店 //门店
businessRespVO.setCarteenId(businessDO.getCarteenId()); businessRespVO.setCarteenId(businessDO.getCarteenId());
} }
void compare(BusinessRespVO today, BusinessRespVO last) { void compare(BusinessRespVO today, BusinessRespVO last) {
today.setTurnoverCompare(today.getTurnover().subtract(last.getTurnover())); today.setTurnoverCompare(today.getTurnover().subtract(last.getTurnover()));
today.setOrderSumCompare(today.getOrderSum()-last.getOrderSum()); today.setOrderSumCompare(today.getOrderSum() - last.getOrderSum());
today.setPriceAvgCompare(today.getPriceAvg().subtract(last.getPriceAvg())); today.setPriceAvgCompare(today.getPriceAvg().subtract(last.getPriceAvg()));
} }
@ -405,17 +402,17 @@ public class BusinessServiceImpl implements BusinessService {
List<BusinessDO> businessDOS = businessMapper.selectList(Wrappers.<BusinessDO>lambdaQuery() List<BusinessDO> businessDOS = businessMapper.selectList(Wrappers.<BusinessDO>lambdaQuery()
.between(BusinessDO::getCreateTime, startOfDay, endOfDay) .between(BusinessDO::getCreateTime, startOfDay, endOfDay)
.eq(BusinessDO::getCarteenId, carteenId)); .eq(BusinessDO::getCarteenId, carteenId));
return CollectionUtil.isNotEmpty(businessDOS)?businessDOS.get(0):new BusinessDO(); return CollectionUtil.isNotEmpty(businessDOS) ? businessDOS.get(0) : new BusinessDO();
} }
@Override @Override
public BusinessRespVO getTurnover(TurnoverVO turnoverVO) { public BusinessRespVO getTurnover(TurnoverVO turnoverVO) {
List<BusinessDO> businessDOS = businessMapper.selectList(Wrappers.<BusinessDO>lambdaQuery() List<BusinessDO> businessDOS = businessMapper.selectList(Wrappers.<BusinessDO>lambdaQuery()
.between(BusinessDO::getCreateTime,MemberTimeUtils.string2Time(turnoverVO.getStartTime()), MemberTimeUtils.string2Time(turnoverVO.getEndTime())) .between(BusinessDO::getCreateTime, MemberTimeUtils.string2Time(turnoverVO.getStartTime()), MemberTimeUtils.string2Time(turnoverVO.getEndTime()))
.eq(BusinessDO::getCarteenId, turnoverVO.getStoreId())); .eq(BusinessDO::getCarteenId, turnoverVO.getStoreId()));
BusinessRespVO businessDO = getInitBusinessRespVO(); BusinessRespVO businessDO = getInitBusinessRespVO();
if(CollectionUtil.isNotEmpty(businessDOS)){ if (CollectionUtil.isNotEmpty(businessDOS)) {
businessDO.setTurnover(businessDOS.stream().map(BusinessDO::getTurnover).reduce(BigDecimal.ZERO, BigDecimal::add)); businessDO.setTurnover(businessDOS.stream().map(BusinessDO::getTurnover).reduce(BigDecimal.ZERO, BigDecimal::add));
businessDO.setOrderSum(businessDOS.stream().map(BusinessDO::getOrderSum).reduce(0, Integer::sum)); businessDO.setOrderSum(businessDOS.stream().map(BusinessDO::getOrderSum).reduce(0, Integer::sum));
businessDO.setCustomerSum(businessDOS.stream().map(BusinessDO::getCustomerSum).reduce(0, Integer::sum)); businessDO.setCustomerSum(businessDOS.stream().map(BusinessDO::getCustomerSum).reduce(0, Integer::sum));
@ -437,9 +434,9 @@ public class BusinessServiceImpl implements BusinessService {
LocalDate startDate = startTime.toLocalDate(); LocalDate startDate = startTime.toLocalDate();
LocalDate endDate = endTime.toLocalDate(); LocalDate endDate = endTime.toLocalDate();
if(startDate.equals(endDate)){ if (startDate.equals(endDate)) {
// 获取本月开始时间本月的第一天00:00:00 // 获取本月开始时间本月的第一天00:00:00
startDate= startTime.with(TemporalAdjusters.firstDayOfMonth()).toLocalDate(); startDate = startTime.with(TemporalAdjusters.firstDayOfMonth()).toLocalDate();
startTime = startDate.atStartOfDay(); startTime = startDate.atStartOfDay();
// 获取本月结束时间本月的最后一天23:59:59.999999999 // 获取本月结束时间本月的最后一天23:59:59.999999999
@ -447,13 +444,13 @@ public class BusinessServiceImpl implements BusinessService {
endTime = endDate.atTime(LocalTime.MAX); endTime = endDate.atTime(LocalTime.MAX);
} }
List<BusinessDO> businessDOS = businessMapper.selectList(Wrappers.<BusinessDO>lambdaQuery() List<BusinessDO> businessDOS = businessMapper.selectList(Wrappers.<BusinessDO>lambdaQuery()
.between(BusinessDO::getCreateTime,startTime, endTime) .between(BusinessDO::getCreateTime, startTime, endTime)
.eq(BusinessDO::getCarteenId, turnoverVO.getStoreId())); .eq(BusinessDO::getCarteenId, turnoverVO.getStoreId()));
Map<LocalDateTime, BusinessDO> map = businessDOS.stream() Map<LocalDateTime, BusinessDO> map = businessDOS.stream()
.filter(Objects::nonNull) // 过滤掉null值 .filter(Objects::nonNull) // 过滤掉null值
.collect(Collectors.toMap( .collect(Collectors.toMap(
vo->vo.getCreateTime().toLocalDate().atStartOfDay(), vo -> vo.getCreateTime().toLocalDate().atStartOfDay(),
vo -> vo, vo -> vo,
(existing, replacement) -> existing (existing, replacement) -> existing
)); ));
@ -466,9 +463,9 @@ public class BusinessServiceImpl implements BusinessService {
List<BusinessRespVO> completeRecords = new ArrayList<>(); List<BusinessRespVO> completeRecords = new ArrayList<>();
for (LocalDateTime date : completeDates) { for (LocalDateTime date : completeDates) {
BusinessRespVO bean; BusinessRespVO bean;
if(map.get(date) == null){ if (map.get(date) == null) {
bean = getInitBusinessRespVO().setTime(MemberTimeUtils.Time2String(date)); bean = getInitBusinessRespVO().setTime(MemberTimeUtils.Time2String(date));
}else { } else {
bean = BeanUtils.toBean(map.get(date), BusinessRespVO.class); bean = BeanUtils.toBean(map.get(date), BusinessRespVO.class);
bean.setTime(MemberTimeUtils.Time2String(date)); bean.setTime(MemberTimeUtils.Time2String(date));
} }

View File

@ -374,9 +374,6 @@ public class OrderServiceImpl implements OrderService {
} }
/** /**
* @param userId
* @param carteenId
* @return
* @Description: 根据会员编号,获得会员余额,充值金额,消费金额 * @Description: 根据会员编号,获得会员余额,充值金额,消费金额
* @Author: qjq * @Author: qjq
* @Date: 2024/4/24 上午9:52 * @Date: 2024/4/24 上午9:52
@ -385,13 +382,13 @@ public class OrderServiceImpl implements OrderService {
public OrderMoneyRespVO getUserMeney(Long userId, Long carteenId) { public OrderMoneyRespVO getUserMeney(Long userId, Long carteenId) {
OrderMoneyRespVO orderMoneyRespVO = new OrderMoneyRespVO(); OrderMoneyRespVO orderMoneyRespVO = new OrderMoneyRespVO();
//获取充值的金额 //获取充值的金额
BigDecimal add = cardMapper.selectAddMoney(userId, CardDO.ADD,carteenId); BigDecimal add = cardMapper.selectAddMoney(userId, CardDO.ADD);
if (add == null) { if (add == null) {
add = BigDecimal.ZERO; add = BigDecimal.ZERO;
} }
orderMoneyRespVO.setRechargeMoney(add); orderMoneyRespVO.setRechargeMoney(add);
//消费的金额 //消费的金额
BigDecimal minus = cardMapper.selectAddMoney(userId, CardDO.MINUS,carteenId); BigDecimal minus = cardMapper.selectReduceMoney(userId, CardDO.MINUS);
if (minus == null) { if (minus == null) {
minus = BigDecimal.ZERO; minus = BigDecimal.ZERO;
} }
@ -400,15 +397,11 @@ public class OrderServiceImpl implements OrderService {
MemberUserDO memberUserDO = memberUserMapper.selectById(userId); MemberUserDO memberUserDO = memberUserMapper.selectById(userId);
orderMoneyRespVO.setCurrentMoney(memberUserDO.getWxAmount()); orderMoneyRespVO.setCurrentMoney(memberUserDO.getWxAmount());
orderMoneyRespVO.setUserId(userId); orderMoneyRespVO.setUserId(userId);
orderMoneyRespVO.setCashMoney(memberUserDO.getCashAmount());
MoneyDO moneyDO = moneyService.getMoney(userId, carteenId);
orderMoneyRespVO.setCashMoney(BigDecimal.ZERO);
orderMoneyRespVO.setDebtMoney(BigDecimal.ZERO); orderMoneyRespVO.setDebtMoney(BigDecimal.ZERO);
if(ObjectUtil.isNotEmpty(moneyDO)){ if(memberUserDO.getMoney().compareTo(BigDecimal.ZERO)<0){
orderMoneyRespVO.setCashMoney(moneyDO.getCashAmount()); orderMoneyRespVO.setDebtMoney(memberUserDO.getMoney());
orderMoneyRespVO.setDebtMoney(moneyDO.getDebtAmount());
} }
BigDecimal wxRechargeMoney = cardMapper.selectWxMoney(userId); BigDecimal wxRechargeMoney = cardMapper.selectWxMoney(userId);
orderMoneyRespVO.setWxRechargeMoney(wxRechargeMoney); orderMoneyRespVO.setWxRechargeMoney(wxRechargeMoney);
return orderMoneyRespVO; return orderMoneyRespVO;

View File

@ -84,7 +84,7 @@ public class OrderSpaceCapsuleServiceImpl implements OrderSpaceCapsuleService {
BigDecimal multiply = orderSpaceCapsule.getComboPrice().multiply(BigDecimal.valueOf(orderSpaceCapsule.getComboNum())); BigDecimal multiply = orderSpaceCapsule.getComboPrice().multiply(BigDecimal.valueOf(orderSpaceCapsule.getComboNum()));
orderSpaceCapsule.setMoney(multiply); orderSpaceCapsule.setMoney(multiply);
// 扣除余额 // 扣除余额
deductionService.spaceDeduct(orderSpaceCapsule.getUserId(), orderSpaceCapsule.getMoney(), CostTypeEnum.SHOPPING.getCode(),createReqVO.getCarteenId()); deductionService.spaceDeduct(orderSpaceCapsule.getUserId(), orderSpaceCapsule.getMoney(), CostTypeEnum.SPACE.getCode(),createReqVO.getCarteenId());
// 设置变动后的余额 // 设置变动后的余额
orderSpaceCapsule.setEndMoney(initialMoney.subtract(orderSpaceCapsule.getMoney())); orderSpaceCapsule.setEndMoney(initialMoney.subtract(orderSpaceCapsule.getMoney()));
// 设置支付方式 // 设置支付方式

View File

@ -234,13 +234,9 @@ public class StoreOrderServiceImpl implements StoreOrderService {
BigDecimal totalMoney = BigDecimal.valueOf(sum); BigDecimal totalMoney = BigDecimal.valueOf(sum);
MemberUserDO user = userService.getUser(Long.valueOf(s)); MemberUserDO user = userService.getUser(Long.valueOf(s));
MoneyDO moneyDO = moneyService.getMoney(user.getId(), storeId);
BigDecimal cashAmount = BigDecimal.ZERO;
if(ObjectUtil.isNotEmpty(moneyDO)){
cashAmount = moneyDO.getCashAmount();
}
dto.setUserId(user.getId()); dto.setUserId(user.getId());
if(user.getWxAmount().add(cashAmount).compareTo(totalMoney) < 0){ if(user.getMoney().compareTo(totalMoney) < 0){
throw exception(AMOUNT_NOT_ENOUGH); throw exception(AMOUNT_NOT_ENOUGH);
} }