ソースを参照

管乐迷商城改造

zouxuan 1 年間 前
コミット
0d1e89788f

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderGoods.java

@@ -4,6 +4,7 @@ package com.ym.mec.biz.dal.entity;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.ym.mec.biz.dal.enums.GoodsType;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -30,6 +31,10 @@ public class MusicGroupPaymentCalenderGoods implements Serializable {
     @ApiModelProperty(value = "商品名称")
     private String goodsName;
 
+    @TableField("goods_type_")
+    @ApiModelProperty(value = "商品类型", required = false)
+    private String goodsType;
+
     @TableField("goods_sn_")
     @ApiModelProperty(value = "商品货号")
     private String goodsSn;

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

@@ -463,6 +463,8 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
                     e.setTotalPrice(goods.getDiscountPrice().multiply(new BigDecimal(e.getNum())));
                     e.setSinglePrice(goods.getDiscountPrice());
                     e.setCalenderId(calenderId);
+                    e.setGoodsType(goods.getType().getCode());
+                    e.setGoodsName(goods.getName());
                     List<ComplementGoodsDto> childGoods = goodsSubService.getBaseMapper().queryChildGoods(e.getGoodsId());
                     if(CollectionUtils.isEmpty(childGoods)){
                         throw new BizException("商品{}没有子商品",goods.getName());

+ 0 - 36
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -2229,8 +2229,6 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 address.setDeliveryFlag(true);
             }
             musicGroupPaymentCalenderAddressService.updateBatchById(calenderAddresses);
-            //如果有审核通过的外部订单,更新对应的商品信息
-
         }
         if (CollectionUtils.isEmpty(sellOrders)) {
             return;
@@ -2241,7 +2239,6 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         }
         String format = DateUtil.format(new Date(), DateUtil.ISO_EXPANDED_DATE_FORMAT);
         Map<String,List<SellOrder>> sellOrderMap = sellOrders.stream().collect(Collectors.groupingBy(SellOrder::getOrderNo));
-//        Map<String,Map<Long,BigDecimal>> skuCostMap = new HashMap<>(orderSkuSyncs.size());
         for (OrderSkuSync orderSkuSync : orderSkuSyncs) {
             List<SellOrder> dtos = sellOrderMap.get(orderSkuSync.getOrderNo());
             if(CollectionUtils.isEmpty(dtos)){
@@ -2259,40 +2256,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                     }
                 }
             }
-
-
-/*            //获取sku平均成本价
-            Map<Long,List<OrderSkuSync.SkuSync>> skuDetailMap = orderSkuSync.getSkuSyncList().stream().collect(Collectors.groupingBy(OrderSkuSync.SkuSync::getSku));
-            Map<Long,BigDecimal> costMap = new HashMap<>(skuDetailMap.keySet().size());
-            Map<Long,String> stockMap = new HashMap<>(skuDetailMap.keySet().size());
-            for (Long skuId : skuDetailMap.keySet()) {
-                List<OrderSkuSync.SkuSync> skuSyncs = skuDetailMap.get(skuId);
-                //汇总成本价
-                BigDecimal costPrice = skuSyncs.stream().map(e -> e.getPrice().multiply(new BigDecimal(e.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
-                //获取总数
-                int count = skuSyncs.stream().mapToInt(e -> e.getCount()).sum();
-                BigDecimal avgCostPrice = costPrice;
-                if (count > 1) {
-                    avgCostPrice = costPrice.divide(new BigDecimal(count), 2, BigDecimal.ROUND_HALF_UP);
-                }
-                costMap.put(skuId,avgCostPrice);
-                stockMap.put(skuId,skuSyncs.get(0).getStock());
-            }
-            skuCostMap.put(orderSkuSync.getOrderNo(),costMap);*/
         }
