完善下单接口
This commit is contained in:
@ -1,20 +0,0 @@
|
||||
package com.sczx.order.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Author: 张黎
|
||||
* @Date: 2024/03/08/17:42
|
||||
* @Description: 小程序类型枚举
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum MiniPogramTypeEnum {
|
||||
WX_MINI_PROGRAM("WX_MINI_PROGRAM", "微信小程序"),
|
||||
ZFB_MINI_PROGRAM("ZFB_MINI_PROGRAM", "支付宝小程序"),
|
||||
;
|
||||
private final String code;
|
||||
|
||||
private final String msg;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.sczx.order.common.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 小程序类型枚举
|
||||
*/
|
||||
@Getter
|
||||
public enum MiniProgramTypeEnum {
|
||||
WECHAT("wechat"),
|
||||
ALIPAY("alipay");
|
||||
|
||||
private final String type;
|
||||
|
||||
MiniProgramTypeEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,12 +3,13 @@ package com.sczx.order.controller;
|
||||
import com.sczx.order.common.Result;
|
||||
import com.sczx.order.dto.OrderMainDTO;
|
||||
import com.sczx.order.dto.RentCarOrderReq;
|
||||
import com.sczx.order.dto.RentCarOrderResultDTO;
|
||||
import com.sczx.order.service.OrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 张黎
|
||||
* @Date: 2025/07/25/16:42
|
||||
@ -19,10 +20,18 @@ import java.util.List;
|
||||
@RequestMapping("/clientOrder")
|
||||
public class ClientOrderController {
|
||||
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
@ApiOperation(value = "生成租车订单")
|
||||
@PostMapping("/confirmRentalCarOrder")
|
||||
public Result<OrderMainDTO> confirmRentalCarOrder(@RequestBody RentCarOrderReq rentCarOrderReq){
|
||||
return Result.ok(null);
|
||||
public Result<RentCarOrderResultDTO> confirmRentalCarOrder(@RequestBody RentCarOrderReq rentCarOrderReq){
|
||||
return Result.ok(orderService.submitRentCarOrder(rentCarOrderReq));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "生成租车订单")
|
||||
@GetMapping("/getOrderInfoByOrderNo")
|
||||
public Result<OrderMainDTO> getOrderInfoByOrderNo(@RequestParam("orderNo") String orderNo){
|
||||
return Result.ok(orderService.getOrderInfoByOrderNo(orderNo));
|
||||
}
|
||||
}
|
||||
|
||||
17
src/main/java/com/sczx/order/dto/RentCarOrderResultDTO.java
Normal file
17
src/main/java/com/sczx/order/dto/RentCarOrderResultDTO.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.sczx.order.dto;
|
||||
|
||||
import com.sczx.order.thirdpart.dto.UnifiedPaymentInfoDTO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@ApiModel(value = "租车结果")
|
||||
@Data
|
||||
public class RentCarOrderResultDTO {
|
||||
@ApiModelProperty(value = "租车订单信息")
|
||||
private OrderMainDTO orderMainInfo;
|
||||
|
||||
@ApiModelProperty(value = "统一预支付信息")
|
||||
private UnifiedPaymentInfoDTO unifiedPaymentInfo;
|
||||
}
|
||||
@ -20,6 +20,10 @@ public class SimpleUserInfoDTO {
|
||||
@ApiModelProperty(value = "角色id")
|
||||
private Integer roleId;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "小程序类型")
|
||||
private String miniPogramType;
|
||||
private String miniProgramType;
|
||||
|
||||
@ApiModelProperty("头像")
|
||||
private String avatarUrl;
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package com.sczx.order.service;
|
||||
|
||||
|
||||
import com.sczx.order.dto.OrderMainDTO;
|
||||
import com.sczx.order.dto.RentCarOrderReq;
|
||||
import com.sczx.order.dto.RentCarOrderResultDTO;
|
||||
|
||||
public interface OrderService {
|
||||
|
||||
@ -10,5 +12,12 @@ public interface OrderService {
|
||||
* @param rentCarOrderReq
|
||||
* @return
|
||||
*/
|
||||
OrderMainDTO submitRentCarOrder(RentCarOrderReq rentCarOrderReq);
|
||||
RentCarOrderResultDTO submitRentCarOrder(RentCarOrderReq rentCarOrderReq);
|
||||
|
||||
/**
|
||||
* 根据订单号查询订单信息
|
||||
* @param orderNo
|
||||
* @return
|
||||
*/
|
||||
OrderMainDTO getOrderInfoByOrderNo(String orderNo);
|
||||
}
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
package com.sczx.order.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.sczx.order.common.constant.RedisKeyConstants;
|
||||
import com.sczx.order.common.enums.MiniPogramTypeEnum;
|
||||
import com.sczx.order.common.enums.MiniProgramTypeEnum;
|
||||
import com.sczx.order.common.enums.PaymentTypeEnum;
|
||||
import com.sczx.order.common.enums.SubOrderTypeEnum;
|
||||
import com.sczx.order.common.enums.YesOrNoEnum;
|
||||
import com.sczx.order.convert.OrderConvert;
|
||||
import com.sczx.order.dto.OrderMainDTO;
|
||||
import com.sczx.order.dto.RentCarOrderReq;
|
||||
import com.sczx.order.dto.RentCarOrderResultDTO;
|
||||
import com.sczx.order.dto.SimpleUserInfoDTO;
|
||||
import com.sczx.order.exception.InnerException;
|
||||
import com.sczx.order.po.OrderMainPO;
|
||||
@ -18,6 +19,7 @@ import com.sczx.order.service.OrderService;
|
||||
import com.sczx.order.thirdpart.dto.CarModelSimpleDTO;
|
||||
import com.sczx.order.thirdpart.dto.CompanyStoreDTO;
|
||||
import com.sczx.order.thirdpart.dto.RentCarRuleDTO;
|
||||
import com.sczx.order.thirdpart.dto.UnifiedPaymentInfoDTO;
|
||||
import com.sczx.order.thirdpart.integration.CarInteg;
|
||||
import com.sczx.order.thirdpart.integration.StoreInteg;
|
||||
import com.sczx.order.utils.JwtUtil;
|
||||
@ -55,7 +57,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Override
|
||||
public OrderMainDTO submitRentCarOrder(RentCarOrderReq rentCarOrderReq) {
|
||||
public RentCarOrderResultDTO submitRentCarOrder(RentCarOrderReq rentCarOrderReq) {
|
||||
|
||||
SimpleUserInfoDTO userInfoDTO = jwtUtil.getUserInfoFromToken();
|
||||
|
||||
@ -77,22 +79,24 @@ public class OrderServiceImpl implements OrderService {
|
||||
//生成子表订单
|
||||
String paymentType;
|
||||
if(rentCarOrderReq.getIsAutoDeduct()){
|
||||
if(StringUtils.equalsIgnoreCase(userInfoDTO.getMiniPogramType(), MiniPogramTypeEnum.WX_MINI_PROGRAM.getCode())){
|
||||
if(StringUtils.equalsIgnoreCase(userInfoDTO.getMiniProgramType(), MiniProgramTypeEnum.WECHAT.getType())){
|
||||
paymentType = PaymentTypeEnum.WX_DQ.getCode();
|
||||
}else {
|
||||
paymentType = PaymentTypeEnum.ZFB_DQ.getCode();
|
||||
}
|
||||
} else {
|
||||
if(StringUtils.equalsIgnoreCase(userInfoDTO.getMiniPogramType(), MiniPogramTypeEnum.WX_MINI_PROGRAM.getCode())){
|
||||
if(StringUtils.equalsIgnoreCase(userInfoDTO.getMiniProgramType(), MiniProgramTypeEnum.ALIPAY.getType())){
|
||||
paymentType = PaymentTypeEnum.WX_PAY.getCode();
|
||||
}else {
|
||||
paymentType = PaymentTypeEnum.ZFB_PAY.getCode();
|
||||
}
|
||||
}
|
||||
List<OrderSubPO> orderSubPOList = new ArrayList<>();
|
||||
String subOrderNo = OrderUtil.generateSubOrderNo();
|
||||
//如果未开通免押则要生成押金订单
|
||||
if(!rentCarOrderReq.getIsDepositFree()){
|
||||
OrderSubPO depositOrder = new OrderSubPO();
|
||||
depositOrder.setSuborderNo(subOrderNo);
|
||||
depositOrder.setOrderId(orderMainPO.getOrderId());
|
||||
depositOrder.setSuborderType(SubOrderTypeEnum.DEPOSIT.getCode());
|
||||
depositOrder.setAmount(orderMainPO.getDepositPrice());
|
||||
@ -101,6 +105,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderSubPOList.add(depositOrder);
|
||||
}
|
||||
OrderSubPO rentOrder = new OrderSubPO();
|
||||
rentOrder.setSuborderNo(subOrderNo);
|
||||
rentOrder.setOrderId(orderMainPO.getOrderId());
|
||||
rentOrder.setSuborderType(SubOrderTypeEnum.RENTCAR.getCode());
|
||||
rentOrder.setAmount(orderMainPO.getRentalPrice());
|
||||
@ -108,14 +113,19 @@ public class OrderServiceImpl implements OrderService {
|
||||
rentOrder.setPaymentMethod(paymentType);
|
||||
orderSubPOList.add(rentOrder);
|
||||
orderSubRepo.saveBatch(orderSubPOList);
|
||||
// TODO 发起支付
|
||||
// TODO 发起支付返回预支付信息
|
||||
UnifiedPaymentInfoDTO unifiedPaymentInfoDTO = new UnifiedPaymentInfoDTO();
|
||||
|
||||
//返回订单信息
|
||||
OrderMainDTO orderMainDTO = OrderConvert.INSTANCE.poToDto(orderMainPO);
|
||||
orderMainDTO.setCompanyStoreDTO(companyStoreDTO);
|
||||
orderMainDTO.setCarModelSimpleDTO(carModelSimpleDTO);
|
||||
|
||||
return orderMainDTO;
|
||||
RentCarOrderResultDTO rentCarOrderResultDTO = new RentCarOrderResultDTO();
|
||||
rentCarOrderResultDTO.setOrderMainInfo(orderMainDTO);
|
||||
rentCarOrderResultDTO.setUnifiedPaymentInfo(unifiedPaymentInfoDTO);
|
||||
|
||||
return rentCarOrderResultDTO;
|
||||
|
||||
}catch (Exception e){
|
||||
log.warn("下单失败", e);
|
||||
@ -128,4 +138,19 @@ public class OrderServiceImpl implements OrderService {
|
||||
throw new InnerException("服务器正在处理,请稍后再试");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderMainDTO getOrderInfoByOrderNo(String orderNo) {
|
||||
LambdaQueryWrapper<OrderMainPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(OrderMainPO::getOrderNo, orderNo);
|
||||
OrderMainPO orderMainPO = orderMainRepo.getOne(queryWrapper);
|
||||
OrderMainDTO orderMainDTO = OrderConvert.INSTANCE.poToDto(orderMainPO);
|
||||
//获取门店信息
|
||||
CompanyStoreDTO companyStoreDTO = storeInteg.getStoreById(Integer.valueOf(orderMainPO.getStoreId().toString()));
|
||||
|
||||
CarModelSimpleDTO carModelSimpleDTO = carInteg.getCarModelByModelId(orderMainPO.getCarModelId());
|
||||
orderMainDTO.setCarModelSimpleDTO(carModelSimpleDTO);
|
||||
orderMainDTO.setCompanyStoreDTO(companyStoreDTO);
|
||||
return orderMainDTO;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
package com.sczx.order.thirdpart.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel(value = "统一预支付信息DTO")
|
||||
@Data
|
||||
public class UnifiedPaymentInfoDTO {
|
||||
/**
|
||||
* 应用ID(微信小程序ID/支付宝小程序ID)
|
||||
*/
|
||||
@ApiModelProperty(value = "应用ID(微信小程序ID/支付宝小程序ID)")
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
@ApiModelProperty(value = "时间戳")
|
||||
private String timeStamp;
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
@ApiModelProperty(value = "随机字符串")
|
||||
private String nonceStr;
|
||||
|
||||
/**
|
||||
* 订单信息包
|
||||
* 微信支付:prepay_id=xxxxxx
|
||||
* 支付宝支付:完整的订单参数字符串
|
||||
*/
|
||||
@ApiModelProperty(value = "订单信息包")
|
||||
private String packageValue;
|
||||
|
||||
/**
|
||||
* 签名类型
|
||||
*/
|
||||
@ApiModelProperty(value = "签名类型")
|
||||
private String signType;
|
||||
|
||||
/**
|
||||
* 签名
|
||||
* 微信支付:paySign
|
||||
* 支付宝支付:sign
|
||||
*/
|
||||
@ApiModelProperty(value = "签名")
|
||||
private String paySign;
|
||||
|
||||
/**
|
||||
* 支付类型标识
|
||||
* WX-微信支付,ALI-支付宝支付
|
||||
*/
|
||||
@ApiModelProperty(value = "支付类型标识")
|
||||
private String paymentType;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
@ApiModelProperty(value = "商户订单号")
|
||||
private String outTradeNo;
|
||||
}
|
||||
@ -16,4 +16,15 @@ public class OrderUtil {
|
||||
String uuidSuffix = UUID.randomUUID().toString().replace("-", "").substring(0, 6).toUpperCase();
|
||||
return "OC" + timestamp + uuidSuffix; // OC代表Order Car
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成子订单号用于支付
|
||||
* @return 唯一订单号字符串
|
||||
*/
|
||||
public static String generateSubOrderNo() {
|
||||
// 使用时间戳+UUID后缀确保唯一性
|
||||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
String uuidSuffix = UUID.randomUUID().toString().replace("-", "").substring(0, 6).toUpperCase();
|
||||
return "SUB" + timestamp + uuidSuffix; // sub代表子订单号
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user