|
|
@@ -13,6 +13,8 @@ import com.alipay.api.domain.*;
|
|
|
import com.alipay.api.internal.util.AlipaySignature;
|
|
|
import com.alipay.api.request.*;
|
|
|
import com.alipay.api.response.AlipayFundTransCommonQueryResponse;
|
|
|
+import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
|
|
|
+import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeRefundResponse;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -235,7 +237,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
} else {
|
|
|
//寻找差不多过期时间规格的车位
|
|
|
- relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths());
|
|
|
+ relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths(), null);
|
|
|
if (relation == null) {
|
|
|
//TODO 如果没指定座位,等待逻辑确认
|
|
|
GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, payRequest.getSkuId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
@@ -462,6 +464,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (null == order) {
|
|
|
throw BusinessRuntimeException.getInstance("订单不存在.");
|
|
|
}
|
|
|
+ log.info("微信商家订单号orderNo:{},status:{},进行回调", order.getOrderNo(), order.getStatus());
|
|
|
+
|
|
|
String appId = map.get("mch_id");
|
|
|
|
|
|
// 校验签名
|
|
|
@@ -476,7 +480,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
String transactionId = map.get("transaction_id");
|
|
|
|
|
|
- if (order.getStatus().equals(OrderDon.Status.hasPayment)) {
|
|
|
+ if (!order.getStatus().equals(OrderDon.Status.noPayment) && !order.getStatus().equals(OrderDon.Status.close)) {
|
|
|
log.info("已回调,重复修改状态 id:{}", order.getId());
|
|
|
return;
|
|
|
}
|
|
|
@@ -499,6 +503,15 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
order.setStatus(OrderDon.Status.hasPayment);
|
|
|
}
|
|
|
|
|
|
+ boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
|
+ .set(OrderDon::getStatus, order.getStatus())
|
|
|
+ .in(OrderDon::getStatus, List.of(OrderDon.Status.noPayment, OrderDon.Status.close))
|
|
|
+ .eq(OrderDon::getId, order.getId()));
|
|
|
+ if (!isSuccess) {
|
|
|
+ log.info("微信回调商家订单号:{}订单状态已修改", order.getOrderNo());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (!order.getIsNoLogin()) {
|
|
|
if (order.getOrderType() == 2 && order.getIsChangeTicket()) {
|
|
|
//将奈飞月付车票更换成其他规格的车票
|
|
|
@@ -563,23 +576,26 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//关闭订单逻辑
|
|
|
OrderDon orderDon = getById(orderId);
|
|
|
if (OrderDon.Status.noPayment.equals(orderDon.getStatus())) {
|
|
|
- //查询微信支付是否已支付
|
|
|
- orderDon.setStatus(OrderDon.Status.close);
|
|
|
- updateById(orderDon);
|
|
|
-
|
|
|
- //关闭车位锁定
|
|
|
- GroupsRelation groupsRelation = groupsRelationMapper.selectById(orderDon.getRelationId());
|
|
|
- if (groupsRelation != null) {
|
|
|
- if (!groupsRelation.getUserId().equals(orderDon.getUserId())) {
|
|
|
- throw new BusinessRuntimeException("订单用户与车位用户不匹配!");
|
|
|
- } else {
|
|
|
- if (GroupsRelation.Status.locking.equals(groupsRelation.getStatus())) {
|
|
|
- groupsRelation.setUserId(0L);
|
|
|
- groupsRelation.setStatus(GroupsRelation.Status.none);
|
|
|
- groupsRelationMapper.updateById(groupsRelation);
|
|
|
- delRelation(groupsRelation.getId());
|
|
|
-
|
|
|
- //车位空余发送模板消息
|
|
|
+ //调用微信、支付宝第三方接口查询订单是否支付
|
|
|
+ OrderDon.Status status = isHasPaid(orderDon);
|
|
|
+ if (status == OrderDon.Status.noPayment) {
|
|
|
+ //查询微信支付是否已支付
|
|
|
+ orderDon.setStatus(OrderDon.Status.close);
|
|
|
+ updateById(orderDon);
|
|
|
+ //关闭车位锁定
|
|
|
+ GroupsRelation groupsRelation = groupsRelationMapper.selectById(orderDon.getRelationId());
|
|
|
+ if (groupsRelation != null) {
|
|
|
+ if (!groupsRelation.getUserId().equals(orderDon.getUserId())) {
|
|
|
+ throw new BusinessRuntimeException("订单用户与车位用户不匹配!");
|
|
|
+ } else {
|
|
|
+ if (GroupsRelation.Status.locking.equals(groupsRelation.getStatus())) {
|
|
|
+ log.info("清理用户userId:{}未支付订单orderNo:", orderDon.getUserId(), orderDon.getOrderNo());
|
|
|
+ groupsRelation.setUserId(0L);
|
|
|
+ groupsRelation.setStatus(GroupsRelation.Status.none);
|
|
|
+ groupsRelationMapper.updateById(groupsRelation);
|
|
|
+ delRelation(groupsRelation.getId());
|
|
|
+
|
|
|
+ //车位空余发送模板消息
|
|
|
// TASK_POOL.execute(() -> {
|
|
|
// try {
|
|
|
// List<CustomerService> customerServices = customerServiceMapper.selectList(null);
|
|
|
@@ -591,12 +607,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
// log.error("发送{}空车位模板消息至客服失败:{}", orderDon.getGoodsId(), e);
|
|
|
// }
|
|
|
// });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- //返还优惠券
|
|
|
- if (orderDon.getCouponUserId() != 0) {
|
|
|
- updateOrderDonCouponStatus(orderDon);
|
|
|
+ //返还优惠券
|
|
|
+ if (orderDon.getCouponUserId() != 0) {
|
|
|
+ updateOrderDonCouponStatus(orderDon);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -796,8 +813,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
String transactionId = params.get("trade_no");
|
|
|
String payTimeStr = params.get("gmt_payment");
|
|
|
-
|
|
|
- if (orderDon.getStatus().equals(OrderDon.Status.hasPayment)) {
|
|
|
+ if (!orderDon.getStatus().equals(OrderDon.Status.noPayment) && !orderDon.getStatus().equals(OrderDon.Status.close)) {
|
|
|
log.info("支付宝已回调,重复修改状态 id:{}", orderDon.getId());
|
|
|
return;
|
|
|
}
|
|
|
@@ -819,6 +835,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getIsNoLogin()) {
|
|
|
orderDon.setStatus(OrderDon.Status.hasPayment);
|
|
|
}
|
|
|
+ boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
|
+ .set(OrderDon::getStatus, orderDon.getStatus())
|
|
|
+ .in(OrderDon::getStatus, List.of(OrderDon.Status.noPayment, OrderDon.Status.close))
|
|
|
+ .eq(OrderDon::getId, orderDon.getId()));
|
|
|
+ if (!isSuccess) {
|
|
|
+ log.info("支付宝回调商家订单号:{}订单状态已修改", orderDon.getOrderNo());
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!orderDon.getIsNoLogin()) {
|
|
|
if (orderDon.getOrderType() == 2 && orderDon.getIsChangeTicket()) {
|
|
|
//将奈飞月付车票更换成其他规格的车票
|
|
|
@@ -1240,21 +1264,26 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw new BusinessRuntimeException("您有未支付订单.");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId) != null) {
|
|
|
- log.info("=====>用户:{}获取了已有人座位:{}", userId, relationId);
|
|
|
- throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
- } else {
|
|
|
- if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
|
|
|
- log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
- throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
- }
|
|
|
+ Object value = redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId);
|
|
|
+ if (value != null) {
|
|
|
GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
- int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
|
|
|
- if (count == 0) {
|
|
|
- log.error("车位异常 groupId:{}", relation.getGroupsId());
|
|
|
- throw new BusinessRuntimeException("车位异常");
|
|
|
+ if (relation != null && relation.getUserId() == 0l) {
|
|
|
+ redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relationId);
|
|
|
}
|
|
|
+ if (relation != null && relation.getUserId() != 0l) {
|
|
|
+ log.info("=====>用户:{}获取了已有人座位:{}", userId, relationId);
|
|
|
+ throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
|
|
|
+ log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
+ throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
+ }
|
|
|
+ GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
+ int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
|
|
|
+ if (count == 0) {
|
|
|
+ log.error("车位异常 groupId:{}", relation.getGroupsId());
|
|
|
+ throw new BusinessRuntimeException("车位异常");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1354,6 +1383,53 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
return transUniTransferRequest;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询支付宝订单详情
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AlipayTradeQueryResponse getZfbOrderDetail(String shopId, String orderNo) throws AlipayApiException {
|
|
|
+ AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(shopId);
|
|
|
+ AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
|
|
+ AlipayTradeWapPayModel bizModel = new AlipayTradeWapPayModel();
|
|
|
+ bizModel.setOutTradeNo(orderNo);
|
|
|
+ request.setBizModel(bizModel);
|
|
|
+ AlipayTradeQueryResponse response;
|
|
|
+ ShopConfig shopConfig = shopConfigMapper.selectOne(Wrappers.lambdaQuery(ShopConfig.class).eq(ShopConfig::getAppId, shopId));
|
|
|
+ if (shopConfig != null && shopConfig.getIsCert()) {
|
|
|
+ response = alipayClient.certificateExecute(request);
|
|
|
+ } else {
|
|
|
+ response = alipayClient.execute(request);
|
|
|
+ }
|
|
|
+ if (response.isSuccess()) {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询支付宝退款订单详情
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AlipayTradeFastpayRefundQueryResponse getZfbRefundDetail(String shopId, String orderNo) throws AlipayApiException {
|
|
|
+ AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(shopId);
|
|
|
+ AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest();
|
|
|
+ AlipayTradeRefundModel bizModel = new AlipayTradeRefundModel();
|
|
|
+ bizModel.setOutTradeNo(orderNo);
|
|
|
+ bizModel.setOutRequestNo(orderNo);
|
|
|
+ request.setBizModel(bizModel);
|
|
|
+ AlipayTradeFastpayRefundQueryResponse response;
|
|
|
+ ShopConfig shopConfig = shopConfigMapper.selectOne(Wrappers.lambdaQuery(ShopConfig.class).eq(ShopConfig::getAppId, shopId));
|
|
|
+ if (shopConfig != null && shopConfig.getIsCert()) {
|
|
|
+ response = alipayClient.certificateExecute(request);
|
|
|
+ } else {
|
|
|
+ response = alipayClient.execute(request);
|
|
|
+ }
|
|
|
+ if (response.isSuccess()) {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public AliPayParams commonAliPay(Long orderId, String returnUrl, String productCode, String appId, String qrPayMode) throws Exception {
|
|
|
AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(Optional.ofNullable(appId).orElse(ShopConfig.ZFB_DEFAULT_APP_ID));
|
|
|
// 创建API对应的request
|
|
|
@@ -1435,10 +1511,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
public void updateCarParkAndSendMsg(GoodsDon goodsDon, GoodsDonSku sku, OrderDon order) {
|
|
|
if (goodsDon.getType() == 1) {
|
|
|
+ log.info("虚物订单orderNo:{}开始更新车票信息", order.getOrderNo());
|
|
|
//修改车位状态
|
|
|
GroupsRelation relation = groupsRelationMapper.selectById(order.getRelationId());
|
|
|
GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
if (GroupsRelation.Status.locking.equals(relation.getStatus()) || GroupsRelation.Status.validity.equals(relation.getStatus())) {
|
|
|
+ log.info("订单号orderNo:{}开始修改车位:{}状态", order.getOrderNo(), relation.getId());
|
|
|
relation.setStatus(GroupsRelation.Status.validity);
|
|
|
//续费后,下一次续费意愿状态为false
|
|
|
relation.setRenewStatus(false);
|
|
|
@@ -1452,6 +1530,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
relation.setExpiryTime(newDate);
|
|
|
relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
|
|
|
} else if (GroupsTrips.Status.waiting.equals(groupsTrips.getStatus())) {
|
|
|
+ log.info("车位groupsId:{}未发车,修改订单号orderNo:{}订单为已付款状态:{}", groupsTrips.getId(), order.getOrderNo());
|
|
|
order.setStatus(OrderDon.Status.hasPayment);
|
|
|
}
|
|
|
//TODO 如未发车逻辑
|
|
|
@@ -1931,4 +2010,63 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
userRenewChangeTicketRecordMapper.insert(record);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询第三放接口订单是否已支付
|
|
|
+ */
|
|
|
+ public OrderDon.Status isHasPaid(OrderDon orderDon) {
|
|
|
+ OrderDon.Status noPayment = OrderDon.Status.noPayment;
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
+ if (orderDon.getType() == OrderDon.Type.WeChat) {
|
|
|
+ try {
|
|
|
+ Map<String, String> reMap = weChatService.getWxOrderDetail(orderDon.getShopId(), orderDon.getOrderNo());
|
|
|
+ if (reMap != null) {
|
|
|
+ String orderStatus = reMap.get("trade_state");
|
|
|
+ if ("SUCCESS".equals(orderStatus)) {
|
|
|
+ orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
+ orderDon.setTransactionId(reMap.get("transaction_id"));
|
|
|
+ return updateNoPayment(noPayment, orderDon, goodsDon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ } else if (orderDon.getType() == OrderDon.Type.ALI_PAY) {
|
|
|
+ try {
|
|
|
+ AlipayTradeQueryResponse zfbOrderDetail = getZfbOrderDetail(orderDon.getShopId(), orderDon.getOrderNo());
|
|
|
+ if (zfbOrderDetail != null) {
|
|
|
+ String tradeStatus = zfbOrderDetail.getTradeStatus();
|
|
|
+ if ("TRADE_SUCCESS".equals(tradeStatus)) {
|
|
|
+ orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
+ orderDon.setTransactionId(zfbOrderDetail.getTradeNo());
|
|
|
+ return updateNoPayment(noPayment, orderDon, goodsDon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return orderDon.getStatus();
|
|
|
+ }
|
|
|
+
|
|
|
+ private OrderDon.Status updateNoPayment(OrderDon.Status noPayment, OrderDon orderDon, GoodsDon goodsDon) {
|
|
|
+ boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
|
+ .set(OrderDon::getStatus, orderDon.getStatus())
|
|
|
+ .set(OrderDon::getTransactionId, orderDon.getTransactionId())
|
|
|
+ .eq(OrderDon::getStatus, noPayment)
|
|
|
+ .eq(OrderDon::getId, orderDon.getId()));
|
|
|
+ if (isSuccess) {
|
|
|
+ //更新车位情况
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
+ if (orderDon.getOrderType() == 2 && orderDon.getIsChangeTicket()) {
|
|
|
+ //将奈飞月付车票更换成其他规格的车票
|
|
|
+ changeTicketAndRecord(orderDon.getPreSkuId(), orderDon.getRelationId(), orderDon.getId(), orderDon.getNum(), sku, orderDon.getUserId());
|
|
|
+ } else {
|
|
|
+ updateCarParkAndSendMsg(goodsDon, sku, orderDon);
|
|
|
+ }
|
|
|
+ updateById(orderDon);
|
|
|
+ return orderDon.getStatus();
|
|
|
+ }
|
|
|
+ return noPayment;
|
|
|
+ }
|
|
|
}
|