|
|
@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
@@ -12,7 +14,10 @@ import com.alipay.api.AlipayRequest;
|
|
|
import com.alipay.api.AlipayResponse;
|
|
|
import com.alipay.api.domain.*;
|
|
|
import com.alipay.api.internal.util.AlipaySignature;
|
|
|
-import com.alipay.api.request.*;
|
|
|
+import com.alipay.api.request.AlipayFundTransCommonQueryRequest;
|
|
|
+import com.alipay.api.request.AlipayFundTransUniTransferRequest;
|
|
|
+import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest;
|
|
|
+import com.alipay.api.request.AlipayTradeQueryRequest;
|
|
|
import com.alipay.api.response.AlipayFundTransCommonQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
|
@@ -50,17 +55,21 @@ import com.cyksj.model.entity.Address;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.manage.views.OrderDonView;
|
|
|
+import com.cyksj.model.request.GiftCardPayReq;
|
|
|
import com.cyksj.model.request.OrderAttach;
|
|
|
import com.cyksj.model.request.OrderPayRequest;
|
|
|
import com.cyksj.model.request.TransferAccountsReq;
|
|
|
import com.cyksj.model.views.CouponNewUserView;
|
|
|
import com.cyksj.model.views.CouponUserView;
|
|
|
+import com.cyksj.model.views.GiftCardGoodsSkuFrontView;
|
|
|
import com.cyksj.model.views.GoodsDonSkuView;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
|
import com.cyksj.service.distribute.UserBusinessFrontService;
|
|
|
import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
|
|
|
import com.cyksj.service.exchange.ExchangeCodeService;
|
|
|
+import com.cyksj.service.giftcard.GiftCardOrderUseRecordService;
|
|
|
+import com.cyksj.service.giftcard.GiftCardUserRecordService;
|
|
|
import com.cyksj.service.groups.GroupsFuncService;
|
|
|
import com.cyksj.service.market.MarketFrontService;
|
|
|
import com.cyksj.service.market.task.TaskService;
|
|
|
@@ -90,6 +99,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
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;
|
|
|
@@ -209,38 +221,69 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final ChannelPopularizeMapper channelPopularizeMapper;
|
|
|
|
|
|
+ private final GiftCardUserRecordService giftCardUserRecordService;
|
|
|
+
|
|
|
+ private final GiftCardOrderUseRecordService giftCardOrderUseRecordService;
|
|
|
+
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@Override
|
|
|
public OrderDon submit(OrderPayRequest payRequest) throws Exception {
|
|
|
+ GoodsDonSku sku = null;
|
|
|
+ Long goodsId;
|
|
|
+ List<GiftCardPayReq> giftCards = payRequest.getGiftCards();
|
|
|
+ AtomicBoolean isGiftCardPay = new AtomicBoolean(false);
|
|
|
+ if (CollUtil.isNotEmpty(giftCards)) {
|
|
|
+ goodsId = payRequest.getGoodsId();
|
|
|
+ isGiftCardPay.set(true);
|
|
|
+ } else {
|
|
|
+ if (payRequest.getSkuId() == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请指定对应平台规格下单");
|
|
|
+ }
|
|
|
+ sku = goodsDonSkuMapper.selectById(payRequest.getSkuId());
|
|
|
+ Assert.notNull(sku, "规格不存在");
|
|
|
+ goodsId = sku.getGoodsId();
|
|
|
+ }
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
|
|
|
+ if (goodsDon == null || !goodsDon.getStatus()) {
|
|
|
+ throw new BusinessRuntimeException("商品已下架");
|
|
|
+ }
|
|
|
+ if (isGiftCardPay.get() && (goodsDon.getSpecialType() == null || goodsDon.getSpecialType() != GoodsDon.SpecialType.giftCard)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("非礼品卡类型商品");
|
|
|
+ }
|
|
|
CouponUser couponUser = null;
|
|
|
if (StrUtil.isNotBlank(payRequest.getCouponExCode()) || payRequest.getCouponId() != null) {
|
|
|
CouponPopularizeDto couponPopularizeDto = checkCouponStatus(payRequest.getSkuId(), payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), false);
|
|
|
//记录优惠券使用状态
|
|
|
couponUser = couponStatusRecord(payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), couponPopularizeDto);
|
|
|
}
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(payRequest.getSkuId());
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
- if (goodsDon == null || !goodsDon.getStatus()) {
|
|
|
- throw new BusinessRuntimeException("商品已下架");
|
|
|
- }
|
|
|
Boolean isNoLogin = payRequest.getIsNoLogin();
|
|
|
User user;
|
|
|
String payOpenId = null;
|
|
|
Long relationId = 0L;
|
|
|
|
|
|
- if (isNoLogin != null && isNoLogin) {
|
|
|
+ Boolean isNeedTicket = checkIsNeedGroupsRelation(goodsDon);
|
|
|
+ Long userId = payRequest.getUserId();
|
|
|
+ if (userId != null) {
|
|
|
+ int noPayCount = count(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, userId).eq(OrderDon::getGoodsId, goodsId).eq(OrderDon::getStatus, OrderDon.Status.noPayment.toString()));
|
|
|
+ if (noPayCount > 0) {
|
|
|
+ throw new BusinessRuntimeException("您有未支付订单.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
user = new User();
|
|
|
user.setId(0l);
|
|
|
} else {
|
|
|
- user = userMapper.selectById(payRequest.getUserId());
|
|
|
+ user = userMapper.selectById(userId);
|
|
|
if (user == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
|
|
|
if (user.getIsBlack()) throw BusinessRuntimeException.getInstance("系统检测操作异常,请稍后再试");
|
|
|
- //ChatGPT Plus账号限购校验
|
|
|
- checkChatGPTPlusPurchaseLimit(user.getId(), goodsDon.getId(), goodsDon.getTitle(), sku.getId(), sku.getSpecVal());
|
|
|
payOpenId = user.getOpenId();
|
|
|
- if (goodsDon.getType() == 1) {
|
|
|
+ if (sku != null) {
|
|
|
+ //ChatGPT Plus账号限购校验
|
|
|
+ checkChatGPTPlusPurchaseLimit(user.getId(), goodsDon.getId(), goodsDon.getTitle(), sku.getId(), sku.getSpecVal());
|
|
|
+ }
|
|
|
+ if (goodsDon.getType() == 1 && isNeedTicket) {
|
|
|
//获取座位
|
|
|
relationId = getRelation(payRequest, sku);
|
|
|
} else {
|
|
|
@@ -257,12 +300,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
orderDon.setOrderNo(donNo);
|
|
|
orderDon.setOpenId(payOpenId);
|
|
|
- if (sku.getPrice() == null || sku.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- throw BusinessRuntimeException.getInstance("下单商品价格异常");
|
|
|
- }
|
|
|
- if (payRequest.getDonMoney().compareTo(sku.getPrice()) < 0) {
|
|
|
- log.info("规格:{}支付金额:{}异常,调整用户userId:{}支付金额为:{}", sku.getSpecVal(), payRequest.getDonMoney(), user.getId(), sku.getPrice());
|
|
|
- payRequest.setDonMoney(sku.getPrice());
|
|
|
+ if (sku != null) {
|
|
|
+ if (sku.getPrice() == null || sku.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("下单商品价格异常");
|
|
|
+ }
|
|
|
+ if (payRequest.getDonMoney().compareTo(sku.getPrice()) < 0) {
|
|
|
+ log.info("规格:{}支付金额:{}异常,调整用户userId:{}支付金额为:{}", sku.getSpecVal(), payRequest.getDonMoney(), user.getId(), sku.getPrice());
|
|
|
+ payRequest.setDonMoney(sku.getPrice());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
orderDon.setMoney(payRequest.getDonMoney());
|
|
|
@@ -298,8 +343,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (payRequest.getPopularizeId() != null) {
|
|
|
orderDon.setPopularizeId(payRequest.getPopularizeId());
|
|
|
}
|
|
|
- //扣除使用优惠券、余额的订单金额
|
|
|
- deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType());
|
|
|
+ if (sku != null) {
|
|
|
+ //扣除使用优惠券、余额的订单金额
|
|
|
+ deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds());
|
|
|
+ }
|
|
|
|
|
|
orderDon.setSkuId(payRequest.getSkuId());
|
|
|
orderDon.setRelationId(relationId);
|
|
|
@@ -311,24 +358,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setIsWebPay(payRequest.getIsWebPay());
|
|
|
orderDon.setSource(payRequest.getSource());
|
|
|
orderDon.setCouponExCode(payRequest.getCouponExCode());
|
|
|
- if (isNoLogin == null || !isNoLogin) {
|
|
|
- //虚拟商品订单,是否是分销订单
|
|
|
- if (goodsDon.getType() == 1 || goodsDon.getType() == 2) {
|
|
|
- //若该订单使用了规定推广者的兑换码 增加上下级关系
|
|
|
- if (StrUtil.isNotBlank(orderDon.getCouponExCode()) && orderDon.getUserId() != 0) {
|
|
|
- addDistributeCouponCode(orderDon.getUserId(), orderDon.getCouponExCode());
|
|
|
- }
|
|
|
- UserDistributeShared userDistributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class).eq(UserDistributeShared::getUserId, user.getId()).last("limit 1"));
|
|
|
- if (userDistributeShared != null) {
|
|
|
- orderDon.setIsDistribute(true);
|
|
|
- UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, userDistributeShared.getSharedId()));
|
|
|
- if (userDistribute != null) {
|
|
|
- orderDon.setIsFixedDistribute(true);
|
|
|
- orderDon.setCpsPopularizeId(userDistributeShared.getDsPopularizeId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //设置分销订单
|
|
|
+ setDistributeOrderMark(orderDon, goodsDon.getType(), user.getId());
|
|
|
if (relationId != 0) {
|
|
|
Long gtSkuId = groupsRelationMapper.getGroupTripsSkuIdByRelationId(relationId);
|
|
|
if (!gtSkuId.equals(orderDon.getSkuId())) {
|
|
|
@@ -338,7 +369,46 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setPayDesc(goodsDon.getPayDesc());
|
|
|
StringBuilder payTitle = new StringBuilder();
|
|
|
payTitle.append(goodsDon.getTitle());
|
|
|
- payTitle.append(sku.getSpecVal());
|
|
|
+ if (sku != null) {
|
|
|
+ payTitle.append(sku.getSpecVal());
|
|
|
+ }
|
|
|
+ if (isGiftCardPay.get()) {
|
|
|
+ //礼品卡规格
|
|
|
+ Map<Long, Integer> giftCardPayNumMap = new ConcurrentHashMap<>();
|
|
|
+ giftCards.stream().forEach(data->{
|
|
|
+ giftCardPayNumMap.putIfAbsent(data.getGcId(), data.getNum());
|
|
|
+ });
|
|
|
+ List<GiftCardGoodsSkuFrontView> giftCardViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getId, giftCardPayNumMap.keySet()).build());
|
|
|
+ if (giftCardViews.size() != giftCards.size()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
+ }
|
|
|
+ payTitle.append("礼品卡:");
|
|
|
+ BigDecimal gift_card_pay_money = BigDecimal.ZERO;
|
|
|
+ for (GiftCardGoodsSkuFrontView data : giftCardViews) {
|
|
|
+ //礼品卡数量
|
|
|
+ Integer num = giftCardPayNumMap.get(data.getId());
|
|
|
+ gift_card_pay_money = gift_card_pay_money.add(data.getPrice().multiply(BigDecimal.valueOf(num)));
|
|
|
+
|
|
|
+ //礼品卡关系
|
|
|
+ if (!payTitle.toString().endsWith("礼品卡:")) {
|
|
|
+ payTitle.append(" + ");
|
|
|
+ }
|
|
|
+ String gcDetail;
|
|
|
+ if (data.getGcType() == 1) {
|
|
|
+ gcDetail = String.format("%s张现金卡%s", num, data.getCash().divide(BigDecimal.valueOf(100)));
|
|
|
+ payTitle.append(gcDetail);
|
|
|
+ } else {
|
|
|
+ gcDetail = String.format("%s张虚拟卡%s%s", num, data.getGcGoodsTitle(), data.getGcSpecVal());
|
|
|
+ payTitle.append(gcDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //调整礼品卡金额
|
|
|
+ if (gift_card_pay_money.compareTo(orderDon.getMoney()) > 0) {
|
|
|
+ orderDon.setMoney(gift_card_pay_money);
|
|
|
+ orderDon.setRealMoney(gift_card_pay_money);
|
|
|
+ }
|
|
|
+ }
|
|
|
if (orderDon.getIsDp()) {
|
|
|
List<GoodsDonSkuView> dp_skuViewList = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, dpSkuIds).op(Operator.InList).build());
|
|
|
if (dp_skuViewList.size() != dpSkuIds.size()) {
|
|
|
@@ -391,9 +461,31 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
}
|
|
|
orderDon.setSpecialType(goodsDon.getSpecialType());
|
|
|
+ //礼品卡购买记录
|
|
|
+ if (CollUtil.isNotEmpty(payRequest.getGiftCards())) {
|
|
|
+ redisService.set(RedisService.key.GIFT_CARD_USER_PAY_SUCCESS_RECORD_KEY.getName() + orderDon.getId(), payRequest.getGiftCards(), RedisService.key.GIFT_CARD_USER_PAY_SUCCESS_RECORD_KEY.getTimeout());
|
|
|
+ }
|
|
|
+ //礼品卡现金使用记录
|
|
|
+ if (CollUtil.isNotEmpty(orderDon.getGcUseRecords())) {
|
|
|
+ orderDon.getGcUseRecords().forEach(data -> {
|
|
|
+ data.setOrderId(orderDon.getId());
|
|
|
+ });
|
|
|
+ giftCardOrderUseRecordService.saveBatch(orderDon.getGcUseRecords());
|
|
|
+ }
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
+ private Boolean checkIsNeedGroupsRelation(GoodsDon goodsDon) {
|
|
|
+ if (goodsDon.getType() == 1) {
|
|
|
+ //礼品卡特殊类型不需要车票
|
|
|
+ if (goodsDon.getSpecialType() != null && goodsDon.getSpecialType() == GoodsDon.SpecialType.giftCard) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public H5JsPayParams pay(Long orderId, String tradeType) throws Exception {
|
|
|
log.info("调起微信支付[start] orderId:{}", orderId);
|
|
|
@@ -516,7 +608,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
// 更改订单状态
|
|
|
order.setTransactionId(transactionId);
|
|
|
- order.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
|
|
|
order.setPayTime(DateUtil.parse(map.get("time_end"), "yyyyMMddHHmmss"));
|
|
|
order.setShopId(appId);
|
|
|
@@ -528,63 +619,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
order.setOpenId(map.get("openid"));
|
|
|
}
|
|
|
order.setType(OrderDon.Type.WeChat);
|
|
|
- if (order.getIsNoLogin()) {
|
|
|
- order.setStatus(OrderDon.Status.hasPayment);
|
|
|
- }
|
|
|
-
|
|
|
- boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
|
- .set(OrderDon::getStatus, order.getStatus())
|
|
|
- .in(OrderDon::getStatus, List.of(OrderDon.Status.noPayment, OrderDon.Status.close))
|
|
|
- .eq(OrderDon::getId, order.getId()));
|
|
|
- if (!isSuccess) {
|
|
|
- log.info("微信回调商家订单号:{}订单状态已修改", order.getOrderNo());
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- if (!order.getIsNoLogin()) {
|
|
|
- //更新座位信息
|
|
|
- updateGroupsTicket(order, goodsDon, sku);
|
|
|
- if (order.getMoney().compareTo(BigDecimal.ZERO) > 0 && order.getIsDistribute()) {
|
|
|
- TASK_POOL.execute(() -> distributeWaitingSendPointsRecord(order));
|
|
|
- }
|
|
|
- if (goodsDon.getType() == 1) {
|
|
|
- //无车队,新增车队
|
|
|
- checkNoGroupsTripsAndSendMsg(sku, order);
|
|
|
- }
|
|
|
- //完成任务
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
- TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
|
|
|
- .eq(TaskType::getName, TaskTypeEnum.yh_order.getDesc()).last("limit 1"));
|
|
|
- taskService.completeTask(taskType, order.getUserId());
|
|
|
- });
|
|
|
- //客服续费订单
|
|
|
- handleServiceRenewOrder(order);
|
|
|
- }
|
|
|
- //购买Midjourney课程 赠送Midjourney车票
|
|
|
- if (goodsId != null && goodsId.equals(27l)) {
|
|
|
- order.setStatus(OrderDon.Status.complete);
|
|
|
- TASK_POOL.execute(() -> sendMidjourneyTicketIfCourse(order.getUserId()));
|
|
|
- }
|
|
|
- this.updateById(order);
|
|
|
- //配置了特定奖池,增加抽奖机会
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
- try {
|
|
|
- marketFrontService.addSpecificChanceNum(order.getUserId(), order.getId(), order.getGoodsId(), order.getSkuId());
|
|
|
- if (goodsDon.getType() == 2) {
|
|
|
- equipmentDistributeService.addDistributeBenefitsChance(order.getUserId(), order.getId());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("wx增加抽奖机会错误,orderId:{},error:{}", order.getId(), e);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- TASK_POOL.execute(()->{
|
|
|
- try {
|
|
|
- orderDonPostService.postData((order.getId()));
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("回传错误 {}",StringUtil.getErrorText(e));
|
|
|
- }
|
|
|
- });
|
|
|
+ unifiedHandlerOrderNotify(order, goodsDon, sku);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -670,6 +706,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
userBenefitsService.addUserBalance(orderDon.getUserId(), orderDon.getBalance(), UserBalanceSourceRecord.Source.close);
|
|
|
}
|
|
|
+
|
|
|
+ //是否是礼品卡 现金支付订单
|
|
|
+ BigDecimal gcCash = orderDon.getGcCash();
|
|
|
+ if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ giftCardOrderUseRecordService.returnGiftCardCash(orderDon.getId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -795,7 +837,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
orderDon.setRealMoney(orderDon.getMoney());
|
|
|
//扣除使用优惠券、余额的订单金额
|
|
|
- deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType());
|
|
|
+ deductOrderMoney(orderDon, couponUser, payRequest.getBalance(), user, sku.getPrice(), goodsDon.getType(), payRequest.getGcCash(), payRequest.getGcpIds());
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
//订单金额为0 且订单为已完成 更新虚物车票
|
|
|
if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
@@ -807,6 +849,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
closeOrder(orderDon.getId(), null);
|
|
|
});
|
|
|
}
|
|
|
+ //礼品卡现金使用记录
|
|
|
+ if (CollUtil.isNotEmpty(orderDon.getGcUseRecords())) {
|
|
|
+ orderDon.getGcUseRecords().forEach(data -> {
|
|
|
+ data.setOrderId(orderDon.getId());
|
|
|
+ });
|
|
|
+ giftCardOrderUseRecordService.saveBatch(orderDon.getGcUseRecords());
|
|
|
+ }
|
|
|
return orderDon;
|
|
|
}
|
|
|
|
|
|
@@ -873,78 +922,14 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
// 更改订单状态
|
|
|
orderDon.setTransactionId(transactionId);
|
|
|
- orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
orderDon.setPayTime(payTime);
|
|
|
orderDon.setShopId(appId);
|
|
|
orderDon.setType(OrderDon.Type.ALI_PAY);
|
|
|
- if (orderDon.getIsNoLogin()) {
|
|
|
- orderDon.setStatus(OrderDon.Status.hasPayment);
|
|
|
- }
|
|
|
- boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
|
- .set(OrderDon::getStatus, orderDon.getStatus())
|
|
|
- .in(OrderDon::getStatus, List.of(OrderDon.Status.noPayment, OrderDon.Status.close))
|
|
|
- .eq(OrderDon::getId, orderDon.getId()));
|
|
|
- if (!isSuccess) {
|
|
|
- log.info("支付宝回调商家订单号:{}订单状态已修改", orderDon.getOrderNo());
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!orderDon.getIsNoLogin()) {
|
|
|
- //更新座位信息
|
|
|
- updateGroupsTicket(orderDon, goodsDon, sku);
|
|
|
- if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0 && orderDon.getIsDistribute()) {
|
|
|
- TASK_POOL.execute(() -> distributeWaitingSendPointsRecord(orderDon));
|
|
|
- }
|
|
|
- if (goodsDon.getType() == 1) {
|
|
|
- //无车队,新增车队
|
|
|
- checkNoGroupsTripsAndSendMsg(sku, orderDon);
|
|
|
- }
|
|
|
- //完成任务
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
- TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
|
|
|
- .eq(TaskType::getName, TaskTypeEnum.yh_order.getDesc()).last("limit 1"));
|
|
|
- taskService.completeTask(taskType, orderDon.getUserId());
|
|
|
- });
|
|
|
- //客服续费订单
|
|
|
- handleServiceRenewOrder(orderDon);
|
|
|
- }
|
|
|
- //购买Midjourney课程 赠送Midjourney车票
|
|
|
- if (goodsId != null && goodsId.equals(27l)) {
|
|
|
- orderDon.setStatus(OrderDon.Status.complete);
|
|
|
- TASK_POOL.execute(() -> sendMidjourneyTicketIfCourse(orderDon.getUserId()));
|
|
|
- }
|
|
|
- this.updateById(orderDon);
|
|
|
- //配置了特定奖池,增加抽奖机会
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
- try {
|
|
|
- marketFrontService.addSpecificChanceNum(orderDon.getUserId(), orderDon.getId(), orderDon.getGoodsId(), orderDon.getSkuId());
|
|
|
- if (goodsDon.getType() == 2) {
|
|
|
- equipmentDistributeService.addDistributeBenefitsChance(orderDon.getUserId(), orderDon.getId());
|
|
|
- }
|
|
|
- //若该订单使用了规定推广者的兑换码 增加上下级关系
|
|
|
- if (StrUtil.isNotBlank(orderDon.getCouponExCode())) {
|
|
|
- addDistributeCouponCode(orderDon.getUserId(), orderDon.getCouponExCode());
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("zfb增加抽奖机会错误,orderId:{},error:{}", orderDon.getId(), e);
|
|
|
- }
|
|
|
- });
|
|
|
|
|
|
- TASK_POOL.execute(()->{
|
|
|
- try {
|
|
|
- orderDonPostService.postData((orderDon.getId()));
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("回传错误 {}",StringUtil.getErrorText(e));
|
|
|
- }
|
|
|
- });
|
|
|
+ unifiedHandlerOrderNotify(orderDon, goodsDon, sku);
|
|
|
}
|
|
|
|
|
|
public void setRelation(Long relationId, Long groupsId, Long userId, Long goodsId, Boolean isLoginPopularize) {
|
|
|
- if (isLoginPopularize == null || !isLoginPopularize) {
|
|
|
- int noPayCount = count(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, userId).eq(OrderDon::getGoodsId, goodsId).eq(OrderDon::getStatus, OrderDon.Status.noPayment.toString()));
|
|
|
- if (noPayCount > 0) {
|
|
|
- throw new BusinessRuntimeException("您有未支付订单.");
|
|
|
- }
|
|
|
- }
|
|
|
if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
|
|
|
log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
@@ -1110,91 +1095,15 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
this.updateById(orderDon);
|
|
|
}
|
|
|
|
|
|
- public AliPayParams commonAliPay(Long orderId, String returnUrl, String productCode, String appId, String qrPayMode) throws Exception {
|
|
|
- AlipayClient alipayClient = AliPayClientFactory.getAlipayClient(Optional.ofNullable(appId).orElse(ShopConfig.ZFB_DEFAULT_APP_ID));
|
|
|
- // 创建API对应的request
|
|
|
- AlipayRequest alipayRequest = getAliAayRequest(orderId, productCode, qrPayMode);
|
|
|
- if (alipayRequest == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("支付宝不支持该支付方式:{0}", productCode);
|
|
|
- }
|
|
|
- //回调地址
|
|
|
- String host = envCommonService.getHost();
|
|
|
- String notifyUrl = String.format("%s%s", host, BaseZfbConfig.notifyUrl);
|
|
|
- if (BaseZfbConfig.qrPayMode_redirect.equals(qrPayMode)) {
|
|
|
- returnUrl = String.format("%s%s", envCommonService.getDomain(), BaseZfbConfig.loginReturnUrl);
|
|
|
- alipayRequest.setReturnUrl(returnUrl);
|
|
|
- } else if (StrUtil.isNotBlank(returnUrl)) {
|
|
|
- alipayRequest.setReturnUrl(returnUrl);
|
|
|
- }
|
|
|
- alipayRequest.setNotifyUrl(notifyUrl);
|
|
|
- String form = null;
|
|
|
- try {
|
|
|
- //调用SDK生成表单
|
|
|
- //pagePay 统一下单接口
|
|
|
- form = alipayClient.pageExecute(alipayRequest).getBody();
|
|
|
- } catch (AlipayApiException e) {
|
|
|
- log.error("支付宝生成表单错误:{}", e == null ? null : e.getMessage());
|
|
|
- }
|
|
|
- log.info("支付宝返回参数:{}", form);
|
|
|
- return new AliPayParams(form);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 支付宝获取不同的request
|
|
|
- * @param productCode 销售产品码,与支付宝签约的产品码名称
|
|
|
- * @return
|
|
|
- */
|
|
|
- private AlipayRequest getAliAayRequest(Long orderId, String productCode, String qrPayMode) throws Exception {
|
|
|
- OrderAttach attach = new OrderAttach();
|
|
|
- attach.setO(orderId);
|
|
|
- String body = Codec.DoBase64.custom()
|
|
|
- .setData(Jsons.toJson(attach)).encodeAsText();
|
|
|
- OrderDon orderDon = orderDonMapper.selectById(orderId);
|
|
|
- if (orderDon.getType() != OrderDon.Type.ALI_PAY) {
|
|
|
- orderDon.setType(OrderDon.Type.ALI_PAY);
|
|
|
- orderDonMapper.updateById(orderDon);
|
|
|
- }
|
|
|
- GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(goodsDonSku.getGoodsId());
|
|
|
- String subject = goodsDon.getTitle().contains("ChatGPT") ? "AI订阅" : goodsDon.getTitle();
|
|
|
- if (ZfbProductCode.MOBILE_WEB.getProductCode().equals(productCode)) {
|
|
|
- //手机网站支付
|
|
|
- AlipayTradeWapPayRequest alipayTradeWapPayRequest = new AlipayTradeWapPayRequest();
|
|
|
- //手机网站支付支付参数
|
|
|
- AlipayTradeWapPayModel alipayTradeWapPayModel = new AlipayTradeWapPayModel();
|
|
|
- alipayTradeWapPayModel.setBody(body);
|
|
|
- alipayTradeWapPayModel.setOutTradeNo(orderDon.getOrderNo());
|
|
|
- alipayTradeWapPayModel.setTotalAmount(orderDon.getMoney().divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN).toString());
|
|
|
- alipayTradeWapPayModel.setSubject(subject);
|
|
|
- alipayTradeWapPayModel.setProductCode(productCode);
|
|
|
- //5分钟订单失效时间
|
|
|
- alipayTradeWapPayModel.setTimeExpire(DateUtil.offsetMinute(orderDon.getCreatedTime(), 5).toString());
|
|
|
- alipayTradeWapPayRequest.setBizModel(alipayTradeWapPayModel);
|
|
|
- return alipayTradeWapPayRequest;
|
|
|
- } else if (ZfbProductCode.PC_WEB.getProductCode().equals(productCode)) {
|
|
|
- //电脑网站支付
|
|
|
- AlipayTradePagePayRequest alipayTradePagePayRequest = new AlipayTradePagePayRequest();
|
|
|
- //电脑网站支付参数
|
|
|
- AlipayTradePagePayModel alipayTradePagePayModel = new AlipayTradePagePayModel();
|
|
|
- alipayTradePagePayModel.setBody(body);
|
|
|
- alipayTradePagePayModel.setOutTradeNo(orderDon.getOrderNo());
|
|
|
- alipayTradePagePayModel.setTotalAmount(orderDon.getMoney().divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN).toString());
|
|
|
- alipayTradePagePayModel.setSubject(subject);
|
|
|
- alipayTradePagePayModel.setProductCode(productCode);
|
|
|
- //5分钟订单失效时间
|
|
|
- alipayTradePagePayModel.setTimeExpire(DateUtil.offsetMinute(orderDon.getCreatedTime(), 5).toString());
|
|
|
- alipayTradePagePayModel.setQrPayMode(qrPayMode);
|
|
|
- alipayTradePagePayRequest.setBizModel(alipayTradePagePayModel);
|
|
|
- return alipayTradePagePayRequest;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
public void updateCarParkAndSendMsg(GoodsDon goodsDon, GoodsDonSku sku, OrderDon order) {
|
|
|
if (goodsDon.getType() == 1) {
|
|
|
log.info("虚物订单orderNo:{}开始更新车票信息", order.getOrderNo());
|
|
|
//修改车位状态
|
|
|
GroupsRelation relation = groupsRelationMapper.selectById(order.getRelationId());
|
|
|
+ if (relation == null) {
|
|
|
+ log.info("无需更新车票信息");
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (order.getIsDp()) {
|
|
|
//是否已经发送优惠加购车票
|
|
|
OrderDiscountPlusPurchaseSkuRelation purchaseSkuRelation = orderDiscountPlusPurchaseSkuRelationMapper.selectOne(Wrappers.lambdaQuery(OrderDiscountPlusPurchaseSkuRelation.class)
|
|
|
@@ -1961,7 +1870,52 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
/**
|
|
|
* 使用优惠营销 订单金额抵扣
|
|
|
*/
|
|
|
- public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, Integer goodsType) {
|
|
|
+ public void deductOrderMoney(OrderDon orderDon, CouponUser couponUser, BigDecimal balance, User user, BigDecimal skuMoney, Integer goodsType, BigDecimal gcCash, List<Long> gcpIds) {
|
|
|
+ //礼品卡现金支付 不参与其他优惠
|
|
|
+ if (gcCash != null && gcCash.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (CollUtil.isEmpty(gcpIds)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("礼品卡现金支付参数异常");
|
|
|
+ }
|
|
|
+ BigDecimal money = orderDon.getMoney();
|
|
|
+ if (gcCash.compareTo(money) > 0) {
|
|
|
+ gcCash = money;
|
|
|
+ }
|
|
|
+ List<GiftCardUserRecord> availableGiftCards = giftCardUserRecordService.list(Wrappers.lambdaQuery(GiftCardUserRecord.class)
|
|
|
+ .eq(GiftCardUserRecord::getToUserId, user.getId())
|
|
|
+ .in(GiftCardUserRecord::getId, gcpIds)
|
|
|
+ .eq(GiftCardUserRecord::getIsPay, true)
|
|
|
+ .eq(GiftCardUserRecord::getGcType, 1)
|
|
|
+ .gt(GiftCardUserRecord::getRemainCash, 0));
|
|
|
+ if (availableGiftCards.size() != gcpIds.size()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("礼品卡使用异常,请刷新页面重试");
|
|
|
+ }
|
|
|
+ //需要扣除的礼品卡现金
|
|
|
+ BigDecimal deductCash = gcCash;
|
|
|
+ List<GiftCardOrderUseRecord> gcUseRecords = new ArrayList<>();
|
|
|
+ for (GiftCardUserRecord giftCard : availableGiftCards) {
|
|
|
+ if (deductCash.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ BigDecimal remainCash = giftCard.getRemainCash();
|
|
|
+ //扣完
|
|
|
+ if (remainCash.compareTo(deductCash) == 0) {
|
|
|
+ deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords);
|
|
|
+ deductCash = BigDecimal.ZERO;
|
|
|
+ } else if (remainCash.compareTo(deductCash) < 0) {
|
|
|
+ deductGiftCardCash(user.getId(), giftCard.getId(), remainCash, remainCash, gcUseRecords);
|
|
|
+ deductCash = deductCash.subtract(remainCash);
|
|
|
+ } else if (remainCash.compareTo(deductCash) > 0) {
|
|
|
+ deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords);
|
|
|
+ deductCash = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orderDon.setMoney(orderDon.getMoney().subtract(gcCash));
|
|
|
+ orderDon.setGcCash(gcCash);
|
|
|
+ if (!gcUseRecords.isEmpty()) {
|
|
|
+ orderDon.setGcUseRecords(gcUseRecords);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
//存在优惠券
|
|
|
if (couponUser != null) {
|
|
|
Long couponId = couponUser.getCouponId();
|
|
|
@@ -2042,11 +1996,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
|
GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
- orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
+ unifiedHandlerOrderNotify(orderDon, goodsDon, sku);
|
|
|
+ }
|
|
|
|
|
|
- if (orderDon.getIsNoLogin()) {
|
|
|
- orderDon.setStatus(OrderDon.Status.hasPayment);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 统一订单信息回调
|
|
|
+ */
|
|
|
+ public void unifiedHandlerOrderNotify(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) {
|
|
|
boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
|
.set(OrderDon::getStatus, orderDon.getStatus())
|
|
|
.in(OrderDon::getStatus, List.of(OrderDon.Status.noPayment, OrderDon.Status.close))
|
|
|
@@ -2055,34 +2011,40 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
log.info("支付宝回调商家订单号:{}订单状态已修改", orderDon.getOrderNo());
|
|
|
return;
|
|
|
}
|
|
|
+ orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
+
|
|
|
+ if (orderDon.getIsNoLogin()) {
|
|
|
+ orderDon.setStatus(OrderDon.Status.hasPayment);
|
|
|
+ }
|
|
|
+ Long goodsId = goodsDon.getId();
|
|
|
if (!orderDon.getIsNoLogin()) {
|
|
|
//更新座位信息
|
|
|
updateGroupsTicket(orderDon, goodsDon, sku);
|
|
|
- if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0 && orderDon.getIsDistribute()) {
|
|
|
- TASK_POOL.execute(() -> distributeWaitingSendPointsRecord(orderDon));
|
|
|
- }
|
|
|
if (goodsDon.getType() == 1) {
|
|
|
//无车队,新增车队
|
|
|
checkNoGroupsTripsAndSendMsg(sku, orderDon);
|
|
|
}
|
|
|
- //完成任务
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
- TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
|
|
|
- .eq(TaskType::getName, TaskTypeEnum.yh_order.getDesc()).last("limit 1"));
|
|
|
- taskService.completeTask(taskType, orderDon.getUserId());
|
|
|
- });
|
|
|
//客服续费订单
|
|
|
handleServiceRenewOrder(orderDon);
|
|
|
}
|
|
|
- //购买Midjourney课程 赠送Midjourney车票
|
|
|
- if (goodsId != null && goodsId.equals(27l)) {
|
|
|
- orderDon.setStatus(OrderDon.Status.complete);
|
|
|
- TASK_POOL.execute(() -> sendMidjourneyTicketIfCourse(orderDon.getUserId()));
|
|
|
- }
|
|
|
this.updateById(orderDon);
|
|
|
- //配置了特定奖池,增加抽奖机会
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
+
|
|
|
+ TASK_POOL.execute(()->{
|
|
|
try {
|
|
|
+ //发放积分
|
|
|
+ if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0 && orderDon.getIsDistribute()) {
|
|
|
+ TASK_POOL.execute(() -> distributeWaitingSendPointsRecord(orderDon));
|
|
|
+ }
|
|
|
+ //完成任务
|
|
|
+ TaskType taskType = taskTypeMapper.selectOne(Wrappers.lambdaQuery(TaskType.class)
|
|
|
+ .eq(TaskType::getName, TaskTypeEnum.yh_order.getDesc()).last("limit 1"));
|
|
|
+ taskService.completeTask(taskType, orderDon.getUserId());
|
|
|
+ //购买Midjourney课程 赠送Midjourney车票
|
|
|
+ if (goodsId != null && goodsId.equals(27l)) {
|
|
|
+ orderDon.setStatus(OrderDon.Status.complete);
|
|
|
+ TASK_POOL.execute(() -> sendMidjourneyTicketIfCourse(orderDon.getUserId()));
|
|
|
+ }
|
|
|
+ //配置了特定奖池,增加抽奖机会
|
|
|
marketFrontService.addSpecificChanceNum(orderDon.getUserId(), orderDon.getId(), orderDon.getGoodsId(), orderDon.getSkuId());
|
|
|
if (goodsDon.getType() == 2) {
|
|
|
equipmentDistributeService.addDistributeBenefitsChance(orderDon.getUserId(), orderDon.getId());
|
|
|
@@ -2091,9 +2053,126 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (StrUtil.isNotBlank(orderDon.getCouponExCode())) {
|
|
|
addDistributeCouponCode(orderDon.getUserId(), orderDon.getCouponExCode());
|
|
|
}
|
|
|
+
|
|
|
+ //礼品卡
|
|
|
+ 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) {
|
|
|
+ List<GiftCardPayReq> giftCardPayReqs = Jsons.parseList(giftCardPay, GiftCardPayReq.class);
|
|
|
+ if (CollUtil.isNotEmpty(giftCardPayReqs)) {
|
|
|
+ log.info("记录用户userId:{}订单orderId:{}购买成功礼品卡", orderDon.getUserId(), orderDon.getId());
|
|
|
+ giftCardUserPayRecord(giftCardPayReqs, orderDon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("回调修改订单信息错误,orderId:{},error:{}", orderDon.getId(), StringUtil.getErrorText(e));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ TASK_POOL.execute(()->{
|
|
|
+ try {
|
|
|
+ orderDonPostService.postData((orderDon.getId()));
|
|
|
} catch (Exception e) {
|
|
|
- log.error("zfb增加抽奖机会错误,orderId:{},error:{}", orderDon.getId(), e);
|
|
|
+ log.error("回传错误 {}",StringUtil.getErrorText(e));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ public void setDistributeOrderMark(OrderDon orderDon, Integer goodsType, Long userId) {
|
|
|
+ if (userId == null || userId == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //虚拟商品订单,是否是分销订单
|
|
|
+ if (goodsType == 1 || goodsType == 2) {
|
|
|
+ //若该订单使用了规定推广者的兑换码 增加上下级关系
|
|
|
+ if (StrUtil.isNotBlank(orderDon.getCouponExCode()) && orderDon.getUserId() != 0) {
|
|
|
+ addDistributeCouponCode(orderDon.getUserId(), orderDon.getCouponExCode());
|
|
|
+ }
|
|
|
+ UserDistributeShared userDistributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class).eq(UserDistributeShared::getUserId, userId).last("limit 1"));
|
|
|
+ if (userDistributeShared != null) {
|
|
|
+ orderDon.setIsDistribute(true);
|
|
|
+ UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, userDistributeShared.getSharedId()));
|
|
|
+ if (userDistribute != null) {
|
|
|
+ orderDon.setIsFixedDistribute(true);
|
|
|
+ orderDon.setCpsPopularizeId(userDistributeShared.getDsPopularizeId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deductGiftCardCash(Long userId, Long gcId, BigDecimal deductCash, BigDecimal gcRemainCash, List<GiftCardOrderUseRecord> gcUseRecords) {
|
|
|
+ Boolean is_update = giftCardUserRecordService.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
|
|
|
+ .set(GiftCardUserRecord::getRemainCash, gcRemainCash.subtract(deductCash))
|
|
|
+ .eq(GiftCardUserRecord::getId, gcId)
|
|
|
+ .eq(GiftCardUserRecord::getIsPay, true)
|
|
|
+ .eq(GiftCardUserRecord::getRemainCash, gcRemainCash));
|
|
|
+ if (!is_update) {
|
|
|
+ throw BusinessRuntimeException.getInstance("礼品卡支付异常,请刷新页面重试");
|
|
|
+ }
|
|
|
+ //记录使用关系 订单关闭 退款使用
|
|
|
+ GiftCardOrderUseRecord useRecord = new GiftCardOrderUseRecord();
|
|
|
+ useRecord.setUserId(userId);
|
|
|
+ useRecord.setCash(deductCash);
|
|
|
+ useRecord.setGcId(gcId);
|
|
|
+ gcUseRecords.add(useRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户购买成功礼品卡记录
|
|
|
+ */
|
|
|
+ private void giftCardUserPayRecord(List<GiftCardPayReq> giftCards, OrderDon orderDon) {
|
|
|
+ //礼品卡规格
|
|
|
+ Map<Long, Integer> giftCardPayNumMap = new ConcurrentHashMap<>();
|
|
|
+ AtomicInteger init_size = new AtomicInteger(0);
|
|
|
+ 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()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ giftCardUserRecord.setOrderId(orderDon.getId());
|
|
|
+ giftCardUserRecord.setUserId(orderDon.getUserId());
|
|
|
+ giftCardUserRecord.setGcType(data.getGcType());
|
|
|
+ giftCardUserRecord.setGcDetail(gcDetail);
|
|
|
+ gcUserPayRecords.add(giftCardUserRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(gcUserPayRecords)) {
|
|
|
+ giftCardUserRecordService.saveBatch(gcUserPayRecords);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|