Browse Source

Merge branch 'master' into river

# Conflicts:
#	mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java
周箭河 5 years ago
parent
commit
0349541a64
19 changed files with 579 additions and 244 deletions
  1. 7 5
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysAccountDao.java
  2. 24 1
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrder.java
  3. 26 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysAccount.java
  4. 24 1
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysUserCashAccountDetail.java
  5. 10 0
      mec-biz/src/main/java/com/ym/mec/biz/service/PayService.java
  6. 8 6
      mec-biz/src/main/java/com/ym/mec/biz/service/SysAccountService.java
  7. 180 54
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java
  8. 142 2
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java
  9. 8 4
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java
  10. 5 1
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java
  11. 4 4
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysAccountServiceImpl.java
  12. 20 1
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java
  13. 10 2
      mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml
  14. 25 8
      mec-biz/src/main/resources/config/mybatis/SysAccountMapper.xml
  15. 12 0
      mec-biz/src/main/resources/config/mybatis/SysUserCashAccountDetailMapper.xml
  16. 3 132
      mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java
  17. 36 2
      mec-thirdparty/src/main/java/com/ym/mec/thirdparty/yqpay/YqPayUtil.java
  18. 18 9
      mec-web/src/main/java/com/ym/mec/web/controller/StudentPaymentOrderController.java
  19. 17 12
      mec-web/src/main/java/com/ym/mec/web/controller/SysUserCashAccountDetailController.java

+ 7 - 5
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysAccountDao.java

@@ -10,21 +10,23 @@ import java.util.List;
 public interface SysAccountDao extends BaseDAO<Integer, SysAccount> {
 
     /**
-     * 获取一个私
+     * 获取支付账
      *
+     * @param company
+     * @param channel
+     * @param type
      * @param amount
      * @return
      */
-    SysAccount getPerAccount(@Param("amount") BigDecimal amount);
+    List<SysAccount> getAccount(@Param("company") String company, @Param("channel") String channel, @Param("type") String type, @Param("amount") BigDecimal amount);
 
     /**
-     * 获取一个支付账户
+     * 获取一个支付
      * @param company
      * @param channel
      * @param type
      * @param amount
      * @return
      */
-    SysAccount getAccount(@Param("company") String company, @Param("channel") String channel, @Param("type") String type, @Param("amount") BigDecimal amount);
-
+    SysAccount getOneAccount(@Param("company") String company, @Param("channel") String channel, @Param("type") String type, @Param("amount") BigDecimal amount);
 }

+ 24 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentPaymentOrder.java

@@ -42,6 +42,14 @@ public class StudentPaymentOrder {
 	/** 实际金额 */
 	@ApiModelProperty(value = "实际金额",required = true)
 	private BigDecimal actualAmount;
+
+	/** 公户金额 */
+	@ApiModelProperty(value = "公户金额",required = true)
+	private BigDecimal comAmount;
+
+	/** 私户金额 */
+	@ApiModelProperty(value = "私户金额",required = true)
+	private BigDecimal perAmount;
 	
 	@ApiModelProperty(value = "余额付款金额",required = true)
 	private BigDecimal balancePaymentAmount;
@@ -279,9 +287,24 @@ public class StudentPaymentOrder {
 		this.user = user;
 	}
 
+	public BigDecimal getComAmount() {
+		return comAmount;
+	}
+
+	public void setComAmount(BigDecimal comAmount) {
+		this.comAmount = comAmount;
+	}
+
+	public BigDecimal getPerAmount() {
+		return perAmount;
+	}
+
+	public void setPerAmount(BigDecimal perAmount) {
+		this.perAmount = perAmount;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);
 	}
-
 }

+ 26 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysAccount.java

@@ -45,6 +45,16 @@ public class SysAccount {
     */
     private String type;
 
+    /**
+     * 状态 0-停用 1-使用
+     */
+    private Integer status;
+
+    /**
+    * 分佣金额
+    */
+    private BigDecimal routingFee;
+
 
     public Integer getId() {
         return id;
@@ -117,4 +127,20 @@ public class SysAccount {
     public void setRoutingMerNo(String routingMerNo) {
         this.routingMerNo = routingMerNo;
     }
+
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
+    public BigDecimal getRoutingFee() {
+        return routingFee;
+    }
+
+    public void setRoutingFee(BigDecimal routingFee) {
+        this.routingFee = routingFee;
+    }
 }

+ 24 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysUserCashAccountDetail.java

@@ -43,6 +43,14 @@ public class SysUserCashAccountDetail {
 	@ApiModelProperty(value = "交易金额",required = false)
 	private BigDecimal amount;
 
+	/** 公户金额 */
+	@ApiModelProperty(value = "公户金额",required = false)
+	private BigDecimal comAmount;
+
+	/** 私户金额 */
+	@ApiModelProperty(value = "私户金额",required = false)
+	private BigDecimal perAmount;
+
 	/** 账户可用余额 */
 	@ApiModelProperty(value = "账户可用余额",required = false)
 	private BigDecimal balance;
@@ -191,9 +199,24 @@ public class SysUserCashAccountDetail {
 		this.platformAccountNo = platformAccountNo;
 	}
 
+	public BigDecimal getComAmount() {
+		return comAmount;
+	}
+
+	public void setComAmount(BigDecimal comAmount) {
+		this.comAmount = comAmount;
+	}
+
+	public BigDecimal getPerAmount() {
+		return perAmount;
+	}
+
+	public void setPerAmount(BigDecimal perAmount) {
+		this.perAmount = perAmount;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);
 	}
-
 }

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/PayService.java

@@ -1,9 +1,16 @@
 package com.ym.mec.biz.service;
 
 
+import com.ym.mec.biz.dal.entity.CooperationOrgan;
+import com.ym.mec.biz.dal.entity.MusicGroup;
+import com.ym.mec.biz.dal.entity.SysAccount;
+import com.ym.mec.biz.dal.enums.PaymentChannelTypeEnum;
+import com.ym.mec.thirdparty.adapay.Pay;
 import com.ym.mec.thirdparty.yqpay.Msg;
+import com.ym.mec.thirdparty.yqpay.YqPayUtil;
 
 import java.math.BigDecimal;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -28,6 +35,9 @@ public interface PayService {
     Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer userId) throws Exception;
 
 
+    Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer userId,Map<String,BigDecimal> fee,Integer organId) throws Exception;
+
+
     Map query(String orderNo) throws Exception;
 
 }

+ 8 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/SysAccountService.java

@@ -10,21 +10,23 @@ import java.util.List;
 public interface SysAccountService extends BaseService<Integer, SysAccount> {
 
     /**
-     * 获取一个私户
-     *
+     * 获取收款账户
+     * @param company
+     * @param channel
+     * @param type
+     * @param amount
      * @return
      */
-    SysAccount getPerAccount(BigDecimal amount);
-
+    List<SysAccount> getAccount(String company, String channel, String type,  BigDecimal amount);
 
     /**
-     * 获取一个收款账户
+     * 获取一个支付账户
      * @param company
      * @param channel
      * @param type
      * @param amount
      * @return
      */
-    SysAccount getAccount(String company, String channel, String type,  BigDecimal amount);
+    SysAccount getOneAccount(String company, String channel, String type,  BigDecimal amount);
 
 }

+ 180 - 54
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -128,13 +128,13 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
     @Autowired
     private CourseScheduleTeacherSalaryDao courseScheduleTeacherSalaryDao;
-    
+
     @Autowired
     private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
 
     @Autowired
     private CooperationOrganDao cooperationOrganDao;
-    
+
     @Autowired
     private TeacherAttendanceDao teacherAttendanceDao;
 
@@ -152,19 +152,19 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
     @Autowired
     private EmployeeDao employeeDao;
-	
+
 	@Autowired
 	private SysMessageService sysMessageService;
 
 	@Autowired
 	private SysConfigDao sysConfigDao;
-	
+
 	@Autowired
 	private ClassGroupService classGroupService;
-	
+
 	@Autowired
     private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
-	
+
     @Autowired
     private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
     @Autowired
