| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package com.etotem.cfc.controller;
- import com.etotem.cfc.common.Result;
- import com.etotem.cfc.service.PurchaseService;
- import com.etotem.cfc.service.ChallengeService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import java.util.Map;
- @RestController
- @RequestMapping("/api/purchase")
- public class PurchaseController {
- @Autowired private PurchaseService purchaseService;
- @Autowired private ChallengeService challengeService;
- @PostMapping("/check")
- public Result<Map<String, Object>> checkPurchase(HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- Map<String, Object> result = purchaseService.checkPurchase(userId);
- return Result.success(result);
- }
- @PostMapping("/create")
- public Result<Map<String, Object>> createOrder(HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- Long familyId = (Long) request.getAttribute("familyId");
- Map<String, Object> result = purchaseService.createOrder(userId, familyId);
- return Result.success(result);
- }
- @PostMapping("/confirm")
- public Result<Map<String, Object>> confirmPayment(@RequestBody Map<String, Object> params, HttpServletRequest request) {
- String orderNo = (String) params.get("orderNo");
- String paymentMethod = (String) params.get("paymentMethod");
- String transactionId = (String) params.get("transactionId");
- Map<String, Object> result = purchaseService.confirmPayment(orderNo, paymentMethod, transactionId);
- return Result.success(result);
- }
- @PostMapping("/renewal-info")
- public Result<Map<String, Object>> getRenewalInfo(HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- Map<String, Object> result = purchaseService.getRenewalInfo(userId);
- return Result.success(result);
- }
- @PostMapping("/renew")
- public Result<Map<String, Object>> renew(@RequestBody Map<String, Object> params, HttpServletRequest request) {
- Long userId = (Long) request.getAttribute("userId");
- Long familyId = (Long) request.getAttribute("familyId");
- Integer amount = params.get("amount") != null ? ((Number) params.get("amount")).intValue() : null;
- Map<String, Object> result = purchaseService.processRenewal(userId, familyId, amount);
- return Result.success(result);
- }
- @GetMapping("/challenge/progress")
- public Result<Map<String, Object>> getChallengeProgress(@RequestParam Long memberId, HttpServletRequest request) {
- Map<String, Object> result = challengeService.getChallengeProgress(memberId);
- return Result.success(result);
- }
- @PostMapping("/challenge/update")
- public Result<Void> updateChallengeProgress(@RequestBody Map<String, Object> params, HttpServletRequest request) {
- Long memberId = (Long) params.get("memberId");
- String taskKey = (String) params.get("taskKey");
- int currentValue = ((Number) params.get("currentValue")).intValue();
- challengeService.updateTaskProgress(memberId, taskKey, currentValue);
- return Result.success(null);
- }
- }
|