zoujiajian hace 3 años
padre
commit
d56d7586d8

+ 1 - 4
netflix-dao/src/main/java/com/cyksj/mapper/AppleAutoRegisterDataMapper.java

@@ -26,9 +26,6 @@ public interface AppleAutoRegisterDataMapper extends BaseMapper<AppleAutoRegiste
 			" and rd.status = 'noPayment'")
 	Integer checkNoPayOrder(@Param("userId") long userId, @Param("countryOrArea") AppleAutoRegisterData.CountryOrArea countryOrArea);
 
-	@Select("select rd.id from apple_auto_register_data ad inner join register_order_don rd on rd.id = ad.order_id" +
-			" where ad.status = true" +
-			" and ad.user_id != 0" +
-			" and rd.status = 'noPayment' and rd.created_time <= #{newDate}")
+	@Select("select id from register_order_don where status = 'noPayment' and created_time <= #{newDate}")
 	List<Long> getAllNoPayOrders(Date newDate);
 }

+ 6 - 1
netflix-dao/src/main/java/com/cyksj/model/request/AlipayOrderDonReq.java

@@ -3,6 +3,7 @@ package com.cyksj.model.request;
 import lombok.Getter;
 import lombok.Setter;
 
+import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 
 /*
@@ -17,9 +18,13 @@ public class AlipayOrderDonReq {
 	@NotNull
 	private Long orderId;
 
+	/**
+	 *  1、手机网页支付 2、电脑网页支付
+	 */
+	@NotEmpty(message = "支付类型为空")
 	private Integer type;
 
-	private Integer payMode;
+	private String payMode;
 
 	private String returnUrl;
 }

+ 11 - 0
netflix-service/src/main/java/com/cyksj/config/zfb/BaseZfbConfig.java

@@ -51,4 +51,15 @@ public class BaseZfbConfig {
 	 * qr_pay_mode PC扫码支付的方式。订单码 默认4嵌入
 	 */
 	public static String qrPayMode_orderCode = "4";
+
+
+	/**
+	 * 支付宝手机支付
+	 */
+	public static String ONE_STR = "1";
+
+	/**
+	 * 支付网页支付
+	 */
+	public static String TWO_STR = "2";
 }

+ 4 - 14
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -68,6 +68,7 @@ import com.cyksj.service.market.MarketFrontService;
 import com.cyksj.service.market.task.TaskService;
 import com.cyksj.service.order.OrderCommonService;
 import com.cyksj.service.order.OrderDonService;
+import com.cyksj.service.pay.AliPayCommonService;
 import com.cyksj.service.relation.GroupRelationClearService;
 import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.sys.SysConfigService;
@@ -199,6 +200,8 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 
 	private final GroupsFuncService groupsFuncService;
 
+	private final AliPayCommonService aliPayCommonService;
+
 	private final List<String> noChekGoodsTemp = List.of("Apple One", "Youtube", "Spotify");
 
 	@Transactional(rollbackFor = Throwable.class)
@@ -718,20 +721,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 
 	@Override
 	public AliPayParams aliPay(Long orderId, String returnUrl, String productCode, String qrPayMode) throws Exception {
-		OrderDon orderDon = getById(orderId);
-		//获取支付宝默认商户
-		String appId = sysConfigService.getDefaultShopConfigByType("zfb");
-
-		if (orderDon.getPopularizeId() != null) {
-			ShopConfig shopConfig = shopConfigMapper.getByChannelPopularizeId(orderDon.getPopularizeId(), "zfb");
-			if (shopConfig != null) {
-				appId = shopConfig.getAppId();
-			}
-		}
-		orderDon.setType(OrderDon.Type.ALI_PAY);
-		orderDon.setShopId(appId);
-		this.updateById(orderDon);
-		return commonAliPay(orderId, returnUrl, productCode, appId, qrPayMode);
+		return aliPayCommonService.unifiedPay(orderId, productCode, qrPayMode, returnUrl);
 	}
 
 	@Override

