This commit is contained in:
Vinjor 2025-04-29 16:21:16 +08:00
commit fcefa000bf
5 changed files with 79 additions and 40 deletions

View File

@ -116,43 +116,51 @@ public class PayApi {
@RequestMapping("/entPay")
@ApiOperation(value = "商家转账给用户")
public JSONObject entPay(String orderNo){
LambdaQueryWrapper<MemberPoints> queryWrapper =new LambdaQueryWrapper<>();
queryWrapper.eq(MemberPoints::getOrderNo,orderNo).last("limit 1");
MemberPoints memberPoints = pointsService.getOne(queryWrapper);
if (!memberPoints.getUserId().equals(SecurityUtils.getUserId())){
throw new RuntimeException("非本人账户");
}
SysUser sysUser = sysUserService.selectUserById(memberPoints.getUserId());
// 初始化商户配置
TransferToUser.TransferToUserRequest userRequest = new TransferToUser.TransferToUserRequest();
userRequest.appid = appConfig.getAppId();
userRequest.openid=sysUser.getOpenId();
// 将元转换为分
double pointsInYuan = memberPoints.getPoints();
userRequest.transferAmount = BigDecimal.valueOf(pointsInYuan).multiply(BigDecimal.valueOf(100)).setScale(0, RoundingMode.HALF_UP).longValue();
try{
LambdaQueryWrapper<MemberPoints> queryWrapper =new LambdaQueryWrapper<>();
queryWrapper.eq(MemberPoints::getOrderNo,orderNo).last("limit 1");
MemberPoints memberPoints = pointsService.getOne(queryWrapper);
if (!memberPoints.getUserId().equals(SecurityUtils.getUserId())){
throw new RuntimeException("非本人账户");
}
SysUser sysUser = sysUserService.selectUserById(memberPoints.getUserId());
// 初始化商户配置
TransferToUser.TransferToUserRequest userRequest = new TransferToUser.TransferToUserRequest();
userRequest.appid = appConfig.getAppId();
userRequest.openid=sysUser.getOpenId();
// 将元转换为分
double pointsInYuan = memberPoints.getPoints();
userRequest.transferAmount = BigDecimal.valueOf(pointsInYuan).multiply(BigDecimal.valueOf(10)).setScale(0, RoundingMode.HALF_UP).longValue();
userRequest.notifyUrl = wechatPayConfig.getZhuanNotifyUrl();
userRequest.outBillNo = orderNo;
userRequest.transferSceneId = "1000";
userRequest.transferRemark = "通告快接积分提现";
List<TransferToUser.TransferSceneReportInfo> transferSceneReportInfos = new ArrayList<>();
TransferToUser.TransferSceneReportInfo transferSceneReportInfo = new TransferToUser.TransferSceneReportInfo();
transferSceneReportInfo.infoContent = "发布通告得积分";
transferSceneReportInfo.infoType = "活动名称";
TransferToUser.TransferSceneReportInfo transferSceneReportInfo2 = new TransferToUser.TransferSceneReportInfo();
transferSceneReportInfo2.infoContent = "发布通告得积分";
transferSceneReportInfo2.infoType = "奖励说明";
transferSceneReportInfos.add(transferSceneReportInfo);
transferSceneReportInfos.add(transferSceneReportInfo2);
userRequest.transferSceneReportInfos = transferSceneReportInfos;
TransferToUser.TransferToUserResponse run = transferToUser.run(userRequest);
JSONObject res = new JSONObject();
res.put("runData",run);
JSONObject config = new JSONObject();
config.put("appId",appConfig.getAppId());
config.put("mchId",wechatPayConfig.getMchId());
res.put("config",config);
return res;
}catch (Exception e){
LambdaQueryWrapper<MemberPoints> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemberPoints::getOrderNo,orderNo);
pointsService.remove(queryWrapper);
throw new RuntimeException(e);
}
userRequest.notifyUrl = wechatPayConfig.getZhuanNotifyUrl();
userRequest.outBillNo = orderNo;
userRequest.transferSceneId = "1000";
userRequest.transferRemark = "通告快接积分提现";
List<TransferToUser.TransferSceneReportInfo> transferSceneReportInfos = new ArrayList<>();
TransferToUser.TransferSceneReportInfo transferSceneReportInfo = new TransferToUser.TransferSceneReportInfo();
transferSceneReportInfo.infoContent = "发布通告得积分";
transferSceneReportInfo.infoType = "活动名称";
TransferToUser.TransferSceneReportInfo transferSceneReportInfo2 = new TransferToUser.TransferSceneReportInfo();
transferSceneReportInfo2.infoContent = "发布通告得积分";
transferSceneReportInfo2.infoType = "奖励说明";
transferSceneReportInfos.add(transferSceneReportInfo);
transferSceneReportInfos.add(transferSceneReportInfo2);
userRequest.transferSceneReportInfos = transferSceneReportInfos;
TransferToUser.TransferToUserResponse run = transferToUser.run(userRequest);
JSONObject res = new JSONObject();
res.put("runData",run);
JSONObject config = new JSONObject();
config.put("appId",appConfig.getAppId());
config.put("mchId",wechatPayConfig.getMchId());
res.put("config",config);
return res;
}

