浏览代码

Merge branch 'zx_1026_1111' of http://git.dayaedu.com/yonge/mec into test

zouxuan 2 年之前
父节点
当前提交
8ba8803915

+ 24 - 19
mec-application/src/main/java/com/ym/mec/web/controller/open/OpenDouble11StaticsController.java

@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.math.BigDecimal;
+import java.rmi.MarshalledObject;
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -148,9 +149,27 @@ public class OpenDouble11StaticsController extends BaseController {
         }
         setQueryParam(query, configParam);
 
+        List<Double11StaticWrapper.SaleAmountAndUser> saleAmount = studentPaymentOrderDao.saleStaticsByOrgId(query);
+        Map<Integer, Double11StaticWrapper.SaleAmountAndUser> idDataMap = saleAmount.stream()
+                .collect(Collectors.toMap(Double11StaticWrapper.SaleAmountAndUser::getOrganId, Function.identity()));
+
+        List<Double11StaticWrapper.SaleAmountAndUser> result = orgIdMap.entrySet().stream()
+                .map(next -> {
+                    if(idDataMap.containsKey(next.getKey())){
+                        Double11StaticWrapper.SaleAmountAndUser saleAmountAndUser = idDataMap.get(next.getKey());
+                        saleAmountAndUser.setOrganName(next.getValue().getName());
+                        return saleAmountAndUser;
+                    }
+
+                    Double11StaticWrapper.SaleAmountAndUser statics = new Double11StaticWrapper.SaleAmountAndUser();
+                    statics.setOrganId(next.getKey());
+                    statics.setOrganName(next.getValue().getName());
+                    statics.setActualAmount(new BigDecimal(0));
+                    statics.setBalancePaymentAmount(new BigDecimal(0));
+                    statics.setUserPurchaseNumber(0);
+                    return statics;
+                }).collect(Collectors.toList());
 
-        List<Double11StaticWrapper.SaleAmountAndUser> result = studentPaymentOrderDao.saleStaticsByOrgId(query);
-        result.forEach(next -> next.setOrganName(orgIdMap.getOrDefault(next.getOrganId(), new Organization()).getName()));
         String orderBy = Optional.ofNullable(query.getOrderBy()).orElse("saleAmount");
         int asc = Optional.ofNullable(query.getAsc()).orElse(0);
         if ("saleAmount".equals(orderBy)) {
@@ -170,20 +189,6 @@ public class OpenDouble11StaticsController extends BaseController {
                 }
             });
         }
-
-//        Double11StaticWrapper.SaleAmountAndUser total = new Double11StaticWrapper.SaleAmountAndUser();
-//        total.setOrganName("总部");
-//        double acAmount = result.stream().map(Double11StaticWrapper.SaleAmountAndUser::getActualAmount)
-//                .mapToDouble(BigDecimal::doubleValue).sum();
-//        total.setActualAmount(new BigDecimal(acAmount));
-//        double baAmount = result.stream().map(Double11StaticWrapper.SaleAmountAndUser::getBalancePaymentAmount)
-//                .mapToDouble(BigDecimal::doubleValue).sum();
-//        total.setBalancePaymentAmount(new BigDecimal(baAmount));
-//        int totalUser = result.stream().map(Double11StaticWrapper.SaleAmountAndUser::getUserPurchaseNumber)
-//                .mapToInt(Integer::intValue).sum();
-//        total.setUserPurchaseNumber(totalUser);
-//
-//        result.add(0, total);
         return R.from(result);
     }
 
