浏览代码

Merge branch 'saas' of http://git.dayaedu.com/yonge/mec into saas_zouxuan_2022_05_31

zouxuan 3 年之前
父节点
当前提交
23512294b9

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentOrderDetailDao.java

@@ -26,6 +26,8 @@ public interface StudentPaymentOrderDetailDao extends BaseDAO<Long, StudentPayme
      * @return
      */
     int batchAdd(@Param("studentPaymentOrderDetailList") List<StudentPaymentOrderDetail> studentPaymentOrderDetailList);
+    
+    int batchUpdate(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList);
 
     /**
      * 查询注册支付的订单详情

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

@@ -60,6 +60,10 @@ public class StudentPaymentOrderDetail extends BaseEntity {
 
 	//乐保是否是续费 0-否 1-是
 	private Integer isRenew;
+	
+	private String incomeItem;
+	
+	private BigDecimal income;
 
 	@ApiModelProperty(value = "子商品列表",required = false)
 	private List<Goods> childGoodsList;
@@ -208,4 +212,20 @@ public class StudentPaymentOrderDetail extends BaseEntity {
 	public void setCloudTeacherOrderDto(CloudTeacherOrderDto cloudTeacherOrderDto) {
 		this.cloudTeacherOrderDto = cloudTeacherOrderDto;
 	}
+
+	public String getIncomeItem() {
+		return incomeItem;
+	}
+
+	public void setIncomeItem(String incomeItem) {
+		this.incomeItem = incomeItem;
+	}
+
+	public BigDecimal getIncome() {
+		return income;
+	}
+
+	public void setIncome(BigDecimal income) {
+		this.income = income;
+	}
 }

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/PayService.java

@@ -12,7 +12,8 @@ import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
 public interface PayService {
 	/**
 	*
-	* @param amount 支付金额
+	* @param amount 支付现金
+	* @param balanceAmount 支付余额
 	* @param orderNo 订单编号
 	* @param notifyUrl 回调地址
 	* @param returnUrl 返回地址

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

@@ -18,6 +18,8 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
      * @param studentPaymentOrderDetailList 订单详情
      */
     int batchAdd(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList);