@@ -175,12 +175,12 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     private MusicGroupSubjectGoodsGroupService musicGroupSubjectGoodsGroupService;
     @Autowired
     private GoodsService goodsService;
-    
+
     @Autowired
     private ImFeignService imFeignService;
-    
+
     private SimpleDateFormat sdf_ymd = new SimpleDateFormat("yyyy-MM-dd");
-    
+
     private SimpleDateFormat sdf_hms=new SimpleDateFormat("HH:mm:ss");
 
     @Override
@@ -358,6 +358,13 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         studentPaymentOrder.setVersion(studentPaymentOrder.getVersion()+1);
 
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
+
+        Map<String, BigDecimal> classFee = new HashMap<>();
+        classFee.put("course",BigDecimal.ZERO);
+        classFee.put("instrument",BigDecimal.ZERO);
+        classFee.put("accessories",BigDecimal.ZERO);
+        classFee.put("other",amount);
+
         Map payMap = payService.getPayMap(
                 amount,
                 orderNo,
@@ -365,8 +372,14 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 baseApiUrl+"/#/paymentresult?orderNo=" + orderNo,
                 chargeInfo.getTitle(),
                 chargeInfo.getTitle(),
-                userId);
-
+                userId,
+                classFee,
+                chargeInfo.getOrganId()
+        );
+
+        Map<String,BigDecimal> routingFee = (Map<String,BigDecimal>)payMap.get("routingFee");
+        studentPaymentOrder.setComAmount(routingFee.get("COM"));
+        studentPaymentOrder.setPerAmount(routingFee.get("PER"));
         studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
         studentPaymentOrder.setUpdateTime(date);
         studentPaymentOrderService.update(studentPaymentOrder);
@@ -395,10 +408,12 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
         orderAmount = orderAmount.add(courseFee);
 
+        BigDecimal instrumentFee = BigDecimal.ZERO;
+        BigDecimal accessoriesFee = BigDecimal.ZERO;
+        BigDecimal otherFee = BigDecimal.ZERO;
 
         //乐器及打包辅件
         List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
-
         if (studentRegistration.getTemporaryCourseFee() != null) {
             List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), DealStatusEnum.WAIT_PAY);
             for (StudentPaymentOrderDetail orderDetail : orderDetails) {
@@ -415,6 +430,13 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 musicGroupSubjectGoodsGroup.setPrice(orderDetail.getPrice());
 
                 goodsGroups.add(musicGroupSubjectGoodsGroup);
+                if(musicGroupSubjectGoodsGroup.getType().equals(GoodsType.INSTRUMENT)){
+                    instrumentFee = instrumentFee.add(orderDetail.getPrice());
+                }else if(musicGroupSubjectGoodsGroup.getType().equals(GoodsType.ACCESSORIES)) {
+                    accessoriesFee = accessoriesFee.add(orderDetail.getPrice());
+                }else {
+                    otherFee = otherFee.add(orderDetail.getPrice());
+                }
 
                 orderAmount = orderAmount.add(orderDetail.getPrice());
             }
@@ -422,18 +444,23 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
             for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
-                    orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
                     goodsGroup.setPrice(musicOneSubjectClassPlan.getDepositFee());
-                    continue;
                 }
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
                 	goodsGroup.setPrice(new BigDecimal(0));
-                	continue;
                 }
                 orderAmount = orderAmount.add(goodsGroup.getPrice());
+                if(goodsGroup.getType().equals(GoodsType.INSTRUMENT)){
+                    instrumentFee = instrumentFee.add(goodsGroup.getPrice());
+                }else if(goodsGroup.getType().equals(GoodsType.ACCESSORIES)) {
+                    accessoriesFee = accessoriesFee.add(goodsGroup.getPrice());
+                }else {
+                    otherFee = otherFee.add(goodsGroup.getPrice());
+                }
                 //团购乐器减免课程费用
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
                     orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
+                    courseFee.subtract(goodsGroup.getRemissionCourseFee());
                 }
             }
         }
@@ -444,6 +471,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
             for (Goods goods : goodsList) {
                 orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+                accessoriesFee = accessoriesFee.add(goods.getGroupPurchasePrice());
             }
         }
 
@@ -453,14 +481,14 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
             for (Goods goods : otherGoodsList) {
                 orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+                otherFee = otherFee.add(goods.getGroupPurchasePrice());
             }
         }
         if (amount.compareTo(orderAmount) != 0) {
             throw new BizException("商品价格不符");
         }
-
         String orderNo = idGeneratorService.generatorId("payment") + "";
-        
+
         String channelType = "";
 
         StudentPaymentOrder studentPaymentOrder = studentRegistrationService.addOrder(studentRegistration, amount, orderNo, channelType, courseFee, goodsGroups, goodsList, otherGoodsList);
@@ -504,6 +532,28 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
         studentPaymentOrder.setVersion(studentPaymentOrder.getVersion()+1);
 
+        MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
+        //分类费用 course,instrument,accessories,other
+        Map<String, BigDecimal> classFee = new HashMap<>();
+        classFee.put("course",courseFee);
+        classFee.put("instrument",instrumentFee);
+        classFee.put("accessories",accessoriesFee);
+        classFee.put("other",otherFee);
+        BigDecimal classFeeAmount = courseFee.add(instrumentFee).add(accessoriesFee).add(otherFee);
+
+        if(amount.compareTo(classFeeAmount) < 0){
+            BigDecimal subAmount = classFeeAmount.subtract(amount);
+            for (Map.Entry<String, BigDecimal> feeEntry : classFee.entrySet()) {
+                if(subAmount.compareTo(feeEntry.getValue()) > 0){
+                    classFee.put(feeEntry.getKey(),BigDecimal.ZERO);
+                    subAmount = subAmount.subtract(feeEntry.getValue());
+                }else {
+                    classFee.put(feeEntry.getKey(),feeEntry.getValue().subtract(subAmount));
+                    break;
+                }
+            }
+        }
+
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
         Map payMap = payService.getPayMap(
                 amount,
@@ -512,8 +562,14 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 baseApiUrl+"/#/paymentresult?orderNo=" + orderNo,
                 "乐团报名缴费",
                 "乐团报名缴费",
-                userId);
-
+                userId,
+                classFee,
+                musicGroup.getOrganId()
+        );
+
+        Map<String,BigDecimal> routingFee = (Map<String,BigDecimal>)payMap.get("routingFee");
+        studentPaymentOrder.setComAmount(routingFee.get("COM"));
+        studentPaymentOrder.setPerAmount(routingFee.get("PER"));
         studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
         studentPaymentOrder.setUpdateTime(date);
         studentPaymentOrderService.update(studentPaymentOrder);
@@ -529,7 +585,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
 
         Integer userId = studentRegistration.getUserId();
-        
+
         StudentPaymentOrder ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId(), DealStatusEnum.ING);
         if (ApplyOrder == null) {
             throw new BizException("没有支付中的订单,请勿非法请求");
@@ -546,6 +602,10 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
         orderAmount = orderAmount.add(courseFee);
 
+        BigDecimal instrumentFee = BigDecimal.ZERO;
+        BigDecimal accessoriesFee = BigDecimal.ZERO;
+        BigDecimal otherFee = BigDecimal.ZERO;
+
 
         //乐器及打包辅件
         List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
@@ -564,23 +624,38 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 musicGroupSubjectGoodsGroup.setGoodsIdList(orderDetail.getGoodsIdList());
                 musicGroupSubjectGoodsGroup.setPrice(orderDetail.getPrice());
                 goodsGroups.add(musicGroupSubjectGoodsGroup);
+
+                if(musicGroupSubjectGoodsGroup.getType().equals(GoodsType.INSTRUMENT)){
+                    instrumentFee = instrumentFee.add(orderDetail.getPrice());
+                }else if(musicGroupSubjectGoodsGroup.getType().equals(GoodsType.ACCESSORIES)) {
+                    accessoriesFee = accessoriesFee.add(orderDetail.getPrice());
+                }else {
+                    otherFee = otherFee.add(orderDetail.getPrice());
+                }
                 orderAmount = orderAmount.add(orderDetail.getPrice());
             }
         } else if (studentRegistration.getTemporaryCourseFee() == null && !registerPayDto.getGoodsGroupIds().equals("")) {
             goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
             for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
-                    orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
-                    continue;
+                    goodsGroup.setPrice(musicOneSubjectClassPlan.getDepositFee());
                 }
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
-                    continue;
+                    goodsGroup.setPrice(new BigDecimal(0));
                 }
 
                 orderAmount = orderAmount.add(goodsGroup.getPrice());
