| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- package com.etotem.cfc.controller.guide;
- import com.etotem.cfc.common.Result;
- import com.etotem.cfc.dto.GuideRegisterDTO;
- import com.etotem.cfc.dto.PackagePurchaseDTO;
- import com.etotem.cfc.entity.GuideApplication;
- import com.etotem.cfc.entity.GuideApplicationRecord;
- import com.etotem.cfc.entity.GuideInviteCode;
- import com.etotem.cfc.entity.GuidePackage;
- import com.etotem.cfc.entity.GuideHierarchy;
- import com.etotem.cfc.entity.PackageOrder;
- import com.etotem.cfc.entity.User;
- import com.etotem.cfc.mapper.UserMapper;
- import com.etotem.cfc.service.GuideApplicationService;
- import com.etotem.cfc.service.GuideHierarchyService;
- import com.etotem.cfc.service.GuideInviteCodeService;
- import com.etotem.cfc.service.GuidePackageService;
- import com.etotem.cfc.service.UserService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * 成长规划师管理控制器
- */
- @Tag(name = "成长规划师管理", description = "成长规划师注册、邀请码、层级关系等接口")
- @RestController
- @RequestMapping("/api/guide")
- public class GuideManagementController {
- @Resource
- private GuideInviteCodeService guideInviteCodeService;
- @Resource
- private GuideHierarchyService guideHierarchyService;
- @Resource
- private GuidePackageService guidePackageService;
- @Resource
- private UserMapper userMapper;
- @Resource
- private UserService userService;
- @Resource
- private GuideApplicationService guideApplicationService;
- /**
- * 成长规划师注册(保存草稿)
- */
- @Operation(summary = "成长规划师注册")
- @PostMapping("/register")
- public Result<Boolean> registerGuide(@RequestBody GuideRegisterDTO dto) {
- // 检查用户是否存在
- User user = userMapper.selectById(dto.getUserId());
- if (user == null) {
- return Result.error("用户不存在");
- }
- // 更新用户信息
- user.setTeacherNo(dto.getTeacherNo());
- user.setTeacherPhoto(dto.getTeacherPhoto());
- user.setCertificateImage(dto.getCertificateImage());
- user.setRealName(dto.getRealName());
- user.setPhone(dto.getPhone());
- user.setIdCard(dto.getIdCard());
- user.setAddress(dto.getAddress());
- user.setTeacherStatus("pending");
- user.setUpdatedAt(new java.util.Date());
- userMapper.updateById(user);
- // 创建申请记录
- guideApplicationService.createDraft(
- dto.getUserId(), "new_apply", "junior", null,
- dto.getRealName(), dto.getPhone(), dto.getIdCard(),
- dto.getTeacherNo(), dto.getTeacherPhoto(), dto.getCertificateImage(),
- dto.getAddress(), dto.getBankCard(), dto.getBankName()
- );
- // 将teacher角色添加到用户的角色列表中
- userService.addRole(user.getId(), "teacher");
- return Result.success(true);
- }
- /**
- * 提交申请(draft -> pending)
- */
- @Operation(summary = "提交成长规划师申请")
- @PostMapping("/application/submit")
- public Result<Boolean> submitApplication(@RequestAttribute("userId") Long userId) {
- // 查找用户的草稿申请
- List<GuideApplication> apps = guideApplicationService.getUserApplications(userId);
- GuideApplication draft = null;
- for (GuideApplication app : apps) {
- if ("draft".equals(app.getStatus())) {
- draft = app;
- break;
- }
- }
- if (draft == null) {
- return Result.error("未找到草稿申请");
- }
- boolean success = guideApplicationService.submitApplication(draft.getId(), userId);
- return success ? Result.success(true) : Result.error("提交失败");
- }
- /**
- * 撤回申请
- */
- @Operation(summary = "撤回成长规划师申请")
- @PostMapping("/application/withdraw")
- public Result<Boolean> withdrawApplication(@RequestAttribute("userId") Long userId) {
- List<GuideApplication> apps = guideApplicationService.getUserApplications(userId);
- GuideApplication pending = null;
- for (GuideApplication app : apps) {
- if ("pending".equals(app.getStatus())) {
- pending = app;
- break;
- }
- }
- if (pending == null) {
- return Result.error("未找到待审核的申请");
- }
- boolean success = guideApplicationService.withdrawApplication(pending.getId(), userId);
- return success ? Result.success(true) : Result.error("撤回失败");
- }
- /**
- * 重新提交申请
- */
- @Operation(summary = "重新提交成长规划师申请")
- @PostMapping("/application/resubmit")
- public Result<Boolean> resubmitApplication(@RequestAttribute("userId") Long userId) {
- List<GuideApplication> apps = guideApplicationService.getUserApplications(userId);
- GuideApplication target = null;
- for (GuideApplication app : apps) {
- if ("withdrawn".equals(app.getStatus()) || "rejected".equals(app.getStatus())) {
- target = app;
- break;
- }
- }
- if (target == null) {
- return Result.error("未找到可重新提交的申请");
- }
- boolean success = guideApplicationService.resubmitApplication(target.getId(), userId);
- return success ? Result.success(true) : Result.error("重新提交失败");
- }
- /**
- * 获取用户申请列表
- */
- @Operation(summary = "获取用户申请列表")
- @PostMapping("/applications")
- public Result<List<GuideApplication>> getUserApplications(@RequestAttribute("userId") Long userId) {
- return Result.success(guideApplicationService.getUserApplications(userId));
- }
- /**
- * 获取申请处理记录
- */
- @Operation(summary = "获取申请处理记录")
- @PostMapping("/application/{id}/records")
- public Result<List<GuideApplicationRecord>> getApplicationRecords(@PathVariable Long id) {
- return Result.success(guideApplicationService.getApplicationRecords(id));
- }
- /**
- * 如果有邀请码,验证并建立层级关系
- */
- private void processInviteCode(String inviteCode, Long userId) {
- if (inviteCode != null && !inviteCode.isEmpty()) {
- GuideInviteCode code = guideInviteCodeService.validateInviteCode(inviteCode);
- if (code != null) {
- guideHierarchyService.addChildGuide(code.getGuideId(), userId);
- guideInviteCodeService.useInviteCode(inviteCode, userId);
- }
- }
- }
- /**
- * 生成邀请码
- */
- @Operation(summary = "生成邀请码")
- @PostMapping("/invite-code/generate")
- public Result<GuideInviteCode> generateInviteCode(@RequestAttribute("userId") Long userId,
- @RequestParam(defaultValue = "1") Integer maxUseCount,
- @RequestParam(defaultValue = "30") Integer expireDays) {
- GuideInviteCode inviteCode = guideInviteCodeService.generateInviteCode(userId, maxUseCount, expireDays);
- return Result.success(inviteCode);
- }
- /**
- * 获取邀请码列表
- */
- @Operation(summary = "获取邀请码列表")
- @PostMapping("/invite-codes")
- public Result<List<GuideInviteCode>> getInviteCodes(@RequestAttribute("userId") Long userId) {
- List<GuideInviteCode> inviteCodes = guideInviteCodeService.getGuideInviteCodes(userId);
- return Result.success(inviteCodes);
- }
- /**
- * 验证邀请码
- */
- @Operation(summary = "验证邀请码")
- @PostMapping("/invite-code/validate")
- public Result<Map<String, Object>> validateInviteCode(@RequestParam String code) {
- GuideInviteCode inviteCode = guideInviteCodeService.validateInviteCode(code);
- if (inviteCode == null) {
- return Result.error("邀请码无效或已过期");
- }
- Map<String, Object> result = new HashMap<>();
- result.put("guideId", inviteCode.getGuideId());
- result.put("code", inviteCode.getCode());
- result.put("maxUseCount", inviteCode.getMaxUseCount());
- result.put("useCount", inviteCode.getUseCount());
- result.put("expireAt", inviteCode.getExpireAt());
- User guide = userMapper.selectById(inviteCode.getGuideId());
- if (guide != null) {
- result.put("guideName", guide.getNickname());
- result.put("guideAvatar", guide.getAvatar());
- }
- return Result.success(result);
- }
- /**
- * 获取下级成长规划师列表
- */
- @Operation(summary = "获取下级成长规划师列表")
- @PostMapping("/child-guides")
- public Result<List<User>> getChildGuides(@RequestAttribute("userId") Long userId) {
- List<User> childGuides = guideHierarchyService.getChildGuides(userId);
- return Result.success(childGuides);
- }
- /**
- * 获取所有下级成长规划师(包括间接下级)
- */
- @Operation(summary = "获取所有下级成长规划师")
- @PostMapping("/all-child-guides")
- public Result<List<User>> getAllChildGuides(@RequestAttribute("userId") Long userId) {
- List<User> childGuides = guideHierarchyService.getAllChildGuides(userId);
- return Result.success(childGuides);
- }
- /**
- * 获取上级成长规划师
- */
- @Operation(summary = "获取上级成长规划师")
- @PostMapping("/parent-guide")
- public Result<User> getParentGuide(@RequestAttribute("userId") Long userId) {
- User parentGuide = guideHierarchyService.getParentGuide(userId);
- return Result.success(parentGuide);
- }
- /**
- * 添加成长规划师套餐
- */
- @Operation(summary = "添加成长规划师套餐")
- @PostMapping("/package/add")
- public Result<Boolean> addGuidePackage(@RequestAttribute("userId") Long userId,
- @RequestBody Map<String, Object> params) {
- Long packageId = Long.valueOf(params.get("packageId").toString());
- Integer price = Integer.valueOf(params.get("price").toString());
- Integer commissionRate = params.containsKey("commissionRate")
- ? Integer.valueOf(params.get("commissionRate").toString())
- : 1000; // 默认10%
- boolean success = guidePackageService.addGuidePackage(userId, packageId, price, commissionRate);
- return Result.success(success);
- }
- /**
- * 获取成长规划师对特定套餐的定价
- */
- @Operation(summary = "获取成长规划师套餐定价")
- @PostMapping("/package/{packageId}")
- public Result<GuidePackage> getGuidePackage(@RequestAttribute("userId") Long userId,
- @PathVariable Long packageId) {
- GuidePackage guidePackage = guidePackageService.getGuidePackage(userId, packageId);
- return Result.success(guidePackage);
- }
- /**
- * 更新成长规划师套餐价格
- */
- @Operation(summary = "更新成长规划师套餐价格")
- @PostMapping("/package/{packageId}/update")
- public Result<Boolean> updateGuidePackage(@RequestAttribute("userId") Long userId,
- @PathVariable Long packageId,
- @RequestBody Map<String, Object> params) {
- Integer price = Integer.valueOf(params.get("price").toString());
- boolean success = guidePackageService.updateGuidePackagePrice(userId, packageId, price);
- return Result.success(success);
- }
- /**
- * 删除成长规划师套餐
- */
- @Operation(summary = "删除成长规划师套餐")
- @PostMapping("/package/{packageId}/delete")
- public Result<Boolean> deleteGuidePackage(@RequestAttribute("userId") Long userId,
- @PathVariable Long packageId) {
- boolean success = guidePackageService.deleteGuidePackage(userId, packageId);
- return Result.success(success);
- }
- }
|