Browse Source

Merge branch 'zx-2023-04-13' of http://git.dayaedu.com/yonge/mec into master_saas

zouxuan 2 years ago
parent
commit
7f93872949

+ 32 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/GoodsOrderItemVO.java

@@ -0,0 +1,32 @@
+package com.ym.mec.biz.dal.dto;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class GoodsOrderItemVO {
+    private double couponAmount; // 优惠券金额
+    private int giftGrowth; // 赠送成长值
+    private int giftIntegration; // 赠送积分
+    private long id; // 唯一标识符
+    private double integrationAmount; // 积分抵扣金额
+    private long orderId; // 所属订单的唯一标识符
+    private String orderSn; // 订单编号
+    private double precisionAmount; // 精确金额
+    private String productAttr; // 商品属性,JSON 格式
+    private String productBrand; // 商品品牌
+    private long productCategoryId; // 商品分类的唯一标识符
+    private long productId; // 商品的唯一标识符
+    private String productSn; // 商品货号
+    private String productName; // 商品名称
+    private String productPic; // 商品图片
+    private double productPrice; // 商品价格
+    private int productQuantity; // 商品数量
+    private String productSkuCode; // 商品 SKU 编码
+    private long productSkuId; // 商品 SKU 的唯一标识符
+    private double promotionAmount; // 促销金额
+    private String promotionName; // 促销名称
+    private BigDecimal realAmount; // 实际支付金额
+    private int returnStatus; // 退货状态
+}

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/OrderDetailTypeEnum.java

@@ -9,6 +9,7 @@ public enum OrderDetailTypeEnum implements BaseEnum<String, OrderDetailTypeEnum>
     MUSICAL("MUSICAL", "乐器"),
     ACCESSORIES("ACCESSORIES", "辅件"),
     TEACHING("TEACHING", "教谱"),
+    STAFF("STAFF", "曲谱"),
     OTHER("OTHER", "其他"),
     COURSE("COURSE", "乐团课"),
     HIGH_ONLINE_COURSE("HIGH_ONLINE_COURSE", "线上基础技能课"),

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

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
@@ -119,6 +120,10 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     private TenantConfigService tenantConfigService;
     @Autowired
     private GoodsProcurementDao goodsProcurementDao;
+    @Autowired
+    private SysPaymentConfigService sysPaymentConfigService;
+    @Autowired
+    private SellOrderDao sellOrderDao;
 
     @Lazy
     @Autowired
@@ -1318,6 +1323,104 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             } catch (Exception e) {
                 logger.error("产品协议生成失败", e);
             }
