Jelajahi Sumber

微信认证更新

lianghanqiang 4 tahun lalu
induk
melakukan
5ac8999d7c

+ 5 - 1
ldt-core/src/main/java/org/springblade/flow/shop/task/QueryAuthStatus.java

@@ -182,6 +182,7 @@ public class QueryAuthStatus {
 	 * */
 	private void notifyUserTask(AuthInfoData item, JSONObject resObj) {
 		Audit audit = auditService.getById(Convert.toLong(item.getVariables().get("auditId")));
+		Shop shop = shopService.getById(audit.getEntityId());
 		BladeFlow bladeFlow = new BladeFlow();
 		bladeFlow.setAssignee("$INITIATOR");
 		bladeFlow.setProcessInstanceId(audit.getProcessInstanceId());
@@ -193,7 +194,10 @@ public class QueryAuthStatus {
 		String authUrl = resObj.getString("qrcodeUrl");
 		variables.put("qrcodeUrl", UrlTransform.cheakUrl(authUrl));
 		taskService.setVariables(task.getTaskId(),variables);
-
+		shop.setAuditStatus(ShopEnum.WAITING_AUTH.name());
+		audit.setAuditStatus(ShopEnum.WAITING_AUTH.name());
+		shopService.saveOrUpdate(shop);
+		auditService.saveOrUpdate(audit);
 	}
 
 

+ 0 - 5
ldt-core/src/main/java/org/springblade/flow/shop/task/WechatApplyTask.java

@@ -85,11 +85,6 @@ public class WechatApplyTask implements JavaDelegate {
 			queryAuthStatus.applyReject(authInfoData,resObj.toJSONString());
 		}else {
 			FlowCache.addAuthMember(authInfoData);
-
-			shop.setAuditStatus(ShopEnum.WAITING_AUTH.name());
-			audit.setAuditStatus(ShopEnum.WAITING_AUTH.name());
-			shopService.saveOrUpdate(shop);
-			auditService.saveOrUpdate(audit);
 		}
 	}
 

+ 1 - 1
ldt-core/src/main/java/org/springblade/gateway/shop_gateway/controller/ShopTradeController.java

@@ -75,7 +75,7 @@ public class ShopTradeController {
 
 
 		try {
-			trade.tradeForPayCode(order,codeOrder.getChannelId());
+			trade.tradeForScanPay(order,codeOrder.getChannelId());
 		} catch (Exception e) {
 			e.printStackTrace();
 			throw  new ServiceException(ResCode.TRADE_ERROR);

+ 68 - 63
ldt-core/src/main/java/org/springblade/payment/callback/trade/UserPayCS.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.AllArgsConstructor;
+import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import org.springblade.common.enums.AppConstant;
 import org.springblade.common.enums.OrderType;
@@ -71,6 +72,7 @@ public class UserPayCS {
 	private IMallService mallService;
 
 
+
 	@EventListener
 	@Async
 	public void   PaySuccess(UserPayCsEvent userPayCsEvent) {
@@ -79,65 +81,67 @@ public class UserPayCS {
 		try {
 			//获取对应交易的积分账单、余额账单、支付账单以及交易用户
 			LoginUser user = loginUserService.getById(successParams.getBills().getPayId());
+			synchronized(user.getId()){
+				Bills bills = billsService.getById(successParams.getBills().getId());
+				//回调已处理,忽略后续回调
+				if (!Objects.equals(bills.getPayStatus(), AppConstant.BillPayStatus.付款成功.name())){
+					return;
+				}
 
-			Bills bills = billsService.getById(successParams.getBills().getId());
-			//回调已处理,忽略后续回调
-			if (!Objects.equals(bills.getPayStatus(), AppConstant.BillPayStatus.付款成功.name())){
-				return;
-			}
-
-			//记录第三方支付平台订单号
-			bills.setThirdOrderId(successParams.getThirdOrderId());
-
-			PointBills pointBills = Objects.isNull(successParams.getPointBillsId()) ? null : pointBillsService.getById(successParams.getPointBillsId());
-			BalanceBills balanceBills = Objects.isNull(successParams.getBalanceBillsId()) ? null : balanceBillsService.getById(successParams.getBalanceBillsId());
-			//获取渠道积分收取的服务费
-			BigDecimal pointBillFee = Optional.ofNullable(pointBills)
-				.map(PointBills::getFee).orElse(BigDecimal.ZERO);
-			//获取积分余额收取的服务费
-			BigDecimal balanceBillFee = Optional.ofNullable(balanceBills)
-				.map(BalanceBills::getFee).orElse(BigDecimal.ZERO);
-			//获取支付平台收取的服务费
-			BigDecimal merchantFee = BigDecimal.ZERO;
-			BigDecimal ypSettleAmount = BigDecimal.ZERO;
-
-			if(!Objects.isNull(successParams.getRes())){
-				ypSettleAmount = successParams.getRes().getBigDecimal("ypSettleAmount");
-				merchantFee = successParams.getRes().getBigDecimal("merchantFee");
-				bills.setMerchantFee(merchantFee);
-				bills.setReceiveNumYp(ypSettleAmount);
-				bills.setReceiveNumTotal(bills.getBalanceNum().add(bills.getPointNum().add(ypSettleAmount)));
-				if (Objects.isNull(bills.getReceiveNumTotal())) {
-					bills.setActualIncome(bills.getCost());
-				}else{
-					bills.setActualIncome(bills.getReceiveNumTotal());
+				//记录第三方支付平台订单号
+				bills.setThirdOrderId(successParams.getThirdOrderId());
+
+				PointBills pointBills = Objects.isNull(successParams.getPointBillsId()) ? null : pointBillsService.getById(successParams.getPointBillsId());
+				BalanceBills balanceBills = Objects.isNull(successParams.getBalanceBillsId()) ? null : balanceBillsService.getById(successParams.getBalanceBillsId());
+				//获取渠道积分收取的服务费
+				BigDecimal pointBillFee = Optional.ofNullable(pointBills)
+					.map(PointBills::getFee).orElse(BigDecimal.ZERO);
+				//获取积分余额收取的服务费
+				BigDecimal balanceBillFee = Optional.ofNullable(balanceBills)
+					.map(BalanceBills::getFee).orElse(BigDecimal.ZERO);
+				//获取支付平台收取的服务费
+				BigDecimal merchantFee = BigDecimal.ZERO;
+				BigDecimal ypSettleAmount = BigDecimal.ZERO;
+
+				if(!Objects.isNull(successParams.getRes())){
+					ypSettleAmount = successParams.getRes().getBigDecimal("ypSettleAmount");
+					merchantFee = successParams.getRes().getBigDecimal("merchantFee");
+					bills.setMerchantFee(merchantFee);
+					bills.setReceiveNumYp(ypSettleAmount);
+					bills.setReceiveNumTotal(bills.getBalanceNum().add(bills.getPointNum().add(ypSettleAmount)));
+					if (Objects.isNull(bills.getReceiveNumTotal())) {
+						bills.setActualIncome(bills.getCost());
+					}else{
+						bills.setActualIncome(bills.getReceiveNumTotal());
+					}
 				}
+
+				//账单的总积分服务费
+				bills.setPointFee(balanceBillFee.add(pointBillFee));
+				//账单的总收取的价格(商品价格 + 国信服务费 +积分服务费)
+				BigDecimal totalPrice = bills.getCost().add(bills.getPointFee()).add(Optional.ofNullable(bills.getFee()).orElse(BigDecimal.ZERO));
+				bills.setTotalPrice(totalPrice);
+
+				//获取待更新的各类型信息
+				List<TenantEntity> tenantEntities = handlePointBills(pointBills, user);
+				UserChannelPoint channelPoint = (UserChannelPoint) tenantEntities.get(1);
+				pointBills = (PointBills) tenantEntities.get(0);
+				balanceBills = handleBalanceBills(balanceBills, user);
+				bills.setPayStatus(AppConstant.BillPayStatus.已完结.name());
+				Shop shop = updateShopBalance(bills,ypSettleAmount);
+
+				List<TenantEntity> handleSendPointBills = handleSendPointBills(channelPoint,bills, user);
+				PointBills sendPointBills = (PointBills) handleSendPointBills.get(0);
+				UserChannelPoint sendUserChanelPoint = (UserChannelPoint) handleSendPointBills.get(1);
+				Member mallMember = (Member) handleSendPointBills.get(2);
+				//更新信息
+				updateStatus(channelPoint,pointBills,bills,user,shop,balanceBills,sendPointBills,sendUserChanelPoint,mallMember);
+
+				//通知处理代理费,申请分账
+				successParams.setBills(bills);
+				applicationEventPublisher.publishEvent(new BillSuccessEvent(successParams));
 			}
 
-			//账单的总积分服务费
-			bills.setPointFee(balanceBillFee.add(pointBillFee));
-			//账单的总收取的价格(商品价格 + 国信服务费 +积分服务费)
-			BigDecimal totalPrice = bills.getCost().add(bills.getPointFee()).add(Optional.ofNullable(bills.getFee()).orElse(BigDecimal.ZERO));
-			bills.setTotalPrice(totalPrice);
-
-			//获取待更新的各类型信息
-			List<TenantEntity> tenantEntities = handlePointBills(pointBills, user, successParams.getChannelId());
-			UserChannelPoint channelPoint = (UserChannelPoint) tenantEntities.get(1);
-			pointBills = (PointBills) tenantEntities.get(0);
-			balanceBills = handleBalanceBills(balanceBills, user);
-			bills.setPayStatus(AppConstant.BillPayStatus.已完结.name());
-			Shop shop = updateShopBalance(bills,ypSettleAmount);
-
-			List<TenantEntity> handleSendPointBills = handleSendPointBills(bills, user);
-			PointBills sendPointBills = (PointBills) handleSendPointBills.get(0);
-			UserChannelPoint sendUserChanelPoint = (UserChannelPoint) handleSendPointBills.get(1);
-			Member mallMember = (Member) handleSendPointBills.get(2);
-			//更新信息
-			updateStatus(channelPoint,pointBills,bills,user,shop,balanceBills,sendPointBills,sendUserChanelPoint,mallMember);
-
-			//通知处理代理费,申请分账
-			successParams.setBills(bills);
-			applicationEventPublisher.publishEvent(new BillSuccessEvent(successParams));
 
 		} catch (Exception e) {
 			log.error("清算回调异常:");
@@ -218,10 +222,10 @@ public class UserPayCS {
 	 * 修改用户积分以及积分账单状态
 	 * @return
 	 */
-	private List<TenantEntity> handlePointBills(PointBills pointBills, LoginUser user, Long channelId) {
+	private List<TenantEntity> handlePointBills(PointBills pointBills, LoginUser user) {
 		UserChannelPoint channelPoint = null;
 		if(!Objects.isNull(pointBills)){
-			channelPoint = userChannelPointService.getById(channelId);
+			channelPoint = userChannelPointService.getById(pointBills.getChannelId());
 			channelPoint.setAvailable(channelPoint.getAvailable().subtract(pointBills.getPrice()).subtract(pointBills.getFee()));
 			user.setChannelPoint(user.getChannelPoint().subtract(pointBills.getPrice()).subtract(pointBills.getFee()));
 			pointBills.setPayStatus(AppConstant.BillPayStatus.付款成功.name());
@@ -245,17 +249,18 @@ public class UserPayCS {
 	 * 商场赠送用户积分
 	 * @return
 	 */
-	private List<TenantEntity> handleSendPointBills(Bills bills, LoginUser user) {
+	private List<TenantEntity> handleSendPointBills(UserChannelPoint userChannelPoint, Bills bills, LoginUser user) {
 		PointBills pointBills = pointBillsService.getOne(new QueryWrapper<PointBills>().lambda().eq(PointBills::getTradeNo, bills.getId()).eq(PointBills::getType,OrderType.MALL_SEND.name()));
-		UserChannelPoint userChannelPoint = null;
 		Member member = null;
 		if(!Objects.isNull(pointBills)){
 			user.setChannelPoint(user.getChannelPoint().add(pointBills.getPrice()));
-			userChannelPoint = userChannelPointService.getOne(new QueryWrapper<UserChannelPoint>().lambda()
-				.eq(UserChannelPoint::getUserId,user.getId())
-				.eq(UserChannelPoint::getChannelId, pointBills.getChannelId()));
 			if (Objects.isNull(userChannelPoint)) {
-				userChannelPoint = initUserChannelPoint(user, pointBills);
+				userChannelPoint = userChannelPointService.getOne(new QueryWrapper<UserChannelPoint>().lambda()
+					.eq(UserChannelPoint::getUserId,user.getId())
+					.eq(UserChannelPoint::getChannelId, pointBills.getChannelId()));
+				if(Objects.isNull(userChannelPoint)){
+					userChannelPoint = initUserChannelPoint(user, pointBills);
+				}
 			}
 			userChannelPoint.setTotalPoint(userChannelPoint.getTotalPoint().add(pointBills.getPrice()));
 			userChannelPoint.setAvailable(userChannelPoint.getAvailable().add(pointBills.getPrice()));

+ 55 - 55
ldt-core/src/main/java/org/springblade/payment/handle/Trade.java

@@ -43,61 +43,61 @@ public class Trade {
 	private IAppShopService appShopService;
 	private ApplicationEventPublisher applicationEventPublisher;
 
-
-	@Transactional
-	public boolean tradeForPayCode(Order order, long channelId) throws Exception {
-		/**
-		 * 	交易处理链,每个handle处理负责一个业务节点
-		 * 	1、处理各种商家折扣,计算实际交易金额
-		 * 	2、用户渠道积分用以抵消交易金额
-		 * 	3、用户账户余额抵消交易金额
-		 * 	4、剩余金额用户微信支付
-		 * */
-		List<BaseHandle> chain = new ArrayList(){{
-			add(discountHandle);
-			add(channelPointHandle);
-			add(balanceHandle);
-			add(wxPayHandle);
-		}} ;
-
-	 	BigDecimal remain = order.getMoney();
-
-		//获取tenantId
-		String tenantId = appShopService.getTenantId(order.getShopId());
-		Bills bills = initBill(order,channelId,tenantId);
-
-		//支付参数
-		SuccessParams successParams  = SuccessParams.builder()
-			.orderType(OrderType.USER_PAY.name())
-			.status(AppConstant.BillPayStatus.待付款.name())
-			.userId(order.getLoginUser().getId())
-			.totalPrice(order.getMoney())
-			.bills(bills)
-			.shopId(order.getShopId())
-			.tenantId(tenantId)
-			.channelId(channelId)
-			.build();
-
-		//处理各个节点
-		for (BaseHandle node: chain) {
-			HandleData res = node.handle(remain, order,successParams);
-			Assert.isTrue(res.isSuccess(),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
-			remain = res.getRemain();
-			successParams = res.getSuccessParams();
-
-			if(remain.compareTo(BigDecimal.ZERO)==0){
-				successParams.setStatus(AppConstant.BillPayStatus.付款成功.name());
-				dataHandle.saveOrUpdateEntity(billsService,successParams.getBills());
-				applicationEventPublisher.publishEvent(new UserPayCsEvent(successParams));
-				break;
-			}
-		}
-
-		//新建事务,保存订单信息,
-		Assert.isTrue(dataHandle.saveOrUpdateEntity(billsService,successParams.getBills()),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
-		PaymentCache.putSuccessParams(Convert.toStr(successParams.getBills().getId()),successParams);
-	 	return true;
-	}
+//
+//	@Transactional
+//	public boolean tradeForPayCode(Order order, long channelId) throws Exception {
+//		/**
+//		 * 	交易处理链,每个handle处理负责一个业务节点
+//		 * 	1、处理各种商家折扣,计算实际交易金额
+//		 * 	2、用户渠道积分用以抵消交易金额
+//		 * 	3、用户账户余额抵消交易金额
+//		 * 	4、剩余金额用户微信支付
+//		 * */
+//		List<BaseHandle> chain = new ArrayList(){{
+//			add(discountHandle);
+//			add(channelPointHandle);
+//			add(balanceHandle);
+//			add(wxPayHandle);
+//		}} ;
+//
+//	 	BigDecimal remain = order.getMoney();
+//
+//		//获取tenantId
+//		String tenantId = appShopService.getTenantId(order.getShopId());
+//		Bills bills = initBill(order,channelId,tenantId);
+//
+//		//支付参数
+//		SuccessParams successParams  = SuccessParams.builder()
+//			.orderType(OrderType.USER_PAY.name())
+//			.status(AppConstant.BillPayStatus.待付款.name())
+//			.userId(order.getLoginUser().getId())
+//			.totalPrice(order.getMoney())
+//			.bills(bills)
+//			.shopId(order.getShopId())
+//			.tenantId(tenantId)
+//			.channelId(channelId)
+//			.build();
+//
+//		//处理各个节点
+//		for (BaseHandle node: chain) {
+//			HandleData res = node.handle(remain, order,successParams);
+//			Assert.isTrue(res.isSuccess(),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
+//			remain = res.getRemain();
+//			successParams = res.getSuccessParams();
+//
+//			if(remain.compareTo(BigDecimal.ZERO)==0){
+//				successParams.setStatus(AppConstant.BillPayStatus.付款成功.name());
+//				dataHandle.saveOrUpdateEntity(billsService,successParams.getBills());
+//				applicationEventPublisher.publishEvent(new UserPayCsEvent(successParams));
+//				break;
+//			}
+//		}
+//
+//		//新建事务,保存订单信息,
+//		Assert.isTrue(dataHandle.saveOrUpdateEntity(billsService,successParams.getBills()),()->{throw new ServiceException(ResCode.TRADE_ERROR);});
+//		PaymentCache.putSuccessParams(Convert.toStr(successParams.getBills().getId()),successParams);
+//	 	return true;
+//	}
 
 	@Transactional
 	public SuccessParams tradeForScanPay(Order order, long channelId) throws Exception {

+ 2 - 2
ldt-core/src/main/java/org/springblade/payment/handle/handler/WxPayHandle.java

@@ -105,7 +105,7 @@ public class WxPayHandle implements BaseHandle {
 			sendBill.setTradeNo(bills.getId());
 			if (!Objects.isNull(shop)) {
 				BigDecimal sendNum = payNum.multiply(shop.getSendPointUnit());
-				BigDecimal sendPrice = sendNum.multiply(shop.getPointRate());
+				BigDecimal sendPrice = sendNum.multiply(shop.getPointRate()).setScale(2, BigDecimal.ROUND_FLOOR);
 				BigDecimal fee = sendPrice.multiply(pointFee);
 				sendBill.setPrice(sendPrice);
 				sendBill.setSendNum(sendNum);
@@ -144,7 +144,7 @@ public class WxPayHandle implements BaseHandle {
 			sendBill.setTradeNo(bills.getId());
 			if (!Objects.isNull(mall)) {
 				BigDecimal sendNum = payNum.multiply(mall.getSendPointUnnit());
-				BigDecimal sendPrice = sendNum.multiply(mall.getPointRate()).setScale(2, BigDecimal.ROUND_HALF_UP);
+				BigDecimal sendPrice = sendNum.multiply(mall.getPointRate()).setScale(2, BigDecimal.ROUND_FLOOR);
 				BigDecimal fee = sendPrice.multiply(pointFee);
 				sendBill.setSendNum(sendNum);
 				sendBill.setPrice(sendPrice);