|
|
@@ -10,12 +10,11 @@ import com.cyksj.common.util.Codec;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.config.WeChatConfig;
|
|
|
import com.cyksj.dto.RedisKey;
|
|
|
+import com.cyksj.mapper.AppleAutoRegisterDataMapper;
|
|
|
import com.cyksj.mapper.RegisterOrderDonMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.model.dto.H5JsPayParams;
|
|
|
-import com.cyksj.model.entity.RegisterOrderDon;
|
|
|
-import com.cyksj.model.entity.SysConfig;
|
|
|
-import com.cyksj.model.entity.User;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.request.RegisterReq;
|
|
|
import com.cyksj.model.request.OrderAttach;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
@@ -23,6 +22,7 @@ import com.cyksj.service.register.RegisterOrderDonService;
|
|
|
import com.cyksj.service.register.SpotifyService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
+import com.cyksj.task.JobManager;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -57,6 +57,14 @@ public class RegisterOrderDonServiceImpl extends ServiceImpl<RegisterOrderDonMap
|
|
|
|
|
|
private final UserMapper userMapper;
|
|
|
|
|
|
+ private final AppleAutoRegisterDataMapper appleAutoRegisterDataMapper;
|
|
|
+
|
|
|
+ private final JobManager jobManager;
|
|
|
+
|
|
|
+ private final RegisterOrderDonMapper registerOrderDonMapper;
|
|
|
+
|
|
|
+ private static final Long EXPIRY_TIME = 1000 * 60 * 5L;
|
|
|
+
|
|
|
/**
|
|
|
* 判断是否免费
|
|
|
* @author chan
|
|
|
@@ -93,7 +101,6 @@ public class RegisterOrderDonServiceImpl extends ServiceImpl<RegisterOrderDonMap
|
|
|
BeanUtil.copyProperties(req,orderDon);
|
|
|
SysConfig register_price = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "register_price").last("limit 1"));
|
|
|
Map<String, Integer> map = Jsons.toMap(register_price.getSysValue());
|
|
|
-
|
|
|
orderDon.setOrderNo(SEQUENCE.nextId() + "");
|
|
|
orderDon.setUserId(userId);
|
|
|
orderDon.setOpenId(user.getOpenId());
|
|
|
@@ -101,15 +108,68 @@ public class RegisterOrderDonServiceImpl extends ServiceImpl<RegisterOrderDonMap
|
|
|
orderDon.setMoney(isFree ? BigDecimal.ZERO : BigDecimal.valueOf(map.get(req.getPlatform())));
|
|
|
orderDon.setStatus(isFree ? RegisterOrderDon.Status.hasPayment : RegisterOrderDon.Status.noPayment);
|
|
|
save(orderDon);
|
|
|
-
|
|
|
+ //apple
|
|
|
+ handleAppleIdAuto(userId, req, orderDon);
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Apple ID自动注册
|
|
|
+ */
|
|
|
+ private void handleAppleIdAuto(long userId, RegisterReq req, RegisterOrderDon orderDon) {
|
|
|
+ if ("apple".equals(req.getPlatform()) && "auto".equals(req.getAppleRegisterType())) {
|
|
|
+ //是否有未支付的国家或区域的订单
|
|
|
+ Integer exists = appleAutoRegisterDataMapper.checkNoPayOrder(userId, req.getCountryOrArea());
|
|
|
+ if (exists != null) {
|
|
|
+ throw BusinessRuntimeException.getInstance(String.format("您有%s随机生成Apple ID未支付的订单", req.getCountryOrArea().getDesc()));
|
|
|
+ }
|
|
|
+ if (req.getCountryOrArea() == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请选择对应的国家或地区");
|
|
|
+ }
|
|
|
+ //查看是否有空余账号
|
|
|
+ AppleAutoRegisterData appleAutoRegisterData = appleAutoRegisterDataMapper.selectOne(Wrappers.lambdaQuery(AppleAutoRegisterData.class).eq(AppleAutoRegisterData::getCountryOrArea, req.getCountryOrArea()).eq(AppleAutoRegisterData::getStatus, false).select(AppleAutoRegisterData::getId).last("limit 1"));
|
|
|
+ if (appleAutoRegisterData == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("自动生成Apple ID库存不足");
|
|
|
+ }
|
|
|
+ appleAutoRegisterData.setUserId(userId);
|
|
|
+ appleAutoRegisterData.setStatus(true);
|
|
|
+ appleAutoRegisterData.setOrderId(orderDon.getId());
|
|
|
+ int update = appleAutoRegisterDataMapper.update(appleAutoRegisterData, Wrappers.lambdaUpdate(AppleAutoRegisterData.class).eq(AppleAutoRegisterData::getStatus, false).eq(AppleAutoRegisterData::getId, appleAutoRegisterData.getId()));
|
|
|
+ if (update != 1) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请重新操作");
|
|
|
+ }
|
|
|
+ jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
+ updateAppleAutoStatus(orderDon.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateAppleAutoStatus(Long orderId) {
|
|
|
+ log.info("校验appleID自动注册订单 orderId:{}", orderId);
|
|
|
+ RegisterOrderDon registerOrderDon = this.getById(orderId);
|
|
|
+ if (registerOrderDon != null && RegisterOrderDon.Status.noPayment == registerOrderDon.getStatus()) {
|
|
|
+ AppleAutoRegisterData appleAutoRegisterData = appleAutoRegisterDataMapper.selectOne(Wrappers.lambdaQuery(AppleAutoRegisterData.class).eq(AppleAutoRegisterData::getOrderId, orderId).last("limit 1"));
|
|
|
+ if (appleAutoRegisterData != null) {
|
|
|
+ appleAutoRegisterData.setStatus(false);
|
|
|
+ appleAutoRegisterData.setUserId(0l);
|
|
|
+ appleAutoRegisterData.setOrderId(0l);
|
|
|
+ appleAutoRegisterDataMapper.updateById(appleAutoRegisterData);
|
|
|
+ //订单关闭
|
|
|
+ registerOrderDon.setStatus(RegisterOrderDon.Status.close);
|
|
|
+ registerOrderDonMapper.updateById(registerOrderDon);
|
|
|
+ log.info("未支付appleID自动注册订单:{},修改appleID使用状态", orderId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public H5JsPayParams pay(Long orderId) throws Exception {
|
|
|
log.info("注册 账号调起微信支付[start] orderId:{}", orderId);
|
|
|
RegisterOrderDon orderDon = this.getById(orderId);
|
|
|
-
|
|
|
+ if (orderDon.getStatus() == RegisterOrderDon.Status.close) {
|
|
|
+ throw BusinessRuntimeException.getInstance("订单已关闭");
|
|
|
+ }
|
|
|
OrderAttach attach = new OrderAttach();
|
|
|
attach.setO(orderDon.getId());
|
|
|
|
|
|
@@ -125,7 +185,7 @@ public class RegisterOrderDonServiceImpl extends ServiceImpl<RegisterOrderDonMap
|
|
|
toWechatAttach,
|
|
|
"注册服务",
|
|
|
"JSAPI",
|
|
|
- orderDon.getCreatedTime()
|
|
|
+ null
|
|
|
);
|
|
|
|
|
|
log.info("微信支付成功[end]");
|
|
|
@@ -169,6 +229,10 @@ public class RegisterOrderDonServiceImpl extends ServiceImpl<RegisterOrderDonMap
|
|
|
// 更改订单状态
|
|
|
order.setTransactionId(transactionId);
|
|
|
order.setStatus(RegisterOrderDon.Status.hasPayment);
|
|
|
+ AppleAutoRegisterData appleAutoRegisterData = appleAutoRegisterDataMapper.selectOne(Wrappers.lambdaQuery(AppleAutoRegisterData.class).eq(AppleAutoRegisterData::getOrderId, order.getId()).eq(AppleAutoRegisterData::getStatus, true));
|
|
|
+ if (appleAutoRegisterData != null) {
|
|
|
+ order.setStatus(RegisterOrderDon.Status.complete);
|
|
|
+ }
|
|
|
|
|
|
order.setPayTime(DateUtil.parse(map.get("time_end"), "yyyyMMddHHmmss"));
|
|
|
|