|
@@ -1,5 +1,9 @@
|
|
|
package com.zhongshu.reward.server.core.service;
|
|
|
|
|
|
+import com.github.microservice.productcenter.client.model.ProductRuleModel;
|
|
|
+import com.github.microservice.productcenter.client.ret.ResultContent;
|
|
|
+import com.github.microservice.productcenter.client.ret.ResultState;
|
|
|
+import com.github.microservice.productcenter.client.service.ProductRuleService;
|
|
|
import com.zhongshu.reward.client.type.ReceiptsStatus;
|
|
|
import com.zhongshu.reward.client.type.ReceiptsType;
|
|
|
import com.zhongshu.reward.server.core.dao.WalletDao;
|
|
@@ -7,6 +11,8 @@ import com.zhongshu.reward.server.core.dao.WalletReceiptsDao;
|
|
|
import com.zhongshu.reward.server.core.domain.Wallet;
|
|
|
import com.zhongshu.reward.server.core.domain.WalletReceipts;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -33,15 +39,25 @@ public class GoodsReceiptsService {
|
|
|
@Autowired
|
|
|
WalletReceiptsDao walletReceiptsDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ProductRuleService productRuleService;
|
|
|
+
|
|
|
/**
|
|
|
* 购物返利 todo// 1、获取产品库 返利规则 2、获取订单详情、获取商品详情
|
|
|
* @param userId 用户id
|
|
|
- * @param total 返利金额
|
|
|
+ * @param goodsTotal 商品金额
|
|
|
* @param orderNo 订单号
|
|
|
* @param goodsId 商品id
|
|
|
*/
|
|
|
@Transactional
|
|
|
- public void receipts(String userId, BigDecimal total, String orderNo, String goodsId){
|
|
|
+ public void receipts(String userId, BigDecimal goodsTotal, String orderNo, String goodsId){
|
|
|
+
|
|
|
+ ProductRuleModel productRule = getRule(goodsId);
|
|
|
+ if (null == productRule){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal total = getReceiptsTotal(goodsTotal, productRule);
|
|
|
|
|
|
Wallet wallet = walletService.getWalletByUserId(userId);
|
|
|
|
|
@@ -59,6 +75,32 @@ public class GoodsReceiptsService {
|
|
|
log.info("购物返利入账");
|
|
|
}
|
|
|
|
|
|
+ @NotNull
|
|
|
+ private static BigDecimal getReceiptsTotal(BigDecimal goodsTotal, ProductRuleModel productRule) {
|
|
|
+ BigDecimal total = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (productRule.getCashBackFixed()!=null){
|
|
|
+ total = productRule.getCashBackFixed();
|
|
|
+ }else if (productRule.getCashBackPercent()!=null){
|
|
|
+ total = goodsTotal.multiply(productRule.getCashBackPercent().multiply(BigDecimal.TEN.pow(2)));
|
|
|
+ } return total;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ private ProductRuleModel getRule(String goodsId) {
|
|
|
+ ResultContent<ProductRuleModel> goodsRulerResult = productRuleService.list(goodsId);
|
|
|
+ ResultContent<ProductRuleModel> overRulerResult = productRuleService.list(null);
|
|
|
+
|
|
|
+ ProductRuleModel productRule = goodsRulerResult.getContent();
|
|
|
+ ProductRuleModel overRule = overRulerResult.getContent();
|
|
|
+ if (productRule.getEnableCashback()!=null && productRule.getEnableCashback()){
|
|
|
+ return productRule;
|
|
|
+ }else if (overRule.getEnableCashback()!=null && overRule.getEnableCashback()){
|
|
|
+ return overRule;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 取消购物返利
|