Browse Source

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 5 years ago
parent
commit
b76bafe575

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/RouteScaleDto.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.dal.dto;
 
+import com.ym.mec.biz.dal.enums.FeeTypeEnum;
 import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
 
 import java.math.BigDecimal;
@@ -18,6 +19,8 @@ public class RouteScaleDto {
 
     private String feeFlag;
 
+    private FeeTypeEnum feeType;
+
     public Integer getOrganId() {
         return organId;
     }
@@ -66,4 +69,12 @@ public class RouteScaleDto {
     public void setPayType(PaymentChannelEnum payType) {
         this.payType = payType;
     }
+
+    public FeeTypeEnum getFeeType() {
+        return feeType;
+    }
+
+    public void setFeeType(FeeTypeEnum feeType) {
+        this.feeType = feeType;
+    }
 }

+ 14 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysPaymentConfig.java

@@ -44,6 +44,12 @@ public class SysPaymentConfig {
     private String routeScale;
 
     /**
+     * 根据费用分配规则
+     */
+    @ApiModelProperty(value = "根据费用分配规则")
+    private String typeRouteScale;
+
+    /**
      * 分部id
      */
     @ApiModelProperty(value = "分部id")
@@ -247,5 +253,13 @@ public class SysPaymentConfig {
     public void setAccountType(AccountType accountType) {
         this.accountType = accountType;
     }
+
+    public String getTypeRouteScale() {
+        return typeRouteScale;
+    }
+
+    public void setTypeRouteScale(String typeRouteScale) {
+        this.typeRouteScale = typeRouteScale;
+    }
 }
 

+ 27 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/FeeTypeEnum.java

@@ -0,0 +1,27 @@
+package com.ym.mec.biz.dal.enums;
+
+import com.ym.mec.common.enums.BaseEnum;
+
+public enum FeeTypeEnum implements BaseEnum<String, FeeTypeEnum> {
+	SERVICE("SERVICE", "服务"),
+	SELL("SELL", "销售");
+
+	private String code;
+
+	private String desc;
+
+	private FeeTypeEnum(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+
+	@Override
+	public String getCode() {
+		return code;
+	}
+
+	public String getDesc() {
+		return desc;
+	}
+
+}

+ 35 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/SysPaymentConfigQueryInfo.java

@@ -0,0 +1,35 @@
+package com.ym.mec.biz.dal.page;
+
+import com.ym.mec.common.page.QueryInfo;
+import io.swagger.annotations.ApiModelProperty;
+
+public class SysPaymentConfigQueryInfo extends QueryInfo {
+
+    /**
+     * 分部id
+     */
+    @ApiModelProperty(value = "分部id", required = true)
+    private Integer organId;
+
+    /**
+     * 是否设置按费用类型分润
+     */
+    @ApiModelProperty(value = "是否设置按费用类型分润 1-是 0 -否", required = true)
+    private Integer hasTypeRoute;
+
+    public Integer getOrganId() {
+        return organId;
+    }
+
+    public void setOrganId(Integer organId) {
+        this.organId = organId;
+    }
+
+    public Integer getHasTypeRoute() {
+        return hasTypeRoute;
+    }
+
+    public void setHasTypeRoute(Integer hasTypeRoute) {
+        this.hasTypeRoute = hasTypeRoute;
+    }
+}

+ 8 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/SellOrderService.java

@@ -69,4 +69,12 @@ public interface SellOrderService extends BaseService<Integer, SellOrder> {
      */
     List<SellOrder> getRefundSellOrder(Long orderId);
 
+
+    /**
+     * 获取订单的实际销售金额(除去余额部分)
+     * @param orderNo
+     * @return
+     */
+    BigDecimal getSellActualAmount(String orderNo);
+
 }

+ 62 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java

@@ -9,6 +9,7 @@ import com.ym.mec.biz.dal.dto.RouteScaleDto;
 import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
 import com.ym.mec.biz.dal.entity.SysAccount;
 import com.ym.mec.biz.dal.entity.SysPaymentConfig;
+import com.ym.mec.biz.dal.enums.FeeTypeEnum;
 import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
 import com.ym.mec.biz.dal.enums.PaymentChannelTypeEnum;
 import com.ym.mec.biz.service.*;
@@ -41,6 +42,8 @@ public class PayServiceImpl implements PayService {
     private SysPaymentConfigService sysPaymentConfigService;
     @Autowired
     private StudentPaymentRouteOrderDao studentPaymentRouteOrderDao;
+    @Autowired
+    private SellOrderService sellOrderService;
 
     @Override
     public Map<String, Object> getPayMap(BigDecimal amount, BigDecimal balanceAmount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer organId, String receiver) throws Exception {
@@ -51,6 +54,11 @@ public class PayServiceImpl implements PayService {
             routeScaleDtos = noUsePaymentConfig(amount);
         }
 
+        //根据费用类型
+        if(routeScaleDtos == null){
+            routeScaleDtos = getTypeRouteChannel(organId, orderNo, amount);
+        }
+
         //根据金额获取分润
         if (routeScaleDtos == null) {
             routeScaleDtos = getAmountChannel(organId, amount, receiver);
@@ -364,4 +372,58 @@ public class PayServiceImpl implements PayService {
         return unionPay;
     }
 
+    /**
+     * @param organId
+     * @param orderNo
+     * @param amount
+     * @return
+     */
+    private List<RouteScaleDto> getTypeRouteChannel(Integer organId, String orderNo, BigDecimal amount) {
+        SysPaymentConfig paymentConfig = sysPaymentConfigService.findPaymentConfigByOrganId(organId);
+        if (paymentConfig == null || StringUtils.isBlank(paymentConfig.getTypeRouteScale())) {
+            return null;
+        }
+
+        String typeRouteScale = paymentConfig.getTypeRouteScale();
+        List<RouteScaleDto> routeScaleDtos = JSON.parseArray(typeRouteScale, RouteScaleDto.class);
+        List<Integer> organIds = routeScaleDtos.stream().map(RouteScaleDto::getOrganId).collect(Collectors.toList());
+        List<SysPaymentConfig> paymentConfigByOrganIds = sysPaymentConfigService.findPaymentConfigByOrganIds(organIds);
+
+        BigDecimal sellActualAmount = sellOrderService.getSellActualAmount(orderNo);
+        if (sellActualAmount == null) {
+            return null;
+        }
+
+        Iterator<RouteScaleDto> iterator = routeScaleDtos.iterator();
+        boolean hasFeeFlag = false;
+        while (iterator.hasNext()) {
+            RouteScaleDto routeScaleDto = iterator.next();
+            routeScaleDto.setPayType(paymentConfig.getPayType());
+            if (routeScaleDto.getFeeType().equals(FeeTypeEnum.SELL)) {
+                routeScaleDto.setAmount(sellActualAmount);
+            } else {
+                routeScaleDto.setAmount(amount.subtract(sellActualAmount));
+            }
+
+            if (routeScaleDto.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
+                iterator.remove();
+                continue;
+            }
+            if (!hasFeeFlag && routeScaleDto.getAmount().compareTo(amount.divide(new BigDecimal(2), 2, BigDecimal.ROUND_DOWN)) >= 0) {
+                routeScaleDto.setFeeFlag("Y");
+                hasFeeFlag = true;
+            }
+
+            for (SysPaymentConfig paymentConfigByOrganId : paymentConfigByOrganIds) {
+                if (!paymentConfigByOrganId.getOrganId().equals(routeScaleDto.getOrganId())) continue;
+                if (paymentConfig.getPayType().equals(PaymentChannelEnum.YQPAY)) {
+                    routeScaleDto.setMerNo(paymentConfigByOrganId.getYqMerNo());
+                } else {
+                    routeScaleDto.setMerNo(paymentConfigByOrganId.getHfMerNo());
+                }
+            }
+        }
+        return routeScaleDtos;
+    }
+
 }

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

@@ -1,10 +1,8 @@
 package com.ym.mec.biz.service.impl;
 
 
-import com.ym.mec.biz.dal.dao.GoodsDao;
-import com.ym.mec.biz.dal.dao.MusicGroupDao;
-import com.ym.mec.biz.dal.dao.SellOrderDao;
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
+import com.alibaba.fastjson.JSONObject;
+import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.service.*;
@@ -36,6 +34,12 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
     private SysUserCashAccountService sysUserCashAccountService;
     @Autowired
     private GoodsService goodsService;
+    @Autowired
+    private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
+    @Autowired
+    private SporadicChargeInfoDao sporadicChargeInfoDao;
+    @Autowired
+    private StudentRepairDao studentRepairDao;
 
     @Override
     public BaseDAO<Integer, SellOrder> getDAO() {
@@ -338,4 +342,69 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
         return sellOrderDao.getRefundSellOrder(orderId);
     }
 
+    @Override
+    public BigDecimal getSellActualAmount(String orderNo) {
+        StudentPaymentOrder order = studentPaymentOrderDao.findOrderByOrderNo(orderNo);
+        if (order == null) {
+            return null;
+        }
+
+        //零星支付除了充值其他都是服务费用
+        if (order.getType().equals(OrderTypeEnum.SPORADIC)) {
+            SporadicChargeInfo info = sporadicChargeInfoDao.get(Integer.parseInt(order.getMusicGroupId()));
+            if (info.getChargeType().equals(SporadicChargeTypeEnum.RECHARGE)) {
+                return null;
+            }
+        }
+        //乐器销售,声部更改
+        if (order.getType().equals(OrderTypeEnum.GOODS_SELL) || order.getType().equals(OrderTypeEnum.SUBJECT_CHANGE)) {
+            return order.getActualAmount();
+        }
+
+        //乐器维修
+        if (order.getType().equals(OrderTypeEnum.REPAIR)) {
+            StudentRepair repairInfo = studentRepairDao.getRepairInfo(Integer.parseInt(order.getMusicGroupId()));
+
+            if (StringUtils.isBlank(repairInfo.getGoodsJson())) {
+                return BigDecimal.ZERO;
+            }
+            List<Goods> goodies = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
+            List<Integer> goodsIds = goodies.stream().map(Goods::getId).collect(Collectors.toList());
+            if (goodsIds.size() <= 0) {
+                return BigDecimal.ZERO;
+            }
+
+            BigDecimal goodsTotalPrice = BigDecimal.ZERO;
+            goodies = goodsDao.getGoodies(goodsIds);
+            int i = 1;
+            for (Integer goodsId : goodsIds) {
+                for (Goods goods : goodies) {
+                    if (goods.getId().equals(goodsId)) {
+                        goodsTotalPrice = goodsTotalPrice.add(goods.getDiscountPrice());
+                        break;
+                    }
+                }
+            }
+            BigDecimal balance = order.getBalancePaymentAmount() == null ? BigDecimal.ZERO : order.getBalancePaymentAmount();
+            BigDecimal goodsTotalBalance = goodsTotalPrice.multiply(balance).divide(order.getExpectAmount(), 2, BigDecimal.ROUND_HALF_UP);
+            return goodsTotalPrice.subtract(goodsTotalBalance);
+        }
+
+        //乐团报名
+        if (order.getType().equals(OrderTypeEnum.APPLY)) {
+            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailDao.getOrderDetail(order.getId());
+            //总余额支付
+            BigDecimal totalBalance = order.getBalancePaymentAmount() != null ? order.getBalancePaymentAmount() : BigDecimal.ZERO;
+            //总价格
+            BigDecimal totalPrice = order.getExpectAmount();
+            //商品总付款
+            BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+            //商品销售占的余额
+            BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_HALF_UP);
+            return detailTotalPrice.subtract(detailTotalBalance);
+        }
+
+        return BigDecimal.ZERO;
+    }
+
 }

+ 31 - 3
mec-biz/src/main/resources/config/mybatis/SysPaymentConfigMapper.xml

@@ -5,12 +5,14 @@
         <!--@Table sys_payment_config-->
         <id column="id_" jdbcType="INTEGER" property="id"/>
         <result column="organ_id_" property="organId"/>
-        <result column="account_type_" property="accountType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
+        <result column="account_type_" property="accountType"
+                typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="pay_type_" property="payType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
         <result column="yq_mer_no_" property="yqMerNo"/>
         <result column="hf_mer_no_" property="hfMerNo"/>
         <result column="type_" property="type"/>
         <result column="route_scale_" property="routeScale"/>
+        <result column="type_route_scale_" property="typeRouteScale"/>
         <result column="organ_name" property="organName"/>
         <result column="per_scale_" property="perScale"/>
         <result column="com_scale_" property="comScale"/>
@@ -23,7 +25,8 @@
     </resultMap>
     <sql id="Base_Column_List">
         <!--@mbg.generated-->
-        id_, organ_id_,account_type_,pay_type_,yq_mer_no_,hf_mer_no_,type_,route_scale_,create_time_, update_time_
+        id_, organ_id_,account_type_,pay_type_,yq_mer_no_,hf_mer_no_,type_,route_scale_,type_route_scale_,create_time_,
+        update_time_
     </sql>
     <select id="get" parameterType="java.lang.Integer" resultMap="SysPaymentConfig">
         <!--@mbg.generated-->
@@ -60,6 +63,9 @@
             <if test="routeScale != null">
                 route_scale_,
             </if>
+            <if test="typeRouteScale != null">
+                type_route_scale_,
+            </if>
             <if test="type != null">
                 type_,
             </if>
@@ -89,6 +95,9 @@
             <if test="routeScale != null">
                 #{routeScale},
             </if>
+            <if test="typeRouteScale != null">
+                #{typeRouteScale},
+            </if>
             <if test="type != null">
                 #{type},
             </if>
@@ -122,6 +131,9 @@
             <if test="routeScale != null">
                 route_scale_ = #{routeScale},
             </if>
+            <if test="typeRouteScale != null">
+                type_route_scale_ = #{typeRouteScale},
+            </if>
             <if test="type != null">
                 type_ = #{type},
             </if>
@@ -137,15 +149,31 @@
         ORDER BY id_
     </select>
 
+    <sql id="queryCondition">
+        <where>
+            <if test="organId!=null">
+                AND spc.organ_id_=#{organId}
+            </if>
+            <if test='hasTypeRoute != null and hasTypeRoute.toString()=="1".toString()'>
+                AND spc.type_route_scale_ != ''
+            </if>
+            <if test='hasTypeRoute != null and hasTypeRoute.toString()=="0".toString()'>
+                AND spc.type_route_scale_ = ''
+            </if>
+        </where>
+    </sql>
+
     <!-- 分页查询 -->
     <select id="queryPage" resultMap="SysPaymentConfig" parameterType="map">
         SELECT spc.*,o.name_ organ_name FROM sys_payment_config spc LEFT JOIN organization o on spc.organ_id_ = o.id_
+        <include refid="queryCondition"/>
         <include refid="global.limit"/>
     </select>
 
     <!-- 查询当前表的总记录数 -->
     <select id="queryCount" resultType="int">
-        SELECT COUNT(*) FROM sys_payment_config
+        SELECT COUNT(*) FROM sys_payment_config spc
+        <include refid="queryCondition"/>
         <include refid="global.limit"/>
     </select>
 

+ 52 - 1
mec-web/src/main/java/com/ym/mec/web/controller/SysPaymentConfigController.java

@@ -2,11 +2,13 @@ package com.ym.mec.web.controller;
 
 import com.ym.mec.biz.dal.entity.SysPaymentConfig;
 import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
+import com.ym.mec.biz.dal.page.SysPaymentConfigQueryInfo;
 import com.ym.mec.biz.service.SysPaymentConfigService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.page.QueryInfo;
 import io.swagger.annotations.*;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
@@ -69,7 +71,7 @@ public class SysPaymentConfigController extends BaseController {
     @ApiOperation(value = "分页查询支付配置列表")
     @GetMapping("/queryPage")
     @PreAuthorize("@pcs.hasPermissions('paymentConfig/queryPage')")
-    public Object queryPage(QueryInfo queryInfo) {
+    public Object queryPage(SysPaymentConfigQueryInfo queryInfo) {
         return succeed(sysPaymentConfigService.queryPage(queryInfo));
     }
 
@@ -80,4 +82,53 @@ public class SysPaymentConfigController extends BaseController {
         return succeed(sysPaymentConfigService.getPaymentConfigs(payType));
     }
 
+
+    @ApiOperation(value = "新增按费用类型配置")
+    @PostMapping("/addTypeRoute")
+    @PreAuthorize("@pcs.hasPermissions('paymentConfig/addTypeRoute')")
+    public HttpResponseResult<SysPaymentConfig> addTypeRoute(SysPaymentConfig config) {
+        if (StringUtils.isBlank(config.getTypeRouteScale())) {
+            return failed("分润配置不能为空");
+        }
+        SysPaymentConfig paymentConfig = sysPaymentConfigService.get(config.getId());
+        if (paymentConfig != null && StringUtils.isNotBlank(paymentConfig.getTypeRouteScale())) {
+            return failed("此分部配置存在,请核查");
+        }
+        Date nowDate = new Date();
+        paymentConfig.setTypeRouteScale(config.getTypeRouteScale());
+        paymentConfig.setUpdateTime(nowDate);
+        sysPaymentConfigService.update(paymentConfig);
+        return succeed(paymentConfig);
+    }
+
+    @ApiOperation(value = "更新按费用类型配置")
+    @PostMapping("/updateTypeRoute")
+    @PreAuthorize("@pcs.hasPermissions('paymentConfig/updateTypeRoute')")
+    public HttpResponseResult<SysPaymentConfig> updateTypeRoute(SysPaymentConfig config) {
+        if (StringUtils.isBlank(config.getTypeRouteScale())) {
+            return failed("分润配置不能为空");
+        }
+        SysPaymentConfig paymentConfig = sysPaymentConfigService.get(config.getId());
+        Date nowDate = new Date();
+        paymentConfig.setTypeRouteScale(config.getTypeRouteScale());
+        paymentConfig.setUpdateTime(nowDate);
+        sysPaymentConfigService.update(paymentConfig);
+        return succeed(paymentConfig);
+    }
+
+    @ApiOperation(value = "删除按费用类型配置")
+    @PostMapping("/delTypeRoute")
+    @PreAuthorize("@pcs.hasPermissions('paymentConfig/delTypeRoute')")
+    public HttpResponseResult<SysPaymentConfig> delTypeRoute(Integer id) {
+        SysPaymentConfig paymentConfig = sysPaymentConfigService.get(id);
+        if (paymentConfig == null) {
+            return failed("此分部配置不存在");
+        }
+        Date nowDate = new Date();
+        paymentConfig.setTypeRouteScale("");
+        paymentConfig.setUpdateTime(nowDate);
+        sysPaymentConfigService.update(paymentConfig);
+        return succeed(paymentConfig);
+    }
+
 }