|
|
@@ -102,7 +102,6 @@ import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
|
@@ -226,6 +225,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final GiftCardOrderUseRecordService giftCardOrderUseRecordService;
|
|
|
|
|
|
+ private final GiftCardOrderRelateMapper giftCardOrderRelateMapper;
|
|
|
+
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@@ -392,6 +393,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
for (GiftCardGoodsSkuFrontView data : giftCardViews) {
|
|
|
//礼品卡数量
|
|
|
Integer num = giftCardPayNumMap.get(data.getId());
|
|
|
+ data.setGcNum(num);
|
|
|
+ data.setGcShowType(gcPayInfo.getGcShowType());
|
|
|
+ data.setGcImg(gcPayInfo.getGcImg());
|
|
|
gift_card_pay_money = gift_card_pay_money.add(data.getPrice().multiply(BigDecimal.valueOf(num)));
|
|
|
|
|
|
//礼品卡关系
|
|
|
@@ -407,6 +411,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
payTitle.append(gcDetail);
|
|
|
}
|
|
|
}
|
|
|
+ gcPayInfo.setGcPayDetail(giftCardViews);
|
|
|
|
|
|
//调整礼品卡金额
|
|
|
if (gift_card_pay_money.compareTo(orderDon.getMoney()) > 0) {
|
|
|
@@ -468,8 +473,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setSpecialType(goodsDon.getSpecialType());
|
|
|
//礼品卡购买记录
|
|
|
if (CollUtil.isNotEmpty(giftCards)) {
|
|
|
- redisService.set(RedisService.key.GIFT_CARD_USER_PAY_SUCCESS_RECORD_KEY.getName() + orderDon.getId(), gcPayInfo, RedisService.key.GIFT_CARD_USER_PAY_SUCCESS_RECORD_KEY.getTimeout());
|
|
|
+ log.info("用户userId:{}购买礼品卡下单orderId:{}", userId, orderDon.getId());
|
|
|
+ GiftCardOrderRelate giftCardOrderRelate = new GiftCardOrderRelate();
|
|
|
+ giftCardOrderRelate.setOrderId(orderDon.getId());
|
|
|
+ giftCardOrderRelate.setGcPayDetail(Jsons.toJson(gcPayInfo.getGcPayDetail()));
|
|
|
+ giftCardOrderRelateMapper.insert(giftCardOrderRelate);
|
|
|
}
|
|
|
+
|
|
|
//礼品卡现金使用记录
|
|
|
if (CollUtil.isNotEmpty(orderDon.getGcUseRecords())) {
|
|
|
orderDon.getGcUseRecords().forEach(data -> {
|
|
|
@@ -2061,28 +2071,19 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
//礼品卡
|
|
|
if (goodsDon.getSpecialType() != null && goodsDon.getSpecialType() == GoodsDon.SpecialType.giftCard) {
|
|
|
- List<GiftCardUserRecord> GiftCardUserRecords = giftCardUserRecordService.list(Wrappers.lambdaQuery(GiftCardUserRecord.class)
|
|
|
- .eq(GiftCardUserRecord::getOrderId, orderDon.getId())
|
|
|
- .eq(GiftCardUserRecord::getIsPay, false));
|
|
|
- if (CollUtil.isNotEmpty(GiftCardUserRecords)) {
|
|
|
- GiftCardUserRecords.forEach(data->{
|
|
|
- giftCardUserRecordService.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
|
|
|
- .set(GiftCardUserRecord::getIsPay, true)
|
|
|
- .set(GiftCardUserRecord::getRc, RandomUtil.randomString(6))
|
|
|
- .set(GiftCardUserRecord::getPayTime, Optional.ofNullable(orderDon.getPayTime()).orElse(orderDon.getCreatedTime()))
|
|
|
- .eq(GiftCardUserRecord::getId, data.getId())
|
|
|
- .eq(GiftCardUserRecord::getIsPay, false));
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //礼品卡购买记录
|
|
|
- Object giftCardPay = redisService.get(RedisService.key.GIFT_CARD_USER_PAY_SUCCESS_RECORD_KEY.getName() + orderDon.getId());
|
|
|
- if (giftCardPay != null) {
|
|
|
- GiftCardDto giftCardDto = Jsons.parseObject(giftCardPay.toString(), GiftCardDto.class);
|
|
|
- if (giftCardDto != null) {
|
|
|
- log.info("记录用户userId:{}订单orderId:{}购买成功礼品卡", orderDon.getUserId(), orderDon.getId());
|
|
|
- giftCardUserPayRecord(giftCardDto, orderDon);
|
|
|
+ //礼品卡购买记录
|
|
|
+ GiftCardOrderRelate giftCardOrderRelate = giftCardOrderRelateMapper.selectOne(Wrappers.lambdaQuery(GiftCardOrderRelate.class)
|
|
|
+ .eq(GiftCardOrderRelate::getOrderId, orderDon.getId())
|
|
|
+ .eq(GiftCardOrderRelate::getIsPay, false).last("limit 1"));
|
|
|
+ if (giftCardOrderRelate != null) {
|
|
|
+ int update = giftCardOrderRelateMapper.update(null, Wrappers.lambdaUpdate(GiftCardOrderRelate.class)
|
|
|
+ .set(GiftCardOrderRelate::getIsPay, true)
|
|
|
+ .eq(GiftCardOrderRelate::getId, giftCardOrderRelate.getId())
|
|
|
+ .eq(GiftCardOrderRelate::getIsPay, false));
|
|
|
+ if (update > 0) {
|
|
|
+ log.info("礼品卡订单:{}开始回调", orderDon.getId());
|
|
|
+ giftCardUserPayRecord(giftCardOrderRelate.getGcPayDetail(), orderDon);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -2141,48 +2142,42 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
/**
|
|
|
* 用户购买成功礼品卡记录
|
|
|
*/
|
|
|
- private void giftCardUserPayRecord(GiftCardDto giftCardDto, OrderDon orderDon) {
|
|
|
- //礼品卡规格
|
|
|
- Map<Long, Integer> giftCardPayNumMap = new ConcurrentHashMap<>();
|
|
|
- AtomicInteger init_size = new AtomicInteger(0);
|
|
|
- List<GiftCardPayReq> giftCards = giftCardDto.getGiftCards();
|
|
|
- String gcImg = giftCardDto.getGcImg();
|
|
|
- String gcShowType = giftCardDto.getGcShowType();
|
|
|
- giftCards.stream().forEach(data -> {
|
|
|
- giftCardPayNumMap.putIfAbsent(data.getGcId(), data.getNum());
|
|
|
- init_size.addAndGet(data.getNum());
|
|
|
- });
|
|
|
- List<GiftCardGoodsSkuFrontView> giftCardViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getId, giftCardPayNumMap.keySet()).build());
|
|
|
- if (giftCardViews.size() != giftCards.size()) {
|
|
|
- log.info("用户userId:{}购买orderId:{}成功后,礼品卡兑换数量错误", orderDon.getUserId(), orderDon.getId());
|
|
|
- }
|
|
|
- List<GiftCardUserRecord> gcUserPayRecords = new ArrayList<>(init_size.get());
|
|
|
- for (GiftCardGoodsSkuFrontView data : giftCardViews) {
|
|
|
- //礼品卡数量
|
|
|
- for (Integer i = 0; i < giftCardPayNumMap.get(data.getId()); i++) {
|
|
|
- //礼品卡关系
|
|
|
- GiftCardUserRecord giftCardUserRecord = new GiftCardUserRecord();
|
|
|
- String gcDetail;
|
|
|
- if (data.getGcType() == 1) {
|
|
|
- gcDetail = String.format("现金卡%s", data.getCash().divide(BigDecimal.valueOf(100)));
|
|
|
- giftCardUserRecord.setCash(data.getCash());
|
|
|
- giftCardUserRecord.setRemainCash(data.getCash());
|
|
|
- } else {
|
|
|
- gcDetail = String.format("虚拟卡%s%s", data.getGcGoodsTitle(), data.getGcSpecVal());
|
|
|
- giftCardUserRecord.setGcGoodsId(data.getGcGoodsId());
|
|
|
- giftCardUserRecord.setGcSkuId(data.getGcSkuId());
|
|
|
+ private void giftCardUserPayRecord(String gcPayDetail, OrderDon orderDon) {
|
|
|
+ try {
|
|
|
+ //礼品卡规格
|
|
|
+ List<GiftCardGoodsSkuFrontView> gcList = Jsons.parseList(gcPayDetail, GiftCardGoodsSkuFrontView.class);
|
|
|
+ List<GiftCardUserRecord> gcUserPayRecords = new ArrayList<>();
|
|
|
+ for (GiftCardGoodsSkuFrontView data : gcList) {
|
|
|
+ for (Integer i = 0; i < data.getGcNum(); i++) {
|
|
|
+ //礼品卡关系
|
|
|
+ GiftCardUserRecord giftCardUserRecord = new GiftCardUserRecord();
|
|
|
+ String gcDetail;
|
|
|
+ if (data.getGcType() == 1) {
|
|
|
+ gcDetail = String.format("现金卡%s", data.getCash().divide(BigDecimal.valueOf(100)));
|
|
|
+ giftCardUserRecord.setCash(data.getCash());
|
|
|
+ giftCardUserRecord.setRemainCash(data.getCash());
|
|
|
+ } else {
|
|
|
+ gcDetail = String.format("虚拟卡%s%s", data.getGcGoodsTitle(), data.getGcSpecVal());
|
|
|
+ giftCardUserRecord.setGcGoodsId(data.getGcGoodsId());
|
|
|
+ giftCardUserRecord.setGcSkuId(data.getGcSkuId());
|
|
|
+ }
|
|
|
+ giftCardUserRecord.setOrderId(orderDon.getId());
|
|
|
+ giftCardUserRecord.setUserId(orderDon.getUserId());
|
|
|
+ giftCardUserRecord.setGcType(data.getGcType());
|
|
|
+ giftCardUserRecord.setGcDetail(gcDetail);
|
|
|
+ giftCardUserRecord.setType(data.getGcShowType());
|
|
|
+ giftCardUserRecord.setImg(data.getGcImg());
|
|
|
+ giftCardUserRecord.setIsPay(true);
|
|
|
+ giftCardUserRecord.setRc(RandomUtil.randomString(6));
|
|
|
+ giftCardUserRecord.setPayTime(Optional.ofNullable(orderDon.getPayTime()).orElse(orderDon.getCreatedTime()));
|
|
|
+ gcUserPayRecords.add(giftCardUserRecord);
|
|
|
}
|
|
|
- giftCardUserRecord.setOrderId(orderDon.getId());
|
|
|
- giftCardUserRecord.setUserId(orderDon.getUserId());
|
|
|
- giftCardUserRecord.setGcType(data.getGcType());
|
|
|
- giftCardUserRecord.setGcDetail(gcDetail);
|
|
|
- giftCardUserRecord.setType(gcShowType);
|
|
|
- giftCardUserRecord.setImg(gcImg);
|
|
|
- gcUserPayRecords.add(giftCardUserRecord);
|
|
|
}
|
|
|
- }
|
|
|
- if (CollUtil.isNotEmpty(gcUserPayRecords)) {
|
|
|
- giftCardUserRecordService.saveBatch(gcUserPayRecords);
|
|
|
+ if (CollUtil.isNotEmpty(gcUserPayRecords)) {
|
|
|
+ giftCardUserRecordService.saveBatch(gcUserPayRecords);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("用户userId:{}礼品订单orderId:{}支付成功,记录购买成功记录错误,e:", orderDon.getUserId(), orderDon.getId(), StringUtil.getErrorText(e));
|
|
|
}
|
|
|
}
|
|
|
}
|