|
|
@@ -17,11 +17,15 @@ import org.springblade.common.enums.NumberEnum;
|
|
|
import org.springblade.core.secure.BladeUser;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.pay.tonglianPayment.entity.Parameters;
|
|
|
import org.springblade.pay.tonglianPayment.fegin.IPaymentClient;
|
|
|
import org.springblade.salesPart.corps.service.ICorpsAttnService;
|
|
|
import org.springblade.salesPart.corps.service.ICorpsDescService;
|
|
|
+import org.springblade.salesPart.coupon.dto.TireUserCouponDto;
|
|
|
+import org.springblade.salesPart.coupon.entity.TireUserCoupon;
|
|
|
+import org.springblade.salesPart.coupon.mapper.TireUserCouponMapper;
|
|
|
import org.springblade.salesPart.entity.*;
|
|
|
import org.springblade.salesPart.enums.FinalMap;
|
|
|
import org.springblade.salesPart.enums.OrderTypeEnum;
|
|
|
@@ -48,12 +52,14 @@ import org.springblade.system.user.entity.User;
|
|
|
import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springblade.system.user.feign.IUserSearchClient;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
@@ -79,7 +85,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
private final ISysClient sysClient;
|
|
|
private final PayService payService;
|
|
|
private IUserSearchClient userSearchClient;
|
|
|
- private final IMessageClient messageClient;//消息
|
|
|
+ private final IMessageClient messageClient;
|
|
|
private IUserClient userClient;
|
|
|
|
|
|
private final IPjIntegralDetailService integralDetailService;
|
|
|
@@ -92,6 +98,8 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
|
|
|
private final GreenRecyclingRecordMapper greenRecyclingRecordMapper;
|
|
|
|
|
|
+ private final TireUserCouponMapper tireUserCouponMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 保存修改购物车信息
|
|
|
@@ -195,17 +203,20 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
order.setReceivableType("网络支付");
|
|
|
orderService.save(order);
|
|
|
ids.append(order.getId()).append(",");
|
|
|
+ // 红包金额
|
|
|
+ BigDecimal redPacketAmount = BigDecimal.ZERO;
|
|
|
+ List<Long> useCouponIdList = new ArrayList<>();
|
|
|
//保存销售明细信息
|
|
|
if (ObjectUtil.isNotEmpty(shoppingCartList)) {
|
|
|
List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
- shoppingCartList.forEach(e -> {
|
|
|
+ for (PjShoppingCart e : shoppingCartList) {
|
|
|
PjOrderItems orderItems = new PjOrderItems();
|
|
|
BeanUtils.copyProperties(e, orderItems);
|
|
|
if (e.getInventory().compareTo(orderItems.getGoodsNum()) < 0) {
|
|
|
throw new RuntimeException("库存不足");
|
|
|
}
|
|
|
orderItems.setId(null);
|
|
|
- orderItems.setSendNum(new BigDecimal("0.00"));
|
|
|
+ orderItems.setSendNum(FinalMap.ZERO_POINT_ZERO);
|
|
|
orderItems.setCreateUser(bladeUser.getUserId());
|
|
|
orderItems.setCreateDept(order.getCreateDept());
|
|
|
orderItems.setCreateTime(new Date());
|
|
|
@@ -218,6 +229,24 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
orderItems.setSubTotalMoney(orderItems.getGoodsNum().multiply(orderItems.getPrice()));
|
|
|
orderItems.setUrl(ObjectUtils.isNotNull(e.getFilesList()) && !e.getFilesList().isEmpty() ? e.getFilesList().get(0).getUrl() : "");
|
|
|
orderItems.setGoodsName(e.getGoodsName());
|
|
|
+ existCoupon: if (CollectionUtil.isNotEmpty(e.getItemCouponIds())) {
|
|
|
+ // 是否有匹配到红包
|
|
|
+ List<TireUserCouponDto> userCouponDtoList = tireUserCouponMapper.getUserCouponList(finalCorpsDesc.getId(), bladeUser.getTenantId());
|
|
|
+ if (CollectionUtil.isEmpty(userCouponDtoList)) {
|
|
|
+ break existCoupon;
|
|
|
+ }
|
|
|
+ List<Long> useCouponIds = userCouponDtoList.stream().map(TireUserCouponDto::getId).filter(id -> e.getItemCouponIds().contains(id) && !useCouponIdList.contains(id)).collect(Collectors.toList());
|
|
|
+ if (useCouponIds.isEmpty()) {
|
|
|
+ break existCoupon;
|
|
|
+ }
|
|
|
+ BigDecimal couponAmount = userCouponDtoList.stream().filter(coupon -> e.getItemCouponIds().contains(coupon.getId()) && !useCouponIdList.contains(coupon.getId())).map(TireUserCouponDto::getCouponValue).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal itemAmount = orderItems.getTotalAmount().subtract(couponAmount);
|
|
|
+ orderItems.setTotalAmount(itemAmount);
|
|
|
+ orderItems.setSubTotalMoney(itemAmount);
|
|
|
+ orderItems.setCouponIds(useCouponIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
|
|
|
+ redPacketAmount = redPacketAmount.add(couponAmount);
|
|
|
+ useCouponIdList.addAll(useCouponIds);
|
|
|
+ }
|
|
|
orderItemsMapper.insert(orderItems);
|
|
|
PjGoodsDesc goodsDesc = goodsDescMapper.selectById(orderItems.getGoodsId());
|
|
|
if (ObjectUtils.isNotNull(goodsDesc)) {
|
|
|
@@ -236,22 +265,19 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
pjProductLaunchList.add(productLaunch);
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
List<Integer> billType = pjProductLaunchList.stream().map(PjProductLaunch::getBillType).distinct().collect(Collectors.toList());
|
|
|
if (ObjectUtils.isNotNull(billType) && billType.size() > 1) {
|
|
|
throw new RuntimeException("请选择相同仓库的轮胎");
|
|
|
} else {
|
|
|
order.setBillType(billType.get(0));
|
|
|
}
|
|
|
- BigDecimal totalMoney = BigDecimal.ZERO;
|
|
|
- order.setNumberRows(shoppingCartList.size());//行数
|
|
|
+ order.setNumberRows(shoppingCartList.size());
|
|
|
//明细总数量
|
|
|
order.setGoodsTotalNum(shoppingCartList.stream().map(PjShoppingCart::getGoodsNum).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
|
|
|
//明细总金额
|
|
|
- totalMoney = shoppingCartList.stream().reduce(BigDecimal.ZERO, (x, y) -> {
|
|
|
- return x.add(y.getGoodsNum().multiply(y.getPrice()));
|
|
|
- }, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal totalMoney = shoppingCartList.stream().reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsNum().multiply(y.getPrice())), BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
order.setSalesAmount(totalMoney);
|
|
|
order.setTotalMoney(totalMoney);
|
|
|
@@ -259,10 +285,24 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
BigDecimal freightAmount = WxParamUtil.getFreightByOrder(order.getGoodsTotalNum(), freight);
|
|
|
order.setTotalMoney(totalMoney.add(freightAmount));
|
|
|
order.setFreight(freightAmount);
|
|
|
- amount = amount.add(order.getTotalMoney());
|
|
|
// order.setPaymentAmountTl(totalMoney);
|
|
|
order.setSharedCompanyId(shoppingCartList.get(0).getSharedCompanyId() + "");
|
|
|
order.setSharedCompanyName(shoppingCartList.get(0).getSharedCompanyName());
|
|
|
+ if (redPacketAmount.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ order.setSalesAmount(totalMoney.subtract(redPacketAmount));
|
|
|
+ order.setTotalMoney(order.getTotalMoney().subtract(redPacketAmount));
|
|
|
+ order.setRedPacketAmount(redPacketAmount);
|
|
|
+ TireUserCoupon updateUserCoupon = new TireUserCoupon();
|
|
|
+ updateUserCoupon.setOrderId(order.getId());
|
|
|
+ updateUserCoupon.setUsedTime(new Date());
|
|
|
+ updateUserCoupon.setStatus(1);
|
|
|
+ int updateUserCouponCount = tireUserCouponMapper.update(updateUserCoupon, new LambdaQueryWrapper<TireUserCoupon>().in(TireUserCoupon::getId, useCouponIdList)
|
|
|
+ .eq(TireUserCoupon::getCorpsId, finalCorpsDesc.getId()).eq(TireUserCoupon::getTenantId, bladeUser.getTenantId()));
|
|
|
+ if (updateUserCouponCount <= 0) {
|
|
|
+ throw new RuntimeException("使用优惠券失败,请重新下单");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ amount = amount.add(order.getTotalMoney());
|
|
|
}
|
|
|
if (goodsName.length() > 0) {
|
|
|
order.setGoodsNameJoin(goodsName.substring(0, goodsName.length() - 1));
|
|
|
@@ -613,7 +653,10 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
//保存销售明细信息
|
|
|
if (ObjectUtil.isNotEmpty(shoppingCartList)) {
|
|
|
List<PjProductLaunch> pjProductLaunchList = new ArrayList<>();
|
|
|
- shoppingCartList.forEach(e -> {
|
|
|
+ // 红包金额
|
|
|
+ BigDecimal redPacketAmount = BigDecimal.ZERO;
|
|
|
+ List<Long> useCouponIdList = new ArrayList<>();
|
|
|
+ for (PjShoppingCart e : shoppingCartList) {
|
|
|
PjOrderItems orderItems = new PjOrderItems();
|
|
|
BeanUtils.copyProperties(e, orderItems);
|
|
|
if (e.getInventory().compareTo(orderItems.getGoodsNum()) < 0) {
|
|
|
@@ -633,6 +676,24 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
orderItems.setSubTotalMoney(orderItems.getGoodsNum().multiply(orderItems.getPrice()));
|
|
|
orderItems.setUrl(ObjectUtils.isNotNull(e.getFilesList()) && !e.getFilesList().isEmpty() ? e.getFilesList().get(0).getUrl() : "");
|
|
|
orderItems.setGoodsName(e.getGoodsName());
|
|
|
+ existCoupon: if (CollectionUtil.isNotEmpty(e.getItemCouponIds())) {
|
|
|
+ // 是否有匹配到红包
|
|
|
+ List<TireUserCouponDto> userCouponDtoList = tireUserCouponMapper.getUserCouponList(corpsDesc.getId(), nowOrderUser.getTenantId());
|
|
|
+ if (CollectionUtil.isEmpty(userCouponDtoList)) {
|
|
|
+ break existCoupon;
|
|
|
+ }
|
|
|
+ List<Long> useCouponIds = userCouponDtoList.stream().map(TireUserCouponDto::getId).filter(id -> e.getItemCouponIds().contains(id) && !useCouponIdList.contains(id)).collect(Collectors.toList());
|
|
|
+ if (useCouponIds.isEmpty()) {
|
|
|
+ break existCoupon;
|
|
|
+ }
|
|
|
+ BigDecimal couponAmount = userCouponDtoList.stream().filter(coupon -> e.getItemCouponIds().contains(coupon.getId()) && !useCouponIdList.contains(coupon.getId())).map(TireUserCouponDto::getCouponValue).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal itemAmount = orderItems.getTotalAmount().subtract(couponAmount);
|
|
|
+ orderItems.setTotalAmount(itemAmount);
|
|
|
+ orderItems.setSubTotalMoney(itemAmount);
|
|
|
+ orderItems.setCouponIds(useCouponIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
|
|
|
+ redPacketAmount = redPacketAmount.add(couponAmount);
|
|
|
+ useCouponIdList.addAll(useCouponIds);
|
|
|
+ }
|
|
|
orderItemsMapper.insert(orderItems);
|
|
|
PjGoodsDesc goodsDesc = goodsDescMapper.selectById(orderItems.getGoodsId());
|
|
|
if (ObjectUtils.isNotNull(goodsDesc)) {
|
|
|
@@ -657,7 +718,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
pjProductLaunchList.add(productLaunch);
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
List<Integer> billType = pjProductLaunchList.stream().map(PjProductLaunch::getBillType).distinct().collect(Collectors.toList());
|
|
|
if (ObjectUtils.isNotNull(billType) && billType.size() > 1) {
|
|
|
throw new RuntimeException("请选择相同仓库的轮胎");
|
|
|
@@ -674,7 +735,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
order.setSalesAmount(totalMoney);
|
|
|
order.setTotalMoney(totalMoney);
|
|
|
|
|
|
- if (order.getGoodsTotalNum().compareTo(new BigDecimal(1)) == 0) {
|
|
|
+ if (order.getGoodsTotalNum().compareTo(BigDecimal.ONE) == 0) {
|
|
|
String freight = sysClient.getParamServiceDWT("freight", corpsDesc.getTenantId());
|
|
|
if (ObjectUtils.isNotNull(freight)) {
|
|
|
try {
|
|
|
@@ -690,6 +751,19 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
order.setTotalMoney(totalMoney);
|
|
|
order.setFreight(new BigDecimal(5));*/
|
|
|
}
|
|
|
+ if (redPacketAmount.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ order.setTotalMoney(order.getTotalMoney().subtract(redPacketAmount));
|
|
|
+ order.setRedPacketAmount(redPacketAmount);
|
|
|
+ TireUserCoupon updateUserCoupon = new TireUserCoupon();
|
|
|
+ updateUserCoupon.setOrderId(order.getId());
|
|
|
+ updateUserCoupon.setUsedTime(new Date());
|
|
|
+ updateUserCoupon.setStatus(1);
|
|
|
+ int updateUserCouponCount = tireUserCouponMapper.update(updateUserCoupon, new LambdaQueryWrapper<TireUserCoupon>().in(TireUserCoupon::getId, useCouponIdList)
|
|
|
+ .eq(TireUserCoupon::getCorpsId, corpsDesc.getId()).eq(TireUserCoupon::getTenantId, nowOrderUser.getTenantId()));
|
|
|
+ if (updateUserCouponCount <= 0) {
|
|
|
+ throw new RuntimeException("使用红包失败,请重新下单");
|
|
|
+ }
|
|
|
+ }
|
|
|
amount = amount.add(order.getTotalMoney());
|
|
|
order.setPaymentDate(new Date());
|
|
|
// 额度支付默认已付款
|
|
|
@@ -1280,6 +1354,12 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
if (ObjectUtil.isEmpty(parametersR.getData())) {
|
|
|
return R.fail("未查到支付类型数据");
|
|
|
}
|
|
|
+ BladeUser bladeUser = AuthUtil.getUser();
|
|
|
+ PjCorpsAttn nowShopUser = corpsAttnService.getOne(new LambdaQueryWrapper<PjCorpsAttn>().eq(PjCorpsAttn::getIsDeleted, 0)
|
|
|
+ .eq(PjCorpsAttn::getTenantId, bladeUser.getTenantId()).eq(PjCorpsAttn::getUserId, bladeUser.getUserId()).last("limit 1"));
|
|
|
+ if (Objects.isNull(nowShopUser)) {
|
|
|
+ return R.fail("未查找到您的门店信息");
|
|
|
+ }
|
|
|
String payType = parametersR.getData().getPayType();
|
|
|
PjOrder srcOrder = orderService.getById(order.getId());
|
|
|
if (org.springframework.util.ObjectUtils.isEmpty(srcOrder) || srcOrder.getIsDeleted() == 1) {
|
|
|
@@ -1309,6 +1389,11 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
if (org.springframework.util.CollectionUtils.isEmpty(pjProductLaunchList)) {
|
|
|
return R.fail("该订单商品数据已全部下架,请重新下单");
|
|
|
}
|
|
|
+
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ List<TireUserCoupon> userCouponList = tireUserCouponMapper.selectList(new LambdaQueryWrapper<TireUserCoupon>()
|
|
|
+ .eq(TireUserCoupon::getCorpsId, nowShopUser.getPid()).eq(TireUserCoupon::getTenantId, bladeUser.getTenantId())
|
|
|
+ .le(TireUserCoupon::getEffectiveStart, today).ge(TireUserCoupon::getEffectiveEnd, today));
|
|
|
for (PjOrderItems item : orderItemsList) {
|
|
|
ShoppingMallDetail productLaunch = pjProductLaunchList.stream().filter(x -> x.getGoodsId().equals(item.getGoodsId())).findFirst().orElse(null);
|
|
|
if (productLaunch == null) {
|
|
|
@@ -1317,6 +1402,17 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
if (productLaunch.getInventory().compareTo(item.getGoodsNum()) < 0) {
|
|
|
return R.fail("该订单商品-“" + item.getGoodsName() + "”-库存不足,请重新下单");
|
|
|
}
|
|
|
+ if (StringUtil.isNotBlank(item.getCouponIds()) && CollectionUtil.isNotEmpty(userCouponList)) {
|
|
|
+ // 是否有匹配到红包
|
|
|
+ List<Long> itemCouponIds = Arrays.stream(item.getCouponIds().split(",")).map(Long::parseLong).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(itemCouponIds)) {
|
|
|
+ return R.fail("该订单存在使用红包,但已过期或不存在,请重新下单");
|
|
|
+ }
|
|
|
+ long couponCount = userCouponList.stream().filter(y -> itemCouponIds.contains(y.getId())).count();
|
|
|
+ if (couponCount != itemCouponIds.size()) {
|
|
|
+ return R.fail("该订单存在使用红包,但已过期或不存在,请重新下单");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
String orderIdsStr = orderIds.stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
String orderGoodsNameStr = orderItemsList.stream().map(PjOrderItems::getGoodsName).collect(Collectors.joining(","));
|