|
@@ -2,13 +2,18 @@ package com.zhongshu.reward.server.core.service;
|
|
|
|
|
|
import com.github.microservice.core.util.result.content.ResultContent;
|
|
|
import com.github.microservice.core.util.result.content.ResultState;
|
|
|
-import com.zhongshu.reward.client.model.param.WalletReceiptsParam;
|
|
|
import com.zhongshu.reward.client.model.wallet.WalletReceiptsModel;
|
|
|
import com.zhongshu.reward.client.type.ReceiptsStatus;
|
|
|
+import com.zhongshu.reward.client.type.ReceiptsType;
|
|
|
+import com.zhongshu.reward.server.core.dao.VipUserRecordDao;
|
|
|
import com.zhongshu.reward.server.core.dao.WalletDao;
|
|
|
import com.zhongshu.reward.server.core.dao.WalletReceiptsDao;
|
|
|
+import com.zhongshu.reward.server.core.domain.VipUserRecord;
|
|
|
import com.zhongshu.reward.server.core.domain.Wallet;
|
|
|
import com.zhongshu.reward.server.core.domain.WalletReceipts;
|
|
|
+import com.zhongshu.reward.server.core.util.DateUtils;
|
|
|
+import com.zhongshu.vip.client.model.param.VipUserParam;
|
|
|
+import com.zswl.cloud.bdb.client.vo.PromotionLogVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -16,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -37,25 +43,57 @@ public class WalletReceiptsService {
|
|
|
@Autowired
|
|
|
WalletReceiptsDao walletReceiptsDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ VipUserRecordDao vipUserRecordDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PromotionLogFeignService promotionLogFeignService;
|
|
|
+
|
|
|
/**
|
|
|
* 邀请返利入账
|
|
|
- * @param param
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional
|
|
|
- public Object receipts(WalletReceiptsParam param){
|
|
|
+ public void receipts(VipUserParam vipUserParam){
|
|
|
|
|
|
- Wallet wallet = walletService.getWalletByUserId(param.getUserId());
|
|
|
+ VipUserRecord vipUserRecord = new VipUserRecord();
|
|
|
+ BeanUtils.copyProperties(vipUserParam, vipUserRecord, "createTime");
|
|
|
+ vipUserRecord.setOperateTime(DateUtils.timeToLong(vipUserParam.getCreateTime(), DateUtils.FORMAT_LONG));
|
|
|
+ VipUserRecord save = vipUserRecordDao.save(vipUserRecord);
|
|
|
+ //查询邀请关系
|
|
|
+ PromotionLogVo promotionLog = promotionLogFeignService.getPromotionLog(vipUserParam.getCpId());
|
|
|
+ if (Objects.isNull(promotionLog)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(promotionLog.getUserType().equals(2)){//是否老用户
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- WalletReceipts walletReceipts = new WalletReceipts();
|
|
|
- BeanUtils.copyProperties(param, walletReceipts);
|
|
|
- walletReceipts.setWallet(wallet);
|
|
|
- if (walletReceipts.getReceiptsType()==null){
|
|
|
- walletReceipts.setStatus(ReceiptsStatus.WAIT);
|
|
|
+ //todo 校验对应套餐返利规则
|
|
|
+ BigDecimal total = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (vipUserRecord.getSuc().equals(1) || vipUserRecord.getSuc().equals(4)){
|
|
|
+ //订阅入账
|
|
|
+ WalletReceipts walletReceipts = new WalletReceipts();
|
|
|
+ //获取邀请人userid
|
|
|
+ String inviteId = promotionLog.getResourceId();
|
|
|
+ Wallet wallet = walletService.getWalletByUserId(inviteId);
|
|
|
+ walletReceipts.setWallet(wallet);
|
|
|
+ walletReceipts.setUserId(vipUserParam.getCpId());
|
|
|
+ walletReceipts.setReceiptsType(ReceiptsType.COMMISSION);
|
|
|
+ walletReceipts.setOutTradeNo(vipUserParam.getPlanningId());
|
|
|
+ walletReceipts.setTotal(total);
|
|
|
+ walletReceipts.setEstimatedTime(DateUtils.nextMonthDayStartTime(25));
|
|
|
+ walletReceipts.setVipUserRecord(save);
|
|
|
+ //邀请人钱包
|
|
|
+ if (walletReceipts.getReceiptsType()==null){
|
|
|
+ walletReceipts.setStatus(ReceiptsStatus.WAIT);
|
|
|
+ }
|
|
|
+ wallet.setWaitAmount(wallet.getWaitAmount().add(total));
|
|
|
+ walletDao.save(wallet);
|
|
|
+ walletReceiptsDao.save(walletReceipts);
|
|
|
}
|
|
|
- wallet.setWaitAmount(wallet.getWaitAmount().add(param.getTotal()));
|
|
|
- walletDao.save(wallet);
|
|
|
- return ResultContent.buildContent(toModel(walletReceiptsDao.save(walletReceipts)));
|
|
|
}
|
|
|
|
|
|
/**
|