|
@@ -219,6 +219,61 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void activeById(String id, Long userId) {
|
|
|
+ Student student = studentDao.selectById(userId);
|
|
|
+ if (student == null) {
|
|
|
+ throw new BizException("学生不存在");
|
|
|
+ }
|
|
|
+ Long tenantId = -1L;
|
|
|
+ if (student.getTenantId() != null) {
|
|
|
+ tenantId = student.getTenantId();
|
|
|
+ }
|
|
|
+ TenantActivationCode code = baseMapper.selectById(id);
|
|
|
+ if(code == null || !code.getTenantId().equals(tenantId)) {
|
|
|
+ throw new BizException("激活码不存在");
|
|
|
+ }
|
|
|
+ SysUser sysUser = sysUserMapper.selectById(student.getUserId());
|
|
|
+ if(!sysUser.getPhone().equals(code.getActivationPhone())) {
|
|
|
+ // 该激活码未指定为当前学生使用
|
|
|
+ throw new BizException("激活码不存在");
|
|
|
+ }
|
|
|
+ if (Boolean.TRUE.equals(code.getActivationStatus())) {
|
|
|
+ throw new BizException("激活码已经被使用");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通过状态和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();
|
|
|
+ if (!update) {
|
|
|
+ throw new BizException("激活码已经被使用");
|
|
|
+ }
|
|
|
+ Long tenantAlbumPurchaseId = code.getTenantAlbumPurchaseId();
|
|
|
+ TenantAlbumPurchase purchase = tenantAlbumPurchaseMapper.selectById(tenantAlbumPurchaseId);
|
|
|
+
|
|
|
+ addUserTenantAlbumRecord(student.getUserId(), purchase, null);
|
|
|
+
|
|
|
+ // 更新购买记录中激活码使用统计数量值
|
|
|
+ Integer activeCodeNumber = this.lambdaQuery()
|
|
|
+ .eq(TenantActivationCode::getTenantId, tenantId)
|
|
|
+ .eq(TenantActivationCode::getTenantAlbumPurchaseId, code.getTenantAlbumPurchaseId())
|
|
|
+ .eq(TenantActivationCode::getActivationStatus, true).count();
|
|
|
+
|
|
|
+ TenantAlbumPurchase tenantAlbumPurchase = new TenantAlbumPurchase();
|
|
|
+ tenantAlbumPurchase.setId(code.getTenantAlbumPurchaseId());
|
|
|
+ tenantAlbumPurchase.setActiveQuantity(activeCodeNumber);
|
|
|
+ tenantAlbumPurchaseMapper.updateById(tenantAlbumPurchase);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 添加用户机构专辑激活记录
|
|
|
*
|