| | |
| | | import java.math.RoundingMode; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.*; |
| | | |
| | | import java.time.ZoneId; |
| | | import java.time.ZoneOffset; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new ServiceException("生成核销码失败"); |
| | | } |
| | | if(3!=order.getOrderStatus()){ |
| | | //不属于未使用的,应该有个核销\取消时间 |
| | | orderDetailVO.setEndTime(order.getEndTime()); |
| | | } |
| | | //该商品是否被用户评论 |
| | | Long evaluateId = goodsEvaluateClient.getEvaluateIdByOrderId(order.getId()).getData(); |
| | |
| | | //退款成功再回退积分 |
| | | AppUser appUser = appUserClient.getAppUserById(order.getAppUserId()); |
| | | if (order.getPoint()>0) { |
| | | if(null==appUser.getCancelPoint()){ |
| | | appUser.setCancelPoint(0); |
| | | } |
| | | //返回订单抵扣积分 |
| | | Integer historicalPoint = appUser.getAvailablePoint(); |
| | | Integer availablePoint = appUser.getAvailablePoint() + order.getPoint();//可用积分 |
| | |
| | | //判断是否是积分支付 |
| | | if (type == 1) {//现金 |
| | | confirmOrderVo.setOrderMoney(confirmOrderVo.getCash()); |
| | | Integer availablePoint = appUser.getAvailablePoint();//用户可用积分 |
| | | |
| | | BigDecimal maxPointDeductionAmount = getCashByPoint(availablePoint);//最大可抵扣金额 |
| | | |
| | | //计算积分抵扣的金额 将积分转为金额,去掉小数 |
| | | BigDecimal deduction=getCashByPoint(confirmOrderVo.getResidualPoint()); |
| | | //实际抵扣金额 |
| | | BigDecimal deduction= maxPointDeductionAmount.min(confirmOrderVo.getCash()); |
| | | confirmOrderVo.setDeduction(deduction); |
| | | }else {//积分 |
| | | confirmOrderVo.setOrderPoint(good.getIntegral()); |
| | | confirmOrderVo.setOrderPoint(confirmOrderVo.getPoint()); |
| | | } |
| | | //限购检查 |
| | | //判断当前数量是否已经超出限购数量(需要计算已经购买的数量) |
| | |
| | | } |
| | | //判断积分是否为零,积分支付 |
| | | if (0 != order.getPoint()){ |
| | | if (null==appUser.getAvailablePoint()){ |
| | | appUser.setAvailablePoint(0); |
| | | } |
| | | if (null==appUser.getExchangePoint()){ |
| | | appUser.setExchangePoint(0); |
| | | } |
| | | |
| | | //积分支付 |
| | | Integer historicalPoint = appUser.getAvailablePoint();//历史积分 |
| | | Integer availablePoint = historicalPoint - orderPoint;//可用积分 |
| | |
| | | |
| | | //门店增加冻结资金 即增加余额, 冻结资金=余额-可用资金 |
| | | Shop shop = shopClient.getShopById(order.getShopId()).getData(); |
| | | if (null==shop.getBalance()){ |
| | | shop.setBalance(BigDecimal.ZERO); |
| | | } |
| | | |
| | | BigDecimal historicalBalance=shop.getBalance();//历史余额 |
| | | BigDecimal variableAmount=goods.getSellingPrice();//变动金额 |
| | | BigDecimal balance=shop.getBalance().add(goods.getSellingPrice());//变动后余额 |
| | |
| | | queryWrapper.eq("shop_id", shopId); |
| | | } |
| | | // 添加订单状态条件 |
| | | if (status != null) { |
| | | queryWrapper.eq("order_status", status); |
| | | if (status != null&&status==4) { //4-已完成 8-已评价 |
| | | queryWrapper.in("order_status",Arrays.asList(4,8)); |
| | | } |
| | | if (status != null&&status!=4) {//3-待核销 5-已取消 |
| | | queryWrapper.eq("order_status",status); |
| | | } |
| | | // 模糊查询条件 |
| | | if (StringUtils.isNotBlank(content)) { |
| | |
| | | return R.fail("订单取消失败"); |
| | | } |
| | | order.setOrderStatus(5); |
| | | order.setEndTime(LocalDateTime.now()); |
| | | R r = refundPayMoney(order); |
| | | if (200 == r.getCode()) { |
| | | this.updateById(order); |
| | | } |
| | | return r; |
| | | } |
| | | |
| | | /** |
| | | * 后台-工作台-折线图 |
| | | * @param startTime |
| | | * @param endTime |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<OrderStatisticsDetail> getOrderListGroupByDate(LocalDate startTime, LocalDate endTime) { |
| | | // 查询数据库获取原始数据 |
| | | List<OrderStatisticsDetail> rawData = orderMapper.getOrderListGroupByDate( |
| | | startTime.atTime(0,0, 0), |
| | | endTime.atTime(23,59,59) |
| | | ); |
| | | |
| | | // 创建完整日期范围的映射 |
| | | Map<LocalDate, OrderStatisticsDetail> dateMap = rawData.stream() |
| | | .collect(Collectors.toMap( |
| | | OrderStatisticsDetail::getDateTime, |
| | | Function.identity() |
| | | )); |
| | | |
| | | // 生成完整日期序列并填充缺失数据 |
| | | List<OrderStatisticsDetail> completeList = new ArrayList<>(); |
| | | for (LocalDate date = startTime; !date.isAfter(endTime); date = date.plusDays(1)) { |
| | | if (dateMap.containsKey(date)) { |
| | | completeList.add(dateMap.get(date)); |
| | | } else { |
| | | completeList.add(new OrderStatisticsDetail(date, 0, BigDecimal.ZERO)); |
| | | } |
| | | } |
| | | return completeList; |
| | | } |
| | | |
| | | |
| | | private OrderPageListVo convertToOrderListVo(Order order) { |
| | | OrderPageListVo vo = new OrderPageListVo(); |
| | |
| | | if (user != null) { |
| | | vo.setPhone(user.getPhone()); |
| | | } |
| | | vo.setIdStr(order.getId().toString()); |
| | | return vo; |
| | | } |
| | | |