刘俊驰 4 месяцев назад
Родитель
Сommit
ce88eb860a
16 измененных файлов с 678 добавлено и 112 удалено
  1. 39 7
      cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/VipCardRecordController.java
  2. 7 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/student/controller/ImGroupController.java
  3. 7 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java
  4. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/VipCardRecordDao.java
  5. 31 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/VipCardRecord.java
  6. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/ImGroupService.java
  7. 16 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/VipCardRecordService.java
  8. 11 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/DiscountCardRecordServiceImpl.java
  9. 18 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImGroupServiceImpl.java
  10. 10 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserTenantAlbumRecordServiceImpl.java
  11. 302 102
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/VipCardRecordServiceImpl.java
  12. 10 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/DiscountCardRecordWrapper.java
  13. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/UserTenantAlbumRecordWrapper.java
  14. 152 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/VipCardRecordWrapper.java
  15. 2 0
      cooleshow-user/user-biz/src/main/resources/config/mybatis/DiscountCardRecordMapper.xml
  16. 64 0
      cooleshow-user/user-biz/src/main/resources/config/mybatis/VipCardRecordMapper.xml

+ 39 - 7
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/VipCardRecordController.java

@@ -2,6 +2,9 @@ package com.yonge.cooleshow.admin.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.google.common.collect.Lists;
+import com.microsvc.toolkit.common.response.paging.PageInfo;
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
+import com.microsvc.toolkit.common.response.template.R;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dao.UserOrderDao;
@@ -13,12 +16,11 @@ import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
 import com.yonge.cooleshow.biz.dal.service.VipCardRecordService;
 import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
 import com.yonge.cooleshow.biz.dal.vo.VipCardRecordVo;
+import com.yonge.cooleshow.biz.dal.wrapper.DiscountCardRecordWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.VipCardRecordWrapper;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.base.exception.BizException;
-import com.yonge.toolset.base.page.PageInfo;
-import com.yonge.toolset.mybatis.support.PageUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.checkerframework.checker.units.qual.A;
@@ -63,20 +65,41 @@ public class VipCardRecordController extends BaseController {
      */
     @PostMapping("/page")
     @ApiOperation(value = "查询分页", notes = "传入vipCardRecordSearch")
-    public HttpResponseResult<PageInfo<VipCardRecordVo>> page(@RequestBody VipCardRecordSearch query) {
-        IPage<VipCardRecordVo> pages = vipCardRecordService.selectPage(PageUtil.getPage(query), query);
-        return succeed(PageUtil.pageInfo(pages));
+    public HttpResponseResult<PageInfo<VipCardRecordWrapper.VipCardRecord>> page(@RequestBody VipCardRecordWrapper.VipQuery query) {
+        IPage<VipCardRecordWrapper.VipCardRecord> pages = vipCardRecordService.selectAdminPage(QueryInfo.getPage(query), query);
+        return succeed(QueryInfo.pageInfo(pages));
     }
 
+    @ApiOperation("扣减会员")
+    @PostMapping("/deduction")
+    @PreAuthorize("@pcs.hasPermissions('vipCardRecord/deduction')")
+    public HttpResponseResult<Void> deduction(@RequestBody @Validated VipCardRecordWrapper.DeductionVipCardRecord deductionVipCardRecord) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        deductionVipCardRecord.setCreateBy(sysUser.getId());
+
+        // 判断是否有待支付订单 如果有返回不可下单
+        OrderSearch search = new OrderSearch();
+        search.setOrderClient(deductionVipCardRecord.getClientType().name());
+        search.setGoodType(Lists.newArrayList(GoodTypeEnum.VIP, GoodTypeEnum.SVIP).stream().map(GoodTypeEnum::name).collect(Collectors.joining(",")));
+        search.setUserId(deductionVipCardRecord.getUserId());
+
+        UserOrderVo userOrderVo = userOrderDao.getPendingOrder(search);
+        if (null != userOrderVo) {
+            throw new BizException(997, "当前用户存在未支付订单,不可操作添加/扣减会员");
+        }
+        vipCardRecordService.deduction(deductionVipCardRecord);
+        return succeed();
+    }
 
-    @ApiOperation("添加/扣减会员")
+
+    @ApiOperation("添加会员")
     @PostMapping("/add")
     @PreAuthorize("@pcs.hasPermissions('vipCardRecord/add')")
     public HttpResponseResult<Void> add(@RequestBody @Validated VipCardRecordWrapper.AddVipCardRecord addVipCardRecord) {
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         addVipCardRecord.setCreateBy(sysUser.getId());
         if (addVipCardRecord.getStatus().equals(EVipRecordStatus.ADD)) {
-            addVipCardRecord.setSourceType(SourceTypeEnum.PLATFORM);
+            addVipCardRecord.setSourceType(SourceTypeEnum.BACKEND_GIVE);
         } else if (addVipCardRecord.getStatus().equals(EVipRecordStatus.DEDUCTION)) {
             addVipCardRecord.setSourceType(SourceTypeEnum.PLATFORM_DEDUCT);
         }
@@ -94,4 +117,13 @@ public class VipCardRecordController extends BaseController {
         vipCardRecordService.add(addVipCardRecord);
         return succeed();
     }
+
+
+
+    @ApiOperation(value = "会员时长")
+    @PostMapping("/info")
+    public R<VipCardRecordWrapper.Info> info(@RequestBody VipCardRecordWrapper.InfoQuery infoQuery) {
+
+        return R.from(vipCardRecordService.info(infoQuery));
+    }
 }

+ 7 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/student/controller/ImGroupController.java

@@ -147,5 +147,12 @@ public class ImGroupController extends BaseController {
 
         return succeed(userFriend);
     }
+
+    @ApiOperation("修改群简介")
+    @PostMapping(value = "/updateIntroduce")
+    public HttpResponseResult<Boolean> updateIntroduce(@Valid @RequestBody ImGroup imGroup) throws Exception {
+        return succeed(imGroupService.updateIntroduce(imGroup));
+    }
+
 }
 

+ 7 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java

@@ -171,6 +171,13 @@ public class ImGroupController extends BaseController {
         return succeed(imGroupService.queryAll(imGroupSearchDto));
     }
 