+ 5 - 3
netflix-service/src/main/java/com/cyksj/service/pay/AliPayCommonService.java

@@ -1,5 +1,7 @@
 package com.cyksj.service.pay;
 
+import com.cyksj.model.dto.AliPayParams;
+
 /*
  *项目名: netflix
  *文件名: AliPayCommonService
@@ -10,11 +12,11 @@ public interface AliPayCommonService {
 	/**
 	 *
 	 * @param orderId
-	 * @param type 支付方式 1、手机网页支付 2、电脑网页支付
+	 * @param productCode 支付产品码
 	 * @param returnUrl
 	 * @return
 	 */
-	String unifiedPayRegister(Long orderId, Integer type, Integer payMode, String returnUrl) throws Exception;
+	AliPayParams unifiedPayRegister(Long orderId, String productCode, String payMode, String returnUrl) throws Exception;
 
-	String unifiedPay(Long orderId, Integer type, Integer payMode, String returnUrl, String productCode, String mode) throws Exception;
+	AliPayParams unifiedPay(Long orderId, String productCode, String payMode, String returnUrl) throws Exception;
 }

+ 9 - 16
netflix-service/src/main/java/com/cyksj/service/pay/impl/AliPayCommonServiceImpl.java

@@ -63,17 +63,9 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
 	private final SysConfigService sysConfigService;
 
 	@Override
