|
|
@@ -57,6 +57,9 @@ public class SubscriptionController {
|
|
|
*/
|
|
|
@PostMapping("/status")
|
|
|
public Result<Map<String, Object>> getSubscriptionStatus(@RequestAttribute Long familyId) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
MemberSubscription sub = subscriptionService.getActiveSubscription(familyId);
|
|
|
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
@@ -97,6 +100,9 @@ public class SubscriptionController {
|
|
|
public Result<Object> createOrder(@RequestAttribute Long familyId,
|
|
|
@RequestAttribute("userId") Long userId,
|
|
|
@RequestBody Map<String, Object> body) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
String level = (String) body.get("level");
|
|
|
if (level == null) {
|
|
|
return Result.error("缺少level参数");
|
|
|
@@ -144,6 +150,9 @@ public class SubscriptionController {
|
|
|
@RequestParam Integer amount,
|
|
|
@RequestParam String paymentType,
|
|
|
@RequestParam(required = false) String transactionId) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
if (!testMode) {
|
|
|
return Result.error("仅测试模式可用,正式订阅请走 /create 虚拟支付");
|
|
|
}
|
|
|
@@ -157,6 +166,9 @@ public class SubscriptionController {
|
|
|
*/
|
|
|
@PostMapping("/cancel")
|
|
|
public Result<Void> cancel(@RequestAttribute Long familyId) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
subscriptionService.cancelSubscription(familyId);
|
|
|
return Result.success(null);
|
|
|
}
|
|
|
@@ -167,6 +179,9 @@ public class SubscriptionController {
|
|
|
@PostMapping("/auto-renew")
|
|
|
public Result<Void> setAutoRenew(@RequestAttribute Long familyId,
|
|
|
@RequestBody Map<String, Object> body) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
Object enabledObj = body.get("enabled");
|
|
|
int enabled = 0;
|
|
|
if (enabledObj != null) {
|
|
|
@@ -182,6 +197,9 @@ public class SubscriptionController {
|
|
|
*/
|
|
|
@PostMapping("/benefits/my")
|
|
|
public Result<List<Map<String, Object>>> getMyBenefits(@RequestAttribute Long familyId) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
MemberSubscription sub = subscriptionService.getActiveSubscription(familyId);
|
|
|
if (sub == null) {
|
|
|
return Result.success(new ArrayList<>());
|
|
|
@@ -211,6 +229,9 @@ public class SubscriptionController {
|
|
|
@PostMapping("/benefit/check")
|
|
|
public Result<Map<String, Object>> checkBenefit(@RequestAttribute Long familyId,
|
|
|
@RequestBody Map<String, Object> body) {
|
|
|
+ if (familyId == null) {
|
|
|
+ return Result.noFamily("请先创建或加入家庭");
|
|
|
+ }
|
|
|
String benefitCode = (String) body.get("benefitCode");
|
|
|
if (benefitCode == null || benefitCode.isEmpty()) {
|
|
|
return Result.error("缺少benefitCode");
|