浏览代码

1.激活码激活更新用户专辑有效时长

yuanliang 1 年之前
父节点
当前提交
d72a011a80

+ 54 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantActivationCodeServiceImpl.java

@@ -9,20 +9,23 @@ import com.yonge.cooleshow.biz.dal.entity.Student;
 import com.yonge.cooleshow.biz.dal.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.entity.TenantActivationCode;
 import com.yonge.cooleshow.biz.dal.entity.TenantAlbumPurchase;
+import com.yonge.cooleshow.biz.dal.entity.UserTenantAlbumRecord;
+import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
+import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
 import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantActivationCodeMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumPurchaseMapper;
+import com.yonge.cooleshow.biz.dal.mapper.UserTenantAlbumRecordMapper;
 import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantActivationCodeWrapper;
 import com.yonge.toolset.base.exception.BizException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
-import org.redisson.api.RLock;
-import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -45,6 +48,9 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
     @Autowired
     private TenantAlbumPurchaseMapper tenantAlbumPurchaseMapper;
 
+    @Autowired
+    private UserTenantAlbumRecordMapper userTenantAlbumRecordMapper;
+
     /**
      * 查询详情
      *
@@ -165,11 +171,13 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
             throw new BizException("激活码已经被使用");
         }
 
+        SysUser sysUser = sysUserMapper.selectById(studentId);
         // 通过状态和ID同时判断更新是否存在竞争
         boolean update = this.lambdaUpdate()
                 .set(TenantActivationCode::getActivationStatus, true)
                 .set(TenantActivationCode::getActivationUserId, student.getUserId())
                 .set(TenantActivationCode::getActivationTime, new Date())
+                .set(TenantActivationCode::getActivationPhone, sysUser.getPhone())
                 .eq(TenantActivationCode::getId, code.getId())
                 .eq(TenantActivationCode::getActivationStatus, false)
                 .update();
@@ -177,7 +185,50 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
             throw new BizException("激活码已经被使用");
         }
 
-        // todo 更新会员信息,如果更新异常,回滚激活码
+        QueryWrapper<UserTenantAlbumRecord> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .eq(UserTenantAlbumRecord::getTenantId, student.getTenantId())
+                .eq(UserTenantAlbumRecord::getUserId, student.getUserId())
+                .eq(UserTenantAlbumRecord::getTenantAlbumId, code.getTenantAlbumId())
+                .eq(UserTenantAlbumRecord::getClientType, ClientEnum.STUDENT)
+                .orderByDesc(UserTenantAlbumRecord::getEndTime);
+        List<UserTenantAlbumRecord> userTenantAlbumRecords = userTenantAlbumRecordMapper.selectList(queryWrapper);
+
+        UserTenantAlbumRecord userTenantAlbumRecord = new UserTenantAlbumRecord();
+        userTenantAlbumRecord.setTenantId(student.getTenantId());
+        userTenantAlbumRecord.setUserId(student.getUserId());
+        userTenantAlbumRecord.setTenantAlbumId(code.getTenantAlbumId());
+        userTenantAlbumRecord.setOrderNo("");
+        userTenantAlbumRecord.setSourceType(SourceTypeEnum.TENANT);
+        userTenantAlbumRecord.setClientType(ClientEnum.STUDENT);
+        userTenantAlbumRecord.setSubOrderNo("");
+        userTenantAlbumRecord.setCreateBy(student.getUserId());
+
+        Long tenantAlbumPurchaseId = code.getTenantAlbumPurchaseId();
+        TenantAlbumPurchase purchase = tenantAlbumPurchaseMapper.selectById(tenantAlbumPurchaseId);
+        Integer purchaseCycle = purchase.getPurchaseCycle();
+
+        userTenantAlbumRecord.setType("MONTH");
+        userTenantAlbumRecord.setTimes(purchaseCycle);
+
+        Calendar instance = Calendar.getInstance();
+        if (userTenantAlbumRecords.isEmpty()) {
+            instance.setTime(new Date());
+        } else {
+            // 如果最后一次的时间的小于当前时间,则以当前时间为会员的开始时间
+            // 如果最后一次的时间的大于当前时间,则以最后一次的结束时间为记录的开始时间,相当会员续期
+            UserTenantAlbumRecord lastRecord = userTenantAlbumRecords.get(0);
+            Date lastEndTime = lastRecord.getEndTime();
+            if (lastEndTime.before(new Date())) {
+                instance.setTime(new Date());
+            } else {
+                instance.setTime(lastEndTime);
+            }
+        }
+        userTenantAlbumRecord.setStartTime(instance.getTime());
+        instance.add(Calendar.MONTH, purchaseCycle);
+        userTenantAlbumRecord.setEndTime(instance.getTime());
+        userTenantAlbumRecordMapper.insert(userTenantAlbumRecord);
 
         // 更新购买记录中激活码使用统计数量值
         Integer activeCodeNumber = this.lambdaQuery()

+ 1 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantActivationCodeMapper.xml

@@ -22,7 +22,7 @@
         SELECT
         <include refid="baseColumns"/>, ta.purchase_cycle_ as purchaseCycle, su.username_ as activationUserName
         FROM tenant_activation_code t
-        LEFT JOIN tenant_album_purchase ta on t.tenant_album_id_ = ta.id_
+        LEFT JOIN tenant_album_purchase ta on t.tenant_album_purchase_id_ = ta.id_
         LEFT JOIN sys_user su on t.activation_user_id_ = su.id_
         <where>
             <if test="param.keyword != null and param.keyword.trim() != ''">