|
@@ -1,9 +1,11 @@
|
|
|
package com.zhongshu.reward.server.core.service;
|
|
|
|
|
|
+import com.github.microservice.auth.client.content.ResultState;
|
|
|
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.payment.client.model.order.v2.GoodsResultModel;
|
|
|
+import com.zhongshu.payment.client.service.v2.OrderService2;
|
|
|
import com.zhongshu.reward.client.type.ReceiptsStatus;
|
|
|
import com.zhongshu.reward.client.type.ReceiptsType;
|
|
|
import com.zhongshu.reward.server.core.dao.WalletDao;
|
|
@@ -11,6 +13,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.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author wjf
|
|
@@ -42,32 +45,47 @@ public class GoodsReceiptsService {
|
|
|
@Autowired
|
|
|
ProductRuleService productRuleService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ OrderService2 orderService2;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 购物返利 todo// 1、获取产品库 返利规则 2、获取订单详情、获取商品详情
|
|
|
- * @param userId 用户id
|
|
|
- * @param goodsTotal 商品金额
|
|
|
- * @param orderNo 订单号
|
|
|
- * @param goodsId 商品id
|
|
|
*/
|
|
|
@Transactional
|
|
|
- public void receipts(String userId, BigDecimal goodsTotal, String orderNo, String goodsId){
|
|
|
+ public void receipts(String userId, String orderNo, String payGoodsId, Long operationTime){
|
|
|
|
|
|
- ProductRuleModel productRule = getRule(goodsId);
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<GoodsResultModel> goodsResultModelResultContent = orderService2.qrGoods(payGoodsId);
|
|
|
+ if (!ResultState.Success.equals(goodsResultModelResultContent.getState())){
|
|
|
+ log.info("查询商品信息失败:id:{}", payGoodsId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GoodsResultModel goodsResultModel = goodsResultModelResultContent.getContent();
|
|
|
+ if (StringUtils.isEmpty(goodsResultModel.getGoodsId())){
|
|
|
+ log.info("商品无对应产品库id:{}", payGoodsId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ProductRuleModel productRule = getRule(goodsResultModel.getGoodsId());
|
|
|
if (null == productRule){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- BigDecimal total = getReceiptsTotal(goodsTotal, productRule);
|
|
|
+ BigDecimal total = getReceiptsTotal(goodsResultModel.getPayAmount(), productRule);
|
|
|
+ if (BigDecimal.ZERO.compareTo(total) == 0){
|
|
|
+ log.info("商品返利金额为0, id:{}, productId:{}", payGoodsId, goodsResultModel.getGoodsId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
Wallet wallet = walletService.getWalletByUserId(userId);
|
|
|
|
|
|
WalletReceipts walletReceipts = new WalletReceipts();
|
|
|
walletReceipts.setWallet(wallet);
|
|
|
walletReceipts.setReceiptsType(ReceiptsType.REBATE);
|
|
|
- walletReceipts.setEstimatedTime(new Date().getTime() + 2*24*60*60*1000);
|
|
|
+ walletReceipts.setEstimatedTime(operationTime + 2*24*60*60*1000);
|
|
|
walletReceipts.setTotal(total);
|
|
|
walletReceipts.setOutTradeNo(orderNo);
|
|
|
- walletReceipts.setGoodsId(goodsId);
|
|
|
+ walletReceipts.setGoodsId(goodsResultModel.getGoodsId());
|
|
|
+ walletReceipts.setPaymentGoodsId(payGoodsId);
|
|
|
walletReceipts.setStatus(ReceiptsStatus.WAIT);
|
|
|
|
|
|
walletReceiptsDao.save(walletReceipts);
|
|
@@ -104,21 +122,21 @@ public class GoodsReceiptsService {
|
|
|
|
|
|
/**
|
|
|
* 取消购物返利
|
|
|
- * @param userId 用户id
|
|
|
* @param orderNo 订单号
|
|
|
- * @param goodsIds 商品id
|
|
|
*/
|
|
|
@Transactional
|
|
|
- public void cancel(String userId, String orderNo, List<String> goodsIds){
|
|
|
- BigDecimal total = BigDecimal.ZERO;
|
|
|
- Wallet wallet = walletService.getWalletByUserId(userId);
|
|
|
- List<WalletReceipts> walletReceiptsList = walletReceiptsDao.findByOutTradeNoAndGoodsIdInAndStatus(orderNo, goodsIds, ReceiptsStatus.WAIT);
|
|
|
- for (WalletReceipts it : walletReceiptsList){
|
|
|
- total = total.add(it.getTotal());
|
|
|
- it.setStatus(ReceiptsStatus.CANCEL);
|
|
|
+ public void cancel(String orderNo, String payGoodsId, Long operateTime){
|
|
|
+ WalletReceipts walletReceipts = walletReceiptsDao.findByOutTradeNoAndPaymentGoodsIdAndStatus(orderNo, payGoodsId, ReceiptsStatus.WAIT);
|
|
|
+ if (ObjectUtils.isEmpty(walletReceipts)){
|
|
|
+ log.info("无购物返利订单:{}", payGoodsId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (operateTime > walletReceipts.getEstimatedTime()){
|
|
|
+ return;
|
|
|
}
|
|
|
- walletReceiptsDao.saveAll(walletReceiptsList);
|
|
|
- walletDao.updateIncWaitAmount(wallet.getId(), total.negate());
|
|
|
+ walletReceipts.setStatus(ReceiptsStatus.CANCEL);
|
|
|
+ walletReceiptsDao.save(walletReceipts);
|
|
|
+ walletDao.updateIncWaitAmount(walletReceipts.getWallet().getId(), walletReceipts.getTotal().negate());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -127,12 +145,14 @@ public class GoodsReceiptsService {
|
|
|
@Transactional
|
|
|
public void settle(){
|
|
|
//todo 查询到期入账的订单
|
|
|
- WalletReceipts walletReceipts = walletReceiptsDao.findTop1ById("");
|
|
|
-
|
|
|
- walletReceipts.setReceiptsTime(new Date().getTime());
|
|
|
- walletReceipts.setStatus(ReceiptsStatus.RECEIPTS);
|
|
|
- walletReceiptsDao.save(walletReceipts);
|
|
|
- walletDao.updateIncWaitAmount(walletReceipts.getWallet().getId(), walletReceipts.getTotal().negate());
|
|
|
- walletDao.updateIncAmount(walletReceipts.getWallet().getId(), walletReceipts.getTotal());
|
|
|
+ List<WalletReceipts> waitSettle = walletReceiptsDao.findByWaitSettle(ReceiptsStatus.WAIT, ReceiptsType.REBATE, new Date().getTime());
|
|
|
+ waitSettle.forEach(walletReceipts->{
|
|
|
+ walletReceipts.setReceiptsTime(new Date().getTime());
|
|
|
+ walletReceipts.setStatus(ReceiptsStatus.RECEIPTS);
|
|
|
+ walletReceiptsDao.save(walletReceipts);
|
|
|
+ walletDao.updateIncWaitAmount(walletReceipts.getWallet().getId(), walletReceipts.getTotal().negate());
|
|
|
+ walletDao.updateIncAmount(walletReceipts.getWallet().getId(), walletReceipts.getTotal());
|
|
|
+ log.info("结算商品返利:{}", walletReceipts.getId());
|
|
|
+ });
|
|
|
}
|
|
|
}
|