+                if(goodsGroup.getType().equals(GoodsType.INSTRUMENT)){
+                    instrumentFee = instrumentFee.add(goodsGroup.getPrice());
+                }else if(goodsGroup.getType().equals(GoodsType.ACCESSORIES)) {
+                    accessoriesFee = accessoriesFee.add(goodsGroup.getPrice());
+                }else {
+                    otherFee = otherFee.add(goodsGroup.getPrice());
+                }
                 //团购乐器减免课程费用
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
                     orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
+                    courseFee.subtract(goodsGroup.getRemissionCourseFee());
                 }
             }
         }
@@ -591,6 +666,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
             for (Goods goods : goodsList) {
                 orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+                accessoriesFee = accessoriesFee.add(goods.getGroupPurchasePrice());
             }
         }
 
@@ -600,6 +676,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
             for (Goods goods : otherGoodsList) {
                 orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+                otherFee = otherFee.add(goods.getGroupPurchasePrice());
             }
         }
         if (amount.compareTo(orderAmount) != 0) {
@@ -607,13 +684,13 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
 
         String orderNo = idGeneratorService.generatorId("payment") + "";
-        
+
         String channelType = "";
 
         StudentPaymentOrder studentPaymentOrder = studentRegistrationService.reAddOrder(userId, amount, orderNo, channelType, courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId(), ApplyOrder);
         studentPaymentOrder.setVersion(0);
         Date date = new Date();
-        
+
         if(registerPayDto.getIsUseBalancePayment() || amount.doubleValue() == 0){
         	SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
         	if(userCashAccount == null){
@@ -648,6 +725,28 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
         studentPaymentOrder.setVersion(studentPaymentOrder.getVersion()+1);
 
+        MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
+        //分类费用 course,instrument,accessories,other
+        Map<String, BigDecimal> classFee = new HashMap<>();
+        classFee.put("course",courseFee);
+        classFee.put("instrument",instrumentFee);
+        classFee.put("accessories",accessoriesFee);
+        classFee.put("other",otherFee);
+        BigDecimal classFeeAmount = courseFee.add(instrumentFee).add(accessoriesFee).add(otherFee);
+
+        if(amount.compareTo(classFeeAmount) < 0){
+            BigDecimal subAmount = classFeeAmount.subtract(amount);
+            for (Map.Entry<String, BigDecimal> feeEntry : classFee.entrySet()) {
+                if(subAmount.compareTo(feeEntry.getValue()) > 0){
+                    classFee.put(feeEntry.getKey(),BigDecimal.ZERO);
+                    subAmount = subAmount.subtract(feeEntry.getValue());
+                }else {
+                    classFee.put(feeEntry.getKey(),feeEntry.getValue().subtract(subAmount));
+                    break;
+                }
+            }
+        }
+
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
         Map payMap = payService.getPayMap(
                 amount,
@@ -656,12 +755,17 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 baseApiUrl+"/#/paymentresult?orderNo=" + orderNo,
                 "乐团报名缴费",
                 "乐团报名缴费",
-                userId);
-        
+                userId,
+                classFee,
+                musicGroup.getOrganId()
+        );
+
+        Map<String,BigDecimal> routingFee = (Map<String,BigDecimal>)payMap.get("routingFee");
+        studentPaymentOrder.setComAmount(routingFee.get("COM"));
+        studentPaymentOrder.setPerAmount(routingFee.get("PER"));
         studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
         studentPaymentOrder.setUpdateTime(date);
         studentPaymentOrderService.update(studentPaymentOrder);
-        
 		return payMap;
 	}
 
@@ -926,7 +1030,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         if (studentPaymentOrders != null && studentPaymentOrders.size() > 0) {
             throw new BizException("缴费存在交易中的数据,不能取消乐团");
         }
-        
+
         //删除续费记录
         musicGroupStudentFeeDao.deleteByMusicGroupId(musicGroupId);
 
@@ -935,7 +1039,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 		// 删除每节课的课酬
 		courseScheduleStudentPaymentDao.deleteByMusicGroupId(musicGroupId, GroupType.MUSIC);
 		courseScheduleTeacherSalaryDao.deleteByMusicGroupId(musicGroupId, GroupType.MUSIC);
-        
+
         //删除考勤
 		teacherAttendanceDao.deleteByMusicGroupId(musicGroupId, GroupType.MUSIC);
 
@@ -992,10 +1096,10 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         // 清除下次缴费时间
         musicGroupStudentFeeDao.updateNextPaymentDate(musicGroupId, null);
         musicGroupBuildLogDao.insert(new MusicGroupBuildLog(musicGroupId,"暂停乐团",sysUser.getId(),""));
-        
+
         //删除课表
         courseScheduleDao.logicDeleteCourseSchedulesByMusicGroupID(musicGroup.getId());
-        
+
         return true;
     }
 
@@ -1022,10 +1126,10 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         // 重新设置下次缴费时间
         musicGroupStudentFeeDao.updateNextPaymentDate(musicGroupId, musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId));
         musicGroupBuildLogDao.insert(new MusicGroupBuildLog(musicGroupId,"恢复乐团",sysUser.getId(),""));
-        
+
         //恢复课表
         courseScheduleDao.resumeCourseScheduleByMusicGroupId(musicGroup.getId());
-        
+
         return true;
     }
 
@@ -1121,7 +1225,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 			}
 			//更新学员在班级的状态
 			classGroupStudentMapperDao.deleteStudentByMusicGroupId(musicGroupId, userId);
-			
+
 			List<Integer> classGroupIdList = classGroupStudentMapperDao.queryClassGroupIdList(musicGroupId, userId, GroupType.MUSIC);
 			if (classGroupIdList != null && classGroupIdList.size() > 0) {
 				//更新班级人数
@@ -1134,21 +1238,21 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 }
                 imFeignService.groupBatchQuit(imGroupModels);
 			}
-			
+
 			List<CourseSchedule> musicGroupCourseSchedules = courseScheduleDao.findMusicGroupCourseSchedulesWithStudent(musicGroupId,GroupType.MUSIC.getCode(), CourseStatusEnum.NOT_START.getCode(),userId);
 			if(!CollectionUtils.isEmpty(musicGroupCourseSchedules)){
 				List<Long> courseScheduleIds = musicGroupCourseSchedules.stream().map(courseSchedule -> courseSchedule.getId()).collect(Collectors.toList());
 
 				// 删除未上课
 	            courseScheduleDao.deleteMusicGroupCourseSchedulesWithStudent(courseScheduleIds,userId);
-				
+
 				//删除学生缴费表
 				courseScheduleStudentPaymentDao.deleteStudentCourseSchedule(userId, musicGroupCourseSchedules);
 			}
-			
+
 			//删除续费周期
 			musicGroupStudentFeeDao.deleteByUserIdAndMusicGroupId(userId, musicGroupId);
-			
+
 			// 退团
 			studentRegistration.setMusicGroupStatus(ClassGroupStudentStatusEnum.QUIT);
 			studentRegistration.setUpdateTime(date);
@@ -1229,7 +1333,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 		}
 		//更新学员在班级的状态
 		classGroupStudentMapperDao.deleteStudentByMusicGroupId(musicGroupId, userId);
-		
+
 		List<Integer> classGroupIdList = classGroupStudentMapperDao.queryClassGroupIdList(musicGroupId, userId, GroupType.MUSIC);
 		if (classGroupIdList != null && classGroupIdList.size() > 0) {
 			//更新班级人数
@@ -1243,21 +1347,21 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 			}
             imFeignService.groupBatchQuit(imGroupModels);
 		}
