Untitled

 avatar
unknown
plain_text
2 years ago
3.3 kB
4
Indexable
public PtActivityBO checkPtActivity(long userId, BigDecimal userPayAfterDiscount, long businessId, boolean isBusiness, Integer usePt) {
	PtActivityBO bo = new PtActivityBO()
		.setRealMoney(userPayAfterDiscount);
	if (usePt == null || usePt == 0) {
		log.info("用户没有选择PT支付, {}", usePt);
		return bo;
	}
	if (!isBusiness) {
		log.error("不是商家: {}", businessId);
		return bo;
	}
	PtActivityConfigBO businessPtActivity = businessPtActivityService.getLatestBusinessPtActivityList(businessId);
	if (Func.isEmpty(businessPtActivity) || IsEnable.notEnabled.getCode() == businessPtActivity.getStatus()) {
		log.info("当前没有启用的活动");
		return bo;
	}

	BigDecimal realMoney = userPayAfterDiscount;
	BigDecimal ptDiscountMoney = BigDecimal.ZERO;
	BigDecimal ptMerchantBearMoney = BigDecimal.ZERO;
	BigDecimal ptCompanyBearMoney = BigDecimal.ZERO;
	// 用户PT折扣金额換算成點數
	BigDecimal ptDiscountPoints = BigDecimal.ZERO;
	// PT 匯率,若禁用 PT 匯率設定,則 PT 匯率為 1;若啟用 PT 匯率設定,則 PT 匯率為 PT 匯率設定值
	BigDecimal ptExchangeRate = Func.toBoolean(ParamCache.getValue(FinanceParamConstant.IS_Enable_PT_Exchange_Rate_Setting), false) ?
		new BigDecimal(Func.toStr(ParamCache.getValue(FinanceParamConstant.PT_EXCHANGE_RATE), "1")) : new BigDecimal("1");
	// 店家設定用戶PT折扣比例
	Integer ptProportion = businessPtActivity.getPtProportion();
	Long activityId = 0L;
	Wallet wallet = walletService.getWallet(userId);
	BigDecimal userWalletPtMoney = wallet.getPtMoney();
	if (userWalletPtMoney.compareTo(BigDecimal.ZERO) > 0 && ptProportion > 0) {
		activityId = businessPtActivity.getActivityId();
		// 用户可折扣PT最大金额
		ptDiscountMoney = NumberUtils.multiply(userPayAfterDiscount, ptProportion, 2);
		BigDecimal upPayPtMoney = NumberUtils.roundingUp(ptDiscountMoney); // 向上取整
		if (userWalletPtMoney.compareTo(upPayPtMoney.multiply(ptExchangeRate)) < 0) { // 用戶錢包PT餘額小於(用户可折扣PT最大金額的向上取整值 * PT匯率)
			ptDiscountMoney = userWalletPtMoney.divide(ptExchangeRate, 0 , RoundingMode.DOWN); // 用戶折抵PT金額為用戶錢包PT餘額除以PT匯率後向下取整
		} else {
			ptDiscountMoney = upPayPtMoney;
		}
		// 用戶支付PGP金額(扣掉用戶折抵PT金額)
		realMoney = userPayAfterDiscount.subtract(ptDiscountMoney);
		// 商家承担金额
		Integer businessProportion = businessPtActivity.getBusinessProportion();
		if (businessProportion > 0) {
			ptMerchantBearMoney = NumberUtils.multiply(ptDiscountMoney, businessProportion, 2);
			ptMerchantBearMoney = NumberUtils.roundingUp(ptMerchantBearMoney); //  无条件进位
		}
		// 平台承担金额
		ptCompanyBearMoney = ptDiscountMoney.subtract(ptMerchantBearMoney);
		// 用户PT折扣金额換算成點數
		ptDiscountPoints = ptDiscountMoney.multiply(ptExchangeRate);
	}
	return new PtActivityBO()
		.setPtDiscountId(activityId)
		.setRealMoney(realMoney)
		.setPtDiscountMoney(ptDiscountMoney)
		.setPtMerchantBearMoney(ptMerchantBearMoney)
		.setPtCompanyBearMoney(ptCompanyBearMoney)
		.setPtExchangeRate(ptExchangeRate)
		.setPtDiscountPoints(ptDiscountPoints);
}
Editor is loading...
Leave a Comment