PurchaseController.java 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.etotem.cfc.controller;
  2. import com.etotem.cfc.common.Result;
  3. import com.etotem.cfc.service.PurchaseService;
  4. import com.etotem.cfc.service.ChallengeService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.*;
  7. import javax.servlet.http.HttpServletRequest;
  8. import java.util.Map;
  9. @RestController
  10. @RequestMapping("/api/purchase")
  11. public class PurchaseController {
  12. @Autowired private PurchaseService purchaseService;
  13. @Autowired private ChallengeService challengeService;
  14. @PostMapping("/check")
  15. public Result<Map<String, Object>> checkPurchase(HttpServletRequest request) {
  16. Long userId = (Long) request.getAttribute("userId");
  17. Map<String, Object> result = purchaseService.checkPurchase(userId);
  18. return Result.success(result);
  19. }
  20. @PostMapping("/create")
  21. public Result<Map<String, Object>> createOrder(HttpServletRequest request) {
  22. Long userId = (Long) request.getAttribute("userId");
  23. Long familyId = (Long) request.getAttribute("familyId");
  24. Map<String, Object> result = purchaseService.createOrder(userId, familyId);
  25. return Result.success(result);
  26. }
  27. @PostMapping("/confirm")
  28. public Result<Map<String, Object>> confirmPayment(@RequestBody Map<String, Object> params, HttpServletRequest request) {
  29. String orderNo = (String) params.get("orderNo");
  30. String paymentMethod = (String) params.get("paymentMethod");
  31. String transactionId = (String) params.get("transactionId");
  32. Map<String, Object> result = purchaseService.confirmPayment(orderNo, paymentMethod, transactionId);
  33. return Result.success(result);
  34. }
  35. @PostMapping("/renewal-info")
  36. public Result<Map<String, Object>> getRenewalInfo(HttpServletRequest request) {
  37. Long userId = (Long) request.getAttribute("userId");
  38. Map<String, Object> result = purchaseService.getRenewalInfo(userId);
  39. return Result.success(result);
  40. }
  41. @PostMapping("/renew")
  42. public Result<Map<String, Object>> renew(@RequestBody Map<String, Object> params, HttpServletRequest request) {
  43. Long userId = (Long) request.getAttribute("userId");
  44. Long familyId = (Long) request.getAttribute("familyId");
  45. Integer amount = params.get("amount") != null ? ((Number) params.get("amount")).intValue() : null;
  46. Map<String, Object> result = purchaseService.processRenewal(userId, familyId, amount);
  47. return Result.success(result);
  48. }
  49. @GetMapping("/challenge/progress")
  50. public Result<Map<String, Object>> getChallengeProgress(@RequestParam Long memberId, HttpServletRequest request) {
  51. Map<String, Object> result = challengeService.getChallengeProgress(memberId);
  52. return Result.success(result);
  53. }
  54. @PostMapping("/challenge/update")
  55. public Result<Void> updateChallengeProgress(@RequestBody Map<String, Object> params, HttpServletRequest request) {
  56. Long memberId = (Long) params.get("memberId");
  57. String taskKey = (String) params.get("taskKey");
  58. int currentValue = ((Number) params.get("currentValue")).intValue();
  59. challengeService.updateTaskProgress(memberId, taskKey, currentValue);
  60. return Result.success(null);
  61. }
  62. }