-		
+
 		List<CourseSchedule> musicGroupCourseSchedules = courseScheduleDao.findMusicGroupCourseSchedulesWithStudent(musicGroupId,GroupType.MUSIC.getCode(), CourseStatusEnum.NOT_START.getCode(),userId);
 		if(!CollectionUtils.isEmpty(musicGroupCourseSchedules)){
 			List<Long> courseScheduleIds = musicGroupCourseSchedules.stream().map(courseSchedule -> courseSchedule.getId()).collect(Collectors.toList());
 
 			// 删除未上课
             courseScheduleDao.deleteMusicGroupCourseSchedulesWithStudent(courseScheduleIds,userId);
-			
+
 			// 删除学生缴费表
 			courseScheduleStudentPaymentDao.deleteStudentCourseSchedule(userId, musicGroupCourseSchedules);
 		}
-		
+
 		//删除续费周期
 		musicGroupStudentFeeDao.deleteByUserIdAndMusicGroupId(userId, musicGroupId);
-		
+
 		// 退团
 		studentRegistration.setMusicGroupStatus(ClassGroupStudentStatusEnum.QUIT);
 		studentRegistration.setUpdateTime(date);
@@ -1356,7 +1460,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
 
         studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
-        
+
         if(isUseBalancePayment || amount.doubleValue() == 0){
         	SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
         	if(userCashAccount == null){
@@ -1369,9 +1473,9 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
                 studentPaymentOrder.setUpdateTime(date);
                 studentPaymentOrderService.update(studentPaymentOrder);
-                
+
         		sysUserCashAccountService.updateBalance(userId, amount.negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,"乐团续费");
-        		
+
         		//更新下次续费时间
         		musicGroupStudentFee.setUpdateTime(date);
                 musicGroupStudentFee.setLatestPaidTime(date);
@@ -1392,12 +1496,28 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
 
+        //分类费用 course,instrument,accessories,other
+        Map<String, BigDecimal> classFee = new HashMap<>();
+        classFee.put("course",amount);
+        classFee.put("instrument",BigDecimal.ZERO);
+        classFee.put("accessories",BigDecimal.ZERO);
+        classFee.put("other",BigDecimal.ZERO);
+
         try {
 
             Map<String, Object> payMap = payService.getPayMap(amount, studentPaymentOrder.getOrderNo(),
                     baseApiUrl+"/api-student/studentOrder/notify",
                     baseApiUrl+"/#/paymentresult?orderNo=" + studentPaymentOrder.getOrderNo(),
-                    "续费", "乐团续费",userId);
+                    "续费",
+                    "乐团续费",
+                    userId,
+                    classFee,
+                    musicGroup.getOrganId()
+            );
+
+            Map<String,BigDecimal> routingFee = (Map<String,BigDecimal>)payMap.get("routingFee");
+            studentPaymentOrder.setComAmount(routingFee.get("COM"));
+            studentPaymentOrder.setPerAmount(routingFee.get("PER"));
             studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
             studentPaymentOrder.setUpdateTime(date);
             studentPaymentOrderService.update(studentPaymentOrder);
@@ -1412,7 +1532,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public boolean renewForCallback(StudentPaymentOrder studentPaymentOrder) throws IOException {
 
-        studentPaymentOrderDao.update(studentPaymentOrder);
+        studentPaymentOrderService.update(studentPaymentOrder);
 
         Integer userId = studentPaymentOrder.getUserId();
         String musicGroupId = studentPaymentOrder.getMusicGroupId();
@@ -1436,7 +1556,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             musicGroupStudentFee.setTemporaryCourseFee(new BigDecimal(0));
             musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId));
             musicGroupStudentFeeDao.update(musicGroupStudentFee);
-            
+
             //插入交易明细
             SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
             BigDecimal amount = studentPaymentOrder.getActualAmount();
@@ -1451,21 +1571,27 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
             rechargeDetail.setUpdateTime(date);
             rechargeDetail.setUserId(userId);
+            rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+            rechargeDetail.setComAmount(studentPaymentOrder.getComAmount());
+            rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount());
             sysUserCashAccountDetailService.insert(rechargeDetail);
-            
+
             //缴费
             SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
-            paymentDetail.setAmount(amount);
+            paymentDetail.setAmount(amount.negate());
             paymentDetail.setBalance(cashAccount.getBalance());
-            paymentDetail.setComment("费");
+            paymentDetail.setComment("费");
             paymentDetail.setCreateTime(date);
             paymentDetail.setStatus(DealStatusEnum.SUCCESS);
             paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
             paymentDetail.setType(PlatformCashAccountDetailTypeEnum.PAY_FEE);
             paymentDetail.setUpdateTime(date);
             paymentDetail.setUserId(userId);
+            rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+            rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
+            rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
             sysUserCashAccountDetailService.insert(paymentDetail);
-            
+
             // 发送续费结果通知
             sysMessageService.batchSendMessage(MessageSender.JIGUANG, MessageTypeEnum.STUDENT_SMS_MUSIC_GROUP_RENEW_SUCCESS, push, null, 0, "1",
                     studentRegistration.getParentsName(),studentPaymentOrder.getActualAmount());

+ 142 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java

@@ -5,10 +5,12 @@ import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.entity.CooperationOrgan;
 import com.ym.mec.biz.dal.entity.MusicGroup;
 import com.ym.mec.biz.dal.entity.SysAccount;
+import com.ym.mec.biz.dal.entity.SysPaymentConfig;
 import com.ym.mec.biz.dal.enums.PaymentChannelTypeEnum;
 import com.ym.mec.biz.service.PayService;
 import com.ym.mec.biz.service.StudentPaymentOrderService;
 import com.ym.mec.biz.service.SysAccountService;
+import com.ym.mec.biz.service.SysPaymentConfigService;
 import com.ym.mec.thirdparty.adapay.Pay;
 import com.ym.mec.thirdparty.union.UnionPay;
 import com.ym.mec.thirdparty.union.UnionPayFeignService;
@@ -17,7 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -36,6 +40,8 @@ public class PayServiceImpl implements PayService {
     private MusicGroupDao musicGroupDao;
     @Autowired
     private SysConfigDao sysConfigDao;
+    @Autowired
+    private SysPaymentConfigService sysPaymentConfigService;
 
 
     /**
@@ -50,6 +56,7 @@ public class PayServiceImpl implements PayService {
      * @return
      * @throws Exception
      */
+    @Override
     public Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer userId) throws Exception {
 
         String company = "daya";
@@ -85,6 +92,50 @@ public class PayServiceImpl implements PayService {
     }
 
     @Override
+    public Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer userId, Map<String, BigDecimal> fee, Integer organId) throws Exception {
+        String company = "daya";
+        if (userId != null) {
+            MusicGroup musicGroup = musicGroupDao.findUserMusicGroup(userId);
+            if (musicGroup != null && musicGroup.getOwnershipType().equals(CooperationOrgan.OwnershipType.COOPERATION)) {
+                company = "yadie";
+            }
+        }
+
+        //支付通道决策
+        Map unionPay = new HashMap();
+        Map<String, BigDecimal> routingFee = getRoutingFee(company, amount, fee, organId);
+        List<SysAccount> accounts = getRoutingAccount(routingFee, company);
+        SysAccount routingAccount = accounts.get(0);
+
+        Map payMap = null;
+        String type = null;
+        if (routingAccount.getChannel().equals("YQPAY")) {
+            List<Map> tempRoutingList = new ArrayList();
+            for (SysAccount account : accounts) {
+                Map<String, Object> routingList = new HashMap<>();
+                routingList.put("routingMerNo", account.getRoutingMerNo());//分佣账户
+                routingList.put("routingFee", account.getRoutingFee().subtract((account.getRoutingFee().multiply(new BigDecimal(0.28)).divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_UP))); //分佣金额
+                tempRoutingList.add(routingList);
+            }
+            if(accounts.size() ==1 && routingAccount.getMerNo().equals(routingAccount.getRoutingMerNo())){
+                tempRoutingList = null;
+            }
+
+            payMap = YqPayUtil.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, routingAccount.getMerNo(), tempRoutingList);
+            type = "YQPAY";
+        } else {
+            payMap = new Pay().getPayMap(amount, orderNo, notifyUrl, orderSubject, orderBody);
+            type = "ADAPAY";
+        }
+
+        unionPay.put("orderNo", orderNo);
+        unionPay.put("type", type);
+        unionPay.put("payMap", payMap);
+        unionPay.put("routingFee",routingFee);
+        return unionPay;
+    }
+
+    @Override
     public Map<String, Object> query(String orderNo) throws Exception {
         return new UnionPay(unionPayFeignService).query(orderNo);
     }
