|
@@ -1,18 +1,18 @@
|
|
|
package com.etotem.cfc.controller.subscription;
|
|
package com.etotem.cfc.controller.subscription;
|
|
|
|
|
|
|
|
import com.etotem.cfc.common.Result;
|
|
import com.etotem.cfc.common.Result;
|
|
|
-import com.etotem.cfc.entity.Family;
|
|
|
|
|
|
|
+import com.etotem.cfc.dto.VirtualPayParamsDTO;
|
|
|
import com.etotem.cfc.entity.MemberSubscription;
|
|
import com.etotem.cfc.entity.MemberSubscription;
|
|
|
|
|
+import com.etotem.cfc.entity.MemberSubscriptionOrder;
|
|
|
import com.etotem.cfc.entity.PromotionTier;
|
|
import com.etotem.cfc.entity.PromotionTier;
|
|
|
import com.etotem.cfc.entity.SubscriptionBenefitLog;
|
|
import com.etotem.cfc.entity.SubscriptionBenefitLog;
|
|
|
import com.etotem.cfc.entity.User;
|
|
import com.etotem.cfc.entity.User;
|
|
|
-import com.etotem.cfc.mapper.FamilyMapper;
|
|
|
|
|
import com.etotem.cfc.mapper.MemberSubscriptionMapper;
|
|
import com.etotem.cfc.mapper.MemberSubscriptionMapper;
|
|
|
import com.etotem.cfc.mapper.SubscriptionBenefitLogMapper;
|
|
import com.etotem.cfc.mapper.SubscriptionBenefitLogMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
import com.etotem.cfc.service.MemberSubscriptionService;
|
|
import com.etotem.cfc.service.MemberSubscriptionService;
|
|
|
-import com.etotem.cfc.service.PaymentService;
|
|
|
|
|
import com.etotem.cfc.service.PromotionTierService;
|
|
import com.etotem.cfc.service.PromotionTierService;
|
|
|
|
|
+import com.etotem.cfc.service.VirtualPayService;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -33,12 +33,6 @@ public class SubscriptionController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private PromotionTierService promotionTierService;
|
|
private PromotionTierService promotionTierService;
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
|
- private PaymentService paymentService;
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private FamilyMapper familyMapper;
|
|
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
private UserMapper userMapper;
|
|
|
|
|
|
|
@@ -48,6 +42,9 @@ public class SubscriptionController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private SubscriptionBenefitLogMapper benefitLogMapper;
|
|
private SubscriptionBenefitLogMapper benefitLogMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private VirtualPayService virtualPayService;
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private ObjectMapper objectMapper;
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
|
@@ -96,8 +93,9 @@ public class SubscriptionController {
|
|
|
* 创建订阅订单(JSON body)
|
|
* 创建订阅订单(JSON body)
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/create")
|
|
@PostMapping("/create")
|
|
|
- public Result<Map<String, Object>> createOrder(@RequestAttribute Long familyId,
|
|
|
|
|
- @RequestBody Map<String, Object> body) {
|
|
|
|
|
|
|
+ public Result<Object> createOrder(@RequestAttribute Long familyId,
|
|
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
|
|
+ @RequestBody Map<String, Object> body) {
|
|
|
String level = (String) body.get("level");
|
|
String level = (String) body.get("level");
|
|
|
if (level == null) {
|
|
if (level == null) {
|
|
|
return Result.error("缺少level参数");
|
|
return Result.error("缺少level参数");
|
|
@@ -110,36 +108,30 @@ public class SubscriptionController {
|
|
|
amount = "L2".equals(level) ? 131400 : 36500;
|
|
amount = "L2".equals(level) ? 131400 : 36500;
|
|
|
}
|
|
}
|
|
|
String paymentType = body.get("paymentType") != null ? (String) body.get("paymentType") : "wechat";
|
|
String paymentType = body.get("paymentType") != null ? (String) body.get("paymentType") : "wechat";
|
|
|
- String orderNo = "SUB" + System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
if (testMode) {
|
|
if (testMode) {
|
|
|
- subscriptionService.subscribe(familyId, level, amount, paymentType, null, orderNo);
|
|
|
|
|
|
|
+ MemberSubscriptionOrder order = subscriptionService.createPendingOrder(familyId, level, amount, paymentType);
|
|
|
|
|
+ subscriptionService.activateSubscription(familyId, level, amount, paymentType, null, order.getOrderNo());
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("orderNo", orderNo);
|
|
|
|
|
|
|
+ result.put("orderNo", order.getOrderNo());
|
|
|
result.put("amount", amount);
|
|
result.put("amount", amount);
|
|
|
result.put("paymentUrl", null);
|
|
result.put("paymentUrl", null);
|
|
|
result.put("testMode", true);
|
|
result.put("testMode", true);
|
|
|
return Result.success(result);
|
|
return Result.success(result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Family family = familyMapper.selectById(familyId);
|
|
|
|
|
- Long creatorId = family != null ? family.getCreatorId() : null;
|
|
|
|
|
- User user = creatorId != null ? userMapper.selectById(creatorId) : null;
|
|
|
|
|
- String openid = user != null ? user.getOpenid() : null;
|
|
|
|
|
- Map<String, Object> payResult = paymentService.createWechatPrepay(orderNo, "订阅" + level, amount, openid);
|
|
|
|
|
- if (payResult != null && payResult.containsKey("paymentUrl")) {
|
|
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
|
|
- result.put("orderNo", orderNo);
|
|
|
|
|
- result.put("amount", amount);
|
|
|
|
|
- result.put("paymentUrl", payResult.get("paymentUrl"));
|
|
|
|
|
- return Result.success(result);
|
|
|
|
|
|
|
+ // sessionKey 后端从登录态取(users.session_key,@JsonIgnore 防泄露),不由前端传
|
|
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
|
|
+ if (user == null || user.getSessionKey() == null || user.getSessionKey().isEmpty()) {
|
|
|
|
|
+ return Result.error(400, "会话失效,请重新登录");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- subscriptionService.subscribe(familyId, level, amount, paymentType, null, orderNo);
|
|
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
|
|
- result.put("orderNo", orderNo);
|
|
|
|
|
- result.put("amount", amount);
|
|
|
|
|
- return Result.success(result);
|
|
|
|
|
|
|
+ MemberSubscriptionOrder order = subscriptionService.createPendingOrder(familyId, level, amount, paymentType);
|
|
|
|
|
+ VirtualPayParamsDTO dto = virtualPayService.generateSubscriptionPayParams(order.getOrderNo(), user.getSessionKey());
|
|
|
|
|
+ if (dto == null) {
|
|
|
|
|
+ return Result.error(46001, "该商品暂未开放购买");
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.success(dto);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -151,6 +143,9 @@ public class SubscriptionController {
|
|
|
@RequestParam Integer amount,
|
|
@RequestParam Integer amount,
|
|
|
@RequestParam String paymentType,
|
|
@RequestParam String paymentType,
|
|
|
@RequestParam(required = false) String transactionId) {
|
|
@RequestParam(required = false) String transactionId) {
|
|
|
|
|
+ if (!testMode) {
|
|
|
|
|
+ return Result.error("仅测试模式可用,正式订阅请走 /create 虚拟支付");
|
|
|
|
|
+ }
|
|
|
String orderNo = "SUB" + System.currentTimeMillis();
|
|
String orderNo = "SUB" + System.currentTimeMillis();
|
|
|
subscriptionService.subscribe(familyId, level, amount, paymentType, transactionId, orderNo);
|
|
subscriptionService.subscribe(familyId, level, amount, paymentType, transactionId, orderNo);
|
|
|
return Result.success(null);
|
|
return Result.success(null);
|