|
|
|
@ -11,9 +11,11 @@ import com.hfkj.dao.BsUserSpreadAccountMapper; |
|
|
|
|
import com.hfkj.entity.*; |
|
|
|
|
import com.hfkj.service.spread.BsUserSpreadAccountRecordService; |
|
|
|
|
import com.hfkj.service.spread.BsUserSpreadAccountService; |
|
|
|
|
import com.hfkj.service.spread.BsUserSpreadPowerService; |
|
|
|
|
import com.hfkj.service.user.BsUserService; |
|
|
|
|
import com.hfkj.sysenum.merchant.MerchantAccountRecordTypeEnum; |
|
|
|
|
import com.hfkj.sysenum.spread.UserSpreadAccountRecordSourceTypeEnum; |
|
|
|
|
import com.hfkj.sysenum.spread.UserSpreadAccountStatusEnum; |
|
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
@ -43,6 +45,8 @@ public class BsUserSpreadAccountServiceImpl implements BsUserSpreadAccountServic |
|
|
|
|
@Resource |
|
|
|
|
private BsUserSpreadAccountRecordService userSpreadAccountRecordService; |
|
|
|
|
@Resource |
|
|
|
|
private BsUserSpreadPowerService userSpreadPowerService; |
|
|
|
|
@Resource |
|
|
|
|
private RedisTemplate<String, Object> redisTemplate; |
|
|
|
|
private static final String LOCK_KEY = "USER_SPREAD_ACCOUNT_LOCK_"; |
|
|
|
|
@Override |
|
|
|
@ -63,10 +67,44 @@ public class BsUserSpreadAccountServiceImpl implements BsUserSpreadAccountServic |
|
|
|
|
userSpreadAccountMapper.updateByPrimaryKey(data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void freezeUserSpread(Long userId) { |
|
|
|
|
// 查询账户
|
|
|
|
|
BsUserSpreadAccount account = getDetailByUser(userId); |
|
|
|
|
if (account == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到账户"); |
|
|
|
|
} |
|
|
|
|
account.setStatus(UserSpreadAccountStatusEnum.status2.getType()); |
|
|
|
|
update(account); |
|
|
|
|
// 推广权限
|
|
|
|
|
BsUserSpreadPower userSpreadPower = userSpreadPowerService.getDetailByUser(account.getUserId()); |
|
|
|
|
if (userSpreadPower != null) { |
|
|
|
|
userSpreadPower.setStatus(UserSpreadAccountStatusEnum.status2.getType()); |
|
|
|
|
userSpreadPowerService.editData(userSpreadPower); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void unfreezeUserSpread(Long userId) { |
|
|
|
|
// 查询账户
|
|
|
|
|
BsUserSpreadAccount account = getDetailByUser(userId); |
|
|
|
|
if (account == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到账户"); |
|
|
|
|
} |
|
|
|
|
account.setStatus(UserSpreadAccountStatusEnum.status1.getType()); |
|
|
|
|
update(account); |
|
|
|
|
// 推广权限
|
|
|
|
|
BsUserSpreadPower userSpreadPower = userSpreadPowerService.getDetailByUser(account.getUserId()); |
|
|
|
|
if (userSpreadPower != null) { |
|
|
|
|
userSpreadPower.setStatus(UserSpreadAccountStatusEnum.status1.getType()); |
|
|
|
|
userSpreadPowerService.editData(userSpreadPower); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public BsUserSpreadAccount getDetailByUser(Long userId) { |
|
|
|
|
BsUserSpreadAccountExample example = new BsUserSpreadAccountExample(); |
|
|
|
|
example.createCriteria().andUserIdEqualTo(userId).andStatusNotEqualTo(0); |
|
|
|
|
example.createCriteria().andUserIdEqualTo(userId).andStatusNotEqualTo(UserSpreadAccountStatusEnum.status0.getType()); |
|
|
|
|
List<BsUserSpreadAccount> list = userSpreadAccountMapper.selectByExample(example); |
|
|
|
|
if (!list.isEmpty()){ |
|
|
|
|
return list.get(0); |
|
|
|
@ -93,6 +131,9 @@ public class BsUserSpreadAccountServiceImpl implements BsUserSpreadAccountServic |
|
|
|
|
if (userSpreadAccount == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到账户"); |
|
|
|
|
} |
|
|
|
|
if (!userSpreadAccount.getStatus().equals(UserSpreadAccountStatusEnum.status1.getType())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "账户已被冻结"); |
|
|
|
|
} |
|
|
|
|
if (userSpreadAccount.getAmount().compareTo(amount) < 0) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "余额不足"); |
|
|
|
|
} |
|
|
|
@ -145,6 +186,9 @@ public class BsUserSpreadAccountServiceImpl implements BsUserSpreadAccountServic |
|
|
|
|
if (account == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知账户"); |
|
|
|
|
} |
|
|
|
|
if (!account.getStatus().equals(UserSpreadAccountStatusEnum.status1.getType())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "账户不可用"); |
|
|
|
|
} |
|
|
|
|
// 变更前金额
|
|
|
|
|
BigDecimal beforeAmount = account.getAmount(); |
|
|
|
|
// 计算金额
|
|
|
|
@ -205,6 +249,9 @@ public class BsUserSpreadAccountServiceImpl implements BsUserSpreadAccountServic |
|
|
|
|
if (account == null) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "未知账户"); |
|
|
|
|
} |
|
|
|
|
if (!account.getStatus().equals(UserSpreadAccountStatusEnum.status1.getType())) { |
|
|
|
|
throw ErrorHelp.genException(SysCode.OpenApi, ErrorCode.OPEN_API_COMMON, "账户不可用"); |
|
|
|
|
} |
|
|
|
|
// 变更前金额
|
|
|
|
|
BigDecimal beforeAmount = account.getAmount(); |
|
|
|
|
// 计算金额
|
|
|
|
|