zoujiajian il y a 2 ans
Parent
commit
fa88df42f0

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/OrderDonLocationRelateMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.OrderDonLocationRelate;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: OrderDonLocationRelateMapper
+ * 创建者: JavaZou
+ * 创建时间:2024/4/10 15:50
+ */
+public interface OrderDonLocationRelateMapper extends BaseMapper<OrderDonLocationRelate> {
+}

+ 9 - 1
netflix-dao/src/main/java/com/cyksj/model/entity/OrderDon.java

@@ -2,6 +2,7 @@ package com.cyksj.model.entity;
 
 import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
+import com.ejlchina.searcher.bean.DbIgnore;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 import lombok.Setter;
@@ -51,6 +52,13 @@ public class OrderDon extends BaseEntity implements Serializable {
     /** 金额 */
     private BigDecimal money ;
 
+    /**
+     * 加购商品金额
+     */
+    @TableField(exist = false)
+    @DbIgnore
+    private BigDecimal dpMoney;
+
     /**
      * 货币单位
      */
@@ -242,7 +250,7 @@ public class OrderDon extends BaseEntity implements Serializable {
 
     private String payTitle;
 
-    public enum Status {
+	public enum Status {
         /**
          * 订单状态
          */

+ 24 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/OrderDonLocationRelate.java

@@ -0,0 +1,24 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: OrderDonLocationRelate
+ * 创建者: JavaZou
+ * 创建时间:2024/4/10 15:49
+ */
+@Getter
+@Setter
+public class OrderDonLocationRelate extends BaseEntity{
+	private Long orderId;
+
+	private String ip;
+
+	private String country;
+
+	private String province;
+
+	private String city;
+}

+ 66 - 19
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -148,6 +148,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 
 	private final GroupsRelationNetflixService groupsRelationNetflixService;
 
+	private final OrderDonLocationRelateMapper orderDonLocationRelateMapper;
+
 	@Transactional(rollbackFor = Throwable.class)
 	@Override
 	public OrderDon submit(OrderPayRequest payRequest) throws Exception {
@@ -199,7 +201,35 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		if (sku.getPrice() == null || sku.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
 			throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("sku_price_error"));
 		}
-		if (payRequest.getDonMoney().compareTo(sku.getPrice()) < 0) {
+
+		//是否是特定价格 且是否满足
+		Boolean isSpecificPrice = Optional.ofNullable(payRequest.getIsSpecificPrice()).orElse(false);
+		String specificGoodsIds = null;
+		BigDecimal specificPrice = BigDecimal.ZERO;
+		if (isSpecificPrice) {
+			specificGoodsIds = sku.getSpecificGoodsIds();
+			if (StrUtil.isEmpty(specificGoodsIds)) {
+				throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("sys_error"));
+			}
+			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(I18nMessageUtil.getI18nMsg("sys_error"));
+			}
+			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 (sku != null && payRequest.getDonMoney().compareTo(sku.getPrice()) < 0 && !isSpecificPrice) {
 			log.info("规格:{}支付金额:{}异常,调整用户userId:{}支付金额为:{}", sku.getSpecVal(), payRequest.getDonMoney(), user.getId(), sku.getPrice());
 			payRequest.setDonMoney(sku.getPrice());
 		}
@@ -211,9 +241,6 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		orderDon.setRate(payRequest.getRate());
 		List<Long> dpSkuIds = payRequest.getDpSkuIds();
 		if (CollUtil.isNotEmpty(dpSkuIds)) {
-			if (dpSkuIds.size() > 1) {
-				throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("dp_one_goods_pay_error"));
-			}
 			//是否满足关联
 			List<GoodsDiscountPlusPurchaseRelation> ds_relations = discountPlusPurchaseRelationMapper.selectList(Wrappers.lambdaQuery(GoodsDiscountPlusPurchaseRelation.class)
 					.eq(GoodsDiscountPlusPurchaseRelation::getSkuId, sku.getId())
@@ -226,6 +253,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			for (GoodsDiscountPlusPurchaseRelation re : ds_relations) {
 				goods_discount_plus_pay = goods_discount_plus_pay.add(re.getDisPrice());
 				dsSkuIds.add(re.getDisSid());
+				orderDon.setDpMoney(goods_discount_plus_pay);
 			}
 			BigDecimal pay_money = sku.getPrice().add(goods_discount_plus_pay);
 			if (pay_money.compareTo(orderDon.getMoney()) > 0) {
@@ -260,21 +288,8 @@ 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(I18nMessageUtil.getI18nMsg("sys_error"));
-			}
-			dp_skuViewList.forEach(dp_SkuView -> {
-				payTitle.append(" + ");
-				payTitle.append(dp_SkuView.getGoodsTitle());
-				payTitle.append(dp_SkuView.getSpecVal());
-			});
-		}
-		orderDon.setPayTitle(payTitle.toString());
+		//设置订单支付商品信息
+		setOrderDonPayTile(orderDon, goodsDon, sku, dpSkuIds);
 		if ("TWD".equals(payRequest.getCurrency())){
 			orderDon.setMoney(orderDon.getMoney().setScale(-2, RoundingMode.HALF_UP));
 		}
@@ -316,6 +331,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			}
 		}
 		orderDon.setSpecialType(goodsDon.getSpecialType());
+		//记录订单ip关联
+		recordOrderDonLocationRelate(orderDon.getId(), payRequest.getIp());
 		return orderDon;
 	}
 
@@ -1169,4 +1186,34 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			userBenefitsService.recordBalanceBySource(orderDon.getUserId(), orderDon.getBalance().negate(), UserBalanceSourceRecord.Source.payment, orderDon.getId(), goodsDon.getTitle() + UserBalanceSourceRecord.Source.payment.getDesc());
 		}
 	}
+
+	/**
+	 * 设置订单支付商品属性
+	 */
+	public void setOrderDonPayTile(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku, List<Long> dpSkuIds) {
+		StringBuilder payTitle = new StringBuilder();
+		payTitle.append(goodsDon.getTitle());
+		if (sku != null) {
+			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());
+	}
+
+	private void recordOrderDonLocationRelate(Long orderId, String ip) {
+		OrderDonLocationRelate orderDonLocationRelate = new OrderDonLocationRelate();
+		orderDonLocationRelate.setOrderId(orderId);
+		orderDonLocationRelate.setIp(ip);
+		orderDonLocationRelateMapper.insert(orderDonLocationRelate);
+	}
 }