|
@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateField;
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
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.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
import com.alipay.api.AlipayApiException;
|
|
@@ -12,7 +14,10 @@ import com.alipay.api.AlipayRequest;
|
|
|
import com.alipay.api.AlipayResponse;
|
|
import com.alipay.api.AlipayResponse;
|
|
|
import com.alipay.api.domain.*;
|
|
import com.alipay.api.domain.*;
|
|
|
import com.alipay.api.internal.util.AlipaySignature;
|
|
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.AlipayFundTransCommonQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
|
|
import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse;
|
|
|
import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
import com.alipay.api.response.AlipayTradeQueryResponse;
|
|
@@ -48,19 +53,21 @@ import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
import com.cyksj.model.dto.*;
|
|
import com.cyksj.model.dto.*;
|
|
|
import com.cyksj.model.entity.Address;
|
|
import com.cyksj.model.entity.Address;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
|
|
+import com.cyksj.model.manage.dto.GiftCardDto;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.manage.views.OrderDonView;
|
|
import com.cyksj.model.manage.views.OrderDonView;
|
|
|
-import com.cyksj.model.request.OrderAttach;
|
|
|
|
|
-import com.cyksj.model.request.OrderPayRequest;
|
|
|
|
|
-import com.cyksj.model.request.TransferAccountsReq;
|
|
|
|
|
|
|
+import com.cyksj.model.request.*;
|
|
|
import com.cyksj.model.views.CouponNewUserView;
|
|
import com.cyksj.model.views.CouponNewUserView;
|
|
|
import com.cyksj.model.views.CouponUserView;
|
|
import com.cyksj.model.views.CouponUserView;
|
|
|
|
|
+import com.cyksj.model.views.GiftCardGoodsSkuFrontView;
|
|
|
import com.cyksj.model.views.GoodsDonSkuView;
|
|
import com.cyksj.model.views.GoodsDonSkuView;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
|
import com.cyksj.service.distribute.UserBusinessFrontService;
|
|
import com.cyksj.service.distribute.UserBusinessFrontService;
|
|
|
import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
|
|
import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
|
|
|
import com.cyksj.service.exchange.ExchangeCodeService;
|
|
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.groups.GroupsFuncService;
|
|
|
import com.cyksj.service.market.MarketFrontService;
|
|
import com.cyksj.service.market.MarketFrontService;
|
|
|
import com.cyksj.service.market.task.TaskService;
|
|
import com.cyksj.service.market.task.TaskService;
|
|
@@ -71,6 +78,7 @@ import com.cyksj.service.pay.AliPayCommonService;
|
|
|
import com.cyksj.service.relation.GroupRelationClearService;
|
|
import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
|
|
+import com.cyksj.service.telegram.TelegramService;
|
|
|
import com.cyksj.service.template.TemplateCommonService;
|
|
import com.cyksj.service.template.TemplateCommonService;
|
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
import com.cyksj.service.user.UserBenefitsService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
@@ -90,6 +98,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
@@ -209,38 +219,77 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
|
|
private final ChannelPopularizeMapper channelPopularizeMapper;
|
|
private final ChannelPopularizeMapper channelPopularizeMapper;
|
|
|
|
|
|
|
|
|
|
+ private final TelegramService telegramService;
|
|
|
|
|
+
|
|
|
|
|
+ private final GiftCardUserRecordService giftCardUserRecordService;
|
|
|
|
|
+
|
|
|
|
|
+ private final GiftCardOrderUseRecordService giftCardOrderUseRecordService;
|
|
|
|
|
+
|
|
|
|
|
+ private final GiftCardOrderRelateMapper giftCardOrderRelateMapper;
|
|
|
|
|
+
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@Override
|
|
@Override
|
|
|
public OrderDon submit(OrderPayRequest payRequest) throws Exception {
|
|
public OrderDon submit(OrderPayRequest payRequest) throws Exception {
|
|
|
|
|
+ GoodsDonSku sku = null;
|
|
|
|
|
+ Long goodsId;
|
|
|
|
|
+ List<GiftCardPayReq> giftCards = null;
|
|
|
|
|
+ GiftCardDto gcPayInfo = payRequest.getGcPayInfo();
|
|
|
|
|
+ if (gcPayInfo != null && gcPayInfo.getGiftCards() != null) {
|
|
|
|
|
+ giftCards = gcPayInfo.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;
|
|
CouponUser couponUser = null;
|
|
|
if (StrUtil.isNotBlank(payRequest.getCouponExCode()) || payRequest.getCouponId() != null) {
|
|
if (StrUtil.isNotBlank(payRequest.getCouponExCode()) || payRequest.getCouponId() != null) {
|
|
|
CouponPopularizeDto couponPopularizeDto = checkCouponStatus(payRequest.getSkuId(), payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), false);
|
|
CouponPopularizeDto couponPopularizeDto = checkCouponStatus(payRequest.getSkuId(), payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), false);
|
|
|
//记录优惠券使用状态
|
|
//记录优惠券使用状态
|
|
|
couponUser = couponStatusRecord(payRequest.getCouponExCode(), payRequest.getCouponId(), payRequest.getUserId(), couponPopularizeDto);
|
|
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();
|
|
Boolean isNoLogin = payRequest.getIsNoLogin();
|
|
|
User user;
|
|
User user;
|
|
|
String payOpenId = null;
|
|
String payOpenId = null;
|
|
|
Long relationId = 0L;
|
|
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 = new User();
|
|
|
user.setId(0l);
|
|
user.setId(0l);
|
|
|
} else {
|
|
} else {
|
|
|
- user = userMapper.selectById(payRequest.getUserId());
|
|
|
|
|
|
|
+ user = userMapper.selectById(userId);
|
|
|
if (user == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
|
|
if (user == null) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
|
|
|
if (user.getIsBlack()) throw BusinessRuntimeException.getInstance("系统检测操作异常,请稍后再试");
|
|
if (user.getIsBlack()) throw BusinessRuntimeException.getInstance("系统检测操作异常,请稍后再试");
|
|
|
- //ChatGPT Plus账号限购校验
|
|
|
|
|
- checkChatGPTPlusPurchaseLimit(user.getId(), goodsDon.getId(), goodsDon.getTitle(), sku.getId(), sku.getSpecVal());
|
|
|
|
|
payOpenId = user.getOpenId();
|
|
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);
|
|
relationId = getRelation(payRequest, sku);
|
|
|
} else {
|
|
} else {
|
|
@@ -257,38 +306,39 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
}
|
|
|
orderDon.setOrderNo(donNo);
|
|
orderDon.setOrderNo(donNo);
|
|
|
orderDon.setOpenId(payOpenId);
|
|
orderDon.setOpenId(payOpenId);
|
|
|
- if (sku.getPrice() == null || sku.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("下单商品价格异常");
|
|
|
|
|
- }
|
|
|
|
|
- //是否是特定价格 且是否满足
|
|
|
|
|
- Boolean isSpecificPrice = Optional.ofNullable(payRequest.getIsSpecificPrice()).orElse(false);
|
|
|
|
|
- String specificGoodsIds = sku.getSpecificGoodsIds();
|
|
|
|
|
- BigDecimal specificPrice = BigDecimal.ZERO;
|
|
|
|
|
- if (isSpecificPrice) {
|
|
|
|
|
- if (StrUtil.isEmpty(specificGoodsIds)) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
|
|
- }
|
|
|
|
|
- if (payRequest.getDonMoney().compareTo(sku.getSpecificPrice()) <= 0) {
|
|
|
|
|
- payRequest.setDonMoney(sku.getSpecificPrice());
|
|
|
|
|
- }
|
|
|
|
|
- List<Long> specificGoodsList = Jsons.parseList(specificGoodsIds, Long.class);
|
|
|
|
|
- if (CollUtil.isEmpty(specificGoodsList)) {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
|
|
|
|
+ if (sku != null) {
|
|
|
|
|
+ if (sku.getPrice() == null || sku.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("下单商品价格异常");
|
|
|
|
|
+ }
|
|
|
|
|
+ //是否是特定价格 且是否满足
|
|
|
|
|
+ Boolean isSpecificPrice = Optional.ofNullable(payRequest.getIsSpecificPrice()).orElse(false);
|
|
|
|
|
+ String specificGoodsIds = sku.getSpecificGoodsIds();
|
|
|
|
|
+ BigDecimal specificPrice = BigDecimal.ZERO;
|
|
|
|
|
+ if (isSpecificPrice) {
|
|
|
|
|
+ if (StrUtil.isEmpty(specificGoodsIds)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (payRequest.getDonMoney().compareTo(sku.getSpecificPrice()) <= 0) {
|
|
|
|
|
+ payRequest.setDonMoney(sku.getSpecificPrice());
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> specificGoodsList = Jsons.parseList(specificGoodsIds, Long.class);
|
|
|
|
|
+ if (CollUtil.isEmpty(specificGoodsList)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (user.getId() == 0) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
|
|
|
|
|
+ Number count = beanSearcher.searchCount(OrderDon.class, MapUtils.builder().field(OrderDon::getGoodsId, specificGoodsList).op(Operator.InList)
|
|
|
|
|
+ .field(OrderDon::getUserId, user.getId())
|
|
|
|
|
+ .field(OrderDon::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
|
|
|
|
|
+ .build());
|
|
|
|
|
+ if (count.intValue() <= 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("你不满足该商品特定价格条件");
|
|
|
|
|
+ }
|
|
|
|
|
+ specificPrice = sku.getSpecificPrice();
|
|
|
}
|
|
}
|
|
|
- if (user.getId() == 0) throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
|
|
|
|
|
- Number count = beanSearcher.searchCount(OrderDon.class, MapUtils.builder().field(OrderDon::getGoodsId, specificGoodsList).op(Operator.InList)
|
|
|
|
|
- .field(OrderDon::getUserId, user.getId())
|
|
|
|
|
- .field(OrderDon::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
|
|
|
|
|
- .build());
|
|
|
|
|
- if (count.intValue() <= 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());
|
|
|
}
|
|
}
|
|
|
- specificPrice = sku.getSpecificPrice();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (payRequest.getDonMoney().compareTo(sku.getPrice()) < 0 && !isSpecificPrice) {
|
|
|
|
|
- log.info("规格:{}支付金额:{}异常,调整用户userId:{}支付金额为:{}", sku.getSpecVal(), payRequest.getDonMoney(), user.getId(), sku.getPrice());
|
|
|
|
|
- payRequest.setDonMoney(sku.getPrice());
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
orderDon.setMoney(payRequest.getDonMoney());
|
|
orderDon.setMoney(payRequest.getDonMoney());
|
|
@@ -324,8 +374,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (payRequest.getPopularizeId() != null) {
|
|
if (payRequest.getPopularizeId() != null) {
|
|
|
orderDon.setPopularizeId(payRequest.getPopularizeId());
|
|
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());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (isSpecificPrice && (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0 || orderDon.getMoney().compareTo(specificPrice) != 0)) {
|
|
if (isSpecificPrice && (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0 || orderDon.getMoney().compareTo(specificPrice) != 0)) {
|
|
|
throw BusinessRuntimeException.getInstance("专属价格不支持使用其他优惠");
|
|
throw BusinessRuntimeException.getInstance("专属价格不支持使用其他优惠");
|
|
@@ -341,24 +393,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setIsWebPay(payRequest.getIsWebPay());
|
|
orderDon.setIsWebPay(payRequest.getIsWebPay());
|
|
|
orderDon.setSource(payRequest.getSource());
|
|
orderDon.setSource(payRequest.getSource());
|
|
|
orderDon.setCouponExCode(payRequest.getCouponExCode());
|
|
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) {
|
|
if (relationId != 0) {
|
|
|
Long gtSkuId = groupsRelationMapper.getGroupTripsSkuIdByRelationId(relationId);
|
|
Long gtSkuId = groupsRelationMapper.getGroupTripsSkuIdByRelationId(relationId);
|
|
|
if (!gtSkuId.equals(orderDon.getSkuId())) {
|
|
if (!gtSkuId.equals(orderDon.getSkuId())) {
|
|
@@ -368,7 +404,56 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
orderDon.setPayDesc(goodsDon.getPayDesc());
|
|
orderDon.setPayDesc(goodsDon.getPayDesc());
|
|
|
StringBuilder payTitle = new StringBuilder();
|
|
StringBuilder payTitle = new StringBuilder();
|
|
|
payTitle.append(goodsDon.getTitle());
|
|
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 -> {
|
|
|
|
|
+ if (data.getNum() <= 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ giftCardPayNumMap.putIfAbsent(data.getGcId(), data.getNum());
|
|
|
|
|
+ });
|
|
|
|
|
+ if (giftCardPayNumMap.isEmpty()) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("请选择要购买礼品卡的数量");
|
|
|
|
|
+ }
|
|
|
|
|
+ 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());
|
|
|
|
|
+ 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)));
|
|
|
|
|
+
|
|
|
|
|
+ //礼品卡关系
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ gcPayInfo.setGcPayDetail(giftCardViews);
|
|
|
|
|
+
|
|
|
|
|
+ //调整礼品卡金额
|
|
|
|
|
+ if (gift_card_pay_money.compareTo(orderDon.getMoney()) > 0) {
|
|
|
|
|
+ orderDon.setMoney(gift_card_pay_money);
|
|
|
|
|
+ orderDon.setRealMoney(gift_card_pay_money);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if (orderDon.getIsDp()) {
|
|
if (orderDon.getIsDp()) {
|
|
|
List<GoodsDonSkuView> dp_skuViewList = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, dpSkuIds).op(Operator.InList).build());
|
|
List<GoodsDonSkuView> dp_skuViewList = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, dpSkuIds).op(Operator.InList).build());
|
|
|
if (dp_skuViewList.size() != dpSkuIds.size()) {
|
|
if (dp_skuViewList.size() != dpSkuIds.size()) {
|
|
@@ -421,9 +506,36 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
orderDon.setSpecialType(goodsDon.getSpecialType());
|
|
orderDon.setSpecialType(goodsDon.getSpecialType());
|
|
|
|
|
+ //礼品卡购买记录
|
|
|
|
|
+ if (CollUtil.isNotEmpty(giftCards)) {
|
|
|
|
|
+ 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 -> {
|
|
|
|
|
+ data.setOrderId(orderDon.getId());
|
|
|
|
|
+ });
|
|
|
|
|
+ giftCardOrderUseRecordService.saveBatch(orderDon.getGcUseRecords());
|
|
|
|
|
+ }
|
|
|
return orderDon;
|
|
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
|
|
@Override
|
|
|
public H5JsPayParams pay(Long orderId, String tradeType) throws Exception {
|
|
public H5JsPayParams pay(Long orderId, String tradeType) throws Exception {
|
|
|
log.info("调起微信支付[start] orderId:{}", orderId);
|
|
log.info("调起微信支付[start] orderId:{}", orderId);
|
|
@@ -533,9 +645,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
log.error("回调数据:{}", map);
|
|
log.error("回调数据:{}", map);
|
|
|
throw BusinessRuntimeException.getInstance("支付成功回调, 校验签名失败.");
|
|
throw BusinessRuntimeException.getInstance("支付成功回调, 校验签名失败.");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(order.getSkuId());
|
|
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
|
|
|
|
+ GoodsDonSku sku = null;
|
|
|
|
|
+ if (order.getSkuId() != null) {
|
|
|
|
|
+ sku = goodsDonSkuMapper.selectById(order.getSkuId());
|
|
|
|
|
+ }
|
|
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(order.getGoodsId());
|
|
|
|
|
|
|
|
String transactionId = map.get("transaction_id");
|
|
String transactionId = map.get("transaction_id");
|
|
|
|
|
|
|
@@ -546,7 +660,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
|
|
// 更改订单状态
|
|
// 更改订单状态
|
|
|
order.setTransactionId(transactionId);
|
|
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.setPayTime(DateUtil.parse(map.get("time_end"), "yyyyMMddHHmmss"));
|
|
|
order.setShopId(appId);
|
|
order.setShopId(appId);
|
|
@@ -558,63 +671,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
order.setOpenId(map.get("openid"));
|
|
order.setOpenId(map.get("openid"));
|
|
|
}
|
|
}
|
|
|
order.setType(OrderDon.Type.WeChat);
|
|
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
|
|
@Override
|
|
@@ -700,6 +758,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
userBenefitsService.addUserBalance(orderDon.getUserId(), orderDon.getBalance(), UserBalanceSourceRecord.Source.close);
|
|
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());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -825,7 +889,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
}
|
|
}
|
|
|
orderDon.setRealMoney(orderDon.getMoney());
|
|
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);
|
|
this.saveOrUpdate(orderDon);
|
|
|
//订单金额为0 且订单为已完成 更新虚物车票
|
|
//订单金额为0 且订单为已完成 更新虚物车票
|
|
|
if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
|
|
@@ -837,6 +901,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
closeOrder(orderDon.getId(), null);
|
|
closeOrder(orderDon.getId(), null);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ //礼品卡现金使用记录
|
|
|
|
|
+ if (CollUtil.isNotEmpty(orderDon.getGcUseRecords())) {
|
|
|
|
|
+ orderDon.getGcUseRecords().forEach(data -> {
|
|
|
|
|
+ data.setOrderId(orderDon.getId());
|
|
|
|
|
+ });
|
|
|
|
|
+ giftCardOrderUseRecordService.saveBatch(orderDon.getGcUseRecords());
|
|
|
|
|
+ }
|
|
|
return orderDon;
|
|
return orderDon;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -895,86 +966,25 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getIsNoLogin()) {
|
|
if (orderDon.getIsNoLogin()) {
|
|
|
orderDon.setExCode(exchangeCodeService.getExCode(goodsId, orderDon.getSkuId(), 1));
|
|
orderDon.setExCode(exchangeCodeService.getExCode(goodsId, orderDon.getSkuId(), 1));
|
|
|
}
|
|
}
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
|
|
- GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
|
|
|
|
+ GoodsDonSku sku = null;
|
|
|
|
|
+ if (orderDon.getSkuId() != null) {
|
|
|
|
|
+ sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
|
|
+ }
|
|
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
Date payTime = DateTime.now();
|
|
Date payTime = DateTime.now();
|
|
|
if (StringUtils.isNotBlank(payTimeStr)) {
|
|
if (StringUtils.isNotBlank(payTimeStr)) {
|
|
|
payTime = DateUtil.parse(payTimeStr, "yyyy-MM-dd HH:mm:ss");
|
|
payTime = DateUtil.parse(payTimeStr, "yyyy-MM-dd HH:mm:ss");
|
|
|
}
|
|
}
|
|
|
// 更改订单状态
|
|
// 更改订单状态
|
|
|
orderDon.setTransactionId(transactionId);
|
|
orderDon.setTransactionId(transactionId);
|
|
|
- orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
|
|
orderDon.setPayTime(payTime);
|
|
orderDon.setPayTime(payTime);
|
|
|
orderDon.setShopId(appId);
|
|
orderDon.setShopId(appId);
|
|
|
orderDon.setType(OrderDon.Type.ALI_PAY);
|
|
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) {
|
|
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)) {
|
|
if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
|
|
|
log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
@@ -1130,7 +1140,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw BusinessRuntimeException.getInstance("订单异常");
|
|
throw BusinessRuntimeException.getInstance("订单异常");
|
|
|
}
|
|
}
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
|
|
|
|
+ GoodsDonSku sku = null;
|
|
|
|
|
+ if (orderDon.getSkuId() != null) {
|
|
|
|
|
+ sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
|
|
+ }
|
|
|
orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
updateGroupsTicket(orderDon, goodsDon, sku);
|
|
updateGroupsTicket(orderDon, goodsDon, sku);
|
|
|
if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
if (orderDon.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
@@ -1140,91 +1153,15 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
this.updateById(orderDon);
|
|
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) {
|
|
public void updateCarParkAndSendMsg(GoodsDon goodsDon, GoodsDonSku sku, OrderDon order) {
|
|
|
if (goodsDon.getType() == 1) {
|
|
if (goodsDon.getType() == 1) {
|
|
|
- log.info("虚物订单orderNo:{}开始更新车票信息", order.getOrderNo());
|
|
|
|
|
//修改车位状态
|
|
//修改车位状态
|
|
|
GroupsRelation relation = groupsRelationMapper.selectById(order.getRelationId());
|
|
GroupsRelation relation = groupsRelationMapper.selectById(order.getRelationId());
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ log.info("无需更新车票信息");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("虚物订单orderNo:{}开始更新车票信息", order.getOrderNo());
|
|
|
if (order.getIsDp()) {
|
|
if (order.getIsDp()) {
|
|
|
//是否已经发送优惠加购车票
|
|
//是否已经发送优惠加购车票
|
|
|
OrderDiscountPlusPurchaseSkuRelation purchaseSkuRelation = orderDiscountPlusPurchaseSkuRelationMapper.selectOne(Wrappers.lambdaQuery(OrderDiscountPlusPurchaseSkuRelation.class)
|
|
OrderDiscountPlusPurchaseSkuRelation purchaseSkuRelation = orderDiscountPlusPurchaseSkuRelationMapper.selectOne(Wrappers.lambdaQuery(OrderDiscountPlusPurchaseSkuRelation.class)
|
|
@@ -1593,15 +1530,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
//新增空车队发送模板消息
|
|
//新增空车队发送模板消息
|
|
|
TASK_POOL.execute(() -> {
|
|
TASK_POOL.execute(() -> {
|
|
|
groupsFuncService.createNewGroupsTrips(sku);
|
|
groupsFuncService.createNewGroupsTrips(sku);
|
|
|
-// try {
|
|
|
|
|
-// List<CustomerService> customerServices = customerServiceMapper.selectList(null);
|
|
|
|
|
-// for (CustomerService customerService : customerServices) {
|
|
|
|
|
-// log.info("发送客服{}空车位通知消息", customerService.getNickName());
|
|
|
|
|
-// templateCommonService.emptySendMsgNotify(order, customerService.getOpenId());
|
|
|
|
|
-// }
|
|
|
|
|
-// } catch (Exception e) {
|
|
|
|
|
-// log.error("发送{}空车位模板消息至客服失败:{}", order.getGoodsId(), e);
|
|
|
|
|
-// }
|
|
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1777,7 +1705,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
* 查询第三放接口订单是否已支付
|
|
* 查询第三放接口订单是否已支付
|
|
|
*/
|
|
*/
|
|
|
public OrderDon.Status isHasPaid(OrderDon orderDon) {
|
|
public OrderDon.Status isHasPaid(OrderDon orderDon) {
|
|
|
- OrderDon.Status noPayment = OrderDon.Status.noPayment;
|
|
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
if (orderDon.getType() == OrderDon.Type.WeChat) {
|
|
if (orderDon.getType() == OrderDon.Type.WeChat) {
|
|
|
try {
|
|
try {
|
|
@@ -1787,7 +1714,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if ("SUCCESS".equals(orderStatus)) {
|
|
if ("SUCCESS".equals(orderStatus)) {
|
|
|
orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
orderDon.setTransactionId(reMap.get("transaction_id"));
|
|
orderDon.setTransactionId(reMap.get("transaction_id"));
|
|
|
- return updateNoPayment(noPayment, orderDon, goodsDon);
|
|
|
|
|
|
|
+ return updateNoPayment(orderDon, goodsDon);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -1801,7 +1728,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if ("TRADE_SUCCESS".equals(tradeStatus)) {
|
|
if ("TRADE_SUCCESS".equals(tradeStatus)) {
|
|
|
orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
orderDon.setTransactionId(zfbOrderDetail.getTradeNo());
|
|
orderDon.setTransactionId(zfbOrderDetail.getTradeNo());
|
|
|
- return updateNoPayment(noPayment, orderDon, goodsDon);
|
|
|
|
|
|
|
+ return updateNoPayment(orderDon, goodsDon);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -1811,21 +1738,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
return orderDon.getStatus();
|
|
return orderDon.getStatus();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private OrderDon.Status updateNoPayment(OrderDon.Status noPayment, OrderDon orderDon, GoodsDon goodsDon) {
|
|
|
|
|
- boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
|
|
|
- .set(OrderDon::getStatus, orderDon.getStatus())
|
|
|
|
|
- .set(OrderDon::getTransactionId, orderDon.getTransactionId())
|
|
|
|
|
- .eq(OrderDon::getStatus, noPayment)
|
|
|
|
|
- .eq(OrderDon::getId, orderDon.getId()));
|
|
|
|
|
- if (isSuccess) {
|
|
|
|
|
- //更新车位情况
|
|
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
|
|
- //更新座位信息
|
|
|
|
|
- updateGroupsTicket(orderDon, goodsDon, sku);
|
|
|
|
|
- updateById(orderDon);
|
|
|
|
|
- return orderDon.getStatus();
|
|
|
|
|
|
|
+ private OrderDon.Status updateNoPayment(OrderDon orderDon, GoodsDon goodsDon) {
|
|
|
|
|
+ GoodsDonSku sku = null;
|
|
|
|
|
+ if (orderDon.getSkuId() != null) {
|
|
|
|
|
+ sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
}
|
|
}
|
|
|
- return noPayment;
|
|
|
|
|
|
|
+ unifiedHandlerOrderNotify(orderDon, goodsDon, sku);
|
|
|
|
|
+ return orderDon.getStatus();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void checkIsSameUser(Long relationUserId, Long userId, String openId, String loginPhone) {
|
|
public void checkIsSameUser(Long relationUserId, Long userId, String openId, String loginPhone) {
|
|
@@ -1994,8 +1913,53 @@ 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) {
|
|
|
BigDecimal first_money = orderDon.getMoney();
|
|
BigDecimal first_money = orderDon.getMoney();
|
|
|
|
|
+ //礼品卡现金支付 不参与其他优惠
|
|
|
|
|
+ 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, true);
|
|
|
|
|
+ deductCash = BigDecimal.ZERO;
|
|
|
|
|
+ } else if (remainCash.compareTo(deductCash) < 0) {
|
|
|
|
|
+ deductGiftCardCash(user.getId(), giftCard.getId(), remainCash, remainCash, gcUseRecords, true);
|
|
|
|
|
+ deductCash = deductCash.subtract(remainCash);
|
|
|
|
|
+ } else if (remainCash.compareTo(deductCash) > 0) {
|
|
|
|
|
+ deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords, false);
|
|
|
|
|
+ deductCash = BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ orderDon.setMoney(orderDon.getMoney().subtract(gcCash));
|
|
|
|
|
+ orderDon.setGcCash(gcCash);
|
|
|
|
|
+ if (!gcUseRecords.isEmpty()) {
|
|
|
|
|
+ orderDon.setGcUseRecords(gcUseRecords);
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
//存在优惠券
|
|
//存在优惠券
|
|
|
if (couponUser != null) {
|
|
if (couponUser != null) {
|
|
|
Long couponId = couponUser.getCouponId();
|
|
Long couponId = couponUser.getCouponId();
|
|
@@ -2077,13 +2041,19 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon.getIsNoLogin()) {
|
|
if (orderDon.getIsNoLogin()) {
|
|
|
orderDon.setExCode(exchangeCodeService.getExCode(goodsId, orderDon.getSkuId(), 1));
|
|
orderDon.setExCode(exchangeCodeService.getExCode(goodsId, orderDon.getSkuId(), 1));
|
|
|
}
|
|
}
|
|
|
- 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);
|
|
|
|
|
-
|
|
|
|
|
- if (orderDon.getIsNoLogin()) {
|
|
|
|
|
- orderDon.setStatus(OrderDon.Status.hasPayment);
|
|
|
|
|
|
|
+ GoodsDonSku sku = null;
|
|
|
|
|
+ if (orderDon.getSkuId() != null) {
|
|
|
|
|
+ sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
}
|
|
}
|
|
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
|
|
+ unifiedHandlerOrderNotify(orderDon, goodsDon, sku);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 统一订单信息回调
|
|
|
|
|
+ */
|
|
|
|
|
+ public void unifiedHandlerOrderNotify(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku) {
|
|
|
|
|
+ orderDon.setStatus(goodsDon.getType() == 1 && goodsDon.getSecondType() == 2 ? OrderDon.Status.complete : OrderDon.Status.hasPayment);
|
|
|
boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
boolean isSuccess = update(Wrappers.lambdaUpdate(OrderDon.class)
|
|
|
.set(OrderDon::getStatus, orderDon.getStatus())
|
|
.set(OrderDon::getStatus, orderDon.getStatus())
|
|
|
.in(OrderDon::getStatus, List.of(OrderDon.Status.noPayment, OrderDon.Status.close))
|
|
.in(OrderDon::getStatus, List.of(OrderDon.Status.noPayment, OrderDon.Status.close))
|
|
@@ -2092,34 +2062,39 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
log.info("支付宝回调商家订单号:{}订单状态已修改", orderDon.getOrderNo());
|
|
log.info("支付宝回调商家订单号:{}订单状态已修改", orderDon.getOrderNo());
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (!orderDon.getIsNoLogin()) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (orderDon.getIsNoLogin()) {
|
|
|
|
|
+ orderDon.setStatus(OrderDon.Status.hasPayment);
|
|
|
|
|
+ }
|
|
|
|
|
+ Long goodsId = goodsDon.getId();
|
|
|
|
|
+ if (!orderDon.getIsNoLogin() && sku != null) {
|
|
|
//更新座位信息
|
|
//更新座位信息
|
|
|
updateGroupsTicket(orderDon, goodsDon, sku);
|
|
updateGroupsTicket(orderDon, goodsDon, sku);
|
|
|
- if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0 && orderDon.getIsDistribute()) {
|
|
|
|
|
- TASK_POOL.execute(() -> distributeWaitingSendPointsRecord(orderDon));
|
|
|
|
|
- }
|
|
|
|
|
if (goodsDon.getType() == 1) {
|
|
if (goodsDon.getType() == 1) {
|
|
|
//无车队,新增车队
|
|
//无车队,新增车队
|
|
|
checkNoGroupsTripsAndSendMsg(sku, orderDon);
|
|
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);
|
|
handleServiceRenewOrder(orderDon);
|
|
|
}
|
|
}
|
|
|
- //购买Midjourney课程 赠送Midjourney车票
|
|
|
|
|
- if (goodsId != null && goodsId.equals(27l)) {
|
|
|
|
|
- orderDon.setStatus(OrderDon.Status.complete);
|
|
|
|
|
- TASK_POOL.execute(() -> sendMidjourneyTicketIfCourse(orderDon.getUserId()));
|
|
|
|
|
- }
|
|
|
|
|
this.updateById(orderDon);
|
|
this.updateById(orderDon);
|
|
|
- //配置了特定奖池,增加抽奖机会
|
|
|
|
|
- TASK_POOL.execute(() -> {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ TASK_POOL.execute(()->{
|
|
|
try {
|
|
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());
|
|
marketFrontService.addSpecificChanceNum(orderDon.getUserId(), orderDon.getId(), orderDon.getGoodsId(), orderDon.getSkuId());
|
|
|
if (goodsDon.getType() == 2) {
|
|
if (goodsDon.getType() == 2) {
|
|
|
equipmentDistributeService.addDistributeBenefitsChance(orderDon.getUserId(), orderDon.getId());
|
|
equipmentDistributeService.addDistributeBenefitsChance(orderDon.getUserId(), orderDon.getId());
|
|
@@ -2128,9 +2103,147 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (StrUtil.isNotBlank(orderDon.getCouponExCode())) {
|
|
if (StrUtil.isNotBlank(orderDon.getCouponExCode())) {
|
|
|
addDistributeCouponCode(orderDon.getUserId(), orderDon.getCouponExCode());
|
|
addDistributeCouponCode(orderDon.getUserId(), orderDon.getCouponExCode());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //礼品卡
|
|
|
|
|
+ if (goodsDon.getSpecialType() != null && goodsDon.getSpecialType() == GoodsDon.SpecialType.giftCard) {
|
|
|
|
|
+ //礼品卡购买记录
|
|
|
|
|
+ GiftCardOrderRelate giftCardOrderRelate = giftCardOrderRelateMapper.selectOne(Wrappers.lambdaQuery(GiftCardOrderRelate.class)
|
|
|
|
|
+ .eq(GiftCardOrderRelate::getOrderId, orderDon.getId())
|
|
|
|
|
+ .eq(GiftCardOrderRelate::getIsPay, false).last("limit 1"));
|
|
|
|
|
+ if (giftCardOrderRelate != null) {
|
|
|
|
|
+ log.info("该订单:{}是礼品卡类型", orderDon.getId());
|
|
|
|
|
+ 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) {
|
|
} catch (Exception e) {
|
|
|
- log.error("zfb增加抽奖机会错误,orderId:{},error:{}", orderDon.getId(), e);
|
|
|
|
|
|
|
+ log.error("回调修改订单信息错误,orderId:{},error:{}", orderDon.getId(), StringUtil.getErrorText(e));
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ TASK_POOL.execute(()->{
|
|
|
|
|
+ try {
|
|
|
|
|
+ orderDonPostService.postData((orderDon.getId()));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("回传错误 {}",StringUtil.getErrorText(e));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ //虚拟物品购买推送电报消息
|
|
|
|
|
+ if(goodsDon.getType() == 1){
|
|
|
|
|
+ TASK_POOL.execute(()->{
|
|
|
|
|
+ sendTelegramMsg(orderDon, goodsDon);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void sendTelegramMsg(OrderDon orderDon, GoodsDon goodsDon) {
|
|
|
|
|
+ if(!redisService.hasKey(RedisKey.TELEGRAM_BOT_MSG)){
|
|
|
|
|
+ TelegramBotMsgReq msgReq = new TelegramBotMsgReq();
|
|
|
|
|
+ msgReq.setGoodsName(goodsDon.getTitle());
|
|
|
|
|
+ User user = userMapper.selectById(orderDon.getUserId());
|
|
|
|
|
+ msgReq.setName(user.getNickname());
|
|
|
|
|
+ GroupsRelation groupsRelation = groupsRelationMapper.selectById(orderDon.getRelationId());
|
|
|
|
|
+ long day = DateUtil.betweenDay(new Date(), groupsRelation.getExpiryTime(),true);
|
|
|
|
|
+ if(day > 1000){
|
|
|
|
|
+ day = 365;
|
|
|
|
|
+ }
|
|
|
|
|
+ msgReq.setDay(day);
|
|
|
|
|
+ msgReq.setNumber(groupsRelation.getNum() >= 10 ? RandomUtil.randomInt(10) + 1 : groupsRelation.getNum());
|
|
|
|
|
+ try {
|
|
|
|
|
+ telegramService.sendMsg(msgReq);
|
|
|
|
|
+ redisService.set(RedisKey.TELEGRAM_BOT_MSG,1, 60L * 3L);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("发送电报推送消息错误 msg:{}",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 isUsed) {
|
|
|
|
|
+ Boolean is_update = giftCardUserRecordService.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
|
|
|
|
|
+ .set(GiftCardUserRecord::getRemainCash, gcRemainCash.subtract(deductCash))
|
|
|
|
|
+ .set(isUsed, GiftCardUserRecord::getIsUsed, isUsed)
|
|
|
|
|
+ .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(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);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollUtil.isNotEmpty(gcUserPayRecords)) {
|
|
|
|
|
+ giftCardUserRecordService.saveBatch(gcUserPayRecords);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.info("用户userId:{}礼品订单orderId:{}支付成功,记录购买成功记录错误,e:{}", orderDon.getUserId(), orderDon.getId(), StringUtil.getErrorText(e));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|