|
|
@@ -3,6 +3,7 @@ package com.cyksj.service.order.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUnit;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
@@ -303,6 +304,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final MidjourneyUserMapper midjourneyUserMapper;
|
|
|
|
|
|
+ private final ChatgptUserMapper chatgptUserMapper;
|
|
|
+
|
|
|
private final DistributeExtraRebateService distributeExtraRebateService;
|
|
|
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
@@ -3234,14 +3237,41 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (upgradePackage.getPrice() == null || upgradePackage.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
throw BusinessRuntimeException.getInstance("下单商品价格异常");
|
|
|
}
|
|
|
- if (payRequest.getDonMoney().compareTo(upgradePackage.getPrice()) < 0) {
|
|
|
- log.info("套餐包:{}支付金额:{}异常,调整用户userId:{}支付金额为:{}", upgradePackage.getName(), payRequest.getDonMoney(), user.getId(), upgradePackage.getPrice());
|
|
|
- payRequest.setDonMoney(upgradePackage.getPrice());
|
|
|
+ if (goodsDonSku.getGoodsId() == 18) {
|
|
|
+ ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getRelationId, payRequest.getRelationId()));
|
|
|
+ if (chatgptUser == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("车票未激活gpt账号,请先激活");
|
|
|
+ }
|
|
|
+ if (chatgptUser.getLimitNum() > goodsDonSku.getGptLimitNum()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("您已升级车票套餐");
|
|
|
+ }
|
|
|
+ Date expiryTime = groupsRelation.getExpiryTime();
|
|
|
+ //剩余多少天
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+ long day = DateUtil.between(now, expiryTime, DateUnit.DAY);
|
|
|
+
|
|
|
+ BigDecimal upgradePackagePrice = upgradePackage.getPrice();
|
|
|
+ //自然月差价
|
|
|
+ int thisMonthDays = DateUtil.endOfMonth(now).dayOfMonth();
|
|
|
+ BigDecimal singlePrice = upgradePackagePrice.divide(BigDecimal.valueOf(thisMonthDays));
|
|
|
+
|
|
|
+ BigDecimal payUpgradePackagePrice = singlePrice.multiply(BigDecimal.valueOf(day));
|
|
|
+ if (payRequest.getDonMoney().compareTo(payUpgradePackagePrice) < 0) {
|
|
|
+ payRequest.setDonMoney(payUpgradePackagePrice);
|
|
|
+ }
|
|
|
}
|
|
|
- MidjourneyUser midjourneyUser = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class).eq(MidjourneyUser::getRelationId, payRequest.getRelationId()));
|
|
|
- if (midjourneyUser == null){
|
|
|
- throw BusinessRuntimeException.getInstance("车票未激活Midjourney账号,请先激活");
|
|
|
+
|
|
|
+ if (goodsDonSku.getGoodsId() == 26) {
|
|
|
+ if (payRequest.getDonMoney().compareTo(upgradePackage.getPrice()) < 0) {
|
|
|
+ log.info("套餐包:{}支付金额:{}异常,调整用户userId:{}支付金额为:{}", upgradePackage.getName(), payRequest.getDonMoney(), user.getId(), upgradePackage.getPrice());
|
|
|
+ payRequest.setDonMoney(upgradePackage.getPrice());
|
|
|
+ }
|
|
|
+ MidjourneyUser midjourneyUser = midjourneyUserMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUser.class).eq(MidjourneyUser::getRelationId, payRequest.getRelationId()));
|
|
|
+ if (midjourneyUser == null){
|
|
|
+ throw BusinessRuntimeException.getInstance("车票未激活Midjourney账号,请先激活");
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
String donNo = SEQUENCE.nextId().toString();
|
|
|
UpgradeOrderDon upgradeOrderDon = new UpgradeOrderDon();
|
|
|
upgradeOrderDon.setOrderNo(donNo);
|
|
|
@@ -3415,6 +3445,31 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //gpt 升级套餐
|
|
|
+ if (upgradePackage.getGoodsId() == 18) {
|
|
|
+ ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getRelationId, orderDon.getRelationId()));
|
|
|
+ Long oriTime = chatgptUser.getLimitTime();
|
|
|
+ if (chatgptUser != null) {
|
|
|
+ Integer time = upgradePackage.getTime();
|
|
|
+ Integer num = upgradePackage.getNum();
|
|
|
+
|
|
|
+ int update = chatgptUserMapper.update(null, Wrappers.lambdaUpdate(ChatgptUser.class)
|
|
|
+ .set(ChatgptUser::getLimitTime, time)
|
|
|
+ .set(ChatgptUser::getLimitNum, num)
|
|
|
+ .eq(ChatgptUser::getId, chatgptUser.getId()));
|
|
|
+ if (update == 0) {
|
|
|
+ log.info("chatgptUser 升级套餐包增值失败 id:{},orderId:{}", chatgptUser.getId(), orderDon.getId());
|
|
|
+ }
|
|
|
+ String key = RedisService.key.CHATGPT_CONVERSATION_LIMIT.getName() + ":" + chatgptUser.getUserToken();
|
|
|
+ Long expire = redisService.getExpire(key);
|
|
|
+ //存在
|
|
|
+ if (expire > 0) {
|
|
|
+ //加上剩余的时间
|
|
|
+ redisService.expire(key, expire + (time - oriTime) * 60 * 60);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|