| | |
| | | import com.mzl.flower.config.security.SecurityUtils; |
| | | import com.mzl.flower.constant.Constants; |
| | | import com.mzl.flower.dto.PriceDTO; |
| | | import com.mzl.flower.dto.request.comment.QueryFlowerCommentDTO; |
| | | import com.mzl.flower.dto.request.menber.MemberGrowthRecordDTO; |
| | | import com.mzl.flower.dto.request.payment.*; |
| | | import com.mzl.flower.dto.response.comment.FlowerCommentVO; |
| | | import com.mzl.flower.dto.response.coupon.CouponRecordVO; |
| | | import com.mzl.flower.dto.response.flower.FlowerCartListDTO; |
| | | import com.mzl.flower.dto.response.flower.FlowerCartListWrapDTO; |
| | |
| | | import com.mzl.flower.mapper.system.UserWechatMapper; |
| | | import com.mzl.flower.mapper.warehouse.WarehouseLocationMapper; |
| | | import com.mzl.flower.service.BaseService; |
| | | import com.mzl.flower.service.ConfigParamService; |
| | | import com.mzl.flower.service.comment.FlowerCommentService; |
| | | import com.mzl.flower.service.coupon.CouponRecordService; |
| | | import com.mzl.flower.service.flower.FlowerService; |
| | | import com.mzl.flower.service.menber.MemberGrowthRecordService; |
| | |
| | | @Autowired |
| | | private CouponRecordService couponRecordService; |
| | | |
| | | @Autowired |
| | | private FlowerCommentService flowerCommentService; |
| | | |
| | | @Autowired |
| | | private ConfigParamService configParamService; |
| | | |
| | | public void changeFlower2Cart(CartSaveDTO dto) { |
| | | String userId = SecurityUtils.getUserId(); |
| | |
| | | Integer completeNumToday=getFlowerCompleteNumToday(userId,c.getFlowerId()); |
| | | Integer tmp=completeNumToday+c.getNum(); |
| | | if(null!=tmp && null!=flowerDetail.getLimited() |
| | | && tmp.compareTo(flowerDetail.getLimited())>0){ |
| | | && tmp.compareTo(flowerDetail.getLimited())>0){ |
| | | throw new ValidationException("当天的订单的花数量加上购物车的数量不能超过限售数量!"); |
| | | } |
| | | |
| | |
| | | |
| | | // 限购 1.首先查看购物车中的数量是否已经超过限售数量 |
| | | if(null!=c.getNum() && null!=flowerDetail.getLimited() |
| | | && c.getNum().compareTo(flowerDetail.getLimited())>0){ |
| | | && c.getNum().compareTo(flowerDetail.getLimited())>0){ |
| | | throw new ValidationException("数量不能超过限售数量!"); |
| | | } |
| | | |
| | |
| | | Integer completeNumToday=getFlowerCompleteNumToday(userId,c.getFlowerId()); |
| | | Integer tmp=completeNumToday+c.getNum(); |
| | | if(null!=tmp && null!=flowerDetail.getLimited() |
| | | && tmp.compareTo(flowerDetail.getLimited())>0){ |
| | | && tmp.compareTo(flowerDetail.getLimited())>0){ |
| | | throw new ValidationException("当天的订单的花数量加上购物车的数量不能超过限售数量!"); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public Map commitOrder(OrderCommitDTO dto, PreOrderDTO p, Map<Long, PriceDTO> priceMap) { |
| | | public Map commitOrder(OrderCommitDTO dto, PreOrderDTO p, Map<Long, PriceDTO> priceMap) throws Exception { |
| | | String userId = SecurityUtils.getUserId(); |
| | | p.getFlowers().forEach(flower -> { |
| | | // 限购数量 鲜花数量校验 |
| | |
| | | usePointGoods(order.getId(), goodsRecordIdList);//使用积分商品兑换券 |
| | | |
| | | order.create(userId); |
| | | // 根据当前的时间判断,如果时间大于当天的下午17:00 ,那么日期则为下一天的日期,否则为当天日期 |
| | | if(null!=order.getCreateTime()){ |
| | | LocalDateTime createDateTime = order.getCreateTime(); |
| | | LocalDate createDate = createDateTime.toLocalDate(); |
| | | LocalDateTime today1700 = createDateTime.with(LocalTime.of(17, 0)); |
| | | // 比较时间是否大于当天的 17:00 |
| | | if (createDateTime.isAfter(today1700)) { |
| | | // 如果大于 17:00,设置为下一天的日期 |
| | | createDate = createDate.plusDays(1); |
| | | } |
| | | order.setCreateDateSta(createDate); |
| | | } |
| | | // order.setCreateDate(); |
| | | order.setRemarks(dto.getRemarks()); |
| | | order.setSpecialNeeds(dto.getSpecialNeeds()); |
| | | order.setStatusBackend(Constants.ORDER_STATUS_BACKEND.PENDING.name()); |
| | |
| | | totalAmount = new BigDecimal(0); |
| | | } |
| | | totalAmount = totalAmount.add(p.getPacking()).add(transportFee); |
| | | if(totalAmount.doubleValue() <= 0){//假如总价小于等于0,则支付0.01元 |
| | | totalAmount = new BigDecimal(0.01); |
| | | |
| | | // 判断最低金额如果小于配置的钱,则不能提交 |
| | | String paramGroup = "orderpay"; |
| | | String paramKey = "order_min_fee"; |
| | | String baseString = configParamService.getBaseString(paramGroup, paramKey); |
| | | if(StringUtils.isNotEmpty(baseString)){ |
| | | // 判断类型是否错误,可转换成BigDecimal |
| | | try { |
| | | BigDecimal minFee = new BigDecimal(baseString); |
| | | if(totalAmount.compareTo(minFee) < 0){ |
| | | throw new ValidationException("订单金额不能低于"+minFee+"元"); |
| | | } |
| | | } catch (NumberFormatException e) { |
| | | log.error("订单金额配置有误,请检查配置", e); |
| | | throw new ValidationException("订单金额配置有误,请检查配置"); |
| | | } |
| | | } |
| | | // if(totalAmount.doubleValue() <= 0){//假如总价小于等于0,则支付0.01元 |
| | | // totalAmount = new BigDecimal("0.01"); |
| | | // } |
| | | order.setTotalAmount(totalAmount); |
| | | |
| | | order.setCustomer(address.getName()); |
| | |
| | | orderIds.add(o.getId()); |
| | | |
| | | OrderPlatformListDTO p = new OrderPlatformListDTO(); |
| | | //增加订单扎数 |
| | | Integer sumNumByOrderId = orderItemMapper.getSumNumByOrderId(o.getId()); |
| | | o.setSaleNum(sumNumByOrderId); |
| | | |
| | | BeanUtils.copyProperties(o, p); |
| | | result.add(p); |
| | | } |
| | |
| | | new QueryWrapper<OrderItem>().eq("order_id", id)); |
| | | |
| | | Map<Long, String> stationMap = prepareStationMap(); |
| | | Map<String, FlowerCommentVO> commentMap=prepareCommentMap(id); |
| | | |
| | | List<OrderItemListDTO> result = new ArrayList<>(); |
| | | for (OrderItem oi : ls) { |
| | |
| | | |
| | | dto.setStationName(stationMap.get(oi.getStationId())); |
| | | |
| | | // 评论 |
| | | final FlowerCommentVO flowerCommentVO = commentMap.get(oi.getId()); |
| | | copyCommentInfo(dto,flowerCommentVO); |
| | | |
| | | result.add(dto); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private Map<String, FlowerCommentVO> prepareCommentMap(String orderId) { |
| | | QueryFlowerCommentDTO queryFlowerCommentDTO = new QueryFlowerCommentDTO(); |
| | | queryFlowerCommentDTO.setOrderId(orderId); |
| | | final List<FlowerCommentVO> list = flowerCommentService.getList(queryFlowerCommentDTO); |
| | | if (list == null || list.isEmpty()) { |
| | | return Collections.emptyMap(); |
| | | } |
| | | // 将 List 转换为 Map,其中 key 为 FlowerCommentVO 的 id |
| | | return list.stream().collect(Collectors.toMap(FlowerCommentVO::getOrderItemId, item -> item)); |
| | | } |
| | | |
| | | |
| | | private void copyCommentInfo(OrderItemListDTO dto,FlowerCommentVO flowerCommentVO){ |
| | | if(null != dto && null!=flowerCommentVO){ |
| | | dto.setCommentGrade(flowerCommentVO.getCommentGrade()); |
| | | dto.setComment(flowerCommentVO.getComment()); |
| | | dto.setCommentImages(flowerCommentVO.getCommentImages()); |
| | | dto.setAnonymityFalg(flowerCommentVO.getAnonymityFalg()); |
| | | } |
| | | } |
| | | |
| | | public List<Order> autoReceive() { |
| | | int days = -5; //5天前的订单自动收货 |
| | | String paramGroup = "order"; |
| | | String paramKey = "order_auto_receive"; |
| | | String baseString = configParamService.getBaseString(paramGroup, paramKey); |
| | | int days = -Integer.parseInt(baseString); |
| | | // int days = -5; //5天前的订单自动收货 |
| | | LocalDateTime endTime = LocalDateTime.now().plusDays(days); |
| | | List<Order> ls = orderMapper.getOrderForAutoReceive(endTime); |
| | | if (ls == null || ls.size() == 0) { |
| | |
| | | return dto; |
| | | } |
| | | |
| | | public void processAbnormalOrder(String id) { |
| | | public void processAbnormalOrder(String id) throws Exception { |
| | | Order o = orderMapper.selectById(id); |
| | | String transferId = o.getTransferId(); |
| | | if (StringUtils.isNotEmpty(transferId)) { |
| | |
| | | orderMapper.updateById(o); |
| | | } |
| | | |
| | | public void processLevelDown(OrderReduceDTO dto) { |
| | | public void processLevelDown(OrderReduceDTO dto) throws Exception { |
| | | Order o = orderMapper.selectById(dto.getId()); |
| | | String transferId = o.getTransferId(); |
| | | if (StringUtils.isNotEmpty(transferId)) { |
| | |
| | | // 新增 |
| | | cartMapper.updateById(cart); |
| | | }else{ |
| | | // 更新 |
| | | // 更新 |
| | | cartMapper.insert(cart); |
| | | } |
| | | } |
| | |
| | | |
| | | public void exportOrderDetail(HttpServletResponse response, OrderQueryDTO dto) { |
| | | List<OrderListExportDTO> ls = getOrderExportListBase( dto); |
| | | String[] rowsName = new String[]{"序号","订单号", "用户账号", "收货人", "收货人电话", "收获地址", "订单金额" |
| | | , "底价", "订单状态", "下单时间", "合伙人", "库位", "特殊需求", "备注"}; |
| | | String[] rowsName = new String[]{"序号","订单号", "用户账号", "收货人", "收货人电话", "收货地址", "订单金额" |
| | | , "底价","销售扎数", "订单状态", "下单时间", "合伙人", "库位", "特殊需求", "备注"}; |
| | | List<Object[]> dataList = new ArrayList<>(); |
| | | int sn = 1; |
| | | for (OrderListExportDTO o : ls) { |
| | |
| | | objs[a++] = o.getCustomerAddress(); |
| | | objs[a++] = o.getTotalAmount(); |
| | | objs[a++] = o.getSupplierAmount(); |
| | | objs[a++] = o.getSaleNum(); |
| | | objs[a++] = o.getStatusBackendStr(); |
| | | objs[a++] = o.getCreateTime(); |
| | | objs[a++] = o.getPartnerName(); |
| | |
| | | |
| | | } |
| | | |
| | | public void exportPartnerOrderList(HttpServletResponse response, OrderQueryDTO dto) { |
| | | Partner p = getCurrentPartner(); |
| | | dto.setPartnerId(p.getId()); |
| | | exportOrderDetail(response, dto); |
| | | } |
| | | |
| | | public void refreshDate() { |
| | | List<Order> allOrderList= orderMapper.selectAllDateList(); |
| | | |
| | | allOrderList.forEach(order -> { |
| | | orderMapper.updatePaymentCreateDate(order); |
| | | }); |
| | | } |
| | | |
| | | public Order getOrderInfoById(String id) { |
| | | return orderMapper.selectById(id); |
| | | } |
| | | } |