|
@@ -38,9 +38,12 @@ import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.api.ClaudeCodexApiService;
|
|
import com.cyksj.service.api.ClaudeCodexApiService;
|
|
|
import com.cyksj.service.codex.CodexService;
|
|
import com.cyksj.service.codex.CodexService;
|
|
|
|
|
+import com.cyksj.service.coin.UserGalaxyCoinService;
|
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
|
import com.cyksj.service.groups.GroupsFuncService;
|
|
import com.cyksj.service.groups.GroupsFuncService;
|
|
|
|
|
+import com.cyksj.service.order.OrderDonService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
|
|
+import com.cyksj.task.JobManager;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
@@ -119,6 +122,14 @@ public class CodexServiceImpl implements CodexService {
|
|
|
|
|
|
|
|
private final ClaudeCodexApiService claudeCodexApiService;
|
|
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
|
|
@Override
|
|
|
public void createOrUpdateUserPackage(CodexUserPackageReq req) {
|
|
public void createOrUpdateUserPackage(CodexUserPackageReq req) {
|
|
|
Long userId = req.getUserId();
|
|
Long userId = req.getUserId();
|
|
@@ -214,12 +225,15 @@ public class CodexServiceImpl implements CodexService {
|
|
|
Integer extendsDays = codexDeductResp.getExtendsDays();
|
|
Integer extendsDays = codexDeductResp.getExtendsDays();
|
|
|
Long skuId = payReq.getSkuId();
|
|
Long skuId = payReq.getSkuId();
|
|
|
|
|
|
|
|
- GoodsDonSku sku = skuMapper.selectById(skuId);
|
|
|
|
|
- if (sku == null || sku.getGoodsId() != Constant.CODEX_GOODS_ID) {
|
|
|
|
|
|
|
+ GoodsDonSku upgradeSku = skuMapper.selectById(skuId);
|
|
|
|
|
+ if (upgradeSku == null || upgradeSku.getGoodsId() != Constant.CODEX_GOODS_ID) {
|
|
|
throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
}
|
|
}
|
|
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- int noPayCount = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class).in(OrderDon::getUserId, userIdList).eq(OrderDon::getGoodsId, sku.getGoodsId())
|
|
|
|
|
|
|
+ int noPayCount = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
|
|
+ .in(OrderDon::getUserId, userIdList)
|
|
|
|
|
+ .eq(OrderDon::getGoodsId, upgradeSku.getGoodsId())
|
|
|
.eq(OrderDon::getStatus, OrderDon.Status.noPayment.toString()));
|
|
.eq(OrderDon::getStatus, OrderDon.Status.noPayment.toString()));
|
|
|
if (noPayCount > 0) {
|
|
if (noPayCount > 0) {
|
|
|
throw new BusinessRuntimeException("您有未支付订单.");
|
|
throw new BusinessRuntimeException("您有未支付订单.");
|
|
@@ -235,16 +249,28 @@ public class CodexServiceImpl implements CodexService {
|
|
|
//记录优惠券使用状态
|
|
//记录优惠券使用状态
|
|
|
couponUser = couponStatusRecord(null, payReq.getCouponId(), userId, couponPopularizeDto);
|
|
couponUser = couponStatusRecord(null, payReq.getCouponId(), userId, couponPopularizeDto);
|
|
|
}
|
|
}
|
|
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(upgradeSku.getGoodsId());
|
|
|
|
|
|
|
|
OrderDon orderDon;
|
|
OrderDon orderDon;
|
|
|
try {
|
|
try {
|
|
|
orderDon = new OrderDon();
|
|
orderDon = new OrderDon();
|
|
|
- orderDon.setGoodsId(sku.getGoodsId());
|
|
|
|
|
- orderDon.setSkuId(sku.getId());
|
|
|
|
|
|
|
+ orderDon.setGoodsId(upgradeSku.getGoodsId());
|
|
|
|
|
+ orderDon.setSkuId(upgradeSku.getId());
|
|
|
orderDon.setUserId(userId);
|
|
orderDon.setUserId(userId);
|
|
|
- //优惠 --> 订单金额
|
|
|
|
|
- deductOrderMoney(orderDon, couponUser);
|
|
|
|
|
- orderDon.setMoney(sku.getPrice().subtract(deductMoney));
|
|
|
|
|
|
|
+ //抵扣升级订单
|
|
|
|
|
+ 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);
|
|
orderDon.setType(OrderDon.Type.ALI_PAY);
|
|
|
|
|
|
|
|
/* 生成订单 */
|
|
/* 生成订单 */
|
|
@@ -252,39 +278,37 @@ public class CodexServiceImpl implements CodexService {
|
|
|
orderDon.setOrderNo(donNo);
|
|
orderDon.setOrderNo(donNo);
|
|
|
orderDon.setStatus(OrderDon.Status.noPayment);
|
|
orderDon.setStatus(OrderDon.Status.noPayment);
|
|
|
|
|
|
|
|
- //锁一个cc的车票id
|
|
|
|
|
- //是否存在无赠送的claude code 直接原规格上抵扣
|
|
|
|
|
-// List<Long> sendCodexSkuIds = skuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID).eq(GoodsDonSku::getIsCodex, Boolean.TRUE)).stream().map(GoodsDonSku::getId).collect(Collectors.toList());
|
|
|
|
|
- //cc车票id
|
|
|
|
|
- Long ccRelationId = null;
|
|
|
|
|
-// if (CollUtil.isEmpty(sendCodexSkuIds)) {
|
|
|
|
|
-// //是否存在cc
|
|
|
|
|
-// Integer selectCount = claudeCodeUserMapper.selectCount(Wrappers.lambdaQuery(ClaudeCodeUser.class).in(ClaudeCodeUser::getUserId, userIdList));
|
|
|
|
|
-// if (selectCount > 0) {
|
|
|
|
|
-// throw BusinessRuntimeException.getInstance("你存在claude code 无法抵扣");
|
|
|
|
|
-// }
|
|
|
|
|
-// } else {
|
|
|
|
|
-// GroupsRelationMirrorView groupsRelationMirrorView = beanSearcher.searchFirst(GroupsRelationMirrorView.class, MapUtils.builder()
|
|
|
|
|
-// .field(GroupsRelationMirrorView::getUserId, userIdList).op(Operator.InList)
|
|
|
|
|
-// .field(GroupsRelationMirrorView::getSkuId, sendCodexSkuIds).op(Operator.NotIn)
|
|
|
|
|
-// .field(GroupsRelationMirrorView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
|
|
|
|
|
-// .build());
|
|
|
|
|
-// if (groupsRelationMirrorView != null) {
|
|
|
|
|
-// ccRelationId = groupsRelationMirrorView.getId();
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
- GroupsRelation relation = getClaudeCodeRelation(userId, sku);
|
|
|
|
|
|
|
+ //虚拟商品订单,是否是分销订单
|
|
|
|
|
+ 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());
|
|
orderDon.setRelationId(relation.getId());
|
|
|
orderDonMapper.insert(orderDon);
|
|
orderDonMapper.insert(orderDon);
|
|
|
|
|
|
|
|
//记录抵扣记录
|
|
//记录抵扣记录
|
|
|
CodexDeductRecord codexDeductRecord = new CodexDeductRecord();
|
|
CodexDeductRecord codexDeductRecord = new CodexDeductRecord();
|
|
|
- codexDeductRecord.setCcRelationId(ccRelationId);
|
|
|
|
|
|
|
+ codexDeductRecord.setCcRelationId(null);
|
|
|
codexDeductRecord.setOrderId(orderDon.getId());
|
|
codexDeductRecord.setOrderId(orderDon.getId());
|
|
|
codexDeductRecord.setRelationId(relationId);
|
|
codexDeductRecord.setRelationId(relationId);
|
|
|
codexDeductRecord.setExtendsDays(extendsDays);
|
|
codexDeductRecord.setExtendsDays(extendsDays);
|
|
|
codexDeductRecordMapper.insert(codexDeductRecord);
|
|
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 {
|
|
} finally {
|
|
|
if (redisService.hasKey(cacheKye)) {
|
|
if (redisService.hasKey(cacheKye)) {
|
|
|
redisService.del(cacheKye);
|
|
redisService.del(cacheKye);
|