|
|
@@ -34,6 +34,7 @@ import com.cyksj.model.request.AlipayOrderDonReq;
|
|
|
import com.cyksj.model.request.OrderAttach;
|
|
|
import com.cyksj.service.pay.AliPayCommonService;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -126,36 +127,35 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
|
|
|
Long orderId = re.getOrderId();
|
|
|
String returnUrl = re.getReturnUrl();
|
|
|
OrderDon orderDon = orderDonMapper.selectById(orderId);
|
|
|
+ Boolean isWebPay = orderDon.getIsWebPay();
|
|
|
+ if (ZfbProductCode.PC_WEB.getProductCode().equals(productCode)) {
|
|
|
+ orderDon.setIsWebPay(true);
|
|
|
+ }
|
|
|
+ if (ZfbProductCode.MOBILE_WEB.getProductCode().equals(productCode)) {
|
|
|
+ orderDon.setIsWebPay(false);
|
|
|
+ }
|
|
|
String appId = orderDon.getShopId();
|
|
|
if (StrUtil.isEmpty(appId)) {
|
|
|
- if (orderDon.getPopularizeId() != null) {
|
|
|
- ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(), "zfb");
|
|
|
- if (shopConfig != null) {
|
|
|
- appId = shopConfig.getAppId();
|
|
|
- }
|
|
|
- }
|
|
|
- //排除推广链接
|
|
|
- if (StrUtil.isEmpty(appId)) {
|
|
|
- //获取每日订单限制 支付宝商户
|
|
|
- ZfbShopOrderDayLimit dayLimit = getZfbShopOrdersDayLimit(orderDon.getGoodsId());
|
|
|
- if (dayLimit == null) {
|
|
|
- //获取支付宝默认商户
|
|
|
- appId = sysConfigService.getDefaultShopConfigByType("zfb");
|
|
|
- } else {
|
|
|
- appId = dayLimit.getAppId();
|
|
|
- }
|
|
|
+ appId = getZfbDayLimitShopId(orderDon);
|
|
|
+ }
|
|
|
+ //若切换支付环境
|
|
|
+ if (StrUtil.isNotBlank(orderDon.getShopId()) && isWebPay != orderDon.getIsWebPay()) {
|
|
|
+ //当前支付宝商户 不支持所有环境 使用默认支付宝
|
|
|
+ ZfbShopOrderDayLimit dayLimit = zfbShopOrderDayLimitMapper.selectOne(Wrappers.lambdaQuery(ZfbShopOrderDayLimit.class)
|
|
|
+ .eq(ZfbShopOrderDayLimit::getAppId, orderDon.getShopId())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (dayLimit != null && dayLimit.getScope() != 0) {
|
|
|
+ appId = sysConfigService.getDefaultShopConfigByType("zfb");
|
|
|
+ //恢复支付宝每日限单数
|
|
|
+ zfbShopOrderDayLimitMapper.incrDayLimitRemainOrders(orderDon.getShopId());
|
|
|
+ //恢复小时限单数
|
|
|
+ zfbShopOrderDayLimitMapper.incrHourLimitRemainOrders(orderDon.getShopId());
|
|
|
}
|
|
|
}
|
|
|
if (OrderDon.Type.ALI_PAY != orderDon.getType()) {
|
|
|
orderDon.setType(OrderDon.Type.ALI_PAY);
|
|
|
}
|
|
|
orderDon.setShopId(appId);
|
|
|
- if (ZfbProductCode.PC_WEB.getProductCode().equals(productCode)) {
|
|
|
- orderDon.setIsWebPay(true);
|
|
|
- }
|
|
|
- if (ZfbProductCode.MOBILE_WEB.getProductCode().equals(productCode)) {
|
|
|
- orderDon.setIsWebPay(false);
|
|
|
- }
|
|
|
orderDonMapper.updateById(orderDon);
|
|
|
String notifyPath = BaseZfbConfig.notifyUrl;
|
|
|
Boolean isUserBenefits = re.getIsUserBenefits();
|
|
|
@@ -209,7 +209,7 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
|
|
|
return aliPayParams;
|
|
|
}
|
|
|
|
|
|
- private ZfbShopOrderDayLimit getZfbShopOrdersDayLimit(Long goodsId) {
|
|
|
+ private ZfbShopOrderDayLimit getZfbShopOrdersDayLimit(Long goodsId, List<Integer> scope) {
|
|
|
int hour = DateUtil.hour(DateTime.now(), true);
|
|
|
//如果是ai订单 不分配给善缘
|
|
|
Integer aiCount = goodsDonCategoryRelateMapper.selectCount(Wrappers.lambdaQuery(GoodsDonCategoryRelate.class)
|
|
|
@@ -221,6 +221,7 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
|
|
|
.gt(ZfbShopOrderDayLimit::getDayRemainOrders, 0)
|
|
|
.gt(ZfbShopOrderDayLimit::getHourRemainOrders, 0)
|
|
|
.eq(ZfbShopOrderDayLimit::getStatus, 1)
|
|
|
+ .in(ZfbShopOrderDayLimit::getScope, scope)
|
|
|
.ne(aiCount > 0, ZfbShopOrderDayLimit::getAppId, Constant.SY_SHOP_ID));
|
|
|
if (orderDayLimits.isEmpty()) {
|
|
|
return null;
|
|
|
@@ -526,4 +527,31 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
|
|
|
notifyUrl,
|
|
|
returnUrl);
|
|
|
}
|
|
|
+
|
|
|
+ public String getZfbDayLimitShopId(OrderDon orderDon) {
|
|
|
+ String appId = orderDon.getShopId();
|
|
|
+ if (orderDon.getPopularizeId() != null) {
|
|
|
+ ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(), "zfb");
|
|
|
+ if (shopConfig != null) {
|
|
|
+ appId = shopConfig.getAppId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Integer> scope = Lists.newArrayList(0);
|
|
|
+ //是否是PC的端支付
|
|
|
+ if (orderDon.getIsWebPay()) {
|
|
|
+ scope.add(1);
|
|
|
+ } else scope.add(2);
|
|
|
+ //排除推广链接
|
|
|
+ if (StrUtil.isEmpty(appId)) {
|
|
|
+ //获取每日订单限制 支付宝商户
|
|
|
+ ZfbShopOrderDayLimit dayLimit = getZfbShopOrdersDayLimit(orderDon.getGoodsId(), scope);
|
|
|
+ if (dayLimit == null) {
|
|
|
+ //获取支付宝默认商户
|
|
|
+ appId = sysConfigService.getDefaultShopConfigByType("zfb");
|
|
|
+ } else {
|
|
|
+ appId = dayLimit.getAppId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return appId;
|
|
|
+ }
|
|
|
}
|