From af0a37eabe8b9a267c1ba496a7136d6b19436590 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com>
Date: Sun, 15 Sep 2024 17:36:44 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E9=99=90=E5=88=B6=E9=80=80=E6=AC=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/ruoyi/common/core/domain/entity/SmUser.java | 8 ++++++++
.../java/com/ruoyi/ss/user/mapper/SmUserMapper.xml | 9 +++++++++
.../controller/app/AppTransactionBillController.java | 12 +++++++++++-
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/core/domain/entity/SmUser.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/core/domain/entity/SmUser.java
index 9326d081..08726f16 100644
--- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/core/domain/entity/SmUser.java
+++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/core/domain/entity/SmUser.java
@@ -178,4 +178,12 @@ public class SmUser extends BaseEntity
@JsonView(JsonViewProfile.App.class)
@Size(max = 200, message = "限制提现原因长度不能超过200个字符")
private String limitWithdrawReason;
+
+ @Excel(name = "是否限制退款")
+ @ApiModelProperty("是否限制退款")
+ private Boolean limitRefund;
+
+ @Excel(name = "限制退款原因")
+ @ApiModelProperty("限制退款原因")
+ private String limitRefundReason;
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml
index 88aed127..7475b58d 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml
@@ -47,6 +47,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
su.is_real,
su.limit_withdraw,
su.limit_withdraw_reason,
+ su.limit_refund,
+ su.limit_refund_reason,
(select sum(stb.money) from sm_transaction_bill stb where stb.user_id = su.user_id and stb.type = '1' and stb.status = '2') as recharge_amount,
(select sum(stb.arrival_amount) from sm_transaction_bill stb where stb.user_id = su.user_id and stb.type = '2' and stb.status = '14') as with_drawl_amount,
(select sum(stb.arrival_amount) from sm_transaction_bill stb where stb.mch_id = su.user_id and stb.type = '1' and stb.status = '2') as total_income
@@ -69,6 +71,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and withdraw_service_type = #{withdrawServiceType}
and service_type = #{serviceType}
and limit_withdraw = #{limitWithdraw}
+ and limit_refund = #{limitRefund}
and su.user_id in (
select sdt.tenant_id
@@ -164,6 +167,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
is_real,
limit_withdraw,
limit_withdraw_reason,
+ limit_refund,
+ limit_refund_reason,
#{userName},
@@ -199,6 +204,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{isReal},
#{limitWithdraw},
#{limitWithdrawReason},
+ #{limitRefund},
+ #{limitRefundReason},
@@ -244,6 +251,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
is_real = #{isReal},
limit_withdraw = #{limitWithdraw},
limit_withdraw_reason = #{limitWithdrawReason},
+ limit_refund = #{limitRefund},
+ limit_refund_reason = #{limitRefundReason},
where user_id = #{userId}
diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java
index e37e8f11..a9411d5a 100644
--- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java
+++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java
@@ -22,6 +22,8 @@ import com.ruoyi.ss.transactionBill.service.TransactionAssembler;
import com.ruoyi.ss.transactionBill.service.TransactionBillConverter;
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
import com.ruoyi.ss.transactionBill.service.TransactionBillValidator;
+import com.ruoyi.ss.user.domain.SmUserVo;
+import com.ruoyi.ss.user.service.ISmUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -64,6 +66,9 @@ public class AppTransactionBillController extends BaseController
@Autowired
private TransactionBillConverter transactionBillConverter;
+ @Autowired
+ private ISmUserService userService;
+
/**
* 查询充值记录列表
*/
@@ -236,9 +241,14 @@ public class AppTransactionBillController extends BaseController
if (bill == null) {
return error("订单不存在");
}
- if (!Objects.equals(bill.getMchId(), getUserId())) {
+ Long userId = getUserId();
+ if (!Objects.equals(bill.getMchId(), userId )) {
return error("您无权操作退款");
}
+ SmUserVo user = userService.selectSmUserByUserId(userId);
+ if (user.getLimitRefund() != null && user.getLimitRefund()) {
+ return error("退款失败:" + user.getLimitRefundReason());
+ }
LoginUser loginUser = getLoginUser();
dto.setUserName(loginUser.getUsername());
dto.setUserType(loginUser.getLoginType().getType());
From ad2f6bdfba61270d206be7e78f498d92e71bb0aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com>
Date: Mon, 16 Sep 2024 11:07:15 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=BD=BF=E7=94=A8?=
=?UTF-8?q?=E7=8A=B6=E6=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ss/device/service/impl/DeviceServiceImpl.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java
index a479ed94..0a4f4cff 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java
@@ -716,6 +716,8 @@ public class DeviceServiceImpl implements DeviceService
if (CollectionUtils.isEmptyElement(list)) {
return;
}
+ LocalDateTime now = LocalDateTime.now();
+
for (DeviceVO device : list) {
try {
if (StringUtils.isAnyBlank(device.getMac(), device.getModelProductId())) {
@@ -736,6 +738,19 @@ public class DeviceServiceImpl implements DeviceService
data.setSurplusEle(deviceInfo.getM());
}
+ // 判断设备是否正在使用
+ // 时长优先级最高,若当前设备过期时间 > 当前时间,则正在使用
+ boolean hasTime = device.getExpireTime().isAfter(now);
+ // 若当前设备有电量,则正在使用
+ boolean hasEle = device.getSurplusEle().compareTo(BigDecimal.ZERO) > 0;
+ // 若开关开启,则正在使用
+ boolean hasOpen = DevicePowerStatus.ON.getStatus().equals(device.getPowerStatus());
+ if (hasTime || hasEle || hasOpen) {
+ data.setStatus(DeviceStatus.USING.getStatus());
+ } else {
+ data.setStatus(DeviceStatus.NORMAL.getStatus());
+ }
+
// 是否在线
data.setOnlineStatus(iotService.getOnlineStatus(device.getMac(), device.getModelProductId()).getStatus());
From 957ab5abd83f3bfc2fb1a3e706b48ea6c543682a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A3=B7=E5=8F=B6?=
<14103883+leaf-phos@user.noreply.gitee.com>
Date: Mon, 16 Sep 2024 14:34:34 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../common/pay/syb/enums/SybTrxStatus.java | 7 +-
.../common/pay/syb/service/ApiTestV2.java | 82 ++++++++++---------
.../service/impl/PayBillServiceImpl.java | 49 ++++++-----
.../src/main/resources/application-dev.yml | 2 +-
4 files changed, 78 insertions(+), 62 deletions(-)
diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/enums/SybTrxStatus.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/enums/SybTrxStatus.java
index fca4a548..97d6e327 100644
--- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/enums/SybTrxStatus.java
+++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/enums/SybTrxStatus.java
@@ -1,9 +1,10 @@
package com.ruoyi.common.pay.syb.enums;
import lombok.AllArgsConstructor;
-import lombok.Data;
import lombok.Getter;
+import java.util.Map;
+
/**
* 交易结果
* @author wjh
@@ -27,6 +28,10 @@ public enum SybTrxStatus {
return SUCCESS.getCode().equals(code);
}
+ public static boolean isSuccess(Map result) {
+ return result != null && isSuccess(result.get("trxstatus"));
+ }
+
public static SybTrxStatus getByCode(String code) {
for (SybTrxStatus value : SybTrxStatus.values()) {
if (value.getCode().equals(code)) {
diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/ApiTestV2.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/ApiTestV2.java
index c44a63de..09bbbccb 100644
--- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/ApiTestV2.java
+++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/pay/syb/service/ApiTestV2.java
@@ -1,12 +1,9 @@
package com.ruoyi.common.pay.syb.service;
import com.ruoyi.common.core.controller.BaseController;
-import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.math.BigDecimal;
-import java.util.Map;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
@RestController
@@ -16,39 +13,44 @@ public class ApiTestV2 extends BaseController {
@Autowired
private SybPayClient service;
- @GetMapping("/scanPay")
- public AjaxResult testScanPay() throws Exception {
- // TODO Auto-generated method stub
- String reqsn = String.valueOf(System.currentTimeMillis());
- Map map = service.scanPay(1, reqsn, "标题", "备注", "134775931316089668", "", "", "", "");
- return success(map);
- }
-
- @GetMapping("/query")
- public AjaxResult testQuery(@RequestParam String trxid) throws Exception {
- Map map = service.query("", trxid);
- return success(map);
- }
-
- @PostMapping("/refund")
- public AjaxResult testRefund() throws Exception {
- String reqsn = String.valueOf(System.currentTimeMillis());
- Map map = service.refund(1, reqsn, "", "20160712167578.2547");
- return success(map);
- }
-
- @PostMapping("/cancel")
- public AjaxResult testCancel() throws Exception {
- String reqsn = String.valueOf(System.currentTimeMillis());
- Map map = service.cancel(1, reqsn, "112094120001088316", "");
- return success(map);
- }
-
- @PostMapping("/pay")
- public AjaxResult testPay() throws Exception {
-
- String reqsn = String.valueOf(System.currentTimeMillis());
- Map map = service.pay(1L, reqsn, "W06", "标题", "备注", "ol5kD7eeXNGeYE5z7uIhk12K-rBA", "123", "https://test.allinpaygd.com/JWeb/NotifyServlet", "", "", "", "", "", "", "", "", "", "", "", "");
- return success(map);
- }
+// @GetMapping("/scanPay")
+// public AjaxResult testScanPay() throws Exception {
+// // TODO Auto-generated method stub
+// String reqsn = String.valueOf(System.currentTimeMillis());
+// Map map = service.scanPay(1, reqsn, "标题", "备注", "134775931316089668", "", "", "", "");
+// return success(map);
+// }
+//
+// @GetMapping("/query")
+// public AjaxResult testQuery(@RequestParam String trxid) throws Exception {
+// Map map = service.query("", trxid);
+// return success(map);
+// }
+//
+// @PostMapping("/refund")
+// public AjaxResult testRefund(@RequestParam String sn,@RequestParam Integer amount) throws Exception {
+// Map map = service.refund(amount, null, "", sn);
+// return success(map);
+// }
+//
+// @PostMapping("/cancel")
+// public AjaxResult testCancel() throws Exception {
+// String reqsn = String.valueOf(System.currentTimeMillis());
+// Map map = service.cancel(1, reqsn, "112094120001088316", "");
+// return success(map);
+// }
+//
+// @PostMapping("/close")
+// public AjaxResult close(@RequestParam String id, @RequestParam String sn) throws Exception {
+// Map map = service.close(id, sn);
+// return success(map);
+// }
+//
+// @PostMapping("/pay")
+// public AjaxResult testPay() throws Exception {
+//
+// String reqsn = String.valueOf(System.currentTimeMillis());
+// Map map = service.pay(1L, reqsn, "W06", "标题", "备注", "ol5kD7eeXNGeYE5z7uIhk12K-rBA", "123", "https://test.allinpaygd.com/JWeb/NotifyServlet", "", "", "", "", "", "", "", "", "", "", "", "");
+// return success(map);
+// }
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java
index d9bd8ce9..cf1da606 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java
@@ -1,24 +1,20 @@
package com.ruoyi.ss.payBill.service.impl;
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.common.core.redis.enums.RedisLockKey;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.pay.syb.enums.SybTrxStatus;
import com.ruoyi.common.pay.syb.service.SybPayService;
+import com.ruoyi.common.pay.wx.service.WxPayService;
import com.ruoyi.common.pay.wx.util.WxPayUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.SnowFlakeUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.ss.payBill.domain.PayBill;
+import com.ruoyi.ss.payBill.domain.PayBillQuery;
+import com.ruoyi.ss.payBill.domain.PayBillVO;
import com.ruoyi.ss.payBill.domain.bo.PayBillRefundBO;
import com.ruoyi.ss.payBill.domain.bo.RefundSuccessBO;
import com.ruoyi.ss.payBill.domain.dto.PayBillRefundDTO;
@@ -28,23 +24,27 @@ import com.ruoyi.ss.payBill.domain.vo.DoPayVO;
import com.ruoyi.ss.payBill.domain.vo.PayResultVO;
import com.ruoyi.ss.payBill.interfaces.AfterPay;
import com.ruoyi.ss.payBill.interfaces.AfterRefund;
+import com.ruoyi.ss.payBill.mapper.PayBillMapper;
import com.ruoyi.ss.payBill.service.PayBillConverter;
+import com.ruoyi.ss.payBill.service.PayBillService;
import com.ruoyi.ss.refund.domain.RefundVO;
import com.ruoyi.ss.refund.service.RefundConverter;
import com.ruoyi.ss.refund.service.RefundService;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillPayType;
-import com.ruoyi.common.pay.wx.service.WxPayService;
import com.wechat.pay.java.service.payments.model.Transaction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import com.ruoyi.ss.payBill.mapper.PayBillMapper;
-import com.ruoyi.ss.payBill.domain.PayBill;
-import com.ruoyi.ss.payBill.domain.PayBillVO;
-import com.ruoyi.ss.payBill.domain.PayBillQuery;
-import com.ruoyi.ss.payBill.service.PayBillService;
import org.springframework.transaction.support.TransactionTemplate;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
/**
* 支付订单Service业务层处理
*
@@ -165,11 +165,11 @@ public class PayBillServiceImpl implements PayBillService
return null;
};
try {
- return transactionTemplate.execute(status -> {
- // 关闭旧的支付订单
- boolean close = this.closeByBstId(bill.getBstId(), bill.getBstType());
- ServiceUtil.assertion(!close, "关闭旧支付订单失败");
+ // 尝试关闭旧的支付订单
+ boolean close = this.closeByBstId(bill.getBstId(), bill.getBstType());
+ ServiceUtil.assertion(!close, "关闭旧支付订单失败");
+ return transactionTemplate.execute(status -> {
// 插入订单
bill.setStatus(PayBillStatus.PAYING.getStatus());
int insert = this.insertPayBill(bill);
@@ -218,7 +218,16 @@ public class PayBillServiceImpl implements PayBillService
}
// 通联微信
else if (TransactionBillPayType.TL_WX.getType().equals(bill.getChannelId())) {
- sybPayService.closeOrderWx(bill.getPayNo());
+ try {
+ sybPayService.closeOrderWx(bill.getPayNo());
+ } catch (Exception e) {
+ Map result = sybPayService.queryOrderByOutTradeNo(bill.getPayNo());
+ if (SybTrxStatus.isSuccess(result)) {
+ throw new ServiceException("交易已成功,无法关闭");
+ } else {
+ log.error("关闭通联支付订单出错:{}", e.getMessage());
+ }
+ }
}
}
}
@@ -473,7 +482,7 @@ public class PayBillServiceImpl implements PayBillService
} else if (TransactionBillPayType.TL_WX.getType().equals(bill.getChannelId())) {
// 通联微信支付
Map result = sybPayService.queryOrderByOutTradeNo(bill.getPayNo());
- if (SybTrxStatus.isSuccess(result.get("trxstatus"))) {
+ if (SybTrxStatus.isSuccess(result)) {
return PayResultVO.success(DateUtils.toLocalDate(result.get("fintime"), "yyyyMMddHHmmss"));
} else {
return PayResultVO.fail("暂未支付成功");
diff --git a/smart-switch-web/src/main/resources/application-dev.yml b/smart-switch-web/src/main/resources/application-dev.yml
index 16a5d5d7..1d527908 100644
--- a/smart-switch-web/src/main/resources/application-dev.yml
+++ b/smart-switch-web/src/main/resources/application-dev.yml
@@ -26,7 +26,7 @@ wx:
# 转账回调地址
transferNotifyUrl: https://kg-dev.chuangtewl.com/dev-api/app/pay/notify/wx/transfer
# 密钥所在位置
- privateKeyPath: D:/project/证书/wxpay-kg/apiclient_key.pem
+ privateKeyPath: H:/project/创特/证书/wxpay-kg/apiclient_key.pem
# 证书序列号
merchantSerialNumber: 6AD69237C0F22A9AE51A64F1927E3A0962AC1FB0