+            Long paymentOrderId = studentPaymentOrder.getId();
+            Integer organId = studentPaymentOrder.getOrganId();
+            String transNo = studentPaymentOrder.getTransNo();
+            String orderNo = studentPaymentOrder.getOrderNo();
+            BigDecimal balancePaymentAmount = studentPaymentOrder.getBalancePaymentAmount();
+            //解析student_goods_sell字段goodsJson,生成订单详情和sellOrder
+            StudentGoodsSellDto studentGoodsSellDto = studentGoodsSellDao.getStudentGoodsSellDto(studentPaymentOrder.getOrderNo());
+            if(Objects.nonNull(studentGoodsSellDto)){
+                if(StringUtils.isNotEmpty(studentGoodsSellDto.getGoodsJson())){
+                    JSONObject jsonObject = JSON.parseObject(studentGoodsSellDto.getGoodsJson());
+                    String orderItemList = jsonObject.getString("orderItemList");
+                    if(StringUtils.isNotEmpty(orderItemList)){
+                        List<GoodsOrderItemVO> goodsOrderItemVOS = JSON.parseArray(orderItemList, GoodsOrderItemVO.class);
+                        long count = goodsOrderItemVOS.stream().filter(e -> StringUtils.isEmpty(e.getOrderSn())).count();
+                        //如果有空的商品货号,不处理
+                        if(count == 0l){
+                            List<String> productSns = goodsOrderItemVOS.stream().map(e -> e.getProductSn()).distinct().collect(Collectors.toList());
+                            List<Goods> goodsList = goodsDao.findBySns(productSns);
+                            //如果有不匹配的商品货号,不处理
+                            if(CollectionUtils.isEmpty(goodsList) || goodsList.size() < productSns.size()){
+                                return;
+                            }
+                            Map<String, Goods> goodsSnMap = goodsList.stream().collect(Collectors.groupingBy(e -> e.getSn(),
+                                    Collectors.collectingAndThen(Collectors.toList(), v -> v.get(0))));
+                            List<StudentPaymentOrderDetail> orderDetails = new ArrayList<>();
+                            List<SellOrder> sellOrders = new ArrayList<>();
+                            BigDecimal subjectBalance = balancePaymentAmount;
+                            for (int i = 0; i < goodsOrderItemVOS.size(); i++) {
+                                GoodsOrderItemVO goodsVo = goodsOrderItemVOS.get(i);
+                                Goods goods = goodsSnMap.get(goodsVo.getProductSn());
+                                StudentPaymentOrderDetail detail = new StudentPaymentOrderDetail();
+                                detail.setType(OrderDetailTypeEnum.valueOf(goods.getType().getCode()));
+                                detail.setGoodsIdList(goods.getId().toString());
+                                detail.setPrice(goodsVo.getRealAmount());
+                                detail.setRemitFee(BigDecimal.ZERO);
+                                detail.setPaymentOrderId(paymentOrderId);
+                                orderDetails.add(detail);
+
+                                SellOrder sellOrder = new SellOrder();
+                                sellOrder.setOrganId(organId);
+                                sellOrder.setTransNo(transNo);
+                                sellOrder.setOrderId(paymentOrderId);
+                                sellOrder.setOrderNo(orderNo);
+                                BigDecimal totalAmount = goodsVo.getRealAmount().multiply(new BigDecimal(goodsVo.getProductQuantity()));
+                                sellOrder.setExpectAmount(goodsVo.getRealAmount());
+                                if(goodsOrderItemVOS.size() - 1 == i){
+                                    sellOrder.setBalanceAmount(subjectBalance);
+                                }else {
+                                    //获取比例
+                                    BigDecimal ratioAmount = totalAmount.divide(studentGoodsSellDto.getExpectAmount(), 6, BigDecimal.ROUND_HALF_UP);
+                                    BigDecimal multiply = balancePaymentAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
+                                    sellOrder.setBalanceAmount(multiply);
+                                }
+                                sellOrder.setActualAmount(totalAmount.subtract(sellOrder.getBalanceAmount()));
+
+                                AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(studentPaymentOrder.getPaymentChannel()), studentPaymentOrder.getMerNos(), studentPaymentOrder.getTenantId());
+                                GoodsProcurement goodsProcurement = null;
+                                if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(accountType))){
+                                    goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
+                                    if(Objects.nonNull(goodsProcurement)){
+                                        goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
+                                    }
+                                }else if(StockType.EXTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.EXTERNAL.equals(accountType))){
+                                    goodsProcurement = goodsProcurementDao.getWithTaxStockSurplusProcurement(goods.getId());
+                                    if(Objects.nonNull(goodsProcurement)){
+                                        goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
+                                    }
+                                }
+
+                                //如果有采购清单,初始化总部成本价
+                                if(Objects.nonNull(goodsProcurement)){
+                                    goodsProcurementDao.update(goodsProcurement);
+                                    sellOrder.setBatchNo(goodsProcurement.getBatchNo());
+                                    sellOrder.setSellCost(goodsProcurement.getDiscountPrice());
+                                    Map<String, BigDecimal> CostMap = new HashMap<>();
+                                    CostMap.put("sellCost", goodsProcurement.getDiscountPrice());
+                                    if (Objects.nonNull(goodsProcurement.getAgreeCostPrice())) {
+                                        CostMap.put("SellCost2", goodsProcurement.getAgreeCostPrice());
+                                    }
+                                    sellOrder.setSellCost2(JSON.toJSONString(CostMap));
+                                    sellOrder.setBatchNo(goodsProcurement.getBatchNo());
+                                }
+                                sellOrder.setNum(goodsVo.getProductQuantity());
+                                sellOrder.setUserId(userId);
+                                sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
+                                sellOrder.setMerNo(studentPaymentOrder.getMerNos());
+                                sellOrder.setStockType(goods.getStockType());
+                                sellOrder.setAccountType(accountType);
+                                sellOrder.setStatus(SellStatus.NORMAL);
+                                sellOrder.setSellTime(studentPaymentOrder.getPayTime());
+                                sellOrders.add(sellOrder);
+                            }
+                            sellOrderDao.batchInsert(sellOrders);
+                            studentPaymentOrderDetailService.batchAdd(orderDetails);
+                        }
+                    }
+                }
+            }
             // 完全余额支付 不生成下面的记录
             if (BigDecimal.ZERO.compareTo(studentPaymentOrder.getActualAmount()) == 0) return;
 

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

@@ -4260,6 +4260,10 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
                 
                 // 删除课表
                 courseScheduleDao.deleteCourseSchedulesByMusicGroupID(vipGroup.getId() + "", GroupType.VIP);
+                courseScheduleTeacherSalaryDao.deleteByMusicGroupId(vipGroup.getId() + "", GroupType.VIP);
+
+                //删除考勤
+                teacherAttendanceDao.deleteByMusicGroupId(vipGroup.getId() + "", GroupType.VIP);
         	}
             vipGroupDao.batchUpdate(vipGroupList);