xiongzhu 4 years ago
parent
commit
b5df52336c

+ 45 - 1
src/main/comos/src/views/Submit.vue

@@ -109,7 +109,8 @@ export default {
             enable_wx_pub: false,
             launchName: '',
             launchPath: '',
-            iosPrice: 0
+            iosPrice: 0,
+            createOrderTimer: null
         };
     },
     computed: {
@@ -132,6 +133,9 @@ export default {
     },
     beforeRouteLeave(to, from, next) {
         console.log(to);
+        if (this.createOrderTimer) {
+            clearInterval(this.createOrderTimer);
+        }
         if (to.path !== '/couponList') {
             this.$store.commit('setCouponInfo', null);
         }
@@ -250,6 +254,46 @@ export default {
                     });
                 });
         },
+        createOrder() {
+            if (!this.payType) {
+                this.$toast('请选择支付方式');
+                return;
+            }
+            this.$toast.loading('请不要离开当前页面');
+
+            let params = {
+                collectionId: this.$route.query.id,
+                qty: 1,
+                couponId: (this.couponInfo || {}).id || '',
+                invitor: sessionStorage.getItem('invitor')
+            };
+            return this.$http.post('/order/mqCreate', params).then(res => {
+                return new Promise((resolve, reject) => {
+                    let checkOrder = () => {
+                        this.$http
+                            .get('/order/createResult', { id: res.id })
+                            .then(res => {
+                                if (res) {
+                                    clearInterval(this.createOrderTimer);
+                                    this.createOrderTimer = null;
+                                    if (res.success) {
+                                        resolve(res.data);
+                                    } else {
+                                        reject({ error: res.data });
+                                    }
+                                }
+                            })
+                            .catch(e => {
+                                clearInterval(this.createOrderTimer);
+                                this.createOrderTimer = null;
+                                reject(e);
+                            });
+                    };
+                    setTimeout(checkOrder, 500);
+                    this.createOrderTimer = setInterval(checkOrder, 2000);
+                });
+            });
+        },
         submit() {
             if (!this.payType) {
                 this.$toast('请选择支付方式');

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

@@ -29,6 +29,7 @@ import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.*;
 import com.izouma.nineth.security.Authority;
 import com.izouma.nineth.utils.JpaUtils;
+import com.izouma.nineth.utils.SecurityUtils;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -677,6 +678,23 @@ public class OrderService {
         wxPayService.refund(request);
     }
 
+    public Object queryCreateOrder(String id) {
+        Object res = redisTemplate.opsForValue().get(RedisKeys.CREATE_ORDER + id);
+        if (res != null) {
+            if (res instanceof Map) {
+                if (MapUtils.getBooleanValue((Map) res, "success", false)) {
+                    Order order = (Order) MapUtils.getObject((Map) res, "data");
+                    if (!SecurityUtils.getAuthenticatedUser().getId().equals(order.getUserId())) {
+                        log.error("queryCreateOrder userId错误 requestUserId={} orderUserId={}",
+                                SecurityUtils.getAuthenticatedUser().getId(), order.getUserId());
+                        return null;
+                    }
+                }
+            }
+        }
+        return res;
+    }
+
     // 获取订单锁,有效时间1小时
     public boolean getOrderLock(Long orderId) {
         BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps(RedisKeys.ORDER_LOCK + orderId);

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

@@ -122,5 +122,11 @@ public class OrderController extends BaseController {
             orderRepo.save(order);
         });
     }
+
+    @GetMapping("/createResult")
+    public Object createResult(@RequestParam String id) {
+        return orderService.queryCreateOrder(id);
+    }
+
 }