xiongzhu 4 سال پیش
والد
کامیت
13d5eac8bd

+ 1 - 0
src/main/java/com/izouma/nineth/security/WebSecurityConfig.java

@@ -93,6 +93,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/user/code2openId").permitAll()
                 .antMatchers("/blindBoxItem/all").permitAll()
                 .antMatchers("/collection/recommend").permitAll()
+                .antMatchers("/order/**/status").permitAll()
                 // all other requests need to be authenticated
                 .anyRequest().authenticated().and()
                 // make sure we use stateless session; session won't be used to

+ 11 - 4
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -254,7 +254,10 @@ public class OrderService {
         Order order = orderRepo.findByIdAndDelFalse(id).orElseThrow(new BusinessException("订单不存在"));
         Collection collection = collectionRepo.findById(order.getCollectionId())
                 .orElseThrow(new BusinessException("藏品不存在"));
-        User invitor = userRepo.findById(order.getInvitor()).orElse(null);
+        User invitor = null;
+        if (order.getInvitor() != null) {
+            invitor = userRepo.findById(order.getInvitor()).orElse(null);
+        }
         if (order.getStatus() != OrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");
         }
@@ -265,6 +268,7 @@ public class OrderService {
         paymentParams.put("app_id", adapayProperties.getAppId());
         paymentParams.put("pay_channel", payChannel);
         paymentParams.put("goods_title", collection.getName());
+        paymentParams.put("goods_desc", collection.getName());
         paymentParams.put("time_expire", DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
                 .format(LocalDateTime.now().plusMinutes(5)));
         paymentParams.put("notify_url", adapayProperties.getNotifyUrl() + "/order/" + order.getId());
@@ -288,7 +292,10 @@ public class OrderService {
             restAmount = divMoney(order.getTotalPrice(), restAmount, divMembers, "0",
                     -1, true);
         }
-        paymentParams.put("div_members", JSON.toJSONString(divMembers));
+        if (divMembers.size() > 1) {
+            paymentParams.put("div_members", JSON.toJSONString(divMembers));
+        }
+
         if (restAmount.compareTo(BigDecimal.ZERO) != 0) {
             log.error("分账出错 {}", JSON.toJSONString(divMembers, SerializerFeature.PrettyFormat));
             throw new BusinessException("分账出错");
@@ -313,9 +320,9 @@ public class OrderService {
         switch (payChannel) {
             case "alipay_wap":
             case "alipay":
-                MapUtils.getString(MapUtils.getMap(response, "expend"), "pay_info");
+                return MapUtils.getString(MapUtils.getMap(response, "expend"), "pay_info");
             case "alipay_qr":
-                MapUtils.getString(MapUtils.getMap(response, "expend"), "qrcode_url");
+                return MapUtils.getString(MapUtils.getMap(response, "expend"), "qrcode_url");
         }
         return response;
     }

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

@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -93,5 +94,13 @@ public class OrderController extends BaseController {
     public void refund(@RequestParam Long id) throws WxPayException {
         orderService.refund(id);
     }
+
+    @GetMapping("/{id}/status")
+    public Object status(@PathVariable Long id) {
+        Order order = orderRepo.findById(id).orElseThrow(new BusinessException("订单不存在"));
+        return new HashMap<>() {{
+            put("status", order.getStatus());
+        }};
+    }
 }
 

+ 2 - 0
src/main/java/com/izouma/nineth/web/OrderPayController.java

@@ -32,6 +32,7 @@ public class OrderPayController {
     private final GiftOrderService giftOrderService;
 
     @RequestMapping(value = "/alipay_h5", method = RequestMethod.GET)
+    @ResponseBody
     public String payOrderAlipayH5(Long id, Model model) throws BaseAdaPayException {
         return (String) orderService.payAdapay(id, "alipay_wap", null);
     }
@@ -40,6 +41,7 @@ public class OrderPayController {
     public String payOrderAlipayWx(Long id, Model model) throws BaseAdaPayException {
         String payUrl = (String) orderService.payAdapay(id, "alipay_wap", null);
         model.addAttribute("payUrl", payUrl);
+        model.addAttribute("orderId", id);
         return "AlipayHtml";
     }
 

+ 10 - 1
src/main/resources/templates/AlipayHtml.ftlh

@@ -132,7 +132,7 @@
         <a id="link" href="alipays://platformapi/startapp?saId=10000007&qrcode=${payUrl?no_esc}">
             <button id="btn-zfb">打开支付宝</button>
         </a>
-        <a id="">
+        <a id="" href="/9th/orders">
             <button id="btn-finish">我已完成支付</button>
         </a>
     </div>
@@ -151,6 +151,15 @@
         }
     }
 
+    setInterval(function () {
+        $.get('/order/${orderId}/status', function (data) {
+            console.log(data);
+            if (data.status !== 'NOT_PAID') {
+                window.location = '/9th/orders';
+            }
+        });
+    }, 1000);
+
     window.onload = function () {
         console.log('onload');
         if (/micromessenger/i.test(navigator.userAgent)) {

+ 1 - 2
src/test/java/com/izouma/nineth/service/AdapayServiceTest.java

@@ -35,11 +35,10 @@ public class AdapayServiceTest extends ApplicationTests {
 
         paymentParams.put("app_id", "app_f8760acc-f4d8-46f6-8f70-d80e36517075");
         paymentParams.put("order_no", "jsdk_payment" + System.currentTimeMillis());
-        paymentParams.put("pay_channel", "alipay");
+        paymentParams.put("pay_channel", "alipay_wap");
         paymentParams.put("pay_amt", "0.10");
         paymentParams.put("goods_title", "your goods title");
         paymentParams.put("goods_desc", "your goods desc");
-        paymentParams.put("div_members", JSON.toJSONString(divMembers));
         paymentParams.put("notify_url", "http://9th.frp.izouma.com/notify/adapay/order/1");
         paymentParams.put("description", "orderId=1");