yonge il y a 2 ans
Parent
commit
226c2c806e

+ 6 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderService.java

@@ -103,10 +103,9 @@ public interface StudentPaymentOrderService extends BaseService<Long, StudentPay
      *
      * @param date
      * @param payingOrder
-     * @param checkTime
      * @return
      */
-    OrderCancelModel updateOrderStatus(Date date, StudentPaymentOrder payingOrder, Boolean checkTime) throws Exception;
+    OrderCancelModel updateOrderStatus(Date date, StudentPaymentOrder payingOrder) throws Exception;
 
     //退优惠券和余额
     void quitCouponAndBalance(StudentPaymentOrder order);
@@ -162,6 +161,11 @@ public interface StudentPaymentOrderService extends BaseService<Long, StudentPay
      * @return
      */
     List<StudentPaymentOrder> reConfirmOrder(Date startTime, Date endTime);
+    
+    /**
+     * 分账
+     */
+    Boolean confirmOrder(StudentPaymentOrder order);
 
     /**
      * 获取学生报名的订单

+ 13 - 8
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -418,15 +418,18 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             if (DateUtil.minutesBetween(payingOrder.getCreateTime(), date) < 10) {
                 continue;
             }
-
-            updateOrderStatus(date, payingOrder,true);
+            try {
+            	updateOrderStatus(date, payingOrder);
+            }catch (Exception e) {
+				logger.error("执行[订单状态查询]任务失败", e);
+			}
         }
         closeOrders(orderNoList);
     }
 
     @Override
     @Transactional
-    public OrderCancelModel updateOrderStatus(Date date, StudentPaymentOrder payingOrder, Boolean checkTime) throws Exception {
+    public OrderCancelModel updateOrderStatus(Date date, StudentPaymentOrder payingOrder) throws Exception {
     	
         HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(payingOrder.getTenantId(), payingOrder.getPaymentChannel());
         if(hfMerchantConfig == null){
@@ -450,6 +453,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             	payment.put("status", "succeeded");
         	}else if(StringUtils.equals("FAIL", respStatus) || StringUtils.equals("TIME_OUT", respStatus) || StringUtils.equals("CLOSE", respStatus)) {
             	payment.put("status", "failed");
+        	}else {
+        		payment.put("status", "pending");
         	}
         	payment.put("error_msg", orderInfo.get("failReason"));
         }else {
@@ -470,14 +475,14 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         if (status.equals("succeeded")) {
             rpMap.put("tradeState", "1");
             model.setStatus(true);
-        } else if (status.equals("failed") || !checkTime
+        } else if (status.equals("failed")
                 || (DateUtil.minutesBetween(DateUtil.addHours(payingOrder.getUpdateTime(), 2),date) > 0)) {
             rpMap.put("tradeState", "0");
             model.setStatus(false);
         }
 
         if (status.equals("succeeded") ||
-                (status.equals("failed") || !checkTime || payingOrder.getCreateTime().before(DateUtil.addMinutes(new Date(), -35)))) {
+                (status.equals("failed") || payingOrder.getCreateTime().before(DateUtil.addMinutes(new Date(), -35)))) {
             try {
                 updateOrder(rpMap); //更新订单
                 model.setSuccess(true);
@@ -504,7 +509,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
 
     @Transactional(rollbackFor = Exception.class)
     public void updateOrder(Map<String, String> rpMap) throws Exception {
-        DealStatusEnum status = rpMap.get("tradeState").equals("1") ? DealStatusEnum.SUCCESS : DealStatusEnum.FAILED;
+        DealStatusEnum status = "1".equals(rpMap.get("tradeState")) ? DealStatusEnum.SUCCESS : DealStatusEnum.FAILED;
         StudentPaymentOrder order = findOrderByOrderNo(rpMap.get("merOrderNo"));
         //关闭或失败的订单查询订单成功,订单改成成功,钱退到余额
         if (order != null && (order.getStatus().equals(DealStatusEnum.CLOSE) || order.getStatus().equals(DealStatusEnum.FAILED)) && status.equals(DealStatusEnum.SUCCESS)) {
@@ -524,7 +529,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                     PlatformCashAccountDetailTypeEnum.REFUNDS, order.getMemo() + ",订单号:" + order.getOrderNo());
 
             if (StringUtils.isNotBlank(order.getPaymentChannel())
-                    && order.getPaymentChannel().equals("ADAPAY")
+                    && (order.getPaymentChannel().equals(PaymentChannelEnum.ADAPAY.getCode()) || order.getPaymentChannel().equals(PaymentChannelEnum.YEEPAY.getCode()))
                     && !rpMap.containsKey("simulation")) {
                 confirmOrder(order);
             }
@@ -562,7 +567,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         TenantContextHolder.clearTenantId();
     }
 
-    private Boolean confirmOrder(StudentPaymentOrder order) {
+    public Boolean confirmOrder(StudentPaymentOrder order) {
         // 只有大雅延迟分账,其他实时分账
         if (order.getTenantId() != 1) {
             return true;

+ 18 - 3
mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -122,6 +122,7 @@ import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
 import com.ym.mec.thirdparty.yqpay.Msg;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
+import com.ym.mec.util.json.JsonUtil;
 import com.ym.mec.util.web.WebUtil;
 
 import io.swagger.annotations.Api;
@@ -272,6 +273,8 @@ public class StudentOrderController extends BaseController {
 				
 				String content = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
 				
+				JSONObject jsonObject = JSONObject.parseObject(content);
+				
 				HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(studentPaymentOrder.getTenantId(), studentPaymentOrder.getPaymentChannel());
 		        if(hfMerchantConfig == null){
 		        	throw new BizException("机构[{}][{}]商户信息找不到", studentPaymentOrder.getTenantId(), studentPaymentOrder.getPaymentChannel());
@@ -279,15 +282,27 @@ public class StudentOrderController extends BaseController {
 				
 				// 构造结果通知请求对象
 				DigitalEnvelopeDTO dto = new DigitalEnvelopeDTO();
-				dto.setCipherText(content);
+				dto.setCipherText(jsonObject.getString("response"));
 				PrivateKey privateKey =RSAKeyUtils.string2PrivateKey(hfMerchantConfig.getRsaPrivateKey());
 				PublicKey publicKey = RSAKeyUtils.string2PublicKey(hfMerchantConfig.getRsaPublicKey());
 				
 				dto = DigitalEnvelopeUtils.decrypt(dto, privateKey, publicKey);
 				
-				logger.info("易宝支付回调信息:{}", JSON.toJSONString(dto));
-				System.out.println("支付回调信息:" + JSON.toJSONString(dto));
+				logger.info("易宝支付回调信息:{}", dto.getPlainText());
+				
+				JSONObject dataObj = JSON.parseObject(dto.getPlainText());
 				
+				Map<String, String> notifyMap = new HashMap<>();
+				notifyMap.put("channelType", dataObj.getString("channel"));
+				
+				if("SUCCESS".equals(dataObj.getString("status"))) {
+					notifyMap.put("tradeState", "1");
+				}else {
+					notifyMap.put("tradeState", "0");
+				}
+				notifyMap.put("totalMoney", dataObj.getString("orderAmount"));
+				notifyMap.put("merOrderNo", dataObj.getString("orderId"));
+				studentPaymentOrderService.updateOrder(notifyMap);
 				
 				break;
 

+ 18 - 2
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/yeepay/YeepayPaymentService.java

@@ -1,9 +1,9 @@
 package com.ym.mec.thirdparty.yeepay;
 
 import java.io.IOException;
+import java.util.Date;
 import java.util.Map;
 
-import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -14,6 +14,8 @@ import com.yeepay.g3.sdk.yop.client.YopRequest;
 import com.yeepay.g3.sdk.yop.client.YopResponse;
 import com.yeepay.g3.sdk.yop.client.YopRsaClient;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
+import com.ym.mec.thirdparty.exception.ThirdpartyException;
+import com.ym.mec.util.date.DateUtil;
 
 @Service
 public class YeepayPaymentService {
@@ -30,6 +32,7 @@ public class YeepayPaymentService {
 		request.addParam("merchantNo", params.get("merchantNo"));
 		request.addParam("orderId", params.get("orderId"));
 		request.addParam("orderAmount", params.get("orderAmount"));
+		request.addParam("expiredTime", DateUtil.addMinutes(new Date(), 30));
 		request.addParam("notifyUrl", params.get("notifyUrl"));
 		request.addParam("redirectUrl", params.get("redirectUrl"));
 		request.addParam("scene", params.get("scene"));
@@ -58,12 +61,25 @@ public class YeepayPaymentService {
 		request.addParam("orderId", orderNo);
 		
 		YopResponse response = YopRsaClient.get("/rest/v1.0/trade/order/query", request);
+		
+		if("FAILURE".equals(response.getState())) {
+			throw new ThirdpartyException(response.getError().getSubMessage());
+		}
 
 		LOGGER.info("易宝[订单查询][{}] Resp:{}", orderNo, response.getStringResult());
 		
 		JSONObject jsonObject = JSONObject.parseObject(response.getStringResult());
 		
-		return jsonObject;
+		if("OPR00000".equals(jsonObject.get("code").toString())) {
+
+			return jsonObject;
+    	}else if("OPR12002".equals(jsonObject.get("code").toString())) {
+    		//订单不存在
+    		jsonObject.put("status", "CLOSE");
+    		return jsonObject;
+    	}
+        throw new ThirdpartyException(jsonObject.get("message").toString());
+		
 	}
 
 	public Map<String,Object> divide(HfMerchantConfig hfMerchantConfig, Map<String, Object> params) throws IOException {

+ 21 - 10
mec-web/src/main/java/com/ym/mec/web/controller/StudentPaymentOrderController.java

@@ -1,5 +1,17 @@
 package com.ym.mec.web.controller;
 
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
 import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dto.BasicUserDto;
@@ -13,20 +25,11 @@ import com.ym.mec.biz.service.StudentPaymentOrderService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.page.PageInfo;
+
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.stream.Collectors;
 
 @RequestMapping("order")
 @Api(tags = "订单服务")
@@ -160,4 +163,12 @@ public class StudentPaymentOrderController extends BaseController {
     public Object queryOrderDetail(Long orderId){
         return studentPaymentOrderDetailService.queryOrderDetail(orderId);
     }
+
+    @ApiOperation(value = "分账")
+    @PostMapping("/divideAmount")
+    @PreAuthorize("@pcs.hasPermissions('order/divideAmount')")
+    public Object divideAmount(Long orderId){
+    	StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.get(orderId);
+        return studentPaymentOrderService.confirmOrder(studentPaymentOrder);
+    }
 }

+ 12 - 9
mec-web/src/main/java/com/ym/mec/web/controller/payment/YeepayController.java

@@ -115,23 +115,26 @@ public class YeepayController extends BaseController {
     @PostMapping("/callback/{tenantId}")
 	public String callback(@PathVariable("tenantId") Integer tenantId, HttpServletRequest request) {
 
+		HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(tenantId, PaymentChannelEnum.YEEPAY.getCode());
+        if(hfMerchantConfig == null){
+        	throw new BizException("机构[{}][{}]商户信息找不到", tenantId, PaymentChannelEnum.YEEPAY.getCode());
+        }
+        
 		try {
-			String content = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
 			
-			HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(tenantId, PaymentChannelEnum.YEEPAY.getCode());
-	        if(hfMerchantConfig == null){
-	        	throw new BizException("机构[{}][{}]商户信息找不到", tenantId, PaymentChannelEnum.YEEPAY.getCode());
-	        }
+	        String content = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
+			
+			JSONObject jsonObject = JSONObject.parseObject(content);
 			
 			// 构造结果通知请求对象
 			DigitalEnvelopeDTO dto = new DigitalEnvelopeDTO();
-			dto.setCipherText(content);
+			dto.setCipherText(jsonObject.getString("response"));
 			PrivateKey privateKey =RSAKeyUtils.string2PrivateKey(hfMerchantConfig.getRsaPrivateKey());
 			PublicKey publicKey = RSAKeyUtils.string2PublicKey(hfMerchantConfig.getRsaPublicKey());
 			
-			dto = DigitalEnvelopeUtils.decrypt(dto, privateKey, publicKey);	
-			logger.info("易宝支付回调信息:{}", JSON.toJSONString(dto));			
-			System.out.println("支付回调信息:" + JSON.toJSONString(dto));
+			dto = DigitalEnvelopeUtils.decrypt(dto, privateKey, publicKey);
+			
+			logger.info("易宝支付回调信息:{}", dto.getPlainText());
 			
 			return "SUCCESS";
 		} catch (Exception e) {