|
@@ -2,232 +2,80 @@ package com.zxyj.controller.guide;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.zxyj.common.Result;
|
|
import com.zxyj.common.Result;
|
|
|
-import com.zxyj.dto.BindGuideDTO;
|
|
|
|
|
-import com.zxyj.dto.GuidePackageDTO;
|
|
|
|
|
-import com.zxyj.dto.GuidePackageTemplateDTO;
|
|
|
|
|
-import com.zxyj.entity.*;
|
|
|
|
|
-import com.zxyj.mapper.FamilyMapper;
|
|
|
|
|
-import com.zxyj.mapper.UserMapper;
|
|
|
|
|
-import com.zxyj.service.GuideFamilyService;
|
|
|
|
|
|
|
+import com.zxyj.entity.Guide;
|
|
|
|
|
+import com.zxyj.entity.GuideApplication;
|
|
|
|
|
+import com.zxyj.entity.GuidePackage;
|
|
|
|
|
+import com.zxyj.service.GuideApplicationService;
|
|
|
import com.zxyj.service.GuidePackageService;
|
|
import com.zxyj.service.GuidePackageService;
|
|
|
-import com.zxyj.service.GuidePackageTemplateService;
|
|
|
|
|
-import com.zxyj.service.ServiceContentService;
|
|
|
|
|
-import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
-import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
|
|
+import com.zxyj.service.GuideService;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
-@Tag(name = "成长规划师管理", description = "成长规划师绑定家庭、管理套餐等接口")
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/api/guide")
|
|
@RequestMapping("/api/guide")
|
|
|
public class GuideController {
|
|
public class GuideController {
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private GuideFamilyService guideFamilyService;
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private GuideApplicationService guideApplicationService;
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private FamilyMapper familyMapper;
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private GuideService guideService;
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private UserMapper userMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private GuidePackageTemplateService templateService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
|
|
+ @Autowired
|
|
|
private GuidePackageService guidePackageService;
|
|
private GuidePackageService guidePackageService;
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private ServiceContentService serviceContentService;
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 生成绑定邀请链接
|
|
|
|
|
- */
|
|
|
|
|
- @Operation(summary = "生成绑定邀请链接")
|
|
|
|
|
- @PostMapping("/invite-link")
|
|
|
|
|
- public Result<Map<String, String>> generateBindInvite(@RequestAttribute("userId") Long userId) {
|
|
|
|
|
- // 获取当前用户家庭
|
|
|
|
|
- User user = new User();
|
|
|
|
|
- user.setId(userId);
|
|
|
|
|
-
|
|
|
|
|
- // 生成邀请信息
|
|
|
|
|
- Map<String, String> result = new HashMap<>();
|
|
|
|
|
- result.put("bindToken", userId + "_" + System.currentTimeMillis());
|
|
|
|
|
- result.put("inviteUrl", "/pages/bind/accept?token=" + result.get("bindToken"));
|
|
|
|
|
-
|
|
|
|
|
- return Result.success(result);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取绑定的家庭列表
|
|
|
|
|
- */
|
|
|
|
|
- @Operation(summary = "获取绑定的家庭列表")
|
|
|
|
|
- @PostMapping("/bound-families")
|
|
|
|
|
- public Result<List<Map<String, Object>>> getBoundFamilies(@RequestAttribute("userId") Long userId) {
|
|
|
|
|
- List<GuideFamily> bindings = guideFamilyService.getFamiliesByGuide(userId);
|
|
|
|
|
-
|
|
|
|
|
- List<Map<String, Object>> result = bindings.stream().map(binding -> {
|
|
|
|
|
- Map<String, Object> item = new HashMap<>();
|
|
|
|
|
- item.put("id", binding.getId());
|
|
|
|
|
- item.put("familyId", binding.getFamilyId());
|
|
|
|
|
- item.put("serviceType", binding.getServiceType());
|
|
|
|
|
- item.put("servicePrice", binding.getServicePrice());
|
|
|
|
|
- item.put("status", binding.getStatus());
|
|
|
|
|
- item.put("boundAt", binding.getBoundAt());
|
|
|
|
|
-
|
|
|
|
|
- // 获取家庭信息
|
|
|
|
|
- Family family = familyMapper.selectById(binding.getFamilyId());
|
|
|
|
|
- if (family != null) {
|
|
|
|
|
- item.put("familyName", family.getName());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return item;
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- return Result.success(result);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 确认绑定家庭
|
|
|
|
|
- */
|
|
|
|
|
- @Operation(summary = "确认绑定家庭")
|
|
|
|
|
- @PostMapping("/bind/confirm")
|
|
|
|
|
- public Result<Boolean> confirmBind(@RequestAttribute("userId") Long userId,
|
|
|
|
|
- @RequestBody BindGuideDTO dto) {
|
|
|
|
|
- // 这里简化处理,实际应该通过 bindToken 解析
|
|
|
|
|
- // 暂时使用 familyId
|
|
|
|
|
- boolean success = guideFamilyService.confirmBind(userId, dto.getFamilyId(),
|
|
|
|
|
- dto.getServiceType(), dto.getServicePrice());
|
|
|
|
|
- return Result.success(success);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 解除绑定
|
|
|
|
|
- */
|
|
|
|
|
- @Operation(summary = "解除绑定")
|
|
|
|
|
- @DeleteMapping("/bind/{id}")
|
|
|
|
|
- public Result<Boolean> unbind(@PathVariable Long id) {
|
|
|
|
|
- boolean success = guideFamilyService.unbind(id);
|
|
|
|
|
- return Result.success(success);
|
|
|
|
|
|
|
+ @GetMapping("/packages")
|
|
|
|
|
+ public Result<List<GuidePackage>> getPackages() {
|
|
|
|
|
+ return Result.success(guidePackageService.getActivePackages());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 成长规划师绑定家庭(设置家庭关联的成长规划师)
|
|
|
|
|
- */
|
|
|
|
|
- @Operation(summary = "成长规划师绑定家庭")
|
|
|
|
|
- @PostMapping("/bind/family/{familyId}")
|
|
|
|
|
- public Result<Boolean> bindFamily(@RequestAttribute("userId") Long teacherId,
|
|
|
|
|
- @RequestAttribute("role") String role,
|
|
|
|
|
- @PathVariable Long familyId) {
|
|
|
|
|
- if (!"teacher".equals(role)) {
|
|
|
|
|
- return Result.error("只有成长规划师可以执行此操作");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Family family = familyMapper.selectById(familyId);
|
|
|
|
|
- if (family == null) {
|
|
|
|
|
- return Result.error("家庭不存在");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 更新家庭的成长规划师ID
|
|
|
|
|
- family.setTeacherId(teacherId);
|
|
|
|
|
- family.setUpdatedAt(new java.util.Date());
|
|
|
|
|
- familyMapper.updateById(family);
|
|
|
|
|
-
|
|
|
|
|
- // 同时更新成长规划师的 teacherFamilyIds
|
|
|
|
|
- User teacher = userMapper.selectById(teacherId);
|
|
|
|
|
- if (teacher != null) {
|
|
|
|
|
- String currentIds = teacher.getTeacherFamilyIds();
|
|
|
|
|
- String newFamilyId = String.valueOf(familyId);
|
|
|
|
|
- if (currentIds == null || !currentIds.contains(newFamilyId)) {
|
|
|
|
|
- String updatedIds = currentIds == null ? newFamilyId : currentIds + "," + newFamilyId;
|
|
|
|
|
- teacher.setTeacherFamilyIds(updatedIds);
|
|
|
|
|
- teacher.setUpdatedAt(new java.util.Date());
|
|
|
|
|
- userMapper.updateById(teacher);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return Result.success(true);
|
|
|
|
|
|
|
+ @GetMapping("/packages/{level}")
|
|
|
|
|
+ public Result<List<GuidePackage>> getPackagesByLevel(@PathVariable String level) {
|
|
|
|
|
+ return Result.success(guidePackageService.getPackagesByLevel(level));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 成长规划师获取家庭邀请码(用于分享给家长)
|
|
|
|
|
- */
|
|
|
|
|
- @Operation(summary = "获取家庭邀请码")
|
|
|
|
|
- @PostMapping("/family/invite-code/{familyId}")
|
|
|
|
|
- public Result<String> getFamilyInviteCode(@RequestAttribute("userId") Long teacherId,
|
|
|
|
|
- @RequestAttribute("role") String role,
|
|
|
|
|
- @PathVariable Long familyId) {
|
|
|
|
|
- if (!"teacher".equals(role)) {
|
|
|
|
|
- return Result.error("只有成长规划师可以执行此操作");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Family family = familyMapper.selectById(familyId);
|
|
|
|
|
- if (family == null) {
|
|
|
|
|
- return Result.error("家庭不存在");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 检查家庭是否已绑定该成长规划师
|
|
|
|
|
- if (family.getTeacherId() != null && !family.getTeacherId().equals(teacherId)) {
|
|
|
|
|
- return Result.error("该家庭已绑定其他成长规划师");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果家庭没有邀请码,生成一个
|
|
|
|
|
- if (family.getInviteCode() == null || family.getInviteCode().isEmpty()) {
|
|
|
|
|
- family.setInviteCode(generateInviteCode());
|
|
|
|
|
- family.setUpdatedAt(new java.util.Date());
|
|
|
|
|
- familyMapper.updateById(family);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return Result.success(family.getInviteCode());
|
|
|
|
|
|
|
+ @PostMapping("/apply/new")
|
|
|
|
|
+ public Result<Boolean> applyNew(@RequestParam Long userId,
|
|
|
|
|
+ @RequestParam String targetLevel,
|
|
|
|
|
+ @RequestParam Long packageId,
|
|
|
|
|
+ @RequestParam String paymentProof) {
|
|
|
|
|
+ return Result.success(guideApplicationService.applyNew(userId, targetLevel, packageId, paymentProof));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private String generateInviteCode() {
|
|
|
|
|
- return UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase();
|
|
|
|
|
|
|
+ @PostMapping("/apply/upgrade")
|
|
|
|
|
+ public Result<Boolean> applyUpgrade(@RequestParam Long userId,
|
|
|
|
|
+ @RequestParam String fromLevel,
|
|
|
|
|
+ @RequestParam String toLevel,
|
|
|
|
|
+ @RequestParam String paymentProof) {
|
|
|
|
|
+ return Result.success(guideApplicationService.applyUpgrade(userId, fromLevel, toLevel, paymentProof));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "获取套餐模板列表")
|
|
|
|
|
- @GetMapping("/package-templates")
|
|
|
|
|
- public Result<List<GuidePackageTemplate>> getPackageTemplates() {
|
|
|
|
|
- List<GuidePackageTemplate> templates = templateService.getActiveTemplates();
|
|
|
|
|
- return Result.success(templates);
|
|
|
|
|
|
|
+ @GetMapping("/my")
|
|
|
|
|
+ public Result<Guide> getMyGuide(@RequestParam Long userId) {
|
|
|
|
|
+ return Result.success(guideService.getByUserId(userId));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "获取套餐模板详情")
|
|
|
|
|
- @GetMapping("/package-templates/{id}")
|
|
|
|
|
- public Result<GuidePackageTemplate> getPackageTemplate(@PathVariable Long id) {
|
|
|
|
|
- GuidePackageTemplate template = templateService.getTemplateById(id);
|
|
|
|
|
- return template != null ? Result.success(template) : Result.error("模板不存在");
|
|
|
|
|
|
|
+ @GetMapping("/applications/my")
|
|
|
|
|
+ public Result<List<GuideApplication>> getMyApplications(@RequestParam Long userId) {
|
|
|
|
|
+ LambdaQueryWrapper<GuideApplication> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(GuideApplication::getUserId, userId)
|
|
|
|
|
+ .orderByDesc(GuideApplication::getCreatedAt);
|
|
|
|
|
+ return Result.success(guideApplicationService.list(wrapper));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- @Operation(summary = "获取所有服务内容")
|
|
|
|
|
- @GetMapping("/services")
|
|
|
|
|
- public Result<List<ServiceContent>> getServices(
|
|
|
|
|
- @RequestParam(required = false) Long typeId) {
|
|
|
|
|
- List<ServiceContent> services;
|
|
|
|
|
- if (typeId != null) {
|
|
|
|
|
- services = serviceContentService.getContentsByType(typeId);
|
|
|
|
|
- } else {
|
|
|
|
|
- services = serviceContentService.getActiveContents();
|
|
|
|
|
|
|
+ @GetMapping("/my/packages")
|
|
|
|
|
+ public Result<List<GuidePackage>> getMyPackages(@RequestParam Long userId) {
|
|
|
|
|
+ Guide guide = guideService.getByUserId(userId);
|
|
|
|
|
+ if (guide == null) {
|
|
|
|
|
+ return Result.success(null);
|
|
|
}
|
|
}
|
|
|
- return Result.success(services);
|
|
|
|
|
|
|
+ return Result.success(guidePackageService.getPackagesByLevel(guide.getLevel()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Operation(summary = "获取团队统计")
|
|
|
|
|
- @GetMapping("/team/stats")
|
|
|
|
|
- public Result<Map<String, Object>> getTeamStats(@RequestAttribute("userId") Long userId) {
|
|
|
|
|
- Map<String, Object> stats = new HashMap<>();
|
|
|
|
|
- stats.put("totalSales", new BigDecimal("8000.00"));
|
|
|
|
|
- stats.put("myCommission", new BigDecimal("800.00"));
|
|
|
|
|
- stats.put("familyCount", 5);
|
|
|
|
|
- stats.put("memberCount", 2);
|
|
|
|
|
- return Result.success(stats);
|
|
|
|
|
|
|
+ @GetMapping("/package/templates")
|
|
|
|
|
+ public Result<List<GuidePackage>> getPackageTemplates() {
|
|
|
|
|
+ return Result.success(guidePackageService.getActivePackages());
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|