+
+    @ApiOperation("修改群简介")
+    @PostMapping(value = "/updateIntroduce")
+    public HttpResponseResult<Boolean> updateIntroduce(@Valid @RequestBody ImGroup imGroup) throws Exception {
+        return succeed(imGroupService.updateIntroduce(imGroup));
+    }
+
     @ApiOperation("修改群信息")
     @PostMapping(value = "/update")
     public HttpResponseResult<Boolean> update(@Valid @RequestBody ImGroup imGroup) throws Exception {

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/VipCardRecordDao.java

@@ -64,4 +64,7 @@ public interface VipCardRecordDao extends BaseMapper<VipCardRecord> {
     List<VipCardRecordWrapper.UserVipInfo> queryUserVipInfo(@Param("userIdList") List<Long> userIdList ,@Param("clientType") String clientType);
 
     void updateMsgStatus(@Param("ids") List<Long> ids, @Param("msgStatus") int msgStatus);
+
+    IPage<VipCardRecordWrapper.VipCardRecord> selectAdminPage(@Param("page") IPage<VipCardRecordWrapper.VipCardRecord> page,
+                                                              @Param("param") VipCardRecordWrapper.VipQuery query);
 }

+ 31 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/VipCardRecord.java

@@ -54,6 +54,16 @@ public class VipCardRecord implements Serializable {
     @TableField(value = "source_type_")
     private SourceTypeEnum sourceType;
 
+
+
+    @ApiModelProperty("预计开始时间")
+    @TableField(value = "estimated_start_time_")
+    private Date estimatedStartTime;
+
+    @ApiModelProperty("预计结束时间")
+    @TableField(value = "estimated_end_time_")
+    private Date estimatedEndTime;
+
     @ApiModelProperty("会员卡开始时间 ")
 	@TableField(value = "start_time_")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -114,4 +124,25 @@ public class VipCardRecord implements Serializable {
     @TableField(value = "send_msg_")
     private Boolean sendMsg;
 
+    @ApiModelProperty("扣减状态")
+    @TableField(value = "deduction_status_")
+    private EDeductionStatus deductionStatus;
+
+    @ApiModelProperty("扣减时间")
+    @TableField(value = "deduction_time_")
+    private Date deductionTime;
+
+    @ApiModelProperty("扣减原因")
+    @TableField(value = "deduction_reason_")
+    private String deductionReason;
+
+    @ApiModelProperty("扣减操作人")
+    @TableField(value = "deduction_by_")
+    private Long deductionBy;
+
+
+    @ApiModelProperty("版本")
+    @TableField(value = "version_")
+    private Integer version;
+
 }

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/ImGroupService.java

@@ -17,6 +17,7 @@ import com.yonge.cooleshow.biz.dal.enums.RoleEnum;
 import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupWrapper;
 import io.rong.models.Result;
 
+import javax.validation.Valid;
 import java.io.File;
 import java.util.List;
 import java.util.Set;
@@ -221,5 +222,7 @@ public interface ImGroupService extends IService<ImGroup> {
     void groupAvatarUpdate();
 
     Boolean muteAll(ImGroupWrapper.Mute mute);
+
+    Boolean updateIntroduce( ImGroup imGroup);
 }
 

+ 16 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/VipCardRecordService.java

@@ -119,4 +119,20 @@ public interface VipCardRecordService extends IService<VipCardRecord> {
     VipCardRecord addVip(VipCardRecordWrapper.AddVipCardRecord addVipCardRecord);
 
     List<VipCardRecordWrapper.UserVipInfo> queryUserVipInfo(List<Long> userIdList , String clientType);
+
+    /**
+     * 扣减会员
+     *
+     * @param deductionVipCardRecord
+     */
+    void deduction(VipCardRecordWrapper.DeductionVipCardRecord deductionVipCardRecord);
+
+    /**
+     *
+     *  获取会员信息
+     *
+     */
+    VipCardRecordWrapper.Info info(VipCardRecordWrapper.InfoQuery infoQuery);
+
+    IPage<VipCardRecordWrapper.VipCardRecord> selectAdminPage(IPage<VipCardRecordWrapper.VipCardRecord> page, VipCardRecordWrapper.VipQuery query);
 }

+ 11 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/DiscountCardRecordServiceImpl.java

@@ -148,7 +148,9 @@ public class DiscountCardRecordServiceImpl extends ServiceImpl<DiscountCardRecor
         deductionRecord.setEndTime(addTime(record.getEndTime(), PeriodEnum.DAY, -days,1));
         deductionRecord.setDeductionBy(result.getCreateBy());
         deductionRecord.setDeductionStatus(EDeductionStatus.DEDUCT);
-        deductionRecord.setEfficientFlag(false);
+        if (record.getStartTime().after(record.getEndTime())) {
+            deductionRecord.setEfficientFlag(false);
+        }
         this.updateById(deductionRecord);
 
         // 对比剩余天数
@@ -245,6 +247,14 @@ public class DiscountCardRecordServiceImpl extends ServiceImpl<DiscountCardRecor
                 .map(DiscountCardRecordWrapper.DiscountCardRecord::getOperatorId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
         Map<Long, SysUser> userMap = sysUserService.getMapByIds(createByList);
         records.forEach(discountCardRecord -> {
+
+
+            if (discountCardRecord.getStartTime().before(new Date())) {
+                discountCardRecord.setSurplusDay(DateUtil.daysBetweenUp(new Date(), discountCardRecord.getEndTime()));
+            } else {
+                discountCardRecord.setSurplusDay(DateUtil.daysBetweenUp(discountCardRecord.getStartTime(), discountCardRecord.getEndTime()));
+            }
+
             SysUser sysUser = userMap.get(discountCardRecord.getOperatorId());
             if (sysUser != null) {
                 discountCardRecord.setOperatorName(sysUser.getRealName());

+ 18 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImGroupServiceImpl.java

@@ -1455,6 +1455,24 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
         return true;
     }
 
+    @Override
+    @Transactional
+    public Boolean updateIntroduce(ImGroup imGroup) {
+
+        if (StringUtils.isEmpty(imGroup.getId())) {
+            throw new BizException("群组ID不能为空");
+        }
+        if (StringUtils.isEmpty(imGroup.getIntroduce())) {
+            throw new BizException("群组介绍不能为空");
+        }
+
+        return this.lambdaUpdate()
+                .eq(ImGroup::getId, imGroup.getId())
+                .set(ImGroup::getIntroduce, imGroup.getIntroduce())
+                .update();
+
+    }
+
     private void groupAvatarUpdate(List<ImGroup> records) {
 
         for (ImGroup imGroup : records) {

+ 10 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserTenantAlbumRecordServiceImpl.java

@@ -711,7 +711,9 @@ public class UserTenantAlbumRecordServiceImpl extends ServiceImpl<UserTenantAlbu
         userTenantAlbumRecord.setEndTime(addTime(record.getEndTime(), PeriodEnum.DAY, -days,1));
         userTenantAlbumRecord.setDeductionBy(result.getCreateBy());
         userTenantAlbumRecord.setDeductionStatus(EDeductionStatus.DEDUCT);
-        userTenantAlbumRecord.setEfficientFlag(false);
+        if (record.getStartTime().after(record.getEndTime())) {
+            userTenantAlbumRecord.setEfficientFlag(false);
+        }
         this.updateById(userTenantAlbumRecord);
 
         // 对比剩余天数
@@ -826,6 +828,13 @@ public class UserTenantAlbumRecordServiceImpl extends ServiceImpl<UserTenantAlbu
                 .map(UserTenantAlbumRecordWrapper.AdminUserTenantAlbumRecord::getOperatorId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
         Map<Long, com.yonge.cooleshow.biz.dal.entity.SysUser> userMap = sysUserService.getMapByIds(createByList);
         records.forEach(userTenantAlbumRecord -> {
+
+            if (userTenantAlbumRecord.getStartTime().before(new Date())) {
+                userTenantAlbumRecord.setSurplusDay(DateUtil.daysBetweenUp(new Date(), userTenantAlbumRecord.getEndTime()));
+            } else {
+                userTenantAlbumRecord.setSurplusDay(DateUtil.daysBetweenUp(userTenantAlbumRecord.getStartTime(), userTenantAlbumRecord.getEndTime()));
+            }
+
             com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = userMap.get(userTenantAlbumRecord.getOperatorId());
             if (sysUser != null) {
                 userTenantAlbumRecord.setOperatorName(sysUser.getRealName());

+ 302 - 102
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/VipCardRecordServiceImpl.java

@@ -9,29 +9,29 @@ import com.microsvc.toolkit.common.webportal.exception.BizException;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dao.MemberPriceSettingsDao;
 import com.yonge.cooleshow.biz.dal.dto.search.VipRecordSearch;
-import com.yonge.cooleshow.biz.dal.entity.ActivityReward;
-import com.yonge.cooleshow.biz.dal.entity.MemberPriceSettings;
-import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.entity.*;
 import com.yonge.cooleshow.biz.dal.enums.*;
 import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.vo.*;
+import com.yonge.cooleshow.biz.dal.wrapper.DiscountCardRecordWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.VipCardRecordWrapper;
 import com.yonge.toolset.base.page.PageInfo;
 import com.yonge.toolset.mybatis.support.PageUtil;
 import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 import com.yonge.toolset.utils.date.DateUtil;
+import org.jetbrains.annotations.NotNull;
 import org.joda.time.DateTime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.yonge.cooleshow.biz.dal.entity.VipCardRecord;
 import com.yonge.cooleshow.biz.dal.dto.search.VipCardRecordSearch;
 import com.yonge.cooleshow.biz.dal.dao.VipCardRecordDao;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.ZoneId;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
@@ -425,13 +425,39 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
             Integer vipDays = addVipCardRecord.getVipDays();
             // 存在转换,先扣除,再添加
             if (vipDays != null && vipDays > 0) {
-                VipCardRecordWrapper.AddVipCardRecord dedectRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecordWrapper.AddVipCardRecord.class);
-                dedectRecord.setStatus(EVipRecordStatus.DEDUCTION);
-                dedectRecord.setVipType(EVipType.VIP);
-                dedectRecord.setType(PeriodEnum.DAY);
-                dedectRecord.setTimes(vipDays);
-                dedectRecord.setReason("后台转换扣减");
-                deductVip(dedectRecord);
+
+                // 转换的 ,找到转换的记录,设置为失效,修改时间,添加一条转换后的记录 订单与添加转换订单一致
+                List<VipCardRecord> vipCardRecords = getVipCardRecords(addVipCardRecord.getUserId(), clientType, Lists.newArrayList(EVipType.VIP));
+                int vipDaysNum = vipDays;
+                if (CollectionUtils.isNotEmpty(vipCardRecords)) {
+                    // 根据结束时间正序
+                    vipCardRecords.sort(Comparator.comparing(VipCardRecord::getEndTime));
+                    List<VipCardRecord> vipCardRecordList = new ArrayList<>();
+                    for (VipCardRecord vipCardRecord : vipCardRecords) {
+                        int i = DateUtil.daysBetweenUp(vipCardRecord.getStartTime(), vipCardRecord.getEndTime());
+                        VipCardRecord record = new VipCardRecord();
+                        record.setId(vipCardRecord.getId());
+                        if (vipDaysNum == 0) {
+                            record.setStartTime(addTime(vipCardRecord.getStartTime(), PeriodEnum.DAY, -vipDaysNum,0));
+                            record.setEndTime(addTime(vipCardRecord.getEndTime(), PeriodEnum.DAY, -vipDaysNum,1));
+                        } else if (i > vipDaysNum) {
+                            record.setEndTime(addTime(vipCardRecord.getEndTime(), PeriodEnum.DAY, -vipDaysNum,1));
+                            record.setEfficientFlag(true);
+                            record.setDisplayFlag(true);
+                            record.setReason("后台转换扣减");
+                            record.setUpdateTime(new Date());
+                        } else {
+                            record.setEfficientFlag(false);
+                            record.setDeductionStatus(EDeductionStatus.EXPIRED);
+                            record.setUpdateTime(new Date());
+                            record.setReason("后台转换扣减");
+                            vipDaysNum = vipDaysNum - i;
+                        }
+                        vipCardRecordList.add(record);
+                    }
+                    this.updateBatchById(vipCardRecordList);
+                }
+
 
                 VipCardRecordWrapper.AddVipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecordWrapper.AddVipCardRecord.class);
                 addRecord.setStatus(EVipRecordStatus.ADD);
@@ -451,7 +477,8 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
         }
 
         if (Boolean.TRUE.equals(addVipCardRecord.getSendMsg())) {
-            sendAddVipMsg(addVipCardRecord);
+            sendAddVipMsg(addVipCardRecord.getUserId(),addVipCardRecord.getClientType(),addVipCardRecord.getStatus(),
+                    addVipCardRecord.getVipType(),addVipCardRecord.getType(),addVipCardRecord.getTimes(),addVipCardRecord.getReason());
         }
     }
 
@@ -480,38 +507,17 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
     // 会员添加
     @Override
     public VipCardRecord addVip(VipCardRecordWrapper.AddVipCardRecord addVipCardRecord) {
-        List<VipCardRecord> vipCardRecordList = this.lambdaQuery()
-                .eq(VipCardRecord::getClientType, addVipCardRecord.getClientType())
-                .eq(VipCardRecord::getUserId, addVipCardRecord.getUserId())
-                .ge(VipCardRecord::getEndTime, new Date())
-                .eq(VipCardRecord::getEfficientFlag, true)
-                .list()
-                .stream()
-//                .filter(n -> n.getEndTime() == null || n.getEndTime().after(new Date()))
-                .sorted(Comparator.comparing(VipCardRecord::getStartTime))
-                .collect(Collectors.toList());
+        List<VipCardRecord> vipCardRecordList = getVipCardRecords(addVipCardRecord.getUserId(),addVipCardRecord.getClientType(), Lists.newArrayList(EVipType.VIP,EVipType.SVIP));
 
 
         EVipType addVipType = addVipCardRecord.getVipType();
-//        List<VipCardRecord> perpetualRecords = vipCardRecordList.stream()
-//                .filter(n -> n.getVipType().equals(addVipType) && PeriodEnum.PERPETUAL.equals(n.getType()))
-//                .collect(Collectors.toList());
-//        if (!perpetualRecords.isEmpty()) {
-//            throw new BizException("已经是永久会员");
-//        }
 
         Date now = new Date();
-        long startTimeMills = now.getTime();
+        Date startDate = now;
         // 没有会员信息
         if (vipCardRecordList.isEmpty()) {
             PeriodEnum period = addVipCardRecord.getType();
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTime(now);
-            calendar.set(Calendar.HOUR_OF_DAY, 23);
-            calendar.set(Calendar.MINUTE, 59);
-            calendar.set(Calendar.SECOND, 59);
-            calendar.set(Calendar.MILLISECOND, 0);
-            Date endDate = plusDate(calendar.getTime(), period, Long.valueOf(addVipCardRecord.getTimes()));
+
 
             VipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecord.class);
             addRecord.setSourceType(addVipCardRecord.getSourceType() !=null?addVipCardRecord.getSourceType():SourceTypeEnum.BACKEND_GIVE);
@@ -519,74 +525,86 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
             addRecord.setDisplayFlag(true);
             addRecord.setEfficientFlag(true);
             addRecord.setStartTime(now);
-            addRecord.setEndTime(endDate);
+            addRecord.setVersion(2);
+            addRecord.setEndTime(addTime(addRecord.getStartTime(), period, addRecord.getTimes(),1));
+            formatVipRecordTime(addRecord);
+
+            addRecord.setEstimatedEndTime(addRecord.getEndTime());
+            addRecord.setEstimatedStartTime(addRecord.getStartTime());
             return addRecord;
         }
 
-        // 找到插入数据的位置
-        int index = 0;
         if (addVipType.equals(EVipType.VIP)) { // vip 放到最后
-            index = vipCardRecordList.size();
-            startTimeMills = vipCardRecordList.stream().map(VipCardRecord::getEndTime).max(Date::compareTo).get().getTime() + 1000L;
-        }
-        if (addVipType.equals(EVipType.SVIP)) { //放到VIP的前面
-            index = (int) vipCardRecordList.stream().filter(n -> EVipType.SVIP.equals(n.getVipType()) && !PeriodEnum.PERPETUAL.equals(n.getType())).count();
-            if (index > 0) {
-                startTimeMills = vipCardRecordList.stream().filter(n -> EVipType.SVIP.equals(n.getVipType()) && !PeriodEnum.PERPETUAL.equals(n.getType()))
-                        .map(VipCardRecord::getEndTime).max(Date::compareTo).get().getTime() + 1000;
+            startDate = vipCardRecordList.stream().map(VipCardRecord::getEndTime).max(Date::compareTo).get();
+        } else if (addVipType.equals(EVipType.SVIP)) { //放到VIP的前面
+            Optional<VipCardRecord> max = vipCardRecordList.stream().filter(o -> o.getVipType().equals(EVipType.SVIP)).max(Comparator.comparing(VipCardRecord::getEndTime));
+            if (max.isPresent()) {
+                startDate = max.get().getEndTime();
             }
         }
 
         VipCardRecord newRecord = JSON.parseObject(JSON.toJSONString(addVipCardRecord), VipCardRecord.class);
         newRecord.setSourceType(addVipCardRecord.getSourceType() !=null?addVipCardRecord.getSourceType():SourceTypeEnum.BACKEND_GIVE);
         newRecord.setStatus(EVipRecordStatus.ADD);
-        newRecord.setStartTime(new Date(startTimeMills));
-        if (index == 0) { // 当天剩余时间属于赠送
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTime(new Date(startTimeMills));
-            calendar.set(Calendar.HOUR_OF_DAY, 23);
-            calendar.set(Calendar.MINUTE, 59);
-            calendar.set(Calendar.SECOND, 59);
-            calendar.set(Calendar.MILLISECOND, 0);
-            Date endDate = plusDate(calendar.getTime(), addVipCardRecord.getType(), Long.valueOf(addVipCardRecord.getTimes()));
-            newRecord.setEndTime(new Date(endDate.getTime()));
-        } else {
-            Date endDate = plusDate(new Date(startTimeMills - 1000), addVipCardRecord.getType(), Long.valueOf(addVipCardRecord.getTimes()));
-            newRecord.setEndTime(endDate);
-        }
+        newRecord.setStartTime(startDate);
+        newRecord.setEndTime(addTime(newRecord.getStartTime(), addVipCardRecord.getType(), addVipCardRecord.getTimes(),1));
 
         newRecord.setDisplayFlag(true);
         newRecord.setEfficientFlag(true);
 
-        // 平移时间
-//        long plusMills = newRecord.getEndTime().getTime() - startTimeMills;
-        long beforeEndTime = newRecord.getEndTime().getTime();
-        for (int i = 0; i < vipCardRecordList.size(); i++) {
-            VipCardRecord vipCardRecord = vipCardRecordList.get(i);
-            if (i >= index) {
-                VipCardRecord addRecord = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class);
-                addRecord.setStatus(EVipRecordStatus.UPDATE);
-
-                addRecord.setStartTime(new Date(beforeEndTime + 1000));
-
-//                int days = (int) Math.ceil(plusMills * 1.0D / (24 * 60 * 60 * 1000));
-                Date endTime = plusDate(vipCardRecord.getEndTime(), addVipCardRecord.getType(), addVipCardRecord.getTimes());
-                addRecord.setEndTime(endTime);
-                addRecord.setDisplayFlag(false);
-                addRecord.setEfficientFlag(true);
-                save(addRecord);
-                Long refId = addRecord.getId();
+        // 如果是SVIP,平移VIP
+        List<VipCardRecord> vipList = vipCardRecordList.stream().filter(o -> o.getVipType() == EVipType.VIP).collect(Collectors.toList());
+        if (addVipType.equals(EVipType.SVIP) && CollectionUtils.isNotEmpty(vipList)) {
+            // 更新开始时间/结束时间
+            List<VipCardRecord> updateList = new ArrayList<>();
+            for (VipCardRecord vipCardRecord : vipList) {
+                formatVipRecordTime(vipCardRecord);
+
+                // 如果开始时间小于当前时间, 切分过去的时间为一段记录,并且不显示,剩余的时间为一段记录,标记为显示并且生效中
+                if (vipCardRecord.getStartTime().before(now)) {
+                    VipCardRecord record = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class);
+                    record.setStartTime(vipCardRecord.getStartTime());
+                    record.setEndTime(addTime(new Date(),PeriodEnum.DAY,-1,1));
+                    record.setEfficientFlag(true);
+                    record.setDeductionStatus(EDeductionStatus.EXPIRED);
+                    record.setDisplayFlag(false);
+                    record.setVersion(2);
+                    save(record);
+                    vipCardRecord.setStartTime(addTime(new Date(),PeriodEnum.DAY,0,0));
+                }
 
-                VipCardRecord updateRecord = JSON.parseObject(JSON.toJSONString(vipCardRecord), VipCardRecord.class);
-                updateRecord.setEfficientFlag(false);
-                updateRecord.setRefId(refId);
-                updateById(updateRecord);
-                beforeEndTime = endTime.getTime();
+                VipCardRecord record = new VipCardRecord();
+                record.setStartTime(addTime(vipCardRecord.getStartTime(), addVipCardRecord.getType(), addVipCardRecord.getTimes(),0));
+                record.setEndTime(addTime(vipCardRecord.getEndTime(), addVipCardRecord.getType(), addVipCardRecord.getTimes(),1));
+
+                record.setId(vipCardRecord.getId());
+                updateList.add(record);
             }
+            updateBatchById(updateList);
         }
+        newRecord.setDeductionStatus(EDeductionStatus.EFFECTIVE);
+        newRecord.setVersion(2);
+        formatVipRecordTime(newRecord);
+        newRecord.setEstimatedEndTime(newRecord.getEndTime());
+        newRecord.setEstimatedStartTime(newRecord.getStartTime());
         return newRecord;
     }
 
+    @NotNull
+    private List<VipCardRecord> getVipCardRecords(Long userId,ClientEnum client, List<EVipType> vipTypes) {
+        List<VipCardRecord> vipCardRecordList = this.lambdaQuery()
+                .eq(VipCardRecord::getClientType, client)
+                .eq(VipCardRecord::getUserId, userId)
+                .in(CollectionUtils.isNotEmpty(vipTypes),VipCardRecord::getVipType, vipTypes)
+                .ge(VipCardRecord::getEndTime, new Date())
+                .eq(VipCardRecord::getEfficientFlag, true)
+                .list()
+                .stream()
+                .sorted(Comparator.comparing(VipCardRecord::getStartTime))
+                .collect(Collectors.toList());
+        return vipCardRecordList;
+    }
+
     @Override
     public List<VipCardRecordWrapper.UserVipInfo> queryUserVipInfo(List<Long> userIdList, String clientType) {
         List<VipCardRecordWrapper.UserVipInfo> userVipInfos = baseMapper.queryUserVipInfo(userIdList, clientType);
@@ -603,19 +621,147 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
     }
 
 
+    /**
+     * 扣减会员
+     *
+     * @param result
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deduction(VipCardRecordWrapper.DeductionVipCardRecord result) {
+
+        // 查找被扣除的记录
+        VipCardRecord record = this.getById(result.getRecordId());
+        if (record == null) {
+            throw new BizException("记录不存在");
+        }
+        if (record.getDeductionTime() != null) {
+            throw new BizException("记录已扣除");
+        }
+        Date endTime = record.getEndTime();
+        if (endTime.before(new Date())) {
+            throw new BizException("记录已过期");
+        }
+
+        // 获取 剩余时长
+        int days =0;
+        if (record.getStartTime().before(new Date())) {
+            days = DateUtil.daysBetweenUp(new Date(), endTime);
+        } else {
+            days = DateUtil.daysBetweenUp(record.getStartTime(), endTime);
+        }
+        VipCardRecord vipCardRecord = new VipCardRecord();
+        vipCardRecord.setId(record.getId());
+        vipCardRecord.setDeductionTime(new Date());
+        vipCardRecord.setDeductionReason(result.getReason());
+        vipCardRecord.setEndTime(addTime(record.getEndTime(), PeriodEnum.DAY, -days,1));
+        vipCardRecord.setDeductionBy(result.getCreateBy());
+        vipCardRecord.setDeductionStatus(EDeductionStatus.DEDUCT);
+        if (record.getStartTime().after(record.getEndTime())) {
+            vipCardRecord.setEfficientFlag(false);
+        }
+        this.updateById(vipCardRecord);
+
+        // 对比剩余天数
+
+        // 获取其他有效的记录
+        List<VipCardRecord> list = this.lambdaQuery()
+                .eq(VipCardRecord::getUserId, record.getUserId())
+                .gt(VipCardRecord::getEndTime, endTime)
+                .eq(VipCardRecord::getEfficientFlag, 1)
+                .list();
+
+        if (CollectionUtils.isNotEmpty(list)) {
+            List<VipCardRecord> updateList = new ArrayList<>();
+            for (VipCardRecord vipCardRecord1 : list) {
+                VipCardRecord cardRecord = new VipCardRecord();
+                cardRecord.setId(vipCardRecord1.getId());
+                cardRecord.setStartTime(addTime(vipCardRecord1.getStartTime(), PeriodEnum.DAY, -days,0));
+                cardRecord.setEndTime(addTime(vipCardRecord1.getEndTime(), PeriodEnum.DAY, -days,1));
+                updateList.add(cardRecord);
+            }
+            this.updateBatchById(updateList);
+        }
+
+
+        if (Boolean.TRUE.equals(result.getSendMsg())) {
+            sendAddVipMsg(record.getUserId(),record.getClientType(),EVipRecordStatus.DEDUCTION,
+                    record.getVipType(),record.getType(),record.getTimes(),result.getReason());
+        }
+    }
+
+
+    /**
+     *
+     *  获取会员信息
+     *
+     */
+    @Override
+    public VipCardRecordWrapper.Info info(VipCardRecordWrapper.InfoQuery infoQuery) {
+        VipCardRecordWrapper.Info info = new VipCardRecordWrapper.Info();
+
+        // 所有的会员重新生成
+        List<VipCardRecord> vipCardRecordList = getVipCardRecords(infoQuery.getUserId(),infoQuery.getClient(), Lists.newArrayList(EVipType.VIP,EVipType.SVIP));
+        if (CollectionUtils.isEmpty(vipCardRecordList)) {
+            return info;
+        }
+        // 过滤出会员
+        List<VipCardRecord> vipList = vipCardRecordList.stream().filter(o -> o.getVipType() == EVipType.VIP).collect(Collectors.toList());
+        // 计算天数
+        int vipDays = 0;
+        if (CollectionUtils.isNotEmpty(vipList)) {
+            vipDays = vipList.stream().mapToInt(o -> DateUtil.daysBetweenUp(o.getStartTime(), o.getEndTime())).sum();
+        }
+        info.setSurplusVipDay(vipDays);
+        // 过滤出SVIP
+        List<VipCardRecord> svipList = vipCardRecordList.stream().filter(o -> o.getVipType() == EVipType.SVIP && o.getType() !=PeriodEnum.PERPETUAL).collect(Collectors.toList());
+        // 计算天数
+        int svipDays = 0;
+        if (CollectionUtils.isNotEmpty(svipList)) {
+            svipDays = svipList.stream().mapToInt(o -> DateUtil.daysBetweenUp(o.getStartTime(), o.getEndTime())).sum();
+        }
+        info.setSurplusSvipDay(svipDays);
+        // 过滤出永久SVIP
+        List<VipCardRecord> svipPerpetualList = vipCardRecordList.stream().filter(o -> o.getVipType() == EVipType.SVIP && o.getType() ==PeriodEnum.PERPETUAL).collect(Collectors.toList());
+        if (CollectionUtils.isNotEmpty(svipPerpetualList)) {
+            info.setPerpetualFlag(true);
+        }
+        return info;
+    }
+
+    @Override
+    public IPage<VipCardRecordWrapper.VipCardRecord> selectAdminPage(IPage<VipCardRecordWrapper.VipCardRecord> page, VipCardRecordWrapper.VipQuery query) {
+        IPage<VipCardRecordWrapper.VipCardRecord> vipCardRecordIPage = baseMapper.selectAdminPage(page, query);
+        List<VipCardRecordWrapper.VipCardRecord> records = vipCardRecordIPage.getRecords();
+        if (CollectionUtils.isEmpty(records)) {
+            return vipCardRecordIPage;
+        }
+        // 创建人ID集合
+        List<Long> createByList = records.stream()
+                .map(VipCardRecordWrapper.VipCardRecord::getOperatorId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
+        Map<Long, com.yonge.cooleshow.biz.dal.entity.SysUser> userMap = sysUserService.getMapByIds(createByList);
+        records.forEach(vipCardRecord -> {
+
+            if (vipCardRecord.getStartTime().before(new Date())) {
+                vipCardRecord.setSurplusDay(DateUtil.daysBetweenUp(new Date(), vipCardRecord.getEndTime()));
+            } else {
+                vipCardRecord.setSurplusDay(DateUtil.daysBetweenUp(vipCardRecord.getStartTime(), vipCardRecord.getEndTime()));
+            }
+
+            com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = userMap.get(vipCardRecord.getOperatorId());
+            if (sysUser != null) {
+                vipCardRecord.setOperatorName(sysUser.getRealName());
+            }
+        });
+        return vipCardRecordIPage;
+    }
+
+
     // 会员扣减
     private VipCardRecord deductVip(VipCardRecordWrapper.AddVipCardRecord addVipCardRecord) {
 
         // 所有的会员重新生成
-        List<VipCardRecord> vipCardRecordList = this.lambdaQuery()
-                .eq(VipCardRecord::getClientType, addVipCardRecord.getClientType())
-                .eq(VipCardRecord::getUserId, addVipCardRecord.getUserId())
-                .ge(VipCardRecord::getEndTime, new Date())
-                .eq(VipCardRecord::getEfficientFlag, true)
-                .list()
-                .stream()
-                .sorted(Comparator.comparing(VipCardRecord::getStartTime))
-                .collect(Collectors.toList());
+        List<VipCardRecord> vipCardRecordList = getVipCardRecords(addVipCardRecord.getUserId(),addVipCardRecord.getClientType(), Lists.newArrayList(EVipType.VIP,EVipType.SVIP));
 
         // 当前类型的VIP
         PeriodEnum period = addVipCardRecord.getType();
@@ -878,19 +1024,16 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
     }
 
     // 添加、扣除会员发送推送
-    private void sendAddVipMsg(VipCardRecordWrapper.AddVipCardRecord addVipCardRecord) {
-        SysUser sysUser = sysUserService.getByUserId(addVipCardRecord.getUserId());
+    private void sendAddVipMsg(Long userId,ClientEnum client,EVipRecordStatus status,EVipType vipType,PeriodEnum period,Integer times,String reason) {
+        SysUser sysUser = sysUserService.getByUserId(userId);
         if (sysUser == null) {
             return;
         }
         MessageTypeEnum messageTypeEnum;
-        EVipRecordStatus status = addVipCardRecord.getStatus();
-        EVipType vipType = addVipCardRecord.getVipType();
         if (EVipRecordStatus.ADD.equals(status)) {
             if (EVipType.VIP.equals(vipType)) {
                 messageTypeEnum = MessageTypeEnum.PLATFORM_ADD_VIP;
             }else {
-                PeriodEnum period = addVipCardRecord.getType();
                 if (PeriodEnum.PERPETUAL.equals(period)) {
                     messageTypeEnum = MessageTypeEnum.PLATFORM_ADD_PER_SVIP;
                 } else {
@@ -901,7 +1044,6 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
             if (EVipType.VIP.equals(vipType)) {
                 messageTypeEnum = MessageTypeEnum.PLATFORM_ADD_DUDECT_VIP;
             }else {
-                PeriodEnum period = addVipCardRecord.getType();
                 if (PeriodEnum.PERPETUAL.equals(period)) {
                     messageTypeEnum = MessageTypeEnum.PLATFORM_ADD_DUDECT_PER_SVIP;
                 } else {
@@ -913,17 +1055,49 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
         }
 
         Map<Long, String> receivers = new HashMap<>();
-        receivers.put(addVipCardRecord.getUserId(), sysUser.getPhone());
+        receivers.put(userId, sysUser.getPhone());
 
         try {
             sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, messageTypeEnum,
-                    receivers, null, 0, null, addVipCardRecord.getClientType().getCode(), String.valueOf(addVipCardRecord.getTimes()), addVipCardRecord.getType().getMsg(),
-                    addVipCardRecord.getReason());
+                    receivers, null, 0, null, client.getCode(), String.valueOf(times), period.getMsg(),
+                    reason);
         } catch (Exception e) {
             log.error("会员添加消息发送失败 : {}", e.getMessage());
         }
     }
 
+
+
+    private Date addTime(Date time, PeriodEnum period, Integer times, int type) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(time);
+
+        if (PeriodEnum.DAY.equals(period)) {
+            cal.add(Calendar.DAY_OF_MONTH, times);
+        } else if (PeriodEnum.MONTH.equals(period)) {
+            cal.add(Calendar.MONTH, times);
+        } else if (PeriodEnum.YEAR.equals(period)) {
+            cal.add(Calendar.YEAR, times);
+        } else if (PeriodEnum.QUARTERLY.equals(period)) {
+            cal.add(Calendar.MONTH, times * 3);
+        } else if (PeriodEnum.YEAR_HALF.equals(period)) {
+            cal.add(Calendar.MONTH, times * 6);
+        } else if (PeriodEnum.PERPETUAL.equals(period)) {
+            cal.add(Calendar.YEAR, 100);
+        }
+        if (type ==0) {
+            cal.set(Calendar.HOUR_OF_DAY, 0);
+            cal.set(Calendar.MINUTE, 0);
+            cal.set(Calendar.SECOND, 0);
+        } else {
+            cal.set(Calendar.HOUR_OF_DAY, 23);
+            cal.set(Calendar.MINUTE, 59);
+            cal.set(Calendar.SECOND, 59);
+            cal.set(Calendar.MILLISECOND, 0);
+        }
+        cal.set(Calendar.MILLISECOND, 0);
+        return cal.getTime();
+    }
     private Date formatEnd(Date date) {
         Calendar c1 = Calendar.getInstance();
         c1.setTime(date);
@@ -942,4 +1116,30 @@ public class VipCardRecordServiceImpl extends ServiceImpl<VipCardRecordDao, VipC
         c1.set(Calendar.MILLISECOND, 0);
         return c1.getTime();
     }
+
+
+
+    public VipCardRecord formatVipRecordTime(VipCardRecord vipCardRecord) {
+        // 如果开始时间是23:59:59,开始时间改为第二天的00:00:00
+        LocalDateTime startTime = vipCardRecord.getStartTime().toInstant()
+                .atZone(ZoneId.systemDefault()).toLocalDateTime();
+        if (startTime.toLocalTime().equals(LocalTime.of(23, 59, 59))) {
+            startTime = startTime.plusDays(1);
+        }
+
+        startTime = startTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
+        // 如果结束时间是00:00:00,开始时间改为前一天的23:59:59
+        LocalDateTime endTime = vipCardRecord.getEndTime().toInstant()
+                .atZone(ZoneId.systemDefault()).toLocalDateTime();
+        if (endTime.toLocalTime().equals(LocalTime.of(0, 0, 0))) {
+            endTime = endTime.plusDays(-1);
+        }
+        endTime = endTime.withHour(23).withMinute(59).withSecond(59).withNano(0);
+        vipCardRecord.setStartTime(Date.from(startTime.atZone(ZoneId.systemDefault()).toInstant()));
+        vipCardRecord.setEndTime(Date.from(endTime.atZone(ZoneId.systemDefault()).toInstant()));
+        if (vipCardRecord.getStartTime().after(vipCardRecord.getEndTime())) {
+            vipCardRecord.setEndTime(vipCardRecord.getStartTime());
+        }
+        return vipCardRecord;
+    }
 }

+ 10 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/DiscountCardRecordWrapper.java

@@ -195,6 +195,12 @@ public class DiscountCardRecordWrapper {
         @ApiModelProperty("购买人员类型 TEACHRE :老师端 STUDNET : 学生端")
         private ClientEnum clientType;
 
+        @ApiModelProperty("会员卡开始时间")
+        private Date startTime;
+
+        @ApiModelProperty("会员卡结束时间")
+        private Date endTime;
+
 
         @ApiModelProperty("创建时间")
         private Date createTime;
@@ -224,6 +230,10 @@ public class DiscountCardRecordWrapper {
         private Date deductionTime;
 
 
+        @ApiModelProperty("剩余天数")
+        private Integer surplusDay = 0;
+
+
     }
 
     @Data

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/UserTenantAlbumRecordWrapper.java

@@ -218,6 +218,9 @@ public class UserTenantAlbumRecordWrapper {
         private String reason;
 
 
+        @ApiModelProperty("剩余天数")
+        private Integer surplusDay = 0;
+
         @ApiModelProperty("扣减状态")
         private EDeductionStatus deductionStatus;
 

+ 152 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/VipCardRecordWrapper.java

@@ -1,6 +1,7 @@
 package com.yonge.cooleshow.biz.dal.wrapper;
 
 import com.baomidou.mybatisplus.annotation.TableField;
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
 import com.yonge.cooleshow.biz.dal.enums.*;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -59,7 +60,7 @@ public class VipCardRecordWrapper {
         @NotNull(message = "用户类型不能为空")
         private ClientEnum clientType;
 
-        @ApiModelProperty("状态 ADD:新增,DEDUCTION:扣减,UPDATE:变更")
+        @ApiModelProperty("状态 ADD:新增")
         @NotNull
         private EVipRecordStatus status;
 
@@ -136,4 +137,154 @@ public class VipCardRecordWrapper {
             }
         }
     }
+
+    @Data
+    public static class DeductionVipCardRecord {
+
+        @ApiModelProperty("用户id")
+        @NotNull(message = "用户id不能为空")
+        private Long userId;
+
+        @ApiModelProperty("人员类型 TEACHRE :老师端 STUDNET : 学生端")
+        @NotNull(message = "人员类型不能为空")
+        private ClientEnum clientType;
+
+        @ApiModelProperty("操作人ID")
+        private Long createBy;
+
+        @ApiModelProperty("记录ID")
+        @NotNull(message = "记录ID不能为空")
+        private Long recordId;
+
+        @ApiModelProperty("备注")
+        private String reason;
+
+        @ApiModelProperty("是否发送推送,1:是,0:否")
+        private Boolean sendMsg;
+    }
+
+
+
+    @Data
+    public static class InfoQuery {
+
+        @ApiModelProperty("用户ID")
+        private Long userId;
+
+        @ApiModelProperty("类型")
+        private ClientEnum client;
+    }
+
+    @Data
+    public static class Info {
+
+        @ApiModelProperty("剩余vip天数")
+        private Integer surplusVipDay = 0;
+
+        @ApiModelProperty("剩余svip天数")
+        private Integer surplusSvipDay = 0;
+
+        @ApiModelProperty("是否永久")
+        private Boolean perpetualFlag = false;
+
+    }
+
+    @Data
+    public static class VipQuery  implements QueryInfo {
+
+        @ApiModelProperty("当前页")
+        private Integer page;
+
+        @ApiModelProperty("分页行数")
+        private Integer rows;
+
+        @ApiModelProperty("关键字匹配")
+        private String keyword;
+
+        @ApiModelProperty("用户Id")
+        private Long userId;
+
+
+        @ApiModelProperty("用户类型 学生:STUDENT 老师 :TEACHER")
+        private ClientEnum clientType;
+
+        @ApiModelProperty("开始时间")
+        private Date startTime;
+
+        @ApiModelProperty("结束时间")
+        private Date endTime;
+
+        @ApiModelProperty("会员类型 VIP,SVIP")
+        private EVipType vipType;
+
+        @ApiModelProperty("ORDER:激活码激活,TENANT:自行购买,BACKEND_GIVE:后台添加")
+        private SourceTypeEnum sourceType;
+
+        @ApiModelProperty("扣减状态 生效中:EFFECTIVE 过期 EXPIRED 扣减 DEDUCT")
+        private EDeductionStatus deductionStatus;
+
+        @ApiModelProperty("扣减开始时间")
+        private Date deductionStartTime;
+
+
+        @ApiModelProperty("扣减结束时间")
+        private Date deductionEndTime;
+    }
+
+    @Data
+    public static class VipCardRecord {
+
+        @ApiModelProperty("记录id")
+        private String id;
+
+        @ApiModelProperty("用户id")
+        private Long userId;
+
+
+        @ApiModelProperty("订单号")
+        private String orderNo;
+
+        @ApiModelProperty("ORDER:订单")
+        private SourceTypeEnum sourceType;
+
+        @ApiModelProperty("购买人员类型 TEACHRE :老师端 STUDNET : 学生端")
+        private ClientEnum clientType;
+
+
+        @ApiModelProperty("开始时间")
+        private Date startTime;
+
+        @ApiModelProperty("结束时间")
+        private Date endTime;
+
+        @ApiModelProperty("创建时间")
+        private Date createTime;
+
+        @ApiModelProperty("操作人")
+        private Long operatorId;
+
+        @ApiModelProperty("操作人")
+        private String operatorName;
+
+
+        @ApiModelProperty("时间类型 DAY:天 MONTH:月,YEAR:年")
+        private PeriodEnum type;
+
+        @ApiModelProperty("添加时间数量")
+        private Integer times;
+
+        @ApiModelProperty("备注")
+        private String reason;
+
+
+        @ApiModelProperty("剩余天数")
+        private Integer surplusDay = 0;
+
+        @ApiModelProperty("扣减状态")
+        private EDeductionStatus deductionStatus;
+
+        @ApiModelProperty("扣减时间")
+        private Date deductionTime;
+
+    }
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/DiscountCardRecordMapper.xml

@@ -60,6 +60,8 @@
                t.create_time_,
                 if(t.deduction_by_ is not null, t.deduction_by_, t.create_by_) as operatorId,
                t.type_,
+                t.start_time_,
+        t.end_time_,
                t.times_,
                 if(t.deduction_reason_ is not null, t.deduction_reason_, t.reason_) as reason,
                t.deduction_time_,

+ 64 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/VipCardRecordMapper.xml

@@ -185,4 +185,68 @@
         left join vip_card_record vcr on m.userId = vcr.user_id_ and vcr.end_time_ > now() and now() >= vcr.start_time_ and efficient_flag_ = 1 and vcr.client_type_ = #{clientType}
         order by vcr.end_time_ desc
     </select>
+
+	<select id="selectAdminPage"
+            resultType="com.yonge.cooleshow.biz.dal.wrapper.VipCardRecordWrapper$VipCardRecord">
+        select t.id_,
+        t.user_id_,
+        t.order_no_,
+        t.source_type_,
+        t.client_type_,
+        t.create_time_,
+        if(t.deduction_by_ is not null, t.deduction_by_, t.create_by_) as operatorId,
+        t.type_,
+        t.start_time_,
+        t.end_time_,
+        t.times_,
+        if(t.deduction_reason_ is not null, t.deduction_reason_, t.reason_) as reason,
+        t.deduction_time_,
+        t.deduction_status_
+        from vip_card_record t
+
+        <if test="param.keyword != null and param.keyword != ''">
+            left join sys_user t1
+            on if(t.deduction_by_ is not null, t.deduction_by_, t.create_by_) = t1.id_
+        </if>
+        <where>
+            t.display_flag_ = 1
+            <if test="param.userId != null">
+                and t.user_id_ = #{param.userId}
+            </if>
+            <if test="param.clientType != null">
+                and t.client_type_ = #{param.clientType}
+            </if>
+            <if test="param.sourceType != null">
+                and t.source_type_ = #{param.sourceType}
+            </if>
+            <if test="param.vipType != null">
+                and t.vip_type_ = #{param.vipType}
+            </if>
+            <if test="param.deductionStatus != null">
+                and t.deduction_status_ = #{param.deductionStatus}
+            </if>
+            <if test="param.keyword != null and param.keyword != ''">
+                and (t1.username_ like CONCAT('%', #{param.keyword}, '%')
+                or
+                if(t.source_type_ = 'ORDER' and t.order_no_ is not null, t.order_no_, '') like
+                CONCAT('%', #{param.keyword}, '%')
+                or if(t.deduction_reason_ is not null, t.deduction_reason_, t.reason_) like
+                CONCAT('%', #{param.keyword}, '%')
+                )
+            </if>
+            <if test="param.startTime != null">
+                and t.create_time_ &gt;= #{param.startTime}
+            </if>
+            <if test="param.endTime != null">
+                and t.create_time_ &lt;= #{param.endTime}
+            </if>
+            <if test="param.deductionStartTime != null">
+                and t.deduction_time_ &gt;= #{param.deductionStartTime}
+            </if>
+            <if test="param.deductionEndTime != null">
+                and t.deduction_time_ &lt;= #{param.deductionEndTime}
+            </if>
+        </where>
+        order by t.id_ desc
+    </select>
 </mapper>