|
|
@@ -4,6 +4,7 @@ import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.entity.DistributionRelation;
|
|
|
import com.etotem.cfc.entity.DistributionSystem;
|
|
|
import com.etotem.cfc.service.DistributionService;
|
|
|
+import com.etotem.cfc.service.WechatService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
@@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import com.etotem.cfc.util.ParamUtils;
|
|
|
@@ -22,17 +24,43 @@ import com.etotem.cfc.util.ParamUtils;
|
|
|
@RequestMapping("/api/distribution/invite")
|
|
|
public class DistributionInviteController {
|
|
|
|
|
|
+ /** 团队邀请独立落地页(§11-#11 已拍板:独立页,团队场景信息不同) */
|
|
|
+ private static final String TEAM_INVITE_PAGE = "pages/team-invite/join";
|
|
|
+
|
|
|
@Resource
|
|
|
private DistributionService distributionService;
|
|
|
|
|
|
- @Operation(summary = "生成/获取我的销售邀请码")
|
|
|
+ @Resource
|
|
|
+ private WechatService wechatService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成/获取我的销售邀请码(团队邀请,S-cfc-60 / team.invitation.create)。
|
|
|
+ * <p>
|
|
|
+ * 契约 §5.2:返回 {@code inviteCode + wxacode(小程序码, 独立团队落地页) + systemId + teamName + inviterId},
|
|
|
+ * 复用 {@code distribution_relations.invite_code}(§7.7),不新建表。
|
|
|
+ */
|
|
|
+ @Operation(summary = "生成/获取我的销售邀请码(团队邀请)")
|
|
|
@PostMapping("/generate")
|
|
|
- public Result<String> generate(
|
|
|
+ public Result<Map<String, Object>> generate(
|
|
|
@RequestAttribute("userId") Long userId,
|
|
|
@RequestBody Map<String, Object> params) {
|
|
|
Long systemId = ParamUtils.getLong(params.get("systemId"));
|
|
|
if (systemId == null) return Result.error("systemId不能为空");
|
|
|
- return distributionService.generateInviteCode(systemId, userId);
|
|
|
+
|
|
|
+ Result<String> codeResult = distributionService.generateInviteCode(systemId, userId);
|
|
|
+ if (codeResult == null || codeResult.getCode() == null
|
|
|
+ || codeResult.getCode() != 200 || codeResult.getData() == null) {
|
|
|
+ return Result.error(codeResult != null ? codeResult.getMessage() : "生成邀请失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ String inviteCode = codeResult.getData();
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
+ data.put("inviteCode", inviteCode);
|
|
|
+ data.put("systemId", systemId);
|
|
|
+ data.put("inviterId", userId);
|
|
|
+ data.put("teamName", resolveTeamName(systemId, userId));
|
|
|
+ data.put("wxacode", resolveWxacode(systemId, userId, inviteCode));
|
|
|
+ return Result.success(data);
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "校验邀请码有效性")
|
|
|
@@ -100,4 +128,42 @@ public class DistributionInviteController {
|
|
|
if (systemId == null) return Result.error("systemId不能为空");
|
|
|
return distributionService.getUserPosition(systemId, userId);
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析当前用户在该销售体系下的团队名;查询不可用/未命中时降级为空串(契约仅要求非 null)。
|
|
|
+ */
|
|
|
+ private String resolveTeamName(Long systemId, Long userId) {
|
|
|
+ try {
|
|
|
+ Result<List<DistributionSystem>> teamsResult = distributionService.getUserTeams(userId);
|
|
|
+ if (teamsResult != null && teamsResult.getData() != null) {
|
|
|
+ for (DistributionSystem system : teamsResult.getData()) {
|
|
|
+ if (system != null && systemId.equals(system.getId())
|
|
|
+ && system.getName() != null && !system.getName().isEmpty()) {
|
|
|
+ return system.getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 团队信息不可用,避免影响邀请码生成
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成团队邀请落地页小程序码(scene=inviteCode,page=独立团队落地页)。
|
|
|
+ * WechatService 不可用或生成失败时,返回带 code 参数的落地页路径兜底。
|
|
|
+ */
|
|
|
+ private String resolveWxacode(Long systemId, Long userId, String inviteCode) {
|
|
|
+ try {
|
|
|
+ if (wechatService != null) {
|
|
|
+ String wxacode = wechatService.generateWxacode("code=" + inviteCode, TEAM_INVITE_PAGE);
|
|
|
+ if (wxacode != null && !wxacode.isEmpty()) {
|
|
|
+ return wxacode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 小程序码生成失败,走落地页路径兜底
|
|
|
+ }
|
|
|
+ return TEAM_INVITE_PAGE + "?code=" + inviteCode;
|
|
|
+ }
|
|
|
+}
|