|
@@ -3,6 +3,7 @@ package com.yonge.cooleshow.portal.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.common.entity.MallCreateOrderModel;
|
|
@@ -12,6 +13,7 @@ import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.web.WebFeignService;
|
|
|
import com.yonge.cooleshow.mall.common.api.CommonPage;
|
|
|
import com.yonge.cooleshow.mall.common.enums.OrderCacheEnum;
|
|
|
+import com.yonge.cooleshow.mall.common.enums.TradeStatusEnum;
|
|
|
import com.yonge.cooleshow.mall.common.exception.Asserts;
|
|
|
import com.yonge.cooleshow.mall.common.service.RedisService;
|
|
|
import com.yonge.cooleshow.mall.common.util.DistributedLock;
|
|
@@ -90,6 +92,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
@Autowired
|
|
|
private RedissonClient redissonClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserOrderPaymentService userOrderPaymentService;
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
private PortalProductDao productDao;
|
|
@@ -127,22 +132,21 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
// 订单号不为空 先删除订单 在重新创建订单
|
|
|
OmsOrderDetail detail = detail(orderParam.getOrderNo());
|
|
|
if (detail != null && detail.getStatus() == 0) {
|
|
|
- detail.setStatus(4);
|
|
|
- orderMapper.updateByPrimaryKeySelective(detail);
|
|
|
- // 另外生成一个订单
|
|
|
- detail.setId(null);
|
|
|
- detail.setStatus(0);
|
|
|
- detail.setOrderSn(orderSn);
|
|
|
- List<OmsOrderItem> orderItemList = detail.getOrderItemList();
|
|
|
- orderMapper.insert(detail);
|
|
|
- for (OmsOrderItem omsOrderItem : orderItemList) {
|
|
|
- omsOrderItem.setId(null);
|
|
|
- omsOrderItem.setOrderSn(detail.getOrderSn());
|
|
|
- omsOrderItem.setOrderId(detail.getId());
|
|
|
- }
|
|
|
- orderItemDao.insertList(orderItemList);
|
|
|
+ // 取消原有的订单支付
|
|
|
+ UserOrderPayment userOrderPayment = userOrderPaymentService.getByOrderNoAndStatusPaying(
|
|
|
+ orderParam.getOrderNo());
|
|
|
+ userOrderPayment.setStatus(TradeStatusEnum.close.getCode());
|
|
|
|
|
|
- return feignMecCreateOrder(order.getCouponId(),orderParam.getOrderNo(), orderSn, detail.getMemberId(), detail.getTotalAmount());
|
|
|
+ String oldORderNo = userOrderPayment.getAdapayNo();
|
|
|
+ userOrderPaymentService.saveOrUpdate(userOrderPayment);
|
|
|
+
|
|
|
+ // 增加一个支付中的记录
|
|
|
+ userOrderPayment.setStatus(TradeStatusEnum.pending.getCode());
|
|
|
+ userOrderPayment.setAdapayNo(orderSn);
|
|
|
+ userOrderPayment.setId(null);
|
|
|
+ userOrderPaymentService.saveOrUpdate(userOrderPayment);
|
|
|
+
|
|
|
+ return feignMecCreateOrder(order.getCouponId(), oldORderNo, orderSn, null, detail.getMemberId().intValue(), detail.getTotalAmount());
|
|
|
} else {
|
|
|
throw new BizException("订单信息获取失败");
|
|
|
}
|
|
@@ -154,9 +158,11 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
}
|
|
|
List<OmsOrderItem> orderItemList = new ArrayList<>();
|
|
|
//获取购物车及优惠信息
|
|
|
- UmsMember currentMember = memberService.getCurrentMember();
|
|
|
+ UmsMember currentMember;
|
|
|
if (orderParam.getUserId() != null && orderParam.getUserId() > 0) {
|
|
|
currentMember = memberService.getById(orderParam.getUserId());
|
|
|
+ } else {
|
|
|
+ currentMember = memberService.getCurrentMember();
|
|
|
}
|
|
|
|
|
|
List<CartPromotionItem> cartPromotionItemList = cartItemService.listPromotion(currentMember.getId(),
|
|
@@ -190,7 +196,8 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
|
|
|
BigDecimal amount = calcTotalAmount(orderItemList);
|
|
|
|
|
|
- Map data = feignMecCreateOrder(orderParam.getCouponId(),orderParam.getOrderNo(), orderSn, currentMember.getId(), amount);
|
|
|
+ Map data = feignMecCreateOrder(orderParam.getCouponId(),orderParam.getOrderNo(), orderSn,
|
|
|
+ orderParam.getTeacherId()==null?null:orderParam.getTeacherId().intValue(), currentMember.getId().intValue(), amount);
|
|
|
|
|
|
BigDecimal couponAmount = MapUtil.get(data, "mallCouponAmount", BigDecimal.class);
|
|
|
if (couponAmount == null) {
|
|
@@ -340,20 +347,48 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("order", order);
|
|
|
result.put("orderItemList", orderItemList);
|
|
|
+ result.put("orderType","paying");
|
|
|
+
|
|
|
+ // 创建订单时,创建一条用户支付订单信息 金额信息不做处理
|
|
|
+ UserOrderPayment userOrderPayment = new UserOrderPayment();
|
|
|
+ userOrderPayment.setOpenType("ADAPAY");
|
|
|
+ userOrderPayment.setPaymentClient(orderParam.getPlatformType());
|
|
|
+ userOrderPayment.setOrderNo(order.getOrderSn());
|
|
|
+ userOrderPayment.setAdapayNo(order.getOrderSn());
|
|
|
+ userOrderPayment.setStatus(TradeStatusEnum.pending.getCode());
|
|
|
+
|
|
|
if (order.getPayAmount().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
paySuccess(order.getId(),order.getPayType());
|
|
|
order.setStatus(1);
|
|
|
+ result.put("orderType","success");
|
|
|
+ userOrderPayment.setStatus(TradeStatusEnum.succeeded.getCode());
|
|
|
}
|
|
|
+ userOrderPaymentService.save(userOrderPayment);
|
|
|
result.put("pay",data);
|
|
|
+
|
|
|
+ // 保存商品信息到管乐迷
|
|
|
+ OmsOrderDetail detail = detail(order.getOrderSn());
|
|
|
+
|
|
|
+ MallCreateOrderModel model = new MallCreateOrderModel();
|
|
|
+ model.setOrderNo(order.getOrderSn());
|
|
|
+ model.setOrderInfo(JSON.toJSONString(detail));
|
|
|
+ HttpResponseResult<Map> mapHttpResponseResult = webFeignService.mallSaveOrderInfo(model);
|
|
|
+ if (!mapHttpResponseResult.getStatus()) {
|
|
|
+ throw new BizException(mapHttpResponseResult.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private Map feignMecCreateOrder(String couponId,String oldOrderNo, String orderSn, Long userId, BigDecimal amount) {
|
|
|
+ private Map feignMecCreateOrder(String couponId, String oldOrderNo, String orderSn, Integer teacherId, Integer userId, BigDecimal amount) {
|
|
|
// 远程调用管乐迷订单记录
|
|
|
MallCreateOrderModel model = new MallCreateOrderModel();
|
|
|
model.setAmount(amount);
|
|
|
model.setOrderNo(orderSn);
|
|
|
- model.setUserId(userId.intValue());
|
|
|
+ if (!userId.equals(teacherId)) {
|
|
|
+ model.setTeacherId(teacherId);
|
|
|
+ }
|
|
|
+ model.setUserId(userId);
|
|
|
model.setCouponIdList(StringUtil.toIntegerList(couponId));
|
|
|
model.setOldOrderNo(oldOrderNo);
|
|
|
HttpResponseResult<Map> mapHttpResponseResult = webFeignService.mallCreateOrder(model);
|
|
@@ -741,14 +776,22 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
@Transactional
|
|
|
public void paymentSucceededHandle(String orderNo, BigDecimal payAmount, String payChannel) {
|
|
|
//订单完成
|
|
|
- OmsOrderDetail detail = detail(orderNo);
|
|
|
+ UserOrderPayment orderPayment = userOrderPaymentService.getByAdapayNo(orderNo);
|
|
|
+ if (orderPayment == null) {
|
|
|
+ throw new BizException("订单支付信息未找到");
|
|
|
+ }
|
|
|
+ OmsOrderDetail detail = detail(orderPayment.getOrderNo());
|
|
|
if (detail.getStatus() == 0) {
|
|
|
orderSuccess(detail, payAmount, payChannel);
|
|
|
+
|
|
|
+ orderPayment.setStatus(TradeStatusEnum.succeeded.getCode());
|
|
|
+ userOrderPaymentService.saveOrUpdate(orderPayment);
|
|
|
+
|
|
|
Map<String,Object> notifyMap = new HashMap<>();
|
|
|
notifyMap.put("channelType", payChannel);
|
|
|
notifyMap.put("tradeState", "1");
|
|
|
notifyMap.put("totalMoney", payAmount);
|
|
|
- notifyMap.put("merOrderNo", orderNo);
|
|
|
+ notifyMap.put("merOrderNo",orderNo);
|
|
|
HttpResponseResult httpResponseResult = webFeignService.updateOrder(notifyMap);
|
|
|
if (!httpResponseResult.getStatus()) {
|
|
|
throw new BizException(httpResponseResult.getMsg());
|
|
@@ -768,14 +811,22 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void paymentFailedHandle(String orderNo, Map<String, Object> notifyMap) {
|
|
|
-
|
|
|
- OmsOrderDetail detail = detail(orderNo);
|
|
|
+ UserOrderPayment orderPayment = userOrderPaymentService.getByAdapayNo(orderNo);
|
|
|
+ if (orderPayment == null) {
|
|
|
+ throw new BizException("订单支付信息未找到");
|
|
|
+ }
|
|
|
+ OmsOrderDetail detail = detail(orderPayment.getOrderNo());
|
|
|
if (null == detail) {
|
|
|
LOG.error("汇付支付回调,订单未找到。 req is {}", orderNo);
|
|
|
throw new BizException("订单未找到");
|
|
|
}
|
|
|
if (detail.getStatus() == 0) {
|
|
|
cancelOrder(detail.getId(), "支付失败");
|
|
|
+
|
|
|
+ // 修改用户付款状态
|
|
|
+ orderPayment.setStatus(TradeStatusEnum.succeeded.getCode());
|
|
|
+ userOrderPaymentService.saveOrUpdate(orderPayment);
|
|
|
+
|
|
|
HttpResponseResult httpResponseResult = webFeignService.updateOrder(notifyMap);
|
|
|
if (!httpResponseResult.getStatus()) {
|
|
|
throw new BizException(httpResponseResult.getMsg());
|
|
@@ -785,6 +836,30 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<OmsOrderDetail> list(List<String> adapayNoList) {
|
|
|
+ String adapayNos = adapayNoList.stream().collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ List<OmsOrder> orderList = portalOrderDao.listByAdapayNo(adapayNoList,adapayNos);
|
|
|
+ //设置数据信息
|
|
|
+ List<Long> orderIds = orderList.stream().map(OmsOrder::getId).collect(Collectors.toList());
|
|
|
+ OmsOrderItemExample orderItemExample = new OmsOrderItemExample();
|
|
|
+ orderItemExample.createCriteria().andOrderIdIn(orderIds);
|
|
|
+ List<OmsOrderItem> orderItemList = orderItemMapper.selectByExample(orderItemExample);
|
|
|
+ List<OmsOrderDetail> orderDetailList = new ArrayList<>();
|
|
|
+ for (OmsOrder omsOrder : orderList) {
|
|
|
+ OmsOrderDetail orderDetail = new OmsOrderDetail();
|
|
|
+ BeanUtil.copyProperties(omsOrder, orderDetail);
|
|
|
+ List<OmsOrderItem> relatedItemList = orderItemList.stream()
|
|
|
+ .filter(item -> item.getOrderId()
|
|
|
+ .equals(orderDetail.getId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ orderDetail.setOrderItemList(relatedItemList);
|
|
|
+ orderDetailList.add(orderDetail);
|
|
|
+ }
|
|
|
+ return orderDetailList;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 订单完成
|
|
|
*
|