|
@@ -26,6 +26,7 @@ import com.yonge.cooleshow.portal.dao.PortalOrderDao;
|
|
|
import com.yonge.cooleshow.portal.dao.PortalOrderItemDao;
|
|
|
import com.yonge.cooleshow.portal.dao.PortalProductDao;
|
|
|
import com.yonge.cooleshow.portal.domain.*;
|
|
|
+import com.yonge.cooleshow.portal.dto.StockOperateModel;
|
|
|
import com.yonge.cooleshow.portal.service.*;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
@@ -131,6 +132,8 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> generateOrder(OrderParam orderParam) {
|
|
|
+
|
|
|
+ LOG.info("订单生成请求参数:{}",orderParam);
|
|
|
OmsOrder order = new OmsOrder();
|
|
|
String orderSn = generateOrderSn();
|
|
|
if (!StringUtil.isEmpty(orderParam.getOrderNo())) {
|
|
@@ -149,10 +152,12 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
userOrderPayment.setStatus(TradeStatusEnum.pending.getCode());
|
|
|
userOrderPayment.setAdapayNo(orderSn);
|
|
|
userOrderPayment.setId(null);
|
|
|
+ userOrderPayment.setCreateTime(new Date());
|
|
|
userOrderPaymentService.saveOrUpdate(userOrderPayment);
|
|
|
|
|
|
- return feignMecCreateOrder(order.getCouponId(), oldOrderNo, orderSn, null, detail.getMemberId().intValue(), detail.getTotalAmount(),
|
|
|
- JSON.toJSONString(detail));
|
|
|
+ return feignMecCreateOrder(detail.getCouponId(), oldOrderNo, orderSn, orderParam.getTeacherId() == null?null:orderParam.getTeacherId().intValue()
|
|
|
+ , detail.getMemberId().intValue(), detail.getTotalAmount(),
|
|
|
+ JSON.toJSONString(detail),detail.getPayType()!= null && detail.getPayType() == 3);
|
|
|
} else {
|
|
|
throw new BizException("订单信息获取失败");
|
|
|
}
|
|
@@ -196,17 +201,19 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
orderItem.setGiftGrowth(cartPromotionItem.getGrowth());
|
|
|
orderItem.setPromoterId(cartPromotionItem.getPromoterId());
|
|
|
orderItem.setPrecisionAmount(BigDecimal.ZERO);
|
|
|
+ orderItem.setIntegrationAmount(new BigDecimal(0));
|
|
|
orderItemList.add(orderItem);
|
|
|
}
|
|
|
//判断购物车中商品是否都有库存
|
|
|
if (!hasStock(cartPromotionItemList)) {
|
|
|
Asserts.fail("库存不足,无法下单");
|
|
|
}
|
|
|
-
|
|
|
+ BigDecimal couponAmount = BigDecimal.ZERO;
|
|
|
BigDecimal amount = calcTotalAmount(orderItemList);
|
|
|
- Map data = feignMecCouponAmount(orderParam.getCouponId(), orderParam.getOrderAmount());
|
|
|
-
|
|
|
- BigDecimal couponAmount = MapUtil.get(data, "mallCouponAmount", BigDecimal.class);
|
|
|
+ if (!StringUtil.isEmpty(orderParam.getCouponId())) {
|
|
|
+ Map data = feignMecCouponAmount(orderParam.getCouponId(), amount);
|
|
|
+ couponAmount = new BigDecimal(MapUtil.get(data, "mallCouponAmount", String.class));
|
|
|
+ }
|
|
|
if (couponAmount == null) {
|
|
|
couponAmount = BigDecimal.ZERO;
|
|
|
}
|
|
@@ -230,34 +237,50 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
// if(data != null) {
|
|
|
// couponAmount = data.getDiscountedPrices();
|
|
|
// }
|
|
|
- if (couponAmount.compareTo(orderParam.getOrderAmount()) > 0) {
|
|
|
- couponAmount = orderParam.getOrderAmount();
|
|
|
+ if (couponAmount.compareTo(amount) > 0) {
|
|
|
+ couponAmount = amount;
|
|
|
}
|
|
|
handleCouponAmount(orderItemList, couponAmount);
|
|
|
}
|
|
|
+ BigDecimal balanceAmount = BigDecimal.ZERO;
|
|
|
//判断是否使用积分
|
|
|
- if (orderParam.getUseIntegration() == null || orderParam.getUseIntegration().equals(0)) {
|
|
|
- //不使用积分
|
|
|
- for (OmsOrderItem orderItem : orderItemList) {
|
|
|
- orderItem.setIntegrationAmount(new BigDecimal(0));
|
|
|
- }
|
|
|
- } else {
|
|
|
- //使用积分
|
|
|
- BigDecimal totalAmount = calcTotalAmount(orderItemList);
|
|
|
- BigDecimal integrationAmount = getUseIntegrationAmount(orderParam.getUseIntegration(), totalAmount,
|
|
|
- currentMember, orderParam.getCouponId() != null);
|
|
|
- if (integrationAmount.compareTo(new BigDecimal(0)) == 0) {
|
|
|
- Asserts.fail("积分不可用");
|
|
|
- } else {
|
|
|
- //可用情况下分摊到可用商品中
|
|
|
- for (OmsOrderItem orderItem : orderItemList) {
|
|
|
- BigDecimal perAmount = orderItem.getProductPrice()
|
|
|
- .divide(totalAmount, 3, RoundingMode.HALF_EVEN)
|
|
|
- .multiply(integrationAmount);
|
|
|
- orderItem.setIntegrationAmount(perAmount);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // if (orderParam.isUseBalance()) {
|
|
|
+ //
|
|
|
+ // // 查询余额
|
|
|
+ // HttpResponseResult<BigDecimal> balance = webFeignService.balance(orderParam.getUserId());
|
|
|
+ // if(balance.getStatus()) {
|
|
|
+ // balanceAmount = balance.getData();
|
|
|
+ // } else {
|
|
|
+ // LOG.error("余额查询失败:{}",balance.getMsg());
|
|
|
+ // }
|
|
|
+ // if(balanceAmount.compareTo(orderParam.getOrderAmount()) >0) {
|
|
|
+ // balanceAmount = orderParam.getOrderAmount();
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //不使用积分
|
|
|
+ // for (OmsOrderItem orderItem : orderItemList) {
|
|
|
+ // orderItem.setIntegrationAmount(new BigDecimal(0));
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // for (OmsOrderItem orderItem : orderItemList) {
|
|
|
+ // orderItem.setIntegrationAmount(new BigDecimal(0));
|
|
|
+ // }
|
|
|
+ // //使用积分
|
|
|
+ // // BigDecimal totalAmount = calcTotalAmount(orderItemList);
|
|
|
+ // // BigDecimal integrationAmount = getUseIntegrationAmount(orderParam.getUseIntegration(), totalAmount,
|
|
|
+ // // currentMember, orderParam.getCouponId() != null);
|
|
|
+ // // if (integrationAmount.compareTo(new BigDecimal(0)) == 0) {
|
|
|
+ // // Asserts.fail("积分不可用");
|
|
|
+ // // } else {
|
|
|
+ // // //可用情况下分摊到可用商品中
|
|
|
+ // // for (OmsOrderItem orderItem : orderItemList) {
|
|
|
+ // // BigDecimal perAmount = orderItem.getProductPrice()
|
|
|
+ // // .divide(totalAmount, 3, RoundingMode.HALF_EVEN)
|
|
|
+ // // .multiply(integrationAmount);
|
|
|
+ // // orderItem.setIntegrationAmount(perAmount);
|
|
|
+ // // }
|
|
|
+ // // }
|
|
|
+ // }
|
|
|
//计算order_item的实付金额
|
|
|
handleRealAmount(orderItemList);
|
|
|
//进行sku库存锁定
|
|
@@ -267,38 +290,42 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
lockProductStock(cartPromotionItemList);
|
|
|
|
|
|
//根据商品合计、运费、活动优惠、优惠券、积分计算应付金额
|
|
|
- String cartIds = orderParam.getCartIds().stream().map(String::valueOf).collect(Collectors.joining());
|
|
|
+ String cartIds = orderParam.getCartIds().stream().map(String::valueOf).collect(Collectors.joining(","));
|
|
|
order.setCartIds(cartIds);
|
|
|
order.setDiscountAmount(new BigDecimal(0));
|
|
|
order.setTotalAmount(amount);
|
|
|
order.setFreightAmount(new BigDecimal(0));
|
|
|
order.setPromotionAmount(calcPromotionAmount(orderItemList));
|
|
|
order.setPromotionInfo(getOrderPromotionInfo(orderItemList));
|
|
|
- order.setPlatformType(orderParam.getPlatformType() == null?"STUDENT":orderParam.getPlatformType());
|
|
|
+ order.setPlatformType(StringUtil.isEmpty(orderParam.getPlatformType())?"STUDENT":orderParam.getPlatformType());
|
|
|
if (StringUtil.isEmpty(orderParam.getCouponId())) {
|
|
|
order.setCouponAmount(new BigDecimal(0));
|
|
|
} else {
|
|
|
order.setCouponId(orderParam.getCouponId());
|
|
|
order.setCouponAmount(couponAmount);
|
|
|
}
|
|
|
- if (orderParam.getUseIntegration() == null) {
|
|
|
+ if (!orderParam.isUseBalance()) {
|
|
|
order.setIntegration(0);
|
|
|
order.setIntegrationAmount(new BigDecimal(0));
|
|
|
} else {
|
|
|
- order.setIntegration(orderParam.getUseIntegration());
|
|
|
- order.setIntegrationAmount(calcIntegrationAmount(orderItemList));
|
|
|
+ order.setIntegration(0);
|
|
|
+ order.setIntegrationAmount(balanceAmount);
|
|
|
}
|
|
|
LOG.info("payAmount:{},totalAmount:{},couponAmount:{}",order.getTotalAmount().subtract(couponAmount),order.getTotalAmount(),couponAmount);
|
|
|
if (orderParam.getOrderAmount().compareTo(order.getTotalAmount().subtract(couponAmount)) != 0) {
|
|
|
throw new BizException("订单金额校验不通过");
|
|
|
}
|
|
|
- order.setPayAmount(orderParam.getOrderAmount());
|
|
|
+ order.setPayAmount(orderParam.getOrderAmount().subtract(balanceAmount));
|
|
|
//转化为订单信息并插入数据库
|
|
|
order.setMemberId(currentMember.getId());
|
|
|
order.setCreateTime(new Date());
|
|
|
order.setMemberUsername(currentMember.getUsername());
|
|
|
- //支付方式:0->未支付;1->支付宝;2->微信
|
|
|
- order.setPayType(orderParam.getPayType());
|
|
|
+ //支付方式:0->未支付;1->支付宝;2->微信 3:余额
|
|
|
+ if (orderParam.isUseBalance()) {
|
|
|
+ order.setPayType(3);
|
|
|
+ } else {
|
|
|
+ order.setPayType(orderParam.getPayType());
|
|
|
+ }
|
|
|
//订单来源:0->PC订单;1->app订单
|
|
|
order.setSourceType(1);
|
|
|
//订单状态:0->待付款;1->待发货;2->已发货;3->已完成;4->已关闭;5->无效订单 6 -> 未支付
|
|
@@ -363,6 +390,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
userOrderPayment.setOrderNo(order.getOrderSn());
|
|
|
userOrderPayment.setAdapayNo(order.getOrderSn());
|
|
|
userOrderPayment.setStatus(TradeStatusEnum.pending.getCode());
|
|
|
+ userOrderPayment.setCreateTime(new Date());
|
|
|
|
|
|
if (order.getPayAmount().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
paySuccess(order.getId(),order.getPayType());
|
|
@@ -370,19 +398,44 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
result.put("orderType","success");
|
|
|
userOrderPayment.setStatus(TradeStatusEnum.succeeded.getCode());
|
|
|
}
|
|
|
- userOrderPaymentService.save(userOrderPayment);
|
|
|
+ userOrderPaymentService.saveOrUpdate(userOrderPayment);
|
|
|
|
|
|
// 生成订单
|
|
|
// 保存商品信息到管乐迷
|
|
|
OmsOrderDetail detail = detail(order.getOrderSn());
|
|
|
- data = feignMecCreateOrder(orderParam.getCouponId(),orderParam.getOrderNo(), orderSn,
|
|
|
+ Map data = feignMecCreateOrder(orderParam.getCouponId(),orderParam.getOrderNo(), orderSn,
|
|
|
orderParam.getTeacherId()==null?null:orderParam.getTeacherId().intValue(),
|
|
|
- currentMember.getId().intValue(), amount,JSON.toJSONString(detail));
|
|
|
+ currentMember.getId().intValue(), amount,JSON.toJSONString(detail),orderParam.isUseBalance());
|
|
|
+ if ("1".equals(MapUtil.getStr(data, "tradeState"))) {
|
|
|
+ paySuccess(order.getId(),order.getPayType());
|
|
|
+ order.setStatus(1);
|
|
|
+ result.put("orderType","success");
|
|
|
+ userOrderPayment.setStatus(TradeStatusEnum.succeeded.getCode());
|
|
|
+ userOrderPaymentService.saveOrUpdate(userOrderPayment);
|
|
|
+ }
|
|
|
+ // 记录余额支付金额
|
|
|
+ String balanceAmount1 = MapUtil.get(data, "balanceAmount", String.class);
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(balanceAmount1);
|
|
|
+ if (BigDecimal.ZERO.compareTo(bigDecimal) !=0 ) {
|
|
|
+ order.setIntegrationAmount(bigDecimal);
|
|
|
+ order.setPayAmount(order.getPayAmount().subtract(bigDecimal));
|
|
|
+ orderMapper.updateByPrimaryKeySelective(order);
|
|
|
+
|
|
|
+ updateOrderDetail(order, userOrderPayment);
|
|
|
+ }
|
|
|
result.put("pay",data);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private void updateOrderDetail(OmsOrder order, UserOrderPayment userOrderPayment) {
|
|
|
+ OmsOrderDetail detail = detail(order.getOrderSn());
|
|
|
+ MallCreateOrderModel model = new MallCreateOrderModel();
|
|
|
+ model.setOrderNo(userOrderPayment.getAdapayNo());
|
|
|
+ model.setOrderInfo(JSON.toJSONString(detail));
|
|
|
+ webFeignService.mallSaveOrderInfo(model);
|
|
|
+ }
|
|
|
+
|
|
|
private Map feignMecCouponAmount(String couponId,BigDecimal amount) {
|
|
|
|
|
|
MallCreateOrderModel model = new MallCreateOrderModel();
|
|
@@ -390,25 +443,27 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
model.setAmount(amount);
|
|
|
HttpResponseResult<Map> mapHttpResponseResult = webFeignService.couponAmount(model);
|
|
|
if (!mapHttpResponseResult.getStatus()) {
|
|
|
- throw new BizException("管乐迷获取优惠券优惠失败");
|
|
|
+ LOG.error("管乐迷获取优惠券优惠失败:{}",mapHttpResponseResult.getMsg());
|
|
|
+ throw new BizException(mapHttpResponseResult.getMsg());
|
|
|
}
|
|
|
return mapHttpResponseResult.getData();
|
|
|
}
|
|
|
|
|
|
- private Map feignMecCreateOrder(String couponId, String oldOrderNo, String orderSn, Integer teacherId, Integer userId, BigDecimal amount, String orderDetail) {
|
|
|
+ private Map feignMecCreateOrder(String couponId, String oldOrderNo, String orderSn, Integer teacherId, Integer userId,
|
|
|
+ BigDecimal amount, String orderDetail,boolean useBalance) {
|
|
|
// 远程调用管乐迷订单记录
|
|
|
MallCreateOrderModel model = new MallCreateOrderModel();
|
|
|
+ model.setTeacherId(teacherId);
|
|
|
model.setAmount(amount);
|
|
|
model.setOrderNo(orderSn);
|
|
|
- if (!userId.equals(teacherId)) {
|
|
|
- model.setTeacherId(teacherId);
|
|
|
- }
|
|
|
+ model.setUseBalance(useBalance);
|
|
|
model.setUserId(userId);
|
|
|
model.setCouponIdList(StringUtil.toIntegerList(couponId));
|
|
|
model.setOldOrderNo(oldOrderNo);
|
|
|
model.setOrderInfo(orderDetail);
|
|
|
HttpResponseResult<Map> mapHttpResponseResult = webFeignService.mallCreateOrder(model);
|
|
|
if (!mapHttpResponseResult.getStatus()) {
|
|
|
+ LOG.error("管乐迷下单错误信息:{}",mapHttpResponseResult.getMsg());
|
|
|
throw new BizException("管乐迷订单生成失败");
|
|
|
}
|
|
|
Map data = mapHttpResponseResult.getData();
|
|
@@ -513,7 +568,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
UserOrderPayment userOrderPayment = userOrderPaymentService.getByOrderNoAndStatusPaying(
|
|
|
cancelOrder.getOrderSn());
|
|
|
if (userOrderPayment != null) {
|
|
|
- HttpResponseResult<OrderCancelModel> responseResult = webFeignService.cancelOrder(userOrderPayment.getAdapayNo());
|
|
|
+ HttpResponseResult<OrderCancelModel> responseResult = webFeignService.cancelOrder(userOrderPayment.getAdapayNo(),message);
|
|
|
if (!responseResult.getStatus()) {
|
|
|
throw new BizException("远程取消失败");
|
|
|
}
|
|
@@ -534,10 +589,27 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
OmsOrderItemExample orderItemExample = new OmsOrderItemExample();
|
|
|
orderItemExample.createCriteria().andOrderIdEqualTo(orderId);
|
|
|
List<OmsOrderItem> orderItemList = orderItemMapper.selectByExample(orderItemExample);
|
|
|
+
|
|
|
//解除订单商品库存锁定
|
|
|
if (!CollectionUtils.isEmpty(orderItemList)) {
|
|
|
portalOrderDao.releaseSkuStockLock(orderItemList);
|
|
|
- portalOrderDao.releaseProductStockLock(orderItemList);
|
|
|
+ Map<Long, List<OmsOrderItem>> collect = orderItemList
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.groupingBy(OmsOrderItem::getProductId));
|
|
|
+ List<ProductStock> productStockList = new ArrayList<>();
|
|
|
+ for (Map.Entry<Long, List<OmsOrderItem>> entry : collect.entrySet()) {
|
|
|
+ ProductStock stock = new ProductStock();
|
|
|
+ stock.setProductId(entry.getKey());
|
|
|
+ List<OmsOrderItem> value = entry.getValue();
|
|
|
+ if (CollectionUtils.isEmpty(value)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int sum = value.stream().mapToInt(OmsOrderItem::getProductQuantity).sum();
|
|
|
+ stock.setStock(sum);
|
|
|
+ productStockList.add(stock);
|
|
|
+ }
|
|
|
+
|
|
|
+ portalOrderDao.releaseProductStockLock(productStockList);
|
|
|
}
|
|
|
//修改优惠券使用状态
|
|
|
// updateCouponStatus(cancelOrder.getCouponId(), cancelOrder.getMemberId(), 0);
|
|
@@ -569,7 +641,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void confirmReceiveOrder(Long orderId) {
|
|
|
+ public void confirmReceiveOrder(Long orderId, boolean auto) {
|
|
|
// UmsMember member = memberService.getCurrentMember();
|
|
|
OmsOrder order = orderMapper.selectByPrimaryKey(orderId);
|
|
|
// if (!member.getId().equals(order.getMemberId())) {
|
|
@@ -585,6 +657,20 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
order.setReceiveTime(new Date());
|
|
|
orderMapper.updateByPrimaryKey(order);
|
|
|
|
|
|
+
|
|
|
+ // 管乐迷状态同步更新为手动确认收货
|
|
|
+ mecReceive(order.getOrderSn(),auto);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 管乐迷状态同步更新为手、自动确认收货
|
|
|
+ private void mecReceive(String orderSn, boolean auto) {
|
|
|
+ UserOrderPayment userOrderPayment = userOrderPaymentService.getByOrderNoAndStatusSuccess(orderSn);
|
|
|
+ HttpResponseResult receive = webFeignService.receive(userOrderPayment.getAdapayNo(), auto);
|
|
|
+ if (!receive.getStatus()) {
|
|
|
+ LOG.error("管乐迷状态同步更新为手、自动确认收货失败:{}",receive.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -709,7 +795,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
.runIfLockCanGet(OrderCacheEnum.LOCK_ORDER_NO_MALL.getRedisKey(omsOrder.getOrderSn())
|
|
|
, () -> {
|
|
|
try {
|
|
|
- this.confirmReceiveOrder(omsOrder.getId());
|
|
|
+ this.confirmReceiveOrder(omsOrder.getId(), true);
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
LOG.warn("订单收货,{}",e.fillInStackTrace());
|