|
@@ -0,0 +1,198 @@
|
|
|
+package com.game.business.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.game.business.domain.AppUser;
|
|
|
+import com.game.business.domain.FinTranRecord;
|
|
|
+import com.game.business.service.IAppUserService;
|
|
|
+import com.game.business.service.IFinTranRecordService;
|
|
|
+import com.game.common.constant.AppSceneType;
|
|
|
+import com.game.common.constant.finance.FinTranAddedInfo;
|
|
|
+import com.game.common.constant.finance.FinTranType1;
|
|
|
+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.utils.DateUtils;
|
|
|
+import com.game.common.utils.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.game.business.mapper.AppUserCountDividendMapper;
|
|
|
+import com.game.business.domain.AppUserCountDividend;
|
|
|
+import com.game.business.service.IAppUserCountDividendService;
|
|
|
+import com.game.common.annotation.DataSource;
|
|
|
+import com.game.common.enums.DataSourceType;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+
|
|
|
+ * 用户代理分红Service业务层处理
|
|
|
+ *
|
|
|
+ * @author game
|
|
|
+ * @date 2024-06-30
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class AppUserCountDividendServiceImpl extends ServiceImpl<AppUserCountDividendMapper, AppUserCountDividend> implements IAppUserCountDividendService {
|
|
|
+ @Autowired
|
|
|
+ private AppUserCountDividendMapper appUserCountDividendMapper;
|
|
|
+ @Autowired
|
|
|
+ private IAppUserService appUserService;
|
|
|
+ @Autowired
|
|
|
+ private IFinTranRecordService finTranRecordService;
|
|
|
+
|
|
|
+
|
|
|
+ * 查询用户代理分红
|
|
|
+ *
|
|
|
+ * @param id 用户代理分红主键
|
|
|
+ * @return 用户代理分红
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AppUserCountDividend selectAppUserCountDividendById(Long id) {
|
|
|
+ return appUserCountDividendMapper.selectAppUserCountDividendById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 查询用户代理分红列表
|
|
|
+ *
|
|
|
+ * @param appUserCountDividend 用户代理分红
|
|
|
+ * @return 用户代理分红
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<AppUserCountDividend> selectAppUserCountDividendList(AppUserCountDividend appUserCountDividend) {
|
|
|
+ return appUserCountDividendMapper.selectAppUserCountDividendList(appUserCountDividend);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 新增用户代理分红
|
|
|
+ *
|
|
|
+ * @param appUserCountDividend 用户代理分红
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertAppUserCountDividend(AppUserCountDividend appUserCountDividend) {
|
|
|
+ appUserCountDividend.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return appUserCountDividendMapper.insertAppUserCountDividend(appUserCountDividend);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 修改用户代理分红
|
|
|
+ *
|
|
|
+ * @param appUserCountDividend 用户代理分红
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateAppUserCountDividend(AppUserCountDividend appUserCountDividend) {
|
|
|
+ appUserCountDividend.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return appUserCountDividendMapper.updateAppUserCountDividend(appUserCountDividend);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 批量删除用户代理分红
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的用户代理分红主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteAppUserCountDividendByIds(Long[] ids) {
|
|
|
+ return appUserCountDividendMapper.deleteAppUserCountDividendByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 删除用户代理分红信息
|
|
|
+ *
|
|
|
+ * @param id 用户代理分红主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteAppUserCountDividendById(Long id) {
|
|
|
+ return appUserCountDividendMapper.deleteAppUserCountDividendById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AppUserCountDividend> selectUserDividendList(Long userId) {
|
|
|
+ List<AppUserCountDividend> dividendList = appUserCountDividendMapper.selectUserDividendList(userId);
|
|
|
+ if(null != dividendList && dividendList.size()>0){
|
|
|
+ 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->{
|
|
|
+ AppUser appUser = userMap.get(String.valueOf(e.getUserId()));
|
|
|
+ if(null != appUser){
|
|
|
+ e.setNickName(appUser.getNickname());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dividendList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @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);
|
|
|
+ if(null == dividendList || dividendList.size() < 1){
|
|
|
+ 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());
|
|
|
+
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ updateAppUser.setDiamondCoin(e.getDiamondCoin());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return HttpRet.success("发放成功",true);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|