|
@@ -0,0 +1,155 @@
|
|
|
|
|
+package org.springblade.gateway.web_gateway.controller;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
|
+import org.springblade.common.cache.PaymentCache;
|
|
|
|
|
+import org.springblade.common.enums.*;
|
|
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
|
|
+import org.springblade.gateway.client_gateway.entity.dto.ClientTradeDto;
|
|
|
|
|
+import org.springblade.ldt.bills.entity.WithdrawRec;
|
|
|
|
|
+import org.springblade.ldt.bills.service.IWithdrawRecService;
|
|
|
|
|
+import org.springblade.ldt.shop.entity.Shop;
|
|
|
|
|
+import org.springblade.ldt.shop.service.IShopService;
|
|
|
|
|
+import org.springblade.ldt.user.entity.LoginUser;
|
|
|
|
|
+import org.springblade.ldt.user.service.ILoginUserService;
|
|
|
|
|
+import org.springblade.payment.entity.SuccessParams;
|
|
|
|
|
+import org.springblade.payment.event.UserPayCsEvent;
|
|
|
|
|
+import org.springblade.payment.event.UserPayEvent;
|
|
|
|
|
+import org.springblade.payment.event.UserWithdrawEvent;
|
|
|
|
|
+import org.springblade.payment.handle.Trade;
|
|
|
|
|
+import org.springblade.payment.handle.entity.Order;
|
|
|
|
|
+import org.springblade.yeePay.common.YeePayConst;
|
|
|
|
|
+import org.springblade.yeePay.common.YeepayApiConstant;
|
|
|
|
|
+import org.springframework.context.ApplicationEventPublisher;
|
|
|
|
|
+import org.springframework.util.Assert;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author July
|
|
|
|
|
+ * @version 1.0.0
|
|
|
|
|
+ * @ClassName WithdrawPressureTestController.java
|
|
|
|
|
+ * @Description 提现压测控制层
|
|
|
|
|
+ * @createTime 2021年10月30日 09:49:00
|
|
|
|
|
+ */
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/pressure_test")
|
|
|
|
|
+@AllArgsConstructor
|
|
|
|
|
+public class PressureTestController {
|
|
|
|
|
+
|
|
|
|
|
+ private IWithdrawRecService withdrawRecService;
|
|
|
|
|
+ private IShopService shopService;
|
|
|
|
|
+ private YeePayConst yeePayConst;
|
|
|
|
|
+ private ApplicationEventPublisher eventPublisher;
|
|
|
|
|
+ private ILoginUserService loginUserService;
|
|
|
|
|
+ private Trade trade;
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/userBalanceWithdraw")
|
|
|
|
|
+ @ApiOperation(value = "用户余额提现(结算)")
|
|
|
|
|
+ public R userBalanceWithdraw() {
|
|
|
|
|
+ //保存提现数据
|
|
|
|
|
+ WithdrawRec withdrawRec = new WithdrawRec();
|
|
|
|
|
+ withdrawRec.setType(WithdrawType.BALANCE_WITHDRAW);
|
|
|
|
|
+ withdrawRec.setReceiveType(YeepayApiConstant.receiveType.REAL_TIME.name());
|
|
|
|
|
+ withdrawRec.setPrice(BigDecimal.ONE);
|
|
|
|
|
+ withdrawRec.setOwnerType(AppConstant.USER_TYPE.商户.name());
|
|
|
|
|
+ withdrawRec.setOwnerId(1440871712886366210L);
|
|
|
|
|
+ withdrawRec.setWithdrawStatus(WithdrawStatus.WAITING.getValue());
|
|
|
|
|
+ withdrawRec.setFee(BigDecimal.ZERO);
|
|
|
|
|
+ withdrawRec.setReceiveAmount(withdrawRec.getPrice().subtract(withdrawRec.getFee()));
|
|
|
|
|
+ withdrawRec.setFailReason("测试数据");
|
|
|
|
|
+ withdrawRecService.saveOrUpdate(withdrawRec);
|
|
|
|
|
+ //模拟易宝请求
|
|
|
|
|
+ return R.data(simulationUserBalanceWithdraw(withdrawRec.getId()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 模拟用户余额提现
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param withdrawRecId 提现id
|
|
|
|
|
+ */
|
|
|
|
|
+ private R simulationUserBalanceWithdraw(Long withdrawRecId) {
|
|
|
|
|
+ WithdrawRec withdrawRec = withdrawRecService.getById(withdrawRecId);
|
|
|
|
|
+ cn.hutool.core.lang.Assert.notNull(withdrawRec, "提现申请查询失败,无此申请信息!");
|
|
|
|
|
+
|
|
|
|
|
+ Shop shop = shopService.getOne(Wrappers.<Shop>lambdaQuery().select(Shop::getMerchantNo).eq(Shop::getId, withdrawRec.getOwnerId()));
|
|
|
|
|
+ cn.hutool.core.lang.Assert.notNull(shop, "提现申请查询失败,无此申请商户信息!");
|
|
|
|
|
+
|
|
|
|
|
+ String settleRequestNo = IdUtil.simpleUUID();
|
|
|
|
|
+ withdrawRec.setRequestNo(settleRequestNo);
|
|
|
|
|
+ withdrawRecService.updateById(withdrawRec);
|
|
|
|
|
+
|
|
|
|
|
+ //支付参数
|
|
|
|
|
+ SuccessParams successParams = SuccessParams.builder()
|
|
|
|
|
+ .orderType(OrderType.USER_WITHDRAW.name())
|
|
|
|
|
+ .status(WithdrawStatus.WAITING.getValue())
|
|
|
|
|
+ .userId(withdrawRec.getOwnerId())
|
|
|
|
|
+ .totalPrice(withdrawRec.getActualPrice())
|
|
|
|
|
+ .shopId(withdrawRec.getOwnerId())
|
|
|
|
|
+ .tenantId(withdrawRec.getTenantId())
|
|
|
|
|
+ .withdrawRecId(withdrawRec.getId())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ JSONObject res = JSONObject.parseObject("{\n" +
|
|
|
|
|
+ " \"settleRequestNo\":\"" + settleRequestNo + "\",\n" +
|
|
|
|
|
+ " \"settleAmount\":\"" + withdrawRec.getReceiveAmount() + "\",\n" +
|
|
|
|
|
+ " \"feeAmount\":\"0.0\",\n" +
|
|
|
|
|
+ " \"settleStatus\":\"SUCCESS \",\n" +
|
|
|
|
|
+ " \"message\":\"\"\n" +
|
|
|
|
|
+ "}");
|
|
|
|
|
+ successParams.setRes(res);
|
|
|
|
|
+ PaymentCache.putSuccessParams(Convert.toStr(settleRequestNo), successParams);
|
|
|
|
|
+
|
|
|
|
|
+ eventPublisher.publishEvent(new UserWithdrawEvent(successParams));
|
|
|
|
|
+ return R.data(res);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/scanPay")
|
|
|
|
|
+ public R scanPay() {
|
|
|
|
|
+ ClientTradeDto clientTradeDto = new ClientTradeDto();
|
|
|
|
|
+ clientTradeDto.setUserId(1432597234212978690L);
|
|
|
|
|
+ clientTradeDto.setAppId("wx9ad53e8c83ae1a51");
|
|
|
|
|
+ clientTradeDto.setBillsTitle("用户扫码支付");
|
|
|
|
|
+ clientTradeDto.setExpireTime(LocalDateTime.now());
|
|
|
|
|
+ clientTradeDto.setMoney(BigDecimal.ONE);
|
|
|
|
|
+ clientTradeDto.setOpenId("ocWnO5eEuHMhl7RV_ebnp_Ff9A0M");
|
|
|
|
|
+ clientTradeDto.setShopId(1440871712886366210L);
|
|
|
|
|
+ LoginUser loginUser = loginUserService.getById(clientTradeDto.getUserId());
|
|
|
|
|
+ Assert.notNull(loginUser, () -> {
|
|
|
|
|
+ throw new ServiceException(ResCode.USER_NOT_FOUNT);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ //处理订单
|
|
|
|
|
+ Order order = Order.builder()
|
|
|
|
|
+ .appId(clientTradeDto.getAppId())
|
|
|
|
|
+ .billsTitle(clientTradeDto.getBillsTitle())
|
|
|
|
|
+ .loginUser(loginUser)
|
|
|
|
|
+ .money(clientTradeDto.getMoney())
|
|
|
|
|
+ .expireTime(clientTradeDto.getExpireTime())
|
|
|
|
|
+ .secret(clientTradeDto.getSecret())
|
|
|
|
|
+ .shopId(clientTradeDto.getShopId())
|
|
|
|
|
+ .openId(loginUser.getOpenid())
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ SuccessParams successParams = null;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ successParams = trade.tradeForScanPay(order, clientTradeDto.getChannelId());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new ServiceException(ResCode.TRADE_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ eventPublisher.publishEvent(UserPayEvent.class);
|
|
|
|
|
+ eventPublisher.publishEvent(UserPayCsEvent.class);
|
|
|
|
|
+ return R.data(successParams);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|