Commit 846addd2 authored by m1991's avatar m1991

Merge remote-tracking branch 'origin/master'

parents 85e8c202 a5d3d44d
......@@ -44,7 +44,12 @@ public interface UsersMapper extends BaseMapper<User> {
List<User> getList(Map<String, Object> map);
List<User> findAll();
/**
* 获取所有的非普通用户列表
*
* @return 非普通用户列表
*/
List<User> findAllNotZeroUser();
User findByName(String name);
......@@ -54,6 +59,7 @@ public interface UsersMapper extends BaseMapper<User> {
/**
* 获取用户信息
*
* @return 用户信息
*/
User getUserById(@Param("id") Long id);
......@@ -113,6 +119,7 @@ public interface UsersMapper extends BaseMapper<User> {
/**
* 用户注册
*
* @param userId
* @param inviteCode
* @param beInvitedCode
......@@ -155,7 +162,6 @@ public interface UsersMapper extends BaseMapper<User> {
List<User> getByLevel(@Param("userLevel") Integer userLevel);
/**
*
* @param
* @return
*/
......@@ -164,6 +170,7 @@ public interface UsersMapper extends BaseMapper<User> {
/**
* 用户邀请码查询用户数据
*
* @param inviteCode
* @return
*/
......@@ -171,6 +178,7 @@ public interface UsersMapper extends BaseMapper<User> {
/**
* 根据用户的推荐人邀请码 查询上级用户的id
*
* @param beInvitedCode
* @return
*/
......@@ -181,13 +189,15 @@ public interface UsersMapper extends BaseMapper<User> {
/**
* 获取所有的空投用户
* 且注册时间为一月之前
*
* @return
*/
List<User> getAerialDeliveryUserBeforOneMonth(@Param("before") String before,
@Param("now") String now );
@Param("now") String now);
/**
* 随机获取一条小于当前id的用户 即: 比当前用户早注册的用户
*
* @param id
* @return
*/
......
......@@ -93,7 +93,7 @@
where
p.user_id=u.user_id
and p.`year_month` = #{yearMonth}
order by p.`growth_rate` desc,u.create_time desc
order by p.`growth_rate` desc,u.create_time desc,p.award_money desc
</select>
</mapper>
\ No newline at end of file
......@@ -146,8 +146,9 @@
from
<include refid="table"/>
<where>
user_level != 0
<if test="yearMonth != null">
`year_month` = #{yearMonth}
and `year_month` = #{yearMonth}
</if>
order by month_team_performance desc
limit 20
......
......@@ -151,9 +151,14 @@
</where>
</select>
<!--查询全部-->
<select id="findAll" resultType="cn.wisenergy.model.app.User">
select * from User
<select id="findAllNotZeroUser" resultType="cn.wisenergy.model.app.User">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_level !=0
</where>
</select>
<!--查询用户-->
......@@ -379,10 +384,11 @@
BETWEEN #{before} AND #{now}
</select>
<select id="randOneGetUserByUserId" resultType="cn.wisenergy.model.app.User" >
<select id="randOneGetUserByUserId" resultType="cn.wisenergy.model.app.User">
SELECT
<include refid="cols_all"/>
FROM <include refid="table"/>
FROM
<include refid="table"/>
WHERE id &lt; #{id}
ORDER BY RAND() LIMIT 1
</select>
......
......@@ -65,16 +65,13 @@ public class AccountManager {
//1、计算返佣金额
BigDecimal bigDecimal = orderInfo.getPayment().multiply(memberPercent.getPercent());
BigDecimal extractMoney = accountInfo.getExtractMoney().add(bigDecimal);
extractMoney.setScale(2, RoundingMode.HALF_UP);
accountInfo.setExtractMoney(extractMoney);
accountInfo.setExtractMoney(extractMoney.setScale(2, RoundingMode.HALF_UP));
BigDecimal performanceMonth = accountInfo.getEarningsMonth().add(bigDecimal);
performanceMonth.setScale(2, RoundingMode.HALF_UP);
accountInfo.setEarningsMonth(performanceMonth);
accountInfo.setEarningsMonth(performanceMonth.setScale(2, RoundingMode.HALF_UP));
BigDecimal performanceTotal = accountInfo.getEarningsMonth().add(bigDecimal);
performanceTotal.setScale(2, RoundingMode.HALF_UP);
accountInfo.setEarningsTotal(performanceTotal);
accountInfo.setEarningsTotal(performanceTotal.setScale(2, RoundingMode.HALF_UP));
//2、修改订单返佣状态:已返佣 1
orderInfo.setRebateStatus(RebateStatusEnum.ALREADY_REBATE.getCode());
......@@ -127,10 +124,10 @@ public class AccountManager {
*/
@Transactional(rollbackFor = Exception.class)
public Boolean updateOrSavePrize(List<TeamPerformanceSortVo> listVo, List<AccountInfo> accountInfoList,
List<ProgressPrize> prizes) {
List<ProgressPrize> prizes, int flag) {
Date date = new Date();
String yearMonth = DateUtil.convertDateToStr(date, PATTERN);
//构造一个map key:userId value progressPrize
Map<String, ProgressPrize> map = new HashMap<>(32);
for (ProgressPrize progressPrize : prizes) {
......@@ -179,8 +176,9 @@ public class AccountManager {
addList.add(progress);
}
}
List<ProgressPrize> deleteList = new ArrayList<>(prizes);
//剩余的是要删除的
List<ProgressPrize> deleteList = new ArrayList<>(prizes);
for (ProgressPrize updatePrize : updateList) {
int count = progressPrizeMapper.edit(updatePrize);
if (count == 0) {
......@@ -212,7 +210,12 @@ public class AccountManager {
tradeRecord.setUserId(accountInfo.getUserId());
tradeRecord.setTradeType(TradeRecordEnum.PROGRESS_PRIZE.getCode());
tradeRecord.setTradeNo(null);
if (flag == 1) {
tradeRecord.setStatus(TradeStatusEnum.NO_SETTLE_ACCOUNTS.getCode());
} else {
tradeRecord.setStatus(TradeStatusEnum.ALREADY_SETTLE_ACCOUNTS.getCode());
}
int count = recordMapper.add(tradeRecord);
if (count == 0) {
return false;
......
......@@ -143,15 +143,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
//key 不存在,加入集合
map.put(userId, payMoney);
}
//累加订单成交额
totalMoney = totalMoney.add(orderInfo.getPayment());
}
//累计用户和上级用户-团队业绩
Map<String, Double> tempMap = new HashMap<>();
//遍历订单
for (Map.Entry<String, Double> entity : map.entrySet()) {
String userId = entity.getKey();
//1)、统计当前用户月度业绩
......@@ -223,14 +219,13 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
return R.ok(1, false);
}
return R.ok(0, true);
}
/**
* 获取用户的商机信息
* 获取用户的上级列表
*
* @param userId 用户id
* @return
* @return 用户的上级列表
*/
@Override
public List<User> getByList(String userId) {
......@@ -268,20 +263,15 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
Double twentyTotal = teamPerformanceMapper.countTwenty(yearMonth);
List<AccountInfo> accountInfoList = new ArrayList<>();
List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> prizeList=new ArrayList<>();
List<ProgressPrize> prizeList = new ArrayList<>();
for (TeamPerformance user : list) {
//用户是普通用户的,不计算最大进步奖
if (user.getUserLevel().equals(UserLevelEnum.NORMAL_USER.getCode())) {
continue;
}
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), 3);
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(),
MemberPercentEnum.MONTH_BEST_AWARD.getCode());
//计算收益
double userTeamPerformance = user.getMonthTeamPerformance().doubleValue();
double percent = memberPercent.getPercent().doubleValue();
double income = Math.floor(number * 3980 * percent * userTeamPerformance / twentyTotal);
//获取账户信息
......@@ -316,7 +306,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
}
//更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,prizeList);
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList, prizeList);
if (!bool) {
return R.ok(1, false);
}
......@@ -326,27 +316,22 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
//3、集合不为空 不是业绩开始的第一个月
//获取用户列表
List<User> userList = usersMapper.findAll();
List<User> userList = usersMapper.findAllNotZeroUser();
if (CollectionUtils.isEmpty(userList)) {
return R.ok(0, true);
}
//4计算每个用户本月的业绩增长率
//4计算每个用户本月的业绩增长率 如果集合大于20 ,取前二十名,小于,取全部
List<TeamPerformanceSortVo> listVo = progressPrizeStatistics(userList);
//5、如果集合大于20 ,取前二十名,小于,取全部
if (listVo.size() >= TWENTY) {
//取排名前20的
listVo.subList(0, TWENTY);
}
//计算前20的总业绩
//5、计算前20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
totalPerformanceIncome(listVo, number, total);
return R.ok(0, true);
} else {
//计算用户数少于20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
totalPerformanceIncome(listVo, number, total);
boolean bool = totalPerformanceIncome(listVo, number, total);
if (!bool) {
return R.ok(1, false);
}
return R.ok(0, true);
}
......@@ -358,7 +343,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
if (null != user && !StringUtils.isBlank(user.getBeInvitedCode())) {
User userInfo = usersMapper.getByBeInvitedCode(user.getBeInvitedCode());
if (null != userInfo) {
if(userInfo.getBeInvitedCode().equals(userInfo.getInviteCode())){
if (userInfo.getBeInvitedCode().equals(userInfo.getInviteCode())) {
return;
}
getUser(list, userInfo.getUserId());
......@@ -371,7 +356,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
*
* @param totalMoney 月金额总额
* @param userList 用户列表
* @return
* @return true or false
*/
private boolean monthlyIncome(BigDecimal totalMoney, List<User> userList) {
double total = totalMoney.doubleValue();
......@@ -497,7 +482,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
* @param number 个人业绩
* @param total 总业绩
*/
private void totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) {
private boolean totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) {
//要更新的账户列表
List<AccountInfo> updateAccountList = new ArrayList<>();
......@@ -533,6 +518,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
List<ProgressPrize> prizes = progressPrizeMapper.getByYearMonth(yearMonth);
//修改或保存最大进步奖信息
accountManager.updateOrSavePrize(listVo, updateAccountList, prizes);
// flag 1: 日定时任务 2:月定时任务
int flag = 1;
return accountManager.updateOrSavePrize(listVo, updateAccountList, prizes, flag);
}
}
......@@ -221,11 +221,6 @@ public class MonthTaskServiceImpl implements MonthTaskService {
List<TradeRecord> tradeRecordList = new ArrayList<>();
List<ProgressPrize> prizeList = new ArrayList<>();
for (TeamPerformance user : list) {
//用户是普通用户的,不计算最大进步奖
if (user.getUserLevel().equals(UserLevelEnum.NORMAL_USER.getCode())) {
continue;
}
//获取最大进步奖 百分比
MemberPercent memberPercent = memberPercentMapper.getByLevelAndType(user.getUserLevel(), 3);
......@@ -234,10 +229,8 @@ public class MonthTaskServiceImpl implements MonthTaskService {
double percent = memberPercent.getPercent().doubleValue();
double income = Math.floor(number * 3980 * percent * userTeamPerformance / twentyTotal);
//获取账户信息
//获取账户信息 用户月收益 =其他收益+最大进步奖收益
AccountInfo accountInfo = accountMapper.getByUserId(user.getUserId());
//用户月收益 =其他收益+最大进步奖收益
BigDecimal earningsMonth = accountInfo.getEarningsMonth().add(BigDecimal.valueOf(income));
accountInfo.setEarningsMonth(earningsMonth.setScale(2, RoundingMode.HALF_UP));
......@@ -266,7 +259,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
}
//更新账户信息,添加交易流水记录
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList,prizeList);
boolean bool = accountManager.updateAccountAddRecordAddPrize(accountInfoList, tradeRecordList, prizeList);
if (!bool) {
return R.ok(1, false);
}
......@@ -276,27 +269,22 @@ public class MonthTaskServiceImpl implements MonthTaskService {
//3、集合不为空 不是业绩开始的第一个月
//获取用户列表
List<User> userList = usersMapper.findAll();
List<User> userList = usersMapper.findAllNotZeroUser();
if (CollectionUtils.isEmpty(userList)) {
return R.ok(0, true);
}
//4计算每个用户本月的业绩增长率
//4计算每个用户本月的业绩增长率 如果集合大于20 ,取前二十名,小于,取全部
List<TeamPerformanceSortVo> listVo = progressPrizeStatistics(userList);
//5、如果集合大于20 ,取前二十名,小于,取全部
if (listVo.size() >= TWENTY) {
//取排名前20的
listVo.subList(0, TWENTY);
}
//计算前20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
totalPerformanceIncome(listVo, number, total);
return R.ok(0, true);
} else {
//计算用户数少于20的总业绩
//5、计算前20的总业绩
double total = listVo.stream().mapToDouble(TeamPerformanceSortVo::getMonthPerformance).sum();
totalPerformanceIncome(listVo, number, total);
boolean bool = totalPerformanceIncome(listVo, number, total);
if (!bool) {
return R.ok(1, false);
}
return R.ok(0, true);
}
......@@ -554,7 +542,7 @@ public class MonthTaskServiceImpl implements MonthTaskService {
* @param number 个人业绩
* @param total 总业绩
*/
private void totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) {
private boolean totalPerformanceIncome(List<TeamPerformanceSortVo> listVo, double number, double total) {
//要更新的账户列表
List<AccountInfo> updateAccountList = new ArrayList<>();
......@@ -590,6 +578,8 @@ public class MonthTaskServiceImpl implements MonthTaskService {
List<ProgressPrize> prizes = progressPrizeMapper.getByYearMonth(yearMonth);
//修改或保存最大进步奖信息
accountManager.updateOrSavePrize(listVo, updateAccountList, prizes);
// flag 1: 日定时任务 2:月定时任务
int flag = 2;
return accountManager.updateOrSavePrize(listVo, updateAccountList, prizes,flag);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment