yonge 3 سال پیش
والد
کامیت
a73c1a8834

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrderDetail.java

@@ -65,6 +65,8 @@ public class StudentPaymentOrderDetail extends BaseEntity {
 	
 	private BigDecimal income = BigDecimal.ZERO;
 	
+	private BigDecimal balanceIncome = BigDecimal.ZERO;
+	
 	private String minuendStockGoodsIdList;
 
 	@ApiModelProperty(value = "子商品列表",required = false)
@@ -231,6 +233,14 @@ public class StudentPaymentOrderDetail extends BaseEntity {
 		this.income = income;
 	}
 
+	public BigDecimal getBalanceIncome() {
+		return balanceIncome;
+	}
+
+	public void setBalanceIncome(BigDecimal balanceIncome) {
+		this.balanceIncome = balanceIncome;
+	}
+
 	public String getMinuendStockGoodsIdList() {
 		return minuendStockGoodsIdList;
 	}

+ 4 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java

@@ -301,9 +301,9 @@ public class PayServiceImpl implements PayService {
         						}
         					}
         					
-							if (groupPurchaseAmount.doubleValue() > 0) {
+							if (groupPurchaseAmount.compareTo(BigDecimal.ZERO) > 0) {
 	        					// 3.是否使用余额
-								if (balanceAmount.doubleValue() > 0) {
+								if (balanceAmount.compareTo(BigDecimal.ZERO) > 0) {
 									/*tempBalance = balanceAmount.multiply(spod.getPrice()).divide(totalAmout).multiply(groupPurchaseAmount)
 											.divide(totalGroupPurchaseAmount);*/
 									tempBalance = balanceAmount.multiply(spod.getPrice()).multiply(groupPurchaseAmount)
@@ -314,6 +314,7 @@ public class PayServiceImpl implements PayService {
 								subCashAmount = subCashAmount.add(tempCashAmount);
 								spod.setIncomeItem(OrderDetailTypeEnum.CLOUD_TEACHER.name());
 								spod.setIncome(tempCashAmount);
+								spod.setBalanceIncome(tempBalance);
 								if(minuendStockGoodsIdList.size() > 0){
 									spod.setMinuendStockGoodsIdList(minuendStockGoodsIdList.stream().map(t -> t.toString()).collect(Collectors.joining(",")));
 								}
@@ -335,7 +336,7 @@ public class PayServiceImpl implements PayService {
         			goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
         		}
         		
-        		if(subCashAmount.doubleValue() > 0){
+        		if(subCashAmount.compareTo(BigDecimal.ZERO) > 0){
         			StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
     	            studentPaymentRouteOrder.setOrderNo(orderNo);
     	            studentPaymentRouteOrder.setRouteOrganId(sysPaymentConfig.getOrganId());

+ 6 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SellOrderServiceImpl.java

@@ -485,8 +485,10 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         
         List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(order.getId());
         BigDecimal cloudIncome = BigDecimal.ZERO;
+        BigDecimal cloudBalanceIncome = BigDecimal.ZERO;
         if(studentPaymentOrderDetailList != null) {
         	cloudIncome = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNoneBlank(t.getMinuendStockGoodsIdList()) && StringUtils.equals(t.getIncomeItem(), OrderDetailTypeEnum.CLOUD_TEACHER.name())).map(t -> t.getIncome()).reduce(BigDecimal.ZERO, BigDecimal::add);
+        	cloudBalanceIncome = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNoneBlank(t.getMinuendStockGoodsIdList()) && StringUtils.equals(t.getIncomeItem(), OrderDetailTypeEnum.CLOUD_TEACHER.name())).map(t -> t.getBalanceIncome()).reduce(BigDecimal.ZERO, BigDecimal::add);
         }
 
         //零星支付除了充值其他都是服务费用
@@ -500,13 +502,13 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         //乐器销售,声部更改
         if (order.getType().equals(OrderTypeEnum.GOODS_SELL) || order.getType().equals(OrderTypeEnum.SUBJECT_CHANGE)) {
             sellAmount.put("actualAmount", order.getActualAmount().subtract(cloudIncome));
-            sellAmount.put("balance", order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount());
+            sellAmount.put("balance", order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount().subtract(cloudBalanceIncome));
             return sellAmount;
         }
         //乐器置换
         if (order.getType().equals(OrderTypeEnum.REPLACEMENT)) {
             sellAmount.put("actualAmount", order.getActualAmount().subtract(cloudIncome));
-            sellAmount.put("balance", order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount());
+            sellAmount.put("balance", order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount().subtract(cloudBalanceIncome));
             return sellAmount;
         }
 
@@ -550,7 +552,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             BigDecimal goodsTotalBalance = goodsTotalPrice.multiply(balance).divide(totalAmount, 2, BigDecimal.ROUND_DOWN);
             BigDecimal goodsTotalActualAmount = goodsTotalPrice.multiply(order.getActualAmount()).divide(totalAmount, 2, BigDecimal.ROUND_DOWN);
             sellAmount.put("actualAmount", goodsTotalActualAmount.subtract(cloudIncome));
-            sellAmount.put("balance", goodsTotalBalance);
+            sellAmount.put("balance", goodsTotalBalance.subtract(cloudBalanceIncome));
             return sellAmount;
         }
 
@@ -567,7 +569,7 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
             BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_DOWN);
 
             sellAmount.put("actualAmount", detailTotalPrice.subtract(detailTotalBalance).subtract(cloudIncome));
-            sellAmount.put("balance", detailTotalBalance);
+            sellAmount.put("balance", detailTotalBalance.subtract(cloudBalanceIncome));
             return sellAmount;
         }
 

+ 157 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SubjectChangeServiceImpl.java

@@ -469,6 +469,9 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
         for (Goods goods : goodies) {
             goodsPrice = goodsPrice.add(goods.getDiscountPrice());
         }
+        
+        Map<Integer,Goods> goodsMap = goodies.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+        
         subjectChange.setChangeCost(goodsPrice);
         subjectChange.setCostMargin(subjectChange.getChangeCost().subtract(subjectChange.getOriginalCost()));
         //差价 <= 0
@@ -521,6 +524,160 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
             subjectChange.setOrderNo(orderNo);
             subjectChangeDao.update(subjectChange);
 
+            //添加订单详情
+            List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
+            StudentPaymentOrderDetail studentPaymentOrderDetail = null;
+        	Goods goods = null;
+			List<Integer> minuendStockGoodsIdList = null;
+			GoodsProcurement goodsProcurement = null;
+			Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
+			Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
+			
+            for(String goodsIdStr : goodsIds.split(",")){
+        		if(StringUtils.isBlank(goodsIdStr)){
+					continue;
+				}
+				goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+				
+				if(goods != null){
+					studentPaymentOrderDetail = new StudentPaymentOrderDetail();
+	                studentPaymentOrderDetail.setCreateTime(nowDate);
+	                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);
+                	studentPaymentOrderDetail.setPrice(BigDecimal.ZERO);
+	                studentPaymentOrderDetail.setUpdateTime(nowDate);
+	                studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
+	                
+	                studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
+	                
+	                //扣减库存
+					
+					BigDecimal totalGroupPurchaseAmount = BigDecimal.ZERO;
+					
+					BigDecimal groupPurchaseAmount = BigDecimal.ZERO;
+					
+					minuendStockGoodsIdList = new ArrayList<Integer>();
+					
+					// 是否是组合商品
+					if(StringUtils.isNotBlank(goods.getComplementGoodsIdList())){
+						List<Goods> goodsList = goodsService.getGoodsWithLocked(goods.getComplementGoodsIdList());
+						totalGroupPurchaseAmount =  totalGroupPurchaseAmount.add(goodsList.stream().map(Goods :: getGroupPurchasePrice).reduce(BigDecimal.ZERO,BigDecimal :: add));
+						
+						for(Goods subGoods : goodsList){
+							
+							if(batchUpdateGoodsMap.get(subGoods.getId()) != null){
+								subGoods = batchUpdateGoodsMap.get(subGoods.getId());
+							}
+							//判断是否有内部库存
+							if(subGoods.getStockCount() > 0){
+								
+								groupPurchaseAmount = groupPurchaseAmount.add(subGoods.getGroupPurchasePrice());
+								subGoods.setStockCount(new AtomicInteger(subGoods.getStockCount()).decrementAndGet());
+								subGoods.setSellCount(new AtomicInteger(subGoods.getSellCount()).incrementAndGet());
+								subGoods.setUpdateTime(nowDate);
+								
+								batchUpdateGoodsMap.put(subGoods.getId(), subGoods);
+								
+								minuendStockGoodsIdList.add(subGoods.getId());
+								
+								goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(subGoods.getId());
+								if(goodsProcurement != null){
+									if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+										goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+									}
+									goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
+									goodsProcurement.setUpdateTime(nowDate);
+									goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
+								}
+							}
+						}
+					}else{
+						totalGroupPurchaseAmount = totalGroupPurchaseAmount.add(goods.getGroupPurchasePrice());
+						
+						if(batchUpdateGoodsMap.get(goods.getId()) != null){
+							goods = batchUpdateGoodsMap.get(goods.getId());
+						}
+						
+						//判断是否有内部库存
+						if(goods.getStockCount() > 0){
+							
+							groupPurchaseAmount = groupPurchaseAmount.add(goods.getGroupPurchasePrice());
+							goods.setStockCount(new AtomicInteger(goods.getStockCount()).decrementAndGet());
+							goods.setSellCount(new AtomicInteger(goods.getSellCount()).incrementAndGet());
+							goods.setUpdateTime(nowDate);
+							batchUpdateGoodsMap.put(goods.getId(), goods);
+							
+							minuendStockGoodsIdList.add(goods.getId());
+							
+							goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
+							if(goodsProcurement != null){
+								if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+									goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+								}
+								goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
+								goodsProcurement.setUpdateTime(nowDate);
+								goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
+							}
+						}
+					}
+				}
+        	}
+            
+            //原始订单的库存要归还
+            List<StudentPaymentOrderDetail> originalStudentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(subjectChange.getOriginalOrderId().longValue());
+            String originalGoodsIds = originalStudentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
+            if(StringUtils.isNotBlank(originalGoodsIds)){
+            	List<Goods> goodsList = goodsService.getGoodsWithLocked(originalGoodsIds);
+            	goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+            	
+            	for(String goodsIdStr : originalGoodsIds.split(",")){
+            		if(StringUtils.isBlank(goodsIdStr)){
+						continue;
+					}
+					goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+					if(batchUpdateGoodsMap.get(goods.getId()) != null){
+						goods = batchUpdateGoodsMap.get(goods.getId());
+					}
+					goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
+					goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
+					goods.setUpdateTime(nowDate);
+					
+					batchUpdateGoodsMap.put(goods.getId(), goods);
+					
+					// 进货清单
+					goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
+					if(goodsProcurement != null){
+						if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
+							goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
+						}
+						goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
+						goodsProcurement.setUpdateTime(nowDate);
+						goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
+					}
+					
+            	}
+            }
+            
+            if(studentPaymentOrderDetailList.size() > 0){
+            	studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
+            }
+			
+			if(goodsProcurementMap.size() > 0){
+				goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
+			}
+    		
+    		if(batchUpdateGoodsMap.size() > 0){
+    			goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
+    		}
+
             //退原订单商品
             sellOrderService.refundByOrderId(subjectChange.getOriginalOrderId().longValue(), false);
 

