Authored by LUOXC

refactor

... ... @@ -13,6 +13,9 @@ import org.springframework.stereotype.Component;
import java.util.Objects;
import static com.yohoufo.order.constants.InviteConstant.INVITER_TYPE_AGENT;
import static com.yohoufo.order.constants.InviteConstant.INVITER_TYPE_STORED_SELLER;
/**
* @author LUOXC
* @date 2019/4/3 11:47
... ... @@ -86,7 +89,7 @@ public class InviteSettlementItemCreator {
}
int inviterType = inviter.getType();
// 入驻商家
if (inviterType == InviteConstant.INVITER_TYPE_STORED_SELLER) {
if (inviterType == INVITER_TYPE_STORED_SELLER) {
InviteActivity activity = inviteActivityMapper.selectByPrimaryKey(invitee.getInviteActivityId());
if (Objects.isNull(activity)) {
log.warn("{} fail, can not find inviter ", tag);
... ... @@ -114,9 +117,20 @@ public class InviteSettlementItemCreator {
inviteSettlementItem.setOrderAmount(request.getOrderAmount());
inviteSettlementItem.setOrderCreateTime(request.getOrderCreateTime());
// 待结算方式
inviteSettlementItem.setType(inviter.getType());
// 结算方式选择
// 入驻商家角色以type1方式结算
if (inviter.getType() == INVITER_TYPE_STORED_SELLER) {
inviteSettlementItem.setType(1);
}
// 一级代理角色以type2方式结算
else if (inviter.getType() == INVITER_TYPE_AGENT) {
inviteSettlementItem.setType(2);
}
// 其他以type1方式结算
else {
inviteSettlementItem.setType(1);
}
// 待结算订单状态
// 受邀人无效
if (invitee.getStatus() == InviteRecord.STATUS_DISABLE) {
... ...
... ... @@ -12,8 +12,6 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Objects;
import static com.yohoufo.order.constants.InviteConstant.INVITER_TYPE_STORED_SELLER;
/**
* @author LUOXC
* @date 2019/4/3 12:38
... ... @@ -49,27 +47,27 @@ public class InviterSettleService {
// 计算结算金额
int settlementId = settlement.getId();
log.info("settle for {} calculate settle amount for settlement {}.", uid, settlementId);
// 计算入驻商家邀请的结算金额
BigDecimal settleAmountOfStoredSeller = calculateSettleAmountOfStoredSeller(uid, settlementId);
log.info("settle for {} calculate settle amount for settlement {}, the amount of stored seller is {}.",
uid, settlementId, settleAmountOfStoredSeller);
// 一级代理人邀请的结算金额
BigDecimal settleAmountOfAgent = BigDecimal.ZERO;
// type1方式结算金额
BigDecimal settleAmountOfType1 = calculateSettleAmountOfType1(uid, settlementId);
log.info("settle for {} calculate settle amount for settlement {}, the amount of type1 is {}.",
uid, settlementId, settleAmountOfType1);
// type2方式结算金额
BigDecimal settleAmountOfType2 = BigDecimal.ZERO;
// 更新结算金额
settlement.setSettleAmount(settleAmountOfStoredSeller.add(settleAmountOfAgent));
settlement.setSettleAmount(settleAmountOfType1.add(settleAmountOfType2));
inviteSettlementMapper.updateByUidAndId(settlement);
log.info("settle for {} end settle amount for settlement {} is {}.", uid, settlementId, settlement.getSettleAmount());
}
/**
* 计算入驻商家邀请的结算金额
* type1方式结算金额
*
* @param uid
* @param settlementId
* @return
*/
private BigDecimal calculateSettleAmountOfStoredSeller(int uid, int settlementId) {
int type = INVITER_TYPE_STORED_SELLER;
private BigDecimal calculateSettleAmountOfType1(int uid, int settlementId) {
int type = 1;
inviteSettlementItemMapper.updateToSettled(
uid,
type,
... ...