|
@@ -18,6 +18,8 @@ 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.service.InviteReceiptsRoleFeignService;
|
|
|
+import com.zswl.cloud.bdb.client.vo.InviteReceiptsRoleVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
@@ -57,6 +59,9 @@ public class WalletReceiptsService {
|
|
|
@Autowired
|
|
|
AuthHelper authHelper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ InviteReceiptsRoleFeignService inviteReceiptsRoleFeignService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 邀请返利入账
|
|
@@ -64,45 +69,71 @@ public class WalletReceiptsService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional
|
|
|
- public void receipts(VipUserParam vipUserParam){
|
|
|
-
|
|
|
- VipUserRecord vipUserRecord = new VipUserRecord();
|
|
|
- BeanUtils.copyProperties(vipUserParam, vipUserRecord, "createTime");
|
|
|
- vipUserRecord.setOperateTime(DateUtils.timeToLong(vipUserParam.getCreateTime(), DateUtils.FORMAT_LONG));
|
|
|
- VipUserRecord save = vipUserRecordDao.save(vipUserRecord);
|
|
|
- //查询邀请关系
|
|
|
- InviteRecord inviteRecord = inviteRecordDao.findTopByUserIdOrderByCreateTime(vipUserParam.getCpId());
|
|
|
- if (Objects.isNull(inviteRecord)){
|
|
|
- return;
|
|
|
- }
|
|
|
- if(inviteRecord.getUserType().equals(UserType.OLD)){//是否老用户
|
|
|
- return;
|
|
|
+ public void receipts(VipUserRecord vipUserRecord){
|
|
|
+ //校验对应套餐返利规则
|
|
|
+ com.zswl.cloud.bdb.client.ret.ResultContent<InviteReceiptsRoleVo> rulerResultContent = inviteReceiptsRoleFeignService.getOne(vipUserRecord.getPlanningId());
|
|
|
+ if (rulerResultContent.getState().equals(com.zswl.cloud.bdb.client.ret.ResultState.Success)){
|
|
|
+ InviteReceiptsRoleVo rulerVo = rulerResultContent.getContent();
|
|
|
+ if (vipUserRecord.getSuc().equals(1)){
|
|
|
+ //订阅
|
|
|
+ //查询邀请关系
|
|
|
+ InviteRecord inviteRecord = inviteRecordDao.findTopByUserIdOrderByCreateTime(vipUserRecord.getCpId());
|
|
|
+ if (Objects.nonNull(inviteRecord) && inviteRecord.getUserType().equals(UserType.NEW)){
|
|
|
+ if (rulerVo.getFirstPurchaseDay()!=null && !vipUserRecordDao.existsByCpIdAndSucIn(vipUserRecord.getCpId(), List.of(1))) {
|
|
|
+ vipUserRecord.setFirst(true);
|
|
|
+ BigDecimal total = BigDecimal.ZERO;
|
|
|
+ //订阅入账
|
|
|
+ WalletReceipts walletReceipts = new WalletReceipts();
|
|
|
+ //获取邀请人userid
|
|
|
+ String inviteId = inviteRecord.getInviteUserId();
|
|
|
+ Wallet wallet = walletService.getWalletByUserId(inviteId);
|
|
|
+ walletReceipts.setWallet(wallet);
|
|
|
+ walletReceipts.setInviteUserId(inviteId);
|
|
|
+ walletReceipts.setUserId(vipUserRecord.getCpId());
|
|
|
+ walletReceipts.setReceiptsType(ReceiptsType.COMMISSION);
|
|
|
+ walletReceipts.setOutTradeNo(vipUserRecord.getPlanningId());
|
|
|
+ walletReceipts.setTotal(total);
|
|
|
+ walletReceipts.setEstimatedTime(DateUtils.nextMonthDayStartTime(rulerVo.getDay()));
|
|
|
+ walletReceipts.setVipUserRecord(vipUserRecord);
|
|
|
+ //邀请人钱包
|
|
|
+ walletReceipts.setStatus(ReceiptsStatus.WAIT);
|
|
|
+ wallet.setWaitAmount(wallet.getWaitAmount().add(total));
|
|
|
+ walletDao.save(wallet);
|
|
|
+ walletReceiptsDao.save(walletReceipts);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if (vipUserRecord.getSuc().equals(-1) || vipUserRecord.getSuc().equals(5)){
|
|
|
+ VipUserRecord lastOne = vipUserRecordDao.findTop1ByCpIdAndSucOrderByOperateTime(vipUserRecord.getCpId(), 1);
|
|
|
+ //上一单首购
|
|
|
+ if (ObjectUtils.isNotEmpty(lastOne) && lastOne.isFirst() && Math.abs(vipUserRecord.getOperateTime() - lastOne.getOperateTime()) < 24L *60*60*1000*rulerVo.getFirstPurchaseDay()){
|
|
|
+ WalletReceipts walletReceipts = walletReceiptsDao.findTop1ByVipUserRecord_IdAndVipUserRecord_First(lastOne.getId(), true);
|
|
|
+ if (ObjectUtils.isNotEmpty(walletReceipts)){
|
|
|
+ walletReceipts.setStatus(ReceiptsStatus.CANCEL);
|
|
|
+ Wallet wallet = walletService.getWalletByUserId(walletReceipts.getInviteUserId());
|
|
|
+ wallet.setWaitAmount(wallet.getWaitAmount().subtract(walletReceipts.getTotal()));
|
|
|
+ walletDao.save(wallet);
|
|
|
+ walletReceiptsDao.save(walletReceipts);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ vipUserRecordDao.save(vipUserRecord);
|
|
|
+ }
|
|
|
|
|
|
- //todo 校验对应套餐返利规则
|
|
|
- BigDecimal total = BigDecimal.ZERO;
|
|
|
-
|
|
|
- if (vipUserRecord.getSuc().equals(1) || vipUserRecord.getSuc().equals(4)){
|
|
|
- //订阅入账
|
|
|
- WalletReceipts walletReceipts = new WalletReceipts();
|
|
|
- //获取邀请人userid
|
|
|
- String inviteId = inviteRecord.getInviteUserId();
|
|
|
- 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);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算
|
|
|
+ */
|
|
|
+ public void settle(){
|
|
|
+ Long startTime = DateUtils.lastMonthStartTime();
|
|
|
+ Long endTime = DateUtils.lastMonthEndTime();
|
|
|
+ List<WalletReceipts> list = walletReceiptsDao.listMonth(startTime, endTime);
|
|
|
+
|
|
|
+ for (WalletReceipts walletReceipts : list){
|
|
|
+ String inviteUserId = walletReceipts.getInviteUserId();
|
|
|
+ String userId = walletReceipts.getUserId();
|
|
|
}
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
/**
|