|
@@ -1,6 +1,7 @@
|
|
|
package com.game.business.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
@@ -22,7 +23,9 @@ import com.game.common.constant.finance.FinTranType3;
|
|
|
import com.game.common.constant.finance.TranCurrencyType;
|
|
|
import com.game.common.core.domain.HttpRet;
|
|
|
import com.game.common.core.redis.RedisCache;
|
|
|
+import com.game.common.exception.ServiceException;
|
|
|
import com.game.common.utils.DateUtils;
|
|
|
+import com.game.common.utils.SecurityUtils;
|
|
|
import com.game.common.utils.StringUtils;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -138,8 +141,8 @@ public class AppUserCountDividendServiceImpl extends ServiceImpl<AppUserCountDiv
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<AppUserCountDividend> selectUserDividendList(Long userId) {
|
|
|
- List<AppUserCountDividend> dividendList = appUserCountDividendMapper.selectUserDividendList(userId);
|
|
|
+ public List<AppUserCountDividend> selectUserDividendList(Long pid,Long userId,String dateNum) {
|
|
|
+ List<AppUserCountDividend> dividendList = appUserCountDividendMapper.selectUserDividendList(pid,userId,dateNum);
|
|
|
if(null != dividendList && dividendList.size()>0){
|
|
|
List<Long> ids = dividendList.stream().map(AppUserCountDividend::getUserId).collect(Collectors.toList());
|
|
|
List<AppUser> userList = appUserService.selectListByIds(ids);
|
|
@@ -157,66 +160,137 @@ public class AppUserCountDividendServiceImpl extends ServiceImpl<AppUserCountDiv
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
- public HttpRet<Boolean> send(String userId, String dateNo) {
|
|
|
- if(null == userId && StringUtils.isBlank(dateNo)){
|
|
|
- return HttpRet.fail("发放失败,参数为空");
|
|
|
- }
|
|
|
- LambdaQueryWrapper<AppUserCountDividend> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- if(StringUtils.isNotBlank(dateNo)){
|
|
|
- queryWrapper.eq(AppUserCountDividend::getDateNo,dateNo);
|
|
|
- }
|
|
|
- if(null != userId){
|
|
|
- queryWrapper.eq(AppUserCountDividend::getUserId,userId);
|
|
|
- }
|
|
|
- queryWrapper.eq(AppUserCountDividend::getStatus,0);
|
|
|
- List<AppUserCountDividend> dividendList = appUserCountDividendMapper.selectList(queryWrapper);
|
|
|
+ public HttpRet<Boolean> send(String userId, String dateNo,Long sendUserId) {
|
|
|
+ List<AppUserCountDividend> dividendList = this.selectUserDividendList(sendUserId, StringUtils.isBlank(userId)?null:Long.parseLong(userId),dateNo);
|
|
|
if(null == dividendList || dividendList.size() < 1){
|
|
|
return HttpRet.fail("发放失败,不存在或已发放");
|
|
|
}
|
|
|
+
|
|
|
+ if(curUser.getDiamondCoin() < dividendList.stream().mapToDouble(e->e.getDiamondCoin()).sum()){
|
|
|
+ return HttpRet.fail("发放失败,余额不足");
|
|
|
+ }
|
|
|
+ if(curUser.getCoin() < dividendList.stream().mapToDouble(e->e.getCoin()).sum()){
|
|
|
+ return HttpRet.fail("发放失败,金币不足");
|
|
|
+ }*/
|
|
|
|
|
|
List<Long> ids = dividendList.stream().map(AppUserCountDividend::getUserId).collect(Collectors.toList());
|
|
|
List<AppUser> userList = appUserService.selectListByIds(ids);
|
|
|
if(null != userList && userList.size()>0) {
|
|
|
Map<String, AppUser> userMap = userList.stream().collect(Collectors.toMap(e -> String.valueOf(e.getUserid()), Function.identity(), (k1, k2) -> k2));
|
|
|
- dividendList.forEach(e->{
|
|
|
- List<FinTranRecord> tranRecordList = new ArrayList<>();
|
|
|
- AppUser appUser = userMap.get(String.valueOf(e.getUserId()));
|
|
|
- AppUser updateAppUser = new AppUser();
|
|
|
- updateAppUser.setUserid(appUser.getUserid());
|
|
|
- if(null != e.getDiamondCoin() && e.getDiamondCoin()>0){
|
|
|
- updateAppUser.setDiamondCoin(appUser.getDiamondCoin() + e.getDiamondCoin());
|
|
|
- updateAppUser.setDiamondCoinTotal(appUser.getDiamondCoinTotal() + e.getDiamondCoin());
|
|
|
- updateAppUser.setDiamondCoinCash(updateAppUser.getDiamondCoinCash() + e.getDiamondCoin());
|
|
|
-
|
|
|
- FinTranAddedInfo addedInfo = FinTranAddedInfo.createTranInfo(appUser.getUserid(), 0, 0, AppSceneType.Scene_None, "");
|
|
|
- FinTranRecord tran = FinTranRecord.initFinTranRecordSomeParams(addedInfo, FinTranType3.AGENT_DIVIDED, FinTranType1.Agent_Income_Diamond_Coin, appUser);
|
|
|
- tran.setDiamondCoinChange(e.getDiamondCoin());
|
|
|
- tran.setAfterDiamondCoin(appUser.getDiamondCoin() + e.getDiamondCoin());
|
|
|
- tran.setCurrencyType(TranCurrencyType.Balance.getType());
|
|
|
- tranRecordList.add(tran);
|
|
|
- }
|
|
|
- if(null != e.getCoin() && e.getCoin()>0){
|
|
|
- updateAppUser.setCoin(appUser.getDiamondCoin() + e.getDiamondCoin());
|
|
|
-
|
|
|
- FinTranAddedInfo addedInfo = FinTranAddedInfo.createTranInfo(appUser.getUserid(), 0, 0, AppSceneType.Scene_None, "");
|
|
|
- FinTranRecord tran = FinTranRecord.initFinTranRecordSomeParams(addedInfo, FinTranType3.AGENT_DIVIDED, FinTranType1.Agent_Income_Coin, appUser);
|
|
|
- tran.setDiamondCoinChange(e.getDiamondCoin());
|
|
|
- tran.setAfterDiamondCoin(appUser.getDiamondCoin() + e.getDiamondCoin());
|
|
|
- tran.setCurrencyType(TranCurrencyType.Coin.getType());
|
|
|
- tranRecordList.add(tran);
|
|
|
- }
|
|
|
- appUserService.updateAppUser(updateAppUser);
|
|
|
- if(tranRecordList.size() > 0){
|
|
|
- tranRecordList.forEach(t->{
|
|
|
- finTranRecordService.insertFinTranRecord(t);
|
|
|
- });
|
|
|
+ String errMsg = "";
|
|
|
+ for(AppUserCountDividend countDividend : dividendList){
|
|
|
+ Long errUserId = countDividend.getUserId();
|
|
|
+ try {
|
|
|
+ List<FinTranRecord> tranRecordList = new ArrayList<>();
|
|
|
+ AppUser appUser = userMap.get(String.valueOf(countDividend.getUserId()));
|
|
|
+ AppUser curUser = appUserService.selectAppUserByUserid(sendUserId);
|
|
|
+ if(!sendUserId.equals(appUser.getPid())){
|
|
|
+ throw new ServiceException("只能给直属团队成员发放");
|
|
|
+ }
|
|
|
+
|
|
|
+ AppUser curUpdateAppUser = new AppUser();
|
|
|
+
|
|
|
+ if (null != countDividend.getDiamondCoin() && countDividend.getDiamondCoin() > 0) {
|
|
|
+ if(null != countDividend.getDiamondCoin() && curUser.getDiamondCoin() < countDividend.getDiamondCoin()){
|
|
|
+ throw new ServiceException("余额不足");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ curUser.setDiamondCoin(curUser.getDiamondCoin() - e.getDiamondCoin());
|
|
|
+ curUser.setDiamondCoinTotal(curUser.getDiamondCoinTotal() - e.getDiamondCoin());
|
|
|
+ curUpdateAppUser.setUserid(curUser.getUserid());
|
|
|
+ curUpdateAppUser.setDiamondCoinCash(curUser.getDiamondCoinCash());
|
|
|
+ curUpdateAppUser.setDiamondCoin(curUser.getDiamondCoin());
|
|
|
+ curUpdateAppUser.setDiamondCoinTotal(curUser.getDiamondCoinTotal());*/
|
|
|
+
|
|
|
+ FinTranAddedInfo curAddedInfo = FinTranAddedInfo.createTranInfo(appUser.getUserid(), 0, 0, AppSceneType.Scene_None, "");
|
|
|
+ FinTranRecord curTran = FinTranRecord.initFinTranRecordSomeParams(curAddedInfo, FinTranType3.AGENT_DIVIDED, FinTranType1.U_Outcome_Balance, curUser);
|
|
|
+ curTran.setDiamondCoinChange(countDividend.getDiamondCoin() * -1);
|
|
|
+
|
|
|
+ curTran.setCurrencyType(TranCurrencyType.Balance.getType());
|
|
|
+ curTran.setRemarks(countDividend.getDateNo() + " 发放团队分红奖励");
|
|
|
+ curTran.setFromUid(sendUserId);
|
|
|
+
|
|
|
+ appUserService.updateUserAmount(curTran);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ updateAppUser.setDiamondCoinTotal(appUser.getDiamondCoinTotal() + e.getDiamondCoin());
|
|
|
+ updateAppUser.setDiamondCoinCash(appUser.getDiamondCoinCash() + e.getDiamondCoin());*/
|
|
|
+
|
|
|
+ FinTranAddedInfo addedInfo = FinTranAddedInfo.createTranInfo(appUser.getUserid(), 0, 0, AppSceneType.Scene_None, "");
|
|
|
+ FinTranRecord tran = FinTranRecord.initFinTranRecordSomeParams(addedInfo, FinTranType3.AGENT_DIVIDED, FinTranType1.Agent_Income_Diamond_Coin, appUser);
|
|
|
+ tran.setDiamondCoinChange(countDividend.getDiamondCoin());
|
|
|
+ tran.setAfterDiamondCoin(appUser.getDiamondCoin() + countDividend.getDiamondCoin());
|
|
|
+ tran.setCurrencyType(TranCurrencyType.Balance.getType());
|
|
|
+ tran.setRemarks(countDividend.getDateNo() + " 团队周分红奖励");
|
|
|
+ tran.setFromUid(sendUserId);
|
|
|
+
|
|
|
+ appUserService.updateUserAmount(tran);
|
|
|
+ }
|
|
|
+ if (null != countDividend.getCoin() && countDividend.getCoin() > 0) {
|
|
|
+ if(null != countDividend.getCoin() && curUser.getCoin() < countDividend.getCoin()){
|
|
|
+ throw new ServiceException("金币不足");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ curUser.setCoin(curUser.getCoin() - e.getCoin());
|
|
|
+ curUpdateAppUser.setUserid(curUser.getUserid());
|
|
|
+ curUpdateAppUser.setCoinCash(curUser.getCoinCash());
|
|
|
+ curUpdateAppUser.setCoin(curUser.getCoin());*/
|
|
|
+
|
|
|
+ FinTranAddedInfo curAddedInfo = FinTranAddedInfo.createTranInfo(appUser.getUserid(), 0, 0, AppSceneType.Scene_None, "");
|
|
|
+ FinTranRecord curTran = FinTranRecord.initFinTranRecordSomeParams(curAddedInfo, FinTranType3.AGENT_DIVIDED, FinTranType1.U_Outcome_Coin, curUser);
|
|
|
+ curTran.setDiamondCoinChange(countDividend.getDiamondCoin() * -1);
|
|
|
+
|
|
|
+ curTran.setCurrencyType(TranCurrencyType.Coin.getType());
|
|
|
+ curTran.setRemarks(countDividend.getDateNo() + " 发放团队分红奖励");
|
|
|
+ curTran.setFromUid(sendUserId);
|
|
|
+
|
|
|
+ appUserService.updateUserAmount(curTran);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ FinTranAddedInfo addedInfo = FinTranAddedInfo.createTranInfo(appUser.getUserid(), 0, 0, AppSceneType.Scene_None, "");
|
|
|
+ FinTranRecord tran = FinTranRecord.initFinTranRecordSomeParams(addedInfo, FinTranType3.AGENT_DIVIDED, FinTranType1.Agent_Income_Coin, appUser);
|
|
|
+ tran.setDiamondCoinChange(countDividend.getDiamondCoin());
|
|
|
+
|
|
|
+ tran.setCurrencyType(TranCurrencyType.Coin.getType());
|
|
|
+ tran.setRemarks(countDividend.getDateNo() + " 团队周分红奖励");
|
|
|
+ tran.setFromUid(sendUserId);
|
|
|
+ appUserService.updateUserAmount(tran);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ appUserService.updateAppUser(curUpdateAppUser);*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ *
|
|
|
+
|
|
|
+ appUserService.updateUserAmount(t);
|
|
|
+ });*
|
|
|
+ for(FinTranRecord finTranRecord :tranRecordList){
|
|
|
+ try {
|
|
|
+ appUserService.updateUserAmount(finTranRecord);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ throw new RuntimeException(ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ AppUserCountDividend userCountDividend = new AppUserCountDividend();
|
|
|
+ userCountDividend.setId(countDividend.getId());
|
|
|
+ userCountDividend.setStatus(1);
|
|
|
+ this.updateAppUserCountDividend(userCountDividend);
|
|
|
+ }catch (Exception ex){
|
|
|
+ errMsg = "发放失败:" + ex.getMessage();
|
|
|
+ log.info("{}发放失败:{}",errUserId,ex.getMessage());
|
|
|
+ break;
|
|
|
}
|
|
|
- AppUserCountDividend userCountDividend = new AppUserCountDividend();
|
|
|
- userCountDividend.setId(e.getId());
|
|
|
- userCountDividend.setStatus(1);
|
|
|
- this.updateAppUserCountDividend(userCountDividend);
|
|
|
- });
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(errMsg)){
|
|
|
+ return HttpRet.fail(errMsg);
|
|
|
+ }
|
|
|
}
|
|
|
return HttpRet.success("发放成功",true);
|
|
|
}
|