From e5594dd692f7c4a656a77771d463ab5895337cca Mon Sep 17 00:00:00 2001 From: hy001 Date: Mon, 27 Apr 2026 19:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=82=80=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rc-service-wallet/application.yml | 8 ++ .../app/team/bd/TeamLeaderBDServiceImpl.java | 11 +- .../freight/DealerToUserShipCmdExe.java | 48 +++++--- .../freight/SendFreightShipCmdExe.java | 54 ++++++--- .../common/invite/InviteCampaignGoClient.java | 106 ++++++++++++++++++ .../infra/config/InviteCampaignGoConfig.java | 21 ++++ 6 files changed, 212 insertions(+), 36 deletions(-) create mode 100644 rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/common/invite/InviteCampaignGoClient.java create mode 100644 rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/config/InviteCampaignGoConfig.java diff --git a/nacos_config/rc-service-wallet/application.yml b/nacos_config/rc-service-wallet/application.yml index d69060fd..de5ceac2 100644 --- a/nacos_config/rc-service-wallet/application.yml +++ b/nacos_config/rc-service-wallet/application.yml @@ -2,3 +2,11 @@ spring: data: redis: database: 0 + +invite: + campaign: + go: + enabled: ${INVITE_CAMPAIGN_GO_ENABLED:true} + base-url: ${INVITE_CAMPAIGN_GO_URL:} + internal-token: ${GAME_INTERNAL_CALLBACK_SECRET:} + timeout-millis: ${INVITE_CAMPAIGN_GO_TIMEOUT_MILLIS:10000} diff --git a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/team/bd/TeamLeaderBDServiceImpl.java b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/team/bd/TeamLeaderBDServiceImpl.java index d63507cc..7d80b6c0 100644 --- a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/team/bd/TeamLeaderBDServiceImpl.java +++ b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/team/bd/TeamLeaderBDServiceImpl.java @@ -238,11 +238,12 @@ public class TeamLeaderBDServiceImpl implements TeamLeaderBDService { bd.setUpdateUser(param.getUpdateUser()); bdTeamInfoClient.updateSelectiveById(bd); } else { - bdTeamInfoClient.add(new BdTeamInfoCmd() - .setSysOrigin(bdLead.getSysOrigin()) - .setCreateUser(bdLead.getCreateUser()) - .setRegion(bdLead.getRegionId()) - .setUserId(param.getUserId()) + bdTeamInfoClient.add(new BdTeamInfoCmd() + .setId(IdWorkerUtils.getId()) + .setSysOrigin(bdLead.getSysOrigin()) + .setCreateUser(bdLead.getCreateUser()) + .setRegion(bdLead.getRegionId()) + .setUserId(param.getUserId()) .setBdLeadUserId(param.getBdLeadUserId())); } diff --git a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/DealerToUserShipCmdExe.java b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/DealerToUserShipCmdExe.java index cde55aab..0f2f22f8 100644 --- a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/DealerToUserShipCmdExe.java +++ b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/DealerToUserShipCmdExe.java @@ -27,8 +27,9 @@ import com.red.circle.tool.core.num.ArithmeticUtils; import com.red.circle.tool.core.tuple.PennyAmount; import com.red.circle.other.inner.asserts.user.UserErrorCode; import com.red.circle.other.inner.endpoint.user.user.UserSvipClient; -import com.red.circle.wallet.app.dto.cmd.FreightDealerToUserShipCmd; -import com.red.circle.wallet.domain.gateway.FreightShipGateway; +import com.red.circle.wallet.app.dto.cmd.FreightDealerToUserShipCmd; +import com.red.circle.wallet.app.common.invite.InviteCampaignGoClient; +import com.red.circle.wallet.domain.gateway.FreightShipGateway; import com.red.circle.wallet.domain.gateway.WalletGoldGateway; import com.red.circle.wallet.domain.wallet.WalletReceipt; import com.red.circle.wallet.infra.database.cache.service.UserPayAuthCacheService; @@ -79,9 +80,10 @@ public class DealerToUserShipCmdExe { private final CumulativeRechargeClient cumulativeRechargeClient; private final FreightBalanceRunningWaterService freightBalanceRunningWaterService; private final PropsActivityClient propsActivityClient; - private final UserOneTimeTaskClient userOneTimeTaskClient; - private final UserProfileClient userProfileClient; - private final InviteUserClient inviteUserClient; + private final UserOneTimeTaskClient userOneTimeTaskClient; + private final UserProfileClient userProfileClient; + private final InviteUserClient inviteUserClient; + private final InviteCampaignGoClient inviteCampaignGoClient; public BigDecimal execute(FreightDealerToUserShipCmd cmd) { controlSwitch.execute(cmd.requireReqSysOriginChildEnum()); @@ -165,11 +167,12 @@ public class DealerToUserShipCmdExe { ); } - // 累计充值 - incrRechargeQuantity(cmd); - - //累计今日充值,每日累计充值抽奖活动 - cumulativeRechargeClient.incrTodayRechargeScore(cmd.getAcceptUserId(), + // 累计充值 + incrRechargeQuantity(cmd); + notifyInviteCampaignRecharge(cmd, runningWater); + + //累计今日充值,每日累计充值抽奖活动 + cumulativeRechargeClient.incrTodayRechargeScore(cmd.getAcceptUserId(), getGoldToSUD(cmd).doubleValue()); // 余额如果等于0则回收货运代理徽章 @@ -245,10 +248,27 @@ public class DealerToUserShipCmdExe { userProfileClient.removeCacheAll(userId); }*/ } - } - - - private void incrRechargeQuantity(FreightDealerToUserShipCmd cmd) { + } + + private void notifyInviteCampaignRecharge(FreightDealerToUserShipCmd cmd, + FreightBalanceRunningWater runningWater) { + try { + inviteCampaignGoClient.notifyRechargeSuccess( + new InviteCampaignGoClient.RechargeSuccessRequest() + .setOrderId("seller-agent:" + runningWater.getId()) + .setUserId(cmd.getAcceptUserId()) + .setRechargeCoins(InviteCampaignGoClient.toRechargeCoins(cmd.getQuantity())) + .setPayTime(System.currentTimeMillis()) + .setSysOrigin(cmd.getReqSysOrigin().getOrigin()) + ); + } catch (Exception e) { + log.error("Invite campaign recharge notify failed. channel=SELLER_AGENT, userId={}, orderId={}", + cmd.getAcceptUserId(), runningWater.getId(), e); + } + } + + + private void incrRechargeQuantity(FreightDealerToUserShipCmd cmd) { userRechargeCountClient.count(cmd.getAcceptUserId(), getGoldToSUD(cmd), MonthlyRechargeType.SELLER_AGENT diff --git a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/SendFreightShipCmdExe.java b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/SendFreightShipCmdExe.java index bde1c8fe..457a5549 100644 --- a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/SendFreightShipCmdExe.java +++ b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/command/freight/SendFreightShipCmdExe.java @@ -31,9 +31,10 @@ import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.tool.core.date.LocalDateTimeUtils; import com.red.circle.tool.core.json.JacksonUtils; import com.red.circle.tool.core.num.ArithmeticUtils; -import com.red.circle.tool.core.tuple.PennyAmount; -import com.red.circle.other.inner.asserts.user.UserErrorCode; -import com.red.circle.wallet.app.dto.cmd.FreightShipSendCmd; +import com.red.circle.tool.core.tuple.PennyAmount; +import com.red.circle.other.inner.asserts.user.UserErrorCode; +import com.red.circle.wallet.app.common.invite.InviteCampaignGoClient; +import com.red.circle.wallet.app.dto.cmd.FreightShipSendCmd; import com.red.circle.wallet.app.dto.cmd.SalaryWithdrawCmd; import com.red.circle.wallet.domain.gateway.FreightShipGateway; import com.red.circle.wallet.domain.gateway.WalletGoldGateway; @@ -88,10 +89,11 @@ public class SendFreightShipCmdExe { private final TaskMqMessage taskMqMessage; private final UserLevelClient userLevelClient; private final PropsActivityClient propsActivityClient; - private final UserOneTimeTaskClient userOneTimeTaskClient; - private final InviteUserClient inviteUserClient; - private final UserRegionClient userRegionClient; - private final OfficialNoticeClient officialNoticeClient; + private final UserOneTimeTaskClient userOneTimeTaskClient; + private final InviteUserClient inviteUserClient; + private final InviteCampaignGoClient inviteCampaignGoClient; + private final UserRegionClient userRegionClient; + private final OfficialNoticeClient officialNoticeClient; public BigDecimal execute(FreightShipSendCmd cmd) { @@ -183,12 +185,13 @@ public class SendFreightShipCmdExe { log.error("send freight balance failed: {}", e.getMessage()); } - - // 累计充值 - incrRechargeQuantity(cmd); - - //累计今日充值,每日累计充值抽奖活动 - cumulativeRechargeClient.incrTodayRechargeScore(cmd.getAcceptUserId(),getGoldToSUD(cmd).doubleValue()); + + // 累计充值 + incrRechargeQuantity(cmd); + notifyInviteCampaignRecharge(cmd, runningWater); + + //累计今日充值,每日累计充值抽奖活动 + cumulativeRechargeClient.incrTodayRechargeScore(cmd.getAcceptUserId(),getGoldToSUD(cmd).doubleValue()); completedFirstCharge(cmd.getAcceptUserId(), cmd.getReqSysOrigin().getOrigin()); } @@ -274,10 +277,27 @@ public class SendFreightShipCmdExe { }*/ } } - } - - private void incrRechargeQuantity(FreightShipSendCmd cmd) { - + } + + private void notifyInviteCampaignRecharge(FreightShipSendCmd cmd, + FreightBalanceRunningWater runningWater) { + try { + inviteCampaignGoClient.notifyRechargeSuccess( + new InviteCampaignGoClient.RechargeSuccessRequest() + .setOrderId("shipping-agent:" + runningWater.getId()) + .setUserId(cmd.getAcceptUserId()) + .setRechargeCoins(InviteCampaignGoClient.toRechargeCoins(cmd.getQuantity())) + .setPayTime(System.currentTimeMillis()) + .setSysOrigin(cmd.getReqSysOrigin().getOrigin()) + ); + } catch (Exception e) { + log.error("Invite campaign recharge notify failed. channel=SHIPPING_AGENT, userId={}, orderId={}", + cmd.getAcceptUserId(), runningWater.getId(), e); + } + } + + private void incrRechargeQuantity(FreightShipSendCmd cmd) { + userRechargeCountClient.count(cmd.getAcceptUserId(), getGoldToSUD(cmd), MonthlyRechargeType.SHIPPING_AGENT diff --git a/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/common/invite/InviteCampaignGoClient.java b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/common/invite/InviteCampaignGoClient.java new file mode 100644 index 00000000..d279c159 --- /dev/null +++ b/rc-service/rc-service-wallet/wallet-application/src/main/java/com/red/circle/wallet/app/common/invite/InviteCampaignGoClient.java @@ -0,0 +1,106 @@ +package com.red.circle.wallet.app.common.invite; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.red.circle.wallet.infra.config.InviteCampaignGoConfig; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.Duration; +import java.util.Objects; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class InviteCampaignGoClient { + + private static final String RECHARGE_SUCCESS_PATH = "/internal/invite-campaign/recharge-success"; + + private final InviteCampaignGoConfig inviteCampaignGoConfig; + + public void notifyRechargeSuccess(RechargeSuccessRequest request) { + if (!inviteCampaignGoConfig.isEnabled()) { + return; + } + + String baseUrl = Objects.toString(inviteCampaignGoConfig.getBaseUrl(), "").trim(); + if (baseUrl.isEmpty()) { + log.warn("Invite campaign go baseUrl is blank, skip recharge notify. userId={}, orderId={}", + request.getUserId(), request.getOrderId()); + return; + } + + int timeoutMillis = Objects.requireNonNullElse(inviteCampaignGoConfig.getTimeoutMillis(), 10000); + HttpRequest httpRequest = HttpRequest.newBuilder() + .uri(URI.create(trimRightSlash(baseUrl) + RECHARGE_SUCCESS_PATH)) + .timeout(Duration.ofMillis(timeoutMillis)) + .header("Content-Type", "application/json") + .header("Accept", "application/json") + .header("X-Internal-Token", Objects.toString(inviteCampaignGoConfig.getInternalToken(), "")) + .POST(HttpRequest.BodyPublishers.ofString(JSON.toJSONString(request))) + .build(); + + HttpResponse response; + try { + response = HttpClient.newBuilder() + .connectTimeout(Duration.ofMillis(timeoutMillis)) + .build() + .send(httpRequest, HttpResponse.BodyHandlers.ofString()); + } catch (IOException e) { + throw new IllegalStateException("Invite campaign go request failed", e); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException("Invite campaign go request interrupted", e); + } + + String responseBody = response.body(); + if (response.statusCode() < 200 || response.statusCode() >= 300) { + throw new IllegalStateException("Invite campaign go http error, status=" + response.statusCode() + + ", body=" + responseBody); + } + if (responseBody == null || responseBody.trim().isEmpty()) { + throw new IllegalStateException("Invite campaign go response is empty"); + } + + JSONObject root = JSON.parseObject(responseBody); + if (root == null) { + throw new IllegalStateException("Invite campaign go response is invalid"); + } + if (root.containsKey("status") && !root.getBooleanValue("status")) { + throw new IllegalStateException("Invite campaign go business error: " + root.getString("message")); + } + } + + private String trimRightSlash(String value) { + while (value.endsWith("/")) { + value = value.substring(0, value.length() - 1); + } + return value; + } + + public static long toRechargeCoins(BigDecimal quantity) { + if (quantity == null) { + return 0L; + } + return quantity.setScale(0, RoundingMode.DOWN).longValue(); + } + + @Data + @Accessors(chain = true) + public static class RechargeSuccessRequest { + private String orderId; + private Long userId; + private Long rechargeCoins; + private Long payTime; + private String sysOrigin; + } +} diff --git a/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/config/InviteCampaignGoConfig.java b/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/config/InviteCampaignGoConfig.java new file mode 100644 index 00000000..60169818 --- /dev/null +++ b/rc-service/rc-service-wallet/wallet-infrastructure/src/main/java/com/red/circle/wallet/infra/config/InviteCampaignGoConfig.java @@ -0,0 +1,21 @@ +package com.red.circle.wallet.infra.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.stereotype.Component; + +@Data +@Component +@RefreshScope +@ConfigurationProperties(prefix = "invite.campaign.go") +public class InviteCampaignGoConfig { + + private boolean enabled = true; + + private String baseUrl; + + private String internalToken; + + private Integer timeoutMillis = 10000; +}