|
@@ -1,13 +1,11 @@
|
|
package com.caimei.service.impl;
|
|
package com.caimei.service.impl;
|
|
|
|
|
|
|
|
+import com.caimei.mapper.CouponMapper;
|
|
import com.caimei.mapper.OrderSubmitMapper;
|
|
import com.caimei.mapper.OrderSubmitMapper;
|
|
import com.caimei.mapper.ProductMapper;
|
|
import com.caimei.mapper.ProductMapper;
|
|
import com.caimei.model.ResponseJson;
|
|
import com.caimei.model.ResponseJson;
|
|
import com.caimei.model.po.*;
|
|
import com.caimei.model.po.*;
|
|
-import com.caimei.model.vo.ActivityLadderVo;
|
|
|
|
-import com.caimei.model.vo.AddressVo;
|
|
|
|
-import com.caimei.model.vo.CartProductVo;
|
|
|
|
-import com.caimei.model.vo.ShopVo;
|
|
|
|
|
|
+import com.caimei.model.vo.*;
|
|
import com.caimei.service.OrderSubmitService;
|
|
import com.caimei.service.OrderSubmitService;
|
|
import com.caimei.service.ShoppingCartService;
|
|
import com.caimei.service.ShoppingCartService;
|
|
import com.caimei.util.MathUtil;
|
|
import com.caimei.util.MathUtil;
|
|
@@ -15,6 +13,7 @@ import com.caimei.util.OrderNoUtils;
|
|
import com.caimei.util.ProductUtils;
|
|
import com.caimei.util.ProductUtils;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -42,15 +41,18 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
private ShoppingCartService shoppingCartService;
|
|
private ShoppingCartService shoppingCartService;
|
|
@Resource
|
|
@Resource
|
|
private ProductMapper productMapper;
|
|
private ProductMapper productMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private CouponMapper couponMapper;
|
|
@Value("${caimei.oldapi}")
|
|
@Value("${caimei.oldapi}")
|
|
private String domain;
|
|
private String domain;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ResponseJson<Map<String, Object>> orderConfirm(String cartIds, Integer productId, Integer productCount, Integer heUserId) {
|
|
|
|
|
|
+ public ResponseJson<Map<String, Object>> orderConfirm(Integer userId, String cartIds, Integer productId, Integer productCount, Integer heUserId) {
|
|
Map<String, Object> confirmData = new HashMap<>(5);
|
|
Map<String, Object> confirmData = new HashMap<>(5);
|
|
log.info("<<<<< 结算订单 >>>>>");
|
|
log.info("<<<<< 结算订单 >>>>>");
|
|
//商品总金额
|
|
//商品总金额
|
|
- AtomicReference<BigDecimal> totalPrice = new AtomicReference<BigDecimal>(BigDecimal.ZERO);
|
|
|
|
|
|
+ AtomicReference<BigDecimal> totalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
|
+ List<CartProductVo> totalProducts = new ArrayList<>();
|
|
List<ShopVo> shopList = new ArrayList<>();
|
|
List<ShopVo> shopList = new ArrayList<>();
|
|
if (productId != null && productId > 0) {
|
|
if (productId != null && productId > 0) {
|
|
//立即购买
|
|
//立即购买
|
|
@@ -61,25 +63,66 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
}
|
|
}
|
|
shopList.forEach(shop -> {
|
|
shopList.forEach(shop -> {
|
|
shop.setLogo(ProductUtils.getImageURL("shopLogo", shop.getLogo(), 0, domain));
|
|
shop.setLogo(ProductUtils.getImageURL("shopLogo", shop.getLogo(), 0, domain));
|
|
- List<CartProductVo> products = new ArrayList<>();
|
|
|
|
|
|
+ List<CartProductVo> shopProducts = new ArrayList<>();
|
|
if (productId != null && productId > 0) {
|
|
if (productId != null && productId > 0) {
|
|
CartProductVo cartProduct = orderSubmitMapper.findProductById(productId);
|
|
CartProductVo cartProduct = orderSubmitMapper.findProductById(productId);
|
|
cartProduct.setProductCount(productCount);
|
|
cartProduct.setProductCount(productCount);
|
|
cartProduct.setHeUserId(heUserId);
|
|
cartProduct.setHeUserId(heUserId);
|
|
- products.add(cartProduct);
|
|
|
|
|
|
+ shopProducts.add(cartProduct);
|
|
} else {
|
|
} else {
|
|
String[] cartId = cartIds.split(",");
|
|
String[] cartId = cartIds.split(",");
|
|
- products = orderSubmitMapper.findByShopCartProduct(shop.getShopId(), cartId);
|
|
|
|
|
|
+ shopProducts = orderSubmitMapper.findByShopCartProduct(shop.getShopId(), cartId);
|
|
}
|
|
}
|
|
BigDecimal shopTotalPrice = BigDecimal.ZERO;
|
|
BigDecimal shopTotalPrice = BigDecimal.ZERO;
|
|
- for (CartProductVo product : products) {
|
|
|
|
- shoppingCartService.setPrice(product);
|
|
|
|
|
|
+ for (CartProductVo product : shopProducts) {
|
|
|
|
+ shoppingCartService.setPrice(product, userId);
|
|
shopTotalPrice = MathUtil.add(shopTotalPrice, MathUtil.mul(product.getProductCount(), product.getPrice()));
|
|
shopTotalPrice = MathUtil.add(shopTotalPrice, MathUtil.mul(product.getProductCount(), product.getPrice()));
|
|
}
|
|
}
|
|
shop.setShopTotalPrice(shopTotalPrice);
|
|
shop.setShopTotalPrice(shopTotalPrice);
|
|
- shop.setProductList(products);
|
|
|
|
|
|
+ shop.setProductList(shopProducts);
|
|
|
|
+ totalProducts.addAll(shopProducts);
|
|
totalPrice.set(MathUtil.add(totalPrice.get(), shopTotalPrice));
|
|
totalPrice.set(MathUtil.add(totalPrice.get(), shopTotalPrice));
|
|
});
|
|
});
|
|
|
|
+ // 用户所有可用优惠券
|
|
|
|
+ List<CouponVo> receiveCouponList = couponMapper.findReceiveCouponList(userId, null,null, 1);
|
|
|
|
+ receiveCouponList.forEach(coupon -> {
|
|
|
|
+ // 能参与该优惠券的总金额
|
|
|
|
+ BigDecimal touchCouponAmount = BigDecimal.ZERO;
|
|
|
|
+ if (coupon.getProductType() == 1) {
|
|
|
|
+ //全商城商品
|
|
|
|
+ touchCouponAmount = totalPrice.get();
|
|
|
|
+ } else {
|
|
|
|
+ // 参与优惠券的所有商品id
|
|
|
|
+ String couponProductIds = couponMapper.getCouponProductIds(coupon.getCouponId());
|
|
|
|
+ if (productId != null && productId > 0) {
|
|
|
|
+ CartProductVo cartProduct = totalProducts.get(0);
|
|
|
|
+ if (couponProductIds.contains(cartProduct.getProductId().toString())) {
|
|
|
|
+ touchCouponAmount = totalPrice.get();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ for (CartProductVo product : totalProducts) {
|
|
|
|
+ if (couponProductIds.contains(product.getProductId().toString())) {
|
|
|
|
+ touchCouponAmount = MathUtil.add(touchCouponAmount, MathUtil.mul(product.getProductCount(), product.getPrice()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (coupon.getNoThresholdFlag() == 1 || touchCouponAmount.compareTo(coupon.getTouchPrice()) > 0) {
|
|
|
|
+ // 满足优惠条件
|
|
|
|
+ coupon.setTouchFlag(1);
|
|
|
|
+ } else {
|
|
|
|
+ coupon.setTouchFlag(0);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ receiveCouponList.sort((o1, o2) -> {
|
|
|
|
+ // 按满足优惠条件/优惠金额进行排序
|
|
|
|
+ if (!o1.getTouchFlag().equals(o2.getTouchFlag()) ) {
|
|
|
|
+ return o1.getTouchFlag() - o2.getTouchFlag();
|
|
|
|
+ } else {
|
|
|
|
+ return o1.getCouponAmount().compareTo(o2.getCouponAmount());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ confirmData.put("receiveCouponList", receiveCouponList);
|
|
confirmData.put("totalPrice", totalPrice);
|
|
confirmData.put("totalPrice", totalPrice);
|
|
confirmData.put("shopList", shopList);
|
|
confirmData.put("shopList", shopList);
|
|
return ResponseJson.success(confirmData);
|
|
return ResponseJson.success(confirmData);
|
|
@@ -87,7 +130,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public ResponseJson<Map<String, String>> orderSubmit(Integer userId, Integer cartType, Integer addressId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo) {
|
|
|
|
|
|
+ public ResponseJson<Map<String, String>> orderSubmit(Integer userId, Integer cartType, Integer addressId, Integer couponId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo) {
|
|
/*
|
|
/*
|
|
* 逻辑处理 start
|
|
* 逻辑处理 start
|
|
*/
|
|
*/
|
|
@@ -249,6 +292,25 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //处理优惠券
|
|
|
|
+ BigDecimal couponAmount = BigDecimal.ZERO;
|
|
|
|
+ CouponVo coupon = null;
|
|
|
|
+ // 已领取优惠券id
|
|
|
|
+ Integer receiveCouponId = null;
|
|
|
|
+ if (null != couponId && couponId > 0) {
|
|
|
|
+ receiveCouponId = couponMapper.findReceiveCouponId(userId, couponId);
|
|
|
|
+ List<CouponVo> receiveCouponList = couponMapper.findReceiveCouponList(userId, null, receiveCouponId, 1);
|
|
|
|
+ if (receiveCouponList == null || receiveCouponList.size() <= 0) {
|
|
|
|
+ // 设置手动回滚事务
|
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
|
+ return ResponseJson.error("优惠券使用异常", null);
|
|
|
|
+ } else {
|
|
|
|
+ coupon = receiveCouponList.get(0);
|
|
|
|
+ }
|
|
|
|
+ couponAmount = coupon.getCouponAmount();
|
|
|
|
+ }
|
|
|
|
+ order.setCouponAmount(couponAmount);
|
|
|
|
+
|
|
// 设置是否是二手订单
|
|
// 设置是否是二手订单
|
|
order.setSecondHandOrderFlag("0");
|
|
order.setSecondHandOrderFlag("0");
|
|
order.setPromotionFullReduction(BigDecimal.ZERO);
|
|
order.setPromotionFullReduction(BigDecimal.ZERO);
|
|
@@ -267,6 +329,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
payTotalFee = productTotalFee;
|
|
payTotalFee = productTotalFee;
|
|
orderTotalFee = productTotalFee;
|
|
orderTotalFee = productTotalFee;
|
|
order.setOrderTotalFee(orderTotalFee);
|
|
order.setOrderTotalFee(orderTotalFee);
|
|
|
|
+ payTotalFee = MathUtil.sub(payTotalFee, couponAmount);
|
|
order.setPayTotalFee(payTotalFee);
|
|
order.setPayTotalFee(payTotalFee);
|
|
payableAmount = payTotalFee;
|
|
payableAmount = payTotalFee;
|
|
// 订单状态
|
|
// 订单状态
|
|
@@ -394,6 +457,32 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
return ResponseJson.error("订单地址异常", null);
|
|
return ResponseJson.error("订单地址异常", null);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * 保存优惠券使用情况
|
|
|
|
+ */
|
|
|
|
+ if (null != receiveCouponId && receiveCouponId > 0) {
|
|
|
|
+ // 修改优惠券使用情况
|
|
|
|
+ orderSubmitMapper.updateReceiveCouponStatus(receiveCouponId, order.getOrderID());
|
|
|
|
+ CouponOrderRecordPo orderRecord = new CouponOrderRecordPo();
|
|
|
|
+ orderRecord.setOrderId(order.getOrderID().intValue());
|
|
|
|
+ orderRecord.setReceiveCouponId(receiveCouponId);
|
|
|
|
+ orderRecord.setCouponType(coupon.getCouponType());
|
|
|
|
+ orderRecord.setCouponAmount(coupon.getCouponAmount().doubleValue());
|
|
|
|
+ orderRecord.setTouchPrice(1 == coupon.getNoThresholdFlag() ? 0 : coupon.getTouchPrice().doubleValue());
|
|
|
|
+ orderRecord.setCreateDate(new Date());
|
|
|
|
+ //保存订单优惠记录
|
|
|
|
+ orderSubmitMapper.insertCouponOrderRecord(orderRecord);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * 保存好友消费券赠送记录
|
|
|
|
+ */
|
|
|
|
+ Integer couponShareId = couponMapper.getCouponShareId(userId);
|
|
|
|
+ if (null != couponShareId) {
|
|
|
|
+ String consumeCouponIds = couponMapper.getCurrentCouponIds(5);
|
|
|
|
+ couponMapper.updateCouponShareRecord(couponShareId, consumeCouponIds);
|
|
|
|
+ }
|
|
|
|
+
|
|
log.info("******************** 提交订单逻辑处理 end *******************");
|
|
log.info("******************** 提交订单逻辑处理 end *******************");
|
|
/*
|
|
/*
|
|
* 构造返回参数
|
|
* 构造返回参数
|