分账提现接口

This commit is contained in:
张松 2025-10-27 20:11:52 +08:00
parent 1560e5a36f
commit aed955c513
8 changed files with 67 additions and 92 deletions

View File

@ -1,17 +1,13 @@
package com.czg.controller.user;
import com.czg.market.dto.MkDistributionWithdrawFlowDTO;
import com.czg.market.entity.MkDistributionFlow;
import com.czg.market.entity.MkDistributionWithdrawFlow;
import com.czg.market.service.MkDistributionFlowService;
import com.czg.market.service.MkDistributionUserService;
import com.czg.market.service.MkDistributionWithdrawFlowService;
import com.czg.market.vo.DistributionCenterShopVO;
import com.czg.order.dto.MkDistributionPayDTO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.Impl.AppWxServiceImpl;
import com.czg.utils.AssertUtil;
import com.czg.service.market.service.impl.AppWxServiceImpl;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;

View File

@ -7,17 +7,15 @@ import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.CzgPayUtils;
import com.czg.entity.CzgBaseRespParams;
import com.czg.market.service.MkDistributionConfigService;
import com.czg.market.service.MkDistributionUserService;
import com.czg.mq.PrintMqListener;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.order.service.ShopTableOrderStatisticService;
import com.czg.service.Impl.WxServiceImpl;
import com.czg.service.market.service.impl.WxServiceImpl;
import com.czg.task.StatisticTask;
import com.czg.utils.AssertUtil;
import com.ijpay.core.kit.AesUtil;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

View File

