liujunchi пре 2 година
родитељ
комит
76122b761e

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderService.java

@@ -18,6 +18,7 @@ import com.ym.mec.common.entity.MallCreateOrderModel;
 import com.ym.mec.common.entity.OrderCancelModel;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
+import com.ym.mec.thirdparty.adapay.entity.BaseResult;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
 import org.apache.ibatis.annotations.Param;
 
@@ -248,4 +249,7 @@ public interface StudentPaymentOrderService extends BaseService<Long, StudentPay
     void mallSaveOrderInfo(MallCreateOrderModel model);
 
     OrderCancelModel cancelOrder(StudentPaymentOrder orderByOrderNo);
+
+    // 撤销支付
+    BaseResult<Map<String, Object>> refund(String orderNo, String notifyUrl, String refundNo);
 }

+ 20 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -27,6 +27,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.thirdparty.adapay.ConfigInit;
 import com.ym.mec.thirdparty.adapay.Payment;
+import com.ym.mec.thirdparty.adapay.entity.BaseResult;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
 import com.ym.mec.thirdparty.yqpay.*;
 import com.ym.mec.util.collection.MapUtil;
@@ -1237,4 +1238,23 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         }
         return model;
     }
+
+    @Override
+    public BaseResult<Map<String, Object>> refund(String orderNo, String notifyUrl, String refundNo) {
+
+        StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(orderNo);
+        if (orderByOrderNo == null) {
+            throw new BizException("为找到订单");
+        }
+        if (orderByOrderNo.getActualAmount().compareTo(BigDecimal.ZERO) ==0) {
+            throw new BizException("0元订单");
+        }
+
+        HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(orderByOrderNo.getTenantId());
+        if(hfMerchantConfig == null){
+            throw new BizException("请配置机构的汇付商户信息");
+        }
+        return Payment.reversePayment(orderByOrderNo.getTransNo(),hfMerchantConfig.getAppId(),refundNo,
+                               orderByOrderNo.getActualAmount().setScale(2,BigDecimal.ROUND_HALF_UP).toString(),notifyUrl);
+    }
 }

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

@@ -4,6 +4,7 @@ import com.ym.mec.common.config.FeignConfiguration;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.entity.MallCreateOrderModel;
 import com.ym.mec.common.entity.OrderCancelModel;
+import com.ym.mec.common.entity.RefundModel;
 import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.thirdparty.adapay.entity.BaseResult;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
@@ -63,6 +64,6 @@ public interface WebFeignService {
 	HttpResponseResult<Map<String,String>> getBaseUrl(@RequestParam("orderNo") String orderNo);
 
 	// 商城获取 退款数据
-	@GetMapping("/api/refund")
-	public HttpResponseResult<BaseResult<Map<String, Object>>> refund(@RequestParam Map<String,Object> refundInfo);
+	@PostMapping("/refund")
+	HttpResponseResult<BaseResult<Map<String, Object>>> refund(@RequestBody RefundModel refundModel);
 }

+ 2 - 1
mec-client-api/src/main/java/com/ym/mec/web/fallback/WebFeignServiceFallback.java

@@ -3,6 +3,7 @@ package com.ym.mec.web.fallback;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.entity.MallCreateOrderModel;
 import com.ym.mec.common.entity.OrderCancelModel;
+import com.ym.mec.common.entity.RefundModel;
 import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.thirdparty.adapay.entity.BaseResult;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
@@ -88,7 +89,7 @@ public class WebFeignServiceFallback implements WebFeignService {
 	}
 
 	@Override
-	public HttpResponseResult<BaseResult<Map<String, Object>>> refund(Map<String, Object> refundInfo) {
+	public HttpResponseResult<BaseResult<Map<String, Object>>> refund(RefundModel refundModel) {
 		return null;
 	}
 }

+ 40 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/entity/RefundModel.java

