zoujiajian 1 год назад
Родитель
Сommit
50a9278f2f

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/GoodsWholesaleUserReturnRecordMapper.java

@@ -13,5 +13,5 @@ import java.util.List;
  * 创建时间:2024/8/28 11:40
  */
 public interface GoodsWholesaleUserReturnRecordMapper extends BaseMapper<GoodsWholesaleUserReturnRecord> {
-	GoodsWholesaleUserReturnRecord selectGoodsWholeReturnBalanceRecordByUserId(@Param("list") List<Long> userIdList);
+	GoodsWholesaleUserReturnRecord selectGoodsWholeReturnBalanceRecordByUserId(@Param("list") List<Long> userIdList, @Param("skuId") Long skuId);
 }

+ 1 - 0
netflix-dao/src/main/resources/mapper/GoodsWholesaleUserReturnRecordMapper.xml

@@ -8,6 +8,7 @@
         <foreach collection="list" item="item" open="(" separator="," close=")">
             #{item}
         </foreach>
+        and sku_id = #{skuId}
         order by num desc limit 1
     </select>
 </mapper>

+ 22 - 43
netflix-service/src/main/java/com/cyksj/service/order/impl/GoodsWholesalePayServiceImpl.java

@@ -130,6 +130,7 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
 		//余额支付
 		if (orderDon.getMoney().compareTo(BigDecimal.ZERO) == 0) {
 			orderDon.setStatus(GoodsWholesaleOrderDon.Status.hasPayment);
+			orderDon.setType(GoodsWholesaleOrderDon.Type.BALANCE);
 			orderDon.setPayTime(DateTime.now());
 		}
 		orderDon.setType(GoodsWholesaleOrderDon.Type.ALI_PAY);
@@ -212,60 +213,38 @@ public class GoodsWholesalePayServiceImpl implements GoodsWholesalePayService {
 			List<GoodsWholesale.GoodsWholesaleConfig> configs = Jsons.parseList(goodsWholesale.getConfig(), GoodsWholesale.GoodsWholesaleConfig.class);
 			GoodsWholesale.GoodsWholesaleConfig firstConfig = configs.get(0);
 			GoodsWholesale.GoodsWholesaleConfig endConfig = configs.get(configs.size() - 1);
-			//移除第一档
-			configs.remove(firstConfig);
-			//移除倒数第一档
-			configs.remove(endConfig);
 			//未超过第一档
 			if (payNum <= firstConfig.getEnd()) {
 				return;
 			}
-			GoodsWholesaleUserReturnRecord goodsWholesaleUserReturnRecord = goodsWholesaleUserReturnRecordMapper.selectGoodsWholeReturnBalanceRecordByUserId(userIdList);
-			//直接买到最高
-			Integer priceDifferNum = null;
-			BigDecimal differPrice = null;
-			if (payNum >= endConfig.getStart()) {
-				//将之前的全部返还余额差价
-				priceDifferNum = endConfig.getStart() - 1;
-				if (goodsWholesaleUserReturnRecord != null) {
-					//减去之前返差价的数目
-					priceDifferNum = priceDifferNum - goodsWholesaleUserReturnRecord.getNum();
-				}
-				differPrice = endConfig.getSingle().subtract(firstConfig.getSingle());
+			configs.remove(endConfig);
+			GoodsWholesaleUserReturnRecord goodsWholesaleUserReturnRecord = goodsWholesaleUserReturnRecordMapper.selectGoodsWholeReturnBalanceRecordByUserId(userIdList, skuId);
+			if (goodsWholesaleUserReturnRecord != null) {
+				log.info("用户:{}之前已返差价", orderDon.getUserId());
+				return;
 			}
-			if (goodsWholesaleUserReturnRecord != null && priceDifferNum == null) {
-				//寻找符合条件的目前挡位的配置
-				Optional<GoodsWholesale.GoodsWholesaleConfig> first = configs.stream().filter(config -> config.getStart() <= goodsWholesaleUserReturnRecord.getNum() && config.getEnd() >= goodsWholesaleUserReturnRecord.getNum()).collect(Collectors.toList()).stream().findFirst();
-				GoodsWholesale.GoodsWholesaleConfig thisLevel = first.get();
-				log.info("目前批发挡位设置是start:{} ======> end:{}", thisLevel.getStart(), thisLevel.getEnd());
-				priceDifferNum = thisLevel.getStart() - 1;
-				if (goodsWholesaleUserReturnRecord != null) {
-					priceDifferNum = priceDifferNum - goodsWholesaleUserReturnRecord.getNum();
+			//最高
+			if (payNum >= endConfig.getStart()) {
+				BigDecimal returnBalance = BigDecimal.ZERO;
+				for (GoodsWholesale.GoodsWholesaleConfig config : configs) {
+					Integer thisPayNum = config.getEnd() - config.getStart() + 1;
+					BigDecimal differPrice = config.getSingle().subtract(endConfig.getSingle());
+					returnBalance = returnBalance.add(BigDecimal.valueOf(thisPayNum).multiply(differPrice));
 				}
-				differPrice = thisLevel.getSingle().subtract(firstConfig.getSingle());
-			}
-			if (priceDifferNum != null && differPrice != null) {
-				BigDecimal returnBalance = differPrice.multiply(BigDecimal.valueOf(priceDifferNum));
-				log.info("返用户userId:{}批发余额:{}分", orderDon.getUserId(), returnBalance);
-				//记录返差价数量
-				GoodsWholesaleUserReturnRecord wholesaleUserReturnRecord = Optional.ofNullable(goodsWholesaleUserReturnRecord).orElseGet(() -> {
+				try {
+					log.info("用户:{}批发返skuId:{}差价", orderDon.getUserId(), skuId);
 					GoodsWholesaleUserReturnRecord newRecord = new GoodsWholesaleUserReturnRecord();
-					newRecord.setNum(0);
+					newRecord.setNum(endConfig.getStart() - 1);
 					newRecord.setGoodsId(orderDon.getGoodsId());
 					newRecord.setSkuId(orderDon.getSkuId());
-					newRecord.setReturnBalance(BigDecimal.ZERO);
+					newRecord.setReturnBalance(returnBalance);
 					newRecord.setUserId(orderDon.getUserId());
-					return newRecord;
-				});
-				wholesaleUserReturnRecord.setNum(wholesaleUserReturnRecord.getNum() + priceDifferNum);
-				wholesaleUserReturnRecord.setReturnBalance(wholesaleUserReturnRecord.getReturnBalance().add(returnBalance));
-				if (wholesaleUserReturnRecord.getId() != null) {
-					goodsWholesaleUserReturnRecordMapper.updateById(wholesaleUserReturnRecord);
-				} else {
-					goodsWholesaleUserReturnRecordMapper.insert(wholesaleUserReturnRecord);
+					goodsWholesaleUserReturnRecordMapper.insert(newRecord);
+					//返余额差价
+					userBenefitsService.addUserBalance(orderDon.getUserId(), returnBalance, UserBalanceSourceRecord.Source.wholesale_differ, 0l, orderDon.getId(), UserBalanceSourceRecord.Source.wholesale_differ.getDesc(), true);
+				} catch (Exception e) {
+					log.error("返用户:{}差价错误:{}", orderDon.getUserId(), StringUtil.getErrorText(e));
 				}
-				//返余额差价
-				userBenefitsService.addUserBalance(orderDon.getUserId(), returnBalance, UserBalanceSourceRecord.Source.wholesale_differ, 0l, orderDon.getId(), UserBalanceSourceRecord.Source.wholesale_differ.getDesc(), true);
 			}
 		}
 	}