|
@@ -1,6 +1,7 @@
|
|
|
package org.springblade.modules.api.controller;
|
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.api.*;
|
|
|
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
|
|
@@ -9,6 +10,7 @@ import com.alipay.api.domain.Participant;
|
|
|
import com.alipay.api.internal.util.AlipaySignature;
|
|
|
import com.alipay.api.request.*;
|
|
|
import com.alipay.api.response.*;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import com.ijpay.core.kit.PayKit;
|
|
@@ -30,6 +32,8 @@ import org.springblade.core.tool.utils.StringUtil;
|
|
|
import org.springblade.modules.finance.entity.Order;
|
|
|
import org.springblade.modules.finance.entity.OrderConsign;
|
|
|
import org.springblade.modules.finance.entity.OrderGrant;
|
|
|
+import org.springblade.modules.finance.entity.PlatformAuthorization;
|
|
|
+import org.springblade.modules.finance.mapper.PlatformAuthorizationMapper;
|
|
|
import org.springblade.modules.finance.pay.entity.AlipayProperties;
|
|
|
import org.springblade.modules.finance.service.IOrderConsignService;
|
|
|
import org.springblade.modules.finance.service.IOrderGrantService;
|
|
@@ -44,13 +48,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@RestController
|
|
|
@AllArgsConstructor
|
|
@@ -66,6 +69,9 @@ public class AliPay01Controller {
|
|
|
//预授权
|
|
|
private static final String NOTIFY_URL = "/api/v1/aliPay/sdk/auth_notify_url";
|
|
|
|
|
|
+ //平台付款预授权
|
|
|
+ private static final String PLATFORM_URL = "/api/v1/aliPay/sdk/platform_authorization_notify_url";
|
|
|
+
|
|
|
//抢购
|
|
|
private static final String TRADE_URL = "/api/v1/aliPay/sdk/trade_notify_url";
|
|
|
|
|
@@ -84,6 +90,9 @@ public class AliPay01Controller {
|
|
|
private final IOrderConsignService orderConsignService;
|
|
|
private final IConsignService consignService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private PlatformAuthorizationMapper paMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private BladeLogger logger;
|
|
|
|
|
@@ -123,9 +132,9 @@ public class AliPay01Controller {
|
|
|
request.setBizModel(model);
|
|
|
request.setNotifyUrl(properties.getDomain() + ORDER_URL);
|
|
|
try {
|
|
|
- //这里和普通的接口调用不同,使用的是sdkExecute
|
|
|
- //普通模式 使用 execute
|
|
|
- //证书使用 使用 sdkExecute
|
|
|
+// 这里和普通的接口调用不同,使用的是sdkExecute
|
|
|
+// 普通模式 使用 execute
|
|
|
+// 证书使用 使用 sdkExecute
|
|
|
AlipayTradeAppPayResponse response = client.sdkExecute(request);
|
|
|
return R.data(response.getBody());
|
|
|
} catch (AlipayApiException e ) {
|
|
@@ -136,6 +145,7 @@ public class AliPay01Controller {
|
|
|
return R.fail("该支付方式暂不支持!");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@ApiLog("绑定订单-预授权")
|
|
|
@PostMapping("/pay_002")
|
|
|
@ApiOperation(value = "统一收单交易支付接口", notes = "预授权")
|
|
@@ -229,7 +239,7 @@ public class AliPay01Controller {
|
|
|
@ApiParam(value = "数量", required = true) @RequestParam Integer num) throws AlipayApiException {
|
|
|
UserApp userApp = new UserApp();
|
|
|
UserApp query = userApp.selectOne(Wrappers.<UserApp>lambdaQuery().eq(UserApp::getUserId,userId));
|
|
|
- if (Objects.isNull(query)){
|
|
|
+ if (ObjectUtil.isNull(query)){
|
|
|
return R.fail("该用户不存在!");
|
|
|
}
|
|
|
if (query.getEnableAuth() != 2){
|
|
@@ -247,7 +257,7 @@ public class AliPay01Controller {
|
|
|
return R.fail("该账号已冻结!");
|
|
|
}
|
|
|
Consign consign = consignService.queryConsign(batNo, userId);
|
|
|
- if (Objects.isNull(consign)){
|
|
|
+ if (ObjectUtil.isNull(consign)){
|
|
|
return R.fail("亲,好物已抢完欢迎再来!");
|
|
|
}
|
|
|
//判断用户是否在该场次下有预授权
|
|
@@ -256,9 +266,12 @@ public class AliPay01Controller {
|
|
|
.eq(OrderGrant::getUserId, userId)
|
|
|
.eq(OrderGrant::getStatus,1)
|
|
|
);
|
|
|
- if (!Objects.isNull(orderGrant)){
|
|
|
+ if(ObjectUtil.isNotNull(orderGrant)){
|
|
|
return R.fail("您已发起预授权,无需再次发起!");
|
|
|
}
|
|
|
+// if (!ObjectUtil.isNull(orderGrant)){
|
|
|
+// return R.fail("您已发起预授权,无需再次发起!");
|
|
|
+// }
|
|
|
JSONObject data = new JSONObject();
|
|
|
String orderNo = CommonUtil.genTimeID();
|
|
|
data.put("out_order_no", orderNo);
|
|
@@ -449,6 +462,105 @@ public class AliPay01Controller {
|
|
|
return R.status(param.updateById());
|
|
|
}
|
|
|
|
|
|
+ @ApiLog("平台付款预授权回调")
|
|
|
+ @RequestMapping(value = "/platform_authorization_notify_url", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
+ @ApiOperation(value = "异步通知相应-预授回调", notes = "异步通知相应")
|
|
|
+ public void platformAuthorizationNotify(HttpServletRequest request){
|
|
|
+ String errMsg = "预授回调";
|
|
|
+ logger.info(errMsg, request.getParameterMap().toString());
|
|
|
+ if (!NotifyUtils.rsaCheck(properties, request.getParameterMap())) {
|
|
|
+ //这里处理验签失败
|
|
|
+ log.info(errMsg + "-处理验签失败");
|
|
|
+ }
|
|
|
+ String status = request.getParameter("status");
|
|
|
+ String auth_no = request.getParameter("auth_no");
|
|
|
+ if (!"SUCCESS".equals(status)){
|
|
|
+ log.info(errMsg + "-预授权失败");
|
|
|
+ }
|
|
|
+ String out_request_no = request.getParameter("out_request_no");
|
|
|
+ LambdaQueryWrapper<PlatformAuthorization> query = Wrappers.lambdaQuery(PlatformAuthorization.class);
|
|
|
+ query.eq(PlatformAuthorization::getOrderNo, out_request_no);
|
|
|
+ PlatformAuthorization platformAuthorization = paMapper.selectOne(query);
|
|
|
+ if(ObjectUtil.isNotNull(platformAuthorization)){
|
|
|
+ platformAuthorization.setAuthNo(auth_no);
|
|
|
+ platformAuthorization.setState(1);
|
|
|
+ paMapper.updateById(platformAuthorization);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起支付宝预授权
|
|
|
+ *
|
|
|
+ * 1、判断用户是否能抢购
|
|
|
+ * 2、查询是否有寄售/进货单
|
|
|
+ * 3、发起支付宝预支付
|
|
|
+ * 4、请求成功 创建预支付订单 默认为未授权
|
|
|
+ * @param userId 用户id
|
|
|
+ * @param batNo 批次ID
|
|
|
+ * @param price 金额
|
|
|
+ * @param num 预授数量
|
|
|
+ * @return R
|
|
|
+ * @throws AlipayApiException
|
|
|
+ */
|
|
|
+ @ApiLog("发起支付宝预授权")
|
|
|
+ @PostMapping("/platfromAuth")
|
|
|
+ @ApiOperation(value = "线上资金授权冻结接口-调用支付宝预授权", notes = "支付请求")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ public R<String> platfromAuth(@ApiParam(value = "用户号", required = true) @RequestParam Long userId,
|
|
|
+ @ApiParam(value = "批次ID", required = true) @RequestParam Long batNo,
|
|
|
+ @ApiParam(value = "金额", required = true) @RequestParam BigDecimal price,
|
|
|
+ @ApiParam(value = "数量", required = true) @RequestParam Integer num) throws AlipayApiException {
|
|
|
+ UserApp userApp = new UserApp();
|
|
|
+ UserApp query = userApp.selectOne(Wrappers.<UserApp>lambdaQuery().eq(UserApp::getUserId,userId));
|
|
|
+ if (ObjectUtil.isNull(query)){
|
|
|
+ return R.fail("该用户不存在!");
|
|
|
+ }
|
|
|
+ if (query.getEnableAuth() != 2){
|
|
|
+ double k = (double)query.getCreditScore() / 100;
|
|
|
+ int scoreCount = NumberUtil.roundDown(k, 2).intValue();
|
|
|
+ int consignCount = Integer.parseInt(ParamCache.getValue(CommonConstant.DEFAULT_CONDIGN_COUNT));
|
|
|
+ if (scoreCount > consignCount){
|
|
|
+ scoreCount = consignCount;
|
|
|
+ }
|
|
|
+ if (scoreCount < num){
|
|
|
+ return R.fail("预授数量不能大于单场可抢次数!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(query.getState() != 1 ){
|
|
|
+ return R.fail("该账号已冻结!");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ String orderNo = CommonUtil.genTimeID();
|
|
|
+ data.put("out_order_no", orderNo);
|
|
|
+ data.put("out_request_no", orderNo);
|
|
|
+ data.put("order_title","预授权冻结");
|
|
|
+ data.put("amount", price.multiply(new BigDecimal(num)));
|
|
|
+ data.put("product_code","PRE_AUTH_ONLINE"); //销售产品码。支付宝预授权产品固定为 PRE_AUTH_ONLINE
|
|
|
+ data.put("payee_user_id", properties.getPayeeUserId());
|
|
|
+ data.put("timeout_express","30m");
|
|
|
+ //APP支付
|
|
|
+ AlipayFundAuthOrderAppFreezeRequest request = new AlipayFundAuthOrderAppFreezeRequest();
|
|
|
+ request.setNotifyUrl(properties.getDomain() + PLATFORM_URL); //异步通知地址
|
|
|
+ request.setBizContent(data.toJSONString()); //业务参数
|
|
|
+ //APP支付
|
|
|
+ //必须使用 sdkExecute
|
|
|
+ AlipayFundAuthOrderAppFreezeResponse response = client.sdkExecute(request);
|
|
|
+ if(response.isSuccess()){
|
|
|
+ PlatformAuthorization platformAuthorization = new PlatformAuthorization();
|
|
|
+ platformAuthorization.setConsignConfigId(batNo);//场次id
|
|
|
+ platformAuthorization.setTotalNum(num);//授权数量
|
|
|
+ platformAuthorization.setState(0);//未授权
|
|
|
+ platformAuthorization.setOrderNo(orderNo);//订单编号
|
|
|
+ platformAuthorization.setAuthPrice(price.multiply(new BigDecimal(num)).setScale(2, BigDecimal.ROUND_DOWN));//订单金额
|
|
|
+ platformAuthorization.setCreateTime(new Date());
|
|
|
+ paMapper.insert(platformAuthorization);
|
|
|
+ return R.data(response.getBody());
|
|
|
+ }
|
|
|
+ return R.fail("授权失败!");
|
|
|
+ }
|
|
|
+
|
|
|
@ApiLog("预授回调")
|
|
|
@RequestMapping(value = "/auth_notify_url", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
@ApiOperation(value = "异步通知相应-预授回调", notes = "异步通知相应")
|
|
@@ -544,7 +656,7 @@ public class AliPay01Controller {
|
|
|
String out_trade_no = request.getParameter("out_trade_no");//获取请求参数中的商户订单号
|
|
|
log.info(errMsg, "out_trade_no == " + out_trade_no);
|
|
|
Order order = orderService.getOne(Wrappers.<Order>lambdaQuery().eq(Order::getOutTradeNo, out_trade_no));
|
|
|
- if (Objects.isNull(order)){
|
|
|
+ if (ObjectUtil.isNull(order)){
|
|
|
log.info(errMsg + "-订单无数据");
|
|
|
return "error";
|
|
|
}
|
|
@@ -552,7 +664,7 @@ public class AliPay01Controller {
|
|
|
log.info(errMsg, "寄售订单 == " + order.getOrderType());
|
|
|
//查询寄售订单信息
|
|
|
OrderConsign orderConsign = orderConsignService.getOne(Wrappers.<OrderConsign>lambdaQuery().eq(OrderConsign::getOutTradeNo, out_trade_no));
|
|
|
- if (Objects.isNull(orderConsign)){
|
|
|
+ if (ObjectUtil.isNull(orderConsign)){
|
|
|
log.info(errMsg + "-寄售订单无数据");
|
|
|
return "error";
|
|
|
}
|
|
@@ -560,7 +672,7 @@ public class AliPay01Controller {
|
|
|
Double price = orderConsign.getConsignPrice();
|
|
|
//查询寄售订单中的寄售人
|
|
|
Consign consign = consignService.getOne(Wrappers.<Consign>lambdaQuery().eq(Consign::getId, orderConsign.getConsignId()));
|
|
|
- if (Objects.isNull(consign)){
|
|
|
+ if (ObjectUtil.isNull(consign)){
|
|
|
log.info(errMsg + "-寄售无数据");
|
|
|
return "error";
|
|
|
}
|