瀏覽代碼

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

# Conflicts:
#	mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrganizationServiceImpl.java
zouxuan 3 年之前
父節點
當前提交
fae3844b70

+ 1 - 1
mec-auth/mec-auth-server/src/main/resources/config/mybatis/SysUserDeviceMapper.xml

@@ -119,7 +119,7 @@
 	</select>
 	
 	<select id="queryByUserId" resultMap="SysUserDevice" parameterType="map">
-		SELECT * FROM sys_user_device WHERE user_id_ = #{userId} and del_flag_ = 0 and tenant_id_ = #{tenantId}
+		SELECT * FROM sys_user_device WHERE user_id_ = #{userId} and del_flag_ = 0
 		<if test="clientId != null">
 			and client_id_ = #{clientId}
 		</if>

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantProductInfo.java

@@ -67,6 +67,10 @@ public class TenantProductInfo implements Serializable {
     @ApiModelProperty(value = "有效期(具体到期时间)")
     private Date expiryDate;
 
+    @TableField(value = "using_")
+    @ApiModelProperty(value = "正在使用的服务 0是  1否 (一个机构可以购买多个服务,但是只能生效一个))")
+    private Integer using;
+
     private static final long serialVersionUID = 1L;
 
     public Integer getId() {
@@ -157,4 +161,11 @@ public class TenantProductInfo implements Serializable {
         this.expiryDate = expiryDate;
     }
 
+    public Integer getUsing() {
+        return using;
+    }
+
+    public void setUsing(Integer using) {
+        this.using = using;
+    }
 }

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

@@ -3,10 +3,12 @@ package com.ym.mec.biz.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ym.mec.biz.dal.dto.TenantInfoDto;
 import com.ym.mec.biz.dal.entity.TenantInfo;
+import com.ym.mec.biz.dal.entity.TenantProductInfo;
 import com.ym.mec.biz.dal.entity.TenantProductSumm;
 import com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.thirdparty.yqpay.Msg;
+import org.redisson.api.RBucket;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
@@ -30,6 +32,12 @@ public interface TenantInfoService extends IService<TenantInfo> {
 
     Map<String, Object> tenantOpenPay(Integer tenantId) throws Exception;
 
+    Map<String, Object> tenantRenewPay(Integer tenantId, Integer val) throws Exception;
+
+    RBucket<Object> opsRenewInfo(Integer tenantId);
+
+    void renewSuccess(Integer val, TenantProductInfo productInfo, BigDecimal amount);
+
     Msg orderNotify(Msg msg);
 
     Map<String, Object> recharge(Integer tenantId, BigDecimal amount) throws Exception;

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

@@ -63,8 +63,8 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
 
         Map<String, Object> payment = new HashMap<>();
         if (platform != null) {
-            if (platform.equals("tenant")) {
-                //机构开通付款
+            if (WrapperUtil.checkStr(platform,"tenant")) {
+                //机构开通、续费付款
                 TenantOrderRecord tenantOrderRecord = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>()
                         .hasEq("order_no_", payParam.getOrderNo()).queryWrapper());
                 payment = checkOrderAndGetParam(payParam,

+ 3 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrganizationServiceImpl.java

@@ -13,6 +13,7 @@ import com.ym.mec.biz.dal.enums.SixPlusGradeEnum;
 import com.ym.mec.biz.dal.page.EducationBaseQueryInfo;
 import com.ym.mec.biz.service.OrganizationService;
 import com.ym.mec.biz.service.SysEmployeePositionService;
+import com.ym.mec.biz.service.TenantInfoService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
@@ -33,7 +34,7 @@ public class OrganizationServiceImpl extends BaseServiceImpl<Integer, Organizati
 	@Autowired
 	private OrganizationDao organizationDao;
 	@Autowired
-	private TenantInfoDao tenantInfoDao;
+	private TenantInfoService tenantInfoService;
 	@Autowired
 	private TeacherDao teacherDao;
 	@Autowired
@@ -153,7 +154,7 @@ public class OrganizationServiceImpl extends BaseServiceImpl<Integer, Organizati
 	public String getEmployeeOrgan(Integer userId, String organIds,Boolean isSuper) {
 		if(StringUtils.isEmpty(organIds)){
 			Integer tenantId = TenantContextHolder.getTenantId();
-			TenantInfo tenantInfo = tenantInfoDao.selectById(tenantId);
+			TenantInfo tenantInfo = tenantInfoService.get(tenantId);
 			//如果是超管,或者是机构管理员,可以查看当前机构所有分部数据
 			if(isSuper || (tenantInfo.getUserId() != null && tenantInfo.getUserId().equals(userId))){
 				Map<String,Object> param = new HashMap<>();

+ 124 - 41
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -194,7 +194,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         BeanUtils.copyProperties(tenantInfo, tenantInfoDto);
         //机构产品信息
         TenantProductInfo productInfo = tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
-                .eq("tenant_id_", tenantId));
+                .eq("tenant_id_", tenantId).eq("using_", 0));
         setTenantInfo(productInfo, new TenantProductInfoDto(), tenantInfoDto::setProductInfo);
         //机构配置信息
         TenantConfig tenantConfig = tenantConfigService.getOne(new QueryWrapper<TenantConfig>()
@@ -227,16 +227,17 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         if (Objects.isNull(tenantId)) {
             throw new BizException("请传入机构id");
         }
-        //查询最后一条该机构开通记录
-        TenantOrderRecord oneRecord = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>().queryWrapper()
+        //查询开通 续费 正在支付的记录
+        List<TenantOrderRecord> record = tenantOrderRecordService.list(new WrapperUtil<TenantOrderRecord>().queryWrapper()
                 .eq("tenant_id_", tenantId)
                 .isNotNull("trans_no_")
-                .eq("order_type_", "TENANT_OPEN")
+                .and(wrapper -> wrapper.eq("order_type_", "TENANT_OPEN")
+                        .or().eq("order_type_", "TENANT_RENEW"))
                 .eq("payment_channel_", "ADAPAY")
-                .orderByDesc("created_time_"));
+                .eq("order_state_", 0));
         //存在,就去第三方再次校验
-        if (Objects.nonNull(oneRecord)) {
-            tenantOrderRecordService.checkTenantOrder(oneRecord);
+        if (CollectionUtils.isNotEmpty(record)) {
+            record.forEach(r -> tenantOrderRecordService.checkTenantOrder(r));
         }
         return queryTenantInfo(tenantId);
     }
@@ -300,7 +301,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         }
         //获取产品信息得到服务id
         TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
-                .hasEq("tenant_id_", tenantId).queryWrapper());
+                .hasEq("tenant_id_", tenantId).queryWrapper().eq("using_", 0));
         if (Objects.isNull(productInfo)) {
             throw new BizException("开通账号信息异常!未查询到购买的产品信息!");
         }
@@ -320,22 +321,18 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         //建立角色和菜单关系数据
         Lists.partition(collectMenuId, 50)
                 .forEach(idList -> employeeService.batchInsertRoleMenu(roleId, idList, tenantId));
+
+        Date now = new Date();
+
         //创建资产信息
         TenantAssetsInfo assetsInfo = new TenantAssetsInfo();
         assetsInfo.setTenantId(tenantId);
         assetsInfo.setBalance(BigDecimal.ZERO);
         assetsInfo.setFrozenAmount(BigDecimal.ZERO);
-        assetsInfo.setCreatedTime(new Date());
+        assetsInfo.setCreatedTime(now);
         assetsInfoService.save(assetsInfo);
         //修改有效期
-        Date expiryDate;
-        if (TenantProductInfo.MONTH.equals(productInfo.getExpiryUnit())) {
-            expiryDate = DateUtils.addMonths(new Date(), productInfo.getExpiryCount());
-        } else if (TenantProductInfo.YEAR.equals(productInfo.getExpiryUnit())) {
-            expiryDate = DateUtils.addYears(new Date(), productInfo.getExpiryCount());
-        } else {
-            throw new BizException("产品信息异常!开通失败!");
-        }
+        Date expiryDate = getExpiryDate(productInfo.getExpiryCount(), productInfo.getExpiryUnit(), now);
         productInfo.setExpiryDate(expiryDate);
         tenantProductInfoService.updateById(productInfo);
         //发送邮件提醒
@@ -348,6 +345,19 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         bucket.delete();
     }
 
+    //计算过期时间
+    private Date getExpiryDate(Integer expiryCount, String expiryUnit, Date date) {
+        Date expiryDate;
+        if (TenantProductInfo.MONTH.equals(expiryUnit)) {
+            expiryDate = DateUtils.addMonths(date, expiryCount);
+        } else if (TenantProductInfo.YEAR.equals(expiryUnit)) {
+            expiryDate = DateUtils.addYears(date, expiryCount);
+        } else {
+            throw new BizException("产品信息异常!开通失败!");
+        }
+        return expiryDate;
+    }
+
     //拆分菜单获取菜单ID
     private List<Integer> getMenuId(List<String> menuIdList) {
         return menuIdList.stream()
@@ -427,21 +437,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      * 机构开通缴费
      */
     public Map<String, Object> tenantOpenPay(Integer tenantId) throws Exception {
-        TenantInfo tenantInfo = Optional.ofNullable(tenantId)
-                .map(baseMapper::selectById)
-                .orElseThrow(() -> new BizException("未查询到机构信息!"));
-        String key = "Tenant_Pay:" + tenantId;
-        RBucket<Object> bucket = redissonClient.getBucket(key);
-        //原子操作 抢锁成功为true
-        if (!bucket.trySet(tenantId, 10, TimeUnit.SECONDS)) {
-            if (tenantInfo.getPayState() == 1) {
-                throw new BizException("已缴费请勿重复缴费!");
-            }
-            throw new BizException("正在缴费中请稍后!");
-        }
-        //机构产品信息
-        TenantProductInfo productInfo = tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
-                .eq("tenant_id_", tenantId));
+        TenantProductInfo productInfo = getProductInfo(tenantId);
         //生成订单编号
         String orderNo = idGenerator.generatorId("payment") + "";
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
@@ -474,6 +470,94 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         return result;
     }
 
+    /**
+     * 机构续费
+     *
+     * @param tenantId 机构id
+     * @param val      购买周期
+     */
+    public Map<String, Object> tenantRenewPay(Integer tenantId, Integer val) throws Exception {
+        TenantProductInfo productInfo = getProductInfo(tenantId);
+        //续费时 取合同价
+        BigDecimal amount = productInfo.getContractPrice().multiply(new BigDecimal(val));
+
+        //生成订单编号
+        String orderNo = idGenerator.generatorId("payment") + "";
+        TenantOrderRecordEnum tenantEnum = TenantOrderRecordEnum.TENANT_RENEW;
+        Map<String, Object> result = new HashMap<>();
+        int orderState = 0;
+        //消费大于0元则拉起支付
+        if (amount.compareTo(BigDecimal.ZERO) > 0) {
+            result = payService.getPayMap(
+                    amount,
+                    BigDecimal.ZERO,
+                    orderNo,
+                    null,
+                    null,
+                    tenantEnum.getMsg(),
+                    tenantEnum.getMsg(),
+                    1,//临时写死
+                    tenantEnum.getCode()
+            );
+        } else {
+            //续费成功
+            renewSuccess(val, productInfo, amount);
+            orderState = 1;
+        }
+        createOrderRecord(tenantId, amount, orderNo, tenantEnum, orderState);
+        //写入续费信息
+        opsRenewInfo(tenantId).set(val, 1, TimeUnit.HOURS);
+        log.info("tenant pay >>>>> {} ", result);
+        return result;
+    }
+
+    //操作续费信息
+    public RBucket<Object> opsRenewInfo(Integer tenantId) {
+        String key = TenantOrderRecordEnum.TENANT_RENEW.getCode() + ":" + tenantId;
+        return redissonClient.getBucket(key);
+    }
+
+    /**
+     * 续费成功
+     *
+     * @param val         续费周期
+     * @param productInfo 原产品信息
+     * @param amount      续费总金额
+     */
+    public void renewSuccess(Integer val, TenantProductInfo productInfo, BigDecimal amount) {
+        Date expiryDate;
+        Date now = new Date();
+        if (productInfo.getExpiryDate().compareTo(now) > 0) {
+            //在上一个时间节点上做增加操作
+            expiryDate = getExpiryDate(val, productInfo.getExpiryUnit(), productInfo.getExpiryDate());
+        } else {
+            //如果上一个时间已经到期则 取现在时间
+            expiryDate = getExpiryDate(val, productInfo.getExpiryUnit(), now);
+        }
+        productInfo.setExpiryDate(expiryDate);
+        productInfo.setPayAmount(productInfo.getPayAmount().add(amount));
+        productInfo.setExpiryCount(productInfo.getExpiryCount() + val);
+        tenantProductInfoService.updateById(productInfo);
+    }
+
+    private TenantProductInfo getProductInfo(Integer tenantId) {
+        TenantInfo tenantInfo = Optional.ofNullable(tenantId)
+                .map(baseMapper::selectById)
+                .orElseThrow(() -> new BizException("未查询到机构信息!"));
+        String key = "Tenant_Pay:" + tenantId;
+        RBucket<Object> bucket = redissonClient.getBucket(key);
+        //原子操作 抢锁成功为true
+        if (!bucket.trySet(tenantId, 10, TimeUnit.SECONDS)) {
+            if (tenantInfo.getPayState() == 1) {
+                throw new BizException("已缴费请勿重复缴费!");
+            }
+            throw new BizException("正在缴费中请稍后!");
+        }
+        //机构产品信息
+        return tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
+                .eq("tenant_id_", tenantId).eq("using_", 0));
+    }
+
     //生成订单
     private void createOrderRecord(Integer tenantId, BigDecimal payAmount, String orderNo, TenantOrderRecordEnum
             tenantEnum, Integer orderState) {
@@ -614,7 +698,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     @Override
     public Map<String, Object> recharge(Integer tenantId, BigDecimal amount) throws Exception {
         log.error("机构 " + tenantId.toString() + "充值");
-        TenantInfo tenantInfo = Optional.ofNullable(tenantId)
+        Optional.of(tenantId)
                 .map(baseMapper::selectById)
                 .orElseThrow(() -> new BizException("充值时,未查询到机构信息!"));
         String key = "Tenant_Pay:" + tenantId;
@@ -679,19 +763,19 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     @Override
     public void saveTenantContextHolder(HttpServletRequest request) {
         String tenantId = request.getHeader("tenantId");
-        if(StringUtils.isEmpty(tenantId)){
+        if (StringUtils.isEmpty(tenantId)) {
             SysUser sysUser = sysUserFeignService.queryUserInfo();
-            if(sysUser != null && sysUser.getTenantId() != null){
+            if (sysUser != null && sysUser.getTenantId() != null) {
                 tenantId = sysUser.getTenantId().toString();
             }
         }
-        if(StringUtils.isNotEmpty(tenantId)){
+        if (StringUtils.isNotEmpty(tenantId)) {
             TenantContextHolder.setTenantId(Integer.parseInt(tenantId));
-            if(Integer.parseInt(tenantId) != -1){
+            if (Integer.parseInt(tenantId) != -1) {
                 TenantInfo tenantInfo = this.baseMapper.getOpenTenant(Integer.parseInt(tenantId));
-                if(tenantInfo != null){
+                if (tenantInfo != null) {
                     request.setAttribute("datasourceId", tenantInfo.getDataSource());
-                }else {
+                } else {
                     throw new BizException("机构信息异常,请联系管理员");
                 }
             }
@@ -703,7 +787,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         return baseMapper.queryTenantInfoByOrgan(organId);
     }
 
-
     @Override
     public Boolean testEmail() {
         SysUser user = sysUserFeignService.queryUserInfo();
@@ -711,7 +794,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         receivers.put(user.getId(), "yanite1234@sina.com");
         receivers.put(2, "yanite2016@sina.com");
         receivers.put(3, "yanite@qq.com");
-        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, MessageTypeEnum.EMAIL_TENANT_ACTIVATION_SUCCESSFUL, receivers, null, 0, null, "SYSTEM", null);
+        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, MessageTypeEnum.EMAIL_TENANT_ACTIVATION_SUCCESSFUL, receivers, null, 0, null, "SYSTEM", "小风乐团", "xiaofeng", "this is password");
 
         return false;
     }

+ 35 - 16
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java

@@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.*;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
 
 /**
  * 机构付款记录表(TenantOrderRecord)表服务实现类
@@ -107,6 +108,13 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
         return result;
     }
 
+    private static final Map<String, Consumer<TenantOrderRecord>> checkOrder = new HashMap<>();
+    {
+        //开通缴费
+        checkOrder.put(TenantOrderRecordEnum.TENANT_OPEN.getCode(), this::open);
+        //续费
+        checkOrder.put(TenantOrderRecordEnum.TENANT_RENEW.getCode(), this::renew);
+    }
 
     @Override
     public void checkTenantOrder() {
@@ -122,21 +130,7 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
             list.forEach(record -> {
                 checkTransOrderState(record);
                 if (record.getOrderState() == 1) {
-                    //开通缴费
-                    if (TenantOrderRecordEnum.TENANT_OPEN.getCode().equals(record.getOrderType())) {
-                        //机构产品信息
-                        TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
-                                .hasEq("tenant_id_", record.getTenantId()).queryWrapper());
-                        //修改机构信息
-                        TenantInfo tenantInfo = new TenantInfo();
-                        tenantInfo.setId(record.getTenantId());
-                        tenantInfo.setPayState(1);
-                        tenantInfoService.updateById(tenantInfo);
-                        //修改机构产品信息
-                        productInfo.setPayDate(new Date());
-                        productInfo.setTenantId(record.getTenantId());
-                        tenantProductInfoService.updateById(productInfo);
-                    }
+                    checkOrder.get(record.getOrderType()).accept(record);
                     //修改流水
                     LocalDateTime now = LocalDateTime.now();
                     record.setPayDate(now.toLocalDate().toDate());
@@ -148,6 +142,31 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
         bucket.delete();
     }
 
+    private void open(TenantOrderRecord record) {
+        //机构产品信息
+        TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
+                .hasEq("tenant_id_", record.getTenantId()).queryWrapper().eq("using_",0));
+        //修改机构信息
+        TenantInfo tenantInfo = new TenantInfo();
+        tenantInfo.setId(record.getTenantId());
+        tenantInfo.setPayState(1);
+        tenantInfoService.updateById(tenantInfo);
+        //修改机构产品信息
+        productInfo.setPayDate(new Date());
+        productInfo.setTenantId(record.getTenantId());
+        tenantProductInfoService.updateById(productInfo);
+    }
+
+    private void renew(TenantOrderRecord record){
+        //机构产品信息
+        TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
+                .hasEq("tenant_id_", record.getTenantId()).queryWrapper().eq("using_",0));
+        //获取机构续费时长
+        Integer val = (Integer) tenantInfoService.opsRenewInfo(record.getTenantId()).get();
+        //修改产品信息
+        tenantInfoService.renewSuccess(val,productInfo,record.getActualAmount());
+    }
+
     //主动去第三方查询订单状态
     private void checkTransOrderState(TenantOrderRecord orderRecord) {
         if (StringUtils.equals(orderRecord.getPaymentChannel(), PaymentChannelEnum.ADAPAY.getCode())) {
@@ -213,7 +232,7 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
     private void tenantOrderSuccess(TenantOrderRecord orderRecord, Map<String, Object> detail) {
         //机构产品信息
         TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
-                .hasEq("tenant_id_", orderRecord.getTenantId()).queryWrapper());
+                .hasEq("tenant_id_", orderRecord.getTenantId()).queryWrapper().eq("using_",0));
         //获取服务信息
         PlatformServe platformServe = platformServeService.getOne(new WrapperUtil<PlatformServe>()
                 .hasEq("id_", productInfo.getServeId()).queryWrapper());

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantProductInfoServiceImpl.java

@@ -33,6 +33,7 @@ public class TenantProductInfoServiceImpl extends ServiceImpl<TenantProductInfoD
     public void addTenantProduct(TenantProductInfoDto dto) {
         checkServe(dto.getServeId(), dto.getServeDetailId());
         TenantProductInfo info = new TenantProductInfo();
+        info.setUsing(0);
         BeanUtils.copyProperties(dto, info);
         baseMapper.insert(info);
     }

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/PlatformProductMapper.xml

@@ -157,7 +157,7 @@
         FROM
         tenant_info AS a
                 JOIN `tenant_product_info` AS b
-                     ON a.`id_` = b.`tenant_id_`
+                     ON a.`id_` = b.`tenant_id_` and b.using_ = 0
                 JOIN
             (SELECT
                  a.id_ AS serveId,

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

@@ -152,7 +152,7 @@
             create_time_,
             update_time_,
             tenant_id_,
-            IFNULL(b.couponNum,0) AS canBeGetNum
+            a.`limit_exchange_num_` - IFNULL(b.couponNum,0) AS canBeGetNum
         FROM
             sys_coupon AS a
                 LEFT JOIN
@@ -168,7 +168,7 @@
           AND status_ = 1
           AND tenant_id_ = #{tenantId}
           AND a.`limit_exchange_num_` > IFNULL(b.couponNum, 0)
-          AND NOW() >= start_date_
+          AND NOW() >= end_date_
           AND (
                     stock_count_ > consume_num_
                 OR stock_count_ = - 1

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/TenantEntryActivitiesMapper.xml

@@ -39,7 +39,7 @@
 
 	<!-- 根据主键查询一条记录 -->
 	<select id="get" resultMap="TenantEntryActivities">
-		SELECT * FROM tenant_entry_activities WHERE id_ = #{id}
+		SELECT * FROM tenant_entry_activities WHERE id_ = #{id} AND tenant_id_ = #{tenantId}
 	</select>
 
 	<!-- 全查询 -->

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

@@ -60,7 +60,7 @@
         d.`student_up_limit_`,
         b.`expiry_date_`
         FROM tenant_info AS a
-        LEFT JOIN tenant_product_info AS b ON a.`id_` = b.`tenant_id_`
+        LEFT JOIN tenant_product_info AS b ON a.`id_` = b.`tenant_id_` and b.using_ = 0
         LEFT JOIN platform_serve AS c ON b.`serve_id_` = c.`id_`
         LEFT JOIN platform_serve_detail AS d ON b.`serve_detail_id_` = d.`id_` AND c.`id_` = d.`serve_id_`
         LEFT JOIN sys_user AS u ON a.`created_by_` = u.`id_`
@@ -100,7 +100,7 @@
                    psd.student_up_limit_ as studentUpLimit
             FROM `tenant_info` t
                      left join tenant_assets_info ta on ta.tenant_id_ = t.id_
-                     left join tenant_product_info tp on tp.tenant_id_ = t.id_
+                     left join tenant_product_info tp on tp.tenant_id_ = t.id_ and tp.using_ = 0
                      left join platform_serve ps on tp.serve_id_ = ps.id_
                      left join platform_serve_detail psd on tp.serve_detail_id_ = psd.id_
             where t.id_ = #{tenantId}

+ 20 - 16
mec-biz/src/main/resources/config/mybatis/TenantProductInfoMapper.xml

@@ -1,21 +1,25 @@
 <?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.TenantProductInfoDao">
-  <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantProductInfo">
-    <id column="id_" jdbcType="INTEGER" property="id" />
-    <result column="tenant_id_" jdbcType="INTEGER" property="tenantId" />
-    <result column="serve_id_" jdbcType="INTEGER" property="serveId" />
-    <result column="serve_detail_id_" jdbcType="INTEGER" property="serveDetailId" />
-    <result column="original_price_" jdbcType="DECIMAL" property="originalPrice" />
-    <result column="contract_price_" jdbcType="DECIMAL" property="contractPrice" />
-    <result column="pay_amount_" jdbcType="DECIMAL" property="payAmount" />
-    <result column="expiry_count_" jdbcType="INTEGER" property="expiryCount" />
-    <result column="expiry_unit_" jdbcType="VARCHAR" property="expiryUnit" />
-    <result column="expiry_data_" jdbcType="DATE" property="expiryDate" />
-  </resultMap>
-  <sql id="Base_Column_List">
-    id_, tenant_id_, serve_id_, serve_detail_id_, original_price_, contract_price_, pay_amount_, 
-    expiry_count_, expiry_unit_, expiry_data_
-  </sql>
+
+    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantProductInfo">
+        <id column="id_" jdbcType="INTEGER" property="id"/>
+        <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
+        <result column="serve_id_" jdbcType="INTEGER" property="serveId"/>
+        <result column="serve_detail_id_" jdbcType="INTEGER" property="serveDetailId"/>
+        <result column="original_price_" jdbcType="VARCHAR" property="originalPrice"/>
+        <result column="contract_price_" jdbcType="VARCHAR" property="contractPrice"/>
+        <result column="pay_amount_" jdbcType="VARCHAR" property="payAmount"/>
+        <result column="pay_date_" jdbcType="TIMESTAMP" property="payDate"/>
+        <result column="expiry_count_" jdbcType="INTEGER" property="expiryCount"/>
+        <result column="expiry_unit_" jdbcType="VARCHAR" property="expiryUnit"/>
+        <result column="expiry_date_" jdbcType="TIMESTAMP" property="expiryDate"/>
+        <result column="using_" jdbcType="INTEGER" property="using"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id_
+        , tenant_id_, serve_id_, serve_detail_id_, original_price_, contract_price_, pay_amount_, pay_date_, expiry_count_, expiry_unit_, expiry_date_, using_
+    </sql>
 
 </mapper>

+ 1 - 1
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/message/provider/CommEmailPlugin.java

@@ -98,7 +98,7 @@ public class CommEmailPlugin implements MessageSenderPlugin, InitializingBean {
 		try {
 			email.setFrom(from, fromName);
 			email.setSubject(subject);
-			email.setContent(content, "text/html");
+			email.setContent(content, "text/html;charset=utf8");
 			email.addTo(receiver);
 			email.send();
 			return true;

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

@@ -3,18 +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.dto.TenantInfoDto;
-import com.ym.mec.biz.dal.entity.CloudTeacherStudent;
 import com.ym.mec.biz.dal.entity.TenantProductSumm;
 import com.ym.mec.biz.service.TenantInfoService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
-import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.thirdparty.yqpay.Msg;
 import com.ym.mec.util.validator.ValidationKit;
-
 import io.swagger.annotations.*;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -22,9 +18,7 @@ import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
-
 import java.math.BigDecimal;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -89,7 +83,7 @@ public class TenantInfoController extends BaseController {
     @ApiOperation("查询用户机构信息")
     @GetMapping(value = "/queryUserTenantInfo")
     public Object queryUserTenantInfo() {
-    	SysUser user = sysUserFeignService.queryUserInfo();
+        SysUser user = sysUserFeignService.queryUserInfo();
         if (user == null || user.getId() == null) {
             return failed(HttpStatus.FORBIDDEN, "请登录");
         }
@@ -119,8 +113,15 @@ public class TenantInfoController extends BaseController {
         return succeed(tenantInfoService.tenantOpenPay(id));
     }
 
+    @ApiOperation("机构续费")
+    @GetMapping(value = "/renew/{id}")
+    public Object tenantRenewPay(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id, Integer val) throws Exception {
+        return succeed(tenantInfoService.tenantRenewPay(id, val));
+    }
+
     /**
      * 支付回调-第三方回调地址
+     *
      * @param msg
      * @return
      */