From 774d539630e85ec98b6eeac007a659c635207720 Mon Sep 17 00:00:00 2001 From: zhouwentao <1577701412@qq.com> Date: Wed, 26 Jun 2024 13:43:37 +0800 Subject: [PATCH] =?UTF-8?q?updates=20=E6=8A=96=E9=9F=B3=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/config/DouYinConfig.java | 23 ++++++++++ .../mini/douyin/model/DouYinOrderModel.java | 3 ++ .../modules/mini/douyin/util/DouYinUtil.java | 11 +++-- .../yx/controller/YxOrderController.java | 42 ++++++++++++++++++- .../org/jeecg/modules/yx/entity/YxOrder.java | 3 ++ .../src/main/resources/application.yml | 3 +- 6 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/config/DouYinConfig.java diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/config/DouYinConfig.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/config/DouYinConfig.java new file mode 100644 index 0000000..41abb8c --- /dev/null +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/config/DouYinConfig.java @@ -0,0 +1,23 @@ +package org.jeecg.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import java.io.Serializable; + +/** + * @author ZhouWenTao + * @create 2024-06-26-13:03 + */ +@Data +@Component +@ConfigurationProperties(prefix = "dy") +public class DouYinConfig implements Serializable { + private String appId; + private String appSecret; + private String token; + private String notifyUrl;// 支付回调地址 + private String refundNotifyUrl;// 退款回调地址 + private String salt; +} diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mini/douyin/model/DouYinOrderModel.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mini/douyin/model/DouYinOrderModel.java index 3e1d0cd..2f35c1c 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mini/douyin/model/DouYinOrderModel.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mini/douyin/model/DouYinOrderModel.java @@ -2,6 +2,8 @@ package org.jeecg.modules.mini.douyin.model; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; import java.io.Serializable; @@ -11,6 +13,7 @@ import java.io.Serializable; * 官方文档 https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/ecpay/pay-list/pay */ @Data +@Component public class DouYinOrderModel implements Serializable { //小程序APPID private String app_id; diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mini/douyin/util/DouYinUtil.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mini/douyin/util/DouYinUtil.java index 6bf5669..5bd417f 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mini/douyin/util/DouYinUtil.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mini/douyin/util/DouYinUtil.java @@ -103,14 +103,14 @@ public class DouYinUtil { /** * 订单同步 */ - public static void orderRefund(String orderCode,String appId,Long refundAmount,String salt,String notifyUrl){ + public static String orderRefund(String orderCode,String appId,Long refundAmount,String refundReason,String salt,String notifyUrl){ log.debug("抖音订单退款----订单号:"+orderCode); //文档 https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/ecpay/refund-list/refund Map testCase = new HashMap() {{ put("app_id", appId); put("out_order_no", orderCode);// 商户分配支付单号,标识进行退款的订单 put("out_refund_no","tk_"+orderCode);// 商户分配退款号,保证在商户中唯一 - put("reason","不想要了");// 退款原因 + put("reason",refundReason);// 退款原因 put("refund_amount", refundAmount);// 退款金额 put("cp_extra", "一些附加信息"); put("notify_url", notifyUrl); @@ -121,7 +121,12 @@ public class DouYinUtil { String douyinUrl="https://developer.toutiao.com/api/apps/ecpay/v1/create_refund"; testCase.put("sign",sign); JSONObject post = RestUtil.post(douyinUrl, JSONObject.parseObject(JSONObject.toJSONString(testCase))); + Integer errNo = post.getInteger("err_no"); log.debug("抖音退款结果----:"+post.toJSONString()); + if (!errNo.equals(0)) { + return post.getString("err_tips"); + } + return null; } public static void main(String[] args) { @@ -130,7 +135,7 @@ public class DouYinUtil { // String notifyUrl = "https://yitisheng.vip/py/dy/payNotify"; Long refundAmount = 100l; String appId = "tt59a72f1ac6964bfa01"; - orderRefund(orderCode,appId,refundAmount,"wODf6Bg5BXndJ3IELXNb1w5CDMRjatXAmZVP2DQ7",notifyUrl); + orderRefund(orderCode,appId,refundAmount,"不想要了","wODf6Bg5BXndJ3IELXNb1w5CDMRjatXAmZVP2DQ7",notifyUrl); /* long time = new Date().getTime(); String js="{\"count\":7800,\"dates\":[\"2016-09\",\"2018-06\",\"2019-07\",\"2020-01\",\"2022-03\",\"2024-05\"],\"description\":\"☘\uFE0F 如果喜欢秒达工具箱,请收藏和分享本网址MDGJX.COM(首拼缩写)\",\"info\":{\"codeGenTarget\":\"ES5\",\"extraLibs\":[],\"info\":{\"codeGenTarget\":\"ES5\",\"extraLibs\":[],\"info\":{\"codeGenTarget\":\"ES5\",\"extraLibs\":[],\"info\":{\"codeGenTarget\":\"ES5\",\"extraLibs\":[],\"moduleGenTarget\":\"\",\"noImplicitAny\":true,\"noLib\":false,\"scope\":\"/\",\"semanticValidation\":true,\"syntaxValidation\":true},\"moduleGenTarget\":\"\",\"noImplicitAny\":true,\"noLib\":false,\"scope\":\"/\",\"semanticValidation\":true,\"syntaxValidation\":true},\"moduleGenTarget\":\"\",\"noImplicitAny\":true,\"noLib\":false,\"scope\":\"/\",\"semanticValidation\":true,\"syntaxValidation\":true},\"moduleGenTarget\":\"\",\"noImplicitAny\":true,\"noLib\":false,\"scope\":\"/\",\"semanticValidation\":true,\"syntaxValidation\":true},\"link\":\"https://mdgjx.com\",\"name\":\"秒达工具箱\"}"; JSONObject jsonObject = null; diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/yx/controller/YxOrderController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/yx/controller/YxOrderController.java index 5a8651c..c693f62 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/yx/controller/YxOrderController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/yx/controller/YxOrderController.java @@ -1,5 +1,6 @@ package org.jeecg.modules.yx.controller; +import java.math.BigDecimal; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -7,13 +8,18 @@ import java.util.stream.Collectors; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.common.util.AssertUtils; import org.jeecg.common.util.oConvertUtils; +import org.jeecg.config.DouYinConfig; +import org.jeecg.modules.mini.douyin.util.DouYinUtil; +import org.jeecg.modules.yx.constant.YxConstant; import org.jeecg.modules.yx.entity.YxOrder; import org.jeecg.modules.yx.service.IYxOrderService; @@ -29,6 +35,7 @@ import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecg.common.system.base.controller.JeecgController; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -52,7 +59,8 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; public class YxOrderController extends JeecgController { @Autowired private IYxOrderService yxOrderService; - + @Resource + private DouYinConfig douYinConfig; /** * 分页列表查询 * @@ -108,6 +116,38 @@ public class YxOrderController extends JeecgController return Result.OK("编辑成功!"); } + /** + * 编辑 + * + * @param yxOrder + * @return + */ + @AutoLog(value = "订单表-退款") + @ApiOperation(value="订单表-退款", notes="订单表-退款") + @RequiresPermissions("yx:yx_order:edit") + @RequestMapping(value = "/refund", method = {RequestMethod.PUT,RequestMethod.POST}) + public Result refund(@RequestBody YxOrder yxOrder) { + AssertUtils.notNull(yxOrder.getId(),"请求参数有误"); + AssertUtils.notNull(yxOrder.getRefundAmount(),"请输入退款金额"); + AssertUtils.notNull(yxOrder.getRefundReason(),"请输入退款原因"); + YxOrder order = yxOrderService.getById(yxOrder.getId()); + AssertUtils.notNull(order,"请求参数有误"); + // 目前仅支持抖音退款 + AssertUtils.isTrue("toutiao".equals(order.getProvider()),"暂不支持该平台退款"); + //处理金额为分单位 + BigDecimal refundAmount = yxOrder.getRefundAmount(); + BigDecimal multiply = refundAmount.multiply(YxConstant.bigDecimal100); + long refundAmountLong = multiply.longValue(); + String refundOverMessage = DouYinUtil.orderRefund(order.getOrderCode(), douYinConfig.getAppId(), refundAmountLong,yxOrder.getRefundReason(), douYinConfig.getSalt(), douYinConfig.getRefundNotifyUrl()); + if (StringUtils.isNotBlank(refundOverMessage)) { + // 退款失败 + return Result.error(refundOverMessage); + } + // 退款成功,等待抖音回调 + /*yxOrderService.updateById(yxOrder);*/ + return Result.OK("操作成功,请等待后刷新!"); + } + /** * 通过id删除 * diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/yx/entity/YxOrder.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/yx/entity/YxOrder.java index 8683459..cd2992b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/yx/entity/YxOrder.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/yx/entity/YxOrder.java @@ -108,6 +108,9 @@ public class YxOrder implements Serializable { @ApiModelProperty(value = "抖音商户退款号") private String refundNo; + @ApiModelProperty(value = "退款原因") + private String refundReason; + //================== @TableField(exist = false) private String skuName; diff --git a/jeecg-module-system/jeecg-system-start/src/main/resources/application.yml b/jeecg-module-system/jeecg-system-start/src/main/resources/application.yml index 1dfbc14..e81136b 100644 --- a/jeecg-module-system/jeecg-system-start/src/main/resources/application.yml +++ b/jeecg-module-system/jeecg-system-start/src/main/resources/application.yml @@ -30,6 +30,7 @@ dy: appId: tt59a72f1ac6964bfa01 appSecret: 46882267247ca02561cf899d03adf562aa93ad3e token: a1b2c3 - # 回调接口地址 + #支付 回调接口地址 notifyUrl: https://yitisheng.vip/jbt/mini/pay/v1/payNotify + refundNotifyUrl: https://yitisheng.vip/jbt/mini/pay/v1/dy/payNotify salt: wODf6Bg5BXndJ3IELXNb1w5CDMRjatXAmZVP2DQ7