| | |
| | | // 判断已经购买的了多少 |
| | | List<TSysGoodsExchange> list = sysGoodsExchangeMapper.selectList(new LambdaQueryWrapper<TSysGoodsExchange>().eq(TSysGoodsExchange::getGoodsId, dto.getGoodsId())); |
| | | int sum = list.stream().mapToInt(TSysGoodsExchange::getGoodsCount).sum(); |
| | | if(sum+dto.getCount()>tSysGoods.getGoodsTotal()){ |
| | | if(tSysGoods.getGoodsTotal()!=null && sum+dto.getCount()>tSysGoods.getGoodsTotal()){ |
| | | throw new RuntimeException("商品库存不足"); |
| | | } |
| | | if(sum+dto.getCount()>tSysGoods.getConvertibleQuantity()){ |
| | | if(tSysGoods.getConvertibleQuantity()!=null && sum+dto.getCount()>tSysGoods.getConvertibleQuantity()){ |
| | | throw new RuntimeException("可兑换数量不足"); |
| | | } |
| | | List<TCrmClinicPoints> points = crmClinicPointsMapper.selectList(new LambdaQueryWrapper<TCrmClinicPoints>().eq(TCrmClinicPoints::getClinicId, crmClinic.getId()).ge(TCrmClinicPoints::getExpireTime, new Date()).last(" and points > use_points").orderByAsc(TCrmClinicPoints::getCreateTime)); |
| | | List<TCrmClinicPoints> points = crmClinicPointsMapper.selectList(new LambdaQueryWrapper<TCrmClinicPoints>().eq(TCrmClinicPoints::getClinicId, crmClinic.getId()).ge(TCrmClinicPoints::getExpireTime, new Date()).last(" and points > use_points ORDER BY create_time ASC")); |
| | | // 可用积分 |
| | | int userPoints = points.stream().mapToInt(item -> item.getPoints() - item.getUsePoints()).sum(); |
| | | if(userPoints<needPoints){ |
| | |
| | | exchange.setGoodsCount(dto.getCount()); |
| | | exchange.setUsePoints(tSysGoods.getRequiredPoints().intValue() * dto.getCount()); |
| | | exchange.setExchangeTime(LocalDateTime.now()); |
| | | exchange.setClinicId(crmClinic.getId()); |
| | | sysGoodsExchangeMapper.insert(exchange); |
| | | |
| | | // 记录 |