+    
+    int batchUpdate(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList);
 
     /**
      * 按比例分摊优惠券减免金额-并且批量添加订单

+ 14 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ExportServiceImpl.java

@@ -26,6 +26,7 @@ import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.excel.POIUtil;
 import com.ym.mec.util.ini.IniFileUtil;
 import com.ym.mec.util.upload.UploadUtil;
+
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.formula.functions.T;
@@ -39,6 +40,7 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.PostConstruct;
 import javax.servlet.http.HttpServletResponse;
+
 import java.io.*;
 import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
@@ -2444,6 +2446,10 @@ public class ExportServiceImpl implements ExportService {
                             row.setMusicGroupCourseFee(row.getMusicGroupCourseFee().add(orderDetail.getPrice()));
                             break;
                         case MUSICAL:
+                        	if(StringUtils.equals(orderDetail.getIncomeItem(), OrderDetailTypeEnum.CLOUD_TEACHER.name())){
+                        		row.setCloudTeacherFee(orderDetail.getIncome());
+                        		break;
+                        	}
                             if (orderDetail.getKitGroupPurchaseType() != null && orderDetail.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
                                 BigDecimal leaseFee = orderDetail.getPrice();
                                 if (row.getExpectAmount().compareTo(BigDecimal.ZERO) > 0) {
@@ -2456,9 +2462,17 @@ public class ExportServiceImpl implements ExportService {
                             break;
                         case ACCESSORIES:
                         case TEACHING:
+                        	if(StringUtils.equals(orderDetail.getIncomeItem(), OrderDetailTypeEnum.CLOUD_TEACHER.name())){
+                        		row.setCloudTeacherFee(orderDetail.getIncome());
+                        		break;
+                        	}
                             row.setTeachingFee(row.getTeachingFee().add(orderDetail.getPrice()));
                             break;
                         case OTHER:
+                        	if(StringUtils.equals(orderDetail.getIncomeItem(), OrderDetailTypeEnum.CLOUD_TEACHER.name())){
+                        		row.setCloudTeacherFee(orderDetail.getIncome());
+                        		break;
+                        	}
                             row.setOtherFee(row.getOtherFee().add(orderDetail.getPrice()));
                             break;
                         case MAINTENANCE:

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

@@ -283,12 +283,12 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
             }
             //当前用户是否购买过免费直播课
             if(list.contains(sysUser.getId())){
-                throw new BizException("您已购买过本轮免费直播课");
+                throw new BizException("您已领取过本轮免费直播课");
             }
             //购买次数是否超过2次
             int count = tempBuyFreeLiveTheoryCourseDao.countByUserId(sysUser.getId());
             if(count >= 2){
-                throw new BizException("免费直播课已达到购买次数上限");
+                throw new BizException("免费直播课已达到领取次数上限");
             }
             //保存购买记录
             tempBuyFreeLiveTheoryCourseDao.insert(new TempBuyFreeLiveTheoryCourse(sysUser.getId()));
@@ -350,13 +350,13 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
             }
             //当前用户是否购买过免费直播课
             if(list.contains(sysUser.getId())){
-                succeed.setMsg("您已购买过本轮免费直播课");
+                succeed.setMsg("您已领取过本轮免费直播课");
                 return succeed;
             }
             //购买次数是否超过2次
             int count = tempBuyFreeLiveTheoryCourseDao.countByUserId(sysUser.getId());
             if(count >= 2){
-                succeed.setMsg("免费直播课已达到购买次数上限");
+                succeed.setMsg("免费直播课已达到领取次数上限");
                 return succeed;
             }
         }else {

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

@@ -9,7 +9,6 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -23,16 +22,20 @@ import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dto.AmountChannelDto;
 import com.ym.mec.biz.dal.dto.RouteScaleDto;
+import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.HfMember;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
 import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
-import com.ym.mec.biz.dal.entity.SysConfig;
 import com.ym.mec.biz.dal.entity.SysPaymentConfig;
 import com.ym.mec.biz.dal.enums.FeeTypeEnum;
+import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
 import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
+import com.ym.mec.biz.service.GoodsService;
 import com.ym.mec.biz.service.PayService;
 import com.ym.mec.biz.service.SellOrderService;
+import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
 import com.ym.mec.biz.service.StudentPaymentOrderService;
 import com.ym.mec.biz.service.SysConfigService;
 import com.ym.mec.biz.service.SysPaymentConfigService;
@@ -50,6 +53,13 @@ import com.ym.mec.util.date.DateUtil;
 public class PayServiceImpl implements PayService {
     @Autowired
     private StudentPaymentOrderService studentPaymentOrderService;
+    
+    @Autowired
+    private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
+    
+    @Autowired
+    private GoodsService goodsService;
+    
     @Autowired
     private SysConfigDao sysConfigDao;
     @Autowired
@@ -111,6 +121,8 @@ public class PayServiceImpl implements PayService {
             return unionPay;
         }
         
+		Date date = new Date();
+        
         //如果当前是买的小课/网管课
 		if (studentPaymentOrder != null && studentPaymentOrder.getType() == OrderTypeEnum.SMALL_CLASS_TO_BUY || studentPaymentOrder.getType() == OrderTypeEnum.PRACTICE_GROUP_BUY
 				|| studentPaymentOrder.getType() == OrderTypeEnum.PRACTICE_GROUP_RENEW) {
@@ -122,7 +134,6 @@ public class PayServiceImpl implements PayService {
 			String isPlatformCollection = sysConfigDao.findConfigValue(SysConfigService.IS_OPEN_SMALL_CLASS_INCOME_TO_PLATFORM);
 			
 			if (StringUtils.equals("1", isPlatformCollection) && !ignoreOrganList.contains(organId)) {
-				Date date = new Date();
 	        	
 	        	String merNo = sysConfigDao.findConfigValue(SysConfigService.PLATFORM_PAYEE_ACCOUNT);
 	        	
@@ -158,12 +169,125 @@ public class PayServiceImpl implements PayService {
 			}
 			
 		}
+
+		BigDecimal subBalance = BigDecimal.ZERO;
+		
+		BigDecimal subCashAmount = BigDecimal.ZERO;
+    	//忽略的分部
+		List<Integer> ignoreOrganList = Arrays.asList(4, 55, 59);
+		
+		//查询商品收款账户配置
+        String goodsSellReceiptMerNo = sysConfigDao.findConfigValue("goodsSellReceiptMerNo");
+        
+        if(!ignoreOrganList.contains(organId) && StringUtils.isNotBlank(goodsSellReceiptMerNo)){
+			
+        	//根据商户号查询对应分部
+        	SysPaymentConfig sysPaymentConfig = sysPaymentConfigService.findPaymentConfigByMerNo(StringUtils.trim(goodsSellReceiptMerNo));
+        	
+        	if(sysPaymentConfig != null){
+
+    			List<StudentPaymentOrderDetail> batchUpdateList = new ArrayList<StudentPaymentOrderDetail>();
+        		
+        		// 如果买了商品或组合商品,商品有内部库存,则将钱转入指定账户已云教练的方式作为收费项目(杭州、齐齐哈尔除外)
+        		// 1.查询商品订单明细
+        		List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
+        		if (studentPaymentOrderDetailList != null && studentPaymentOrderDetailList.size() > 0) {
+        			
+        			String goodIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getGoodsIdList())).map(StudentPaymentOrderDetail :: getGoodsIdList).collect(Collectors.joining(","));
+        			if(StringUtils.isNotBlank(goodIds)){
+        				List<Goods> goodsList = goodsService.findGoodsByIds(goodIds);
+        				
+        				Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
+        				Goods goods = null;
+        				BigDecimal totalAmout = studentPaymentOrder.getExpectAmount();
+        				
+        				for(StudentPaymentOrderDetail spod : studentPaymentOrderDetailList){
+        					
+        					if(StringUtils.isBlank(spod.getGoodsIdList())){
+        						continue;
+        					}
+        					BigDecimal tempBalance = BigDecimal.ZERO;
+        					
+        					BigDecimal tempCashAmount = BigDecimal.ZERO;
+        					
+        					BigDecimal totalGroupPurchaseAmount = BigDecimal.ZERO;
+        					
+        					BigDecimal groupPurchaseAmount = BigDecimal.ZERO;
+        					
+        					for(String goodsIdStr : spod.getGoodsIdList().split(",")){
+        						if(StringUtils.isBlank(goodsIdStr)){
+        							continue;
+        						}
+        						goods = goodsMap.get(Integer.parseInt(goodsIdStr));
+        						
+        						if(goods != null){
+        							// 是否是组合商品
+        							if(StringUtils.isNotBlank(goods.getComplementGoodsIdList())){
+        								goodsList = goodsService.findGoodsByIds(goods.getComplementGoodsIdList());
+        								totalGroupPurchaseAmount =  totalGroupPurchaseAmount.add(goodsList.stream().map(Goods :: getGroupPurchasePrice).reduce(BigDecimal.ZERO,BigDecimal :: add));
+        								
+        								for(Goods subGoods : goodsList){
+        									//判断是否有内部库存
+        									if(subGoods.getStockCount() > 0){
+        										groupPurchaseAmount = groupPurchaseAmount.add(subGoods.getGroupPurchasePrice());
+        									}
+        								}
+        							}else{
+    									totalGroupPurchaseAmount = totalGroupPurchaseAmount.add(goods.getGroupPurchasePrice());
+        								//判断是否有内部库存
+        								if(goods.getStockCount() > 0){
+    										groupPurchaseAmount = groupPurchaseAmount.add(goods.getGroupPurchasePrice());
+        								}
+        							}
+        						}
+        					}
+        					
+							if (groupPurchaseAmount.doubleValue() > 0) {
+	        					// 3.是否使用余额
+								if (balanceAmount.doubleValue() > 0) {
+									tempBalance = balanceAmount.multiply(spod.getPrice()).divide(totalAmout).multiply(groupPurchaseAmount)
+											.divide(totalGroupPurchaseAmount);
+									subBalance = subBalance.add(tempBalance);
+								}
+								tempCashAmount = spod.getPrice().subtract(tempBalance).multiply(groupPurchaseAmount).divide(totalGroupPurchaseAmount);
+								subCashAmount = subCashAmount.add(spod.getPrice().subtract(tempBalance).subtract(tempCashAmount));
+								spod.setIncomeItem(OrderDetailTypeEnum.CLOUD_TEACHER.name());
+								spod.setIncome(tempCashAmount);
+								batchUpdateList.add(spod);
+							}
+        				}
+        			}
+        		}
+        		
+        		if(batchUpdateList.size() > 0){
+        			studentPaymentOrderDetailService.batchUpdate(batchUpdateList);
+        		}
+        		
+        		if(subCashAmount.doubleValue() > 0){
+        			StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
+    	            studentPaymentRouteOrder.setOrderNo(orderNo);
+    	            studentPaymentRouteOrder.setRouteOrganId(sysPaymentConfig.getOrganId());
+    	            studentPaymentRouteOrder.setFeeFlag("Y");
+    	            studentPaymentRouteOrder.setRouteAmount(subCashAmount);
+    	            studentPaymentRouteOrder.setRouteBalanceAmount(subBalance);
+    	            studentPaymentRouteOrder.setMerNo(goodsSellReceiptMerNo);
+    	            studentPaymentRouteOrder.setSaleAmount(BigDecimal.ZERO);
+    	            studentPaymentRouteOrder.setServiceAmount(amount);
+    	            studentPaymentRouteOrder.setCreateTime(date);
+    	            studentPaymentRouteOrder.setUpdateTime(date);
+    	            studentPaymentRouteOrderDao.insert(studentPaymentRouteOrder);
+        		}
+        	}
+        }
+		
+		amount = amount.subtract(subCashAmount);
+		balanceAmount = balanceAmount.subtract(subBalance);
         
         String usePaymentConfig = sysConfigDao.findConfigValue("use_payment_config");// 是否用收费配置(1:使用 0:不使用)
         List<RouteScaleDto> routeScaleDtos = null;
         //使用配置开关
         if (usePaymentConfig.equals("0")) {
-            routeScaleDtos = noUsePaymentConfig(amount);
+            routeScaleDtos = noUsePaymentConfig(amount); //款项都收到平台商户
         }
 
         //根据费用类型

+ 7 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -10,6 +10,7 @@ import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
+
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -75,7 +76,12 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
                 .orElse(0);
     }
 
-    @Transactional(rollbackFor = Exception.class)
+    @Override
+	public int batchUpdate(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList) {
+		return studentPaymentOrderDetailDao.batchUpdate(studentPaymentOrderDetailList);
+	}
+
+	@Transactional(rollbackFor = Exception.class)
     @Override
     public int allocateAndAdd(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList, BigDecimal couponRemitFee) {
         return Optional.ofNullable(studentPaymentOrderDetailList)

+ 49 - 5
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderDetailMapper.xml

@@ -19,8 +19,9 @@
                 typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="student_instrument_id_" property="studentInstrumentId"/>
         <result column="is_renew_" property="isRenew"/>
+        <result column="income_item_" property="incomeItem"/>
+        <result column="income_" property="income"/>
         <result column="user_id_" property="userId"/>
-        <result column="remit_fee_" property="remitFee"/>
         <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
             <result column="goods_id_" property="id"/>
             <result column="goods_name_" property="name"/>
@@ -63,10 +64,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_,tenant_id_,remit_fee_)
+         student_instrument_id_,is_renew_,income_item_,income_,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},#{tenantId},#{remitFee})
+               #{studentInstrumentId},#{isRenew},#{incomeItem},#{income},#{tenantId},#{remitFee})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -95,9 +96,52 @@
             <if test="studentInstrumentId != null">
                 student_instrument_id_ = #{studentInstrumentId},
             </if>
+            <if test="incomeItem != null">
+                income_item_ = #{incomeItem},
+            </if>
+            <if test="income != null">
+                income_ = #{income},
+            </if>
         </set>
         WHERE id_ = #{id} and tenant_id_ = #{tenantId}
     </update>
+    
+    <update id="batchUpdate" parameterType="java.util.List">
+        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
+	        UPDATE student_payment_order_detail
+	        <set>
+	            <if test="item.price != null">
+	                price_ = #{item.price},
+	            </if>
+	            <if test="item.goodsIdList != null">
+	                goods_id_list_ = #{item.goodsIdList},
+	            </if>
+	            <if test="item.updateTime != null">
+	                update_time_ = NOW(),
+	            </if>
+	            <if test="item.paymentOrderId != null">
+	                payment_order_id_ = #{item.paymentOrderId},
+	            </if>
+	            <if test="item.kitGroupPurchaseType != null">
+	                kit_group_purchase_type_ =
+	                #{item.kitGroupPurchaseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+	            </if>
+	            <if test="item.type != null">
+	                type_ = #{item.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+	            </if>
+	            <if test="item.studentInstrumentId != null">
+	                student_instrument_id_ = #{item.studentInstrumentId},
+	            </if>
+	            <if test="item.incomeItem != null">
+	                income_item_ = #{item.incomeItem},
+	            </if>
+	            <if test="item.income != null">
+	                income_ = #{item.income},
+	            </if>
+	        </set>
+	        WHERE id_ = #{item.id} and tenant_id_ = #{item.tenantId}
+        </foreach>
+    </update>
 
     <!-- 根据主键删除一条记录 -->
     <delete id="delete">
@@ -121,13 +165,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_,tenant_id_)
+         kit_group_purchase_type_,student_instrument_id_,is_renew_,income_item_,income_,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.tenantId})
+            #{orderDetail.studentInstrumentId},#{orderDetail.isRenew},#{orderDetail.incomeItem},#{orderDetail.income},#{orderDetail.tenantId})
         </foreach>
     </insert>
 

+ 3 - 0
mec-biz/src/main/resources/config/mybatis/SysCouponMapper.xml

@@ -106,6 +106,9 @@
 			<if test="useCondition != null">
 				use_condition_ = #{useCondition},
 			</if>
+			<if test="issuanceType != null">
+				issuance_type_ = #{issuanceType},
+			</if>
 				update_time_ = NOW()
 		</set>
 		WHERE id_ = #{id} and tenant_id_ = #{tenantId}