View File

@ -7,6 +7,7 @@ import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.member.domain.MemberPoints;
import com.ruoyi.member.service.IMemberPointsService;
import org.springframework.beans.factory.annotation.Autowired;
@ -47,6 +48,19 @@ public class MemberPointsController extends BaseController {
return success(list);
}
/**
* 查询在途订单
* @author PQZ
* @date 14:36 2025/4/29
* @return com.ruoyi.common.core.domain.AjaxResult
**/
@GetMapping("/getOnWayOrder")
public AjaxResult getOnWayOrder() {
Long userId = SecurityUtils.getUserId();
List<MemberPoints> list = memberPointsService.getOnWayOrder(userId);
return success(list.isEmpty()?null:list.get(0));
}
/**
* 新增博主积分变动记录

View File

@ -61,4 +61,13 @@ public interface IMemberPointsService extends IService<MemberPoints> {
* @type type 回调状态(success:成功其他为失败)
**/
void payoutCallback(String orderNo,String type);
/**
* 查询当前登录用户在途订单
* @author PQZ
* @date 14:32 2025/4/29
* @param userId 用户id
* @return java.util.List<com.ruoyi.member.domain.MemberPoints>
**/
List<MemberPoints> getOnWayOrder(Long userId);
}

View File

@ -153,9 +153,7 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
**/
@Override
public void payoutCallback(String orderNo,String type) {
/*防重复处理*/
Long userId = SecurityUtils.getUserId();
double nowBalance = getBloggerBalance(userId);
//通过订单编号查询积分记录
LambdaQueryWrapper<MemberPoints> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper
@ -166,6 +164,8 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
/*区分微信调用成功和失败*/
if (!memberPoints.isEmpty()) {
MemberPoints points = memberPoints.get(0);
/*防重复处理*/
double nowBalance = getBloggerBalance(points.getUserId());
if ("success".equals(type)) {
points.setBalance(nowBalance - points.getPoints());
points.setStatus("01");
@ -183,7 +183,8 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
* @param userId 用户id
* @return java.util.List<com.ruoyi.member.domain.MemberPoints>
**/
private List<MemberPoints> getOnWayOrder(Long userId){
@Override
public List<MemberPoints> getOnWayOrder(Long userId){
LambdaQueryWrapper<MemberPoints> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper
.eq(MemberPoints::getUserId,userId)

View File

@ -155,16 +155,23 @@ wxpay:
appId: wx7d10b0fa4886a583
#商户号
mchId: 1712447936
#商户密匙v2
mchKey: ab94673dd0cca78abd0a453d0aac9f98
# APIv3密钥
apiV3Key: ab94673dd0cca78abd0a453d0aac9f98
#微信支付p12证书
keyPath: D:/任务平台项目/dl_admin/ruoyi-admin/src/main/resources/apiclient_cert.p12
# 微信支付V3-url前缀
baseUrl: https://api.mch.weixin.qq.com/v3
# 支付通知回调, pjm6m9.natappfree.cc 为内网穿透地址
notifyUrl: https://3w823u8516.vicp.fun/noticeApi/payApi/payNotify
# 转账通知回调, pjm6m9.natappfree.cc 为内网穿透地址
zhuanNotifyUrl: https://3w823u8516.vicp.fun/noticeApi/payApi/zhuanNotify
# 退款通知回调, pjm6m9.natappfree.cc 为内网穿透地址
refundNotifyUrl: https://www.ddtg.site/notice/notify/refundNotify
# 密钥路径,resources根目录下
privateKeyPath: D:/任务平台项目/dl_admin/ruoyi-admin/src/main/resources/apiclient_key.pem
privateCertPath: D:/任务平台项目/dl_admin/ruoyi-admin/src/main/resources/apiclient_cert.pem
publicKeyPath: D:/任务平台项目/dl_admin/ruoyi-admin/src/main/resources/pub_key.pem
#商户证书序列号
serialNo: 7FCDB0E72D6A928013361ACB77FA3F0DCBD370E3