Authored by LUOXC

refactor

@@ -56,6 +56,7 @@ public class InviteSettlementItemCreator { @@ -56,6 +56,7 @@ public class InviteSettlementItemCreator {
56 request.setOrderAmount(buyerOrder.getAmount()); 56 request.setOrderAmount(buyerOrder.getAmount());
57 request.setOrderCreateTime(buyerOrder.getCreateTime()); 57 request.setOrderCreateTime(buyerOrder.getCreateTime());
58 request.setSellerOrderPayment(sellerOrder.getPayment()); 58 request.setSellerOrderPayment(sellerOrder.getPayment());
  59 +
59 createInviteSettlementItem(request); 60 createInviteSettlementItem(request);
60 } 61 }
61 } 62 }
@@ -76,7 +77,7 @@ public class InviteSettlementItemCreator { @@ -76,7 +77,7 @@ public class InviteSettlementItemCreator {
76 return; 77 return;
77 } 78 }
78 int inviterUid = invitee.getInviterUid(); 79 int inviterUid = invitee.getInviterUid();
79 - int inviteTime = invitee.getCreateTime(); 80 +
80 int orderCreateTime = request.getOrderCreateTime(); 81 int orderCreateTime = request.getOrderCreateTime();
81 Inviter inviter = inviterMapper.selectByPrimaryKey(invitee.getInviterId()); 82 Inviter inviter = inviterMapper.selectByPrimaryKey(invitee.getInviterId());
82 if (Objects.isNull(inviter)) { 83 if (Objects.isNull(inviter)) {
@@ -87,25 +88,20 @@ public class InviteSettlementItemCreator { @@ -87,25 +88,20 @@ public class InviteSettlementItemCreator {
87 log.info("{} end, item is exist", tag); 88 log.info("{} end, item is exist", tag);
88 return; 89 return;
89 } 90 }
90 - int inviterType = inviter.getType();  
91 - // 入驻商家  
92 - if (inviterType == INVITER_TYPE_STORED_SELLER) {  
93 - InviteActivity activity = inviteActivityMapper.selectByPrimaryKey(invitee.getInviteActivityId());  
94 - if (Objects.isNull(activity)) {  
95 - log.warn("{} fail, can not find inviter ", tag);  
96 - return;  
97 - }  
98 - // 验证是否过了奖励时间  
99 - int days = activity.getRewardDays();  
100 - if (inviteTime + days < orderCreateTime) {  
101 - log.warn("{} fail, reward end", tag); 91 +
  92 + if (!checkWithInviteActivity(tag, invitee, orderCreateTime, inviter)){
102 return; 93 return;
103 } 94 }
104 - }  
105 95
106 log.info("{}, start create", tag); 96 log.info("{}, start create", tag);
  97 + InviteSettlementItem inviteSettlementItem = buildInviteSettlementItem(request, invitee, inviter);
  98 + inviteSettlementItemMapper.insert(inviteSettlementItem);
107 99
108 - // 可以创建了 100 + log.info("{} success", tag);
  101 +
  102 + }
  103 +
  104 + private InviteSettlementItem buildInviteSettlementItem(InviteSettlementItemCreateRequest request, InviteRecord invitee, Inviter inviter) {
109 InviteSettlementItem inviteSettlementItem = new InviteSettlementItem(); 105 InviteSettlementItem inviteSettlementItem = new InviteSettlementItem();
110 106
111 inviteSettlementItem.setUid(inviter.getUid()); 107 inviteSettlementItem.setUid(inviter.getUid());
@@ -146,11 +142,27 @@ public class InviteSettlementItemCreator { @@ -146,11 +142,27 @@ public class InviteSettlementItemCreator {
146 } 142 }
147 143
148 inviteSettlementItem.setCreateTime(DateUtil.getCurrentTimeSecond()); 144 inviteSettlementItem.setCreateTime(DateUtil.getCurrentTimeSecond());
  145 + return inviteSettlementItem;
  146 + }
149 147
150 - inviteSettlementItemMapper.insert(inviteSettlementItem);  
151 -  
152 - log.info("{} success", tag);  
153 - 148 + private boolean checkWithInviteActivity(String tag, InviteRecord invitee, int orderCreateTime, Inviter inviter) {
  149 + int inviterType = inviter.getType();
  150 + int inviteTime = invitee.getCreateTime();
  151 + // 入驻商家
  152 + if (inviterType == INVITER_TYPE_STORED_SELLER) {
  153 + InviteActivity activity = inviteActivityMapper.selectByPrimaryKey(invitee.getInviteActivityId());
  154 + if (Objects.isNull(activity)) {
  155 + log.warn("{} fail, can not find inviter ", tag);
  156 + return false;
  157 + }
  158 + // 验证是否过了奖励时间
  159 + int days = activity.getRewardDays();
  160 + if (inviteTime + days < orderCreateTime) {
  161 + log.warn("{} fail, reward end", tag);
  162 + return false;
  163 + }
  164 + }
  165 + return true;
154 } 166 }
155 167
156 168