分成逻辑修改、新增运营统计接口
This commit is contained in:
parent
19ce68a16a
commit
e722f2004e
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"java.compile.nullAnalysis.mode": "automatic",
|
||||
"java.configuration.updateBuildConfiguration": "interactive"
|
||||
"java.configuration.updateBuildConfiguration": "interactive",
|
||||
"java.format.settings.url": "eclipse-formatter.xml"
|
||||
}
|
|
@ -44,6 +44,13 @@ public interface BonusDashboard {
|
|||
* @param query 查询条件
|
||||
* @return 平台分成总金额
|
||||
*/
|
||||
BigDecimal selectSumOfPlatformAmount(BonusQuery query);
|
||||
BigDecimal selectSumOfPlatformAmount(BonusQuery query);
|
||||
|
||||
/**
|
||||
* 查询分成数量
|
||||
* @param query 查询条件
|
||||
* @return 分成数量
|
||||
*/
|
||||
Integer selectCount(BonusQuery query);
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class BonusDashboardImpl implements BonusDashboard {
|
|||
public BonusStatVO selectStat(BonusQuery query, List<String> keys) {
|
||||
BonusStatVO vo = new BonusStatVO();
|
||||
if (keys.contains(StatKeys.BONUS_COUNT)) {
|
||||
vo.setCount(MathUtils.dv(bonusMapper.selectCount(query)));
|
||||
vo.setCount(this.selectCount(query));
|
||||
}
|
||||
if (keys.contains(StatKeys.BONUS_AMOUNT)) {
|
||||
vo.setAmount(this.selectSumOfAmount(query));
|
||||
|
@ -62,6 +62,10 @@ public class BonusDashboardImpl implements BonusDashboard {
|
|||
bonusQuery.setArrivalTypes(BonusArrivalType.platformList());
|
||||
return selectSumOfAmount(bonusQuery);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer selectCount(BonusQuery query) {
|
||||
return MathUtils.dv(bonusMapper.selectCount(query));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class BonusUtil {
|
|||
|
||||
/**
|
||||
* 处理退款金额分配的误差
|
||||
*
|
||||
*
|
||||
* @param refundList 退款列表
|
||||
* @param bonusList 原始分成列表
|
||||
* @param dividedAmount 已分配金额
|
||||
|
@ -98,7 +98,7 @@ public class BonusUtil {
|
|||
|
||||
/**
|
||||
* 构建退款列表
|
||||
*
|
||||
*
|
||||
* @param bonusList 原始分成列表
|
||||
* @param refundAmount 需要退款总金额
|
||||
* @param payAmount 原支付金额
|
||||
|
@ -108,6 +108,9 @@ public class BonusUtil {
|
|||
if (CollectionUtils.isEmptyElement(bonusList) || refundAmount == null || payAmount == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (payAmount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Bonus> refundList = new ArrayList<>();
|
||||
BigDecimal dividedAmount = BigDecimal.ZERO; // 已分配金额
|
||||
|
||||
|
@ -163,7 +166,7 @@ public class BonusUtil {
|
|||
|
||||
/**
|
||||
* 分成金额
|
||||
*
|
||||
*
|
||||
* @param bonusList 分成列表
|
||||
* @param totalAmount 总金额
|
||||
*/
|
||||
|
|
|
@ -54,4 +54,8 @@ public class OrderQuery extends OrderVO {
|
|||
@ApiModelProperty("支付超时时间(开始)")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime payExpireTimeStart;
|
||||
}
|
||||
|
||||
@ApiModelProperty("结束日期范围")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private List<LocalDate> endDateRange;
|
||||
}
|
||||
|
|
|
@ -26,5 +26,5 @@ public class OrderStatVO {
|
|||
|
||||
@ApiModelProperty("订单状态数量")
|
||||
private Map<String, Integer> statusCount;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -162,4 +162,21 @@ public interface OrderMapper {
|
|||
*/
|
||||
List<Long> selectIdByQuery(@Param("query") OrderQuery query);
|
||||
|
||||
/**
|
||||
* 扣减实收金额
|
||||
*
|
||||
* @param id
|
||||
* @param amount
|
||||
* @return
|
||||
*/
|
||||
int subtractActualAmount(@Param("id") Long id, @Param("amount") BigDecimal amount);
|
||||
|
||||
/**
|
||||
* 查询订单实收金额
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @return 结果
|
||||
*/
|
||||
BigDecimal selectSumOfActualAmount(@Param("query") OrderQuery query);
|
||||
|
||||
}
|
||||
|
|
|
@ -142,6 +142,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
and date(bo.create_time) >= #{query.createDateRange[0]}
|
||||
and date(bo.create_time) <= #{query.createDateRange[1]}
|
||||
</if>
|
||||
<if test="query.endDateRange != null and query.endDateRange.size() > 1">
|
||||
and date(bo.end_time) >= #{query.endDateRange[0]}
|
||||
and date(bo.end_time) <= #{query.endDateRange[1]}
|
||||
</if>
|
||||
<if test="query.statusList != null and query.statusList.size() > 0"> and bo.status in
|
||||
<foreach item="item" collection="query.statusList" separator="," open="(" close=")">
|
||||
#{item}
|
||||
|
@ -478,4 +482,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</where>
|
||||
</select>
|
||||
|
||||
<!-- subtractActualAmount -->
|
||||
|
||||
<update id="subtractActualAmount">
|
||||
update bst_order bo
|
||||
set bo.actual_amount = bo.actual_amount - #{amount}
|
||||
where bo.id = #{id} and bo.actual_amount >= #{amount}
|
||||
</update>
|
||||
|
||||
|
||||
<!-- selectSumOfActualAmount -->
|
||||
|
||||
<select id="selectSumOfActualAmount" resultType="BigDecimal">
|
||||
select sum(bo.actual_amount)
|
||||
from <include refid="searchTables"/>
|
||||
<where>
|
||||
<include refid="searchCondition"/>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -87,4 +87,9 @@ public interface OrderDashboard {
|
|||
* 查询订单排行榜
|
||||
*/
|
||||
List<OrderRankVO> selectRank(OrderQuery query);
|
||||
|
||||
/**
|
||||
* 查询订单实收金额
|
||||
*/
|
||||
BigDecimal selectSumOfActualAmount(OrderQuery query);
|
||||
}
|
||||
|
|
|
@ -113,4 +113,9 @@ public class OrderDashboardImpl implements OrderDashboard {
|
|||
public List<OrderRankVO> selectRank(OrderQuery query) {
|
||||
return orderMapper.selectRank(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal selectSumOfActualAmount(OrderQuery query) {
|
||||
return MathUtils.dv(orderMapper.selectSumOfActualAmount(query));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -534,6 +534,10 @@ public class OrderServiceImpl implements OrderService {
|
|||
ServiceUtil.assertion(!bonusRefund, "ID为%s的订单分成退款失败", order.getId());
|
||||
}
|
||||
|
||||
// 订单实收扣减
|
||||
int sub = orderMapper.subtractActualAmount(order.getId(), amount);
|
||||
ServiceUtil.assertion(sub != 1, "订单实收金额扣减失败,请检查金额是否充足");
|
||||
|
||||
// 支付退款
|
||||
PayRefundDTO dto = new PayRefundDTO();
|
||||
dto.setId(order.getPayId());
|
||||
|
|
|
@ -178,7 +178,7 @@ public class OrderUtil {
|
|||
if (order == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return MathUtils.subtractDecimal(order.getPayAmount(), order.getPayRefunding(), order.getPayRefunded());
|
||||
return order.getActualAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,8 @@ public class StatKeys {
|
|||
public static final String ORDER_WAIT_VERIFY_COUNT = "order_wait_verify_count";
|
||||
// 订单状态数量
|
||||
public static final String ORDER_STATUS_COUNT = "order_status_count";
|
||||
// 订单实收金额
|
||||
public static final String ORDER_ACTUAL_AMOUNT = "order_actual_amount";
|
||||
|
||||
// 分成数量
|
||||
public static final String BONUS_COUNT = "bonus_count";
|
||||
|
@ -28,6 +30,8 @@ public class StatKeys {
|
|||
public static final String BONUS_REFUND_AMOUNT = "bonus_refund_amount";
|
||||
// 分成未入账金额
|
||||
public static final String BONUS_WAIT_DIVIDE_AMOUNT = "bonus_wait_divide_amount";
|
||||
// 分成实收金额
|
||||
public static final String BONUS_ACTUAL_AMOUNT = "bonus_actual_amount";
|
||||
|
||||
// 用户数量
|
||||
public static final String USER_COUNT = "user_count";
|
||||
|
@ -35,7 +39,7 @@ public class StatKeys {
|
|||
public static final String USER_TODAY_COUNT = "user_today_count";
|
||||
// 用户余额
|
||||
public static final String USER_BALANCE = "user_balance";
|
||||
// 运营商数量
|
||||
// 运营商数量
|
||||
public static final String USER_MCH_COUNT = "user_mch_count";
|
||||
// 代理商数量
|
||||
public static final String USER_AGENT_COUNT = "user_agent_count";
|
||||
|
@ -66,6 +70,6 @@ public class StatKeys {
|
|||
// 待审核的加盟商申请数量
|
||||
public static final String MCH_APPLY_APPROVING_COUNT = "mch_apply_approving_count";
|
||||
|
||||
// 待处理的故障数量
|
||||
// 待处理的故障数量
|
||||
public static final String FAULT_PENDING_COUNT = "fault_pending_count";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package com.ruoyi.dashboard.domain.revenueStat;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import com.ruoyi.bst.bonus.domain.BonusQuery;
|
||||
import com.ruoyi.bst.bonus.domain.enums.BonusStatus;
|
||||
import com.ruoyi.bst.bonusRefund.domain.BonusRefundQuery;
|
||||
import com.ruoyi.bst.order.domain.OrderQuery;
|
||||
import com.ruoyi.bst.order.domain.enums.OrderStatus;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RevenueStatQuery {
|
||||
@ApiModelProperty("日期范围")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private List<LocalDate> dateRange;
|
||||
|
||||
@ApiModelProperty("查询数据")
|
||||
private List<String> keys;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("运营区ID")
|
||||
private Long areaId;
|
||||
|
||||
@ApiModelProperty("数据隔离")
|
||||
private Boolean scope;
|
||||
|
||||
|
||||
private OrderQuery baseOrderQuery() {
|
||||
OrderQuery query = new OrderQuery();
|
||||
query.setStatusList(OrderStatus.valid());
|
||||
query.setUserId(userId);
|
||||
query.setAreaId(areaId);
|
||||
query.setScope(scope);
|
||||
return query;
|
||||
}
|
||||
|
||||
private BonusQuery baseBonusQuery() {
|
||||
BonusQuery query = new BonusQuery();
|
||||
query.setStatusList(BonusStatus.valid());
|
||||
query.setArrivalId(userId);
|
||||
query.setAreaId(areaId);
|
||||
query.setScope(scope);
|
||||
return query;
|
||||
}
|
||||
|
||||
private BonusRefundQuery baseBonusRefundQuery() {
|
||||
BonusRefundQuery query = new BonusRefundQuery();
|
||||
query.setBonusStatusList(BonusStatus.valid());
|
||||
query.setBonusArrivalId(userId);
|
||||
query.setBonusAreaId(areaId);
|
||||
query.setScope(scope);
|
||||
return query;
|
||||
}
|
||||
|
||||
public OrderQuery toOrderQuery() {
|
||||
OrderQuery query = baseOrderQuery();
|
||||
query.setCreateDateRange(dateRange);
|
||||
return query;
|
||||
}
|
||||
|
||||
public OrderQuery toOrderQueryForEnd() {
|
||||
OrderQuery query = baseOrderQuery();
|
||||
query.setEndDateRange(dateRange);
|
||||
return query;
|
||||
}
|
||||
|
||||
public BonusQuery toBonusQuery() {
|
||||
BonusQuery query = baseBonusQuery();
|
||||
query.setCreateDateRange(dateRange);
|
||||
return query;
|
||||
}
|
||||
|
||||
public BonusRefundQuery toBonusRefundQuery() {
|
||||
BonusRefundQuery query = baseBonusRefundQuery();
|
||||
query.setCreateDateRange(dateRange);
|
||||
return query;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.ruoyi.dashboard.domain.revenueStat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ruoyi.common.utils.MathUtils;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RevenueStatVO {
|
||||
|
||||
@ApiModelProperty("订单用户数量")
|
||||
private Integer orderUserCount;
|
||||
@ApiModelProperty("订单实收金额")
|
||||
private BigDecimal orderActualAmount;
|
||||
@ApiModelProperty("订单总数量")
|
||||
private Integer orderCount;
|
||||
@ApiModelProperty("订单状态数量")
|
||||
private Map<String, Integer> orderStatusMap;
|
||||
|
||||
@ApiModelProperty("分成总金额")
|
||||
private BigDecimal bonusAmount;
|
||||
@ApiModelProperty("分成退款金额")
|
||||
private BigDecimal bonusRefundAmount;
|
||||
@ApiModelProperty("分成数量")
|
||||
private Integer bonusCount;
|
||||
@ApiModelProperty("分成实收金额")
|
||||
public BigDecimal getBonusActualAmount() {
|
||||
return MathUtils.subtractDecimal(bonusAmount, bonusRefundAmount);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -21,8 +21,11 @@ import com.ruoyi.bst.order.domain.vo.OrderDailyStatVO;
|
|||
import com.ruoyi.bst.order.service.OrderDashboard;
|
||||
import com.ruoyi.bst.withdraw.service.WithdrawDashboard;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.dashboard.constants.StatKeys;
|
||||
import com.ruoyi.dashboard.domain.dailyStat.DailyStatQuery;
|
||||
import com.ruoyi.dashboard.domain.dailyStat.DailyStatVO;
|
||||
import com.ruoyi.dashboard.domain.revenueStat.RevenueStatQuery;
|
||||
import com.ruoyi.dashboard.domain.revenueStat.RevenueStatVO;
|
||||
import com.ruoyi.dashboard.domain.stat.StatQuery;
|
||||
import com.ruoyi.dashboard.domain.stat.StatVO;
|
||||
import com.ruoyi.dashboard.utils.DashboardUtil;
|
||||
|
@ -122,4 +125,39 @@ public class DashboardService {
|
|||
}
|
||||
|
||||
|
||||
public RevenueStatVO selectRevenueStat(RevenueStatQuery query) {
|
||||
RevenueStatVO vo = new RevenueStatVO();
|
||||
List<String> keys = query.getKeys();
|
||||
|
||||
// 订单用户数量
|
||||
if (keys.contains(StatKeys.ORDER_USER_COUNT)) {
|
||||
vo.setOrderUserCount(orderDashboard.selectUserCount(query.toOrderQuery()));
|
||||
}
|
||||
// 订单实收金额
|
||||
if (keys.contains(StatKeys.ORDER_ACTUAL_AMOUNT)) {
|
||||
vo.setOrderActualAmount(orderDashboard.selectSumOfActualAmount(query.toOrderQueryForEnd()));
|
||||
}
|
||||
// 订单数量
|
||||
if (keys.contains(StatKeys.ORDER_COUNT)) {
|
||||
vo.setOrderCount(orderDashboard.selectCount(query.toOrderQuery()));
|
||||
}
|
||||
// 订单状态数量
|
||||
if (keys.contains(StatKeys.ORDER_STATUS_COUNT)) {
|
||||
vo.setOrderStatusMap(orderDashboard.selectStatusCount(query.toOrderQuery()));
|
||||
}
|
||||
|
||||
// 分成总金额
|
||||
if (keys.contains(StatKeys.BONUS_AMOUNT) || keys.contains(StatKeys.BONUS_ACTUAL_AMOUNT)) {
|
||||
vo.setBonusAmount(bonusDashboard.selectSumOfAmount(query.toBonusQuery()));
|
||||
}
|
||||
// 分成退款金额
|
||||
if (keys.contains(StatKeys.BONUS_REFUND_AMOUNT) || keys.contains(StatKeys.BONUS_ACTUAL_AMOUNT)) {
|
||||
vo.setBonusRefundAmount(bonusRefundDashboard.selectSumOfUserBonusRefund(query.toBonusRefundQuery()));
|
||||
}
|
||||
// 分成数量
|
||||
if (keys.contains(StatKeys.BONUS_COUNT)) {
|
||||
vo.setBonusCount(bonusDashboard.selectCount(query.toBonusQuery()));
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.ruoyi.bst.refund.domain.enums.RefundStatus;
|
|||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.dashboard.domain.dailyStat.DailyStatQuery;
|
||||
import com.ruoyi.dashboard.domain.revenueStat.RevenueStatQuery;
|
||||
import com.ruoyi.dashboard.domain.stat.StatQuery;
|
||||
import com.ruoyi.dashboard.service.DashboardService;
|
||||
|
||||
|
@ -59,4 +60,10 @@ public class DashboardController extends BaseController {
|
|||
return success(dashboardService.selectDailyStat(query));
|
||||
}
|
||||
|
||||
@ApiOperation("获取营收统计")
|
||||
@PreAuthorize("@ss.hasAnyPermi('dashboard:revenue')")
|
||||
@GetMapping("/revenueStat")
|
||||
public AjaxResult getRevenueStat(RevenueStatQuery query) {
|
||||
return success(dashboardService.selectRevenueStat(query));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user