@@ -115,9 +166,98 @@ public class PayServiceImpl implements PayService {
         if (company.equals("yadie")) {
             type = "PER";
         }
-        routingAccount = sysAccountService.getAccount(company, channel, type, null);
+        SysAccount account = sysAccountService.getOneAccount(company, channel, type, null);
+
+        return account;
+    }
+
+    /**
+     * 获取收款账户
+     *
+     * @param routingFee
+     * @param company
+     * @return
+     */
+    private List<SysAccount> getRoutingAccount(Map<String, BigDecimal> routingFee, String company) {
+        String channel = "";
+        String type = "";
+
+        if (routingFee.get("COM").compareTo(BigDecimal.ZERO) > 0 && routingFee.get("PER").compareTo(BigDecimal.ZERO) > 0) {
+            channel = "YQPAY";
+            type = "COM,PER";
+        } else if (routingFee.get("COM").compareTo(BigDecimal.ZERO) > 0 && routingFee.get("PER").compareTo(BigDecimal.ZERO) == 0) {
+            channel = sysConfigDao.findConfigValue("com_account_channel");
+            type = "COM";
+        } else if (routingFee.get("COM").compareTo(BigDecimal.ZERO) == 0 && routingFee.get("PER").compareTo(BigDecimal.ZERO) > 0) {
+            channel = sysConfigDao.findConfigValue("per_account_channel");
+            type = "PER";
+        }
+        List<SysAccount> accounts = sysAccountService.getAccount(company, channel, type, null);
+
+        for (SysAccount account : accounts) {
+            if (account.getType().equals("COM")) {
+                account.setRoutingFee(routingFee.get("COM"));
+            } else {
+                account.setRoutingFee(routingFee.get("PER"));
+            }
+        }
+        return accounts;
+    }
+
+    /**
+     * 获取分佣金额
+     *
+     * @param fee
+     * @param organId
+     * @return
+     */
+    private Map<String, BigDecimal> getRoutingFee(String company, BigDecimal amount, Map<String, BigDecimal> fee, Integer organId) {
+        Map<String, BigDecimal> routingFee = new HashMap<>(2);
+        routingFee.put("COM", BigDecimal.ZERO);
+        routingFee.put("PER", BigDecimal.ZERO);
+        if (company.equals("yadie")) {
+            routingFee.put("PER", amount);
+            return routingFee;
+        }
+
+        SysPaymentConfig paymentConfig = sysPaymentConfigService.findPaymentConfigByOrganId(organId);
+
+        int payOrderNums = studentPaymentOrderService.findPayOrderNum(); //获取支付中和成功的订单数
+        //前几笔收入私户
+        Integer nums = Integer.parseInt(sysConfigDao.findConfigValue("per_account_nums"));
+        if (paymentConfig != null && paymentConfig.getType().equals(1)) {
+            nums = paymentConfig.getPerScale();
+        }
+
+        String type = null;
+        int rem = (payOrderNums + 1) % 10;
+        if (rem > 0 && rem <= nums) { //私人账户
+            type = "PER";
+        } else {
+            type = "COM";
+        }
+        routingFee.put(type, amount);
 
-        return routingAccount;
+        if (paymentConfig == null || !paymentConfig.getType().equals(2)) {
+            return routingFee;
+        }
+        for (Map.Entry<String, BigDecimal> feeEntry : fee.entrySet()) {
+            if (feeEntry.getKey().equals("course")) {
+                BigDecimal RoutingFee = routingFee.get(paymentConfig.getCourseFee()).add(feeEntry.getValue());
+                routingFee.put(paymentConfig.getCourseFee(), RoutingFee);
+            } else if (feeEntry.getKey().equals("instrument")) {
+                BigDecimal RoutingFee = routingFee.get(paymentConfig.getInstrumentFee()).add(feeEntry.getValue());
+                routingFee.put(paymentConfig.getInstrumentFee(), RoutingFee);
+            } else if (feeEntry.getKey().equals("accessories")) {
+                BigDecimal RoutingFee = routingFee.get(paymentConfig.getAccessoriesFee()).add(feeEntry.getValue());
+                routingFee.put(paymentConfig.getAccessoriesFee(), RoutingFee);
+            } else if (feeEntry.getKey().equals("other")) {
+                BigDecimal RoutingFee = routingFee.get(paymentConfig.getOtherFee()).add(feeEntry.getValue());
+                routingFee.put(paymentConfig.getOtherFee(), RoutingFee);
+            }
+        }
+        return routingFee;
     }
 
+
 }

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

@@ -10,6 +10,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
+import com.ym.mec.biz.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -21,10 +22,6 @@ import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
 import com.ym.mec.biz.dal.enums.OrderTypeEnum;
-import com.ym.mec.biz.service.MusicGroupService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
-import com.ym.mec.biz.service.StudentRegistrationService;
-import com.ym.mec.biz.service.VipGroupService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.adapay.Pay;
@@ -46,6 +43,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     private VipGroupService vipGroupService;
     @Autowired
     private MusicGroupService musicGroupService;
+    @Autowired
+    private SporadicChargeInfoService sporadicChargeInfoService;
 
     @Override
     public BaseDAO<Long, StudentPaymentOrder> getDAO() {
@@ -186,6 +185,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             vipGroupService.orderCallback(order);
         } else if (order.getType().equals(OrderTypeEnum.RENEW)) {
             musicGroupService.renewForCallback(order);
+        } else if (order.getType().equals(OrderTypeEnum.SPORADIC)) {
+            sporadicChargeInfoService.renewForCallback(order);
         }
     }
 
@@ -214,6 +215,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                     vipGroupService.orderCallback(order);
                 } else if (order.getType().equals(OrderTypeEnum.RENEW)) {
                     musicGroupService.renewForCallback(order);
+                } else if (order.getType().equals(OrderTypeEnum.SPORADIC)) {
+                    sporadicChargeInfoService.renewForCallback(order);
                 }
             } catch (Exception e) {
                 e.printStackTrace();
@@ -222,4 +225,5 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         }
 
     }
+
 }

+ 5 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -755,11 +755,13 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             rechargeDetail.setUpdateTime(nowDate);
             rechargeDetail.setUserId(studentRegistration.getUserId());
             rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+            rechargeDetail.setComAmount(studentPaymentOrder.getComAmount());
+            rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount());
             sysUserCashAccountDetailService.insert(rechargeDetail);
 
             //缴费
             SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
-            paymentDetail.setAmount(amount);
+            paymentDetail.setAmount(amount.negate());
             paymentDetail.setBalance(cashAccount.getBalance());
             paymentDetail.setComment("报名缴费");
             paymentDetail.setCreateTime(nowDate);
@@ -769,6 +771,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             paymentDetail.setUpdateTime(nowDate);
             paymentDetail.setUserId(studentRegistration.getUserId());
             rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+            rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
+            rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
             sysUserCashAccountDetailService.insert(paymentDetail);
 
             //发送缴费成功通知(短信 + push)

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

@@ -25,13 +25,13 @@ public class SysAccountServiceImpl extends BaseServiceImpl<Integer, SysAccount>
     }
 
     @Override
