Browse Source

取消订单接口修改

weifanli 3 years ago
parent
commit
5001ec8c1d

+ 29 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentTimeServiceImpl.java

@@ -95,19 +95,45 @@ public class StudentTimeServiceImpl extends ServiceImpl<StudentTimeDao, StudentT
         param.put("startTime", query.getStartTime());
         param.put("endTime", query.getEndTime());
         List<Map<String, Object>> mallDataList = mallAdminFeignService.userOrderInfoList(param).getData();
-        Map<Long, LocalDateTime> timeMap = new HashMap<>();
+        Map<Long, Date> timeMap = new HashMap<>();
+        if (CollectionUtils.isEmpty(mallDataList)) {
+            return;
+        }
+
         for (Map<String, Object> data : mallDataList) {
             try {
                 Long userId = Long.valueOf(data.get("userId").toString());
                 Date receiveTime = new Date(Long.valueOf(data.get("receiveTime").toString()));
-
+                timeMap.put(userId, receiveTime);
             } catch (Exception e) {
                 log.error("统计学生首次使用时间异常,param is {}", JSONObject.toJSONString(data));
                 continue;
             }
         }
-        List<Long> userIds = orderList.stream().map(UserOrder::getUserId).collect(Collectors.toList());
 
+        List<StudentTime> studentTimes = baseMapper.selectBatchIds(timeMap.keySet());
+        Map<Long, StudentTime> mallStudentTimeMap = new HashMap<>();
+        for (StudentTime studentTime : studentTimes) {
+            mallStudentTimeMap.put(studentTime.getUserId(), studentTime);
+        }
+
+        for (Long userId : timeMap.keySet()) {
+            StudentTime studentTime = mallStudentTimeMap.get(userId);
+            if (null == studentTime) {
+                studentTime = new StudentTime();
+            }
+
+            if (null == studentTime.getFirstMallTime()) {
+                studentTime.setFirstMallTime(timeMap.get(userId));
+            }
+
+            if (null == studentTime.getUserId()) {
+                studentTime.setUserId(userId);
+                baseMapper.insert(studentTime);
+            } else {
+                baseMapper.updateById(studentTime);
+            }
+        }
 
     }
 

+ 20 - 18
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserOrderServiceImpl.java

@@ -765,24 +765,6 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
             return;
         }
 
-        UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(userOrder.getOrderNo());
-        if (null != orderPayment) {
-            //更新付款单
-            orderPayment.setStatus(TradeStatusEnum.failed);
-            orderPayment.setPayFailMsg(StringUtil.isEmpty(reason) ? "交易取消" : reason);
-            orderPayment.setUpdateTime(new Date());
-            //发送支付关单请求
-            HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.closePayment(userOrder.getTransNo(), reason, "");
-            if (!responseResult.getStatus()) {
-                orderPayment.setCloseStatus(TradeStatusEnum.failed);
-                orderPayment.setCloseFailMsg(responseResult.getMsg());
-                orderPaymentService.updateById(orderPayment);
-                return;
-            } else {
-                orderPayment.setCloseStatus(TradeStatusEnum.pending);
-                orderPaymentService.updateById(orderPayment);
-            }
-        }
         List<UserOrderDetailVo> orderDetailList = orderDetailService.getOrderDetilListByOrderNo(userOrder.getOrderNo());
         for (UserOrderDetailVo orderDetailVo : orderDetailList) {
             orderDetailVo.setUserId(userOrder.getUserId());
@@ -797,6 +779,26 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         userOrder.setStatus(orderStatus);
         userOrder.setUpdateTime(new Date());
         baseMapper.updateById(userOrder);
+
+
+        UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(userOrder.getOrderNo());
+        if (null != orderPayment) {
+            //更新付款单
+            orderPayment.setStatus(TradeStatusEnum.failed);
+            orderPayment.setPayFailMsg(StringUtil.isEmpty(reason) ? "交易取消" : reason);
+            orderPayment.setUpdateTime(new Date());
+        }
+        //发送支付关单请求
+        HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.closePayment(userOrder.getTransNo(), reason, "");
+        if (!responseResult.getStatus()) {
+            orderPayment.setCloseStatus(TradeStatusEnum.failed);
+            orderPayment.setCloseFailMsg(responseResult.getMsg());
+            orderPaymentService.updateById(orderPayment);
+            return;
+        } else {
+            orderPayment.setCloseStatus(TradeStatusEnum.pending);
+            orderPaymentService.updateById(orderPayment);
+        }
     }
 
     void orderSuccess(UserOrderVo detail) {