Browse Source

fix 分销提现按情况进行提现

zoujiajian 3 years ago
parent
commit
46f18bf83f

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/request/ApplyMoneyReq.java

@@ -18,4 +18,9 @@ public class ApplyMoneyReq {
 	private DistributeMoneyApply.Type type;
 
 	private String realName;
+
+	/**
+	 * true提现所有积分金额
+	 */
+	private Boolean isTakeAll;
 }

+ 44 - 37
netflix-web/src/main/java/com/cyksj/web/controller/user/DistributePopularizeController.java

@@ -206,7 +206,7 @@ public class DistributePopularizeController {
 	@NoSubmit
 	@PostMapping("/post/applyMoney")
 	@Transactional(rollbackFor = Throwable.class)
-	public Result<String> applyMoney(@RequestBody ApplyMoneyReq applyMoneyReq) throws Exception {
+	public Result<DistributeMoneyApply> applyMoney(@RequestBody ApplyMoneyReq applyMoneyReq) throws Exception {
 		Long userId = StpUserUtil.getLoginIdAsLong();
 		User user = userMapper.selectById(userId);
 		if (user == null) {
@@ -215,58 +215,65 @@ public class DistributePopularizeController {
 		if (ObjectUtil.hasEmpty(applyMoneyReq.getAccount(), applyMoneyReq.getRealName())) {
 			throw BusinessRuntimeException.getInstance("必填项不能为空");
 		}
+		Boolean isTakeAll = applyMoneyReq.getIsTakeAll();
+		BigDecimal userPoints = user.getPoints();
 		DistributePointsExchangeMoney distributePointsExchangeMoney = distributePointsExchangeMoneyMapper.selectOne(Wrappers.lambdaQuery(DistributePointsExchangeMoney.class).orderByDesc(DistributePointsExchangeMoney::getPoints).last("limit 1"));
 		BigDecimal minPoints = BigDecimal.valueOf(distributePointsExchangeMoney.getMinPoints());
-		BigDecimal min = BigDecimal.valueOf(distributePointsExchangeMoney.getPoints());
-		if (user.getPoints().compareTo(minPoints) < 0) {
+		BigDecimal ratePoints = BigDecimal.valueOf(distributePointsExchangeMoney.getPoints());
+		BigDecimal minMoney = distributePointsExchangeMoney.getMoney();
+		if (userPoints.compareTo(minPoints) < 0) {
 			throw BusinessRuntimeException.getInstance("您当前积分未达到积分门槛,无法提现");
 		}
-		//今日是否已提现
-		DistributeMoneyApply apply = distributeMoneyApplyMapper.selectOne(Wrappers.lambdaQuery(DistributeMoneyApply.class).eq(DistributeMoneyApply::getUserId, userId).between(DistributeMoneyApply::getCreatedTime, DateUtil.beginOfDay(DateTime.now()), DateUtil.endOfDay(DateTime.now())).last("limit 1"));
-		if (apply != null) {
-			throw BusinessRuntimeException.getInstance("今日已提现,请明日再进行操作");
-		}
-		BigDecimal num = user.getPoints().divide(min, RoundingMode.DOWN);
-		BigDecimal points = min.multiply(num);
-		//门槛金额是分
-		BigDecimal money = num.multiply(distributePointsExchangeMoney.getMoney());
+//		//今日是否已提现
+//		DistributeMoneyApply apply = distributeMoneyApplyMapper.selectOne(Wrappers.lambdaQuery(DistributeMoneyApply.class).eq(DistributeMoneyApply::getUserId, userId).between(DistributeMoneyApply::getCreatedTime, DateUtil.beginOfDay(DateTime.now()), DateUtil.endOfDay(DateTime.now())).last("limit 1"));
+//		if (apply != null) {
+//			throw BusinessRuntimeException.getInstance("今日已提现,请明日再进行操作");
+//		}
+		BigDecimal num = userPoints.divide(ratePoints, RoundingMode.DOWN);
+		BigDecimal needApplyMoney = num.multiply(minMoney);
+		BigDecimal needSubPoints = num.multiply(ratePoints);
 		BigDecimal fourHundred = BigDecimal.valueOf(4 * 100 * 100);
-		if (money.compareTo(fourHundred) > 0) {
-			money = fourHundred;
-			points = fourHundred.divide(distributePointsExchangeMoney.getMoney()).multiply(min);
+		if (isTakeAll == null || !isTakeAll) {
+			if (needApplyMoney.compareTo(fourHundred) > 0) {
+				needApplyMoney = fourHundred;
+				needSubPoints = fourHundred.divide(minMoney).multiply(ratePoints);
+			}
 		}
-		Integer update = userMapper.subPoints(user.getId(), points);
+		Integer update = userMapper.subPoints(user.getId(), needSubPoints);
 		if (update == 1) {
-			TransferAccountsReq req = new TransferAccountsReq();
-			req.setMoney(money);
-			req.setAccount(applyMoneyReq.getAccount());
-			req.setName(applyMoneyReq.getRealName());
-			req.setPoints(points);
-			req.setUserId(userId);
-
 			DistributeMoneyApply distributeMoneyApply = new DistributeMoneyApply();
 			distributeMoneyApply.setUserId(userId);
-			distributeMoneyApply.setPoints(points);
-			distributeMoneyApply.setMoney(money);
+			distributeMoneyApply.setPoints(needSubPoints);
+			distributeMoneyApply.setMoney(needApplyMoney);
 			distributeMoneyApply.setAccount(applyMoneyReq.getAccount());
 			distributeMoneyApply.setRealName(applyMoneyReq.getRealName());
-			AlipayResponse alipayResponse = orderService.transferAccounts(req);
-			if (alipayResponse.isSuccess()) {
-				distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.success);
+			if (isTakeAll != null && isTakeAll) {
+				distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.verifying);
 			} else {
-				distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.fail);
-				distributeMoneyApply.setReason(alipayResponse.getSubMsg());
-				while (true) {
-					User db = userMapper.selectById(userId);
-					Integer success = userMapper.updatePoints(user.getId(), db.getPoints(), distributeMoneyApply.getPoints());
-					if (success == 1) {
-						break;
+				TransferAccountsReq req = new TransferAccountsReq();
+				req.setMoney(needApplyMoney);
+				req.setAccount(applyMoneyReq.getAccount());
+				req.setName(applyMoneyReq.getRealName());
+				req.setPoints(needSubPoints);
+				req.setUserId(userId);
+				AlipayResponse alipayResponse = orderService.transferAccounts(req);
+				if (alipayResponse.isSuccess()) {
+					distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.success);
+				} else {
+					distributeMoneyApply.setVerifyStatus(DistributeMoneyApply.Status.fail);
+					distributeMoneyApply.setReason(alipayResponse.getSubMsg());
+					while (true) {
+						User db = userMapper.selectById(userId);
+						Integer success = userMapper.updatePoints(user.getId(), db.getPoints(), distributeMoneyApply.getPoints());
+						if (success == 1) {
+							break;
+						}
 					}
+					return GatewayResponse.FAIL.newBuilder().setMsg(alipayResponse.getSubMsg()).toResult();
 				}
-				return GatewayResponse.FAIL.newBuilder().setMsg(alipayResponse.getSubMsg()).toResult();
 			}
 			distributeMoneyApplyMapper.insert(distributeMoneyApply);
-			return GatewayResponse.SUCCESS.newBuilder().toResult(distributeMoneyApply.getMoney().toString());
+			return GatewayResponse.SUCCESS.newBuilder().toResult(distributeMoneyApply);
 		}
 		throw BusinessRuntimeException.getInstance("系统异常,请重新提交提现申请");
 	}