Browse Source

Merge remote-tracking branch 'origin/saas' into saas

zouxuan 3 years ago
parent
commit
1f5ac67f18
21 changed files with 824 additions and 249 deletions
  1. 0 2
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/OrganizationDao.java
  2. 20 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantAssetsInfoDao.java
  3. 0 1
      mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TenantInfoDto.java
  4. 99 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantAssetsInfo.java
  5. 108 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantConfigDetail.java
  6. 12 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantOrderRecord.java
  7. 9 0
      mec-biz/src/main/java/com/ym/mec/biz/service/OrderPayOpsService.java
  8. 19 0
      mec-biz/src/main/java/com/ym/mec/biz/service/TenantAssetsInfoService.java
  9. 1 1
      mec-biz/src/main/java/com/ym/mec/biz/service/TenantInfoService.java
  10. 302 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrderPayOpsServiceImpl.java
  11. 0 2
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/PlatformServeServiceImpl.java
  12. 59 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantAssetsInfoServiceImpl.java
  13. 52 35
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java
  14. 0 4
      mec-biz/src/main/resources/config/mybatis/OrganizationMapper.xml
  15. 28 0
      mec-biz/src/main/resources/config/mybatis/TenantAssetsInfoMapper.xml
  16. 16 0
      mec-biz/src/main/resources/rebel.xml
  17. 32 201
      mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java
  18. 40 0
      mec-web/src/main/java/com/ym/mec/web/controller/TenantAssetsInfoController.java
  19. 1 1
      mec-web/src/main/java/com/ym/mec/web/controller/TenantInfoController.java
  20. 24 0
      mec-web/src/main/java/com/ym/mec/web/controller/TenantOrderRecordController.java
  21. 2 2
      mec-web/src/main/resources/logback-spring.xml

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