-    public SysAccount getPerAccount(BigDecimal money) {
-        return sysAccountDao.getPerAccount(money);
+    public List<SysAccount> getAccount(String company, String channel, String type, BigDecimal amount) {
+        return sysAccountDao.getAccount(company, channel, type, amount);
     }
 
     @Override
-    public SysAccount getAccount(String company, String channel, String type, BigDecimal amount) {
-        return sysAccountDao.getAccount(company, channel, type, amount);
+    public SysAccount getOneAccount(String company, String channel, String type, BigDecimal amount) {
+        return sysAccountDao.getOneAccount(company,channel,type,amount);
     }
 
 }

+ 20 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -1079,6 +1079,12 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		}
 
 		String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
+		//分类费用 course,instrument,accessories,other
+		Map<String, BigDecimal> classFee = new HashMap<>();
+		classFee.put("course",amount);
+		classFee.put("instrument",BigDecimal.ZERO);
+		classFee.put("accessories",BigDecimal.ZERO);
+		classFee.put("other",BigDecimal.ZERO);
 		try {
 			Map<String,Object> payMap = payService.getPayMap(
 					amount,
@@ -1087,7 +1093,14 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 					baseApiUrl+"/#/paymentresult?orderNo=" + orderNo,
 					"vip课购买",
 					vipGroup.getName(),
-					user.getId());
+					user.getId(),
+					classFee,
+					vipGroup.getOrganId()
+			);
+
+			Map<String,BigDecimal> routingFee = (Map<String,BigDecimal>)payMap.get("routingFee");
+			studentPaymentOrder.setComAmount(routingFee.get("COM"));
+			studentPaymentOrder.setPerAmount(routingFee.get("PER"));
 			studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
 			studentPaymentOrder.setUpdateTime(date);
 			studentPaymentOrderService.update(studentPaymentOrder);
@@ -1143,6 +1156,9 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		sysUserIncomeCashAccountDetail.setAmount(order.getActualAmount());
 		sysUserIncomeCashAccountDetail.setBalance(sysUserCashAccount.getBalance().add(order.getActualAmount()));
 		sysUserIncomeCashAccountDetail.setAttribute(order.getTransNo());
+		sysUserIncomeCashAccountDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+		sysUserIncomeCashAccountDetail.setComAmount(studentPaymentOrder.getComAmount());
+		sysUserIncomeCashAccountDetail.setPerAmount(studentPaymentOrder.getPerAmount());
 
 		//支出
 		SysUserCashAccountDetail sysUserExpendCashAccountDetail = new SysUserCashAccountDetail();
@@ -1152,6 +1168,9 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 		sysUserExpendCashAccountDetail.setAmount(order.getActualAmount().negate());
 		sysUserExpendCashAccountDetail.setBalance(sysUserCashAccount.getBalance());
 		sysUserExpendCashAccountDetail.setAttribute(order.getTransNo());
+		sysUserExpendCashAccountDetail.setChannel(studentPaymentOrder.getPaymentChannel());
+		sysUserExpendCashAccountDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
+		sysUserExpendCashAccountDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
 
 		sysUserCashAccountDetailService.insert(sysUserIncomeCashAccountDetail);
 		sysUserCashAccountDetailService.insert(sysUserExpendCashAccountDetail);

+ 10 - 2
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml

@@ -13,6 +13,8 @@
         <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="expect_amount_" property="expectAmount"/>
         <result column="actual_amount_" property="actualAmount"/>
+        <result column="com_amount_" property="comAmount"/>
+        <result column="per_amount_" property="perAmount"/>
         <result column="balance_payment_amount_" property="balancePaymentAmount"/>
         <result column="trans_no_" property="transNo"/>
         <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
@@ -75,12 +77,12 @@
     <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder" useGeneratedKeys="true"
             keyColumn="id" keyProperty="id">
         INSERT INTO student_payment_order
