Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
45b8e69402
25 files changed
+673
-110
No files matched your search
@@ -42,5 +42,11 @@
|
||||
<groupId>com.bsd</groupId>
|
||||
<artifactId>pjcloud-common-excel</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
<artifactId>pjcloud-wallet-api</artifactId>
|
||||
<version>5.7.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.bsd.pjcloud.thirdparty.api.feign;
|
||||
|
||||
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
|
||||
@FeignClient(contextId = "remoterThirdAppPlusPayService", value = ServiceNameConstants.THIRDPARTY_SERVICE)
|
||||
public interface RemoterThirdAppPlusPayService {
|
||||
|
||||
/**
|
||||
* 编辑商户的回调
|
||||
*/
|
||||
@NoToken
|
||||
@PostMapping("/remoter/change-mch")
|
||||
R<Boolean> remoterChangeMch(@RequestBody MchManageVo dto);
|
||||
|
||||
}
|
||||
+6
@@ -3,7 +3,13 @@ package com.bsd.pjcloud.thirdparty.dto.pay;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class ThirdFzOrderDto extends ThirdFzOrderEntity {
|
||||
|
||||
private LocalDateTime[] fzTimeList;
|
||||
|
||||
private LocalDateTime[] fzRefundTimeList;
|
||||
|
||||
}
|
||||
+7
@@ -26,6 +26,13 @@ public class ThirdFzOrderEntity extends Model<ThirdFzOrderEntity> {
|
||||
@Schema(description = "主键")
|
||||
private Long id;
|
||||
|
||||
|
||||
/**
|
||||
* 分账金额
|
||||
*/
|
||||
@Schema(description = "分账金额")
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 支付订单号
|
||||
*/
|
||||
|
||||
+24
@@ -84,6 +84,12 @@ public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
@Schema(description = "支付金额(分)")
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 分账分掉的金额(分)
|
||||
*/
|
||||
@Schema(description = "分账分掉的金额(分)")
|
||||
private Integer fzPrice;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
@@ -156,6 +162,24 @@ public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
@Schema(description = "订单过期时间")
|
||||
private LocalDateTime expireTime;
|
||||
|
||||
/**
|
||||
* 是否开启分账
|
||||
*/
|
||||
@Schema(description = "是否开启分账")
|
||||
private String enableFz;
|
||||
|
||||
/**
|
||||
* 业务回调是否完成
|
||||
*/
|
||||
@Schema(description = "业务回调是否完成")
|
||||
private String isBizCallback;
|
||||
|
||||
/**
|
||||
* 是否分账成功
|
||||
*/
|
||||
@Schema(description = "是否分账成功")
|
||||
private String isFzSuccess;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
||||
+3
@@ -3,7 +3,10 @@ package com.bsd.pjcloud.thirdparty.vo.pay;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class ThirdFzOrderVo extends ThirdFzOrderEntity {
|
||||
|
||||
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdAppPlusPayService
|
||||
com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdKsService
|
||||
com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdDoorApiService
|
||||
com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdLbApiService
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.bsd.pjcloud.thirdparty.controller.appplus;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformPayType;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.pay.wechat.ThirdMiniWechatRefundDto;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusWechatFzService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.appplus.pay.ThirdMiniAppPayVo;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletManageDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchPaySettingEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.mch.MchPaySettingVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/remoter")
|
||||
@Tag(description = "remoter", name = "小程序支付")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class ThirdAppPlusController {
|
||||
|
||||
private final ThirdAppPlusWechatFzService appPlusWechatFzService;
|
||||
|
||||
@Operation(summary = "支付退款")
|
||||
@PostMapping("/change-mch")
|
||||
@Inner
|
||||
public R<Boolean> remoterChangeMch(@RequestBody MchManageVo dto) {
|
||||
if (ObjectUtil.isNotEmpty(dto)) {
|
||||
List<MchPaySettingVo> paySettingList = dto.getPaySettingList();
|
||||
if (ObjectUtil.isNotEmpty(paySettingList)) {
|
||||
for (MchPaySettingVo v : paySettingList) {
|
||||
if (ObjectUtil.equals(v.getPlatformType(), AppPlusPlatformPayType.WECHAT.getType())) {
|
||||
MchPaySettingEntity.WechatPaySetting jsonSetting = JSONUtil.toBean(v.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
if (ObjectUtil.isNotEmpty(jsonSetting)) {
|
||||
appPlusWechatFzService.addReceiver(jsonSetting.getSubMchid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return R.ok(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+5
-3
@@ -1,11 +1,14 @@
|
||||
package com.bsd.pjcloud.thirdparty.controller.pay;
|
||||
|
||||
;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdFzOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdFzOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdFzOrderVo;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
@@ -33,9 +36,8 @@ public class ThirdFzOrderController {
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdFzOrder_view')")
|
||||
public R getThirdFzOrderPage(@ParameterObject Page page, @ParameterObject ThirdFzOrderEntity thirdFzOrder) {
|
||||
LambdaQueryWrapper<ThirdFzOrderEntity> wrapper = Wrappers.lambdaQuery();
|
||||
return R.ok(thirdFzOrderService.page(page, wrapper));
|
||||
public R<Page<ThirdFzOrderVo>> getThirdFzOrderPage(@ParameterObject Page page, @ParameterObject ThirdFzOrderDto dto) {
|
||||
return R.ok(thirdFzOrderService.scopePageList(page, dto, null));
|
||||
}
|
||||
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.bsd.pjcloud.thirdparty.job;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderStatusEnum;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ThirdAppPlusPayJob {
|
||||
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
private final ThirdAppPlusService thirdAppPlusService;
|
||||
|
||||
/**
|
||||
* 处理,未勾起业务回调的订单
|
||||
*/
|
||||
public void handleUnBizCallbackOrder() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 查询10分钟前未出发业务回调的订单
|
||||
List<ThirdPayOrderEntity> list = thirdPayOrderService.list(new LambdaQueryWrapper<ThirdPayOrderEntity>()
|
||||
.eq(ThirdPayOrderEntity::getIsBizCallback, YesNoEnum.NO.getCode())
|
||||
.in(ThirdPayOrderEntity::getStatus, List.of(
|
||||
ThirdPayOrderStatusEnum.PAY_SUCCESS.getType(),
|
||||
ThirdPayOrderStatusEnum.REFUNDING.getType(),
|
||||
ThirdPayOrderStatusEnum.REFUND_SUCCESS.getType(),
|
||||
ThirdPayOrderStatusEnum.REFUND_FAILED.getType()
|
||||
))
|
||||
.between(ThirdPayOrderEntity::getCreateTime, now.minusMinutes(11), now)
|
||||
);
|
||||
if (ObjectUtil.isEmpty(list)) return;
|
||||
for (ThirdPayOrderEntity item : list) {
|
||||
thirdAppPlusService.queryPayResult(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理,长时间未支付的订单(1个小时不支付)
|
||||
*/
|
||||
|
||||
}
|
||||
+6
@@ -1,11 +1,17 @@
|
||||
package com.bsd.pjcloud.thirdparty.mapper.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdFzOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdFzOrderVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface ThirdFzOrderMapper extends PjcloudBaseMapper<ThirdFzOrderEntity> {
|
||||
|
||||
Page<ThirdFzOrderVo> scopePageList(Page page, @Param("dto") ThirdFzOrderDto dto, DataScope dataScope);
|
||||
|
||||
}
|
||||
+7
@@ -4,6 +4,7 @@ import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.pay.wechat.ThirdMiniWechatRefundDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.vo.appplus.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.appplus.pay.ThirdMiniAppPayVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
@@ -42,6 +43,12 @@ public interface ThirdAppPlusService {
|
||||
*/
|
||||
String miniPayCallback(Map<String, String> parameterMap, String body, Map<String, String> headers);
|
||||
|
||||
/**
|
||||
* 手动查询支付结果
|
||||
*/
|
||||
|
||||
void queryPayResult(ThirdPayOrderEntity dto);
|
||||
|
||||
/**
|
||||
* 小程序退款回调
|
||||
*/
|
||||
|
||||
+27
@@ -1,8 +1,10 @@
|
||||
package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.wechat.pay.java.service.profitsharing.model.OrdersEntity;
|
||||
import com.wechat.pay.java.service.profitsharing.model.ReturnOrdersEntity;
|
||||
|
||||
public interface ThirdAppPlusWechatFzService {
|
||||
|
||||
@@ -11,4 +13,29 @@ public interface ThirdAppPlusWechatFzService {
|
||||
*/
|
||||
OrdersEntity create(ThirdPayOrderEntity orderEntity);
|
||||
|
||||
/**
|
||||
* 分账退款
|
||||
*/
|
||||
ReturnOrdersEntity refund(ThirdPayOrderEntity orderEntity);
|
||||
|
||||
|
||||
/**
|
||||
* 查询分账
|
||||
*/
|
||||
OrdersEntity getFzOrder(ThirdFzOrderEntity fzOrder);
|
||||
|
||||
/**
|
||||
* 查询分账退款
|
||||
*/
|
||||
ReturnOrdersEntity getFzRefundOrder(ThirdFzOrderEntity fzOrder);
|
||||
|
||||
/**
|
||||
* 添加分账方
|
||||
*/
|
||||
boolean addReceiver(String targetMchId);
|
||||
|
||||
/**
|
||||
* 删除分账接收方
|
||||
*/
|
||||
boolean deleteReceiver(String targetMchId);
|
||||
}
|
||||
+7
@@ -1,8 +1,15 @@
|
||||
package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdFzOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdFzOrderVo;
|
||||
|
||||
public interface ThirdFzOrderService extends IService<ThirdFzOrderEntity> {
|
||||
|
||||
Page<ThirdFzOrderVo> scopePageList(Page page, ThirdFzOrderDto dto, DataScope dataScope);
|
||||
|
||||
ThirdFzOrderEntity getByPayNo(String payNo);
|
||||
}
|
||||
+78
-58
@@ -17,6 +17,7 @@ import com.bsd.pjcloud.app.api.dto.AppAdminSyncDto;
|
||||
import com.bsd.pjcloud.app.api.dto.AppUserInfo;
|
||||
import com.bsd.pjcloud.app.api.feign.RemoteAppUserService;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.thirdparty.config.AppPlusPayConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformLoginErrorEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformPayType;
|
||||
@@ -158,8 +159,6 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
if (ObjectUtil.isEmpty(detail)) return null;
|
||||
if (ObjectUtil.notEqual(detail.getUserId(), userId)) return null;
|
||||
|
||||
boolean isPaySuccessAfter = manualQueyPayResult(detail);
|
||||
|
||||
detail = thirdPayOrderService.getByPayNo(payNo);
|
||||
ThirdPayOrderVo vo = BeanUtil.toBean(detail, ThirdPayOrderVo.class);
|
||||
// 查询商户
|
||||
@@ -172,62 +171,6 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
public boolean manualQueyPayResult(ThirdPayOrderEntity payOrder) {
|
||||
ThirdPayOrderEntity update = new ThirdPayOrderEntity();
|
||||
update.setId(payOrder.getId());
|
||||
|
||||
// 判断是否为支付中,如果是则查询支付
|
||||
if (ObjectUtil.equals(payOrder.getStatus(), ThirdPayOrderStatusEnum.PAY_UNPAID.getType()) || ObjectUtil.equals(payOrder.getStatus(), ThirdPayOrderStatusEnum.REFUNDING.getType())) {
|
||||
// 微信
|
||||
if (ObjectUtil.equals(payOrder.getPayPlatformType(), AppPlusPlatformTypeEnum.WECHAT.getType())) {
|
||||
Transaction query = thirdMiniAppWechatService.query(payOrder.getPayNo(), payOrder.getMchPaySettingJson());
|
||||
Transaction.TradeStateEnum tradeState = query.getTradeState();
|
||||
// 支付成功
|
||||
if (ObjectUtil.equals(tradeState, Transaction.TradeStateEnum.SUCCESS)) {
|
||||
update.setPayTime(LocalDateTime.now());
|
||||
update.setPayRes(JSONUtil.toJsonStr(query));
|
||||
update.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
// thirdPayOrderService.updateById(update);
|
||||
return true;
|
||||
}
|
||||
// 退款成功
|
||||
else if (ObjectUtil.equals(tradeState, Transaction.TradeStateEnum.REFUND)) {
|
||||
update.setRefundTime(LocalDateTime.now());
|
||||
update.setRefundRes(JSONUtil.toJsonStr(query));
|
||||
update.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
// thirdPayOrderService.updateById(update);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// 支付宝
|
||||
else if (ObjectUtil.equals(payOrder.getPayPlatformType(), AppPlusPlatformTypeEnum.ALI_PAY.getType())) {
|
||||
AlipayTradeQueryResponse query = thirdMiniAppAliPayService.query(payOrder.getPayNo(), payOrder.getMchPaySettingJson());
|
||||
String tradeStatus = query.getTradeStatus();
|
||||
// 支付成功
|
||||
if (ObjectUtil.equals("TRADE_SUCCESS", tradeStatus)) {
|
||||
update.setPayTime(LocalDateTime.now());
|
||||
update.setPayRes(JSONUtil.toJsonStr(query));
|
||||
update.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
thirdPayOrderService.updateById(update);
|
||||
return true;
|
||||
}
|
||||
// 退款成功
|
||||
else if (ObjectUtil.equals("TRADE_CLOSED", tradeStatus)) {
|
||||
update.setRefundTime(LocalDateTime.now());
|
||||
update.setRefundRes(JSONUtil.toJsonStr(query));
|
||||
update.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
thirdPayOrderService.updateById(update);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序支付
|
||||
*/
|
||||
@@ -366,6 +309,9 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
@Override
|
||||
public String miniPayCallback(Map<String, String> params, String body, Map<String, String> headers) {
|
||||
AppPlusPlatformTypeEnum platformType = checkMiniPlatformType(params, body, headers);
|
||||
|
||||
ThirdPayOrderEntity updateObj = new ThirdPayOrderEntity();
|
||||
|
||||
// 微信小程序
|
||||
if (ObjectUtil.equals(platformType, AppPlusPlatformTypeEnum.WECHAT)) {
|
||||
ThirdPayOrderEntity thirdPayOrder = thirdMiniAppWechatService.payCallback(body, headers);
|
||||
@@ -374,6 +320,11 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
}
|
||||
// 根据订单bizType来处理
|
||||
boolean isSuccess = disposePaySuccessAfter(thirdPayOrder);
|
||||
if (isSuccess) {
|
||||
updateObj.setId(thirdPayOrder.getId());
|
||||
updateObj.setIsBizCallback(YesNoEnum.YES.getCode());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
}
|
||||
return isSuccess ? "success" : "fail";
|
||||
}
|
||||
// 支付宝
|
||||
@@ -384,6 +335,12 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
}
|
||||
// 根据订单bizType来处理
|
||||
boolean isSuccess = disposePaySuccessAfter(thirdPayOrder);
|
||||
// 更新
|
||||
if (isSuccess) {
|
||||
updateObj.setId(thirdPayOrder.getId());
|
||||
updateObj.setIsBizCallback(YesNoEnum.YES.getCode());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
}
|
||||
return isSuccess ? ThirdALiPayCallbackVo.aliPaySuccess() : ThirdALiPayCallbackVo.aliPayFail();
|
||||
}
|
||||
// 不支持的支付类型
|
||||
@@ -392,6 +349,69 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queryPayResult(ThirdPayOrderEntity dto) {
|
||||
ThirdPayOrderEntity updateObj = new ThirdPayOrderEntity();
|
||||
boolean isUpdateOrder = false;
|
||||
// 微信小程序
|
||||
if (ObjectUtil.equals(dto.getPayPlatformType(), AppPlusPlatformTypeEnum.WECHAT)) {
|
||||
Transaction thirdPayOrder = thirdMiniAppWechatService.query(dto.getPayNo(), dto.getMchPaySettingJson());
|
||||
if (ObjectUtil.isEmpty(thirdPayOrder) || ObjectUtil.isEmpty(thirdPayOrder.getTradeState())) {
|
||||
return;
|
||||
}
|
||||
Transaction.TradeStateEnum tradeState = thirdPayOrder.getTradeState();
|
||||
if (ObjectUtil.equals(tradeState, Transaction.TradeStateEnum.SUCCESS)) {
|
||||
if (ObjectUtil.equals(dto.getStatus(), ThirdPayOrderStatusEnum.PAY_UNPAID.getType())) {
|
||||
// 执行支付成功的代码
|
||||
updateObj.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
updateObj.setPayTime(LocalDateTime.now());
|
||||
isUpdateOrder = true;
|
||||
}
|
||||
if (ObjectUtil.notEqual(dto.getIsBizCallback(), YesNoEnum.YES.getCode())) {
|
||||
dto.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
boolean isSuccess = disposePaySuccessAfter(dto);
|
||||
if (isSuccess) {
|
||||
isUpdateOrder = true;
|
||||
updateObj.setIsBizCallback(YesNoEnum.YES.getCode());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 支付宝
|
||||
else if (ObjectUtil.equals(dto.getPayPlatformType(), AppPlusPlatformTypeEnum.ALI_PAY)) {
|
||||
AlipayTradeQueryResponse aliRes = thirdMiniAppAliPayService.query(dto.getPayNo(), dto.getMchPaySettingJson());
|
||||
if (ObjectUtil.isEmpty(aliRes) || ObjectUtil.isEmpty(aliRes.getTradeStatus())) {
|
||||
return;
|
||||
}
|
||||
String tradeStatus = aliRes.getTradeStatus();
|
||||
if (ObjectUtil.equals(tradeStatus, "TRADE_SUCCESS")) {
|
||||
if (ObjectUtil.equals(dto.getStatus(), ThirdPayOrderStatusEnum.PAY_UNPAID.getType())) {
|
||||
// 执行支付成功的代码
|
||||
updateObj.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
updateObj.setPayTime(LocalDateTime.now());
|
||||
isUpdateOrder = true;
|
||||
}
|
||||
if (ObjectUtil.notEqual(dto.getIsBizCallback(), YesNoEnum.YES.getCode())) {
|
||||
dto.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
boolean isSuccess = disposePaySuccessAfter(dto);
|
||||
if (isSuccess) {
|
||||
isUpdateOrder = true;
|
||||
updateObj.setIsBizCallback(YesNoEnum.YES.getCode());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 不支持的支付类型
|
||||
else {
|
||||
return;
|
||||
}
|
||||
if (isUpdateOrder) {
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序退款回调
|
||||
*/
|
||||
|
||||
+33
-7
@@ -9,6 +9,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.thirdparty.config.AppPlusPayConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderStatusEnum;
|
||||
@@ -33,6 +34,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
@@ -42,6 +44,9 @@ import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 微信小程序(app版本)
|
||||
@@ -65,6 +70,8 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
private final ProfitsharingService profitsharingService;
|
||||
private final ThirdAppPlusWechatFzLifecycle appPlusWechatFzLifecycle;
|
||||
|
||||
private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
|
||||
/**
|
||||
* APP支付
|
||||
*/
|
||||
@@ -98,7 +105,7 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
request.setSpMchid(wechatConfig.getMerchantId());
|
||||
request.setSubMchid(dto.getSubMchid());
|
||||
request.setDescription(description);
|
||||
// request.setSettleInfo(settleInfo);
|
||||
request.setSettleInfo(settleInfo);
|
||||
request.setOutTradeNo(dto.getOutTradeNo());
|
||||
request.setNotifyUrl(wechatConfig.getBaseCallbackUrl() + wechatConfig.getPayCallbackUrl());
|
||||
|
||||
@@ -170,12 +177,11 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
req.setSpMchid(wechatConfig.getMerchantId());
|
||||
req.setSubMchid(wechatPaySetting.getSubMchid());
|
||||
req.setOutTradeNo(payNo);
|
||||
Transaction transaction = appServiceExtension.queryOrderByOutTradeNo(req);
|
||||
return appServiceExtension.queryOrderByOutTradeNo(req);
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|查询订单,异常", TAG, e);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,15 +194,20 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
}
|
||||
|
||||
/**
|
||||
* AP申请退款
|
||||
* APP申请退款
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public ThirdPayOrderEntity refund(ThirdPayOrderEntity thirdPayOrder, ThirdMiniWechatRefundDto dto) {
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
|
||||
if (ObjectUtil.isEmpty(thirdPayOrder.getMchPaySettingJson())) {
|
||||
throw new RuntimeException("支付配置不存在");
|
||||
}
|
||||
|
||||
// 订单退款前的回调
|
||||
boolean isFzRefund = appPlusWechatFzLifecycle.beforeOrderRefund(thirdPayOrder);
|
||||
|
||||
MchPaySettingEntity wechatPaySettingEntity = JSONUtil.toBean(thirdPayOrder.getMchPaySettingJson(), MchPaySettingEntity.class);
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(wechatPaySettingEntity.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
|
||||
@@ -207,6 +218,9 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
if (ObjectUtil.isEmpty(refundFee)) {
|
||||
refundFee = thirdPayOrder.getPrice();
|
||||
}
|
||||
if (!isFzRefund) {
|
||||
refundFee = thirdPayOrder.getPrice() - thirdPayOrder.getFzPrice();
|
||||
}
|
||||
String refundNo = "refund_" + thirdPayOrder.getPayNo();
|
||||
|
||||
CreateRequest createRequest = new CreateRequest();
|
||||
@@ -230,12 +244,12 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
try {
|
||||
Refund refund = refundService.create(createRequest);
|
||||
updateObj.setRefundRes(JSONUtil.toJsonStr(refund));
|
||||
if (ObjectUtil.isNotEmpty(refund)) {
|
||||
if (ObjectUtil.isEmpty(refund)) {
|
||||
throw new RuntimeException("微信退款申请错误异常");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|AP申请退款,异常", TAG, e);
|
||||
return null;
|
||||
throw new RuntimeException(e.getMessage());
|
||||
} finally {
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
}
|
||||
@@ -278,12 +292,24 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
updateObj.setThirdPayNo(transaction.getTransactionId());
|
||||
updateObj.setId(payOrderEntity.getId());
|
||||
updateObj.setPayCallbackRes(JSONUtil.toJsonStr(transaction));
|
||||
updateObj.setEnableFz(YesNoEnum.YES.getCode());
|
||||
updateObj.setIsBizCallback(YesNoEnum.NO.getCode());
|
||||
updateObj.setStatus(paySucess ? ThirdPayOrderStatusEnum.PAY_SUCCESS.getType() : ThirdPayOrderStatusEnum.PAY_FAILED.getType());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
|
||||
ThirdPayOrderEntity result = thirdPayOrderService.getById(payOrderEntity.getId());
|
||||
// 订单支付成功
|
||||
appPlusWechatFzLifecycle.orderPaySuccess(result);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
Thread.sleep(30000);
|
||||
appPlusWechatFzLifecycle.orderPaySuccess(result);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error("|{}|延迟调用orderPaySuccess被中断", TAG, e);
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|延迟调用orderPaySuccess异常", TAG, e);
|
||||
}
|
||||
}, executorService);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -35,7 +35,9 @@ public interface AppPlusOrderLifecycle {
|
||||
* 订单退款前
|
||||
* @param order 支付订单
|
||||
*/
|
||||
default void beforeOrderRefund(ThirdPayOrderEntity order) {}
|
||||
default boolean beforeOrderRefund(ThirdPayOrderEntity order) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款后
|
||||
|
||||
+189
-11
@@ -2,17 +2,19 @@ package com.bsd.pjcloud.thirdparty.service.impl.appplus.fz;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.thirdparty.config.AppPlusPayConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.fz.ThirdFzOrderStatusEnum;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.mapper.pay.ThirdFzOrderMapper;
|
||||
import com.bsd.pjcloud.thirdparty.mapper.pay.ThirdPayOrderMapper;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusWechatFzService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdFzOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchPaySettingEntity;
|
||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||
import com.wechat.pay.java.service.profitsharing.model.CreateOrderReceiver;
|
||||
import com.wechat.pay.java.service.profitsharing.model.CreateOrderRequest;
|
||||
import com.wechat.pay.java.service.profitsharing.model.OrdersEntity;
|
||||
import com.wechat.pay.java.service.profitsharing.model.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -37,7 +39,10 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
private final AppPlusPayConfig appPlusPayConfig;
|
||||
|
||||
private final ProfitsharingService profitsharingService;
|
||||
private final ThirdFzOrderService fzOrderService;
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
|
||||
private final ThirdPayOrderMapper thirdPayOrderMapper;
|
||||
private final ThirdFzOrderMapper thirdFzOrderMapper;
|
||||
|
||||
/**
|
||||
@@ -54,29 +59,54 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
log.info("|{}|订单金额太小,无需分账,订单号:{}", TAG, orderEntity.getPayNo());
|
||||
return null;
|
||||
}
|
||||
// 目前理论之能分一次账
|
||||
ThirdFzOrderEntity fzOrderDetail = fzOrderService.getByPayNo(orderEntity.getPayNo());
|
||||
if (ObjectUtil.isNotEmpty(fzOrderDetail)) {
|
||||
log.info("|{}|订单分账,订单号:{}", TAG, orderEntity.getPayNo());
|
||||
return null;
|
||||
}
|
||||
MchPaySettingEntity mchPaySetting = JSONUtil.toBean(orderEntity.getMchPaySettingJson(), MchPaySettingEntity.class);
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(mchPaySetting.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
if (mchPaySetting.getFzRatio() <= 0) {
|
||||
log.info("|{}|订单分账错误,分账比例为0,订单号:{}", TAG, orderEntity.getPayNo());
|
||||
return null;
|
||||
}
|
||||
|
||||
String outOrderNo = "fz" + orderEntity.getPayNo();
|
||||
|
||||
ThirdFzOrderEntity fzOrderEntity = new ThirdFzOrderEntity();
|
||||
fzOrderEntity.setPayNo(orderEntity.getPayNo());
|
||||
fzOrderEntity.setFzNo(outOrderNo);
|
||||
fzOrderEntity.setFzTime(LocalDateTime.now());
|
||||
fzOrderEntity.setStatus(ThirdFzOrderStatusEnum.FZ_UNPAID.getType());
|
||||
|
||||
MchPaySettingEntity mchPaySetting = JSONUtil.toBean(orderEntity.getMchPaySettingJson(), MchPaySettingEntity.class);
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(mchPaySetting.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
|
||||
String outOrderNo = "fz" + orderEntity.getPayNo();
|
||||
// 最少分账1分
|
||||
Long amount = BigDecimal.valueOf(orderEntity.getPrice())
|
||||
.multiply(BigDecimal.valueOf(mchPaySetting.getFzRatio()))
|
||||
.setScale(2, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100))
|
||||
.multiply(BigDecimal.valueOf(mchPaySetting.getFzRatio())).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN)
|
||||
.longValue();
|
||||
// 确保至少1分
|
||||
if (amount < 1L) {
|
||||
amount = 1L;
|
||||
}
|
||||
|
||||
ThirdPayOrderEntity thirdPayOrder = new ThirdPayOrderEntity();
|
||||
Integer fzPrice = 0;
|
||||
if (ObjectUtil.isNotEmpty(orderEntity.getFzPrice())) {
|
||||
fzPrice = orderEntity.getFzPrice();
|
||||
}
|
||||
fzPrice += BigDecimal.valueOf(amount).intValue();
|
||||
|
||||
thirdPayOrder.setId(orderEntity.getId());
|
||||
thirdPayOrder.setFzPrice(fzPrice);
|
||||
thirdPayOrder.setIsFzSuccess(YesNoEnum.YES.getCode());
|
||||
thirdPayOrderMapper.updateById(thirdPayOrder);
|
||||
|
||||
// 请求参数
|
||||
CreateOrderRequest createDto = new CreateOrderRequest();
|
||||
createDto.setSubAppid(wechatPaySetting.getSubMchid());
|
||||
createDto.setAppid(wechatConfig.getAppPlatformAppId());
|
||||
createDto.setSubMchid(wechatPaySetting.getSubMchid());
|
||||
createDto.setTransactionId(orderEntity.getThirdPayNo());
|
||||
createDto.setOutOrderNo(outOrderNo);
|
||||
CreateOrderReceiver zaxReceiver = new CreateOrderReceiver();
|
||||
@@ -88,6 +118,7 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
createDto.setReceivers(List.of(zaxReceiver));
|
||||
createDto.setUnfreezeUnsplit(true);
|
||||
try {
|
||||
fzOrderEntity.setPrice(BigDecimal.valueOf(amount).intValue());
|
||||
fzOrderEntity.setCreateReq(JSONUtil.toJsonStr(createDto));
|
||||
OrdersEntity orderRes = profitsharingService.createOrder(createDto);
|
||||
fzOrderEntity.setCreateRes(JSONUtil.toJsonStr(orderRes));
|
||||
@@ -102,6 +133,153 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分账退款
|
||||
*/
|
||||
@Override
|
||||
public ReturnOrdersEntity refund(ThirdPayOrderEntity orderEntity) {
|
||||
// 查询有没有进行分账
|
||||
ThirdFzOrderEntity fzOrderDetail = fzOrderService.getByPayNo(orderEntity.getPayNo());
|
||||
if (ObjectUtil.isEmpty(fzOrderDetail)) {
|
||||
log.info("|{}|分账退款,该订单未进行分账,订单号:{}", TAG, orderEntity.getPayNo());
|
||||
return null;
|
||||
}
|
||||
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
|
||||
MchPaySettingEntity mchPaySetting = JSONUtil.toBean(orderEntity.getMchPaySettingJson(), MchPaySettingEntity.class);
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(mchPaySetting.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
|
||||
String outOrderNo = "refund_" + fzOrderDetail.getFzNo();
|
||||
|
||||
ThirdFzOrderEntity updateObj = new ThirdFzOrderEntity();
|
||||
updateObj.setId(fzOrderDetail.getId());
|
||||
updateObj.setFzRefundTime(LocalDateTime.now());
|
||||
updateObj.setStatus(ThirdFzOrderStatusEnum.FZ_REFUNDING.getType());
|
||||
updateObj.setFzRefundNo(outOrderNo);
|
||||
|
||||
try {
|
||||
CreateReturnOrderRequest returnDto = new CreateReturnOrderRequest();
|
||||
returnDto.setSubMchid(wechatPaySetting.getSubMchid());
|
||||
returnDto.setOutOrderNo(fzOrderDetail.getFzNo());
|
||||
returnDto.setOutReturnNo(outOrderNo);
|
||||
returnDto.setReturnMchid(wechatConfig.getMerchantId());
|
||||
returnDto.setAmount((long) fzOrderDetail.getPrice());
|
||||
returnDto.setDescription("退回" + getDescription(mchPaySetting, returnDto.getAmount()));
|
||||
|
||||
updateObj.setFzRefundReq(JSONUtil.toJsonStr(returnDto));
|
||||
ReturnOrdersEntity returnOrderRes = profitsharingService.createReturnOrder(returnDto);
|
||||
updateObj.setFzRefundRes(JSONUtil.toJsonStr(returnOrderRes));
|
||||
if (ObjectUtil.equals(returnOrderRes.getResult(), ReturnOrderStatus.SUCCESS)) {
|
||||
updateObj.setStatus(ThirdFzOrderStatusEnum.FZ_REFUND_SUCCESS.getType());
|
||||
} else if (ObjectUtil.equals(returnOrderRes.getResult(), ReturnOrderStatus.FAILED)) {
|
||||
updateObj.setStatus(ThirdFzOrderStatusEnum.FZ_REFUND_SUCCESS.getType());
|
||||
}
|
||||
return returnOrderRes;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
updateObj.setFzRefundError(e.getMessage());
|
||||
log.error("|{}|分账退款意外的错误,error:|{}|", TAG, e.getMessage());
|
||||
return null;
|
||||
} finally {
|
||||
thirdFzOrderMapper.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分账
|
||||
*/
|
||||
@Override
|
||||
public OrdersEntity getFzOrder(ThirdFzOrderEntity fzOrder) {
|
||||
// 查询支付订单
|
||||
ThirdPayOrderEntity thirdPayOrder = thirdPayOrderService.getByPayNo(fzOrder.getPayNo());
|
||||
if (ObjectUtil.isEmpty(thirdPayOrder)) {
|
||||
throw new RuntimeException("支付订单不存在");
|
||||
}
|
||||
|
||||
MchPaySettingEntity mchPaySetting = JSONUtil.toBean(thirdPayOrder.getMchPaySettingJson(), MchPaySettingEntity.class);
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(mchPaySetting.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
|
||||
QueryOrderRequest queryDto = new QueryOrderRequest();
|
||||
queryDto.setOutOrderNo(fzOrder.getFzNo());
|
||||
queryDto.setSubMchid(wechatPaySetting.getSubMchid());
|
||||
queryDto.setTransactionId(thirdPayOrder.getThirdPayNo());
|
||||
|
||||
try {
|
||||
return profitsharingService.queryOrder(queryDto);
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|查询分账意外的错误,fzOrder:{},error:|{}|", TAG, JSONUtil.toJsonStr(fzOrder), e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分账退款
|
||||
*/
|
||||
@Override
|
||||
public ReturnOrdersEntity getFzRefundOrder(ThirdFzOrderEntity fzOrder) {
|
||||
// 查询支付订单
|
||||
ThirdPayOrderEntity thirdPayOrder = thirdPayOrderService.getByPayNo(fzOrder.getPayNo());
|
||||
if (ObjectUtil.isEmpty(thirdPayOrder)) {
|
||||
throw new RuntimeException("支付订单不存在");
|
||||
}
|
||||
|
||||
MchPaySettingEntity mchPaySetting = JSONUtil.toBean(thirdPayOrder.getMchPaySettingJson(), MchPaySettingEntity.class);
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(mchPaySetting.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
|
||||
QueryReturnOrderRequest queryDto = new QueryReturnOrderRequest();
|
||||
queryDto.setOutReturnNo(fzOrder.getFzRefundNo());
|
||||
queryDto.setSubMchid(wechatPaySetting.getSubMchid());
|
||||
queryDto.setOutOrderNo(fzOrder.getFzNo());
|
||||
try {
|
||||
return profitsharingService.queryReturnOrder(queryDto);
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|查询分账退款,fzOrder:{},error:|{}|", TAG, JSONUtil.toJsonStr(fzOrder), e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加分账方
|
||||
*/
|
||||
@Override
|
||||
public boolean addReceiver(String targetMchId) {
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
try {
|
||||
AddReceiverRequest createDto = new AddReceiverRequest();
|
||||
createDto.setAppid(wechatConfig.getAppPlatformAppId());
|
||||
createDto.setSubMchid(targetMchId);
|
||||
createDto.setType(ReceiverType.MERCHANT_ID);
|
||||
createDto.setAccount(wechatConfig.getMerchantId());
|
||||
createDto.setName("浙江资安信信息科技有限公司");
|
||||
createDto.setRelationType(ReceiverRelationType.SERVICE_PROVIDER);
|
||||
AddReceiverResponse result = profitsharingService.addReceiver(createDto);
|
||||
return ObjectUtil.isNotEmpty(result);
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|添加分账方targetMchId:{};,异常,error:|{}|", TAG, targetMchId, e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分账接收方
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteReceiver(String targetMchId) {
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
try {
|
||||
DeleteReceiverRequest deleteDto = new DeleteReceiverRequest();
|
||||
deleteDto.setAppid(wechatConfig.getAppPlatformAppId());
|
||||
deleteDto.setType(ReceiverType.MERCHANT_ID);
|
||||
deleteDto.setAccount(wechatConfig.getMerchantId());
|
||||
DeleteReceiverResponse result = profitsharingService.deleteReceiver(deleteDto);
|
||||
return ObjectUtil.isNotEmpty(result);
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|删除分账接收方targetMchId:{};,异常,error:|{}|", TAG, targetMchId, e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 分账描述,最多80个字
|
||||
private String getDescription(MchPaySettingEntity mchPaySetting, Long amount) {
|
||||
return "商户id:" + mchPaySetting.getMchId() + "分账" + mchPaySetting.getFzRatio() + "%即" + fenToYuan(BigDecimal.valueOf(amount)) + "元,到平台";
|
||||
|
||||
+4
-2
@@ -1,5 +1,6 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.appplus.fz.lifecycle;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusWechatFzService;
|
||||
import com.bsd.pjcloud.thirdparty.service.impl.appplus.common.AppPlusOrderLifecycle;
|
||||
@@ -49,8 +50,9 @@ public class ThirdAppPlusWechatFzLifecycle implements AppPlusOrderLifecycle {
|
||||
* @param order 支付订单
|
||||
*/
|
||||
@Override
|
||||
public void beforeOrderRefund(ThirdPayOrderEntity order) {
|
||||
AppPlusOrderLifecycle.super.beforeOrderRefund(order);
|
||||
public boolean beforeOrderRefund(ThirdPayOrderEntity order) {
|
||||
// 分账退款
|
||||
return ObjectUtil.isNotEmpty(appPlusWechatFzService.refund(order));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+23
@@ -1,15 +1,38 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdFzOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdFzOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.mapper.pay.ThirdFzOrderMapper;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdFzOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdFzOrderVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* 第三方支付分账
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ThirdFzOrderServiceImpl extends ServiceImpl<ThirdFzOrderMapper, ThirdFzOrderEntity> implements ThirdFzOrderService {
|
||||
|
||||
@Override
|
||||
public Page<ThirdFzOrderVo> scopePageList(Page page, ThirdFzOrderDto dto, DataScope dataScope) {
|
||||
return baseMapper.scopePageList(page, dto, dataScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdFzOrderEntity getByPayNo(String payNo) {
|
||||
return baseMapper.selectOne(new LambdaQueryWrapper<ThirdFzOrderEntity>()
|
||||
.eq(ThirdFzOrderEntity::getPayNo, payNo)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -2,6 +2,57 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.bsd.pjcloud.thirdparty.mapper.pay.ThirdFzOrderMapper">
|
||||
<sql id="selectA">
|
||||
select a.id,
|
||||
a.price,
|
||||
a.pay_no,
|
||||
a.fz_no,
|
||||
a.create_req,
|
||||
a.create_res,
|
||||
a.create_error,
|
||||
a.status,
|
||||
a.fz_time,
|
||||
a.fz_refund_no,
|
||||
a.fz_refund_time,
|
||||
a.fz_refund_req,
|
||||
a.fz_refund_res,
|
||||
a.fz_refund_error,
|
||||
a.create_time,
|
||||
a.update_time,
|
||||
a.create_by,
|
||||
a.update_by,
|
||||
a.del_flag,
|
||||
a.tenant_id
|
||||
</sql>
|
||||
|
||||
<sql id="whereA">
|
||||
a.del_flag = '0'
|
||||
<if test="dto.payNo != null and dto.payNo != '' ">
|
||||
and a.pay_no LIKE concat('%',#{dto.payNo},'%')
|
||||
</if>
|
||||
<if test="dto.fzNo != null and dto.fzNo != '' ">
|
||||
and a.fz_no LIKE concat('%',#{dto.fzNo},'%')
|
||||
</if>
|
||||
<if test="dto.fzRefundNo != null and dto.fzRefundNo != '' ">
|
||||
and a.fz_refund_no LIKE concat('%',#{dto.fzRefundNo},'%')
|
||||
</if>
|
||||
<if test="dto.status != null and dto.status != '' ">
|
||||
and a.status = #{dto.status}
|
||||
</if>
|
||||
<if test="dto.fzTimeList != null and dto.fzTimeList.length == 2">
|
||||
and a.fz_time between #{dto.fzTimeList[0]} and #{dto.fzTimeList[1]}
|
||||
</if>
|
||||
<if test="dto.fzRefundTimeList != null and dto.fzRefundTimeList.length == 2">
|
||||
and a.fz_refund_time between #{dto.fzRefundTimeList[0]} and #{dto.fzRefundTimeList[1]}
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="scopePageList" resultType="com.bsd.pjcloud.thirdparty.vo.pay.ThirdFzOrderVo">
|
||||
<include refid="selectA"/>
|
||||
from third_fz_order a
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
</where>
|
||||
order by a.fz_time desc, a.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
Vendored
+33
-27
@@ -3,33 +3,39 @@
|
||||
|
||||
<mapper namespace="com.bsd.pjcloud.thirdparty.mapper.pay.ThirdPayOrderMapper">
|
||||
<sql id="selectA">
|
||||
select a.id,
|
||||
a.pay_platform_type,
|
||||
a.biz_type,
|
||||
a.biz_id,
|
||||
a.user_id,
|
||||
a.user_code,
|
||||
a.mch_id,
|
||||
a.mch_pay_setting_json,
|
||||
a.price,
|
||||
a.status,
|
||||
a.pay_no,
|
||||
a.pay_time,
|
||||
a.pay_rep,
|
||||
a.pay_res,
|
||||
a.pay_callback_res,
|
||||
a.refund_no,
|
||||
a.refund_time,
|
||||
a.refund_rep,
|
||||
a.refund_res,
|
||||
a.refund_callback_res,
|
||||
a.expire_time,
|
||||
a.create_time,
|
||||
a.update_time,
|
||||
a.create_by,
|
||||
a.update_by,
|
||||
a.del_flag,
|
||||
a.tenant_id
|
||||
select
|
||||
a.id,
|
||||
a.third_pay_no,
|
||||
a.pay_platform_type,
|
||||
a.biz_type,
|
||||
a.biz_id,
|
||||
a.user_id,
|
||||
a.user_code,
|
||||
a.mch_id,
|
||||
a.mch_pay_setting_json,
|
||||
a.price,
|
||||
a.fz_price,
|
||||
a.status,
|
||||
a.pay_no,
|
||||
a.pay_time,
|
||||
a.pay_rep,
|
||||
a.pay_res,
|
||||
a.pay_callback_res,
|
||||
a.refund_no,
|
||||
a.refund_time,
|
||||
a.refund_rep,
|
||||
a.refund_res,
|
||||
a.refund_callback_res,
|
||||
a.expire_time,
|
||||
a.enable_fz,
|
||||
a.is_biz_callback,
|
||||
a.is_fz_success,
|
||||
a.create_time,
|
||||
a.update_time,
|
||||
a.create_by,
|
||||
a.update_by,
|
||||
a.del_flag,
|
||||
a.tenant_id
|
||||
</sql>
|
||||
|
||||
<sql id="whereA">
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class MchPaySettingEntity extends Model<MchPaySettingEntity> {
|
||||
* 分账比例(最高100%即分给对方商户的%)
|
||||
*/
|
||||
@Schema(description = "分账比例(最高100%即分给对方商户的%)")
|
||||
private Integer fzRatio;
|
||||
private Double fzRatio;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
|
||||
+8
@@ -263,6 +263,14 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
|
||||
if (ObjectUtil.isNotEmpty(dept)) {
|
||||
DataUtil.convertDept(detail, dept);
|
||||
}
|
||||
// 商户配置
|
||||
MchPaySettingDto paySettingDto = new MchPaySettingDto();
|
||||
paySettingDto.setMchId(detail.getId());
|
||||
paySettingDto.setEnable(YesNoEnum.YES.getCode());
|
||||
List<MchPaySettingVo> paySettingList = paySettingService.pageList(paySettingDto, null);
|
||||
if (ObjectUtil.isNotEmpty(paySettingList)) {
|
||||
detail.setPaySettingList(paySettingList);
|
||||
}
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
|
||||
+16
@@ -11,7 +11,9 @@ import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdAppPlusPayService;
|
||||
import com.bsd.pjcloud.wallet.api.dto.mch.MchPaySettingDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchPaySettingEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.mch.MchPaySettingVo;
|
||||
@@ -27,6 +29,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 商户管理
|
||||
@@ -42,6 +45,8 @@ public class MchPaySettingServiceImpl extends ServiceImpl<MchPaySettingMapper, M
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
|
||||
private final RemoterThirdAppPlusPayService thirdAppPlusPayService;
|
||||
|
||||
@Override
|
||||
public Page<MchPaySettingVo> scopePageList(Page page, MchPaySettingDto dto, DataScope dataScope) {
|
||||
return baseMapper.scopePageList(page, dto, dataScope);
|
||||
@@ -67,6 +72,16 @@ public class MchPaySettingServiceImpl extends ServiceImpl<MchPaySettingMapper, M
|
||||
throw new RuntimeException("改支付类型已经设置,请直接修改");
|
||||
}
|
||||
baseMapper.updateById(dto);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
MchManageVo mchManage = mchManageService.join(dto.getMchId());
|
||||
if (ObjectUtil.isNotEmpty(mchManage)) {
|
||||
thirdAppPlusPayService.remoterChangeMch(mchManage);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("编辑商户的回调异常:{}", e.getMessage());
|
||||
}
|
||||
});
|
||||
return dto;
|
||||
}
|
||||
|
||||
@@ -99,4 +114,5 @@ public class MchPaySettingServiceImpl extends ServiceImpl<MchPaySettingMapper, M
|
||||
}
|
||||
return count >= 1;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user