Przeglądaj źródła

Merge remote-tracking branch 'origin/zx_saas_goods' into zx_saas_goods

yuanliang 1 rok temu
rodzic
commit
2540a33ec5

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

@@ -5,6 +5,7 @@ import com.ym.mec.biz.dal.entity.MusicGroup;
 import com.ym.mec.biz.dal.entity.SellOrder;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
+import com.ym.mec.common.dto.OrderCreate;
 import com.ym.mec.common.service.BaseService;
 
 import java.math.BigDecimal;
@@ -79,4 +80,5 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
      */
     Map<String,BigDecimal> getSellAmount(String orderNo);
 
+    List<OrderCreate.OrderItem> convertMallOrder(List<SellOrder> sellOrderList);
 }

+ 20 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -26,6 +26,7 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import org.apache.commons.collections.CollectionUtils;
@@ -138,6 +139,9 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
     @Autowired
     private CloudCoachPaymentProgramDao cloudCoachPaymentProgramDao;
 
+    @Autowired
+    private MallFeignService mallFeignService;
+
     @Override
     public BaseDAO<Long, MusicGroupPaymentCalender> getDAO() {
         return musicGroupPaymentCalenderDao;
@@ -1034,7 +1038,6 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                 classGroupService.spanGroupClassAdjustPass(adjust.getMasterClassGroupId()
                         , studentIds, courseIds, classGroupStudents, allLockCourseIds, batchNo, adjust.getMasterTotalPrice());
             } else if (calender.getPaymentType() == GOODS_PURCHASE) {
-                //TODO 推送订单到商城
                 MusicGroupPaymentCalenderAddress address = musicGroupPaymentCalenderAddressService.lambdaQuery()
                         .eq(MusicGroupPaymentCalenderAddress::getCalenderId, calender.getId()).one();
                 if (address == null) {
@@ -1093,6 +1096,10 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                     }
                 }
                 orderCreate.setOrderItemList(orderItems);
+                boolean b = mallFeignService.productOrderCreate(orderCreate);
+                if (!b) {
+                    throw new BizException("同步商城订单失败");
+                }
             }
             for (MusicGroupPaymentCalender musicGroupPaymentCalender : musicGroupPaymentCalenders) {
                 //将0元未缴费学员缴费状态更新为已缴费
@@ -1436,15 +1443,18 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
             throw new BizException("操作失败:缴费项目中已存在学员");
         }
         //商品采购订单
+        MusicGroupPaymentCalenderAddress address = null;
         if(calender.getPaymentType() == GOODS_PURCHASE){
             //TODO 商品采购订单是否已经发货
-            MusicGroupPaymentCalenderAddress address = musicGroupPaymentCalenderAddressService.lambdaQuery().eq(MusicGroupPaymentCalenderAddress::getCalenderId, id).one();
+            address = musicGroupPaymentCalenderAddressService.lambdaQuery().eq(MusicGroupPaymentCalenderAddress::getCalenderId, id).one();
             if(address != null){
                 if (address.getDeliveryFlag()) {
                     throw new BizException("操作失败:商品采购订单已发货");
                 }
                 musicGroupPaymentCalenderAddressService.removeById(address.getId());
             }
+            //商品采购订单是否已经录入
+            
             musicGroupPaymentCalenderGoodsService.lambdaUpdate().eq(MusicGroupPaymentCalenderGoods::getCalenderId,id).remove();
         }
 
@@ -1498,6 +1508,14 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                 musicGroupDao.update(musicGroup);
             }
         }
+        //商品采购订单
+        if(calender.getPaymentType() == GOODS_PURCHASE && address != null){
+            //关闭商城订单
+            boolean b = mallFeignService.productUpdateOrderStatus(address.getOrderNo(), 4);
+            if (!b) {
+                throw new BizException("操作失败:关闭商城订单失败");
+            }
+        }
     }
 
     @Override

+ 45 - 12
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -4,6 +4,7 @@ package com.ym.mec.biz.service.impl;
 import static com.ym.mec.biz.dal.enums.GroupType.GOODS_SELL;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -11,6 +12,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
+import com.alibaba.fastjson.JSON;
+import com.ym.mec.biz.dal.dto.ComplementGoodsDto;
+import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.mapper.GoodsSubMapper;
+import com.ym.mec.biz.service.*;
+import com.ym.mec.common.dto.OrderCreate;
+import com.ym.mec.common.page.WrapperUtil;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,13 +33,6 @@ import com.ym.mec.biz.dal.dao.SporadicChargeInfoDao;
 import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
 import com.ym.mec.biz.dal.dao.StudentPaymentOrderDetailDao;
 import com.ym.mec.biz.dal.dao.StudentRepairDao;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.MusicGroup;
-import com.ym.mec.biz.dal.entity.SellOrder;
-import com.ym.mec.biz.dal.entity.SporadicChargeInfo;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
-import com.ym.mec.biz.dal.entity.SysUserCashAccountLog;
 import com.ym.mec.biz.dal.enums.AccountType;
 import com.ym.mec.biz.dal.enums.GoodsType;
 import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
@@ -42,11 +43,6 @@ import com.ym.mec.biz.dal.enums.ReturnFeeEnum;
 import com.ym.mec.biz.dal.enums.SellStatus;
 import com.ym.mec.biz.dal.enums.SellTypeEnum;
 import com.ym.mec.biz.dal.enums.SporadicChargeTypeEnum;