-
-/*        for (String orderNo : sellOrderMap.keySet()) {
-            List<SellOrder> sellOrderList = sellOrderMap.get(orderNo);
-            Map<Long,BigDecimal> costMap = skuCostMap.get(orderNo);
-            for (SellOrder sellOrder : sellOrderList) {
-                BigDecimal costPrice = costMap.get(sellOrder.getGoodsSkuId().longValue());
-                if(costPrice == null){
-                    throw new BizException("商品[{}]成本价不存在",sellOrder.getGoodsSkuId());
-                }
-                sellOrder.setSellCost(costPrice);
-                sellOrder.setDeliveryTime(format);
-            }
-        }*/
         sellOrderDao.batchUpdate(sellOrders);
 
     }

+ 101 - 77
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java

@@ -11,12 +11,14 @@ import com.alibaba.fastjson.JSONArray;
 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.ComplementGoodsDto;
 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.biz.service.*;
 import com.ym.mec.common.api.CommonResult;
 import com.ym.mec.common.dto.OrderCreate;
 import com.ym.mec.common.entity.HttpResponseResult;
+import com.ym.mec.common.entity.OrderSkuSync;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.mall.MallFeignService;
 import com.ym.mec.util.date.DateUtil;
@@ -35,9 +37,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.biz.dal.dto.PageInfoOrder;
 import com.ym.mec.biz.dal.dto.StudentPaymentRouteOrderDto;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
-import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.SellOrderService;
-import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
@@ -56,7 +55,7 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     @Autowired
     private SysUserCashAccountDao sysUserCashAccountDao;
     @Autowired
-    private StudentPaymentOrderDao studentPaymentOrderDao;
+    private StudentPaymentOrderService studentPaymentOrderService;
     @Autowired
     private IdGeneratorService idGeneratorService;
     @Autowired
@@ -64,8 +63,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     @Autowired
     private GoodsDao goodsDao;
     @Autowired
-    private GoodsService goodsService;
-    @Autowired
     private SellOrderService sellOrderService;
     @Autowired
     private SysUserFeignService sysUserFeignService;
@@ -79,6 +76,14 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     private MusicGroupCalenderRefundPeriodService musicGroupCalenderRefundPeriodService;
     @Autowired
     private MallFeignService mallFeignService;