@@ -9,8 +9,6 @@ import java.util.Set;
 
 public interface OrganizationDao extends BaseDAO<Integer, Organization> {
 
-    Organization getByName(@Param("name") String name,@Param("tenantId") Integer tenantId);
-
     /**
      * 根据父级id查询子级列表
      * @param parentId

+ 20 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantAssetsInfoDao.java

@@ -0,0 +1,20 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 机构资产信息(TenantAssetsInfo)表数据库访问层
+ *
+ * @author hgw
+ * @since 2021-12-22 14:27:02
+ */
+public interface TenantAssetsInfoDao extends BaseMapper<TenantAssetsInfo> {
+
+    int insertBatch(@Param("entities") List<TenantAssetsInfo> entities);
+
+}
+

+ 0 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TenantInfoDto.java

@@ -49,7 +49,6 @@ public class TenantInfoDto implements Serializable {
     /**
      * 地址
      */
-    @NotBlank(message = "地址不能为空!")
     @Size(max = 200, message = "地址不能超过200个字!")
     @ApiModelProperty(value = "地址")
     private String address;

+ 99 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantAssetsInfo.java

@@ -0,0 +1,99 @@
+package com.ym.mec.biz.dal.entity;
+
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+import java.io.Serializable;
+
+/**
+ * 机构资产信息(TenantAssetsInfo)表实体类
+ *
+ * @author hgw
+ * @since 2021-12-22 14:27:02
+ */
+@ApiModel(value = "tenant_assets_info-机构资产信息")
+public class TenantAssetsInfo implements Serializable {
+    @TableId(value = "id_", type = IdType.AUTO)
+    @ApiModelProperty(value = "主键")
+    private Integer id;
+
+    @TableField("tenant_id_")
+    @ApiModelProperty(value = "机构id")
+    private Integer tenantId;
+
+    @TableField("balance_")
+    @ApiModelProperty(value = "余额")
+    private BigDecimal balance;
+
+    @TableField("frozen_amount_")
+    @ApiModelProperty(value = "冻结金额")
+    private BigDecimal frozenAmount;
+
+    @TableField("created_time_")
+    @ApiModelProperty(value = "创建时间")
+    private Date createdTime;
+
+    @TableField("updated_time_")
+    @ApiModelProperty(value = "更新时间")
+    private Date updatedTime;
+
+    private static final long serialVersionUID = 1L;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Integer tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    public BigDecimal getBalance() {
+        return balance;
+    }
+
+    public void setBalance(BigDecimal balance) {
+        this.balance = balance;
+    }
+
+    public BigDecimal getFrozenAmount() {
+        return frozenAmount;
+    }
+
+    public void setFrozenAmount(BigDecimal frozenAmount) {
+        this.frozenAmount = frozenAmount;
+    }
+
+    public Date getCreatedTime() {
+        return createdTime;
+    }
+
+    public void setCreatedTime(Date createdTime) {
+        this.createdTime = createdTime;
+    }
+
+    public Date getUpdatedTime() {
+        return updatedTime;
+    }
+
+    public void setUpdatedTime(Date updatedTime) {
+        this.updatedTime = updatedTime;
+    }
+
+
+}
+

+ 108 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantConfigDetail.java

@@ -0,0 +1,108 @@
+package com.ym.mec.biz.dal.entity;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * TenantConfig表config字段,该字段是动态
+ * @author hgw
+ * Created by 2021-12-22
+ */
+public class TenantConfigDetail implements Serializable {
+
+    /**
+     * 会员设置-分润金额
+     */
+    private MemberConfig member_config;
+
+    /**
+     * 云教室规则
+     */
+    private CloudRoomRule cloud_room_rule;
+
+    public static class MemberConfig implements Serializable {
+        private BigDecimal month_divide;
+        private BigDecimal quarter_divide;
+        private BigDecimal half_year_divide;
+        private BigDecimal year_divide;
+
+        public BigDecimal getMonth_divide() {
+            return month_divide;
+        }
+
+        public void setMonth_divide(BigDecimal month_divide) {
+            this.month_divide = month_divide;
+        }
+
+        public BigDecimal getQuarter_divide() {
+            return quarter_divide;
+        }
+
+        public void setQuarter_divide(BigDecimal quarter_divide) {
+            this.quarter_divide = quarter_divide;
+        }
+
+        public BigDecimal getHalf_year_divide() {
+            return half_year_divide;
+        }
+
+        public void setHalf_year_divide(BigDecimal half_year_divide) {
+            this.half_year_divide = half_year_divide;
+        }
+
+        public BigDecimal getYear_divide() {
+            return year_divide;
+        }
+
+        public void setYear_divide(BigDecimal year_divide) {
+            this.year_divide = year_divide;
+        }
+    }
+
+    public static class CloudRoomRule implements Serializable {
+
+        /**
+         * 云教室人数上限(含老师)
+         */
+        private Integer cloud_room_up_limit;
+
+        /**
+         * String人数-BigDecimal每分钟扣费标准
+         */
+        private Map<String, BigDecimal> cloud_room_config;
+
+        public Integer getCloud_room_up_limit() {
+            return cloud_room_up_limit;
+        }
+
+        public void setCloud_room_up_limit(Integer cloud_room_up_limit) {
+            this.cloud_room_up_limit = cloud_room_up_limit;
+        }
+
+        public Map<String, BigDecimal> getCloud_room_config() {
+            return cloud_room_config;
+        }
+
+        public void setCloud_room_config(Map<String, BigDecimal> cloud_room_config) {
+            this.cloud_room_config = cloud_room_config;
+        }
+    }
+
+    public MemberConfig getMember_config() {
+        return member_config;
+    }
+
+    public void setMember_config(MemberConfig member_config) {
+        this.member_config = member_config;
+    }
+
+    public CloudRoomRule getCloud_room_rule() {
+        return cloud_room_rule;
+    }
+
+    public void setCloud_room_rule(CloudRoomRule cloud_room_rule) {
+        this.cloud_room_rule = cloud_room_rule;
+    }
+}

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantOrderRecord.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -75,6 +76,17 @@ public class TenantOrderRecord implements Serializable {
     @ApiModelProperty(value = "订单创建时间")
     private Date createdTime;
 
+    public DealStatusEnum getEnumOrderState() {
+        switch (orderState) {
+            case 0:
+                return DealStatusEnum.ING;
+            case 1:
+                return DealStatusEnum.SUCCESS;
+            default:
+                return DealStatusEnum.FAILED;
+        }
+    }
+
     private static final long serialVersionUID = 1L;
 
     public Integer getId() {

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/OrderPayOpsService.java

@@ -0,0 +1,9 @@
+package com.ym.mec.biz.service;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+public interface OrderPayOpsService {
+
+    Map<String, Object> executePayment(BigDecimal amount, String orderNo, String payChannel, String returnUrl, String orderSubject, String orderBody, String sign, String code, String platform) throws Exception;
+}

+ 19 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/TenantAssetsInfoService.java

@@ -0,0 +1,19 @@
+package com.ym.mec.biz.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ym.mec.biz.dal.entity.CourseSchedule;
+import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
+
+import java.util.List;
+
+/**
+ * 机构资产信息(TenantAssetsInfo)表服务接口
+ *
+ * @author hgw
+ * @since 2021-12-22 14:27:02
+ */
+public interface TenantAssetsInfoService extends IService<TenantAssetsInfo> {
+
+    void courseDeductionRules(List<CourseSchedule> dto);
+}
+

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

@@ -23,7 +23,7 @@ public interface TenantInfoService extends IService<TenantInfo> {
 
     TenantInfo get(Integer tenantId);
 
-    Map<String, Object> pay(Integer tenantId) throws Exception;
+    Map<String, Object> tenantOpenPay(Integer tenantId) throws Exception;
 
     Msg orderNotify(Msg msg);
 

+ 302 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrderPayOpsServiceImpl.java

@@ -0,0 +1,302 @@
+package com.ym.mec.biz.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.entity.TenantOrderRecord;
+import com.ym.mec.biz.dal.entity.TenantPaymentOrder;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
+import com.ym.mec.biz.service.OrderPayOpsService;
+import com.ym.mec.biz.service.StudentPaymentOrderService;
+import com.ym.mec.biz.service.TenantOrderRecordService;
+import com.ym.mec.biz.service.TenantPaymentOrderService;
+import com.ym.mec.common.exception.BizException;
+import com.ym.mec.common.page.WrapperUtil;
+import com.ym.mec.thirdparty.adapay.ConfigInit;
+import com.ym.mec.thirdparty.adapay.Payment;
+import com.ym.mec.util.date.DateUtil;
+import com.ym.mec.util.http.HttpUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.DigestUtils;
+
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+/**
+ * @author hgw
+ * Created by 2021-12-22
+ */
+@Service
+public class OrderPayOpsServiceImpl implements OrderPayOpsService {
+    private static final Logger log = LoggerFactory.getLogger(OrderPayOpsServiceImpl.class);
+
+    @Autowired
+    private StudentPaymentOrderService studentPaymentOrderService;
+    @Autowired
+    private TenantPaymentOrderService tenantPaymentOrderService;
+    @Autowired
+    private TenantOrderRecordService tenantOrderRecordService;
+
+    @Override
+    public Map<String, Object> executePayment(BigDecimal amount, String orderNo, String payChannel, String returnUrl, String orderSubject, String orderBody, String sign, String code, String platform) throws Exception {
+        PaymentParam payParam = new PaymentParam(amount, orderNo, payChannel, returnUrl,
+                orderSubject, orderBody, sign, code, platform);
+        log.info("executePayment >>>>>> "+JSON.toJSONString(payParam));
+        //签名验证
+        checkSing(payParam);
+
+        Map<String, Object> payment = new HashMap<>();
+        if (platform != null) {
+            if (platform.equals("tenant")) {
+                //机构开通付款
+                TenantOrderRecord tenantOrderRecord = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>()
+                        .hasEq("order_no_", payParam.getOrderNo()).queryWrapper());
+                payment = checkOrderAndGetParam(payParam,
+                        tenantOrderRecord,
+                        TenantOrderRecord::getEnumOrderState,
+                        TenantOrderRecord::getCreatedTime,
+                        tenantOrderRecord::setTransNo,
+                        tenantOrderRecordService::updateById
+                );
+            } else if (platform.equals("teacher")) {
+                TenantPaymentOrder tenantPaymentOrder = tenantPaymentOrderService.queryByOrderNo(payParam.getOrderNo());
+                payment = checkOrderAndGetParam(payParam,
+                        tenantPaymentOrder,
+                        TenantPaymentOrder::getStatus,
+                        TenantPaymentOrder::getCreateTime,
+                        tenantPaymentOrder::setTransNo,
+                        tenantPaymentOrderService::update
+                );
+            } else {
+                StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(payParam.getOrderNo());
+                payment = checkOrderAndGetParam(payParam,
+                        studentPaymentOrder,
+                        StudentPaymentOrder::getStatus,
+                        StudentPaymentOrder::getCreateTime,
+                        studentPaymentOrder::setTransNo,
+                        studentPaymentOrderService::update
+                );
+            }
+        }
+
+        return payment;
+    }
+
+    private void checkSing(PaymentParam param) {
+        Map<String, Object> signParams = new LinkedHashMap<>();
+        signParams.put("appId", ConfigInit.appId);
+        signParams.put("amount", param.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+        signParams.put("orderNo", param.getOrderNo());
+        signParams.put("orderSubject", param.getOrderSubject());
+        signParams.put("orderBody", param.getOrderBody());
+        signParams.put("wxAppId", ConfigInit.wxAppId);
+        String originalStr = JSONObject.toJSONString(signParams);
+        String newSign = DigestUtils.md5DigestAsHex(originalStr.getBytes());
+        if (!newSign.equals(param.getSign())) {
+            log.info("executePayment >>>>>> checkSing : "+newSign);
+            throw new BizException("请勿非法请求");
+        }
+    }
+
+    private <T> Map<String, Object> checkOrderAndGetParam(PaymentParam payParam, T clazz,
+                                                          Function<T, DealStatusEnum> enumFunc, Function<T, Date> dateFunc,
+                                                          Consumer<String> setOption, Consumer<T> action) throws Exception {
+        if (Objects.isNull(clazz)) {
+            throw new BizException("订单不存在");
+        }
+        checkOrderState(clazz, enumFunc);
+        Date createTime = dateFunc.apply(clazz);
+        //校验订单是否超时
+        String timeExpire = checkOrderTimeOut(createTime);
+        //初始化支付数据
+        Map<String, Object> paymentParams = getPaymentParam(payParam);
+        paymentParams.put("time_expire", timeExpire);
+        paymentParams.put("expend", getExpend(payParam));
+        //获取第三方的支付的信息
+        Map<String, Object> payment = Payment.executePayment(paymentParams);
+        String transNo = (String) payment.get("id");
+        //修改流水
+        setTransNoByApply(transNo, clazz, setOption, action);
+
+        return payment;
+    }
+
+    private <T> void checkOrderState(T obj, Function<T, DealStatusEnum> func) {
+        BiPredicate<Object, DealStatusEnum> predicate = (o, s) -> Objects.nonNull(o) && !DealStatusEnum.ING.equals(s);
+        DealStatusEnum em = func.apply(obj);
+        if (predicate.test(obj, em)) {
+            String msg = em.equals(DealStatusEnum.SUCCESS) ? "订单已支付,请勿重复支付" : "订单已关闭,不能支付";
+            throw new BizException(msg);
+        }
+    }
+
+    private String checkOrderTimeOut(Date createTime) {
+        Calendar beforeTime = Calendar.getInstance();
+        beforeTime.add(Calendar.MINUTE, -28);// 28 分钟之前的时间
+        Date beforeDate = beforeTime.getTime();
+        if (createTime.before(beforeDate)) {
+            throw new BizException("订单已超时,请重新下单");
+        }
+        Date expireDate = DateUtil.addMinutes(createTime, 30);
+        return new SimpleDateFormat("yyyyMMddHHmmss").format(expireDate);
+    }
+
+    private <T> void setTransNoByApply(String TransNo, T clazz, Consumer<String> setOption, Consumer<T> action) {
+        Optional.ofNullable(clazz)
+                .filter(c -> Objects.nonNull(setOption))
+                .filter(c -> Objects.nonNull(action))
+                .filter(c -> StringUtils.isNotBlank(TransNo))
+                .map(c -> {
+                    setOption.accept(TransNo);
+                    return c;
+                })
+                .ifPresent(action);
+    }
+
+
+    private Map<String, Object> getExpend(PaymentParam payParam) throws Exception {
+        Map<String, Object> expendParams = new HashMap<>(5);
+        String openId = "";
+        if (payParam.getPayChannel().equals("wx_pub")) {
+            //微信支付则获取openId
+            openId = getOpenId(payParam.getCode());
+        }
+        expendParams.put("open_id", openId);
+        expendParams.put("is_raw", "1");
+        expendParams.put("callback_url", payParam.getReturnUrl());
+        expendParams.put("limit_pay", "1");
+        return expendParams;
+    }
+
+    private String getOpenId(String code) throws Exception {
+        String openId;
+        if (code == null || code.isEmpty()) {
+            throw new BizException("微信支付请先授权");
+        }
+        String wxMpOAuth2AccessTokenUrl = String.format(ConfigInit.wxMpOAuth2AccessTokenUrl, ConfigInit.wxAppId, ConfigInit.wxAppSecret, code);
+        Map<String, String> weChatRes = JSON.parseObject(HttpUtil.get(wxMpOAuth2AccessTokenUrl, new HashMap<>()), Map.class);
+        if (!weChatRes.containsKey("openid")) {
+            throw new BizException("授权失败,请重新授权");
+        }
+        openId = weChatRes.get("openid");
+        return openId;
+    }
+
+    private Map<String, Object> getPaymentParam(PaymentParam payParam) {
+        Map<String, Object> paymentParams = new HashMap<>();
+        paymentParams.put("app_id", ConfigInit.appId);
+        paymentParams.put("order_no", payParam.getOrderNo());
+        paymentParams.put("pay_channel", payParam.getPayChannel());
+        paymentParams.put("pay_amt", payParam.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+        paymentParams.put("goods_title", payParam.getOrderSubject());
+        paymentParams.put("goods_desc", payParam.getOrderBody());
+        paymentParams.put("pay_mode", "delay");
+        return paymentParams;
+    }
+
+    static class PaymentParam {
+        private BigDecimal amount;
+        private String orderNo;
+        private String payChannel;
+        private String returnUrl;
+        private String orderSubject;
+        private String orderBody;
+        private String sign;
+        private String code;
+        private String platform;
+
+        PaymentParam(BigDecimal amount, String orderNo, String payChannel, String returnUrl, String orderSubject,
+                     String orderBody, String sign, String code, String platform) {
+            this.amount = amount;
+            this.orderNo = orderNo;
+            this.payChannel = payChannel;
+            this.returnUrl = returnUrl;
+            this.orderSubject = orderSubject;
+            this.orderBody = orderBody;
+            this.sign = sign;
+            this.code = code;
+            this.platform = platform;
+        }
+
+        public BigDecimal getAmount() {
+            return amount;
+        }
+
+        public void setAmount(BigDecimal amount) {
+            this.amount = amount;
+        }
+
+        public String getOrderNo() {
+            return orderNo;
+        }
+
+        public void setOrderNo(String orderNo) {
+            this.orderNo = orderNo;
+        }
+
+        public String getPayChannel() {
+            return payChannel;
+        }
+
+        public void setPayChannel(String payChannel) {
+            this.payChannel = payChannel;
+        }
+
+        public String getReturnUrl() {
+            return returnUrl;
+        }
+
+        public void setReturnUrl(String returnUrl) {
+            this.returnUrl = returnUrl;
+        }
+
+        public String getOrderSubject() {
+            return orderSubject;
+        }
+
+        public void setOrderSubject(String orderSubject) {
+            this.orderSubject = orderSubject;
+        }
+
+        public String getOrderBody() {
+            return orderBody;
+        }
+
+        public void setOrderBody(String orderBody) {
+            this.orderBody = orderBody;
+        }
+
+        public String getSign() {
+            return sign;
+        }
+
+        public void setSign(String sign) {
+            this.sign = sign;
+        }
+
+        public String getCode() {
+            return code;
+        }
+
+        public void setCode(String code) {
+            this.code = code;
+        }
+
+        public String getPlatform() {
+            return platform;
+        }
+
+        public void setPlatform(String platform) {
+            this.platform = platform;
+        }
+    }
+
+}

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

@@ -127,7 +127,6 @@ public class PlatformServeServiceImpl extends ServiceImpl<PlatformServeDao, Plat
         return platformServeDetailDao.queryDetailById(id);
     }
 
-
     private PlatformServeServiceInfo getServeInfo(PlatformServeDto obj) {
         List<PlatformServeDetail> detailList = getDetailList(obj);
 
@@ -177,7 +176,6 @@ public class PlatformServeServiceImpl extends ServiceImpl<PlatformServeDao, Plat
         }
     }
 
-
     private List<PlatformServeDetail> getDetailList(PlatformServeDto obj) {
         return Optional.ofNullable(obj)
                 .filter(o -> CollectionUtils.isNotEmpty(obj.getDetailList()))

+ 59 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantAssetsInfoServiceImpl.java

@@ -0,0 +1,59 @@
+package com.ym.mec.biz.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ym.mec.biz.dal.dao.TenantAssetsInfoDao;
+import com.ym.mec.biz.dal.entity.CourseSchedule;
+import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
+import com.ym.mec.biz.dal.entity.TenantConfig;
+import com.ym.mec.biz.dal.entity.TenantConfigDetail;
+import com.ym.mec.biz.dal.entity.TenantConfigDetail.CloudRoomRule;
+import com.ym.mec.biz.service.TenantAssetsInfoService;
+import com.ym.mec.biz.service.TenantConfigService;
+import com.ym.mec.common.exception.BizException;
+import com.ym.mec.common.filters.TenantIdThreadLocal;
+import com.ym.mec.common.page.WrapperUtil;
+import com.ym.mec.common.tenant.TenantContextHolder;
+import org.apache.commons.collections.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * 机构资产信息(TenantAssetsInfo)表服务实现类
+ *
+ * @author hgw
+ * @since 2021-12-22 14:27:02
+ */
+@Service("tenantAssetsInfoService")
+public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao, TenantAssetsInfo> implements TenantAssetsInfoService {
+
+    private final static Logger log = LoggerFactory.getLogger(TenantAssetsInfoServiceImpl.class);
+
+    @Autowired
+    private TenantConfigService tenantConfigService;
+
+    /**
+     * 排课扣费计算
+     * 1.线上排课计算出的总价格不能超过账户余额(注意多人同时操作账户余额多扣问题)
+     * 2.若符合规则冻结部分账户
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void courseDeductionRules(List<CourseSchedule> dto) {
+
+    }
+
+
+}
+

+ 52 - 35
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysRole;
 import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.auth.api.enums.SysUserType;
 import com.ym.mec.biz.dal.dao.OrganizationDao;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dao.TenantInfoDao;
@@ -74,6 +75,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     private SysConfigDao sysConfigDao;
     @Autowired
     private TenantOrderRecordService tenantOrderRecordService;
+    @Autowired
+    private TenantAssetsInfoService assetsInfoService;
 
     /**
      * 新增机构
@@ -103,20 +106,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
                 tenantProductInfoService::addTenantProduct);
         //添加机构配置
         setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::addConfig);
-        //创建一个和机构同名称的“分部”
-        createOrg(tenantInfo, dto.getAreaId());
-    }
-
-    //创建一个和机构同名称的“分部”
-    private void createOrg(TenantInfo tenantInfo, Integer areaId) {
-        Organization organization = new Organization();
-        organization.setName(tenantInfo.getName());
-        organization.setDelFlag(YesOrNoEnum.NO);
-        organization.setGradeType(GradeTypeEnum.SIX_PLUS);
-        organization.setCreateTime(new Date());
-        organization.setTenantId(tenantInfo.getId());
-        organization.setAreaId(areaId);
-        organizationDao.insert(organization);
     }
 
     /**
@@ -246,8 +235,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         Integer tenantId = tenantInfo.getId();
         SysUser user = sysUserFeignService.queryUserByMobile(tenantInfo.getPhone());
         if (Objects.nonNull(user)) {
-            return;
+            if (user.getUserType().contains(SysUserType.SYSTEM.getCode())) {
+                return;
+            }
         }
+
         //防止重复点击 加锁
         String key = "Tenant_First_Open:" + tenantId;
         RBucket<Object> bucket = redissonClient.getBucket(key);
@@ -268,12 +260,21 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         }
         //拆分菜单获取菜单ID
         List<Integer> collectMenuId = getMenuId(menuIdList);
+        //创建一个和机构同名称的“分部”
+        Integer orgId = createOrg(tenantInfo);
         //建立角色
         Integer roleId = createRole(tenantInfo);
+        // 创建账号、用户信息、用户和角色关系
+        createUser(tenantInfo, orgId, Lists.newArrayList(roleId));
         //建立角色和菜单关系数据
         employeeService.batchInsertRoleMenu(roleId, collectMenuId, tenantId);
-        // 创建账号、用户信息、用户和角色关系
-        createUser(tenantInfo, Lists.newArrayList(roleId));
+        //创建资产信息
+        TenantAssetsInfo assetsInfo = new TenantAssetsInfo();
+        assetsInfo.setTenantId(tenantId);
+        assetsInfo.setBalance(BigDecimal.ZERO);
+        assetsInfo.setFrozenAmount(BigDecimal.ZERO);
+        assetsInfo.setCreatedTime(new Date());
+        assetsInfoService.save(assetsInfo);
     }
 
     //拆分菜单获取菜单ID
@@ -294,21 +295,21 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         sysRole.setCreateTime(new Date());
         sysRole.setDelFlag("0");
         sysRole.setTenantId(tenantInfo.getId());
-        Organization organization = organizationDao.getByName(tenantInfo.getName(), tenantInfo.getId());
-        sysRole.setOrganId(organization.getId());
         employeeService.insertSysRole(sysRole);
         return sysRole.getId();
     }
 
     //创建账号、用户信息、用户和角色关系
-    private void createUser(TenantInfo tenantInfo, List<Integer> roles) {
+    private void createUser(TenantInfo tenantInfo, Integer orgId, List<Integer> roles) {
         Employee e = new Employee();
+        e.setTenantId(tenantInfo.getId());
         e.setPhone(tenantInfo.getPhone());
         e.setRealName(tenantInfo.getContacts());
         e.setJobNature(JobNatureEnum.FULL_TIME);
         e.setEntryDate(LocalDate.now().toDate());
         e.setRoles(roles);
         e.setRoleIds(roles);
+        e.setOrganIdList(String.valueOf(orgId));
         try {
             employeeService.add(e);
         } catch (Exception ex) {
@@ -316,6 +317,19 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         }
     }
 
+    //创建一个和机构同名称的“分部”
+    private Integer createOrg(TenantInfo tenantInfo) {
+        Organization organization = new Organization();
+        organization.setName(tenantInfo.getName());
+        organization.setDelFlag(YesOrNoEnum.NO);
+        organization.setGradeType(GradeTypeEnum.SIX_PLUS);
+        organization.setCreateTime(new Date());
+        organization.setTenantId(tenantInfo.getId());
+        organization.setAreaId(tenantInfo.getAreaId());
+        organizationDao.insert(organization);
+        return organization.getId();
+    }
+
     /**
      * 分页查询
      *
@@ -335,9 +349,9 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     }
 
     /**
-     * 机构缴费
+     * 机构开通缴费
      */
-    public Map<String, Object> pay(Integer tenantId) throws Exception {
+    public Map<String, Object> tenantOpenPay(Integer tenantId) throws Exception {
         TenantInfo tenantInfo = Optional.ofNullable(tenantId)
                 .map(baseMapper::selectById)
                 .orElseThrow(() -> new BizException("未查询到机构信息!"));
@@ -345,7 +359,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         RBucket<Object> bucket = redissonClient.getBucket(key);
         //原子操作 抢锁成功为true
         if (!bucket.trySet(tenantId, 10, TimeUnit.SECONDS)) {
-            if(tenantInfo.getPayState() == 1){
+            if (tenantInfo.getPayState() == 1) {
                 throw new BizException("已缴费请勿重复缴费!");
             }
             throw new BizException("该机构数正在缴费中请勿频繁操作");
@@ -357,11 +371,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         String orderNo = idGenerator.generatorId("payment") + "";
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
         TenantOrderRecordEnum tenantEnum = TenantOrderRecordEnum.TENANT_OPEN;
-        //获取分部信息
-        Organization organization = organizationDao.getByName(tenantInfo.getName(), tenantId);
-        if (Objects.isNull(organization)) {
-            throw new BizException("未查询到机构分部信息!");
-        }
         Map<String, Object> result = new HashMap<>();
         int orderState = 0;
         //消费大于0元则拉起支付
@@ -392,7 +401,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
 
     //生成订单
     private void createOrderRecord(Integer tenantId, BigDecimal payAmount, String orderNo, TenantOrderRecordEnum tenantEnum, Integer orderState) {
-        LocalDateTime now = LocalDateTime.now();
         TenantOrderRecord record = new TenantOrderRecord();
         record.setTenantId(tenantId);
         record.setOrderNo(orderNo);
@@ -401,9 +409,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         record.setExpectAmount(payAmount);
         record.setActualAmount(payAmount);
         record.setOrderState(orderState);
-        record.setPayDate(now.toLocalDate().toDate());
-        record.setPayTime(now.toDate());
-        record.setCreatedTime(now.toDate());
+        record.setCreatedTime(new Date());
         tenantOrderRecordService.save(record);
     }
 
@@ -421,13 +427,15 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         String orderNo = notifyMap.get("merMerOrderNo");
         TenantOrderRecord record = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>()
                 .hasEq("order_no_", orderNo).queryWrapper());
-        record.setTransNo(notifyMap.get("orderNo"));
         String channelType = notifyMap.get("channelType").equals("1") ? "WXPay" : (notifyMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
         record.setPayChannel(channelType);
         //支付中订单存在,更新状态 tradeState 88就是正确的 其他错误的
         if (msg.getResponseType().equals("1") && notifyMap.size() > 0 && msg.getCode().equals("88")) {
             // notifyMap.put("totalMoney", notifyMap.get("payAmount"));
+            LocalDateTime now = LocalDateTime.now();
             record.setOrderState(1);
+            record.setPayDate(now.toLocalDate().toDate());
+            record.setPayTime(now.toDate());
             msg.setCode("000000");
             msg.setMsg("success");
             if (TenantOrderRecordEnum.TENANT_OPEN.getCode().equals(record.getOrderType())) {
@@ -447,12 +455,21 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      * 校验手机号
      */
     private void checkPhone(TenantInfoDto dto) {
-        SysUser sysUser = Optional.ofNullable(dto)
+        //防止重复点击 加锁
+        String key = "Tenant_First_Add:" + dto.getPhone();
+        RBucket<Object> bucket = redissonClient.getBucket(key);
+        //原子操作 抢锁成功为true
+        if (!bucket.trySet(dto.getPhone(), 1L, TimeUnit.MINUTES)) {
+            throw new BizException("同一个手机号请勿频繁操作!");
+        }
+        SysUser sysUser = Optional.of(dto)
                 .map(TenantInfoDto::getPhone)
                 .map(sysUserFeignService::queryUserByMobile)
                 .orElse(null);
         if (Objects.nonNull(sysUser)) {
-            throw new BizException("该手机号已被注册!");
+            if (sysUser.getUserType().contains(SysUserType.SYSTEM.getCode())) {
+                throw new BizException("该手机号已被注册!");
+            }
         }
     }
 

+ 0 - 4
mec-biz/src/main/resources/config/mybatis/OrganizationMapper.xml

@@ -35,10 +35,6 @@
 		SELECT * FROM organization WHERE id_ = #{id} 
 	</select>
 
-    <select id="getByName" parameterType="object" resultMap="Organization">
-        SELECT * FROM organization WHERE name_ = #{name} and tenant_id_ = #{tenantId}
-    </select>
-
     <!-- 全查询 -->
     <select id="findAll" resultMap="Organization">
 		SELECT * FROM organization ORDER BY id_

+ 28 - 0
mec-biz/src/main/resources/config/mybatis/TenantAssetsInfoMapper.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ym.mec.biz.dal.dao.TenantAssetsInfoDao">
+    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantAssetsInfo">
+        <id column="id_" jdbcType="INTEGER" property="id"/>
+        <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
+        <result column="balance_" jdbcType="VARCHAR" property="balance"/>
+        <result column="frozen_amount_" jdbcType="VARCHAR" property="frozenAmount"/>
+        <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
+        <result column="updated_time_" jdbcType="TIMESTAMP" property="updatedTime"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id_
+        , tenant_id_, balance_, frozen_amount_, created_time_, updated_time_
+    </sql>
+
+    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
+            parameterType="com.ym.mec.biz.dal.entity.TenantAssetsInfo">
+        insert into tenant_assets_info(tenant_id_, balance_, frozen_amount_, created_time_, updated_time_)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.tenantId}, #{entity.balance}, #{entity.frozenAmount}, #{entity.createdTime},
+            #{entity.updatedTime})
+        </foreach>
+    </insert>
+
+</mapper>

+ 16 - 0
mec-biz/src/main/resources/rebel.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
+  Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
+-->
+<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd">
+
+	<id>mec-biz</id>
+
+	<classpath>
+		<dir name="E:/hgw/DYYM/项目/mec/mec-biz/target/classes">
+		</dir>
+	</classpath>
+
+</application>

+ 32 - 201
mec-student/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -1,109 +1,45 @@
 package com.ym.mec.student.controller;
 
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.net.URLEncoder;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpStatus;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.util.DigestUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
-import com.ym.mec.biz.dal.dao.ChildrenDayDegreeDetailDao;
-import com.ym.mec.biz.dal.dao.CourseScheduleEvaluateDao;
-import com.ym.mec.biz.dal.dao.DegreeRegistrationDao;
-import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderCourseSettingsDao;
-import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDao;
-import com.ym.mec.biz.dal.dao.OrganizationDao;
-import com.ym.mec.biz.dal.dao.ReplacementInstrumentActivityDao;
-import com.ym.mec.biz.dal.dao.StudentGoodsSellDao;
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
-import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
-import com.ym.mec.biz.dal.dao.SysConfigDao;
-import com.ym.mec.biz.dal.dao.SysCouponCodeDao;
-import com.ym.mec.biz.dal.dao.VipGroupActivityDao;
-import com.ym.mec.biz.dal.dto.CloudTeacherOrderDto;
-import com.ym.mec.biz.dal.dto.LuckStatisDto;
-import com.ym.mec.biz.dal.dto.OrderStatisDto;
-import com.ym.mec.biz.dal.dto.Practice4OrganDto;
-import com.ym.mec.biz.dal.dto.PracticeGroupStatisDto;
-import com.ym.mec.biz.dal.dto.PracticeGroupsDto;
-import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
-import com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto;
-import com.ym.mec.biz.dal.dto.VipBuyResultDto;
-import com.ym.mec.biz.dal.entity.DegreeRegistration;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.LuckDrawCount;
-import com.ym.mec.biz.dal.entity.MusicGroup;
-import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender;
-import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderCourseSettings;
-import com.ym.mec.biz.dal.entity.Organization;
-import com.ym.mec.biz.dal.entity.SellOrder;
-import com.ym.mec.biz.dal.entity.SporadicChargeInfo;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
-import com.ym.mec.biz.dal.entity.StudentRegistration;
-import com.ym.mec.biz.dal.entity.TenantPaymentOrder;
+import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.dto.*;
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
-import com.ym.mec.biz.service.CloudTeacherOrderService;
-import com.ym.mec.biz.service.LuckDrawCountService;
-import com.ym.mec.biz.service.MusicGroupService;
-import com.ym.mec.biz.service.SellOrderService;
-import com.ym.mec.biz.service.SporadicChargeInfoService;
-import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
-import com.ym.mec.biz.service.SysConfigService;
-import com.ym.mec.biz.service.TenantOrderRecordService;
-import com.ym.mec.biz.service.TenantPaymentOrderService;
-import com.ym.mec.biz.service.VipGroupService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.tenant.TenantContextHolder;
-import com.ym.mec.thirdparty.adapay.ConfigInit;
 import com.ym.mec.thirdparty.adapay.Payment;
 import com.ym.mec.thirdparty.yqpay.Msg;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.net.URLEncoder;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @RequestMapping("studentOrder")
 @Api(tags = "订单回调")
@@ -159,6 +95,8 @@ public class StudentOrderController extends BaseController {
     private SellOrderService sellOrderService;
     @Autowired
     private TenantOrderRecordService tenantOrderRecordService;
+    @Autowired
+    private OrderPayOpsService orderPayOpsService;
 
     @Value("${spring.profiles.active:dev}")
     private String profiles;
@@ -304,120 +242,13 @@ public class StudentOrderController extends BaseController {
             @ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String"),
             @ApiImplicitParam(name = "payChannel", value = "支付方式(alipay-支付宝app支付)", required = true, dataType = "String"),
     })
-    public Object executePayment(BigDecimal amount, String orderNo, String payChannel, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sign, String code, String platform) throws Exception {
-        Map<String, Object> signParams = new LinkedHashMap<>();
-        signParams.put("appId", ConfigInit.appId);
-        signParams.put("amount", amount.setScale(2, BigDecimal.ROUND_HALF_UP));
-        signParams.put("orderNo", orderNo);
-//        signParams.put("notifyUrl", notifyUrl);
-//        signParams.put("returnUrl", returnUrl);
-        signParams.put("orderSubject", orderSubject);
-        signParams.put("orderBody", orderBody);
-        signParams.put("wxAppId", ConfigInit.wxAppId);
-
-        String originalStr = JSONObject.toJSONString(signParams);
-        String mewSign = DigestUtils.md5DigestAsHex(originalStr.getBytes());
-        if (!mewSign.equals(sign)) {
-            return failed("请勿非法请求");
-        }
-
-        String openId = "";
-        if (payChannel.equals("wx_pub")) {
-            if (code == null || code.isEmpty()) {
-                return failed("微信支付请先授权");
-            }
-            String wxMpOAuth2AccessTokenUrl = String.format(ConfigInit.wxMpOAuth2AccessTokenUrl, ConfigInit.wxAppId, ConfigInit.wxAppSecret, code);
-            Map<String, String> weChatRes = JSON.parseObject(HttpUtil.get(wxMpOAuth2AccessTokenUrl, new HashMap<>()), Map.class);
-            if (!weChatRes.containsKey("openid")) {
-                return failed("授权失败,请重新授权");
-            }
-            openId = weChatRes.get("openid");
-        }
-
-        Date createTime = null;
-        TenantPaymentOrder tenantPaymentOrder = null;
-        StudentPaymentOrder studentPaymentOrder = null;
-        if (platform != null && platform.equals("teacher")) {
-            tenantPaymentOrder = tenantPaymentOrderService.queryByOrderNo(orderNo);
-        } else {
-            studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(orderNo);
-        }
-
-        if (studentPaymentOrder == null && tenantPaymentOrder == null) {
-            return failed("订单不存在");
-        }
-        if (studentPaymentOrder != null && !studentPaymentOrder.getStatus().equals(DealStatusEnum.ING)) {
-            String msg = studentPaymentOrder.getStatus().equals(DealStatusEnum.SUCCESS) ? "订单已支付,请勿重复支付" : "订单已关闭,不能支付";
-            return failed(msg);
-        }
-        if (tenantPaymentOrder != null && !tenantPaymentOrder.getStatus().equals(DealStatusEnum.ING)) {
-            String msg = tenantPaymentOrder.getStatus().equals(DealStatusEnum.SUCCESS) ? "订单已支付,请勿重复支付" : "订单已关闭,不能支付";
-            return failed(msg);
-        }
-
-        if (studentPaymentOrder != null) {
-            createTime = studentPaymentOrder.getCreateTime();
-        } else {
-            createTime = tenantPaymentOrder.getCreateTime();
-        }
-
-        Calendar beforeTime = Calendar.getInstance();
-        beforeTime.add(Calendar.MINUTE, -28);// 28 分钟之前的时间
-        Date beforeDate = beforeTime.getTime();
-        if (createTime.before(beforeDate)) {
-            return failed("订单已超时,请重新下单");
-        }
-
-        Date expireDate = DateUtil.addMinutes(createTime, 30);
-        String timeExpire = new SimpleDateFormat("yyyyMMddHHmmss").format(expireDate);
-
-        Map<String, Object> paymentParams = new HashMap<>();
-        paymentParams.put("app_id", ConfigInit.appId);
-        paymentParams.put("order_no", orderNo);
-        paymentParams.put("pay_channel", payChannel);
-        paymentParams.put("pay_amt", amount.setScale(2, BigDecimal.ROUND_HALF_UP));
-        paymentParams.put("goods_title", orderSubject);
-        paymentParams.put("goods_desc", orderBody);
-        paymentParams.put("time_expire", timeExpire);
-        paymentParams.put("pay_mode", "delay");
-
-        //延时分账时不需要
-//        List<StudentPaymentRouteOrder> routeOrders = studentPaymentRouteOrderDao.getRouteOrders(orderNo);
-//        List<Map<String, Object>> divMembers = new ArrayList<>();
-//        for (StudentPaymentRouteOrder routeOrder : routeOrders) {
-//            Map<String, Object> divMember = new HashMap<>();
-//            divMember.put("member_id", routeOrder.getMerNo());//分佣账户
-//            divMember.put("amount", routeOrder.getRouteAmount().setScale(2, BigDecimal.ROUND_HALF_UP));//分佣金额
-//            divMember.put("fee_flag", routeOrder.getFeeFlag());
-//            if (routeOrder.getMerNo().equals(ConfigInit.merNo)) {
-//                divMember.put("member_id", 0);
-//            }
-//            divMembers.add(divMember);
-//        }
-//        if (divMembers.size() > 0) {
-//            paymentParams.put("div_members", JSON.toJSONString(divMembers));
-//        }
-
-        Map<String, Object> expendParams = new HashMap<>(5);
-
-        expendParams.put("open_id", openId);
-        expendParams.put("is_raw", "1");
-        expendParams.put("callback_url", returnUrl);
-        expendParams.put("limit_pay", "1");
-
-        paymentParams.put("expend", expendParams);
-
-        Map<String, Object> payment = Payment.executePayment(paymentParams);
-
-        if (studentPaymentOrder != null) {
-            studentPaymentOrder.setTransNo((String) payment.get("id"));
-            studentPaymentOrderService.update(studentPaymentOrder);
-        } else {
-            tenantPaymentOrder.setTransNo((String) payment.get("id"));
-            tenantPaymentOrderService.update(tenantPaymentOrder);
+    public Object executePayment(BigDecimal amount, String orderNo, String payChannel, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sign, String code, String platform) {
+        try {
+            Map<String, Object> payment = orderPayOpsService.executePayment(amount, orderNo, payChannel, returnUrl, orderSubject, orderBody, sign, code, platform);
+            return succeed(payment);
+        } catch (Exception e) {
+            return failed(e.getMessage());
         }
-
-        return succeed(payment);
     }
 
     @GetMapping("/authorize")

+ 40 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TenantAssetsInfoController.java

@@ -0,0 +1,40 @@
+package com.ym.mec.web.controller;
+
+
+import com.ym.mec.biz.dal.entity.CourseSchedule;
+import com.ym.mec.biz.dal.entity.TenantAssetsInfo;
+import com.ym.mec.biz.service.TenantAssetsInfoService;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.web.bind.annotation.*;
+import com.ym.mec.common.controller.BaseController;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 机构资产信息(TenantAssetsInfo)表控制层
+ *
+ * @author hgw
+ * @since 2021-12-22 14:27:02
+ */
+@RestController
+@RequestMapping("/tenantAssetsInfo")
+public class TenantAssetsInfoController extends BaseController {
+    /**
+     * 服务对象
+     */
+    @Resource
+    private TenantAssetsInfoService tenantAssetsInfoService;
+
+    @ApiOperation("修改机构启用停用状态")
+    @GetMapping(value = "/ops/{id}")
+//    @PreAuthorize("@pcs.hasPermissions('tenantInfo/opsState')")
+    public Object opsState() {
+        tenantAssetsInfoService.courseDeductionRules(null);
+        return succeed();
+    }
+
+
+}
+

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

@@ -77,7 +77,7 @@ public class TenantInfoController extends BaseController {
     @ApiOperation("机构支付")
     @GetMapping(value = "/pay/{id}")
     public Object pay(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id) throws Exception {
-        return succeed(tenantInfoService.pay(id));
+        return succeed(tenantInfoService.tenantOpenPay(id));
     }
 
     @PostMapping("/notify")

+ 24 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TenantOrderRecordController.java

@@ -3,16 +3,22 @@ package com.ym.mec.web.controller;
 
 import com.ym.mec.biz.dal.dto.TenantOrderRecordDto;
 import com.ym.mec.biz.dal.entity.TenantOrderRecord;
+import com.ym.mec.biz.service.OrderPayOpsService;
 import com.ym.mec.biz.service.TenantOrderRecordService;
 import com.ym.mec.common.controller.BaseController;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Map;
 
 /**
  * 机构付款记录表(TenantOrderRecord)表控制层
@@ -29,6 +35,8 @@ public class TenantOrderRecordController extends BaseController {
      */
     @Resource
     private TenantOrderRecordService tenantOrderRecordService;
+    @Autowired
+    private OrderPayOpsService orderPayOpsService;
 
     @ApiOperation("分页查询")
     @PostMapping(value = "/queryPage")
@@ -36,5 +44,21 @@ public class TenantOrderRecordController extends BaseController {
         return tenantOrderRecordService.queryPage(dto);
     }
 
+    @ApiOperation(value = "自测用的")
+    @PostMapping("/executePayment")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "amount", value = "支付金额", required = true, dataType = "BigDecimal"),
+            @ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "payChannel", value = "支付方式(alipay-支付宝app支付)", required = true, dataType = "String"),
+    })
+    public Object executePayment(BigDecimal amount, String orderNo, String payChannel, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sign, String code, String platform) {
+        try {
+            Map<String, Object> payment = orderPayOpsService.executePayment(amount, orderNo, payChannel, returnUrl, orderSubject, orderBody, sign, code, platform);
+            return succeed(payment);
+        } catch (Exception e) {
+            return failed(e.getMessage());
+        }
+    }
+
 }
 

+ 2 - 2
mec-web/src/main/resources/logback-spring.xml

@@ -52,14 +52,14 @@
 
 	<!--开发环境:打印控制台 -->
 	<springProfile name="dev">
-		<root level="WARN">
+		<root level="INFO">
 			<appender-ref ref="stdout" />
 			<appender-ref ref="file" />
 		</root>
 	</springProfile>
 
 	<springProfile name="test">
-		<root level="WARN">
+		<root level="INFO">
 			<appender-ref ref="stdout" />
 			<appender-ref ref="file" />
 		</root>