|
@@ -13,7 +13,6 @@ import com.caimei.util.OrderNoUtils;
|
|
|
import com.caimei.util.ProductUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -124,6 +123,15 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
return o1.getCouponAmount().compareTo(o2.getCouponAmount());
|
|
|
}
|
|
|
});
|
|
|
+ // 可参与的分享减免活动
|
|
|
+ ReductionVo currentReduction = orderSubmitMapper.findCurrentReduction();
|
|
|
+ if (null != currentReduction) {
|
|
|
+ // 查询分享次数
|
|
|
+ Integer shareNum = orderSubmitMapper.findShareNum(userId, currentReduction.getReductionId());
|
|
|
+ if (shareNum < currentReduction.getShareNum()) {
|
|
|
+ confirmData.put("reduction", currentReduction);
|
|
|
+ }
|
|
|
+ }
|
|
|
confirmData.put("receiveCouponList", receiveCouponList);
|
|
|
confirmData.put("totalPrice", totalPrice);
|
|
|
confirmData.put("shopList", shopList);
|
|
@@ -132,7 +140,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public ResponseJson<Map<String, String>> orderSubmit(Integer userId, Integer cartType, Integer addressId, Integer couponId, Integer couponShareId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo) {
|
|
|
+ public ResponseJson<Map<String, String>> orderSubmit(Integer userId, Integer cartType, Integer addressId, Map<String, Object> discountInfo, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo) {
|
|
|
/*
|
|
|
* 逻辑处理 start
|
|
|
*/
|
|
@@ -197,6 +205,8 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
* 订单商品
|
|
|
*/
|
|
|
List<CmOrderProductPo> orderProductList = new ArrayList<>();
|
|
|
+ Integer collageFlag = (Integer) discountInfo.get("collageFlag");
|
|
|
+ Integer collageId = (Integer) discountInfo.get("collageId");
|
|
|
for (Map<String, Object> shopOrderInfo : orderInfo) {
|
|
|
Integer shopId = (Integer) shopOrderInfo.get("shopId");
|
|
|
if (null == shopId) {
|
|
@@ -249,6 +259,13 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (collageFlag != null && 1 == collageFlag) {
|
|
|
+ // 拼团价
|
|
|
+ CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(productId);
|
|
|
+ if (collageProduct != null) {
|
|
|
+ productPrice = collageProduct.getPrice();
|
|
|
+ }
|
|
|
+ }
|
|
|
Integer discount = productMapper.findProductDiscount(product.getProductId(), userId);
|
|
|
if (null != discount && discount > 0) {
|
|
|
productPrice = MathUtil.div(MathUtil.mul(productPrice, discount), 100);
|
|
@@ -300,6 +317,8 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
CouponVo coupon = null;
|
|
|
// 已领取优惠券id
|
|
|
Integer receiveCouponId = null;
|
|
|
+ Integer couponId = (Integer) discountInfo.get("couponId");
|
|
|
+ Integer couponShareId = (Integer) discountInfo.get("couponShareId");
|
|
|
if (null != couponId && couponId > 0) {
|
|
|
receiveCouponId = couponMapper.findReceiveCouponId(userId, couponId, couponShareId);
|
|
|
List<CouponVo> receiveCouponList = couponMapper.findReceiveCouponList(userId, null, receiveCouponId, 1);
|
|
@@ -313,6 +332,21 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
couponAmount = coupon.getCouponAmount();
|
|
|
}
|
|
|
order.setCouponAmount(couponAmount);
|
|
|
+ // 处理分享减免
|
|
|
+ BigDecimal reductionAmount = BigDecimal.ZERO;
|
|
|
+ Integer reductionUserId = (Integer) discountInfo.get("reductionUserId");
|
|
|
+ if (null != reductionUserId) {
|
|
|
+ // 分享减免活动
|
|
|
+ ReductionVo reductionVo = orderSubmitMapper.findReduction(reductionUserId);
|
|
|
+ if (null != reductionVo) {
|
|
|
+ reductionAmount = reductionVo.getReducedAmount();
|
|
|
+ } else {
|
|
|
+ // 设置手动回滚事务
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return ResponseJson.error("分享减免异常", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.setReductionAmount(reductionAmount);
|
|
|
|
|
|
// 设置是否是二手订单
|
|
|
order.setSecondHandOrderFlag("0");
|
|
@@ -332,7 +366,10 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
payTotalFee = productTotalFee;
|
|
|
orderTotalFee = productTotalFee;
|
|
|
order.setOrderTotalFee(orderTotalFee);
|
|
|
+ // 优惠券抵扣
|
|
|
payTotalFee = MathUtil.sub(payTotalFee, couponAmount);
|
|
|
+ // 分享减免
|
|
|
+ payTotalFee = MathUtil.sub(payTotalFee, reductionAmount);
|
|
|
// 订单状态
|
|
|
order.setStatus("11");
|
|
|
if (MathUtil.compare(payTotalFee, 0) < 0 && MathUtil.compare(productTotalFee, 0) >= 0 && MathUtil.compare(couponAmount, 0) > 0) {
|
|
@@ -484,6 +521,61 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
orderSubmitMapper.insertCouponOrderRecord(orderRecord);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存拼团成员记录
|
|
|
+ */
|
|
|
+ if (collageFlag != null && collageFlag == 1) {
|
|
|
+ if (orderProductList.size() > 1) {
|
|
|
+ //设置手动回滚事务
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return ResponseJson.error("拼团订单商品数量异常", null);
|
|
|
+ }
|
|
|
+ // 构建拼团成员
|
|
|
+ CmHeheCollageMemberPo collageMember = new CmHeheCollageMemberPo();
|
|
|
+ collageMember.setUserId(userId);
|
|
|
+ collageMember.setOrderId(order.getOrderID());
|
|
|
+ if (collageId == null) {
|
|
|
+ // 拼团发起者,构建拼团记录
|
|
|
+ CmHeheCollagePo collage = new CmHeheCollagePo();
|
|
|
+ CmOrderProductPo orderProductPo = orderProductList.get(0);
|
|
|
+ CmHeheCollageProductPo collageProduct = orderSubmitMapper.findCollageProduct(orderProductPo.getProductID());
|
|
|
+ collage.setProductId(collageProduct.getProductId());
|
|
|
+ collage.setMemberNum(collageProduct.getMemberNum());
|
|
|
+ collage.setPrice(collageProduct.getPrice());
|
|
|
+ collage.setStatus(1);
|
|
|
+ Date startTime = new Date();
|
|
|
+ collage.setStartTime(startTime);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(startTime);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ collage.setEndTime(calendar.getTime());
|
|
|
+ orderSubmitMapper.insertCollage(collage);
|
|
|
+ collageId = collage.getId();
|
|
|
+ collageMember.setLaunchFlag(1);
|
|
|
+ } else {
|
|
|
+ // 已拼人数
|
|
|
+ Integer memberNum = orderSubmitMapper.findCollageMemberNum(collageId);
|
|
|
+ CmHeheCollagePo collage = orderSubmitMapper.findCollage(collageId);
|
|
|
+ if (collage != null && 2 != collage.getStatus() && memberNum < collage.getMemberNum()) {
|
|
|
+ // 参加拼团
|
|
|
+ collageMember.setLaunchFlag(0);
|
|
|
+ } else {
|
|
|
+ //设置手动回滚事务
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return ResponseJson.error("参与拼团异常", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ collageMember.setCollageId(collageId);
|
|
|
+ orderSubmitMapper.insertCollageMember(collageMember);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存分享减免订单抵扣记录
|
|
|
+ */
|
|
|
+ if (null != reductionUserId) {
|
|
|
+ orderSubmitMapper.updateReductionUserId(reductionUserId, order.getOrderID());
|
|
|
+ }
|
|
|
+
|
|
|
log.info("******************** 提交订单逻辑处理 end *******************");
|
|
|
/*
|
|
|
* 构造返回参数
|
|
@@ -499,6 +591,27 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
|
return ResponseJson.success(info);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Integer> shareReduction(Integer userId, Integer reductionId, Integer shareType) {
|
|
|
+ if (null == userId || null == reductionId || null == shareType) {
|
|
|
+ return ResponseJson.error("参数异常", null);
|
|
|
+ }
|
|
|
+ // 可参与的分享减免活动
|
|
|
+ ReductionVo currentReduction = orderSubmitMapper.findCurrentReduction();
|
|
|
+ if (null != currentReduction) {
|
|
|
+ // 查询分享次数
|
|
|
+ Integer shareNum = orderSubmitMapper.findShareNum(userId, currentReduction.getReductionId());
|
|
|
+ if (shareNum <= currentReduction.getShareNum()) {
|
|
|
+ Integer reductionUserId = orderSubmitMapper.insertReductionUser(userId, reductionId, shareType);
|
|
|
+ return ResponseJson.success("分享成功", reductionUserId);
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("分享次数超限", null);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ResponseJson.error("分享减免活动不存在", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 整理订单商品数据
|
|
|
*
|