+    @Autowired
+    private MusicGroupPaymentCalenderAddressService musicGroupPaymentCalenderAddressService;
+    @Autowired
+    private MusicGroupPaymentCalenderGoodsService musicGroupPaymentCalenderGoodsService;
+    @Autowired
+    private SysPaymentConfigService sysPaymentConfigService;
+    @Autowired
+    private MusicGroupDao musicGroupDao;
 
     @Override
     public BaseDAO<Long, StudentPaymentRouteOrder> getDAO() {
@@ -200,12 +205,28 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
         studentPaymentRouteOrder.setUpdateTime(nowDate);
         studentPaymentRouteOrder.setAuditComment(memo);
         studentPaymentRouteOrder.setAuditStatus(auditStatus);
+        MusicGroupPaymentCalender musicGroupPaymentCalender = null;
+        MusicGroupPaymentCalenderAddress address = null;
+        MusicGroup musicGroup = null;
+                //是否同步过商城的发货数据
+        Boolean syncFlag = true;
         if (auditStatus == AuditStatusEnum.PASS) {
+            if (studentPaymentRouteOrder.getCalenderId() != null) {
+                musicGroupPaymentCalender = musicGroupPaymentCalenderDao.get(studentPaymentRouteOrder.getCalenderId());
+                musicGroup = musicGroupDao.get(musicGroupPaymentCalender.getMusicGroupId());
+                if(musicGroupPaymentCalender.getPaymentType() == MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
+                    address = musicGroupPaymentCalenderAddressService.lambdaQuery().
+                            eq(MusicGroupPaymentCalenderAddress::getCalenderId, studentPaymentRouteOrder.getCalenderId()).one();
+                    StudentPaymentOrder addressOrder = studentPaymentOrderService.findOrderByOrderNo(address.getAddress());
+                    syncFlag = Objects.isNull(addressOrder);
+                    if (!syncFlag){
+                        orderNo = address.getOrderNo();
+                    }
+                }
+            }
             studentPaymentRouteOrder.setOrderNo(orderNo);
         }
-
         studentPaymentRouteOrderDao.update(studentPaymentRouteOrder);
-
         if (auditStatus == AuditStatusEnum.PASS) {
             StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
             studentPaymentOrder.setActualAmount(studentPaymentRouteOrder.getRouteAmount());
@@ -236,7 +257,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             studentPaymentRouteOrderDao.insertOrder(studentPaymentOrder);
 
             if (StringUtils.isNoneBlank(studentPaymentRouteOrder.getGoodsJson())) {
-                BigDecimal hasRouteAmount = BigDecimal.ZERO;
                 BigDecimal goodsTotalPrice = BigDecimal.ZERO;
 
                 List<Integer> goodsIdList = new ArrayList<>();
@@ -250,70 +270,8 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
                         goodsIdList.add(goodsId);
                     }
                 }
-//                List<SellOrder> sellOrderList = goodsService.subtractStock(goodsIdList, AccountType.INTERNAL);
-                List<SellOrder> sellOrders = sellOrderService.initSellOrder(studentPaymentOrder, null, goodsIdList, null, false);
+                List<SellOrder> sellOrders = sellOrderService.initSellOrder(studentPaymentOrder, musicGroup==null?null:musicGroup.getId(), goodsIdList, null, false);
                 sellOrderService.batchInsert(sellOrders);
-                /*int i = 1;
-                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);
-
-                    BigDecimal actualAmount = BigDecimal.ZERO;
-                    if (goodsTotalPrice.compareTo(BigDecimal.ZERO) != 0) {
-                        actualAmount = studentPaymentRouteOrder.getSaleAmount().multiply(goods.getGroupPurchasePrice().multiply(new BigDecimal(nums))).divide(goodsTotalPrice, 2, BigDecimal.ROUND_DOWN);
-                    }
-                    if (i == jsonObj.entrySet().size()) {
-                        actualAmount = studentPaymentRouteOrder.getSaleAmount().subtract(hasRouteAmount);
-                    }
-                    hasRouteAmount = hasRouteAmount.add(actualAmount);
-                    i++;
-
-                    int complementNum = goods.getComplementGoodsIdList() == null ? 1 : goods.getComplementGoodsIdList().split(",").length;
-                    int goodsNum = nums * complementNum;
-                    BigDecimal complementPrice = goods.getGroupPurchasePrice().multiply(new BigDecimal(nums));
-                    Map<Integer, BigDecimal> complementGoodsPrice = new HashMap<>();
-                    complementGoodsPrice.put(goods.getId(), goods.getGroupPurchasePrice());
-                    if (goods.getComplementGoodsIdList() != null) {
-                        List<Goods> complementGoodies = goodsDao.findGoodsByIds(goods.getComplementGoodsIdList());
-                        complementGoodsPrice = complementGoodies.stream().collect(Collectors.toMap(Goods::getId, Goods::getGroupPurchasePrice));
-                        complementPrice = complementGoodies.stream().map(Goods::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add).multiply(new BigDecimal(nums));
-                    }
-
-                    BigDecimal hasRouteSellOrderActualAmount = BigDecimal.ZERO;
-                    for (SellOrder sellOrder : sellOrderList) {
-                        if (!Integer.valueOf(goodsMap.getKey()).equals(sellOrder.getParentGoodsId()) && !Integer.valueOf(goodsMap.getKey()).equals(sellOrder.getGoodsId())) {
-                            continue;
-                        }
-                        BigDecimal sellOrderActualAmount = BigDecimal.ZERO;
-                        if (complementPrice.compareTo(BigDecimal.ZERO) > 0) {
-                            sellOrderActualAmount = complementGoodsPrice.get(sellOrder.getGoodsId()).multiply(new BigDecimal(sellOrder.getNum())).multiply(actualAmount).divide(complementPrice, 2, BigDecimal.ROUND_DOWN);
-                        }
-                        goodsNum = goodsNum - sellOrder.getNum();
-                        if (goodsNum <= 0) {
-                            sellOrderActualAmount = actualAmount.subtract(hasRouteSellOrderActualAmount);
-                        }
-                        hasRouteSellOrderActualAmount = hasRouteSellOrderActualAmount.add(sellOrderActualAmount);
-
-                        sellOrder.setSellTime(studentPaymentRouteOrder.getPayTime());
-                        sellOrder.setOrganId(studentPaymentRouteOrder.getRouteOrganId());
-                        sellOrder.setCooperationOrganId(studentPaymentRouteOrder.getSchoolId());
-                        sellOrder.setTransNo(studentPaymentRouteOrder.getTransNo());
-                        sellOrder.setOrderId(studentPaymentOrder.getId());
-                        sellOrder.setOrderNo(studentPaymentRouteOrder.getOrderNo());
-                        sellOrder.setActualAmount(sellOrderActualAmount);
-                        sellOrder.setBalanceAmount(BigDecimal.ZERO);
-                        sellOrder.setExpectAmount(sellOrderActualAmount);
-                        sellOrder.setUserId(studentPaymentRouteOrder.getUserId());
-                        sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
-                        sellOrder.setMerNo(studentPaymentRouteOrder.getMerNo());
-                        sellOrder.setSellTime(studentPaymentRouteOrder.getCreateTime());
-                        sellOrder.setCreateIme(nowDate);
-                        sellOrder.setUpdateTime(nowDate);
-                        sellOrder.setType(SellTypeEnum.SCHOOL_BUY);
-                    }
-                }
-                sellOrderDao.batchInsert(sellOrderList);*/
                 if(calender == null || calender.getPaymentType() != MusicGroupPaymentCalender.PaymentType.GOODS_PURCHASE){
                     OrderCreate mallOrder = new OrderCreate();
                     mallOrder.setOrchestraId(studentPaymentOrder.getMusicGroupId());
@@ -352,6 +310,74 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             if (studentPaymentRouteOrder.getCalenderId() == null) {
                 return true;
             }
+            //同步商城的发货数据
+            if(!syncFlag){
+                AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(studentPaymentOrder.getPaymentChannel()), studentPaymentOrder.getMerNos(), studentPaymentOrder.getTenantId());
+                List<MusicGroupPaymentCalenderGoods> calenderGoods = musicGroupPaymentCalenderGoodsService.lambdaQuery()
+                        .eq(MusicGroupPaymentCalenderGoods::getCalenderId, studentPaymentRouteOrder.getCalenderId()).list();
+                List<SellOrder> sellOrderList = new ArrayList<>();
+                for (MusicGroupPaymentCalenderGoods calenderGood : calenderGoods) {
+                    //待分配金额
+                    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 waitAmount = totalAmount;
+                        for (int j = 0; j < goodsDtoList.size(); j++) {
+                            ComplementGoodsDto goodsDto = goodsDtoList.get(j);
+                            //获取比例
+                            BigDecimal proportion = BigDecimal.ZERO;
+                            if (totalCostPrice.compareTo(BigDecimal.ZERO) > 0) {
+                                proportion = goodsDto.getOrganCostPrice().divide(totalCostPrice, 2, BigDecimal.ROUND_HALF_UP);
+                            }
+                            SellOrder sellOrder = new SellOrder();
+                            sellOrder.setGoodsSkuId(goodsDto.getSkuStockId());
+                            sellOrder.setOrganSellCost(goodsDto.getOrganCostPrice());
+                            sellOrder.setOrderId(studentPaymentOrder.getId());
+                            sellOrder.setType(StringUtils.endsWithIgnoreCase("INSTRUMENT", calenderGood.getGoodsType()) ? SellTypeEnum.INSTRUMENT
+                                    : StringUtils.endsWithIgnoreCase("ACCESSORIES", calenderGood.getGoodsType()) ? SellTypeEnum.ACCESSORIES
+                                    : StringUtils.endsWithIgnoreCase("TEACHING", calenderGood.getGoodsType()) ? SellTypeEnum.TEACHING
+                                    : StringUtils.endsWithIgnoreCase("STAFF", calenderGood.getGoodsType()) ? SellTypeEnum.STAFF
+                                    : SellTypeEnum.OTHER);
+                            sellOrder.setOrderNo(orderNo);
+                            if (j == goodsDtoList.size() - 1) {
+                                sellOrder.setOrderAmount(waitAmount);
+                            } else {
+                                BigDecimal amount = totalAmount.multiply(proportion);
+                                waitAmount = waitAmount.subtract(amount);
+                                sellOrder.setOrderAmount(amount);
+                            }
+                            sellOrder.setActualAmount(sellOrder.getOrderAmount());
+                            sellOrder.setExpectAmount(sellOrder.getOrderAmount());
+                            sellOrder.setCouponRemitAmount(BigDecimal.ZERO);
+                            sellOrder.setBalanceAmount(BigDecimal.ZERO);
+                            sellOrder.setParentGoodsId(calenderGood.getGoodsId());
+                            sellOrder.setNum(1);
+                            sellOrder.setGoodsName(calenderGood.getGoodsName());
+                            sellOrder.setAccountType(accountType);
+                            sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
+                            sellOrder.setEduTeacherId(musicGroup.getEducationalTeacherId());
+                            sellOrder.setTransNo(studentPaymentOrder.getTransNo());
+                            sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
+                            sellOrder.setMerNo(studentPaymentOrder.getMerNos());
+                            sellOrder.setSellTime(studentPaymentOrder.getCreateTime());
+                            sellOrder.setTenantId(studentPaymentOrder.getTenantId());
+                            sellOrderList.add(sellOrder);
+                        }
+                    }
+                }
+                sellOrderService.batchInsert(sellOrderList);
+                if(address.getDeliveryFlag()){
+                    OrderSkuSync orderSkuSync = new OrderSkuSync();
+                    orderSkuSync.setOrderNo(orderNo);
+                    orderSkuSync.setSkuSyncList(JSONArray.parseArray(address.getAddress(), OrderSkuSync.SkuSync.class));
+                    List<OrderSkuSync> orderSkuSyncs = new ArrayList<>();
+                    orderSkuSyncs.add(orderSkuSync);
+                    studentPaymentOrderService.updateShippedStatus(orderSkuSyncs);
+                }
+            }
 
             //根据学校缴费项id,确定缴费状态
 //            BigDecimal amount = studentPaymentRouteOrderDao.sumAmountByCalenderId(studentPaymentRouteOrder.getCalenderId());
