Affiliate 允许为不同的用户设置不同的affiliate
Stripe 添加优惠券删除接口;限制优惠券只能在订阅时使用
This commit is contained in:
@@ -18,7 +18,9 @@ public interface AffiliateService extends IService<Affiliate> {
|
||||
|
||||
double[] getPersonalMonthlyIncome(int year);
|
||||
|
||||
Boolean applicationApproval(Long id, Boolean isApproved);
|
||||
Boolean applicationApproval(Long id, Boolean isApproved, Float commission);
|
||||
|
||||
void updateCommissionPercentage(Long id, Float commission);
|
||||
|
||||
void updateAffiliateInfoWithPayment();
|
||||
|
||||
|
||||
@@ -70,4 +70,6 @@ public interface StripeService {
|
||||
String retrievePromotionCode(String promotionCode);
|
||||
|
||||
IPage<ProductCoupons> getAllCoupons(QueryCouponsPageDTO queryCouponsPageDTO);
|
||||
|
||||
void deleteCoupon(Long id);
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class AffiliateServiceImpl extends ServiceImpl<AffiliateMapper, Affiliate
|
||||
}
|
||||
|
||||
// 审批申请
|
||||
public Boolean applicationApproval(Long id, Boolean isApproved){
|
||||
public Boolean applicationApproval(Long id, Boolean isApproved, Float commission){
|
||||
Affiliate affiliate = baseMapper.selectById(id);
|
||||
|
||||
// 1、更新db状态
|
||||
@@ -156,6 +156,12 @@ public class AffiliateServiceImpl extends ServiceImpl<AffiliateMapper, Affiliate
|
||||
affiliate.setStatus("Active");
|
||||
affiliate.setApproved(true);
|
||||
affiliate.setLink(CommonConstant.AFFILIATE_LINK + affiliate.getId());
|
||||
if (Objects.isNull(commission)) {
|
||||
// 未设置佣金比例的情况下,默认25%
|
||||
affiliate.setCommissionPercent(25f);
|
||||
} else {
|
||||
affiliate.setCommissionPercent(commission);
|
||||
}
|
||||
} else {
|
||||
affiliate.setStatus("Refused");
|
||||
affiliate.setApproved(false);
|
||||
@@ -175,6 +181,19 @@ public class AffiliateServiceImpl extends ServiceImpl<AffiliateMapper, Affiliate
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateCommissionPercentage(Long id, Float commission){
|
||||
Affiliate affiliate = baseMapper.selectById(id);
|
||||
if (Objects.isNull(affiliate)){
|
||||
log.info("未知affiliate id :{}", id);
|
||||
throw new BusinessException("unknown affiliate");
|
||||
}
|
||||
if (!Objects.equals(affiliate.getCommissionPercent(), commission)){
|
||||
affiliate.setCommissionPercent(commission);
|
||||
affiliate.setUpdateTime(LocalDateTime.now());
|
||||
baseMapper.updateById(affiliate);
|
||||
}
|
||||
}
|
||||
|
||||
// 定时计算佣金
|
||||
public void updateAffiliateInfoWithPayment(){
|
||||
// id存redis
|
||||
@@ -211,8 +230,8 @@ public class AffiliateServiceImpl extends ServiceImpl<AffiliateMapper, Affiliate
|
||||
Float payerTotal = paymentInfo.getPayerTotal();
|
||||
|
||||
if (payerTotal > 0){
|
||||
// 分配新用户首次订阅所付费用的25%作为佣金
|
||||
BigDecimal commission = BigDecimal.valueOf(payerTotal).multiply(new BigDecimal("0.25"));
|
||||
// 分配新用户首次订阅所付费用 预设的佣金比例 作为佣金
|
||||
BigDecimal commission = BigDecimal.valueOf(payerTotal).multiply(BigDecimal.valueOf(affiliate.getCommissionPercent() / 100));
|
||||
BigDecimal monthlyEarning = BigDecimal.valueOf(affiliate.getMonthlyEarnings()).add(commission);
|
||||
BigDecimal unpaidEarnings = BigDecimal.valueOf(affiliate.getUnpaidEarnings()).add(commission);
|
||||
int visits = affiliate.getVisits() + 1;
|
||||
|
||||
@@ -116,6 +116,16 @@ public class StripeServiceImpl implements StripeService {
|
||||
default:
|
||||
throw new BusinessException("unknown subscription type");
|
||||
}
|
||||
|
||||
// 添加优惠券(只允许在订阅时使用优惠券)
|
||||
String promotionCode = productPurchaseDTO.getPromotionCode();
|
||||
if (!StringUtil.isNullOrEmpty(promotionCode)){
|
||||
ProductCoupons productCoupon = checkProductCoupon(promotionCode);;
|
||||
if (productCoupon != null){
|
||||
sessionBuilder.addDiscount(SessionCreateParams.Discount.builder()
|
||||
.setPromotionCode(productCoupon.getPromotionCodeId()).build());
|
||||
}
|
||||
}
|
||||
// 只有订阅时才允许使用推广码优惠
|
||||
// sessionBuilder.setAllowPromotionCodes(true);
|
||||
break;
|
||||
@@ -170,16 +180,6 @@ public class StripeServiceImpl implements StripeService {
|
||||
.build());
|
||||
sessionBuilder.putMetadata("orderId", orderId); //通过订单号关联用于检索支付信息(可选)
|
||||
|
||||
// 添加优惠券
|
||||
String promotionCode = productPurchaseDTO.getPromotionCode();
|
||||
if (!StringUtil.isNullOrEmpty(promotionCode)){
|
||||
ProductCoupons productCoupon = checkProductCoupon(promotionCode);;
|
||||
if (productCoupon != null){
|
||||
sessionBuilder.addDiscount(SessionCreateParams.Discount.builder()
|
||||
.setPromotionCode(productCoupon.getPromotionCodeId()).build());
|
||||
}
|
||||
}
|
||||
|
||||
Session session = Session.create(sessionBuilder.build());
|
||||
List<String> paymentMethodTypes = session.getPaymentMethodTypes();
|
||||
log.info("paymentMethodTypes: {}", paymentMethodTypes);
|
||||
@@ -193,6 +193,9 @@ public class StripeServiceImpl implements StripeService {
|
||||
return session.getUrl();
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (InvalidRequestException e) {
|
||||
log.info("创建会话出现异常:", e);
|
||||
throw new BusinessException(e.getMessage().substring(0, e.getMessage().indexOf(";")));
|
||||
} catch (Exception e) {
|
||||
log.error("创建支付会话出现异常:", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user