From d0c47393cbf57134bd539c7cc0804c9c4cddef85 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Wed, 07 Jul 2021 17:31:53 +0800 Subject: [PATCH] 20210707 --- gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java | 70 ++++++++++++++++++++++++++++++++--- 1 files changed, 64 insertions(+), 6 deletions(-) diff --git a/gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java b/gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java index 022caf0..f0f17d6 100644 --- a/gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java +++ b/gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java @@ -61,7 +61,7 @@ private IdUtils idUtils; public Map<String, Object> queryOrderList(QueryOrderListDto model) { - String name = model.getName(); + String name = StrUtil.isEmpty(model.getName())?model.getName():StringUtils.encode(model.getName()); String orderNo = model.getOrderNo(); Integer status = model.getStatus() == null ? 0 : model.getStatus(); Date createdTimeStart = model.getCreatedTimeStart(); @@ -72,6 +72,30 @@ for(QueryOrderListVo queryOrderListVo : maps){ String decode = StringUtils.decode(queryOrderListVo.getName()); queryOrderListVo.setName(decode); + BigDecimal totalPrice = new BigDecimal(StrUtil.isEmpty(queryOrderListVo.getTotalPrice()) ? "0" : queryOrderListVo.getTotalPrice()) + .setScale( 2, BigDecimal.ROUND_DOWN ); + queryOrderListVo.setTotalPrice(totalPrice.toString()); + + Long id = queryOrderListVo.getId(); + Example example = new Example(ScoreOrderDetails.class); + Example.Criteria criteria = example.createCriteria(); + criteria.andEqualTo("orderId",id); + List<ScoreOrderDetails> scoreOrderDetails = scoreOrderDetailsMapper.selectByExample(example); + if(CollUtil.isNotEmpty(scoreOrderDetails)){ + queryOrderListVo.setOrderDetails(scoreOrderDetails); +// StringBuffer stringBuffer = new StringBuffer(); +// for(ScoreOrderDetails scoreOrderDetail : scoreOrderDetails){ +// String goodsName = scoreOrderDetail.getGoodsName(); +// BigDecimal unitPrice = scoreOrderDetail.getUnitPrice(); +// String sku = scoreOrderDetail.getSku(); +// Integer cnt = scoreOrderDetail.getCnt(); +// BigDecimal totalPriceOrderDetail = scoreOrderDetail.getTotalPrice(); +// stringBuffer = stringBuffer.append(goodsName+"(") +// .append("规格:"+sku+","+unitPrice.setScale( 2, BigDecimal.ROUND_DOWN ).toString()+"*"+cnt.toString()+",") +// .append("总价:"+totalPriceOrderDetail.setScale( 2, BigDecimal.ROUND_DOWN ).toString()+";)"); +// } +// queryOrderListVo.setOrderDetails(stringBuffer.toString()); + } } } PageInfo pageInfo = new PageInfo(maps); @@ -150,9 +174,15 @@ } public Long insureOrder(InsureOrderDto model) { + long id = model.getId(); + ScoreOrder scoreOrderBefore = scoreOrderMapper.selectByPrimaryKey(id); ScoreOrder scoreOrder = new ScoreOrder(); scoreOrder.setId(model.getId()); - scoreOrder.setStatus(ScoreOrder.STATUS_DONE); + if(ScoreOrder.STATUS_DOING == scoreOrderBefore.getStatus()){ + scoreOrder.setStatus(ScoreOrder.STATUS_DONE); + } +// scoreOrder.setStatus(ScoreOrder.STATUS_DONE); + scoreOrder.setIsFinish(ScoreOrder.ISFINISH_YES); scoreOrder.setVoucherImg(CollUtil.join(model.getVoucherImgs(),",")); scoreOrderMapper.updateByPrimaryKeySelective(scoreOrder); return scoreOrder.getId(); @@ -176,8 +206,11 @@ } } - AccountInfo accountInfo = accountInfoMapper.selectAccountInfoByUserId(addGoodsOrderDto.getUserId()); + if (addGoodsOrderDto.getCnt() > sku.getStock()) { + throw new RestException(-3, "库存不足"); + } + AccountInfo accountInfo = accountInfoMapper.selectAccountInfoByUserId(addGoodsOrderDto.getUserId()); if (accountInfo.getCollectScore() == null) { throw new RestException(-3, "积分不足"); } @@ -208,6 +241,7 @@ orderDetails.setTotalPrice(totalPrice); orderDetails.setUnitPrice(sku.getPresentPrice()); orderDetails.setGoodsId(goods.getId()); + orderDetails.setSkuId(sku.getId()); orderDetails.setThumb(goods.getThumb()); scoreOrderDetailsMapper.insert(orderDetails); @@ -241,12 +275,12 @@ scoreDetails.setType(ScoreDetails.SCORE_TYPE_SHOPPING); scoreDetails.setOriginalScore(score); scoreDetails.setCurrentScore(remianScore); - scoreDetails.setChangeScore(totalPrice); + scoreDetails.setChangeScore(totalPrice.negate()); scoreDetails.setCreatedTime(new Date()); scoreDetailsMapper.insert(scoreDetails); sku.setStock(sku.getStock() - addGoodsOrderDto.getCnt()); - sku.setQuantity(sku.getQuantity() - addGoodsOrderDto.getCnt()); + sku.setQuantity(sku.getQuantity() + addGoodsOrderDto.getCnt()); scoreGoodsSkuMapper.updateByPrimaryKey(sku); } @@ -324,7 +358,12 @@ throw new RestException(-3, "暂不能确认收货"); } - scoreOrderMapper.updateOrderStatus(id, ScoreOrder.STATUS_DOING, userId); + if (ScoreOrder.ISFINISH_YES.equals(order.getIsFinish())) { + scoreOrderMapper.updateOrderStatus(id, ScoreOrder.STATUS_DONE, userId); + } else { + scoreOrderMapper.updateOrderStatus(id, ScoreOrder.STATUS_DOING, userId); + } + } public void cancelOrder(Long id, String userId) { @@ -378,4 +417,23 @@ } } } + + public StatisticsVo orderStatistics(String userId) { + BigDecimal score = scoreDetailsMapper.selectTotalScoreByUserId(userId, ScoreDetails.SCORE_TYPE_EXCHANGE); + + Map<String, Object> userData = scoreOrderMapper.selectOrderStastics(userId); + Map<String, Object> allData = scoreOrderMapper.selectOrderStastics(null); + + StatisticsVo statisticsVo = new StatisticsVo(); + statisticsVo.setScore(score); + BigDecimal userPrice = (BigDecimal) userData.get("totalPrice"); + statisticsVo.setReduceCarbon(userPrice.divide(BigDecimal.TEN, 2, BigDecimal.ROUND_DOWN)); + statisticsVo.setOrderCnt(Integer.parseInt(userData.get("totalOrder").toString())); + + BigDecimal totalPrice = (BigDecimal) allData.get("totalPrice"); + statisticsVo.setTotalReduceCarbon(totalPrice.divide(BigDecimal.TEN, 2, BigDecimal.ROUND_DOWN)); + statisticsVo.setTotalOrderCnt(Integer.parseInt(allData.get("totalOrder").toString())); + statisticsVo.setTotalBuyCnt(Integer.parseInt(allData.get("totalBuy").toString())); + return statisticsVo; + } } -- Gitblit v1.9.1