|
|
@@ -87,10 +87,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
|
|
|
import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
|
@@ -202,6 +199,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
|
|
|
private final OrderDonPostService orderDonPostService;
|
|
|
|
|
|
+ private final GoodsDiscountPlusPurchaseRelationMapper discountPlusPurchaseRelationMapper;
|
|
|
+
|
|
|
+ private final OrderDiscountPlusPurchaseSkuRelationMapper orderDiscountPlusPurchaseSkuRelationMapper;
|
|
|
+
|
|
|
private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
|
|
|
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
@@ -244,18 +245,49 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
/* 生成订单 */
|
|
|
String donNo = SEQUENCE.nextId().toString();
|
|
|
OrderDon orderDon = new OrderDon();
|
|
|
+ orderDon.setIsDp(false);
|
|
|
if (isNoLogin != null && isNoLogin) {
|
|
|
orderDon.setIsNoLogin(true);
|
|
|
}
|
|
|
orderDon.setOrderNo(donNo);
|
|
|
orderDon.setOpenId(payOpenId);
|
|
|
- if (sku.getPrice() != null && payRequest.getDonMoney().compareTo(sku.getPrice()) < 0) {
|
|
|
+ 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());
|
|
|
orderDon.setRealMoney(payRequest.getDonMoney());
|
|
|
|
|
|
+ List<Long> dpSkuIds = payRequest.getDpSkuIds();
|
|
|
+ if (CollUtil.isNotEmpty(dpSkuIds)) {
|
|
|
+ if (dpSkuIds.size() > 1) {
|
|
|
+ throw BusinessRuntimeException.getInstance("暂只支持优惠加购一件商品");
|
|
|
+ }
|
|
|
+ //是否满足关联
|
|
|
+ List<GoodsDiscountPlusPurchaseRelation> ds_relations = discountPlusPurchaseRelationMapper.selectList(Wrappers.lambdaQuery(GoodsDiscountPlusPurchaseRelation.class)
|
|
|
+ .eq(GoodsDiscountPlusPurchaseRelation::getSkuId, sku.getId())
|
|
|
+ .in(GoodsDiscountPlusPurchaseRelation::getDisSid, dpSkuIds));
|
|
|
+ if (ds_relations.size() != dpSkuIds.size()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新下单");
|
|
|
+ }
|
|
|
+ BigDecimal goods_discount_plus_pay = BigDecimal.ZERO;
|
|
|
+ List<Long> dsSkuIds = new ArrayList<>();
|
|
|
+ for (GoodsDiscountPlusPurchaseRelation re : ds_relations) {
|
|
|
+ goods_discount_plus_pay = goods_discount_plus_pay.add(re.getDisPrice());
|
|
|
+ dsSkuIds.add(re.getDisSid());
|
|
|
+ }
|
|
|
+ BigDecimal pay_money = sku.getPrice().add(goods_discount_plus_pay);
|
|
|
+ if (pay_money.compareTo(orderDon.getMoney()) > 0) {
|
|
|
+ orderDon.setMoney(pay_money);
|
|
|
+ orderDon.setRealMoney(pay_money);
|
|
|
+ }
|
|
|
+ orderDon.setIsDp(true);
|
|
|
+ }
|
|
|
+
|
|
|
//渠道链接id
|
|
|
if (payRequest.getPopularizeId() != null) {
|
|
|
orderDon.setPopularizeId(payRequest.getPopularizeId());
|
|
|
@@ -298,8 +330,31 @@ 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 (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()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新下单");
|
|
|
+ }
|
|
|
+ dp_skuViewList.forEach(dp_SkuView -> {
|
|
|
+ payTitle.append(" + ");
|
|
|
+ payTitle.append(dp_SkuView.getGoodsTitle());
|
|
|
+ payTitle.append(dp_SkuView.getSpecVal());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ orderDon.setPayTitle(payTitle.toString());
|
|
|
this.saveOrUpdate(orderDon);
|
|
|
|
|
|
+ if (orderDon.getIsDp()) {
|
|
|
+ //保存订单优惠加购规格 关系
|
|
|
+ OrderDiscountPlusPurchaseSkuRelation orderDiscountPlusPurchaseSkuRelation = new OrderDiscountPlusPurchaseSkuRelation();
|
|
|
+ orderDiscountPlusPurchaseSkuRelation.setOrderId(orderDon.getId());
|
|
|
+ orderDiscountPlusPurchaseSkuRelation.setPlusSkuIds(dpSkuIds.toString());
|
|
|
+ orderDiscountPlusPurchaseSkuRelationMapper.insert(orderDiscountPlusPurchaseSkuRelation);
|
|
|
+ }
|
|
|
+
|
|
|
if (Constant.realGoodsType.contains(goodsDon.getType()) && !goodsDon.getId().equals(27l)) {
|
|
|
saveTransport(payRequest.getAddressId(), orderDon.getId());
|
|
|
}
|
|
|
@@ -1124,6 +1179,37 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
log.info("虚物订单orderNo:{}开始更新车票信息", order.getOrderNo());
|
|
|
//修改车位状态
|
|
|
GroupsRelation relation = groupsRelationMapper.selectById(order.getRelationId());
|
|
|
+ if (order.getIsDp()) {
|
|
|
+ //是否已经发送优惠加购车票
|
|
|
+ OrderDiscountPlusPurchaseSkuRelation purchaseSkuRelation = orderDiscountPlusPurchaseSkuRelationMapper.selectOne(Wrappers.lambdaQuery(OrderDiscountPlusPurchaseSkuRelation.class)
|
|
|
+ .eq(OrderDiscountPlusPurchaseSkuRelation::getOrderId, order.getId()));
|
|
|
+ if (purchaseSkuRelation != null) {
|
|
|
+ String plusSkuIdsStr = purchaseSkuRelation.getPlusSkuIds();
|
|
|
+ String relationIdsStr = purchaseSkuRelation.getRelationIds();
|
|
|
+ if (StrUtil.isNotEmpty(plusSkuIdsStr) && StrUtil.isEmpty(relationIdsStr)) {
|
|
|
+ try {
|
|
|
+ List<Long> plusSkuIds = Jsons.parseList(plusSkuIdsStr, Long.class);
|
|
|
+ //发送优惠加购 规格车票
|
|
|
+ List<Long> dis_relation_ids = new ArrayList<>();
|
|
|
+ plusSkuIds.forEach(plus_skuId -> {
|
|
|
+ GoodsDonSku plus_sku = goodsDonSkuMapper.selectById(plus_skuId);
|
|
|
+ if (plus_sku == null) {
|
|
|
+ log.error("订单id:{}优惠加购规格已被删除 skuId:{},车票未发送", order.getId(), plus_skuId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GroupsRelation relationNoOrder = exchangeCodeService.getRelationNoOrder(plus_sku, order.getUserId());
|
|
|
+ dis_relation_ids.add(relationNoOrder.getId());
|
|
|
+ });
|
|
|
+ //保存订单关联优惠加购车票
|
|
|
+ orderDiscountPlusPurchaseSkuRelationMapper.update(null, Wrappers.lambdaUpdate(OrderDiscountPlusPurchaseSkuRelation.class)
|
|
|
+ .set(OrderDiscountPlusPurchaseSkuRelation::getRelationIds, dis_relation_ids.toString())
|
|
|
+ .eq(OrderDiscountPlusPurchaseSkuRelation::getOrderId, order.getId())
|
|
|
+ .isNull(OrderDiscountPlusPurchaseSkuRelation::getRelationIds));
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if (order.getRelationId() != 0 && !relation.getUserId().equals(order.getUserId()) && order.getOrderType() == 1) {
|
|
|
GroupsRelation relationNoOrder = exchangeCodeService.getRelationNoOrder(sku, order.getUserId());
|
|
|
if (relationNoOrder == null) {
|