|
|
@@ -29,7 +29,6 @@ import com.cyksj.model.dto.CouponPopularizeDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.request.ClaudeCodeApiKeysReq;
|
|
|
import com.cyksj.model.request.ClaudeCodeDelReq;
|
|
|
-import com.cyksj.model.request.CodexUpgradePayReq;
|
|
|
import com.cyksj.model.request.UpdateDailyLimitRequest;
|
|
|
import com.cyksj.model.request.codex.CodexUserPackageReq;
|
|
|
import com.cyksj.model.response.CodexDeductResp;
|
|
|
@@ -38,12 +37,9 @@ import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.api.ClaudeCodexApiService;
|
|
|
import com.cyksj.service.codex.CodexService;
|
|
|
-import com.cyksj.service.coin.UserGalaxyCoinService;
|
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
|
import com.cyksj.service.groups.GroupsFuncService;
|
|
|
-import com.cyksj.service.order.OrderDonService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
-import com.cyksj.task.JobManager;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
|
@@ -56,7 +52,6 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
@@ -122,14 +117,6 @@ public class CodexServiceImpl implements CodexService {
|
|
|
|
|
|
private final ClaudeCodexApiService claudeCodexApiService;
|
|
|
|
|
|
- private final OrderDonService orderDonService;
|
|
|
-
|
|
|
- private final UserGalaxyCoinService userGalaxyCoinService;
|
|
|
-
|
|
|
- private final JobManager jobManager;
|
|
|
-
|
|
|
- private static final Long EXPIRY_TIME = 1000 * 60 * 5L;
|
|
|
-
|
|
|
@Override
|
|
|
public void createOrUpdateUserPackage(CodexUserPackageReq req) {
|
|
|
Long userId = req.getUserId();
|
|
|
@@ -210,113 +197,6 @@ public class CodexServiceImpl implements CodexService {
|
|
|
return codexDeductResp;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Throwable.class)
|
|
|
- public OrderDon deductSubmitOrder(CodexUpgradePayReq payReq) throws Exception {
|
|
|
- Long userId = payReq.getUserId();
|
|
|
- //codex 车票id
|
|
|
- Long relationId = payReq.getRelationId();
|
|
|
- CodexDeductResp codexDeductResp = getDeductMoney(userId, relationId, payReq.getSkuId());
|
|
|
- if (!codexDeductResp.getIsDeduct()) {
|
|
|
- throw BusinessRuntimeException.getInstance("你存在claude code 无法抵扣");
|
|
|
- }
|
|
|
- //抵扣金额
|
|
|
- BigDecimal deductMoney = codexDeductResp.getDeductMoney();
|
|
|
- Integer extendsDays = codexDeductResp.getExtendsDays();
|
|
|
- Long skuId = payReq.getSkuId();
|
|
|
-
|
|
|
- GoodsDonSku upgradeSku = skuMapper.selectById(skuId);
|
|
|
- if (upgradeSku == null || upgradeSku.getGoodsId() != Constant.CODEX_GOODS_ID) {
|
|
|
- throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
- }
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- int noPayCount = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .in(OrderDon::getUserId, userIdList)
|
|
|
- .eq(OrderDon::getGoodsId, upgradeSku.getGoodsId())
|
|
|
- .eq(OrderDon::getStatus, OrderDon.Status.noPayment.toString()));
|
|
|
- if (noPayCount > 0) {
|
|
|
- throw new BusinessRuntimeException("您有未支付订单.");
|
|
|
- }
|
|
|
- String cacheKye = "codex_deduct_cache_key:" + relationId;
|
|
|
- boolean b = redisService.setNx(cacheKye, relationId, 10L);
|
|
|
- if (!b) {
|
|
|
- throw BusinessRuntimeException.getInstance("系统繁忙,请刷新页面重试");
|
|
|
- }
|
|
|
- CouponUser couponUser = null;
|
|
|
- if (payReq.getCouponId() != null) {
|
|
|
- CouponPopularizeDto couponPopularizeDto = checkCouponStatus(skuId, null, payReq.getCouponId(), userId, false);
|
|
|
- //记录优惠券使用状态
|
|
|
- couponUser = couponStatusRecord(null, payReq.getCouponId(), userId, couponPopularizeDto);
|
|
|
- }
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(upgradeSku.getGoodsId());
|
|
|
-
|
|
|
- OrderDon orderDon;
|
|
|
- try {
|
|
|
- orderDon = new OrderDon();
|
|
|
- orderDon.setGoodsId(upgradeSku.getGoodsId());
|
|
|
- orderDon.setSkuId(upgradeSku.getId());
|
|
|
- orderDon.setUserId(userId);
|
|
|
- //抵扣升级订单
|
|
|
- orderDon.setOrderType(1);
|
|
|
- BigDecimal price = upgradeSku.getPrice();
|
|
|
- orderDon.setOriMoney(price);
|
|
|
- orderDon.setRealMoney(price);
|
|
|
- //抵扣后的金额
|
|
|
- BigDecimal discountPrice = price.subtract(deductMoney);
|
|
|
- //0元订单
|
|
|
- orderDon.setMoney(discountPrice.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : discountPrice);
|
|
|
-
|
|
|
- StringBuilder payTitle = new StringBuilder();
|
|
|
- payTitle.append(goodsDon.getTitle()).append(upgradeSku.getSpecVal());
|
|
|
- orderDon.setPayTitle(payTitle.toString());
|
|
|
-
|
|
|
- orderDon.setType(OrderDon.Type.ALI_PAY);
|
|
|
-
|
|
|
- /* 生成订单 */
|
|
|
- String donNo = SEQUENCE.nextId().toString();
|
|
|
- orderDon.setOrderNo(donNo);
|
|
|
- orderDon.setStatus(OrderDon.Status.noPayment);
|
|
|
-
|
|
|
- //虚拟商品订单,是否是分销订单
|
|
|
- orderDonService.setDistributeOrderMark(orderDon, goodsDon.getType(), userId);
|
|
|
- //存在银河币
|
|
|
- orderDonService.deductGalaxyCoinPayOrderMoney(orderDon, discountPrice, payReq.getGalaxyCoin(), user);
|
|
|
- //存在余额
|
|
|
- orderDonService.deductBalancePayOrderMoney(orderDon, payReq.getBalance(), user);
|
|
|
-
|
|
|
- GroupsRelation relation = getClaudeCodeRelation(userId, upgradeSku);
|
|
|
- orderDon.setRelationId(relation.getId());
|
|
|
- orderDonMapper.insert(orderDon);
|
|
|
-
|
|
|
- //记录抵扣记录
|
|
|
- CodexDeductRecord codexDeductRecord = new CodexDeductRecord();
|
|
|
- codexDeductRecord.setCcRelationId(null);
|
|
|
- codexDeductRecord.setOrderId(orderDon.getId());
|
|
|
- codexDeductRecord.setRelationId(relationId);
|
|
|
- codexDeductRecord.setExtendsDays(extendsDays);
|
|
|
- codexDeductRecordMapper.insert(codexDeductRecord);
|
|
|
-
|
|
|
- Long orderId = orderDon.getId();
|
|
|
- //使用银河币记录
|
|
|
- userGalaxyCoinService.handleUserGalaxyCoinOrderNotify(orderId, userId, orderDon.getOrderNo(), OrderDonGalaxyCoinRecord.Source.ordinary);
|
|
|
- if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- orderDon = orderDonMapper.selectById(orderId);
|
|
|
- orderDonService.unifiedHandlerOrderNotify(orderDon, goodsDon, upgradeSku);
|
|
|
- }
|
|
|
- if (orderDon.getStatus() == OrderDon.Status.noPayment) {
|
|
|
- jobManager.addJob(EXPIRY_TIME, () -> {
|
|
|
- orderDonService.closeOrder(orderId, null);
|
|
|
- });
|
|
|
- }
|
|
|
- } finally {
|
|
|
- if (redisService.hasKey(cacheKye)) {
|
|
|
- redisService.del(cacheKye);
|
|
|
- }
|
|
|
- }
|
|
|
- return orderDon;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Boolean getUserSubs(Long userId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
@@ -458,7 +338,8 @@ public class CodexServiceImpl implements CodexService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private GroupsRelation getClaudeCodeRelation(Long userId, GoodsDonSku sku) {
|
|
|
+ @Override
|
|
|
+ public GroupsRelation getClaudeCodeRelation(Long userId, GoodsDonSku sku) {
|
|
|
//获取车票车位
|
|
|
GroupsRelation relation = getRelation(sku);
|
|
|
//锁定座位
|