|
@@ -60,6 +60,7 @@ import com.kmall.manager.manager.merch.OmsMerchProperties;
|
|
|
import com.kmall.manager.manager.merch.OmsMerchPropertiesBuilder;
|
|
|
import com.kmall.manager.manager.print.ticket.PrintTicketPropertiesBuilder;
|
|
|
import com.kmall.manager.manager.print.ticket.TicketPrintUtil;
|
|
|
+import com.kmall.manager.manager.redis.JedisUtil;
|
|
|
import com.kmall.manager.manager.wechat.WechatUtil;
|
|
|
import com.kmall.manager.manager.wechat.wxglobal.dto.WechatGlobalRefundApiResult;
|
|
|
import okhttp3.Request;
|
|
@@ -81,6 +82,9 @@ import java.nio.charset.Charset;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
|
@Service("orderService")
|
|
@@ -2194,31 +2198,31 @@ public class OrderServiceImpl implements OrderService {
|
|
|
|
|
|
// 设置支付单开始时间
|
|
|
processRecordEntity.setPaymentStartTime(new Date());
|
|
|
- // 判断是微信的支付码还是支付宝的支付码
|
|
|
- if (parCode.startsWith("28")) {
|
|
|
- // 支付宝支付
|
|
|
- try {
|
|
|
- AliPay(user, parCode, order, processRecordEntity, orderWXPayRecordCurrent, store);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw e;
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 微信支付
|
|
|
- try {
|
|
|
- wxPay(user, parCode, resultObj, order, processRecordEntity, orderWXPayRecordCurrent, store);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw e;
|
|
|
- }
|
|
|
- }
|
|
|
+// // 判断是微信的支付码还是支付宝的支付码
|
|
|
+// if (parCode.startsWith("28")) {
|
|
|
+// // 支付宝支付
|
|
|
+// try {
|
|
|
+// AliPay(user, parCode, order, processRecordEntity, orderWXPayRecordCurrent, store);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// throw e;
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// // 微信支付
|
|
|
+// try {
|
|
|
+// wxPay(user, parCode, resultObj, order, processRecordEntity, orderWXPayRecordCurrent, store);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// throw e;
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
- //// TODO 到时候要注释掉,测试用而已
|
|
|
-// OrderEntity orderEntity = queryObject(order.getId());
|
|
|
-// orderEntity.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_201.getItem()));
|
|
|
-// orderEntity.setPayStatus(Integer.parseInt(Dict.payStatus.item_2.getItem()));
|
|
|
-// orderEntity.setPayTime(new Date());
|
|
|
-// orderDao.update(orderEntity);
|
|
|
+ // TODO 到时候要注释掉,测试用而已
|
|
|
+ OrderEntity orderEntity = queryObject(order.getId());
|
|
|
+ orderEntity.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_201.getItem()));
|
|
|
+ orderEntity.setPayStatus(Integer.parseInt(Dict.payStatus.item_2.getItem()));
|
|
|
+ orderEntity.setPayTime(new Date());
|
|
|
+ orderDao.update(orderEntity);
|
|
|
|
|
|
|
|
|
resultObj.put("shopName", store.getStoreName()); // 根据门店编号查询
|
|
@@ -2710,21 +2714,44 @@ public class OrderServiceImpl implements OrderService {
|
|
|
return orderDao.queryObjectByOrderSn(orderSn);
|
|
|
}
|
|
|
|
|
|
+ ExecutorService service = Executors.newSingleThreadExecutor();
|
|
|
// 收银端退款的代码
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public synchronized R orderRefund(OrderEntity order, String sessionId, SysUserEntity user) throws Exception {
|
|
|
+ OrderEntity orderInfo = order;
|
|
|
+ if (null == orderInfo) {
|
|
|
+ return R.error("订单不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_401.getItem()) ||
|
|
|
+ orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_402.getItem())) {
|
|
|
+ return R.error("订单已退款");
|
|
|
+ }
|
|
|
+
|
|
|
String payFlag = order.getPayFlag();
|
|
|
|
|
|
- if (Dict.payFlag.item_weixin.getItem().equals(payFlag)) {
|
|
|
- OrderEntity orderInfo = order;
|
|
|
- if (null == orderInfo) {
|
|
|
- return R.error("订单不存在");
|
|
|
- }
|
|
|
- if (orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_401.getItem()) ||
|
|
|
- orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_402.getItem())) {
|
|
|
- return R.error("订单已退款");
|
|
|
+ String key = "kmall_order_refund_" + order.getOrderSn();
|
|
|
+ if (JedisUtil.exists(key)) {
|
|
|
+ return R.error("订单退款操作过快,请等待!");
|
|
|
+ }
|
|
|
+
|
|
|
+ JedisUtil.set(key, System.currentTimeMillis() + "", 2);
|
|
|
+ if (orderInfo.getPayStatus() == Integer.parseInt(Dict.payStatus.item_3.getItem())) {
|
|
|
+ return R.error("订单正在退款中,请勿重复退款");
|
|
|
+ }
|
|
|
+ CountDownLatch cdl = new CountDownLatch(1);
|
|
|
+ service.submit(()-> {
|
|
|
+ try {
|
|
|
+ orderDao.updateOrderRefunding(order.getId());
|
|
|
+ } finally {
|
|
|
+ cdl.countDown();
|
|
|
}
|
|
|
+ });
|
|
|
+ cdl.await();
|
|
|
+
|
|
|
+ if (Dict.payFlag.item_weixin.getItem().equals(payFlag)) {
|
|
|
+
|
|
|
Double totalActualPrice = orderDao.getTotalActualPrice(orderInfo.getMerchOrderSn());
|
|
|
if (totalActualPrice == null) {
|
|
|
totalActualPrice = 0d;
|
|
@@ -2780,14 +2807,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
// 支付宝的退款代码
|
|
|
} else if (Dict.payFlag.item_alipay.getItem().equals(payFlag)) {
|
|
|
|
|
|
- OrderEntity orderInfo = order;
|
|
|
- if (null == orderInfo) {
|
|
|
- return R.error("订单不存在");
|
|
|
- }
|
|
|
- if (orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_401.getItem()) ||
|
|
|
- orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_402.getItem())) {
|
|
|
- return R.error("订单已退款");
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
AliPayMicropayApiResult userRefund = AliPayUtil.aliTradeRefund(order.getOrderSn(), order.getActualPrice().toString(),
|
|
|
"用户退款", order.getStoreId() + "");
|