Merge remote-tracking branch 'origin/master'

This commit is contained in:
zjf committed 2025-05-07 17:15:26 +08:00
commit 9f3fba9bed
23 files changed
+450 -70

No files matched your search

@@ -18,7 +18,7 @@ public enum HardOrderTypeEnum {
FOREIGN_TICKET("3", "外来人员"),
STRIDE_DEPT("4", "跨单位"),
ZY("5", "正元公务餐"),
LB("5", "宁波银行(美好生活)"),
LB("6", "宁波银行(美好生活)"),
;
private final String type;
private final String description;
@@ -28,7 +28,7 @@ public enum HardOrderTypeEnum {
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
}
public static final List<HardOrderTypeEnum> refundList = List.of(BELOW, RESERVE, FOREIGN_TICKET, ZY);
public static final List<HardOrderTypeEnum> refundList = List.of(BELOW, RESERVE, FOREIGN_TICKET, ZY, LB);
public static final List<HardOrderTypeEnum> payList = List.of(BELOW, RESERVE);
@@ -2,17 +2,23 @@ package com.bsd.pjcloud.hard.api.feign;
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
import com.bsd.pjcloud.common.feign.annotation.NoToken;
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPaySoureBizTypeEnum;
import com.bsd.pjcloud.thirdparty.dto.pay.PayDto;
import com.bsd.pjcloud.thirdparty.dto.pay.RefundDto;
import com.bsd.pjcloud.thirdparty.dto.pay.WaterDto;
import com.bsd.pjcloud.thirdparty.vo.pay.PayBaseVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayWaterVo;
import com.bsd.pjcloud.thirdparty.vo.pay.RefundVo;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(contextId = "remoteHardThirdPayService", value = ServiceNameConstants.HARDWARE_SERVICE)
public interface RemoteHardThirdPayService {
/**
@@ -20,13 +26,19 @@ public interface RemoteHardThirdPayService {
*/
@NoToken
@PostMapping("/hard-third-pay/wallet-pay")
PayBaseVo<PayVo> walletPay(@RequestBody PayDto dto, @RequestParam WalletTypeEnum walletType);
PayBaseVo<PayVo> walletPay(@RequestBody PayDto dto, @RequestParam WalletTypeEnum walletType, @RequestParam ThirdPaySoureBizTypeEnum soureType);
/**
* 第三方退款
*/
@NoToken
@PostMapping("/hard-third-pay/wallet-refund")
PayBaseVo<RefundVo> walletRefund(@RequestBody RefundDto dto);
PayBaseVo<RefundVo> walletRefund(@RequestBody RefundDto dto, @RequestParam ThirdPaySoureBizTypeEnum soureType);
/**
* 第三方退款
*/
@NoToken
@PostMapping("/hard-third-pay/water")
PayBaseVo<List<PayWaterVo>> waterList(@RequestBody WaterDto dto, @RequestParam ThirdPaySoureBizTypeEnum soureType);
}
@@ -5,10 +5,13 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@ConfigurationProperties(prefix = "lb-callback")
@ConfigurationProperties(prefix = "pay-callback")
@Component
public class LbCallbackConfig {
private Long mchId;
/**
* 宁波银行(美好生活)商户id
*/
private Long lbMchId;
}
@@ -3,10 +3,13 @@ package com.bsd.pjcloud.hard.controller.third;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.hard.service.HardThirdPayService;
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPaySoureBizTypeEnum;
import com.bsd.pjcloud.thirdparty.dto.pay.PayDto;
import com.bsd.pjcloud.thirdparty.dto.pay.RefundDto;
import com.bsd.pjcloud.thirdparty.dto.pay.WaterDto;
import com.bsd.pjcloud.thirdparty.vo.pay.PayBaseVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayWaterVo;
import com.bsd.pjcloud.thirdparty.vo.pay.RefundVo;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import io.swagger.v3.oas.annotations.Operation;
@@ -16,6 +19,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/hard-third-pay")
@@ -29,16 +34,24 @@ public class HardThirdPayController {
@PostMapping("/wallet-pay")
@SysLog("第三方支付")
@Operation(summary = "第三方支付")
public PayBaseVo<PayVo> walletPay(@RequestBody PayDto dto, @RequestParam WalletTypeEnum walletType) {
return hardThirdPayService.walletPay(dto, walletType);
public PayBaseVo<PayVo> walletPay(@RequestBody PayDto dto, @RequestParam WalletTypeEnum walletType, @RequestParam ThirdPaySoureBizTypeEnum soureType) {
return hardThirdPayService.walletPay(dto, walletType, soureType);
}
@Inner
@PostMapping("/wallet-refund")
@SysLog("第三方退款")
@Operation(summary = "第三方退款")
public PayBaseVo<RefundVo> walletRefund(@RequestBody RefundDto dto) {
return hardThirdPayService.walletRefund(dto);
public PayBaseVo<RefundVo> walletRefund(@RequestBody RefundDto dto, @RequestParam ThirdPaySoureBizTypeEnum soureType) {
return hardThirdPayService.walletRefund(dto, soureType);
}
@Inner
@PostMapping("/water")
@SysLog("获取流水")
@Operation(summary = "获取流水")
public PayBaseVo<List<PayWaterVo>> waterList(@RequestBody WaterDto dto, @RequestParam ThirdPaySoureBizTypeEnum soureType) {
return hardThirdPayService.waterList(dto, soureType);
}
}
@@ -1,21 +1,31 @@
package com.bsd.pjcloud.hard.service;
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPaySoureBizTypeEnum;
import com.bsd.pjcloud.thirdparty.dto.pay.PayDto;
import com.bsd.pjcloud.thirdparty.dto.pay.RefundDto;
import com.bsd.pjcloud.thirdparty.dto.pay.WaterDto;
import com.bsd.pjcloud.thirdparty.vo.pay.PayBaseVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayWaterVo;
import com.bsd.pjcloud.thirdparty.vo.pay.RefundVo;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import java.util.List;
public interface HardThirdPayService {
/**
* 第三方支付
*/
PayBaseVo<PayVo> walletPay(PayDto dto, WalletTypeEnum walletType);
PayBaseVo<PayVo> walletPay(PayDto dto, WalletTypeEnum walletType, ThirdPaySoureBizTypeEnum soureType);
/**
* 第三方退款
*/
PayBaseVo<RefundVo> walletRefund(RefundDto dto);
PayBaseVo<RefundVo> walletRefund(RefundDto dto, ThirdPaySoureBizTypeEnum soureType);
/**
* 获取流水
*/
PayBaseVo<List<PayWaterVo>> waterList(WaterDto dto, ThirdPaySoureBizTypeEnum soureType);
}
@@ -221,7 +221,11 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
if (ObjectUtil.isEmpty(prefixStr)) prefixStr = "hard";
String refundCode = prefixStr + "_" + order.getId();
// 创建退款单
WalletRechargeRefundDto hardRefundDto = WalletRechargeRefundDto.builder().walletId(order.getWalletId()).orderId(order.getId()).afterSaleId(afterSale.getId()).refundCode(refundCode).reason("订单退款").price(order.getPayPrice()).build();
Integer refundPrice = afterSale.getRefundPrice();
if (ObjectUtil.isEmpty(refundPrice)) {
refundPrice = order.getPayPrice();
}
WalletRechargeRefundDto hardRefundDto = WalletRechargeRefundDto.builder().walletId(order.getWalletId()).orderId(order.getId()).afterSaleId(afterSale.getId()).refundCode(refundCode).reason("订单退款").price(refundPrice).build();
R<WalletRechargeVo> walletRefundResult = walletRechargeService.refund(hardRefundDto);
if (walletRefundResult.getCode() != 0 || ObjectUtil.isEmpty(walletRefundResult.getData())) {
throw new RuntimeException("钱包退款错误");
@@ -232,7 +236,7 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
.orderStatus(HardOrderStatusEnum.REFUND.getType())
.refundStatus(HardRefundStatusEnum.SUCCESS.getStatus())
.payRefundId(walletRefund.getId())
.refundPrice(order.getPayPrice())
.refundPrice(refundPrice)
.refundTime(LocalDateTime.now())
.build();
hardOrderService.updateById(updateObj);
@@ -146,7 +146,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
// 用户
List<Long> userIds = list.getRecords().stream().map(HardOrderVo::getUserId).filter(ObjectUtil::isNotEmpty).distinct().toList();
if (ObjectUtil.isNotEmpty(userIds)) {
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
R<List<SysUser>> userList = userService.getInnerUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(list.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
}
@@ -1,10 +1,11 @@
package com.bsd.pjcloud.hard.service.impl.third;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.admin.api.dto.UserInfo;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
@@ -16,24 +17,26 @@ import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardAfterSaleOperateTypeEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleStatusEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleTypeEnum;
import com.bsd.pjcloud.hard.api.constant.third.HardCallbackPayStatus;
import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleLogEntity;
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderPayTypeVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
import com.bsd.pjcloud.hard.api.vo.third.HardCallbackPayVo;
import com.bsd.pjcloud.hard.config.LbCallbackConfig;
import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleLogMapper;
import com.bsd.pjcloud.hard.service.HardAfterSaleService;
import com.bsd.pjcloud.hard.service.HardCarService;
import com.bsd.pjcloud.hard.service.HardOrderService;
import com.bsd.pjcloud.hard.service.HardThirdPayService;
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPaySoureBizTypeEnum;
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayVoStatusEnum;
import com.bsd.pjcloud.thirdparty.dto.pay.PayDto;
import com.bsd.pjcloud.thirdparty.dto.pay.RefundDto;
import com.bsd.pjcloud.thirdparty.dto.pay.WaterDto;
import com.bsd.pjcloud.thirdparty.vo.pay.PayBaseVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayWaterVo;
import com.bsd.pjcloud.thirdparty.vo.pay.RefundVo;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
@@ -42,12 +45,12 @@ import com.bsd.pjcloud.wallet.api.feign.RemoteWalletService;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTimeUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Validated
@@ -74,11 +77,12 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
*/
@Override
@Transactional(rollbackFor = Exception.class)
public PayBaseVo<PayVo> walletPay(PayDto dto, WalletTypeEnum walletType) {
public PayBaseVo<PayVo> walletPay(PayDto dto, WalletTypeEnum walletType, ThirdPaySoureBizTypeEnum soureType) {
PayBaseVo baseVo = new PayBaseVo<PayVo>();
try {
String orderType = getOrderType(soureType);
// 默认商户
MchManageVo defaultMch = getLbDefaultMch();
MchManageVo defaultMch = getLbDefaultMch(soureType);
if (ObjectUtil.isEmpty(defaultMch)) {
baseVo.set(ThirdPayVoStatusEnum.MCH_EXIST);
return baseVo;
@@ -95,6 +99,16 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
baseVo.set(ThirdPayVoStatusEnum.USER_EXIST);
return baseVo;
}
// 改订单号是否重复
long orderCount = hardOrderService.count(new LambdaQueryWrapper<HardOrderEntity>()
.eq(HardOrderEntity::getOrderNo, dto.getThirdOrderId())
.eq(HardOrderEntity::getOrderType, orderType)
.eq(HardOrderEntity::getOrderStatus, HardOrderStatusEnum.PAY.getType())
);
if (orderCount > 0) {
baseVo.set(ThirdPayVoStatusEnum.ORDER_HAVE_PAY);
return baseVo;
}
// 判断余额
Integer balance = wallet.getBalance();
int totalPrice = dto.getPrice();
@@ -102,12 +116,15 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
baseVo.set(ThirdPayVoStatusEnum.BALANCE_NOT_ENOUGH);
return baseVo;
}
List<PayDto.Product> products = dto.getProducts();
for (PayDto.Product v : products) {
if (!ObjectUtil.isAllNotEmpty(v.getName(), v.getCount(), v.getPrice())) continue;
products.add(v);
List<PayDto.Product> products = new ArrayList<>();
if (ObjectUtil.isNotEmpty(dto.getProducts())) {
for (PayDto.Product v : dto.getProducts()) {
if (!ObjectUtil.isAllNotEmpty(v.getName(), v.getCount(), v.getPrice())) continue;
if (v.getCount() <= 0) continue;
products.add(v);
}
}
String subject = "美好生活物品 * ?";
String subject = "美好生活物品*?";
Integer orderTotalPrice = dto.getPrice();
Long parentCarId = null;
if (ObjectUtil.isNotEmpty(products)) {
@@ -127,11 +144,11 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
.userDeptId(userDetail.getSysUser().getDeptId())
.sysType(HardTypeEnum.OTHER.getType())
.orderStatus(HardOrderStatusEnum.CREATE.getType())
.orderType(HardOrderTypeEnum.LB.getType())
.orderType(orderType)
.payType(HardPayTypeEnum.WALLET_CARD.getType())
.orderSourceTypeId(null)
.totalPrice(orderTotalPrice)
.extraPrice(0)
.extraPrice(dto.getPrice() - orderTotalPrice)
.payPrice(dto.getPrice())
.isOfflineOrder(YesNoEnum.NO.getCode())
.productDesc(subject)
@@ -149,9 +166,10 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
baseVo.setData(payVo);
return baseVo;
} catch (Exception e) {
log.error("|{}|第三方支付异常dto|{}|walletType|{}|error|{}|", TAG, JSONUtil.toJsonStr(dto), walletType, e.getMessage());
baseVo.set(ThirdPayVoStatusEnum.UNKNOWN_ERROR);
return baseVo;
String msg = String.format("|%s|第三方支付异常dto|%s|walletType|%s|", TAG, JSONUtil.toJsonStr(dto), walletType);
log.error(msg, e.getMessage());
// 抛出错误
throw new RuntimeException(msg);
}
}
@@ -160,18 +178,34 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
*/
@Override
@Transactional(rollbackFor = Exception.class)
public PayBaseVo<RefundVo> walletRefund(RefundDto dto) {
public PayBaseVo<RefundVo> walletRefund(RefundDto dto, ThirdPaySoureBizTypeEnum soureType) {
PayBaseVo baseVo = new PayBaseVo<RefundVo>();
try {
// 查询用户
UserInfo userDetail = userService.getInnerByUserId(dto.getUserId()).getData();
if (ObjectUtil.isEmpty(userDetail)) {
baseVo.set(ThirdPayVoStatusEnum.USER_EXIST);
String orderType = getOrderType(soureType);
// 订单是否存在
long orderCount = hardOrderService.count(new LambdaQueryWrapper<HardOrderEntity>()
.eq(HardOrderEntity::getId, dto.getPlatformOrderId())
.eq(HardOrderEntity::getOrderType, orderType)
.eq(HardOrderEntity::getOrderStatus, HardOrderStatusEnum.PAY.getType())
);
if (orderCount <= 0) {
baseVo.set(ThirdPayVoStatusEnum.ORDER_EXIST);
return baseVo;
}
// 退款id是否重复
long refundCount = hardAfterSaleService.count(new LambdaQueryWrapper<HardAfterSaleEntity>()
.eq(HardAfterSaleEntity::getNo, dto.getThirdRefundId())
.eq(HardAfterSaleEntity::getType, HardSaleTypeEnum.AFTER_SALE.getType())
.eq(HardAfterSaleEntity::getStatus, HardSaleStatusEnum.COMPLETE.getStatus())
);
if (refundCount > 0) {
baseVo.set(ThirdPayVoStatusEnum.ORDER_HAVE_REFUND);
return baseVo;
}
// 是否已退款
HardOrderVo order = hardAfterSaleService.validateOrderCanRefund(Long.valueOf(dto.getPlatformOrderId()));
if (ObjectUtil.isEmpty(userDetail)) {
baseVo.set(ThirdPayVoStatusEnum.ORDER_EXIST);
if (ObjectUtil.isEmpty(order)) {
baseVo.set(ThirdPayVoStatusEnum.ORDER_HAVE_REFUND);
return baseVo;
}
// 添加售后订单
@@ -181,7 +215,7 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
saveObj.setNo(dto.getThirdRefundId());
saveObj.setWay("10");
saveObj.setOrderId(order.getId());
saveObj.setRefundPrice(order.getPayPrice());
saveObj.setRefundPrice(dto.getPrice());
saveObj.setUserId(order.getUserId());
saveObj.setAuditUserId(null);
saveObj.setAuditTime(LocalDateTime.now());
@@ -212,19 +246,82 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
baseVo.setData(refundVo);
return baseVo;
} catch (Exception e) {
log.error("|{}|第三方退款dto|{}|error|{}|", TAG, JSONUtil.toJsonStr(dto), e.getMessage());
baseVo.set(ThirdPayVoStatusEnum.UNKNOWN_ERROR);
return baseVo;
String msg = String.format("|%s|第三方退款错误,dto|%s|", TAG, JSONUtil.toJsonStr(dto));
log.error(msg, e.getMessage());
// 抛出错误
throw new RuntimeException(msg);
}
}
/**
* 获取流水
*/
@Override
public PayBaseVo<List<PayWaterVo>> waterList(WaterDto dto, ThirdPaySoureBizTypeEnum soureType) {
String orderType = getOrderType(soureType);
Page page = new Page<>();
page.setCurrent(dto.getCurrent());
page.setSize(dto.getSize());
HardOrderDto query = new HardOrderDto();
query.setOrderType(orderType);
if (ObjectUtil.isNotEmpty(dto.getOrderStatus())) {
query.setOrderStatus(dto.getOrderStatus());
}
Page<HardOrderVo> pageList = hardOrderService.scopePageList(page, query, null);
List<HardOrderVo> records = pageList.getRecords();
List<PayWaterVo> list = new ArrayList<>();
if (ObjectUtil.isNotEmpty(pageList.getRecords())) {
for (HardOrderVo v : records) {
PayWaterVo item = new PayWaterVo();
item.setUserId(v.getUserId());
item.setName(v.getUsername());
item.setSignPhone("");
item.setPlatformOrderId(String.valueOf(v.getId()));
item.setPlatformRefundId(String.valueOf(v.getPayRefundId()));
item.setThirdOrderId(v.getOrderNo());
item.setThirdRefundId("");
item.setOrderStatus(v.getOrderStatus());
item.setOrderPrice(v.getPayPrice());
item.setRefundPrice(v.getRefundPrice());
if (ObjectUtil.isNotEmpty(v.getPayTime())) {
item.setPayTime(LocalDateTimeUtil.format(v.getPayTime(), DatePattern.NORM_DATETIME_PATTERN));
}
if (ObjectUtil.isNotEmpty(v.getRefundTime())) {
item.setRefundTime(LocalDateTimeUtil.format(v.getRefundTime(), DatePattern.NORM_DATETIME_PATTERN));
}
list.add(item);
}
}
PayBaseVo baseVo = new PayBaseVo<List<PayWaterVo>>();
baseVo.set(ThirdPayVoStatusEnum.SUCCESS);
baseVo.setData(list);
return baseVo;
}
/**
* 查询美好生活默认商户信息
*/
private MchManageVo getLbDefaultMch() {
MchManageVo defaultMch = mchService.getById(lbCallbackConfig.getMchId()).getData();
log.info("查询美好生活默认商户信息 mchId |{}|defaultMch{}", lbCallbackConfig.getMchId(), JSONUtil.toJsonStr(defaultMch));
return defaultMch;
private MchManageVo getLbDefaultMch(ThirdPaySoureBizTypeEnum type) {
switch (type) {
case LB -> {
Long lbMchId = lbCallbackConfig.getLbMchId();
if (ObjectUtil.isNotEmpty(lbMchId)) {
MchManageVo defaultMch = mchService.getById(lbMchId).getData();
log.info("查询美好生活默认商户信息 mchId |{}|defaultMch{}", lbCallbackConfig.getLbMchId(), JSONUtil.toJsonStr(defaultMch));
return defaultMch;
}
}
}
return null;
}
private String getOrderType(ThirdPaySoureBizTypeEnum type) {
switch (type) {
case LB -> {
return HardOrderTypeEnum.LB.getType();
}
}
return null;
}
/**
@@ -18,5 +18,9 @@ spring:
- optional:nacos:${spring.application.name}-@profiles.active@.yml
# 正源回调配置
#zy-callback:
# mch-id: 1909168994551459842
# zy-callback:
# mch-id: 1909168994551459842
# 第三方回调配置
# pay-callback:
# lb-mch-id: 1919673632357584898
@@ -15,6 +15,7 @@ public enum ThirdPayApiBizTypeEnum {
PAY("10", "支付"),
REFUND("20", "退款"),
WALLET_INFO("30", "钱包详情"),
WATER("40", "流水"),
;
private final String type;
@@ -20,6 +20,8 @@ public enum ThirdPayVoStatusEnum {
ORDER_EXIST(502, "订单不存在"),
MCH_EXIST(503, "第三方商户未配置"),
BALANCE_NOT_ENOUGH(505, "用户余额不足"),
ORDER_HAVE_PAY(506, "订单已支付"),
ORDER_HAVE_REFUND(507, "订单已退款"),
UNKNOWN_ERROR(599, "未知错误,请联系管理员"),
;
@@ -1,28 +1,28 @@
package com.bsd.pjcloud.thirdparty.dto.pay;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Data
public class RefundDto {
/**
* 用户id
*/
private Long userId;
/**
* 平台唯一订单号
*/
@NotEmpty(message = "平台唯一订单号不能为空")
private String platformOrderId;
/**
* 第三方退款单号
* 第三方退款流水号
*/
@NotEmpty(message = "第三方退款流水号不能为空")
private String thirdRefundId;
/**
* 退款金额(单位分)
*/
@NotNull(message = "退款金额不能为空")
private Integer price;
}
@@ -0,0 +1,26 @@
package com.bsd.pjcloud.thirdparty.dto.pay;
import lombok.Data;
@Data
public class WaterDto {
/**
* 当前页号(默认1)
*/
private Long current;
/**
* 当前页数据条数(默认100,最大200)
*/
private Long size;
/**
* 订单状态
* 1创建订单(未支付)
* 5已经支付
* 10退款
*/
private String orderStatus;
}
@@ -0,0 +1,24 @@
package com.bsd.pjcloud.thirdparty.vo.pay;
import lombok.Data;
@Data
public class PayGetWalletInfoVo {
/**
* sm4加密后的手机号
*/
private String signPhone;
/**
* 用户真实姓名
*/
private String name;
/**
* 用户余额(分)
*/
private int balance;
}
@@ -0,0 +1,71 @@
package com.bsd.pjcloud.thirdparty.vo.pay;
import lombok.Data;
@Data
public class PayWaterVo {
/**
* 用户id
*/
private Long userId;
/**
* 用户真实姓名
*/
private String name;
/**
* sm4加密后的手机号
*/
private String signPhone;
/**
* 平台订单id
*/
private String platformOrderId;
/**
* 平台退款id
*/
private String platformRefundId;
/**
* 第三方订单id
*/
private String thirdOrderId;
/**
* 第三方退款id
*/
private String thirdRefundId;
/**
* 订单状态
* 1创建订单(未支付)
* 5已经支付
* 10退款
*/
private String orderStatus;
/**
* 订单价格(分)
*/
private Integer orderPrice;
/**
* 退款金额(分)
*/
private Integer refundPrice;
/**
* 支付时间(yyyy-MM-dd HH:mm:ss格式)
*/
private String payTime;
/**
* 退款时间(yyyy-MM-dd HH:mm:ss格式)
*/
private String refundTime;
}
@@ -32,7 +32,7 @@ public class RefundVo {
private Integer price;
/**
* 退款时间
* 退款时间(yyyy-MM-dd HH:mm:ss格式)
*/
private String refundTime;
@@ -6,10 +6,7 @@ import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.thirdparty.dto.pay.PayGetWalletInfoDto;
import com.bsd.pjcloud.thirdparty.service.ThirdPayApiService;
import com.bsd.pjcloud.thirdparty.service.ThirdPayLogService;
import com.bsd.pjcloud.thirdparty.vo.pay.PayBaseVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayVo;
import com.bsd.pjcloud.thirdparty.vo.pay.PayWalletInfoVo;
import com.bsd.pjcloud.thirdparty.vo.pay.RefundVo;
import com.bsd.pjcloud.thirdparty.vo.pay.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -18,6 +15,7 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
@@ -56,5 +54,13 @@ public class ThirdPayApiController {
return thirdPayApiService.walletRefund(body, headers);
}
@Inner(value = false)
@Operation(summary = "流水查询", description = "流水查询")
@PostMapping("/water")
public PayBaseVo<List<PayWaterVo>> water(HttpEntity<String> httpEntity, @RequestHeader Map<String, String> headers) {
String body = httpEntity.getBody();
return thirdPayApiService.water(body, headers);
}
}
@@ -6,6 +6,7 @@ import com.bsd.pjcloud.thirdparty.dto.pay.PayGetWalletInfoDto;
import com.bsd.pjcloud.thirdparty.dto.pay.RefundDto;
import com.bsd.pjcloud.thirdparty.vo.pay.*;
import java.util.List;
import java.util.Map;
public interface ThirdPayApiService {
@@ -24,4 +25,9 @@ public interface ThirdPayApiService {
* 根据加密的手机号查询用户钱包信息
*/
PayBaseVo<PayWalletInfoVo> getWalletInfo(String json, Map<String, String> headers);
/**
* 流水查询
*/
PayBaseVo<List<PayWaterVo>> water(String json, Map<String, String> headers);
}
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayVoStatusEnum;
import com.bsd.pjcloud.thirdparty.dto.pay.PayDto;
import com.bsd.pjcloud.thirdparty.dto.pay.PayGetWalletInfoDto;
import com.bsd.pjcloud.thirdparty.dto.pay.RefundDto;
import com.bsd.pjcloud.thirdparty.dto.pay.WaterDto;
import com.bsd.pjcloud.thirdparty.entity.ThirdKeyManageEntity;
import com.bsd.pjcloud.thirdparty.entity.api.ThirdPayLogEntity;
import com.bsd.pjcloud.thirdparty.service.ThirdKeyManageService;
@@ -24,9 +25,11 @@ import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -68,8 +71,10 @@ public class ThirdPayApiServiceImpl implements ThirdPayApiService {
}
PayDto dto = JSONUtil.toBean(json, PayDto.class);
Set<ConstraintViolation<PayDto>> validate = Validation.buildDefaultValidatorFactory().getValidator().validate(dto);
if (ObjectUtil.isEmpty(dto)) {
if (ObjectUtil.isNotEmpty(validate)) {
String firstError = validate.iterator().next().getMessage();
baseVo.set(ThirdPayVoStatusEnum.PARAMS_ERROR);
baseVo.setMessage(firstError);
// 日志
logObj.setRes(JSONUtil.toJsonStr(baseVo));
logObj.setTimeConsuming(Long.toString(System.currentTimeMillis() - startTime));
@@ -78,7 +83,7 @@ public class ThirdPayApiServiceImpl implements ThirdPayApiService {
}
// 开始支付
try {
PayBaseVo<PayVo> payVoPayBaseVo = hardThirdPayService.walletPay(dto, WalletTypeEnum.PAY);
PayBaseVo<PayVo> payVoPayBaseVo = hardThirdPayService.walletPay(dto, WalletTypeEnum.PAY, ThirdPaySoureBizTypeEnum.valueOfByType(keySetting.getBizType()));
if (ObjectUtil.isEmpty(payVoPayBaseVo)) {
throw new RuntimeException("支付失败");
}
@@ -117,8 +122,11 @@ public class ThirdPayApiServiceImpl implements ThirdPayApiService {
return baseVo;
}
RefundDto dto = JSONUtil.toBean(json, RefundDto.class);
if (ObjectUtil.isEmpty(dto)) {
Set<ConstraintViolation<RefundDto>> validate = Validation.buildDefaultValidatorFactory().getValidator().validate(dto);
if (ObjectUtil.isNotEmpty(validate)) {
String firstError = validate.iterator().next().getMessage();
baseVo.set(ThirdPayVoStatusEnum.PARAMS_ERROR);
baseVo.setMessage(firstError);
// 日志
logObj.setRes(JSONUtil.toJsonStr(baseVo));
logObj.setTimeConsuming(Long.toString(System.currentTimeMillis() - startTime));
@@ -127,7 +135,7 @@ public class ThirdPayApiServiceImpl implements ThirdPayApiService {
}
// 开始退款
try {
PayBaseVo<RefundVo> payVoPayBaseVo = hardThirdPayService.walletRefund(dto);
PayBaseVo<RefundVo> payVoPayBaseVo = hardThirdPayService.walletRefund(dto, ThirdPaySoureBizTypeEnum.valueOfByType(keySetting.getBizType()));
if (ObjectUtil.isEmpty(payVoPayBaseVo)) {
throw new RuntimeException("退款失败");
}
@@ -210,4 +218,50 @@ public class ThirdPayApiServiceImpl implements ThirdPayApiService {
return baseVo;
}
/**
* 流水查询
*/
@Override
public PayBaseVo<List<PayWaterVo>> water(String json, Map<String, String> headers) {
// 日志
long startTime = System.currentTimeMillis();
ThirdPayLogEntity logObj = ThirdPayLogEntity.builder().apiUrl("/third/third-pay-api/water").bizType(ThirdPayApiBizTypeEnum.WATER.getType()).req(json).paySourceType(ThirdPaySoureBizTypeEnum.LB.getType()).build();
// 开始处理
PayBaseVo baseVo = new PayBaseVo<PayWalletInfoVo>();
ThirdKeyManageEntity keySetting = keyManageService.checkSignAndReturnConfig(json, headers);
if (ObjectUtil.isEmpty(keySetting)) {
baseVo.set(ThirdPayVoStatusEnum.SIGN_ERROR);
// 日志
logObj.setRes(JSONUtil.toJsonStr(baseVo));
logObj.setTimeConsuming(Long.toString(System.currentTimeMillis() - startTime));
payLogService.save(logObj);
return baseVo;
}
// 处理一下查询参数
WaterDto dto = JSONUtil.toBean(json, WaterDto.class);
if (ObjectUtil.isEmpty(dto.getCurrent())) dto.setCurrent(1L);
if (ObjectUtil.isEmpty(dto.getSize())) dto.setSize(100L);
if (dto.getSize() > 200L) dto.setSize(200L);
try {
PayBaseVo<List<PayWaterVo>> pageList = hardThirdPayService.waterList(dto, ThirdPaySoureBizTypeEnum.valueOfByType(keySetting.getBizType()));
if (ObjectUtil.isEmpty(pageList.getData())) {
baseVo.set(ThirdPayVoStatusEnum.UNKNOWN_ERROR);
baseVo.setData(pageList.getData());
// 日志
logObj.setRes(JSONUtil.toJsonStr(baseVo));
logObj.setTimeConsuming(Long.toString(System.currentTimeMillis() - startTime));
payLogService.save(logObj);
return baseVo;
}
return pageList;
} catch (Exception e) {
log.error("|{}|流水查询,json|{}|headers|{}|", TAG, json, headers, e);
baseVo.set(ThirdPayVoStatusEnum.UNKNOWN_ERROR);
// 日志
logObj.setRes(JSONUtil.toJsonStr(baseVo));
logObj.setTimeConsuming(Long.toString(System.currentTimeMillis() - startTime));
payLogService.save(logObj);
return baseVo;
}
}
}
@@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -33,6 +34,8 @@ public class PayTest {
private final String walletRefundUrl = "/third/third-pay-api/wallet-refund";
private final String waterUrl = "/third/third-pay-api/water";
@Resource
private ThirdKeyManageService keyManageService;
@@ -57,8 +60,8 @@ public class PayTest {
@Test
public void walletPay() throws Exception {
Map<String, Object> paramsMap = new HashMap<>();
// paramsMap.put("userId", 1875049673022279681L);
paramsMap.put("thirdOrderId", "1");
paramsMap.put("userId", 1875049673022279681L);
paramsMap.put("thirdOrderId", "5");
paramsMap.put("price", 100);
paramsMap.put("products", null);
String body = JSONUtil.toJsonStr(paramsMap);
@@ -71,7 +74,22 @@ public class PayTest {
@Test
public void walletCarPay() throws Exception {
ThirdKeyManageEntity config = getLbConfig();
// 购物车
List<Map<String, Object>> carList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
int index = i + 1;
Map<String, Object> item = new HashMap<>();
item.put("name", "商品-" + index);
item.put("pic", "https://cdn-mms.hktvmall.com/HKTV/mms/uploadProductImage/bf8b/516f/5211/mNyyBROdFu20240514003744_1200.png");
item.put("price", index * 100);
item.put("count", index);
carList.add(item);
}
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("userId", 1875049673022279681L);
paramsMap.put("thirdOrderId", System.currentTimeMillis());
paramsMap.put("price", 1500);
paramsMap.put("products", carList);
String body = JSONUtil.toJsonStr(paramsMap);
// 发送请求
String res = HttpRequest.post(baseUrl + walletPayUrl).contentType("application/json").header(apiCountersign(body)).body(body).execute().body();
@@ -83,12 +101,34 @@ public class PayTest {
public void walletRefund() throws Exception {
ThirdKeyManageEntity config = getLbConfig();
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("platformOrderId", "1919704180908027905");
paramsMap.put("thirdRefundId", "10");
paramsMap.put("price", "1000");
String body = JSONUtil.toJsonStr(paramsMap);
// 发送请求
String res = HttpRequest.post(baseUrl + walletRefundUrl).contentType("application/json").header(apiCountersign(body)).body(body).execute().body();
log.info(res);
}
// 查询流水
@Test
public void water() throws Exception {
ThirdKeyManageEntity config = getLbConfig();
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("current", 1);
paramsMap.put("size", 500);
/**
* 1创建订单(未支付)
* 5已经支付
* 10退款
*/
paramsMap.put("orderStatus", "10");
String body = JSONUtil.toJsonStr(paramsMap);
// 发送请求
String res = HttpRequest.post(baseUrl + waterUrl).contentType("application/json").header(apiCountersign(body)).body(body).execute().body();
log.info(res);
}
private ThirdKeyManageEntity getLbConfig() {
return keyManageService.get(ThirdKeyTypeEnum.LB);
}
@@ -83,6 +83,10 @@ public interface RemoteUserService {
@PostMapping("/user/list")
R<List<SysUser>> getUserById(@RequestBody List<Long> userIds);
@NoToken
@PostMapping("/user/inner/list")
R<List<SysUser>> getInnerUserById(@RequestBody List<Long> userIds);
@PostMapping("/user/user-dept")
R<List<UserVO>> getUserDeptByIds(@RequestBody List<Long> userIds);
@@ -396,15 +396,18 @@ public class SysUserController {
/**
* 根据IDS获取用户列表
*
* @param userIds ID列表
* @return 用户列表
*/
@PostMapping("/list")
public R<List<SysUser>> getUserListByIds(@RequestBody List<Long> userIds) {
return R.ok(userService.list(Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserId, userIds)));
}
@Inner
@PostMapping("/inner/list")
public R<List<SysUser>> getInnerUserListByIds(@RequestBody List<Long> userIds) {
return R.ok(userService.list(Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserId, userIds)));
}
@PostMapping("/user-dept")
public R<List<UserVO>> getUserDeptByIds(@RequestBody List<Long> userIds) {
return R.ok(userService.getUserDeptByIds(userIds));
@@ -439,7 +442,7 @@ public class SysUserController {
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysUserLambdaQueryWrapper.like(StringUtils.isNotBlank(mobile), SysUser::getPhone, mobile);
sysUserLambdaQueryWrapper.like(StringUtils.isNotBlank(name), SysUser::getName, name);
sysUserLambdaQueryWrapper.eq(null!=userId,SysUser::getUserId, userId);
sysUserLambdaQueryWrapper.eq(null != userId, SysUser::getUserId, userId);
List<SimpleUserAllListVO> list = userService.listScope(sysUserLambdaQueryWrapper);
return R.ok(list);
}