@@ -255,15 +260,15 @@ public class OpenDouble11StaticsController extends BaseController {
             query.setType(OrderTypeEnum.SMALL_CLASS_TO_BUY);
             query.setActivityId(configParam.getV1());
         } else if (saleStaticsType == 2) {
-            // 乐理
+            // 1v2
             query.setGroupType(GroupType.VIP);
             query.setType(OrderTypeEnum.SMALL_CLASS_TO_BUY);
             query.setActivityId(configParam.getV2());
         } else if (saleStaticsType == 3) {
             // 乐理
             query.setGroupType(GroupType.LIVE);
-            query.setType(OrderTypeEnum.LIVE_BUY);
-            query.setActivityId(configParam.getTheoryLive());
+            query.setType(OrderTypeEnum.LIVE_GROUP_BUY);
+            query.setMusicGroupId(configParam.getTheoryLive());
         } else if (saleStaticsType == 4) {
             // 云教练
             query.setGroupType(GroupType.MEMBER);

+ 9 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -1478,13 +1478,21 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         }
 
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
+        String notifyUrl = "";
+        if ("YEEPAY".equals(studentPaymentOrder.getPaymentChannel())){
+            notifyUrl = baseApiUrl + "/api-mall-portal/payment/callback_yee/" + studentPaymentOrder.getTenantId();
+        }else if ("ADAPAY".equals(studentPaymentOrder.getPaymentChannel())){
+            notifyUrl = baseApiUrl + "/api-mall-portal/payment/callback";
+        }else {
+            throw new BizException("支付渠道错误");
+        }
 
         //  receiver类型
         payMap = payService.getPayMap(
                 studentPaymentOrder.getActualAmount(),
                 studentPaymentOrder.getBalancePaymentAmount(),
                 model.getOrderNo(),
-                baseApiUrl + "/api-mall-portal/payment/callback",
+                notifyUrl,
                 baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + model.getOrderNo(),
                 "商品销售",
                 "商品销售",

+ 2 - 2
mec-client-api/src/main/java/com/ym/mec/web/WebFeignService.java

@@ -43,8 +43,8 @@ public interface WebFeignService {
 	@PostMapping(value = "api/queryVipPracticeGroups")
     Boolean queryVipPracticeGroups();
 
-	@GetMapping(value = "/queryByTenantId/{id}")
-	HttpResponseResult<HfMerchantConfig> queryByTenantId(@PathVariable("id") Integer id);
+	@GetMapping(value = "/queryByTenantId/{payerName}/{id}")
+	HttpResponseResult<HfMerchantConfig> queryByTenantId(@PathVariable("payerName") String payerName,@PathVariable("id") Integer id);
 
 	@PostMapping("/api/mallCreateOrder")
 	HttpResponseResult<Map> mallCreateOrder(@RequestBody MallCreateOrderModel model);

+ 59 - 5
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/controller/PaymentController.java

@@ -5,11 +5,16 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.huifu.adapay.core.AdapayCore;
 import com.huifu.adapay.core.util.AdapaySign;
+import com.yeepay.g3.sdk.yop.encrypt.DigitalEnvelopeDTO;
+import com.yeepay.g3.sdk.yop.utils.DigitalEnvelopeUtils;
+import com.yeepay.g3.sdk.yop.utils.RSAKeyUtils;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
+import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
+import com.ym.mec.web.WebFeignService;
 import com.yonge.cooleshow.mall.common.enums.OrderCacheEnum;
 import com.yonge.cooleshow.mbg.model.UserOrderPayment;
 import com.yonge.cooleshow.portal.dto.OrderPayRes;
@@ -23,14 +28,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 import java.math.BigDecimal;
+import java.security.PrivateKey;
+import java.security.PublicKey;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -57,6 +61,9 @@ public class PaymentController extends BaseController {
     @Autowired
     private UserOrderPaymentService userOrderPaymentService;
 
+    @Autowired
+    private WebFeignService webFeignService;
+
 
     /***
      * 支付回调
@@ -133,7 +140,7 @@ public class PaymentController extends BaseController {
                     e.printStackTrace();
                     return failed("请求超时");
                 }
-            } else {
+            }else {
                 return "验签失败";
             }
         } catch (Exception e) {
@@ -143,4 +150,51 @@ public class PaymentController extends BaseController {
         return "succeeded";
     }
 
+    /***
+     * 易宝支付回调
+     * @author liweifan
+     * @param: request
+     * @updateTime 2022/3/11 18:35
+     */
+    @RequestMapping("/callback_yee/{tenantId}")
+    public Object callback_yee(@PathVariable("tenantId") Integer tenantId, HttpServletRequest request) {
+        try {
+            String content = request.getParameter("response");
+            JSONObject dataObj = JSON.parseObject(content);
+            String orderNo = dataObj.getString("orderId");
+            UserOrderPayment userOrderPayment = userOrderPaymentService.getByAdapayNo(orderNo);
+            if (userOrderPayment == null) {
+                throw new BizException("订单不存在");
+            }
+            HfMerchantConfig hfMerchantConfig = webFeignService.queryByTenantId("YEEPAY",tenantId).getData();
+            if(hfMerchantConfig == null){
+                throw new BizException("机构[{}][{}]商户信息找不到", tenantId, "YEEPAY");
+            }
+
+            // 构造结果通知请求对象
+            DigitalEnvelopeDTO dto = new DigitalEnvelopeDTO();
+            dto.setCipherText(content);
+            PrivateKey privateKey = RSAKeyUtils.string2PrivateKey(hfMerchantConfig.getRsaPrivateKey());
+            PublicKey publicKey = RSAKeyUtils.string2PublicKey(hfMerchantConfig.getRsaPublicKey());
+
+            dto = DigitalEnvelopeUtils.decrypt(dto, privateKey, publicKey);
+
+            log.info("易宝支付回调信息:response:{} plaintText:{}", content, dto.getPlainText());
+            if("SUCCESS".equals(dataObj.getString("status"))) {
+                orderService.paymentSucceededHandle(orderNo,
+                        dataObj.getBigDecimal("orderAmount"),dataObj.getString("channel"));
+            }else {
+                Map<String,Object> notifyMap = new HashMap<>();
+                notifyMap.put("channelType", dataObj.getString("channel"));
+                notifyMap.put("tradeState", "0");
+                notifyMap.put("totalMoney", dataObj.getString("orderAmount"));
+                notifyMap.put("merOrderNo", orderNo);
+                orderService.paymentFailedHandle(orderNo,notifyMap);
+            }
+        } catch (Exception e) {
+            return e.getMessage();
+        }
+        return "SUCCESS";
+    }
+
 }