Affiliate 允许为不同的用户设置不同的affiliate
Stripe 添加优惠券删除接口;限制优惠券只能在订阅时使用
This commit is contained in:
@@ -51,8 +51,17 @@ public class AffiliateController {
|
||||
|
||||
@ApiOperation(value = "审批affiliate申请")
|
||||
@GetMapping("/approval")
|
||||
public Response<Boolean> applicationApproval(@RequestParam("id") Long id, @RequestParam("isApproved")Boolean isApproved) {
|
||||
return Response.success(affiliateService.applicationApproval(id, isApproved));
|
||||
public Response<Boolean> applicationApproval(@RequestParam("id") Long id,
|
||||
@RequestParam("isApproved")Boolean isApproved,
|
||||
@RequestParam("commission") Float commission) {
|
||||
return Response.success(affiliateService.applicationApproval(id, isApproved, commission));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新佣金比例")
|
||||
@GetMapping("/updateCommission")
|
||||
public Response<String> updateCommissionPercentage(@RequestParam("id") Long id, @RequestParam("commission") Float commission) {
|
||||
affiliateService.updateCommissionPercentage(id, commission);
|
||||
return Response.success("success");
|
||||
}
|
||||
|
||||
/*@ApiOperation(value = "定时计算佣金")
|
||||
|
||||
@@ -141,6 +141,14 @@ public class StripeController {
|
||||
@RequestParam(required = false) String cooperator, @RequestParam(required = false) String remark){
|
||||
return Response.success(stripeService.updateCouponsInfo(id, paidCommission, cooperator, remark));
|
||||
}
|
||||
|
||||
@ApiOperation("删除推广码")
|
||||
@GetMapping("/deletePromCode")
|
||||
public Response<String> deleteCoupon(@RequestParam Long id){
|
||||
stripeService.deleteCoupon(id);
|
||||
return Response.success("success");
|
||||
}
|
||||
|
||||
/*@ApiOperation("临时 取消订阅")
|
||||
@GetMapping("/cancelSubscriptionTemp")
|
||||
public Response<String> cancelSubscriptionTemp(@RequestParam String subscriptionId) {
|
||||
|
||||
@@ -14,6 +14,8 @@ public class Affiliate extends BaseEntity{
|
||||
// Active(活跃) || Inactive(过期) || Pending(待审批) || Refused(拒绝)
|
||||
private String status;
|
||||
|
||||
private Float commissionPercent;
|
||||
|
||||
private Float totalEarnings = 0.00F;
|
||||
|
||||
private Float monthlyEarnings = 0.00F;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.ai.da.mapper.primary.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -37,6 +39,9 @@ public class ProductCoupons extends BaseEntity{
|
||||
// 备注
|
||||
private String remark;
|
||||
|
||||
@TableLogic
|
||||
private Integer isDeleted;
|
||||
|
||||
public ProductCoupons(String couponId, Long redeemBy, String promotionCodeId, String promotionCode, Long maxRedemptions, float percentOff, float commissionRate, String cooperator, String remark) {
|
||||
this.couponId = couponId;
|
||||
this.redeemBy = redeemBy;
|
||||
|
||||
@@ -22,6 +22,8 @@ public class SubscriptionEmailParamsDTO {
|
||||
// 费用
|
||||
private String totalFee;
|
||||
|
||||
private String renewalFee;
|
||||
|
||||
// 当前订阅开始时间
|
||||
private String lastOrderDate;
|
||||
|
||||
|
||||
@@ -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