提成明细优化

This commit is contained in:
xiezhijun
2021-03-28 17:38:38 +08:00
parent b90eff14b0
commit b87b96d46e
3 changed files with 178 additions and 119 deletions

View File

@ -42,12 +42,18 @@ public class SysOrderCommisionDayDetail extends BaseEntity {
/**赠送天数*/
private Integer giveDay;
/**订单金额*/
/**订单金额或服务订单金额*/
private BigDecimal orderAmount;
/**订单总提成**/
private BigDecimal orderCommission;
//已发放提成
private BigDecimal hasSendOrderCommission;
//未发放提成
private BigDecimal notHasSendOrderCommission;
/**服务天数*/
private Integer serverDay;

View File

@ -52,7 +52,8 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService {
sysCommissionDayDetail.setNickName(commision.getUserName());
sysCommissionDayDetail.setPostId(commision.getPostId());
sysCommissionDayDetail.setPostName(commision.getPostName());
dealServerOrderCommissionDetail(orderDetailMap.get(sysCommissionDayDetail.getUserId()), sysCommissionDayDetail);
dealServerOrderCommissionDetail(sysCommision, orderDetailMap.get(sysCommissionDayDetail.getUserId()), sysCommissionDayDetail);
result.add(sysCommissionDayDetail);
//统计所以用户总提成、已发放提成、未发放提成
total.setTotalCommissionAmount(total.getTotalCommissionAmount().add(sysCommissionDayDetail.getTotalCommissionAmount()));
@ -150,38 +151,12 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService {
//根据用户ID获取对应订单列表
List<SysOrderCommisionDayDetail> orderDetailList = orderUserMap.get(userId);
for(SysOrderCommisionDayDetail sysOrderCommisionDayDetail : orderDetailList){
String yearMonth = sysOrderCommisionDayDetail.getOrderTime().getYear() + "" + sysOrderCommisionDayDetail.getOrderTime().getMonth().getValue();
sysOrderCommisionDayDetail.setMonthOrderTotalAmount(everyMonthTotalAmountMap.get(yearMonth));
sysOrderCommisionDayDetail.setCommissionRate(rateMap.get(yearMonth));
//计算该笔订单总提成
sysOrderCommisionDayDetail.setOrderCommission(getMoney(sysOrderCommisionDayDetail.getOrderAmount().doubleValue() * sysOrderCommisionDayDetail.getCommissionRate() / 100D));
//每年每月提成
Map<String, BigDecimal> everyYearMonthServerCommission = new TreeMap<>(new MyComparator());
//每年每月提成是否发放状态
Map<String, Boolean> everyYearMonthCommissionSendFlag = new TreeMap<>(new MyComparator());
//当前订单的提成总和
BigDecimal currentOrderCommission = BigDecimal.valueOf(0);
for (String everyMonth : sysOrderCommisionDayDetail.getEveryYearMonthServerMoney().keySet()) {
if(everyMonth.equals(sysOrderCommisionDayDetail.getServerEndDate().getYear()+""+sysOrderCommisionDayDetail.getServerEndDate().getMonth().getValue())){
//最后一个月的提成直接相减,避免误差
everyYearMonthServerCommission.put(everyMonth, sysOrderCommisionDayDetail.getOrderCommission().subtract(currentOrderCommission));
}else{
everyYearMonthServerCommission.put(everyMonth, getMoney(sysOrderCommisionDayDetail.getEveryYearMonthServerMoney().get(everyMonth).doubleValue() * sysOrderCommisionDayDetail.getCommissionRate() / 100D));
}
//判断是否已发放
if(isSendCommissionByYearMonth(everyMonth)){
everyYearMonthCommissionSendFlag.put(everyMonth, true);
totalSendCommission = totalSendCommission.add(everyYearMonthServerCommission.get(everyMonth));
}else{
everyYearMonthCommissionSendFlag.put(everyMonth, false);
totalNotSendCommission = totalNotSendCommission.add(everyYearMonthServerCommission.get(everyMonth));
}
currentOrderCommission = currentOrderCommission.add(everyYearMonthServerCommission.get(everyMonth));
}
sysOrderCommisionDayDetail.setEveryYearMonthServerCommission(everyYearMonthServerCommission);
sysOrderCommisionDayDetail.setEveryYearMonthCommissionSendFlag(everyYearMonthCommissionSendFlag);
//处理订单提成
dealCommissionByOrderCommisionDayDetail(sysOrderCommisionDayDetail, everyMonthTotalAmountMap, rateMap);
totalCommission = totalCommission.add(sysOrderCommisionDayDetail.getOrderCommission());
totalServerAmount = totalServerAmount.add(sysOrderCommisionDayDetail.getOrderAmount());
totalSendCommission = totalSendCommission.add(sysOrderCommisionDayDetail.getHasSendOrderCommission());
totalNotSendCommission = totalNotSendCommission.add(sysOrderCommisionDayDetail.getNotHasSendOrderCommission());
}
result = AjaxResult.success();
int total = sysOrderMapper.selectSimpleOrderMessageCount(sysCommision);
@ -194,72 +169,137 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService {
return result;
}
/**
* 根据用户ID统计出该用户在该月所有订单的服务数量、服务总天数、服务订单总额、暂停总天数
* **/
public void dealServerOrderCommissionDetail(List<SysOrderCommisionDayDetail> orderDetailList, SysCommissionDayDetail sysCommissionDayDetail){
public void dealServerOrderCommissionDetail(SysCommision commisionParam, List<SysOrderCommisionDayDetail> orderDetailList, SysCommissionDayDetail sysCommissionDayDetail){
//总提成
BigDecimal totalCommissionAmount = new BigDecimal(0);
//已发提成
BigDecimal totalHasSentCommissionAmount = new BigDecimal(0);
//未发提成记录
List<Map<String, Object>> sendDetailList = new ArrayList<>();
if(orderDetailList != null){
//获取每个月的成交总额度
Map<String, BigDecimal> orderAmount = new TreeMap<>(new MyComparator());
Set<String> commissionMonthSet = new TreeSet<>(new MyComparator());
for (SysOrderCommisionDayDetail sysOrderCommisionDayDetail : orderDetailList) {
String yearMonth = sysOrderCommisionDayDetail.getOrderTime().getYear()+""+sysOrderCommisionDayDetail.getOrderTime().getMonth().getValue();
if(orderAmount.containsKey(yearMonth)){
orderAmount.put(yearMonth, orderAmount.get(yearMonth).add(sysOrderCommisionDayDetail.getOrderAmount()));
}else{
orderAmount.put(yearMonth, sysOrderCommisionDayDetail.getOrderAmount());
}
commissionMonthSet.addAll(sysOrderCommisionDayDetail.getEveryYearMonthServerMoney().keySet());
}
//获取提成比例以及计算提成
Map<String, Float> rateMap = getRateByAmount(sysCommissionDayDetail.getUserId(), sysCommissionDayDetail.getPostId(), orderAmount);
sysCommissionDayDetail.setTotalCommissionAmount(BigDecimal.valueOf(0));
//总共已发提成
sysCommissionDayDetail.setTotalHasSentCommissionAmount(BigDecimal.valueOf(0));
//总共未发提成
sysCommissionDayDetail.setTotalNotSentCommissionAmount(BigDecimal.valueOf(0));
//提成发放计划
sysCommissionDayDetail.setSendDetailList(new ArrayList<>());
//下月应发提成
sysCommissionDayDetail.setNextMonthCommission(BigDecimal.valueOf(0));
int i = 1;
BigDecimal commissionA = new BigDecimal(0);
for (String ym : commissionMonthSet) {
BigDecimal ym_mession = new BigDecimal(0);
if(orderAmount.containsKey(ym)){
totalCommissionAmount = totalCommissionAmount.add(getMoney(orderAmount.get(ym).doubleValue() * rateMap.get(ym) / 100D));
if(orderDetailList == null || orderDetailList.size() == 0 ){
return;
}
//总提成
BigDecimal totalCommissionAmount = BigDecimal.valueOf(0);
//已发放提成
BigDecimal totalHasSentCommissionAmount = BigDecimal.valueOf(0);
//未发放提成
BigDecimal totalNotHasSentCommissionAmount = BigDecimal.valueOf(0);
//已发放提成记录
List<Map<String, Object>> hasSendYearMonthDetailList = new ArrayList<>();
//未发放提成计划
List<Map<String, Object>> notHasSendYearMonthDetailList = new ArrayList<>();
//获取每个月的成交总额度
commisionParam.setUserId(sysCommissionDayDetail.getUserId());
List<EveryMonthTotalAmount> everyMonthTotalAmountList = sysOrderMapper.getTotalAmountByUserId(commisionParam);
if(everyMonthTotalAmountList == null || everyMonthTotalAmountList.size() == 0){
return;
}
Map<String, BigDecimal> everyMonthTotalAmountMap = new TreeMap<>(new MyComparator());
for (EveryMonthTotalAmount everyMonthTotalAmount : everyMonthTotalAmountList) {
everyMonthTotalAmountMap.put(everyMonthTotalAmount.getYearMonth(), everyMonthTotalAmount.getTotalAmount());
}
//获取每个月的提成比例以及计算提成
Map<String, Float> rateMap = getRateByAmount(sysCommissionDayDetail.getUserId(), sysCommissionDayDetail.getPostId(), everyMonthTotalAmountMap);
//存在提成的年月
Set<String> commissionYearMonthSet = new TreeSet<>(new MyComparator());
for (SysOrderCommisionDayDetail sysOrderCommisionDayDetail : orderDetailList) {
//处理订单提成
dealCommissionByOrderCommisionDayDetail(sysOrderCommisionDayDetail, everyMonthTotalAmountMap, rateMap);
//合并每个订单的年月日
commissionYearMonthSet.addAll(sysOrderCommisionDayDetail.getEveryYearMonthServerCommission().keySet());
//合计总提成
totalCommissionAmount = totalCommissionAmount.add(sysOrderCommisionDayDetail.getOrderCommission());
//合计已发放提成
totalHasSentCommissionAmount = totalHasSentCommissionAmount.add(sysOrderCommisionDayDetail.getHasSendOrderCommission());
//合计未发放提成
totalNotHasSentCommissionAmount = totalNotHasSentCommissionAmount.add(sysOrderCommisionDayDetail.getNotHasSendOrderCommission());
}
for (String yearMonth : commissionYearMonthSet) {
Map<String, Object> map = new HashMap<>();
BigDecimal yearMonthCommiss = BigDecimal.valueOf(0);
for (SysOrderCommisionDayDetail sysOrderCommisionDayDetail : orderDetailList) {
if(sysOrderCommisionDayDetail.getEveryYearMonthServerCommission().containsKey(yearMonth)){
yearMonthCommiss = yearMonthCommiss.add(sysOrderCommisionDayDetail.getEveryYearMonthServerCommission().get(yearMonth));
}
for (SysOrderCommisionDayDetail sysOrderCommisionDayDetail : orderDetailList) {
Map<String, BigDecimal> everyYearMonthServerMoney = sysOrderCommisionDayDetail.getEveryYearMonthServerMoney();
if(everyYearMonthServerMoney.containsKey(ym)){
String orderYearMonth = sysOrderCommisionDayDetail.getOrderTime().getYear()+""+sysOrderCommisionDayDetail.getOrderTime().getMonth().getValue();
BigDecimal m = (everyYearMonthServerMoney.get(ym) == null) ? new BigDecimal(0) : everyYearMonthServerMoney.get(ym);
ym_mession = ym_mession.add(getMoney(m.doubleValue() * rateMap.get(orderYearMonth) / 100D));
}
}
if(isSendCommissionByYearMonth(ym)){
totalHasSentCommissionAmount = totalHasSentCommissionAmount.add(ym_mession);
}else{
Map<String, Object> map = new HashMap<>();
map.put("yearMonth", ym);
if(i != commissionMonthSet.size()){
//计算未发放的提成(除最后一个月)
commissionA = commissionA.add(ym_mession);
map.put("yearMonthCommission", ym_mession);
}else{
//最后一个月除去已发放的月份的提成,再减去前面未发放提成,防止出现误差
map.put("yearMonthCommission", totalCommissionAmount.subtract(totalHasSentCommissionAmount).subtract(commissionA));
}
sendDetailList.add(map);
}
i++;
}
map.put("yearMonth", yearMonth);
map.put("yearMonthCommission", yearMonthCommiss);
if(isSendCommissionByYearMonth(yearMonth)){
hasSendYearMonthDetailList.add(map);
}else{
notHasSendYearMonthDetailList.add(map);
}
}
sysCommissionDayDetail.setTotalCommissionAmount(totalCommissionAmount);
sysCommissionDayDetail.setTotalHasSentCommissionAmount(totalHasSentCommissionAmount);
//未发放提成 = 总提成 - 已发放提成
sysCommissionDayDetail.setTotalNotSentCommissionAmount(totalCommissionAmount.subtract(totalHasSentCommissionAmount));
sysCommissionDayDetail.setSendDetailList(sendDetailList);
sysCommissionDayDetail.setNextMonthCommission(sendDetailList.size() > 0 ? (BigDecimal)sendDetailList.get(0).get("yearMonthCommission") : new BigDecimal(0));
sysCommissionDayDetail.setTotalNotSentCommissionAmount(totalNotHasSentCommissionAmount);
sysCommissionDayDetail.setSendDetailList(notHasSendYearMonthDetailList);
sysCommissionDayDetail.setNextMonthCommission(notHasSendYearMonthDetailList.size() > 0 ? (BigDecimal)notHasSendYearMonthDetailList.get(0).get("yearMonthCommission") : new BigDecimal(0));
}
/**
* 处理每个订单的提成,包括已发放、未发放提成
* @param sysOrderCommisionDayDetail 订单服务详情对象
* @param everyMonthTotalAmountMap 每个月成交总额
* @param rateMap 提成比例
*/
public void dealCommissionByOrderCommisionDayDetail(SysOrderCommisionDayDetail sysOrderCommisionDayDetail, Map<String, BigDecimal> everyMonthTotalAmountMap, Map<String, Float> rateMap){
String yearMonth = sysOrderCommisionDayDetail.getOrderTime().getYear() + "" + sysOrderCommisionDayDetail.getOrderTime().getMonth().getValue();
//该笔订单当月的成交总额
sysOrderCommisionDayDetail.setMonthOrderTotalAmount(everyMonthTotalAmountMap.get(yearMonth));
//该笔订单对应提成比例
sysOrderCommisionDayDetail.setCommissionRate(rateMap.get(yearMonth));
//计算该笔订单总提成
sysOrderCommisionDayDetail.setOrderCommission(getMoney(sysOrderCommisionDayDetail.getOrderAmount().doubleValue() * sysOrderCommisionDayDetail.getCommissionRate() / 100D));
//每年每月提成
Map<String, BigDecimal> everyYearMonthServerCommission = new TreeMap<>(new MyComparator());
//每年每月提成是否发放状态
Map<String, Boolean> everyYearMonthCommissionSendFlag = new TreeMap<>(new MyComparator());
//当前订单的提成总和,用于最后一个月相减
BigDecimal currentOrderCommission = BigDecimal.valueOf(0);
//已发放提成金额
BigDecimal totalSendCommission = BigDecimal.valueOf(0);
//未发放提成金额
BigDecimal totalNotSendCommission = BigDecimal.valueOf(0);
for (String everyMonth : sysOrderCommisionDayDetail.getEveryYearMonthServerMoney().keySet()) {
if(everyMonth.equals(sysOrderCommisionDayDetail.getServerEndDate().getYear()+""+sysOrderCommisionDayDetail.getServerEndDate().getMonth().getValue())){
//最后一个月的提成直接相减,避免误差
everyYearMonthServerCommission.put(everyMonth, sysOrderCommisionDayDetail.getOrderCommission().subtract(currentOrderCommission));
}else{
everyYearMonthServerCommission.put(everyMonth, getMoney(sysOrderCommisionDayDetail.getEveryYearMonthServerMoney().get(everyMonth).doubleValue() * sysOrderCommisionDayDetail.getCommissionRate() / 100D));
}
//判断是否已发放
if(isSendCommissionByYearMonth(everyMonth)){
everyYearMonthCommissionSendFlag.put(everyMonth, true);
totalSendCommission = totalSendCommission.add(everyYearMonthServerCommission.get(everyMonth));
}else{
everyYearMonthCommissionSendFlag.put(everyMonth, false);
totalNotSendCommission = totalNotSendCommission.add(everyYearMonthServerCommission.get(everyMonth));
}
currentOrderCommission = currentOrderCommission.add(everyYearMonthServerCommission.get(everyMonth));
}
sysOrderCommisionDayDetail.setEveryYearMonthServerCommission(everyYearMonthServerCommission);
sysOrderCommisionDayDetail.setEveryYearMonthCommissionSendFlag(everyYearMonthCommissionSendFlag);
sysOrderCommisionDayDetail.setHasSendOrderCommission(totalSendCommission);
sysOrderCommisionDayDetail.setNotHasSendOrderCommission(totalNotSendCommission);
}
/**判断该月提成是否已发放*/
@ -411,7 +451,7 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService {
//服务总天数
int realServerDay = getTotalByMap(realEveryYearMonthServerDay);
//每年每月对于金额
Map<String, BigDecimal> realEveryYearMonthServerMoney = getEveryMonthServerMoney(realEveryYearMonthServerDay, orderAmount, dayMoney, serverEndDate);
Map<String, BigDecimal> realEveryYearMonthServerMoney = getRealEveryMonthServerMoney(realEveryYearMonthServerDay, orderAmount, dayMoney, serverEndDate, everyYearMonthServerDay, everyYearMonthServerMoney);
//服务时间范围内暂停天数
sysOrderCommisionDayDetail.setPauseTotalDay(realPauseTotalDay);
sysOrderCommisionDayDetail.setEveryYearMonthPauseDay(realEveryYearMonthPauseDay);
@ -528,13 +568,10 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService {
public Map<String, BigDecimal> getEveryMonthServerMoney(Map<String, Integer> everyMonthServerDay, BigDecimal orderMoney, BigDecimal dayMoney, LocalDate serverEndTime){
Map<String, BigDecimal > everyMonthServerMoney = new TreeMap<>(new MyComparator());
Set<String> keySet = everyMonthServerDay.keySet();
int i = 1;
BigDecimal total = BigDecimal.valueOf(0);
for(String key : keySet){
//System.out.println(serverEndTime.getYear()+""+serverEndTime.getMonth().getValue());
//判断是否为最后一个月
if(key.equals(serverEndTime.getYear()+""+serverEndTime.getMonth().getValue())){
System.out.println(key);
//由于小数保留问题,最后一个月的金额等于总额减去前几个月金额,避免总数不一致
everyMonthServerMoney.put(key, orderMoney.subtract(total));
}else{
@ -545,6 +582,40 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService {
return everyMonthServerMoney;
}
/**
* 获取订单服务时间范围中每年每月服务金额
* @Param everyMonthServerDay 真正每年每月服务天数
* @Param orderMoney 订单总额
* @Param dayMoney 每天对于金额
* @Param serverEndTime 订单服务结束时间
* @Param everyYearMonthServerDay 整个订单的每年每月服务天数
* @Param everyYearMonthServerMoney 整个订单的每年每月服务金额
* */
public Map<String, BigDecimal> getRealEveryMonthServerMoney(Map<String, Integer> realEveryMonthServerDay, BigDecimal orderMoney, BigDecimal dayMoney, LocalDate serverEndTime,
Map<String, Integer> everyYearMonthServerDay, Map<String, BigDecimal> everyYearMonthServerMoney){
Map<String, BigDecimal > everyMonthServerMoney = new TreeMap<>(new MyComparator());
Set<String> keySet = realEveryMonthServerDay.keySet();
BigDecimal total = null;
String lastMonth = serverEndTime.getYear()+""+serverEndTime.getMonth().getValue();
for(String key : keySet){
//判断是否为最后一个月,以及实际这个月的服务时间是否等于该整个订单最后一个月的天数
if(key.equals(lastMonth) && realEveryMonthServerDay.get(key).intValue() == everyYearMonthServerDay.get(key).intValue() ){
//由于小数保留问题,最后一个月的金额等于总额减去前几个月金额,避免总数不一致
total = BigDecimal.valueOf(0);
//获取该笔订单除最后一个月的金额总和
for (String orderYearMonth : everyYearMonthServerMoney.keySet()) {
if(!orderYearMonth.equals(lastMonth)){
total = total.add(everyYearMonthServerMoney.get(orderYearMonth));
}
}
everyMonthServerMoney.put(key, orderMoney.subtract(total));
}else{
everyMonthServerMoney.put(key, getMoney(realEveryMonthServerDay.get(key) * dayMoney.doubleValue()));
}
}
return everyMonthServerMoney;
}
/**
* 根据订单服务开始日期、订单服务结束日期、营养师或售后实际开始时间、营养师或售后实际结束时间,统计出实际时间范围内每年每月对应的天数
* */
@ -618,31 +689,12 @@ public class SysCommissionDayServiceImpl implements ISysCommissionDayService {
@Override
public int compare(String o1, String o2) {
return Integer.parseInt(o1) - Integer.parseInt(o2);
if(o1.substring(0,4).equals(o2.substring(0,4))){
return Integer.parseInt(o1.substring(4)) - Integer.parseInt(o2.substring(4));
}else{
return Integer.parseInt(o1.substring(0,4)) - Integer.parseInt(o2.substring(0,4));
}
}
}
public static void main(String[] args){
Double s = 31190.1;
/* NumberFormat nf = NumberFormat.getNumberInstance();
// 保留小数位数
nf.setMaximumFractionDigits(1);
// 如果不需要四舍五入,可以使用
nf.setRoundingMode(RoundingMode.DOWN);
System.out.println(Double.parseDouble(nf.format(s)));
System.out.println( new BigDecimal(nf.format(s)).doubleValue());*/
/*System.out.println(new BigDecimal(s).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
LocalDate localDate = LocalDate.of(2020, 1, 15);
System.out.println(ChronoUnit.MONTHS.between(localDate, LocalDate.now()));
System.out.println(localDate.getDayOfMonth());
System.out.println(localDate.getDayOfWeek());
System.out.println(localDate.getDayOfYear());
System.out.println(ChronoUnit.DAYS.between(LocalDate.of(2021, 1,14), LocalDate.now()));*/
/*System.out.println(ts(109792.8 * 6 / 100D, 1));
System.out.println(ts(6587.8,2).doubleValue());*/
}
}

View File

@ -157,11 +157,11 @@
@click="openFormDialog('查看发放计划', scope.row)"
>查看发放计划</el-button
>
<!--<el-button
<el-button
type="text"
@click="handleDetailClick(scope.row)"
>查看订单详情</el-button
>-->
>
</template>
</el-table-column>
@ -186,6 +186,7 @@
:data="sendCommissionPlan.list"
show-summary
:summary-method="getSummaries"
style="height:400px;overflow: auto"
>
<el-table-column
property="nickName"
@ -214,7 +215,7 @@
<OrdercommissDetail ref="ordercommissDetailRef"></OrdercommissDetail>
</div>
</template>
<style>