Parcourir la source

管乐迷商城改造

zouxuan il y a 1 an
Parent
commit
1ddb7cdb83

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderDetailService.java

@@ -1,11 +1,13 @@
 package com.ym.mec.biz.service;
 
 import com.ym.mec.biz.dal.dao.StudentPaymentOrderDetailDao;
+import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.dto.MusicalListDetailDto;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.BaseService;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -154,4 +156,6 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
                            StudentRegistration studentRegistration, List<StudentPaymentOrderDetail> allDetails);
 
     List<StudentPaymentOrderDetail> findByOrderId(Long paymentOrderId);
+
+    List<StudentPaymentOrderDetail> initStudentPaymentOrderDetail(StudentPaymentOrder studentPaymentOrder, List<GoodsSellDto> goodsSellDtos);
 }

+ 74 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service.impl;
 
 import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.dto.MusicalListDetailDto;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
@@ -860,4 +861,77 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
         }
         return paymentOrderDetails;
     }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public List<StudentPaymentOrderDetail> initStudentPaymentOrderDetail(StudentPaymentOrder studentPaymentOrder, List<GoodsSellDto> goodsSellDtos){
+        Date date = new Date();
+        //添加订单详情
+        List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
+        // 添加studentPaymentOrderDetail
+        StudentPaymentOrderDetail studentPaymentOrderDetail = null;
+
+        BigDecimal totalPrice = BigDecimal.ZERO;
+
+        if (goodsSellDtos != null) {
+            StringBuffer sb = new StringBuffer();
+            for (GoodsSellDto goodsSellDto : goodsSellDtos) {
+                for (int i = 0; i < goodsSellDto.getGoodsNum(); i++) {
+                    sb.append(goodsSellDto.getGoodsId()).append(",");
+                }
+            }
+            String goodsIdsStr = StringUtils.removeEnd(sb.toString(), ",");
+
+            List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr);
+            Map<Integer, Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getId, t -> t));
+            BigDecimal totalGroupPurchasePrice =
+                    goodsSellDtos.stream().map(t -> goodsMap.get(t.getGoodsId()).getGroupPurchasePrice().
+                            multiply(new BigDecimal(t.getGoodsNum()))).reduce(BigDecimal.ZERO, BigDecimal::add);
+
+            Goods goods = null;
+            for (String goodsIdStr : goodsIdsStr.split(",")) {
+                if (StringUtils.isBlank(goodsIdStr)) {
+                    continue;
+                }
+                goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+
+                if (goods != null) {
+                    studentPaymentOrderDetail = new StudentPaymentOrderDetail();
+                    studentPaymentOrderDetail.setCreateTime(date);
+                    if (goods.getType() == GoodsType.INSTRUMENT) {
+                        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
+                    } else if (goods.getType() == GoodsType.ACCESSORIES) {
+                        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
+                    } else if (goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF) {
+                        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
+                    } else {
+                        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
+                    }
+                    studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
+
+                    BigDecimal tempPrice = BigDecimal.ZERO;
+                    if (totalGroupPurchasePrice.compareTo(BigDecimal.ZERO) > 0) {
+                        tempPrice = studentPaymentOrder.getExpectAmount().multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, RoundingMode.DOWN).setScale(2, RoundingMode.DOWN);
+                    }
+
+                    if (totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0 || goodsIdsStr.split(",").length == studentPaymentOrderDetailList.size() + 1) {
+                        studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
+                    } else {
+                        studentPaymentOrderDetail.setPrice(tempPrice);
+                    }
+                    studentPaymentOrderDetail.setUpdateTime(date);
+                    studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
+
+                    totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
+                    studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
+                }
+            }
+        }
+
+        if (CollectionUtils.isNotEmpty(studentPaymentOrderDetailList)) {
+            this.batchAdd(studentPaymentOrderDetailList,studentPaymentOrder.getCouponRemitFee(),studentPaymentOrder.getExpectAmount());
+        }
+        return studentPaymentOrderDetailList;
+    }
 }

+ 12 - 55
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java

@@ -5,18 +5,14 @@ import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.dto.GoodsSellDto;
 import com.ym.mec.biz.dal.dto.PageInfoOrder;
 import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
-import com.ym.mec.biz.service.MusicGroupCalenderRefundPeriodService;
-import com.ym.mec.biz.service.SellOrderService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
-import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
-import com.ym.mec.common.api.CommonResult;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
-import com.ym.mec.common.dto.OrderCreate;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
@@ -24,7 +20,6 @@ import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
-import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.excel.POIUtil;
@@ -54,6 +49,8 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     @Resource
     private StudentPaymentOrderService studentPaymentOrderService;
     @Resource