@@ -0,0 +1,40 @@
+package com.ym.mec.common.entity;
+
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author liujunchi
+ * @date 2022-09-22
+ */
+public class RefundModel implements Serializable {
+
+    private String orderNo;
+    private String notifyUrl;
+    private String refundNo;
+
+    public String getOrderNo() {
+        return orderNo;
+    }
+
+    public void setOrderNo(String orderNo) {
+        this.orderNo = orderNo;
+    }
+
+    public String getNotifyUrl() {
+        return notifyUrl;
+    }
+
+    public void setNotifyUrl(String notifyUrl) {
+        this.notifyUrl = notifyUrl;
+    }
+
+    public String getRefundNo() {
+        return refundNo;
+    }
+
+    public void setRefundNo(String refundNo) {
+        this.refundNo = refundNo;
+    }
+}

+ 10 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/PmsProductServiceImpl.java

@@ -2,6 +2,7 @@ package com.yonge.cooleshow.admin.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
 import com.github.pagehelper.PageHelper;
+import com.ym.mec.common.exception.BizException;
 import com.yonge.cooleshow.admin.dao.*;
 import com.yonge.cooleshow.admin.dao.*;
 import com.yonge.cooleshow.admin.dto.HomeStatistical;
@@ -19,6 +20,7 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import java.lang.reflect.Method;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -69,6 +71,14 @@ public class PmsProductServiceImpl implements PmsProductService {
 
     @Override
     public int create(PmsProductParam productParam) {
+        if (productParam.getPrice().compareTo(BigDecimal.ZERO) <=0 ) {
+            throw new BizException("商品价格不能小于等于0");
+        }
+        for (PmsSkuStock pmsSkuStock : productParam.getSkuStockList()) {
+            if (pmsSkuStock.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
+                throw new BizException("商品价格不能小于等于0");
+            }
+        }
         int count;
         //创建商品
         productParam.setId(null);

+ 3 - 1
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/UmsRoleServiceImpl.java

@@ -56,7 +56,9 @@ public class UmsRoleServiceImpl implements UmsRoleService {
 
     @Override
     public List<UmsRole> list() {
-        return roleMapper.selectByExample(new UmsRoleExample());
+        UmsRoleExample umsRoleExample = new UmsRoleExample();
+        umsRoleExample.createCriteria().andStatusEqualTo(1);
+        return roleMapper.selectByExample(umsRoleExample);
     }
 
     @Override

+ 4 - 3
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/controller/PaymentController.java

@@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
+import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -102,12 +103,12 @@ public class PaymentController extends BaseController {
                                 orderService.paymentFailedHandle(dataObj.getString("order_no"),notifyMap);
 
                                 break;
-                            case "refund.succeeded" :
+                            case "payment_reverse.succeeded" :
 
                                 orderService.paymentRefundSucceededHandle(dataObj.getString("payment_id")
-                                                ,dataObj.getString("refund_amt"),dataObj.getString("id"),dataObj.getString("fee_amt"));
+                                                , dataObj.getString("reverse_amt"), dataObj.getString("id"), BigDecimal.ZERO.toString());
                                 break;
-                            case "refund.failed" :
+                            case "payment_reverse.failed" :
 
                                 orderService.paymentRefundFailedHandle(dataObj.getString("payment_id")
                                         ,dataObj.getString("error_msg"),dataObj.getString("id"));

+ 6 - 6
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/impl/OmsPortalOrderServiceImpl.java

@@ -8,6 +8,7 @@ import com.github.pagehelper.PageHelper;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.entity.MallCreateOrderModel;
 import com.ym.mec.common.entity.OrderCancelModel;
+import com.ym.mec.common.entity.RefundModel;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.thirdparty.adapay.Payment;
@@ -817,12 +818,11 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
         String baseUrl = MapUtil.getStr(data,"baseUrl");
         String transNo = MapUtil.getStr(data,"transNo");
         // 金额退回
-        Map<String, Object> refundParams = new HashMap<>(10);
-        refundParams.put("refund_amt", refundAmount);
-        refundParams.put("refund_order_no", orderSn);
-        refundParams.put("notify_url",baseUrl + "/api-mall-portal/payment/callback");
-        refundParams.put("transNo",transNo);
-        HttpResponseResult<BaseResult<Map<String, Object>>> refund = webFeignService.refund(refundParams);
+        RefundModel refundModel = new RefundModel();
+        refundModel.setRefundNo(orderSn);
+        refundModel.setOrderNo(userOrderPayment.getAdapayNo());
+        refundModel.setNotifyUrl(baseUrl + "/api-mall-portal/payment/callback");
+        HttpResponseResult<BaseResult<Map<String, Object>>> refund = webFeignService.refund(refundModel);
         if (!refund.getStatus()) {
             throw new BizException("退款失败");
         }

+ 30 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/Payment.java

@@ -6,6 +6,7 @@ import java.util.*;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
+import com.huifu.adapay.model.PaymentReverse;
 import com.huifu.adapay.model.Refund;
 import com.ym.mec.thirdparty.adapay.entity.BaseResult;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
@@ -166,4 +167,33 @@ public class Payment {
         }
         return BaseResult.succeed(res);
     }
+
+
+    // 撤销支付
+    public static BaseResult<Map<String ,Object>> reversePayment(String paymentId,String appId,String reverseOrderNo,String reverseAmt,String notifyUrl) {
+
+        LOGGER.info("撤销对象信息:paymentId:{},appId:{},reverseOrderNo:{},reverseAmt:{}",paymentId,appId,reverseOrderNo,reverseAmt);
+        Map<String, Object> res;
+        Map<String,Object> param = new HashMap<>();
+        param.put("app_id",appId);
+        param.put("payment_id",paymentId);
+        param.put("reverse_amt",reverseAmt);
+        param.put("order_no",reverseOrderNo);
+        param.put("notify_url",notifyUrl);
+        try {
+            res = PaymentReverse.create(param);
+        } catch (BaseAdaPayException e) {
+            return BaseResult.failed(e.getMessage());
+        }
+        if (CollectionUtils.isEmpty(res)) {
+            return BaseResult.failed("请求失败");
+        }
+        LOGGER.info("汇付[支付退款] Resp:{}", res);
+        String errorCode = (String) res.get("error_code");
+        if (null != errorCode) {
+            String errorMsg = (String) res.get("error_msg");
+            return BaseResult.failed(errorMsg);
+        }
+        return BaseResult.succeed(res);
+    }
 }

+ 5 - 4
mec-web/src/main/java/com/ym/mec/web/controller/APIController.java

@@ -7,6 +7,7 @@ import com.ym.mec.biz.service.*;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.entity.MallCreateOrderModel;
 import com.ym.mec.common.entity.OrderCancelModel;
+import com.ym.mec.common.entity.RefundModel;
 import com.ym.mec.thirdparty.adapay.Payment;
 import com.ym.mec.thirdparty.adapay.entity.BaseResult;
 import io.swagger.annotations.Api;
@@ -215,13 +216,13 @@ public class APIController extends BaseController {
 
 
 
-	// 商城获取 退款数据
-	@GetMapping("/refund")
-	public HttpResponseResult<BaseResult<Map<String, Object>>> refund(@RequestParam Map<String,Object> refundInfo) {
+	// 商城获取 退款数据  只能全额退款
+	@PostMapping("/refund")
+	public HttpResponseResult<BaseResult<Map<String, Object>>> refund(@RequestBody RefundModel refundModel) {
 
 		try {
+			BaseResult<Map<String, Object>> mapBaseResult = studentPaymentOrderService.refund(refundModel.getOrderNo(),refundModel.getNotifyUrl(),refundModel.getRefundNo());
 
-			BaseResult<Map<String, Object>> mapBaseResult = Payment.refundPayment(refundInfo);
 			return succeed(mapBaseResult);
 		} catch (Exception e) {
 			e.printStackTrace();