Authored by LUOXC

refactor

... ... @@ -56,6 +56,7 @@ public class InviteSettlementItemCreator {
request.setOrderAmount(buyerOrder.getAmount());
request.setOrderCreateTime(buyerOrder.getCreateTime());
request.setSellerOrderPayment(sellerOrder.getPayment());
createInviteSettlementItem(request);
}
}
... ... @@ -76,7 +77,7 @@ public class InviteSettlementItemCreator {
return;
}
int inviterUid = invitee.getInviterUid();
int inviteTime = invitee.getCreateTime();
int orderCreateTime = request.getOrderCreateTime();
Inviter inviter = inviterMapper.selectByPrimaryKey(invitee.getInviterId());
if (Objects.isNull(inviter)) {
... ... @@ -87,25 +88,20 @@ public class InviteSettlementItemCreator {
log.info("{} end, item is exist", tag);
return;
}
int inviterType = inviter.getType();
// 入驻商家
if (inviterType == INVITER_TYPE_STORED_SELLER) {
InviteActivity activity = inviteActivityMapper.selectByPrimaryKey(invitee.getInviteActivityId());
if (Objects.isNull(activity)) {
log.warn("{} fail, can not find inviter ", tag);
return;
}
// 验证是否过了奖励时间
int days = activity.getRewardDays();
if (inviteTime + days < orderCreateTime) {
log.warn("{} fail, reward end", tag);
return;
}
if (!checkWithInviteActivity(tag, invitee, orderCreateTime, inviter)){
return;
}
log.info("{}, start create", tag);
InviteSettlementItem inviteSettlementItem = buildInviteSettlementItem(request, invitee, inviter);
inviteSettlementItemMapper.insert(inviteSettlementItem);
log.info("{} success", tag);
}
// 可以创建了
private InviteSettlementItem buildInviteSettlementItem(InviteSettlementItemCreateRequest request, InviteRecord invitee, Inviter inviter) {
InviteSettlementItem inviteSettlementItem = new InviteSettlementItem();
inviteSettlementItem.setUid(inviter.getUid());
... ... @@ -130,7 +126,7 @@ public class InviteSettlementItemCreator {
else {
inviteSettlementItem.setType(1);
}
// 待结算订单状态
// 受邀人无效
if (invitee.getStatus() == InviteRecord.STATUS_DISABLE) {
... ... @@ -146,11 +142,27 @@ public class InviteSettlementItemCreator {
}
inviteSettlementItem.setCreateTime(DateUtil.getCurrentTimeSecond());
return inviteSettlementItem;
}
inviteSettlementItemMapper.insert(inviteSettlementItem);
log.info("{} success", tag);
private boolean checkWithInviteActivity(String tag, InviteRecord invitee, int orderCreateTime, Inviter inviter) {
int inviterType = inviter.getType();
int inviteTime = invitee.getCreateTime();
// 入驻商家
if (inviterType == INVITER_TYPE_STORED_SELLER) {
InviteActivity activity = inviteActivityMapper.selectByPrimaryKey(invitee.getInviteActivityId());
if (Objects.isNull(activity)) {
log.warn("{} fail, can not find inviter ", tag);
return false;
}
// 验证是否过了奖励时间
int days = activity.getRewardDays();
if (inviteTime + days < orderCreateTime) {
log.warn("{} fail, reward end", tag);
return false;
}
}
return true;
}
... ...