+    private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
+    @Resource
     private IdGeneratorService idGeneratorService;
     @Resource
     private SellOrderDao sellOrderDao;
@@ -71,8 +68,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     private MusicGroupPaymentCalenderDetailDao musicGroupPaymentCalenderDetailDao;
     @Resource
     private MusicGroupCalenderRefundPeriodService musicGroupCalenderRefundPeriodService;
-    @Resource
-    private MallFeignService mallFeignService;
 
     @Override
     public BaseDAO<Long, StudentPaymentRouteOrder> getDAO() {
@@ -231,57 +226,19 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
 
             studentPaymentRouteOrderDao.insertOrder(studentPaymentOrder);
 
-            if (StringUtils.isNoneBlank(studentPaymentRouteOrder.getGoodsJson())) {
-                BigDecimal goodsTotalPrice = BigDecimal.ZERO;
 
-                List<Integer> goodsIdList = new ArrayList<>();
+            if (StringUtils.isNoneBlank(studentPaymentRouteOrder.getGoodsJson())) {
                 JSONObject jsonObj = JSON.parseObject(studentPaymentRouteOrder.getGoodsJson());
+                List<GoodsSellDto> goodsSellDtos = new ArrayList<>();
                 for (Entry<String, Object> goodsMap : jsonObj.entrySet()) {
-                    Integer goodsId = Integer.parseInt(goodsMap.getKey());
-                    Integer nums = Integer.parseInt(goodsMap.getValue().toString());
-                    Goods goods = goodsDao.get(goodsId);
-                    goodsTotalPrice = goodsTotalPrice.add(goods.getGroupPurchasePrice().multiply(new BigDecimal(nums)));
-                    for (int i = 0; i < nums; i++) {
-                        goodsIdList.add(goodsId);
-                    }
-                }
-                List<SellOrder> sellOrders = sellOrderService.initSellOrder(studentPaymentOrder, null, goodsIdList, null, false);
-                sellOrderService.batchInsert(sellOrders);
-                if(calender == null || calender.getPaymentType() != MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
-                    OrderCreate mallOrder = new OrderCreate();
-                    mallOrder.setOrchestraId(studentPaymentOrder.getMusicGroupId());
-                    mallOrder.setStatus(1);
-                    mallOrder.setOrderNo(studentPaymentRouteOrder.getOrderNo());
-                    mallOrder.setTotalAmount(studentPaymentOrder.getExpectAmount());
-                    String paymentBusinessChannel = studentPaymentOrder.getPaymentBusinessChannel();
-                    if (StringUtils.endsWithIgnoreCase(paymentBusinessChannel, "wx_pub") ||
-                        StringUtils.endsWithIgnoreCase(paymentBusinessChannel, "WECHAT") ||
-                        StringUtils.endsWithIgnoreCase(paymentBusinessChannel, "WXPay")) {
-                        mallOrder.setPayType(2);
-                    } else {
-                        mallOrder.setPayType(1);
-                    }
-                    if (studentPaymentRouteOrder.getType() == OrderTypeEnum.SCHOOL){
-                        mallOrder.setMemberId(studentPaymentRouteOrder.getSchoolId().longValue());
-                        mallOrder.setPlatformType("SCHOOL");
-                        mallOrder.setSourceType(2);
-                    }else {
-                        mallOrder.setMemberId(studentPaymentOrder.getUserId().longValue());
-                        mallOrder.setPlatformType("STUDENT");
-                        mallOrder.setSourceType(3);
-                    }
-                    if(studentPaymentRouteOrder.getType() == OrderTypeEnum.OTHER){
-                        mallOrder.setSourceType(4);
-                    }
-                    List<OrderCreate.OrderItem> items = sellOrderService.convertMallOrder(sellOrders);
-                    mallOrder.setOrderItemList(items);
-                    CommonResult<Boolean> result = mallFeignService.productOrderCreate(mallOrder);
-                    if (result.getCode() != 200) {
-                        throw new BizException("同步商城订单失败: {}",result.getMessage());
-                    }
+                    GoodsSellDto goodsSellDto = new GoodsSellDto();
+                    goodsSellDto.setGoodsId(Integer.parseInt(goodsMap.getKey()));
+                    goodsSellDto.setGoodsNum(Integer.parseInt(goodsMap.getValue().toString()));
+                    goodsSellDtos.add(goodsSellDto);
                 }
+                List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.initStudentPaymentOrderDetail(studentPaymentOrder, goodsSellDtos);
+                sellOrderService.addOrderDetail2SellOrder(orderDetails, studentPaymentOrder, studentPaymentOrder.getMusicGroupId());
             }
-
             if (studentPaymentRouteOrder.getCalenderId() == null) {
                 return true;
             }

+ 2 - 70
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -352,7 +352,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentPaymentOrder.setTenantId(student.getTenantId());
         studentPaymentOrderService.insert(studentPaymentOrder);
 
-        this.initStudentPaymentOrderDetail(studentPaymentOrder, goodsSellDtos);
+        studentPaymentOrderDetailService.initStudentPaymentOrderDetail(studentPaymentOrder, goodsSellDtos);
 
         studentPaymentOrder.setVersion(0);
         BigDecimal balance = BigDecimal.ZERO;
@@ -403,74 +403,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         return payMap;
     }
 
-    public void initStudentPaymentOrderDetail(StudentPaymentOrder studentPaymentOrder, List<GoodsSellDto> goodsSellDtos){
-        Date date = new Date();
-        //添加订单详情
-        List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
-        // 添加studentPaymentOrderDetail
-        StudentPaymentOrderDetail studentPaymentOrderDetail = null;
-
-        BigDecimal totalPrice = BigDecimal.ZERO;
-
-        if (goodsSellDtos != null) {
-            StringBuffer sb = new StringBuffer();
-            for (GoodsSellDto goodsSellDto : goodsSellDtos) {
-                for (int i = 0; i < goodsSellDto.getGoodsNum(); i++) {
-                    sb.append(goodsSellDto.getGoodsId()).append(",");
-                }
-            }
-            String goodsIdsStr = StringUtils.removeEnd(sb.toString(), ",");
-
-            List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr);
-            Map<Integer, Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getId, t -> t));
-            BigDecimal totalGroupPurchasePrice =
-                    goodsSellDtos.stream().map(t -> goodsMap.get(t.getGoodsId()).getGroupPurchasePrice().
-                            multiply(new BigDecimal(t.getGoodsNum()))).reduce(BigDecimal.ZERO, BigDecimal::add);
-
-            Goods goods = null;
-            for (String goodsIdStr : goodsIdsStr.split(",")) {
-                if (StringUtils.isBlank(goodsIdStr)) {
-                    continue;
-                }
-                goods = goodsMap.get(Integer.parseInt(goodsIdStr));
-
-                if (goods != null) {
-                    studentPaymentOrderDetail = new StudentPaymentOrderDetail();
-                    studentPaymentOrderDetail.setCreateTime(date);
-                    if (goods.getType() == GoodsType.INSTRUMENT) {
-                        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
-                    } else if (goods.getType() == GoodsType.ACCESSORIES) {
-                        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
-                    } else if (goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF) {
-                        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
-                    } else {
-                        studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
-                    }
-                    studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
-
-                    BigDecimal tempPrice = BigDecimal.ZERO;
-                    if (totalGroupPurchasePrice.compareTo(BigDecimal.ZERO) > 0) {
-                        tempPrice = studentPaymentOrder.getExpectAmount().multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, RoundingMode.DOWN).setScale(2, RoundingMode.DOWN);
-                    }
-
-                    if (totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0 || goodsIdsStr.split(",").length == studentPaymentOrderDetailList.size() + 1) {
-                        studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
-                    } else {
-                        studentPaymentOrderDetail.setPrice(tempPrice);
-                    }
-                    studentPaymentOrderDetail.setUpdateTime(date);
-                    studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
-
-                    totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
-                    studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
-                }
-            }
-        }
-
-        if (CollectionUtils.isNotEmpty(studentPaymentOrderDetailList)) {
-            studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList,studentPaymentOrder.getCouponRemitFee(),studentPaymentOrder.getExpectAmount());
-        }
-    }
 
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@@ -543,7 +475,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentPaymentOrder.setTenantId(studentGoodsSell.getTenantId());
         studentPaymentOrderService.insert(studentPaymentOrder);
 
-        this.initStudentPaymentOrderDetail(studentPaymentOrder, goodsSellDtos);
+        studentPaymentOrderDetailService.initStudentPaymentOrderDetail(studentPaymentOrder, goodsSellDtos);
 
         studentPaymentOrder.setVersion(0);
         BigDecimal balance = BigDecimal.ZERO;