yubin 6 дней назад
Родитель
Сommit
62aeb90ff0

+ 5 - 0
mall-api/src/main/java/com/txz/mall/dto/StorePinkSummaryDTO.java

@@ -21,6 +21,11 @@ public class StorePinkSummaryDTO implements Serializable {
      */
     private BigDecimal totalPrice;
 
+    /**
+     * 团购编码
+     */
+    private String code;
+
     /**
      * 拼团商品id
      */

+ 59 - 3
mall-service/src/main/java/com/txz/mall/business/impl/OrderServiceBusinessImpl.java

@@ -8,6 +8,7 @@ import com.txz.mall.core.RedisUtil;
 import com.txz.mall.core.ServiceException;
 import com.txz.mall.dao.StorePinkMapper;
 import com.txz.mall.dubbo.client.CifUserDubboServiceClient;
+import com.txz.mall.enums.PinkOrderStatusEnum;
 import com.txz.mall.model.*;
 import com.txz.mall.service.*;
 import lombok.AllArgsConstructor;
@@ -81,6 +82,58 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
         return vo;
     }
 
+//
+//    @Override
+//    public List<StoreCombinationRankVO> getRank() {
+//        List<StoreCombinationRankVO> list = new ArrayList<>();
+//        String key = "order:rank:";
+//        boolean exists = redisUtil.hasKey("order:rank");
+//        if (exists) {
+//            String orderVoString = redisUtil.get(key).toString();
+//            list = JSONObject.parseArray(orderVoString, StoreCombinationRankVO.class);
+//            return list;
+//        }
+//
+//        Condition orderCondition = new Condition(StoreOrder.class);
+//        Example.Criteria orderCriteria = orderCondition.createCriteria();
+//        Date date = new Date();
+//        Date startDate = DateUtil.beginOfDay(DateUtils.addDays(date, -7));
+//        Date endDate = DateUtil.endOfDay(date);
+//        orderCriteria.andEqualTo("isDelete", 0);
+//        orderCriteria.andBetween("createTime", startDate, endDate);
+//        orderCriteria.andEqualTo("paid", 1);
+//        List<StoreOrder> orderList = storeOrderService.findByCondition(orderCondition);
+//        Map<Long, Long> combinationCountMap = orderList.stream()
+//                .collect(Collectors.groupingBy(
+//                        StoreOrder::getCombinationId,
+//                        Collectors.counting()
+//                ));
+//
+//        // 获取前10个热门商品组合
+//        List<Map.Entry<Long, Long>> topCombinations = combinationCountMap.entrySet()
+//                .stream()
+//                .sorted(Map.Entry.<Long, Long>comparingByValue().reversed())
+//                .collect(Collectors.toList());
+//
+//        List<StoreCombination> combinationList = storeCombinationService.findByIds(String.join(",", topCombinations.stream().map(Map.Entry::getKey).map(Object::toString).collect(Collectors.toList())));
+//        for (StoreCombination storeCombination : combinationList) {
+//            List<StoreCombination> collect = combinationList.stream().filter(c -> c.getId().equals(storeCombination.getId())).collect(Collectors.toList());
+//            if (CollectionUtils.isNotEmpty(collect)) {
+//                StoreCombination combination = collect.get(0);
+//                StoreCombinationRankVO rankVO = new StoreCombinationRankVO();
+//                rankVO.setProductId(combination.getProductId());
+//                rankVO.setProductName(combination.getProductName());
+//                rankVO.setSales(combination.getSales());
+//                rankVO.setImage(combination.getImage());
+//                rankVO.setPrice(combination.getPrice());
+//                list.add(rankVO);
+//            }
+//        }
+//        redisUtil.set(key, list);
+//        return list;
+//    }
+
+
 
     @Override
     public List<StoreCombinationRankVO> getRank() {
@@ -100,7 +153,12 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
         Date endDate = DateUtil.endOfDay(date);
         orderCriteria.andEqualTo("isDelete", 0);
         orderCriteria.andBetween("createTime", startDate, endDate);
-        orderCriteria.andEqualTo("paid", 1);
+        List<Integer> statusList = new ArrayList<>();
+        statusList.add(PinkOrderStatusEnum.GROUP_ORDER_TO_RECEVIE.getKey());
+        statusList.add(PinkOrderStatusEnum.GROUP_ORDER_TO_SHIP.getKey());
+        statusList.add(PinkOrderStatusEnum.GROUP_ORDER_COMPLETED.getKey());
+        statusList.add(PinkOrderStatusEnum.GROUP_ORDER_TO_CLOSED.getKey());
+        orderCriteria.andIn("status", statusList);
         List<StoreOrder> orderList = storeOrderService.findByCondition(orderCondition);
         Map<Long, Long> combinationCountMap = orderList.stream()
                 .collect(Collectors.groupingBy(
@@ -133,6 +191,4 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
     }
 
 
-
-
 }

+ 7 - 0
mall-service/src/main/java/com/txz/mall/dao/StoreOrderMapper.java

@@ -2,6 +2,13 @@ package com.txz.mall.dao;
 
 import com.txz.mall.core.Mapper;
 import com.txz.mall.model.StoreOrder;
+import vo.StoreCombinationRankVO;
+
+import java.util.List;
 
 public interface StoreOrderMapper extends Mapper<StoreOrder> {
+
+
+    List<StoreCombinationRankVO> getRank();
+
 }

+ 1 - 1
mall-service/src/main/java/com/txz/mall/dubbo/client/CifAccountDubboServiceClient.java

@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
 @Component
 public class CifAccountDubboServiceClient {
 
-    @Reference
+    @Reference(timeout = 120000)
     private AccountDubboService accountDubboService;
 
     /**

+ 18 - 0
mall-service/src/main/java/com/txz/mall/model/StorePinkSummary.java

@@ -21,6 +21,13 @@ public class StorePinkSummary {
     @Column(name = "total_price")
     private BigDecimal totalPrice;
 
+
+    /**
+     * 团购编码
+     */
+    @Column(name = "code")
+    private String code;
+
     /**
      * 拼团商品id
      */
@@ -489,4 +496,15 @@ public class StorePinkSummary {
     public void setIsDelete(Integer isDelete) {
         this.isDelete = isDelete;
     }
+
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+
 }

+ 4 - 4
mall-service/src/main/java/com/txz/mall/service/StoreOrderService.java

@@ -5,10 +5,7 @@ import com.txz.mall.core.Service;
 import com.txz.mall.model.StoreOrder;
 import dto.*;
 import org.springframework.web.multipart.MultipartFile;
-import vo.MyRecord;
-import vo.OrderRefundApplyVO;
-import vo.StoreOrderCountItemVO;
-import vo.StoreOrderVO;
+import vo.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
@@ -167,4 +164,7 @@ public interface StoreOrderService extends Service<StoreOrder> {
 
     void batchSigning();
 
+
+    List<StoreCombinationRankVO> getRank();
+
 }

+ 23 - 6
mall-service/src/main/java/com/txz/mall/service/impl/StoreOrderServiceImpl.java

@@ -186,10 +186,14 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
         if (storeOrder == null) {
             throw new ServiceException("订单不存在");
         }
+        UserDTO user = userDubboServiceClient.getUser(storeOrder.getUid());
         StorePink storePink = new StorePink();
-        //        storePink.setUid(user.getUid());
-        //        storePink.setAvatar(user.getAvatar());
-        //        storePink.setNickname(user.getNickname());
+        if(!ObjectUtils.isEmpty(user)){
+            storePink.setAvatar(user.getHeadPic());
+            storePink.setNickname(user.getName());
+        }
+
+        storePink.setUid(storeOrder.getUid());
         storePink.setOrderId(storeOrder.getOrderId());
         storePink.setOrderIdKey(storeOrder.getId());
         storePink.setTotalNum(storeOrder.getTotalNum());
@@ -214,6 +218,9 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
         storePinkSummary.setTotalPrice(storeOrder.getTotalPrice());
         storePinkSummary.setCid(storeCombination.getId());
         storePinkSummary.setPid(storeCombination.getProductId());
+
+        String tgCode = OrderUtils.getTGCode();
+        storePinkSummary.setCode(tgCode);
         storePinkSummary.setPeople(storeCombination.getPeople());
         storePinkSummary.setAddTime(date);
         Integer effectiveTime1 = storeCombination.getEffectiveTime();
@@ -351,8 +358,13 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
         storePink.setOrderStatus(PinkOrderStatusEnum.GROUP_ORDER_TO_PAY.getKey());
         storePink.setIsRefund(0);
         storePink.setKId(1);
-//            storePink.setAvatar();
-//            storePink.setNickname();
+        UserDTO user = userDubboServiceClient.getUser(dto.getUserId());
+        if(!ObjectUtils.isEmpty(user)){
+            storePink.setUid(dto.getUserId());
+            storePink.setAvatar(user.getHeadPic());
+            storePink.setNickname(user.getName());
+        }
+
         storePink.setCreateTime(date);
         storePinkService.save(storePink);
         
@@ -1668,7 +1680,7 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
         if (result.getCode().equals(ResultCode.SUCCESS.getCode())) {
             AccountDTO accountDTO = JSONObject.parseObject(JSONObject.toJSONString(result.getData()), AccountDTO.class);
             if (accountDTO.getBalance().compareTo(storeOrder.getPayPrice()) < 0) {
-                throw new ServiceException(ResultCode.INSUFFICIENT_BALANCE.getMessage()+"uid:"+storeOrder.getUid());
+                throw new ServiceException(ResultCode.INSUFFICIENT_BALANCE);
             }
         } else {
             throw new ServiceException("获取用户钱包账户失败");
@@ -2288,5 +2300,10 @@ public class StoreOrderServiceImpl extends AbstractService<StoreOrder> implement
 
     }
 
+    @Override
+    public List<StoreCombinationRankVO> getRank() {
+
 
+        return null;
+    }
 }

+ 40 - 15
mall-service/src/main/java/com/txz/mall/service/impl/StorePinkServiceImpl.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.txz.cif.dto.Result;
 import com.txz.cif.dto.UserDTO;
 import com.txz.cif.param.AccomplishParam;
+import com.txz.cif.param.OrderParam;
 import com.txz.mall.constants.Constants;
 import com.txz.mall.core.AbstractService;
 import com.txz.mall.core.ServiceException;
@@ -173,11 +174,17 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
         criteria.andEqualTo("orderStatus", PinkOrderStatusEnum.GROUP_ORDER_PAID.getKey());
         List<StorePink> list = findByCondition(condition);
         if (CollUtil.isEmpty(list)) {
-            throw new ServiceException("没有拼团订单");
+            throw new ServiceException("没有拼团订单"+spsId);
         }
         long count = list.stream().filter(i -> i.getLId().equals(1)).count();
         if (count >= luckNum) {
-            throw new ServiceException("已有天选");
+            throw new ServiceException("已有天选"+spsId);
+        }
+
+
+        StorePinkSummary storePinkSummary = storePinkSummaryService.findById(spsId);
+        if(ObjectUtils.isEmpty(storePinkSummary)){
+            throw new ServiceException("没有拼团汇总记录"+spsId);
         }
 
 
@@ -186,6 +193,12 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
         List<Long> idCollect = list.stream().map(StorePink::getId).collect(Collectors.toList());
         List<Long> randomIds = RandomUtil.uniqueRandom(idCollect, (int) luckNum);
 
+        AccomplishParam param = new AccomplishParam();
+
+        param.setBizNo(storePinkSummary.getCode());
+        param.setBizId(storePinkSummary.getId()+"");
+        List<OrderParam> orderParamList = new ArrayList<>();
+
         //选出中奖单号 推进状态
         randomIds.forEach(i -> {
             StorePink luckPink = new StorePink();
@@ -207,11 +220,22 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
 
             storeOrderStatusService.createLog(storeOrder.getId(), Constants.ORDER_STATUS_PINK_SUCCESS_ORDER, "拼团成功");
 
+            //中奖者
+            param.setWinnerOrderNo(storeOrder.getOrderId());
+            param.setWinnerUserId(storeOrder.getUid());
+            Integer kId = storePink.getKId();
+            Integer zero = 0;
+            if(zero.equals(kId)){
+                param.setOpenGroupUserId(storeOrder.getUid());
+                param.setOpenOrderNo(storeOrder.getOrderId());
+            }
             //获奖者的状态联动已经完成了所以把他从列表中移除
             list.remove(storePink);
         });
 
 
+
+        param.setTransTime(date);
         //将所有参团成员的status设置为 已开奖
         list.forEach(a->{
 
@@ -241,28 +265,29 @@ public class StorePinkServiceImpl extends AbstractService<StorePink> implements
 
 
             //非天选之子给他退款
-            AccomplishParam param = new AccomplishParam();
-            param.setBizNo(storeOrder.getOrderId());
-            param.setBizId(storeOrder.getId().toString());
-            List<Long> userIds = CollUtil.newArrayList(storeOrder.getUid());
-            param.setUserIds(userIds);
+            OrderParam orderParam = new OrderParam();
+            orderParam.setOrderId(storeOrder.getId()+"");
+            orderParam.setUserId(storeOrder.getUid());
+            orderParam.setOrderNo(storeOrder.getOrderId());
+
             Integer kId = a.getKId();
             Integer zero = 0;
             if(zero.equals(kId)){
                 param.setOpenGroupUserId(storeOrder.getUid());
+                param.setOpenOrderNo(storeOrder.getOrderId());
             }
-
+            //当前只能拼1个商品 所以理论上这个价格都是一样的,这边就循环覆盖即可
             param.setAmount(storeOrder.getPayPrice());
-            param.setTransTime(date);
-            Result result = cifAccountDubboServiceClient.accomplishGroup(param);
-
-            if(!result.getCode().equals("200")){
-                throw new ServiceException("拼团成团未中奖用户退款失败message:"+result.getMessage());
-            }
-
+            orderParamList.add(orderParam);
 
         });
+        param.setUserIds(orderParamList);
 
+        Result result = cifAccountDubboServiceClient.accomplishGroup(param);
+
+        if(!result.getCode().equals("200")){
+            throw new ServiceException("拼团成团未中奖用户退款失败message:"+result.getMessage());
+        }
 
 
 

+ 17 - 0
mall-service/src/main/java/com/txz/mall/util/OrderUtils.java

@@ -14,6 +14,12 @@ public class OrderUtils {
      * 订单类别头
      */
     private static final String ORDER_CODE = "DD";
+
+    /**
+     * 团购类别头
+     */
+    private static final String TG_CODE = "TG";
+
     /**
      * 签到类别头
      */
@@ -99,6 +105,17 @@ public class OrderUtils {
         return SnowFlakeUtil.getDefaultSnowFlakeId();
     }
 
+
+    /**
+     * 团购编码
+     * @return
+     */
+    public static String getTGCode() {
+        return TG_CODE + getCode();
+    }
+
+
+
     /**
      * 生成订单单号编码(调用方法)
      */

+ 6 - 0
mall-service/src/main/resources/mapper/StoreOrderMapper.xml

@@ -65,4 +65,10 @@
         <result column="is_alter_price" jdbcType="INTEGER" property="isAlterPrice"/>
         <result column="out_trade_no" jdbcType="VARCHAR" property="outTradeNo"/>
     </resultMap>
+
+
+
+
+
+
 </mapper>