@@ -361,8 +387,6 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
             //是否已完成回款
             if(aBoolean){
                 List<MusicGroupPaymentCalenderDetail> calenderDetails = musicGroupPaymentCalenderDetailDao.getCalenderDetailWithCalender(studentPaymentRouteOrder.getCalenderId());
-                MusicGroupPaymentCalender musicGroupPaymentCalender = musicGroupPaymentCalenderDao.get(studentPaymentRouteOrder.getCalenderId());
-
                 if (studentPaymentRouteOrder.getRouteAmount().compareTo(musicGroupPaymentCalender.getCurrentTotalAmount()) >= 0) {
                     musicGroupPaymentCalender.setActualNum(musicGroupPaymentCalender.getExpectNum());
                     musicGroupPaymentCalender.setStatus(MusicGroupPaymentCalender.PaymentCalenderStatusEnum.PAID);
@@ -398,11 +422,11 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean deleteRouteOrder(Long orderId) {
-        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(orderId);
+        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.get(orderId);
         if (studentPaymentOrder == null) {
             throw new BizException("订单不存在,请核查");
         }
-        studentPaymentOrderDao.delete(orderId);
+        studentPaymentOrderService.delete(orderId);
         studentPaymentRouteOrderDao.deleteByOrderNo(studentPaymentOrder.getOrderNo());
         //归还库存
         List<SellOrder> sellOrders = sellOrderService.getSellOrderByParentGoodsId(orderId, null);

+ 2 - 1
mec-biz/src/main/resources/config/mybatis/GoodsSubMapper.xml

@@ -17,6 +17,7 @@
         </foreach>
     </update>
     <select id="queryChildGoods" resultType="com.ym.mec.biz.dal.dto.ComplementGoodsDto">
-        select sku_ skuStockId,goods_id_ goodsId,goods_price_ organCostPrice from goods_sub where goods_id_ = #{goodsId}
+        select sku_ skuStockId,goods_id_ goodsId,goods_price_ organCostPrice,
+        from goods_sub where goods_id_ = #{goodsId}
     </select>
 </mapper>