xiongzhu 4 tahun lalu
induk
melakukan
c0ad8768a6

+ 0 - 2
pics2pic.sql

@@ -1,6 +1,4 @@
-alter table collection_info drop column pic;
 alter table collection_info change pics pic text null;
 
 
-alter table blind_box_item drop column pic;
 alter table blind_box_item change pics pic text null;

+ 14 - 0
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -6,6 +6,7 @@ import com.alipay.api.AlipayClient;
 import com.alipay.api.request.AlipayTradeWapPayRequest;
 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
 import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
+import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
 import com.github.binarywang.wxpay.constant.WxPayConstants;
 import com.github.binarywang.wxpay.exception.WxPayException;
@@ -411,4 +412,17 @@ public class OrderService {
             });
         }
     }
+
+    public void refund(Long id) throws WxPayException {
+        Order order = orderRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        if (order.getStatus() != OrderStatus.FINISH) {
+            throw new BusinessException("订单未付款");
+        }
+        WxPayRefundRequest request = new WxPayRefundRequest();
+        request.setTransactionId(order.getTransactionId());
+        request.setTotalFee(order.getTotalPrice().multiply(BigDecimal.valueOf(100)).intValue());
+        request.setRefundFee(order.getTotalPrice().multiply(BigDecimal.valueOf(100)).intValue());
+        request.setOutRefundNo(String.valueOf(new SnowflakeIdWorker(0, 0).nextId()));
+        wxPayService.refund(request);
+    }
 }

+ 6 - 0
src/main/java/com/izouma/nineth/web/OrderController.java

@@ -1,5 +1,6 @@
 package com.izouma.nineth.web;
 
+import com.github.binarywang.wxpay.exception.WxPayException;
 import com.izouma.nineth.domain.Order;
 import com.izouma.nineth.dto.OrderDTO;
 import com.izouma.nineth.dto.PageQuery;
@@ -87,5 +88,10 @@ public class OrderController extends BaseController {
         order.setHide(true);
         orderRepo.save(order);
     }
+
+    @PostMapping("/refund")
+    public void refund(@RequestParam Long id) throws WxPayException {
+        orderService.refund(id);
+    }
 }
 

+ 1 - 1
src/main/vue/src/views/RecommendList.vue

@@ -13,7 +13,7 @@
         </page-title>
         <div class="filters-container">
             <el-select v-model="type" clearable @change="getData">
-                <el-option v-for="item in typeOptions" :label="item.label" :value="item.value"></el-option>
+                <el-option v-for="item in typeOptions" :label="item.label" :value="item.value" :key="item.value"></el-option>
             </el-select>
             <el-input
                 placeholder="搜索..."

+ 5 - 0
src/test/java/com/izouma/nineth/service/OrderServiceTest.java

@@ -35,4 +35,9 @@ public class OrderServiceTest extends ApplicationTests {
     public void commission() {
         orderService.commission(orderRepo.findById(4437L).get());
     }
+
+    @Test
+    public void refund() throws WxPayException {
+        orderService.refund(4627L);
+    }
 }