-        (id_,group_type_,user_id_,type_,expect_amount_,actual_amount_,balance_payment_amount_,trans_no_,
+        (id_,group_type_,user_id_,type_,expect_amount_,actual_amount_,com_amount_,per_amount_,balance_payment_amount_,trans_no_,
         status_,memo_,create_time_,update_time_,payment_channel_,payment_business_channel_,
         payment_account_no_,order_no_,music_group_id_,class_group_id_)
         VALUES(#{id},#{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
         #{userId},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-        #{expectAmount},#{actualAmount},#{balancePaymentAmount},#{transNo},
+        #{expectAmount},#{actualAmount},#{comAmount},#{perAmount},#{balancePaymentAmount},#{transNo},
         #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{memo},now(),now(),
         #{paymentChannel},#{paymentBusinessChannel},#{paymentAccountNo},#{orderNo},#{musicGroupId},#{classGroupId})
     </insert>
@@ -128,6 +130,12 @@
             <if test="actualAmount != null">
                 actual_amount_ = #{actualAmount},
             </if>
+            <if test="comAmount != null">
+                com_amount_ = #{comAmount},
+            </if>
+            <if test="perAmount != null">
+                per_amount_ = #{perAmount},
+            </if>
             <if test="balancePaymentAmount != null">
                 balance_payment_amount_ = #{balancePaymentAmount},
             </if>

+ 25 - 8
mec-biz/src/main/resources/config/mybatis/SysAccountMapper.xml

@@ -11,6 +11,7 @@
         <result column="has_receipt_" jdbcType="DECIMAL" property="hasReceipt"/>
         <result column="channel_" jdbcType="VARCHAR" property="channel"/>
         <result column="type_" jdbcType="CHAR" property="type"/>
+        <result column="status_" jdbcType="TINYINT" property="status"/>
         <result column="version" jdbcType="INTEGER" property="version"/>
     </resultMap>
     <sql id="Base_Column_List">
@@ -22,6 +23,7 @@
             has_receipt_,
             channel_,
             type_,
+            status_,
             version
     </sql>
     <select id="get" parameterType="java.lang.Integer" resultMap="SysAccount">
@@ -62,6 +64,9 @@
             <if test="type != null">
                 type_,
             </if>
+            <if test="status != null">
+                status_,
+            </if>
             <if test="version != null">
                 version,
             </if>
@@ -88,6 +93,9 @@
             <if test="type != null">
                 #{type,jdbcType=CHAR},
             </if>
+            <if test="status != null">
+                #{status,jdbcType=TINYINT},
+            </if>
             <if test="version != null">
                 #{version,jdbcType=INTEGER},
             </if>
@@ -118,22 +126,31 @@
             <if test="type != null">
                 type_ = #{type,jdbcType=CHAR},
             </if>
+            <if test="status != null">
+                status_ = #{status,jdbcType=TINYINT},
+            </if>
             <if test="version != null">
                 version = version+1,
             </if>
         </set>
         where id_ = #{id,jdbcType=INTEGER} AND version =#{version}
     </update>
-    <!-- 获取一个私户账户 -->
-    <select id="getPerAccount" resultMap="SysAccount">
-        SELECT *
-        FROM sys_account
-        WHERE channel_ = 'YQPAY'
-          AND type_ = 'PER'
-    </select>
 
     <select id="getAccount" resultMap="SysAccount">
-        SELECT * FROM sys_account WHERE company_=#{company}
+        SELECT * FROM sys_account WHERE status_=1 AND company_=#{company}
+        <if test="channel != null">
+            AND channel_ = #{channel}
+        </if>
+        <if test="type != null">
+            AND type_ IN (#{type})
+        </if>
+        <if test="amount != null">
+            <![CDATA[AND max_receipt_ < has_receipt_+ #{amount}]]>
+        </if>
+    </select>
+
+    <select id="getOneAccount" resultMap="SysAccount">
+        SELECT * FROM sys_account WHERE status_ =1 AND company_=#{company}
         <if test="channel != null">
             AND channel_ = #{channel}
         </if>

+ 12 - 0
mec-biz/src/main/resources/config/mybatis/SysUserCashAccountDetailMapper.xml

@@ -14,6 +14,8 @@
         <result column="trans_type_" property="transType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="amount_" property="amount"/>
+        <result column="com_amount_" property="comAmount"/>
+        <result column="per_amount_" property="perAmount"/>
         <result column="balance_" property="balance"/>
         <result column="description_" property="description"/>
         <result column="comment_" property="comment"/>
@@ -48,6 +50,8 @@
             <if test="transType!=null">trans_type_,</if>
             <if test="status!=null">status_,</if>
             <if test="amount!=null">amount_,</if>
+            <if test="comAmount!=null">com_amount_,</if>
+            <if test="perAmount!=null">per_amount_,</if>
             <if test="balance!=null">balance_,</if>
             <if test="description!=null">description_,</if>
             <if test="comment!=null">comment_,</if>
@@ -66,6 +70,8 @@
             <if test="transType!=null">#{transType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},</if>
             <if test="status!=null">#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},</if>
             <if test="amount!=null">#{amount},</if>
+            <if test="comAmount!=null">#{comAmount},</if>
+            <if test="perAmount!=null">#{perAmount},</if>
             <if test="balance!=null">#{balance},</if>
             <if test="description!=null">#{description},</if>
             <if test="comment!=null">#{comment},</if>
@@ -109,6 +115,12 @@
             <if test="amount != null">
                 amount_ = #{amount},
             </if>
+            <if test="comAmount != null">
+                com_amount_ = #{comAmount},
+            </if>
+            <if test="perAmount != null">
+                per_amount_ = #{perAmount},
+            </if>
             <if test="description != null">
                 description_ = #{description},
             </if>

+ 3 - 132
mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -50,10 +50,6 @@ public class StudentOrderController extends BaseController {
     @Autowired
     private MusicGroupService musicGroupService;
     @Autowired
-    private SporadicChargeInfoService sporadicChargeInfoService;
-    @Autowired
-    private YqPayFeignService yqQueryService;
-    @Autowired
     private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
 
     @PostMapping("/notify")
@@ -79,7 +75,7 @@ public class StudentOrderController extends BaseController {
             notifyMap.put("totalMoney", notifyMap.get("payAmount"));
             notifyMap.put("merOrderNo", notifyMap.get("merMerOrderNo"));
             notifyMap.put("channelType", channelType);
-            updateOrder(notifyMap);
+            studentPaymentOrderService.updateOrder(notifyMap);
             msg.setCode("000000");
             msg.setMsg("success");
         }
@@ -154,131 +150,6 @@ public class StudentOrderController extends BaseController {
         return succeed(payment);
     }
 
-
-    //@Scheduled(cron = "0 */1 * * * ?")
-    public void getOrderStatus() throws Exception {
-        List<StudentPaymentOrder> payingOrders = studentPaymentOrderService.findOrdersByStatus(DealStatusEnum.ING, "YQPAY");
-
-        if(payingOrders.size() ==0){
-            return;
-        }
-        List<String> orderNoList = payingOrders.stream().map(StudentPaymentOrder::getOrderNo).collect(Collectors.toList());
-        String merOrderNos = payingOrders.stream().map(StudentPaymentOrder::getOrderNo).collect(Collectors.joining(","));
-
-        String notifyUrl = ""; //回调地址
-        Map<String, Object> resultMap = new LinkedHashMap<>();
-        resultMap.put("merOrderNoList", merOrderNos);
-        Map<String, Object> requestMap = YqPayUtil.getRequestMap(notifyUrl, resultMap);
-
-        RsqMsg rsqMsg = new RsqMsg(requestMap);
-
-        Msg queryRs = yqQueryService.orderQuery(rsqMsg);
-
-        if (queryRs.getCode().equals("88")) {
-            //更新订单状态
-            String[] statusArr = {"0", "1", "7"};
-            String responseParameters = queryRs.getResponseParameters();
-            List<Map<String, String>> responseList = JSON.parseObject(responseParameters, List.class);
-            for (Map<String, String> response : responseList) {
-                Map<String, String> rpMap = response;
-                String channelType = rpMap.get("channelType").equals("1") ? "WXPay" : (rpMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
-                rpMap.put("channelType", channelType);
-
-                if (Arrays.asList(statusArr).contains(rpMap.get("tradeState"))) {
-                    updateOrder(rpMap); //更新订单
-                }
-                if (orderNoList.contains(rpMap.get("merOrderNo"))) {
-                    orderNoList.remove(rpMap.get("merOrderNo"));
-                }
-            }
-            closeOrders(orderNoList); //关闭订单
-        }
-    }
-
-    public void updateOrder(Map<String, String> rpMap) throws Exception {
-        DealStatusEnum status = rpMap.get("tradeState").equals("1") ? DealStatusEnum.SUCCESS : DealStatusEnum.FAILED;
-        StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(rpMap.get("merOrderNo"));
-        if (order == null || !order.getStatus().equals(DealStatusEnum.ING)) {
-            return;
-        }
-
-        if (status.equals(DealStatusEnum.SUCCESS)) {
-            order.setPayTime(new Date());
-        } else {
-            order.setMemo(rpMap.get("remarks"));
-        }
-        order.setStatus(status);
-        order.setTransNo(rpMap.get("orderNo"));
-        order.setPaymentBusinessChannel(rpMap.get("channelType"));
-
-        if (order.getType().equals(OrderTypeEnum.APPLY)) { //报名订单
-            studentRegistrationService.updateApplyOrder(order);
-        } else if (order.getType().equals(OrderTypeEnum.SMALL_CLASS_TO_BUY)) {
-            vipGroupService.orderCallback(order);
-        } else if (order.getType().equals(OrderTypeEnum.RENEW)) {
-            musicGroupService.renewForCallback(order);
-        } else if (order.getType().equals(OrderTypeEnum.SPORADIC)) {
-            sporadicChargeInfoService.renewForCallback(order);
-        }
-    }
-
-    public void closeOrders(List<String> orderNoList) throws Exception {
-        if (orderNoList.size() == 0) {
-            return;
-        }
-
-        Calendar beforeTime = Calendar.getInstance();
-        beforeTime.add(Calendar.MINUTE, -30);// 30分钟之前的时间
-        Date beforeDate = beforeTime.getTime();
-
-        List<StudentPaymentOrder> ordersOverTime = studentPaymentOrderService.findOrdersOverTime(orderNoList, DealStatusEnum.ING, beforeDate);
-        for (StudentPaymentOrder order : ordersOverTime) {
-            order.setStatus(DealStatusEnum.FAILED);
-            order.setMemo("超时未支付关闭");
-            if (order.getType().equals(OrderTypeEnum.APPLY)) { //报名订单
-                studentRegistrationService.updateApplyOrder(order);
-            } else if (order.getType().equals(OrderTypeEnum.SMALL_CLASS_TO_BUY)) {
-                vipGroupService.orderCallback(order);
-            } else if (order.getType().equals(OrderTypeEnum.RENEW)) {
-                musicGroupService.renewForCallback(order);
-            }else if (order.getType().equals(OrderTypeEnum.SPORADIC)) {
-                sporadicChargeInfoService.renewForCallback(order);
-            }
-        }
-
-    }
-
-    // @Scheduled(cron = "0/5 * * * * ?")
-    public void adaPayQuery() throws Exception {
-        List<StudentPaymentOrder> payingOrders = studentPaymentOrderService.findOrdersByStatus(DealStatusEnum.ING, "ADAPAY");
-
-        List<String> orderNoList = new ArrayList<String>();
-
-        for (StudentPaymentOrder payingOrder : payingOrders) {
-            if (payingOrder.getTransNo() == null) {
-                orderNoList.add(payingOrder.getOrderNo());
-                continue;
-            }
-            Payment payment = new Pay().queryPayment(payingOrder.getTransNo());
-            Map<String, String> rpMap = new HashMap<>();
-            rpMap.put("merOrderNo", payingOrder.getOrderNo());
-            rpMap.put("remarks", payment.getReason());
-            rpMap.put("orderNo", payment.getId());
-            rpMap.put("channelType", payment.getPayChannel());
-            if (payment.getStatus().equals("succeeded")) {
-                rpMap.put("tradeState", "1");
-            }
-            if (payment.getStatus().equals("failed")) {
-                rpMap.put("tradeState", "0");
-            }
-            if (payment.getStatus().equals("pending")) {
-                orderNoList.add(payingOrder.getOrderNo());
-            }
-        }
-        closeOrders(orderNoList);
-    }
-
-
     @PostMapping("/adaNotify")
     public void adaNotify(@ModelAttribute NotifyEvent notifyEvent) throws Exception {
         logger.info(notifyEvent.toString());
@@ -296,7 +167,7 @@ public class StudentOrderController extends BaseController {
             notifyMap.put("merOrderNo", notifyMap.get("order_no"));
             notifyMap.put("merOrderNo", notifyMap.get("order_no"));
             notifyMap.put("remarks", notifyMap.get("description"));
-            updateOrder(notifyMap);
+            studentPaymentOrderService.updateOrder(notifyMap);
         }
     }
 
@@ -349,7 +220,7 @@ public class StudentOrderController extends BaseController {
             rpMap.put("channelType", channelType);
             if (Arrays.asList(statusArr).contains(rpMap.get("tradeState"))) {
                 try {
-                    updateOrder(rpMap); //更新订单
+                    studentPaymentOrderService.updateOrder(rpMap); //更新订单
                 }catch (Exception e){
                     e.printStackTrace();
                     continue;

+ 36 - 2
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/yqpay/YqPayUtil.java

@@ -15,7 +15,7 @@ public class YqPayUtil {
 
     public static Map<String, Object> getRequestMap(String notifyUrl, Map<String, Object> resultMap) throws Exception {
         Map<String, Object> rqMap = new LinkedHashMap<>();
-        rqMap.put("merNo",merNo);
+        rqMap.put("merNo", merNo);
         rqMap.put("version", version);
         rqMap.put("notifyUrl", notifyUrl);
         rqMap.put("timestamp", DateUtils.getDateTime());
@@ -40,7 +40,7 @@ public class YqPayUtil {
      * @return
      * @throws Exception
      */
-    public static Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody,String sellerNo, String routingMerNo) throws Exception {
+    public static Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sellerNo, String routingMerNo) throws Exception {
         List<Map> tempRoutingList = new ArrayList();
         Map<String, Object> routingList = new HashMap<>();
         routingList.put("routingMerNo", routingMerNo);//分佣账户
@@ -66,6 +66,40 @@ public class YqPayUtil {
     }
 
     /**
+     * 获取支付Map
+     *
+     * @param amount
+     * @param orderNo
+     * @param notifyUrl
+     * @param returnUrl
+     * @param orderSubject
+     * @param orderBody
+     * @param sellerNo
+     * @param tempRoutingList
+     * @return
+     * @throws Exception
+     */
+    public static Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sellerNo, List<Map> tempRoutingList) throws Exception {
+        Map<String, Object> contentMap = new LinkedHashMap<>();
+        contentMap.put("sellerNo", sellerNo); //收款商户号
+        contentMap.put("payChannels", payChannels); //支付方式
+        contentMap.put("orderBody", orderBody); //订单信息
+        contentMap.put("payAmount", amount); //支付金额
+        contentMap.put("apiPayType", "1"); //*API支付类型1-即时支付,2-担保支付,3-预授权支付*/
+        contentMap.put("tradeType", "0"); //*交易类型1—充值,0—收款*
+        contentMap.put("merMerOrderNo", orderNo); //商户订单号
+        contentMap.put("orderSubject", orderSubject); //订单标题
+        contentMap.put("returnUrl", returnUrl); //前台页面地址
+        if (tempRoutingList != null) {
+            contentMap.put("tempRoutingList", JSON.toJSONString(tempRoutingList));//分账设置
+        }
+        Map<String, Object> payMap = getRequestMap(notifyUrl, contentMap);
+        payMap.put("host", payUrl);
+        return payMap;
+    }
+
+
+    /**
      * 验签
      *
      * @param rsMap

+ 18 - 9
mec-web/src/main/java/com/ym/mec/web/controller/StudentPaymentOrderController.java

@@ -3,11 +3,14 @@ package com.ym.mec.web.controller;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.EmployeeDao;
+import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.entity.Employee;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
 import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
 import com.ym.mec.biz.service.StudentPaymentOrderService;
 import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.page.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -20,6 +23,7 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.List;
 
@@ -28,12 +32,6 @@ import java.util.List;
 @RestController
 public class StudentPaymentOrderController extends BaseController {
 
-    @Value("${payment.hiddenMode}")
-    private Boolean hiddenMode;
-
-    @Value("${payment.channel}")
-    private String channel;
-
     @Autowired
     private StudentPaymentOrderService studentPaymentOrderService;
     @Autowired
@@ -42,6 +40,8 @@ public class StudentPaymentOrderController extends BaseController {
     private SysUserFeignService sysUserFeignService;
     @Autowired
     private EmployeeDao employeeDao;
+    @Autowired
+    private SysConfigDao sysConfigDao;
 
     @ApiOperation(value = "获取订单列表")
     @GetMapping("/queryPage")
@@ -64,10 +64,19 @@ public class StudentPaymentOrderController extends BaseController {
                 }
             }
         }
-        if(hiddenMode){
-            queryInfo.setPaymentChannel(channel);
+
+        PageInfo<StudentPaymentOrder> studentPaymentOrderPageInfo = studentPaymentOrderService.queryPage(queryInfo);
+
+        int openHideMode = Integer.parseInt(sysConfigDao.findConfigValue("open_hide_mode"));
+        if(openHideMode == 1){
+            for (StudentPaymentOrder row : studentPaymentOrderPageInfo.getRows()) {
+                BigDecimal balancePaymentAmount = row.getBalancePaymentAmount() == null ? BigDecimal.ZERO : row.getBalancePaymentAmount();
+                BigDecimal comAmount = row.getComAmount() == null ? BigDecimal.ZERO : row.getComAmount();
+                row.setExpectAmount(comAmount.add(balancePaymentAmount));
+                row.setActualAmount(comAmount.add(balancePaymentAmount));
+            }
         }
-        return succeed(studentPaymentOrderService.queryPage(queryInfo));
+        return succeed(studentPaymentOrderPageInfo);
     }
 
     @ApiOperation(value = "获取乐器采购清单")

+ 17 - 12
mec-web/src/main/java/com/ym/mec/web/controller/SysUserCashAccountDetailController.java

@@ -2,11 +2,14 @@ package com.ym.mec.web.controller;
 
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dto.CashAccountDetail;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 import com.ym.mec.biz.service.SysUserCashAccountDetailService;
 import com.ym.mec.common.controller.BaseController;
 
+import com.ym.mec.common.page.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
@@ -18,22 +21,18 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.math.BigDecimal;
+
 @RequestMapping("userCashAccountDetail")
 @Api(tags = "用户交易明细服务")
 @RestController
 public class SysUserCashAccountDetailController extends BaseController {
-
-    @Value("${payment.hiddenMode}")
-    private Boolean hiddenMode;
-
-    @Value("${payment.channel}")
-    private String channel;
-
-
     @Autowired
     private SysUserCashAccountDetailService sysUserCashAccountDetailService;
     @Autowired
     private SysUserFeignService sysUserFeignService;
+    @Autowired
+    private SysConfigDao sysConfigDao;
 
     @ApiOperation(value = "新增用户交易明细")
     @PostMapping("/add")
@@ -51,11 +50,17 @@ public class SysUserCashAccountDetailController extends BaseController {
         if (user == null && user.getId() != null) {
             return failed("请重新登录");
         }
-        if (hiddenMode){
-            queryInfo.setChannel(channel);
-        }
         queryInfo.setUserId(user.getId());
-        return succeed(sysUserCashAccountDetailService.queryPage(queryInfo));
+        PageInfo<SysUserCashAccountDetail> sysUserCashAccountDetailPageInfo = sysUserCashAccountDetailService.queryPage(queryInfo);
+
+        int openHideMode = Integer.parseInt(sysConfigDao.findConfigValue("open_hide_mode"));
+        if(openHideMode == 1){
+            for (SysUserCashAccountDetail row : sysUserCashAccountDetailPageInfo.getRows()) {
+                BigDecimal comAmount = row.getComAmount() == null ? BigDecimal.ZERO : row.getComAmount();
+                row.setAmount(comAmount.add(comAmount));
+            }
+        }
+        return succeed(sysUserCashAccountDetailPageInfo);
     }
 
 }