-	public String unifiedPayRegister(Long orderId, Integer type, Integer payMode, String returnUrl) throws Exception {
+	public AliPayParams unifiedPayRegister(Long orderId, String productCode, String payMode, String returnUrl) throws Exception {
 		RegisterOrderDon orderDon = registerOrderDonMapper.selectById(orderId);
 		Assert.notNull(orderDon, "订单不存在");
-		if (type == null) throw BusinessRuntimeException.getInstance("请选择对应支付方式");
-		String productCode = StrUtil.EMPTY;
-		if (type == 1) {
-			productCode = ZfbProductCode.MOBILE_WEB.getProductCode();
-		}
-		if (type == 2) {
-			productCode = ZfbProductCode.PC_WEB.getProductCode();
-		}
 		if (StrUtil.isEmpty(productCode)) throw BusinessRuntimeException.getInstance("支付异常");
 		//获取支付宝默认商户
 		String shopId = sysConfigService.getDefaultShopConfigByType("zfb");
@@ -86,7 +78,7 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
 		//回调地址
 		String host = envCommonService.getHost();
 		String notifyUrl = String.format("%s%s", host, BaseZfbConfig.zfb_register_notify_url);
-		if (type == 2 && payMode == 2) {
+		if (ZfbProductCode.MOBILE_WEB.getProductCode().equals(productCode) && BaseZfbConfig.qrPayMode_redirect.equals(payMode)) {
 			returnUrl = String.format("%s%s", envCommonService.getDomain(), BaseZfbConfig.zfb_register_login_return_url);
 		}
 		String subject = "注册服务";
@@ -99,12 +91,11 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
 				String.valueOf(payMode),
 				notifyUrl,
 				returnUrl);
-		String body = aliPayParams.getBody();
-		return body;
+		return aliPayParams;
 	}
 
 	@Override
-	public String unifiedPay(Long orderId, Integer type, Integer payMode, String returnUrl, String productCode, String mode) throws Exception {
+	public AliPayParams unifiedPay(Long orderId, String payMode, String productCode, String returnUrl) throws Exception {
 		OrderDon orderDon = orderDonMapper.selectById(orderId);
 		//获取支付宝默认商户
 		String appId = sysConfigService.getDefaultShopConfigByType("zfb");
@@ -124,7 +115,7 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
 		//回调地址
 		String host = envCommonService.getHost();
 		String notifyUrl = String.format("%s%s", host, BaseZfbConfig.notifyUrl);
-		if (type == 2 && payMode == 2) {
+		if (ZfbProductCode.MOBILE_WEB.getProductCode().equals(productCode) && BaseZfbConfig.qrPayMode_redirect.equals(payMode)) {
 			returnUrl = String.format("%s%s", envCommonService.getDomain(), BaseZfbConfig.loginReturnUrl);
 		}
 		AliPayParams aliPayParams = builderPayParams(orderDon.getId(),
@@ -136,8 +127,7 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
 				String.valueOf(payMode),
 				notifyUrl,
 				returnUrl);
-		String body = aliPayParams.getBody();
-		return body;
+		return aliPayParams;
 	}
 
 	public AliPayParams builderPayParams(Long orderId, String shopId, BigDecimal money, Date orderCreatedTime, String subject, String productCode, String payMode, String notifyUrl, String returnUrl) throws Exception {
@@ -224,6 +214,9 @@ public class AliPayCommonServiceImpl implements AliPayCommonService {
 			alipayTradePagePayModel.setProductCode(productCode);
 			//5分钟订单失效时间
 			alipayTradePagePayModel.setTimeExpire(DateUtil.offsetMinute(orderCreatedTime, 5).toString());
+			if (StrUtil.isEmpty(qrPayMode)) {
+				qrPayMode = BaseZfbConfig.qrPayMode_orderCode;
+			}
 			alipayTradePagePayModel.setQrPayMode(qrPayMode);
 			alipayTradePagePayRequest.setBizModel(alipayTradePagePayModel);
 			return alipayTradePagePayRequest;

+ 2 - 1
netflix-service/src/main/java/com/cyksj/service/register/RegisterOrderDonService.java

@@ -2,6 +2,7 @@ package com.cyksj.service.register;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.cyksj.dto.Result;
+import com.cyksj.model.dto.AliPayParams;
 import com.cyksj.model.dto.H5JsPayParams;
 import com.cyksj.model.entity.RegisterOrderDon;
 import com.cyksj.model.entity.SpotifyUnLimitRecord;
@@ -38,7 +39,7 @@ public interface RegisterOrderDonService extends IService<RegisterOrderDon> {
 
 	void unifiedRefund(OrderRefundReq refundReq) throws Exception;
 
-    String zfbUnifiedPay(AlipayOrderDonReq re) throws Exception;
+    AliPayParams zfbUnifiedPay(AlipayOrderDonReq re) throws Exception;
 
     void aliPayNotify(Map<String, String> params) throws Exception;
 }

+ 14 - 5
netflix-service/src/main/java/com/cyksj/service/register/impl/RegisterOrderDonServiceImpl.java

@@ -19,6 +19,7 @@ import com.cyksj.common.util.Xmls;
 import com.cyksj.config.WeChatConfig;
 import com.cyksj.config.zfb.AliPayClientFactory;
 import com.cyksj.config.zfb.BaseZfbConfig;
+import com.cyksj.config.zfb.ZfbProductCode;
 import com.cyksj.dto.RedisKey;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
@@ -28,6 +29,7 @@ import com.cyksj.mapper.SpotifyUnLimitRecordMapper;
 import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.channel.ShopConfigMapper;
 import com.cyksj.mapper.manage.coupon.CouponMapper;
+import com.cyksj.model.dto.AliPayParams;
 import com.cyksj.model.dto.H5JsPayParams;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.request.RegisterReq;
@@ -196,11 +198,11 @@ public class RegisterOrderDonServiceImpl extends ServiceImpl<RegisterOrderDonMap
                 appleAutoRegisterData.setUserId(0l);
                 appleAutoRegisterData.setOrderId(0l);
                 appleAutoRegisterDataMapper.updateById(appleAutoRegisterData);
-                //订单关闭
-                registerOrderDon.setStatus(RegisterOrderDon.Status.close);
-                registerOrderDonMapper.updateById(registerOrderDon);
                 log.info("未支付appleID自动注册订单:{},修改appleID使用状态", orderId);
             }
+            //订单关闭
+            registerOrderDon.setStatus(RegisterOrderDon.Status.close);
+            registerOrderDonMapper.updateById(registerOrderDon);
         }
     }
 
@@ -286,8 +288,15 @@ public class RegisterOrderDonServiceImpl extends ServiceImpl<RegisterOrderDonMap
     }
 
     @Override
-    public String zfbUnifiedPay(AlipayOrderDonReq re) throws Exception {
-        return aliPayCommonService.unifiedPayRegister(re.getOrderId(), re.getType(), re.getPayMode(), re.getReturnUrl());
+    public AliPayParams zfbUnifiedPay(AlipayOrderDonReq re) throws Exception {
+        String productCode = StrUtil.EMPTY;
+        if (re.getType() == 1) {
+            productCode = ZfbProductCode.MOBILE_WEB.getProductCode();
+        }
+        if (re.getType() == 2) {
+            productCode = ZfbProductCode.PC_WEB.getProductCode();
+        }
+        return aliPayCommonService.unifiedPayRegister(re.getOrderId(), productCode, re.getPayMode(), re.getReturnUrl());
     }
 
     @Override

+ 1 - 1
netflix-service/src/main/java/com/cyksj/task/Scheduler.java

@@ -297,7 +297,7 @@ public class Scheduler {
         //获取为支付订单
         DateTime now = new DateTime();
         Date newDate = DateUtil.offset(now, DateField.MINUTE, -5);
-        List<Long> orderDons = appleAutoRegisterDataMapper.getAllNoPayOrders(newDate);
+	    List<Long> orderDons = appleAutoRegisterDataMapper.getAllNoPayOrders(newDate);
         log.info("定时更新未支付AppleID自动注册订单 订单数:{}",orderDons.size());
         orderDons.forEach((orderId)->{
             registerOrderDonService.updateAppleAutoStatus(orderId);

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/payment/OrderController.java

@@ -238,7 +238,7 @@ public class OrderController {
     public Result<String> zfbWebQrCode(@RequestBody @Validated AlipayOrderDonReq re) throws Exception {
         Long orderId = re.getOrderId();
         String returnUrl = re.getReturnUrl();
-        AliPayParams aliPayParams = orderDonService.aliPay(orderId, returnUrl, ZfbProductCode.PC_WEB.getProductCode(), BaseZfbConfig.qrPayMode_orderCode);
+        AliPayParams aliPayParams = orderDonService.aliPay(orderId, returnUrl, BaseZfbConfig.TWO_STR, BaseZfbConfig.qrPayMode_orderCode);
 //        response.setContentType("text/html;charset=" + BaseZfbConfig.charset);
         //直接将完整的表单html输出到页面
 //        response.getWriter().write(aliPayParams.getBody());
@@ -255,7 +255,7 @@ public class OrderController {
     public Result<String> zfbWebRedirectQrCode(@RequestBody @Validated AlipayOrderDonReq re) throws Exception {
         Long orderId = re.getOrderId();
         String returnUrl = re.getReturnUrl();
-        AliPayParams aliPayParams = orderDonService.aliPay(orderId, returnUrl, ZfbProductCode.PC_WEB.getProductCode(), BaseZfbConfig.qrPayMode_redirect);
+        AliPayParams aliPayParams = orderDonService.aliPay(orderId, returnUrl, BaseZfbConfig.TWO_STR, BaseZfbConfig.qrPayMode_redirect);
         return GatewayResponse.SUCCESS.newBuilder().toResult(aliPayParams.getBody());
     }
 

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/register/RegisterController.java

@@ -130,8 +130,8 @@ public class RegisterController {
      * 支付宝支付
      */
     @PostMapping("/zfb/unified/pay")
-    public Result<String> zfbUnifiedPay(@RequestBody @Validated AlipayOrderDonReq re,HttpServletResponse response) throws Exception {
-        String pay_body = registerOrderDonService.zfbUnifiedPay(re);
+    public Result<String> zfbUnifiedPay(@RequestBody @Validated AlipayOrderDonReq re) throws Exception {
+        String pay_body = registerOrderDonService.zfbUnifiedPay(re).getBody();
 //        response.setContentType("text/html;charset=" + BaseZfbConfig.charset);
 //        //直接将完整的表单html输出到页面
 //        response.getWriter().write(pay_body);