增加支付的流程
This commit is contained in:
21
src/main/java/com/sczx/order/common/enums/PayStatusEnum.java
Normal file
21
src/main/java/com/sczx/order/common/enums/PayStatusEnum.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.sczx.order.common.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: 张黎
|
||||||
|
* @Date: 2024/03/08/17:42
|
||||||
|
* @Description: 订单状态
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum PayStatusEnum {
|
||||||
|
USERPAYING("USERPAYING", "用户支付中"),
|
||||||
|
SUCCESS("SUCCESS", "支付成功"),
|
||||||
|
PAYERROR("PAYERROR", "支付失败"),
|
||||||
|
;
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
private final String msg;
|
||||||
|
}
|
||||||
@ -26,4 +26,16 @@ public class SimpleUserInfoDTO {
|
|||||||
|
|
||||||
@ApiModelProperty("头像")
|
@ApiModelProperty("头像")
|
||||||
private String avatarUrl;
|
private String avatarUrl;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty("微信小程序 openid")
|
||||||
|
private String wechatOpenid;
|
||||||
|
|
||||||
|
@ApiModelProperty("支付宝小程序 userid")
|
||||||
|
private String alipayUserid;
|
||||||
|
|
||||||
|
|
||||||
|
@ApiModelProperty("是否认证0未认证1已认证")
|
||||||
|
private Integer authed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,6 +58,9 @@ public class OrderSubPO implements Serializable {
|
|||||||
@ApiModelProperty("支付ID")
|
@ApiModelProperty("支付ID")
|
||||||
private String paymentId;
|
private String paymentId;
|
||||||
|
|
||||||
|
@ApiModelProperty("支付状态")
|
||||||
|
private String payStatus;
|
||||||
|
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
@ApiModelProperty("实际支付时间")
|
@ApiModelProperty("实际支付时间")
|
||||||
private LocalDateTime paidAt;
|
private LocalDateTime paidAt;
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import com.sczx.order.repository.OrderSubRepo;
|
|||||||
import com.sczx.order.service.OrderService;
|
import com.sczx.order.service.OrderService;
|
||||||
import com.sczx.order.thirdpart.dto.*;
|
import com.sczx.order.thirdpart.dto.*;
|
||||||
import com.sczx.order.thirdpart.dto.req.CarQueryConditionReq;
|
import com.sczx.order.thirdpart.dto.req.CarQueryConditionReq;
|
||||||
|
import com.sczx.order.thirdpart.dto.req.PaymentRequest;
|
||||||
import com.sczx.order.thirdpart.integration.CarInteg;
|
import com.sczx.order.thirdpart.integration.CarInteg;
|
||||||
import com.sczx.order.thirdpart.integration.PayInteg;
|
import com.sczx.order.thirdpart.integration.PayInteg;
|
||||||
import com.sczx.order.thirdpart.integration.StoreInteg;
|
import com.sczx.order.thirdpart.integration.StoreInteg;
|
||||||
@ -102,8 +103,8 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
orderMainPO.setOperatorId(Long.valueOf(companyStoreDTO.getOperatingCompanyId()));
|
orderMainPO.setOperatorId(Long.valueOf(companyStoreDTO.getOperatingCompanyId()));
|
||||||
orderMainPO.setOrderNo(OrderUtil.generateOrderNo());
|
orderMainPO.setOrderNo(OrderUtil.generateOrderNo());
|
||||||
//TODO 默认应该是待支付状态,这里先默认支付完成待取车
|
//TODO 默认应该是待支付状态,这里先默认支付完成待取车
|
||||||
// orderMainPO.setOrderStatus(OrderStatusEnum.WAIT_PAY.getCode());
|
orderMainPO.setOrderStatus(OrderStatusEnum.WAIT_PAY.getCode());
|
||||||
orderMainPO.setOrderStatus(OrderStatusEnum.WAIT_PICK.getCode());
|
// orderMainPO.setOrderStatus(OrderStatusEnum.WAIT_PICK.getCode());
|
||||||
orderMainPO.setFirstOrderTime(LocalDateTime.now());
|
orderMainPO.setFirstOrderTime(LocalDateTime.now());
|
||||||
|
|
||||||
//设置预计还车时间
|
//设置预计还车时间
|
||||||
@ -161,14 +162,35 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
|
|
||||||
BigDecimal orderAmount = orderSubPOList.stream().map(OrderSubPO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
BigDecimal orderAmount = orderSubPOList.stream().map(OrderSubPO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
orderMainPO.setOrderAmount(orderAmount);
|
orderMainPO.setOrderAmount(orderAmount);
|
||||||
|
|
||||||
|
// TODO 发起支付返回预支付信息
|
||||||
|
UnifiedPaymentInfoDTO unifiedPaymentInfoDTO = new UnifiedPaymentInfoDTO();
|
||||||
|
String paymentId = OrderUtil.generateSubOrderNo(OrderUtil.ZF_PREFIX);
|
||||||
|
//发起支付
|
||||||
|
if(StringUtils.equalsIgnoreCase(userInfoDTO.getMiniProgramType(), MiniProgramTypeEnum.WECHAT.getType())){
|
||||||
|
PaymentRequest paymentRequest = new PaymentRequest();
|
||||||
|
paymentRequest.setCompanyId(Long.valueOf(companyStoreDTO.getOperatingCompanyId()));
|
||||||
|
paymentRequest.setOutTradeNo(paymentId);
|
||||||
|
paymentRequest.setOpenId(userInfoDTO.getWechatOpenid());
|
||||||
|
paymentRequest.setAttach(companyStoreDTO.getOperatingCompanyId().toString());
|
||||||
|
paymentRequest.setSpbillCreateIp("127.0.0.1");
|
||||||
|
paymentRequest.setBody(rentCarRuleDTO.getRuleName());
|
||||||
|
paymentRequest.setTotalFee(orderMainPO.getOrderAmount().multiply(new BigDecimal(100)).intValue());
|
||||||
|
unifiedPaymentInfoDTO = payInteg.unifiedOrder(paymentRequest);
|
||||||
|
// TODO 其他支付类型
|
||||||
|
}
|
||||||
|
|
||||||
|
for(OrderSubPO orderSubPO : orderSubPOList){
|
||||||
|
orderSubPO.setPaymentId(paymentId);
|
||||||
|
}
|
||||||
|
|
||||||
orderMainRepo.save(orderMainPO);
|
orderMainRepo.save(orderMainPO);
|
||||||
|
|
||||||
orderSubPOList.forEach(orderSubPO -> {
|
orderSubPOList.forEach(orderSubPO -> {
|
||||||
orderSubPO.setOrderId(orderMainPO.getOrderId());
|
orderSubPO.setOrderId(orderMainPO.getOrderId());
|
||||||
});
|
});
|
||||||
orderSubRepo.saveBatch(orderSubPOList);
|
orderSubRepo.saveBatch(orderSubPOList);
|
||||||
// TODO 发起支付返回预支付信息
|
|
||||||
UnifiedPaymentInfoDTO unifiedPaymentInfoDTO = new UnifiedPaymentInfoDTO();
|
|
||||||
|
|
||||||
//返回订单信息
|
//返回订单信息
|
||||||
OrderDTO orderDTO = OrderConvert.INSTANCE.poToDto(orderMainPO);
|
OrderDTO orderDTO = OrderConvert.INSTANCE.poToDto(orderMainPO);
|
||||||
@ -493,7 +515,22 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
} else if(OrderStatusEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())||OrderStatusEnum.RERENT_WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
} else if(OrderStatusEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())||OrderStatusEnum.RERENT_WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
||||||
//TODO 待支付状态要拉起支付
|
//去查看订单是否支付成功
|
||||||
|
LambdaQueryWrapper<OrderSubPO> querySubOrderWrapper = new LambdaQueryWrapper<>();
|
||||||
|
querySubOrderWrapper.eq(OrderSubPO::getOrderId, orderMainPO.getOrderId())
|
||||||
|
.in(OrderSubPO::getSuborderType, Arrays.asList(SubOrderTypeEnum.RENTBATTEY.getCode(), SubOrderTypeEnum.RENTCAR.getCode()))
|
||||||
|
.ne(OrderSubPO::getPayStatus, PayStatusEnum.SUCCESS).orderByDesc(OrderSubPO::getCreatedAt).last(" limit 1");
|
||||||
|
OrderSubPO orderSubPO = orderSubRepo.getOne(querySubOrderWrapper);
|
||||||
|
if(orderSubPO!=null){
|
||||||
|
//如果是微信支付,则去微信查询支付状态,如果支付成功,则修改订单状态为支付成功
|
||||||
|
if(PaymentTypeEnum.WX_PAY.getCode().equals(orderSubPO.getPaymentMethod())){
|
||||||
|
Map<String, String> result = payInteg.orderQuery((long)companyStoreDTO.getOperatingCompanyId(), orderSubPO.getPaymentId());
|
||||||
|
if(StringUtils.equalsIgnoreCase(result.get("trade_state"), "SUCCESS")){
|
||||||
|
String orderState = paySuccessOrder(orderMainPO, orderSubPO);
|
||||||
|
orderDetailDTO.setOrderStatus(orderState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return orderDetailDTO;
|
return orderDetailDTO;
|
||||||
@ -654,6 +691,32 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
return orderMainRepo.pageQueryOrder(pageNo, pageSize, orderQueryReq.getCustomerId(), orderQueryReq.getStoreId(), orderStatusList, orderQueryReq.getQueryBrandName());
|
return orderMainRepo.pageQueryOrder(pageNo, pageSize, orderQueryReq.getCustomerId(), orderQueryReq.getStoreId(), orderStatusList, orderQueryReq.getQueryBrandName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付成功更新订单状态
|
||||||
|
* @param orderMainPO
|
||||||
|
* @param orderSubPO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String paySuccessOrder(OrderMainPO orderMainPO, OrderSubPO orderSubPO){
|
||||||
|
String orderStatus = null;
|
||||||
|
LambdaUpdateWrapper<OrderSubPO> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.set(OrderSubPO::getPayStatus, PayStatusEnum.SUCCESS.getCode());
|
||||||
|
updateWrapper.eq(OrderSubPO::getSuborderId, orderSubPO.getSuborderId());
|
||||||
|
orderSubRepo.update(updateWrapper);
|
||||||
|
|
||||||
|
LambdaUpdateWrapper<OrderMainPO> updateWrapper2 = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper2.eq(OrderMainPO::getOrderId, orderMainPO.getOrderId());
|
||||||
|
if(OrderStatusEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
||||||
|
updateWrapper2.set(OrderMainPO::getOrderStatus, OrderStatusEnum.WAIT_PICK.getCode());
|
||||||
|
orderStatus = OrderStatusEnum.WAIT_PICK.getCode();
|
||||||
|
} else if(OrderStatusEnum.RERENT_WAIT_PAY.getCode().equalsIgnoreCase(orderMainPO.getOrderStatus())){
|
||||||
|
updateWrapper2.set(OrderMainPO::getOrderStatus, OrderStatusEnum.RENT_ING.getCode());
|
||||||
|
orderStatus = OrderStatusEnum.RENT_ING.getCode();
|
||||||
|
}
|
||||||
|
orderMainRepo.update(updateWrapper2);
|
||||||
|
return orderStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取租车订单金额
|
* 获取租车订单金额
|
||||||
@ -674,4 +737,5 @@ public class OrderServiceImpl implements OrderService {
|
|||||||
return rentCarOrderAmount;
|
return rentCarOrderAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,8 @@ public class OrderUtil {
|
|||||||
|
|
||||||
public static final String YQ_PREFIX = "YQ";
|
public static final String YQ_PREFIX = "YQ";
|
||||||
|
|
||||||
|
public static final String ZF_PREFIX = "ZF";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成订单号的方法
|
* 生成订单号的方法
|
||||||
* @return 唯一订单号字符串
|
* @return 唯一订单号字符串
|
||||||
|
|||||||
Reference in New Issue
Block a user