@ -34,7 +34,7 @@ public class Main {
// String packageName = "product";
String packageName = "market";
// tableName 指定需要生成的表
String tableName = "mk_distribution_flow";
String tableName = "mk_distribution_withdraw_flow";
String author = "ww";
//是否生成DTO实体 默认生成
boolean isGenerateDto = true;

View File

@ -1,38 +1,30 @@
package com.czg.service.Impl;
package com.czg.service.market.service.impl;
import com.czg.service.RedisService;
import com.czg.system.service.SysParamsService;
import com.czg.service.WxService;
import com.ijpay.core.kit.RsaKit;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
/**
* 微信支付service
* @author Administrator
*/
@DubboService
@Component
@Slf4j
public class AppWxServiceImpl implements WxService {
@Primary
public class AppWxServiceImpl extends BaseWx {
@Resource
private RedisService autoRedisService;
@DubboReference
private SysParamsService paramsService;
private static RedisService redisService;
private WxService.Config config = new Config();
@Override
public Config getConfig() {
return config;
}
@Override
public RedisService getRedisService() {
return redisService;
public AppWxServiceImpl(@Autowired RedisService autoRedisService) {
this.redisService = autoRedisService;
config = new Config();
}
@PostConstruct
@ -66,7 +58,10 @@ public class AppWxServiceImpl implements WxService {
config.notifyUrl = paramsService.getSysParamValue("native_notify_url") + "/wx/pay";
config.refundNotifyUrl = "";
config.transferNotifyUrl = paramsService.getSysParamValue("native_notify_url") + "/wx/transfer";
redisService = this.autoRedisService;
}
public BaseWx getAppService() {
return this;
}
}

View File

@ -1,4 +1,4 @@
package com.czg.service;
package com.czg.service.market.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
@ -6,6 +6,7 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.exception.CzgException;
import com.czg.service.RedisService;
import com.ijpay.core.IJPayHttpResponse;
import com.ijpay.core.enums.RequestMethodEnum;
import com.ijpay.core.enums.SignType;
@ -36,10 +37,12 @@ import java.util.Map;
* 微信支付相关
* @author Administrator
*/
public interface WxService {
Logger log = LoggerFactory.getLogger(WxService.class);
public abstract class BaseWx {
public Config config;
public RedisService redisService;
public Logger log = LoggerFactory.getLogger(BaseWx.class);
@Data
class Config {
public static class Config {
public String appId;
public String appSecret;
public String certPath;
@ -56,11 +59,9 @@ public interface WxService {
public String refundNotifyUrl;
public String transferNotifyUrl;
}
Config getConfig();
RedisService getRedisService();
default String getPhone(String code) {
String getPhone(String code) {
String requestBody = JSONObject.toJSONString(Map.of("code", code));
String response = HttpUtil.post("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + getAccessToken(false), requestBody);
log.info("获取手机号响应: {}", response);
@ -75,9 +76,8 @@ public interface WxService {
throw new RuntimeException("获取手机号失败");
}
default String getAccessToken(boolean refresh) {
Object token = getRedisService().get("access_token");
Config config = getConfig();
String getAccessToken(boolean refresh) {
Object token = redisService.get("access_token");
if (!refresh && token instanceof String) {
return (String) token;
}
@ -96,15 +96,15 @@ public interface WxService {
if (expiresIn == null) {
expiresIn = 7200L;
}
getRedisService().set("access_token", accessToken, expiresIn - 200);
redisService.set("access_token", accessToken, expiresIn - 200);
return accessToken;
}
/**
* 使用微信支付平台证书公钥加密敏感信息OAEP
*/
default String encryptByPlatformCert(String content) {
Config config = getConfig();
String encryptByPlatformCert(String content) {
try (var certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(config.getPlatformCertPath())) {
if (certStream == null) {
@ -120,7 +120,7 @@ public interface WxService {
}
}
default String getSerialNumberFromPem(String certContent) {
String getSerialNumberFromPem(String certContent) {
try {
// 去掉 PEM 头尾并清理空格换行
String pem = certContent
@ -151,8 +151,8 @@ public interface WxService {
return null;
}
default String getSerialNumber() {
Config config = getConfig();
public String getSerialNumber() {
try (var certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(config.getCertPath())) {
X509Certificate certificate = PayKit.getCertificate(certStream);
if (certificate != null) {
@ -168,8 +168,8 @@ public interface WxService {
return null;
}
default JSONObject verifySignature(HttpServletRequest request) {
Config config = getConfig();
public JSONObject verifySignature(HttpServletRequest request) {
try {
log.info("开始校验签名并解密");
@ -186,8 +186,8 @@ public interface WxService {
}
}
default String decryptToString(String associatedData, String nonceStr, String ciphertext) {
AesUtil aesUtil = new AesUtil(getConfig().getApiV3Key().getBytes(StandardCharsets.UTF_8));
public String decryptToString(String associatedData, String nonceStr, String ciphertext) {
AesUtil aesUtil = new AesUtil(config.getApiV3Key().getBytes(StandardCharsets.UTF_8));
try {
return aesUtil.decryptToString(
associatedData.getBytes(StandardCharsets.UTF_8),
@ -199,8 +199,8 @@ public interface WxService {
}
}
default String getOpenId(String code) {
Config config = getConfig();
public String getOpenId(String code) {
String response = HttpUtil.get("https://api.weixin.qq.com/sns/jscode2session",
Map.of("appid", config.getAppId() , "secret", config.getAppSecret(), "js_code", code, "grant_type", "authorization_code")
);
@ -213,8 +213,8 @@ public interface WxService {
throw new RuntimeException("获取openId失败");
}
default Map<String, String> v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type) {
Config config = getConfig();
public Map<String, String> v3Pay(String openId, BigDecimal amount, String desc, String tradeNo, String type) {
if (desc == null) desc = "订单支付";
UnifiedOrderModel model = new UnifiedOrderModel();
model.setAppid(config.getAppId());
@ -256,8 +256,8 @@ public interface WxService {
}
default Map<String, String> v2Pay(String openId, BigDecimal amount, String desc, String tradeNo) {
Config config = getConfig();
Map<String, String> v2Pay(String openId, BigDecimal amount, String desc, String tradeNo) {
Map<String, String> payModel = com.ijpay.wxpay.model.UnifiedOrderModel.builder()
.appid(config.appId)
.mch_id(config.mchId)
@ -290,8 +290,8 @@ public interface WxService {
}
default String refund(String tradeNo, String refundTradeNo, BigDecimal amount) {
Config config = getConfig();
String refund(String tradeNo, String refundTradeNo, BigDecimal amount) {
int finalAmount = amount.multiply(new BigDecimal(100)).intValueExact();
RefundModel model = new RefundModel();
model.setOut_trade_no(tradeNo);
@ -325,7 +325,7 @@ public interface WxService {
return jsonObject.getString("refund_id");
}
default String genCode(int shopId, int id, String path) {
String genCode(int shopId, int id, String path) {
Map<String, Object> params = Map.of(
"scene", "id=" + id + "&shopId=" + shopId,
"page", path,
@ -346,8 +346,8 @@ public interface WxService {
default JSONObject transferBalance(String openId, String name, BigDecimal amount, String remarkTxt, String billNoTxt) {
Config config = getConfig();
JSONObject transferBalance(String openId, String name, BigDecimal amount, String remarkTxt, String billNoTxt) {
String remark = remarkTxt == null ? "佣金" : remarkTxt;
String billNo = billNoTxt == null ? IdUtil.simpleUUID() : billNoTxt;
Map<String, Object> params = Map.of(

View File

@ -3,10 +3,8 @@ package com.czg.service.market.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.entity.ShopInfo;
import com.czg.account.entity.ShopUser;
import com.czg.account.entity.UserInfo;
import com.czg.account.service.ShopInfoService;
import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService;
@ -31,7 +29,6 @@ import com.czg.order.dto.MkDistributionPayDTO;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderPaymentService;
import com.czg.sa.StpKit;
import com.czg.service.Impl.AppWxServiceImpl;
import com.czg.service.market.mapper.MkDistributionUserMapper;
import com.czg.utils.AssertUtil;
import com.czg.utils.CzgRandomUtils;
@ -74,10 +71,8 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
private MkDistributionAmountFlowService distributionAmountFlowService;
@Resource
private MkDistributionFlowService distributionFlowService;
@Resource
private MkDistributionUserService distributionUserService;
@DubboReference
@Resource
private AppWxServiceImpl appWxService;
@DubboReference
@ -377,7 +372,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
.setRewardAmount(rewardAmount).setBillNo(IdUtil.simpleUUID());
distributionFlowService.save(mkDistributionFlow);
distributionUserService.updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
updateIncome(!flag ? rewardAmount : BigDecimal.ZERO,
flag ? rewardAmount : BigDecimal.ZERO, BigDecimal.ZERO, distributionUser.getId());
if (flag) {
@ -413,6 +408,10 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
@Override
public Boolean withdraw(long userId, MkDistributionWithdrawFlowDTO withdrawFlowDTO) {
ShopUser shopUserInfo = shopUserService.getShopUserInfo(withdrawFlowDTO.getShopId(), userId);
MkDistributionUser distributionUser = getOne(new QueryWrapper().eq(MkDistributionUser::getShopUserId, shopUserInfo.getId()));
AssertUtil.isNull(distributionUser, "分销员不存在");
// if (distributionUser.get)
return null;
}
}

View File

@ -1,47 +1,32 @@
package com.czg.service.Impl;
package com.czg.service.market.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.exception.CzgException;
import com.czg.service.RedisService;
import com.czg.system.service.SysParamsService;
import com.czg.service.WxService;
import com.ijpay.core.kit.RsaKit;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 微信支付service
* @author Administrator
*/
@DubboService
@Component
@Slf4j
public class WxServiceImpl implements WxService {
public class WxServiceImpl extends BaseWx {
@Resource
private RedisService autoRedisService;
@DubboReference
private SysParamsService paramsService;
private static RedisService redisService;
private WxService.Config config = new Config();
@Override
public Config getConfig() {
return config;
}
@Override
public RedisService getRedisService() {
return redisService;
public WxServiceImpl(@Autowired RedisService redisService) {
this.redisService = redisService;
config = new Config();
}
@PostConstruct
@ -75,7 +60,10 @@ public class WxServiceImpl implements WxService {
config.notifyUrl = paramsService.getSysParamValue("native_notify_url") + "/wx/pay";
config.refundNotifyUrl = "";
config.transferNotifyUrl = paramsService.getSysParamValue("native_notify_url") + "/wx/transfer";
redisService = this.autoRedisService;
}
public BaseWx getAppService() {
return this;
}
}

View File

@ -2,7 +2,6 @@ package com.czg.service.order.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.entity.ShopInfo;
import com.czg.account.entity.ShopUser;
import com.czg.account.entity.UserInfo;
import com.czg.account.service.ShopInfoService;
@ -17,7 +16,7 @@ import com.czg.order.dto.MkDistributionPayDTO;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderPaymentService;
import com.czg.resp.CzgResult;
import com.czg.service.Impl.WxServiceImpl;
import com.czg.service.market.service.impl.WxServiceImpl;
import com.czg.service.order.service.DistributionPayService;
import com.czg.utils.AssertUtil;
import jakarta.annotation.Resource;