-import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.SellOrderService;
-import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
-import com.ym.mec.biz.service.SysPaymentConfigService;
-import com.ym.mec.biz.service.SysUserCashAccountLogService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 
@@ -72,6 +68,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     private SporadicChargeInfoDao sporadicChargeInfoDao;
     @Autowired
     private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
+    @Autowired
+    private GoodsSubService goodsSubService;
 
     @Override
     public BaseDAO<Integer, SellOrder> getDAO() {
@@ -511,6 +509,41 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         return sellAmount;
     }
 
+    @Override
+    public List<OrderCreate.OrderItem> convertMallOrder(List<SellOrder> sellOrderList) {
+        List<OrderCreate.OrderItem> orderItems = new ArrayList<>();
+        for (SellOrder e : sellOrderList) {
+            List<GoodsSub> list = goodsSubService.lambdaQuery().eq(GoodsSub::getGoodsId, e.getGoodsId()).list();
+            if(CollectionUtils.isEmpty(list)){
+                throw new RuntimeException("子商品不存在,请联系管理员");
+            }
+            BigDecimal totalPrice = e.getExpectAmount().divide(new BigDecimal(e.getNum()), 2, RoundingMode.HALF_UP);
+            //总金额按比例分配
+            //待分配
+            BigDecimal waitRemitFee = totalPrice;
+            BigDecimal totalAmount = WrapperUtil.sumList(list, GoodsSub::getGoodsPrice);
+            for (int i = 0; i < list.size(); i++) {
+                GoodsSub goodsDto = list.get(i);
+                OrderCreate.OrderItem orderItemCreate = new OrderCreate.OrderItem();
+                orderItemCreate.setProductQuantity(e.getNum());
+                orderItemCreate.setProductSkuId(goodsDto.getSku().longValue());
+                //如果是最后一件商品
+                if (i == list.size() - 1) {
+                    orderItemCreate.setRealAmount(waitRemitFee);
+                } else {
+                    //获取比例
+                    BigDecimal ratioAmount = goodsDto.getGoodsPrice().divide(totalAmount, 6, RoundingMode.HALF_UP);
+                    //获取分配的金额
+                    BigDecimal multiply = ratioAmount.multiply(totalPrice).setScale(2, RoundingMode.HALF_UP);
+                    orderItemCreate.setRealAmount(multiply);
+                    waitRemitFee = waitRemitFee.subtract(multiply);
+                }
+                orderItems.add(orderItemCreate);
+            }
+        }
+        return orderItems;
+    }
+
     public Map<String, BigDecimal> calcSellAmount(StudentPaymentOrder order,BigDecimal cloudBalanceIncome,BigDecimal cloudIncome) {
         List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetail(order.getId());
         //总余额支付

+ 39 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java

@@ -14,8 +14,10 @@ import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.service.MusicGroupCalenderRefundPeriodService;
+import com.ym.mec.common.dto.OrderCreate;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.tenant.TenantContextHolder;
+import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.excel.POIUtil;
 import com.ym.mec.util.ini.IniFileUtil;
@@ -74,6 +76,8 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     private MusicGroupPaymentCalenderDetailDao musicGroupPaymentCalenderDetailDao;
     @Autowired
     private MusicGroupCalenderRefundPeriodService musicGroupCalenderRefundPeriodService;
+    @Autowired
+    private MallFeignService mallFeignService;
 
     @Override
     public BaseDAO<Long, StudentPaymentRouteOrder> getDAO() {
@@ -202,8 +206,9 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             if(studentPaymentRouteOrder.getSchoolId() != null) {
                 studentPaymentOrder.setCooperationId(studentPaymentRouteOrder.getSchoolId());
             }
+            MusicGroupPaymentCalender calender = null;
             if(studentPaymentRouteOrder.getCalenderId() != null){
-                MusicGroupPaymentCalender calender = musicGroupPaymentCalenderDao.get(studentPaymentRouteOrder.getCalenderId());
+                calender = musicGroupPaymentCalenderDao.get(studentPaymentRouteOrder.getCalenderId());
                 studentPaymentOrder.setMusicGroupId(calender.getMusicGroupId());
                 studentPaymentOrder.setCalenderId(studentPaymentRouteOrder.getCalenderId());
             }
@@ -302,6 +307,39 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
                     }
                 }
                 sellOrderDao.batchInsert(sellOrderList);
+                if(calender != null && calender.getPaymentType() != MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
+                    OrderCreate mallOrder = new OrderCreate();
+                    mallOrder.setOrchestraId(studentPaymentOrder.getMusicGroupId());
+                    mallOrder.setStatus(3);
+                    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(sellOrderList);
+                    mallOrder.setOrderItemList(items);
+                    boolean b = mallFeignService.productOrderCreate(mallOrder);
+                    if (!b) {
+                        throw new BizException("同步商城订单失败");
+                    }
+                }
             }
 
             if (studentPaymentRouteOrder.getCalenderId() == null) {

+ 0 - 2
mec-client-api/src/main/java/com/ym/mec/mall/MallFeignService.java

@@ -1,7 +1,5 @@
 package com.ym.mec.mall;
 
-import com.baomidou.mybatisplus.extension.api.R;
-import com.baomidou.mybatisplus.extension.enums.ApiErrorCode;
 import com.ym.mec.common.config.FeignConfiguration;
 import com.ym.mec.common.dto.*;
 import com.ym.mec.common.page.PageInfo;