+ 11 - 4
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderDetailMapper.xml

@@ -21,6 +21,7 @@
         <result column="is_renew_" property="isRenew"/>
         <result column="income_item_" property="incomeItem"/>
         <result column="income_" property="income"/>
+        <result column="balance_income_" property="balanceIncome"/>
         <result column="minuend_stock_goods_id_list_" property="minuendStockGoodsIdList"/>
         <result column="user_id_" property="userId"/>
         <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
@@ -65,10 +66,10 @@
             keyColumn="id" keyProperty="id">
         INSERT INTO student_payment_order_detail
         (type_,goods_id_list_,price_,create_time_,update_time_,payment_order_id_,kit_group_purchase_type_,
-         student_instrument_id_,is_renew_,income_item_,income_,minuend_stock_goods_id_list_,tenant_id_,remit_fee_)
+         student_instrument_id_,is_renew_,income_item_,income_,balance_income_,minuend_stock_goods_id_list_,tenant_id_,remit_fee_)
         VALUES(#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goodsIdList},#{price},now(),now(),
         #{paymentOrderId},#{kitGroupPurchaseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-               #{studentInstrumentId},#{isRenew},#{incomeItem},#{income},#{minuendStockGoodsIdList},#{tenantId},#{remitFee})
+               #{studentInstrumentId},#{isRenew},#{incomeItem},#{income},#{balanceIncome},#{minuendStockGoodsIdList},#{tenantId},#{remitFee})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -103,6 +104,9 @@
             <if test="income != null">
                 income_ = #{income},
             </if>
+            <if test="balanceIncome != null">
+                balance_income_ = #{balanceIncome},
+            </if>
             <if test="minuendStockGoodsIdList != null">
                 minuend_stock_goods_id_list_ = #{minuendStockGoodsIdList},
             </if>
@@ -142,6 +146,9 @@
 	            <if test="item.income != null">
 	                income_ = #{item.income},
 	            </if>
+	            <if test="item.balanceIncome != null">
+	                balance_income_ = #{item.balanceIncome},
+	            </if>
 	            <if test="item.minuendStockGoodsIdList != null">
 	                minuend_stock_goods_id_list_ = #{item.minuendStockGoodsIdList},
 	            </if>
@@ -172,13 +179,13 @@
     <insert id="batchAdd" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id_">
         INSERT INTO student_payment_order_detail
         (type_,goods_id_list_,price_,remit_fee_,create_time_,update_time_,payment_order_id_,
-         kit_group_purchase_type_,student_instrument_id_,is_renew_,income_item_,income_,minuend_stock_goods_id_list_,tenant_id_)
+         kit_group_purchase_type_,student_instrument_id_,is_renew_,income_item_,income_,balance_income_,minuend_stock_goods_id_list_,tenant_id_)
         VALUE
         <foreach collection="studentPaymentOrderDetailList" item="orderDetail" separator=",">
             (#{orderDetail.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
             #{orderDetail.goodsIdList},#{orderDetail.price},#{orderDetail.remitFee},now(),now(),#{orderDetail.paymentOrderId},
             #{orderDetail.kitGroupPurchaseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-            #{orderDetail.studentInstrumentId},#{orderDetail.isRenew},#{orderDetail.incomeItem},#{orderDetail.income},#{orderDetail.minuendStockGoodsIdList},#{orderDetail.tenantId})
+            #{orderDetail.studentInstrumentId},#{orderDetail.isRenew},#{orderDetail.incomeItem},#{orderDetail.income},#{orderDetail.balanceIncome},#{orderDetail.minuendStockGoodsIdList},#{orderDetail.tenantId})
         </foreach>
     </insert>