Explorar o código

管乐迷商城改造

zouxuan hai 1 ano
pai
achega
ad600b9aca

+ 3 - 3
mec-application/src/main/java/com/ym/mec/web/controller/APIController.java

@@ -56,7 +56,7 @@ public class APIController extends BaseController {
 	@Resource
 	private GoodsService goodsService;
 	@Resource
-	private SchoolService schoolService;
+	private CooperationOrganService cooperationOrganService;
 
 	@GetMapping("/createCashAccount")
 	public Boolean createCashAccount(Integer userId,Integer tenantId) {
@@ -249,7 +249,7 @@ public class APIController extends BaseController {
 	}
 
 	@PostMapping("/schoolListByIds")
-	public HttpResponseResult<List<SchoolDto>> schoolListByIds(@RequestBody List<Integer> schoolIds) {
-		return succeed(schoolService.schoolListByIds(schoolIds));
+	public HttpResponseResult<List<SchoolDto>> coopListByIds(@RequestBody List<Integer> coopIds) {
+		return succeed(cooperationOrganService.coopListByIds(coopIds));
 	}
 }

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/CooperationOrganService.java

@@ -4,6 +4,7 @@ import com.ym.mec.biz.dal.dao.CooperationOrganDao;
 import com.ym.mec.biz.dal.entity.CooperationOrgan;
 import com.ym.mec.biz.dal.entity.MusicGroup;
 import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender;
+import com.ym.mec.common.dto.SchoolDto;
 import com.ym.mec.common.service.BaseService;
 
 import java.util.ArrayList;
@@ -43,4 +44,6 @@ public interface CooperationOrganService extends BaseService<Integer, Cooperatio
     Map<Integer,CooperationOrgan> getMapByIds(List<Integer> cooperationIds);
 
     List<MusicGroup> musicGroupPage(Integer id);
+
+    List<SchoolDto> coopListByIds(List<Integer> coopIds);
 }

+ 0 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/SchoolService.java

@@ -48,6 +48,4 @@ public interface SchoolService extends BaseService<Integer, School> {
     PageInfo<School> queryPageDetail(SchoolQueryInfo queryInfo);
     
     List<School> querySchoolExportList(SchoolQueryInfo queryInfo);
-
-    List<SchoolDto> schoolListByIds(List<Integer> schoolIds);
 }

+ 6 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/SellOrderService.java

@@ -1,10 +1,12 @@
 package com.ym.mec.biz.service;
 
 
+import com.ym.mec.biz.dal.dao.SellOrderDao;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
 import com.ym.mec.common.dto.OrderCreate;
 import com.ym.mec.common.service.BaseService;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -14,6 +16,7 @@ import java.util.function.Function;
 
 public interface SellOrderService extends BaseService<Integer, SellOrder> {
 
+    SellOrderDao getDao();
 
     /**
      * 添加销售订单
@@ -86,8 +89,10 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
 
     void mallRefundByOrderId(List<SellOrder> sellOrders);
 
+    void updateSellOrder(List<SellOrder> sellOrderList, StudentPaymentOrder studentPaymentOrder);
+
     List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds,
-                                  KitGroupPurchaseTypeEnum kitGroupPurchaseType,Boolean saveFlag);
+                                  KitGroupPurchaseTypeEnum kitGroupPurchaseType, Boolean saveFlag);
 
     List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseType,
                                   BigDecimal totalBalance, BigDecimal expectTotalAmount, BigDecimal couponRemitAmount,

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CooperationOrganServiceImpl.java

@@ -11,6 +11,7 @@ import com.ym.mec.biz.service.ImGroupMemberService;
 import com.ym.mec.biz.service.ImGroupService;
 import com.ym.mec.biz.service.SysUserService;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.dto.SchoolDto;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -248,4 +249,15 @@ public class CooperationOrganServiceImpl extends BaseServiceImpl<Integer, Cooper
         return musicGroupList.stream().filter(o -> o.getStatus().equals(MusicGroupStatusEnum.PROGRESS)).collect(Collectors.toList());
     }
 
+    @Override
+    public List<SchoolDto> coopListByIds(List<Integer> coopIds) {
+		List<CooperationOrgan> schools = cooperationOrganDao.getCooperationOrganByIds(coopIds);
+		return schools.stream().map(e -> {
+			SchoolDto schoolDto = new SchoolDto();
+			schoolDto.setId(e.getId());
+			schoolDto.setName(e.getName());
+			return schoolDto;
+		}).collect(Collectors.toList());
+    }
+
 }

+ 26 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupCalenderRefundPeriodServiceImpl.java

@@ -7,10 +7,9 @@ import com.ym.mec.biz.dal.dto.CooperationCalenderRefundDto;
 import com.ym.mec.biz.dal.dto.CooperationCalenderRefundUpdateDto;
 import com.ym.mec.biz.dal.dto.CooperationRefundDto;
 import com.ym.mec.biz.dal.dto.MusicGroupPaymentBaseCalender;
-import com.ym.mec.biz.dal.entity.MusicGroup;
-import com.ym.mec.biz.dal.entity.MusicGroupCalenderRefundPeriod;
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.page.CooperationRefundQueryInfo;
-import com.ym.mec.biz.service.MusicGroupCalenderRefundPeriodService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
@@ -37,6 +36,12 @@ public class MusicGroupCalenderRefundPeriodServiceImpl extends BaseServiceImpl<I
     private MusicGroupDao musicGroupDao;
     @Autowired
     private TeacherDao teacherDao;
+    @Autowired
+    private SellOrderService sellOrderService;
+    @Autowired
+    private MusicGroupPaymentCalenderAddressService musicGroupPaymentCalenderAddressService;
+    @Autowired
+    private StudentPaymentOrderService studentPaymentOrderService;
 
     @Override
     public BaseDAO<Integer, MusicGroupCalenderRefundPeriod> getDAO() {
@@ -214,6 +219,24 @@ public class MusicGroupCalenderRefundPeriodServiceImpl extends BaseServiceImpl<I
         BigDecimal currentAmount = periods.stream().map(e -> e.getRefundAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
         if(originalAmount.compareTo(currentAmount) != 0){
             //变更订单信息
+            Long calenderId = periods.get(0).getCalenderId();
+            MusicGroupPaymentCalenderAddress address =
+                    musicGroupPaymentCalenderAddressService.lambdaQuery().eq(MusicGroupPaymentCalenderAddress::getCalenderId, calenderId).one();
+            if(Objects.isNull(address)){
+                return;
+            }
+            StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(address.getOrderNo());
+            if (Objects.isNull(order)) {
+                return;
+            }
+            order.setExpectAmount(currentAmount);
+            order.setActualAmount(currentAmount);
+            studentPaymentOrderService.update(order);
+            List<SellOrder> orderSellOrder = sellOrderService.getDao().getOrderSellOrder(order.getId());
+            if (CollectionUtils.isEmpty(orderSellOrder)) {
+                return;
+            }
+            sellOrderService.updateSellOrder(orderSellOrder,order);
         }
     }
 }

+ 31 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -151,7 +151,6 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
     private GoodsDao goodsDao;
     @Autowired
     private SellOrderService sellOrderService;
-
     @Autowired
     private SysAreaService sysAreaService;
 
@@ -1153,14 +1152,42 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 
     public void saveSellOrder(List<MusicGroupPaymentCalenderGoods> goods, StudentPaymentOrder studentPaymentOrder) {
         List<SellOrder> sellOrderList = new ArrayList<>();
-        for (MusicGroupPaymentCalenderGoods calenderGood : goods) {
+        BigDecimal originalTotalAmount = goods.stream().map(e -> e.getTotalPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
+        //获取优惠金额
+        BigDecimal totalDiscountAmount = originalTotalAmount.subtract(studentPaymentOrder.getExpectAmount());
+        //待分配优惠
+        BigDecimal waitDiscountAmount = totalDiscountAmount;
+        for (int k = 0; k < goods.size(); k++) {
+            MusicGroupPaymentCalenderGoods calenderGood = goods.get(k);
+            //获取比例
+            BigDecimal totalProportion = BigDecimal.ZERO;
+            if(studentPaymentOrder.getExpectAmount().compareTo(BigDecimal.ZERO) > 0){
+                totalProportion = calenderGood.getTotalPrice().divide(originalTotalAmount, 6, RoundingMode.DOWN);
+            }
+            //获取现价
+            BigDecimal currentTotalAmount;
+            if (k == goods.size() - 1) {
+                currentTotalAmount = calenderGood.getTotalPrice().subtract(waitDiscountAmount);
+            } else {
+                BigDecimal amount = totalDiscountAmount.multiply(totalProportion).setScale(2, RoundingMode.DOWN);
+                waitDiscountAmount = waitDiscountAmount.subtract(amount);
+                currentTotalAmount = calenderGood.getTotalPrice().subtract(amount);
+            }
+            BigDecimal subCurrentTotalAmount = currentTotalAmount;
             //待分配金额
             for (Integer i = 0; i < calenderGood.getNum(); i++) {
                 List<ComplementGoodsDto> goodsDtoList = JSON.parseArray(calenderGood.getChildGoodsJson(), ComplementGoodsDto.class);
                 //获取总成本
                 BigDecimal totalCostPrice = goodsDtoList.stream().map(e->e.getOrganCostPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
                 //待分配金额
-                BigDecimal totalAmount = calenderGood.getSinglePrice();
+                BigDecimal totalAmount;
+                if(i == calenderGood.getNum() - 1){
+                    totalAmount = subCurrentTotalAmount;
+                }else {
+                    BigDecimal divide = currentTotalAmount.divide(new BigDecimal(calenderGood.getNum()), 2, RoundingMode.DOWN);
+                    totalAmount = divide;
+                    subCurrentTotalAmount = subCurrentTotalAmount.subtract(divide);
+                }
                 BigDecimal waitAmount = totalAmount;
                 for (int j = 0; j < goodsDtoList.size(); j++) {
                     ComplementGoodsDto goodsDto = goodsDtoList.get(j);
@@ -1245,7 +1272,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
         OrderCreate orderCreate = new OrderCreate();
         orderCreate.setOrderNo(address.getOrderNo());
         orderCreate.setOrchestraId(musicGroup.getId());
-        orderCreate.setMemberId(musicGroup.getSchoolId().longValue());
+        orderCreate.setMemberId(musicGroup.getCooperationOrganId().longValue());
         orderCreate.setTotalAmount(calender.getCurrentTotalAmount());
         orderCreate.setOrderFormType("MEC");
         orderCreate.setPlatformType("SCHOOL");

+ 0 - 11
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SchoolServiceImpl.java

@@ -77,15 +77,4 @@ public class SchoolServiceImpl extends BaseServiceImpl<Integer, School>  impleme
 	public List<School> querySchoolExportList(SchoolQueryInfo queryInfo) {
 		return schoolDao.querySchoolExportList(queryInfo);
 	}
-
-    @Override
-    public List<SchoolDto> schoolListByIds(List<Integer> schoolIds) {
-		List<School> schools = schoolDao.getSchools(schoolIds);
-		return schools.stream().map(e -> {
-			SchoolDto schoolDto = new SchoolDto();
-			schoolDto.setId(e.getId());
-			schoolDto.setName(e.getName());
-			return schoolDto;
-		}).collect(Collectors.toList());
-    }
 }

+ 33 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -73,6 +73,10 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         return sellOrderDao;
     }
 
+    public SellOrderDao getDao() {
+        return sellOrderDao;
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void addOrderDetail2SellOrder(List<StudentPaymentOrderDetail> orderDetails,
@@ -279,7 +283,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         } else {
             mallOrder.setPayType(1);
         }
-        mallOrder.setMemberId(studentPaymentOrder.getUserId()==null?0L:studentPaymentOrder.getUserId().longValue());
+        Integer memberId = studentPaymentOrder.getUserId()==null?studentPaymentOrder.getCooperationId():studentPaymentOrder.getUserId();
+        mallOrder.setMemberId(memberId==null?0L:memberId);
         mallOrder.setPlatformType(studentPaymentOrder.getUserId()==null?"SCHOOL":"STUDENT");
         mallOrder.setSourceType(1);
 
@@ -527,6 +532,33 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 
     @Override
     @Transactional(rollbackFor = Exception.class)
+    public void updateSellOrder(List<SellOrder> sellOrderList, StudentPaymentOrder studentPaymentOrder) {
+        //获取总价
+        BigDecimal totalCostPrice = sellOrderList.stream().map(e->e.getExpectAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
+        //待分配金额
+        BigDecimal waitAmount = studentPaymentOrder.getExpectAmount();
+        for (int i = 0; i < sellOrderList.size(); i++) {
+            SellOrder sellOrder = sellOrderList.get(i);
+            //获取比例
+            BigDecimal proportion = BigDecimal.ZERO;
+            if (totalCostPrice.compareTo(BigDecimal.ZERO) > 0) {
+                proportion = sellOrder.getExpectAmount().divide(totalCostPrice, 6, RoundingMode.DOWN);
+            }
+            if (i == sellOrderList.size() - 1) {
+                sellOrder.setOrderAmount(waitAmount);
+            } else {
+                BigDecimal amount = studentPaymentOrder.getExpectAmount().multiply(proportion).setScale(2, RoundingMode.DOWN);
+                waitAmount = waitAmount.subtract(amount);
+                sellOrder.setOrderAmount(amount);
+            }
+            sellOrder.setActualAmount(sellOrder.getOrderAmount());
+            sellOrder.setExpectAmount(sellOrder.getOrderAmount());
+        }
+        this.batchUpdate(sellOrderList);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
     public List<SellOrder> initSellOrder(StudentPaymentOrder order, String musicGroupId, List<Integer> goodsIds,
                                          KitGroupPurchaseTypeEnum kitGroupPurchaseType,Boolean saveFlag) {
         if (CollectionUtils.isEmpty(goodsIds)) {