|
|
|
@ -4,6 +4,8 @@ import cn.hutool.core.util.StrUtil; |
|
|
|
import com.qniao.dam.api.command.ccur.user.response.UserUseContactCardVo; |
|
|
|
import com.qniao.dam.application.service.right.RightApplicationService; |
|
|
|
import com.qniao.dam.domain.aggregate.ccur.vobj.ContactCardUsageRecord; |
|
|
|
import com.qniao.dam.domain.aggregate.mica.MarriageInformationContactApplyAggregate; |
|
|
|
import com.qniao.dam.domain.aggregate.mica.entity.MarriageInformationContactApply; |
|
|
|
import com.qniao.dam.domain.aggregate.pcur.vobj.ProfileCardUsageRecord; |
|
|
|
import com.qniao.dam.domian.aggregate.pcur.constant.CardUsageTyepEnum; |
|
|
|
import com.qniao.dam.domian.aggregate.right.constant.RightTypeEnum; |
|
|
|
@ -12,7 +14,9 @@ import com.qniao.dam.infrastructure.persistent.dao.pcur.ProfileCardUsageRecordDa |
|
|
|
import com.qniao.dam.query.ccur.ContactCardUsageRecordQueryService; |
|
|
|
import com.qniao.dam.query.marriageinformation.MarriageInformationQueryService; |
|
|
|
import com.qniao.dam.query.mica.MarriageInformationContactApplyQueryService; |
|
|
|
import com.qniao.dam.query.usermarriageinformation.UserMarriageInformationQueryService; |
|
|
|
import com.qniao.das.domian.aggregate.marriageinformation.MarriageInformation; |
|
|
|
import com.qniao.das.domian.aggregate.marriageinformation.UserMarriageInformation; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
@ -30,31 +34,35 @@ public class ContactCardUsageRecordApplicationService { |
|
|
|
private ContactCardUsageRecordDao contactCardUsageRecordDao; |
|
|
|
@Resource |
|
|
|
private RightApplicationService rightApplicationService; |
|
|
|
@Resource |
|
|
|
private UserMarriageInformationQueryService userMarriageInformationQueryService; |
|
|
|
@Resource |
|
|
|
private MarriageInformationContactApplyAggregate marriageInformationContactApplyAggregate; |
|
|
|
|
|
|
|
public UserUseContactCardVo use(ContactCardUsageRecord usageRecord) { |
|
|
|
UserUseContactCardVo vo = new UserUseContactCardVo(); |
|
|
|
//是否申请中 |
|
|
|
if (marriageInformationContactApplyQueryService.checkApplying(usageRecord.getUserId(), usageRecord.getTargetMiId())){ |
|
|
|
//申请过了 |
|
|
|
vo.setSuccess(true); |
|
|
|
}else { |
|
|
|
MarriageInformation marriageInformation = marriageInformationQueryService.queryByUserId(usageRecord.getUserId()); |
|
|
|
vo.setRealNameAuthenticated(StrUtil.isNotBlank(marriageInformation.getIdentityCard())); |
|
|
|
if (!vo.getRealNameAuthenticated()) { |
|
|
|
//已经认证 |
|
|
|
int usageFreeCount = contactCardUsageRecordQueryService.countUsageRecord(usageRecord.getUserId(), CardUsageTyepEnum.FREE); |
|
|
|
if (usageFreeCount < 10) { |
|
|
|
ContactCardUsageRecord record = ContactCardUsageRecord.build(usageRecord.getUserId(), usageRecord.getTargetMiId(), CardUsageTyepEnum.FREE); |
|
|
|
contactCardUsageRecordDao.insert(record); |
|
|
|
vo.setSuccess(true); |
|
|
|
} else { |
|
|
|
//免费使用完后,看看有没有联系卡使用 |
|
|
|
if (rightApplicationService.consumeRight(usageRecord.getUserId(), marriageInformation.getId(), RightTypeEnum.CONTACT_CARD, null)) { |
|
|
|
ContactCardUsageRecord record = ContactCardUsageRecord.build(usageRecord.getUserId(), usageRecord.getTargetMiId(), CardUsageTyepEnum.CARD); |
|
|
|
contactCardUsageRecordDao.insert(record); |
|
|
|
synchronized (usageRecord.getUserId().toString().intern()) { |
|
|
|
//是否申请中 |
|
|
|
if (marriageInformationContactApplyQueryService.checkApplying(usageRecord.getUserId(), usageRecord.getTargetMiId())) { |
|
|
|
//申请过了 |
|
|
|
vo.setSuccess(true); |
|
|
|
} else { |
|
|
|
MarriageInformation marriageInformation = marriageInformationQueryService.queryByUserId(usageRecord.getUserId()); |
|
|
|
vo.setRealNameAuthenticated(StrUtil.isNotBlank(marriageInformation.getIdentityCard())); |
|
|
|
if (!vo.getRealNameAuthenticated()) { |
|
|
|
//已经认证 |
|
|
|
int usageFreeCount = contactCardUsageRecordQueryService.countUsageRecord(usageRecord.getUserId(), CardUsageTyepEnum.FREE); |
|
|
|
if (usageFreeCount < 10) { |
|
|
|
applyContact(usageRecord, marriageInformation); |
|
|
|
vo.setSuccess(true); |
|
|
|
} else { |
|
|
|
vo.setSuccess(false); |
|
|
|
//免费使用完后,看看有没有联系卡使用 |
|
|
|
if (rightApplicationService.consumeRight(usageRecord.getUserId(), marriageInformation.getId(), RightTypeEnum.CONTACT_CARD, null)) { |
|
|
|
applyContact(usageRecord, marriageInformation); |
|
|
|
vo.setSuccess(true); |
|
|
|
} else { |
|
|
|
vo.setSuccess(false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -62,4 +70,17 @@ public class ContactCardUsageRecordApplicationService { |
|
|
|
return vo; |
|
|
|
} |
|
|
|
|
|
|
|
private void applyContact(ContactCardUsageRecord usageRecord, |
|
|
|
MarriageInformation applicantMarriageInformation) { |
|
|
|
ContactCardUsageRecord record = ContactCardUsageRecord.build(usageRecord.getUserId(), usageRecord.getTargetMiId(), CardUsageTyepEnum.FREE); |
|
|
|
contactCardUsageRecordDao.insert(record); |
|
|
|
MarriageInformationContactApply apply = new MarriageInformationContactApply(); |
|
|
|
apply.setApplicantUserId(usageRecord.getUserId()); |
|
|
|
apply.setApplicantMiId(applicantMarriageInformation.getId()); |
|
|
|
apply.setTargetMiId(usageRecord.getTargetMiId()); |
|
|
|
UserMarriageInformation targetUserMarriageInformation = userMarriageInformationQueryService.queryOwnByMiId(usageRecord.getTargetMiId()); |
|
|
|
apply.setTargetUserId(targetUserMarriageInformation.getUserId()); |
|
|
|
marriageInformationContactApplyAggregate.create(apply); |
|
|
|
} |
|
|
|
|
|
|
|
} |