xiaoyong931011
2021-07-02 b02c10cc0f53a3dac95045bea33eb9aa3c13e3e3
gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java
@@ -72,6 +72,29 @@
            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)){
                    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);
@@ -152,7 +175,8 @@
    public Long insureOrder(InsureOrderDto model) {
        ScoreOrder scoreOrder = new ScoreOrder();
        scoreOrder.setId(model.getId());
        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();
@@ -174,6 +198,10 @@
            if (new Date().after(goods.getQgEndTime())) {
                throw new RestException(-3, "抢购已结束");
            }
        }
        if (addGoodsOrderDto.getCnt() > sku.getStock()) {
            throw new RestException(-3, "库存不足");
        }
        AccountInfo accountInfo = accountInfoMapper.selectAccountInfoByUserId(addGoodsOrderDto.getUserId());
@@ -378,4 +406,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;
    }
}