feat:消费统计修改

This commit is contained in:
dzc committed 2025-06-10 18:24:18 +08:00
1 parent b47948a825
commit f01abe0aab
5 files changed
+163 -36

No files matched your search

@@ -37,12 +37,16 @@ public class HardOrderDto extends HardOrderEntity implements BaseIsIncludeTreeIn
private LocalDateTime[] payTimeList;
private LocalDateTime[] refundTimeList;
private List<String> orderTypeCodes;
private List<String> orderPayTypeCodes;
private List<String> hardTypeCodes;
private List<String> refundStatusCodes;
/**
* 是否查询购物车列表
*/
@@ -17,6 +17,8 @@ public class HardOrderSumAndCountDto {
private List<String> orderStatusCodes;
private List<String> refundStatusCodes;
private LocalDateTime[] createTimeList;
private LocalDateTime[] refundTimeList;
@@ -112,14 +112,20 @@ public interface HardOrderMapper extends PjcloudBaseMapper<HardOrderEntity> {
List<HardOrderSbVo> listSb(@Param("dto") HardOrderDto dto, DataScope dataScope);
List<HardOrderSbVo> listRefundSb(@Param("dto") HardOrderDto refundDto, @Param("refundDataScope") DataScope refundDataScope);
List<HardOrderCsVo> listCs(@Param("dto") HardOrderDto dto, DataScope dataScope);
List<HardOrderCsVo> listRefundCs(@Param("dto") HardOrderDto refundDto, DataScope refundDataScope);
List<HardOrderCsVo> listCsByDay(@Param("dto") HardOrderDto totalDto);
HardOrderCsVo listCsTotal(@Param("dto") HardOrderDto totalDto);
List<HardOrderPayTypeVo> listOrerPayType(@Param("dto") HardOrderDto dto);
List<HardOrderPayTypeVo> listOrerRefundPayType(@Param("dto") HardOrderDto refundDto);
List<HardOrderSumAndCountVo> sumAndCount(@Param("dto") HardOrderSumAndCountDto dto);
List<HardOrderSumAndCountVo> refundSumAndCount(@Param("dto") HardOrderSumAndCountDto refundDto);
@@ -15,6 +15,8 @@ import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardRefundStatusEnum;
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleStatusEnum;
import com.bsd.pjcloud.hard.api.dto.manager.HardManagerDto;
import com.bsd.pjcloud.hard.api.dto.hard.CurrentUserHardTypeInfoDto;
import com.bsd.pjcloud.hard.api.dto.order.HardChartLatitudeVo;
@@ -40,6 +42,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -83,16 +86,13 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
List<HardOrderSbVo> totalList = hardOrderMapper.listSb(totalDto, totalDataScope);
// 扣款总流水
HardOrderDto refundDto = BeanUtil.toBean(dto, HardOrderDto.class);
refundDto.setPayTimeList(null);
refundDto.setRefundTimeList(dto.getPayTimeList());
refundDto.setRefundStatusCodes(List.of(HardSaleStatusEnum.COMPLETE.getStatus()));
refundDto.setOrderStatusCodes(HardOrderStatusEnum.getPayErrorCodes());
DataScope refundDataScope = DataScope.of().func(DataScopeFuncEnum.ALL);
refundDataScope.setScopeDeptName("merchant_dept_id");
List<HardOrderSbVo> refundList = hardOrderMapper.listSb(refundDto, refundDataScope);
// 消费净次数
HardOrderDto profitDto = BeanUtil.toBean(dto, HardOrderDto.class);
profitDto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
DataScope profitDataScope = DataScope.of().func(DataScopeFuncEnum.ALL);
profitDataScope.setScopeDeptName("merchant_dept_id");
List<HardOrderSbVo> profitList = hardOrderMapper.listSb(profitDto, profitDataScope);
List<HardOrderSbVo> refundList = hardOrderMapper.listRefundSb(refundDto, refundDataScope);
// 聚合一下数据
for (HardOrderSbVo v : totalList) {
// 退款
@@ -102,12 +102,21 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
v.setTotalRefundCount(i.getTotalPayCount());
});
}
// 消费净金额
if (ObjectUtil.isNotEmpty(v.getTotalPayPrice())) {
BigDecimal refundPrice = BigDecimal.ZERO;
if (ObjectUtil.isNotEmpty(v.getTotalRefundPrice())) {
refundPrice = v.getTotalRefundPrice();
}
v.setTotalProfitPrice(v.getTotalPayPrice().subtract(refundPrice));
}
// 消费净次数
if (ObjectUtil.isNotEmpty(profitList)) {
profitList.stream().filter(i -> ObjectUtil.equals(i.getHardId(), v.getHardId())).findFirst().ifPresent(i -> {
v.setTotalProfitPrice(i.getTotalPayPrice());
v.setTotalProfitCount(i.getTotalPayCount());
});
if (ObjectUtil.isNotEmpty(v.getTotalPayCount())) {
BigDecimal refundCount = BigDecimal.ZERO;
if (ObjectUtil.isNotEmpty(v.getTotalRefundCount())) {
refundCount = v.getTotalRefundCount();
}
v.setTotalProfitCount(v.getTotalPayCount().subtract(refundCount));
}
}
if (ObjectUtil.isNotEmpty(totalList)) {
@@ -149,16 +158,13 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
List<HardOrderCsVo> totalList = hardOrderMapper.listCs(totalDto, totalDataScope);
// 扣款总流水
HardOrderDto refundDto = BeanUtil.toBean(dto, HardOrderDto.class);
refundDto.setPayTimeList(null);
refundDto.setRefundTimeList(dto.getPayTimeList());
refundDto.setOrderStatusCodes(HardOrderStatusEnum.getPayErrorCodes());
refundDto.setRefundStatusCodes(List.of(HardSaleStatusEnum.COMPLETE.getStatus()));
DataScope refundDataScope = DataScope.of();
refundDataScope.setScopeDeptName("merchant_dept_id");
List<HardOrderCsVo> refundList = hardOrderMapper.listCs(refundDto, refundDataScope);
// 消费净次数
HardOrderDto profitDto = BeanUtil.toBean(dto, HardOrderDto.class);
profitDto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
DataScope profitDataScope = DataScope.of();
profitDataScope.setScopeDeptName("merchant_dept_id");
List<HardOrderCsVo> profitList = hardOrderMapper.listCs(profitDto, profitDataScope);
List<HardOrderCsVo> refundList = hardOrderMapper.listRefundCs(refundDto, refundDataScope);
for (HardOrderCsVo v : totalList) {
// 退款
if (ObjectUtil.isNotEmpty(refundList)) {
@@ -167,12 +173,21 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
v.setTotalRefundCount(i.getTotalPayCount());
});
}
// 消费净金额
if (ObjectUtil.isNotEmpty(v.getTotalPayPrice())) {
BigDecimal refundPrice = BigDecimal.ZERO;
if (ObjectUtil.isNotEmpty(v.getTotalRefundPrice())) {
refundPrice = v.getTotalRefundPrice();
}
v.setTotalProfitPrice(v.getTotalPayPrice().subtract(refundPrice));
}
// 消费净次数
if (ObjectUtil.isNotEmpty(profitList)) {
profitList.stream().filter(i -> ObjectUtil.equals(i.getMerchantId(), v.getMerchantId())).findFirst().ifPresent(i -> {
v.setTotalProfitPrice(i.getTotalPayPrice());
v.setTotalProfitCount(i.getTotalPayCount());
});
if (ObjectUtil.isNotEmpty(v.getTotalPayCount())) {
BigDecimal refundCount = BigDecimal.ZERO;
if (ObjectUtil.isNotEmpty(v.getTotalRefundCount())) {
refundCount = v.getTotalRefundCount();
}
v.setTotalProfitCount(v.getTotalPayCount().subtract(refundCount));
}
}
// 聚合一下数据
@@ -396,6 +411,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
HardOrderSumAndCountDto refundDto = new HardOrderSumAndCountDto();
refundDto.setUserDeptIds(deptIds);
refundDto.setOrderStatusCodes(HardOrderStatusEnum.getPayErrorCodes());
refundDto.setRefundStatusCodes(List.of(HardSaleStatusEnum.COMPLETE.getStatus()));
if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) {
refundDto.setRefundTimeList(dto.getCreateTimeList());
}
@@ -490,14 +506,12 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
List<HardOrderPayTypeVo> totalList = hardOrderMapper.listOrerPayType(totalDto);
// 扣款总流水
HardOrderDto refundDto = BeanUtil.toBean(dto, HardOrderDto.class);
refundDto.setPayTimeList(null);
refundDto.setRefundTimeList(dto.getPayTimeList());
refundDto.setOrderStatusCodes(HardOrderStatusEnum.getPayErrorCodes());
refundDto.setRefundStatusCodes(List.of(HardSaleStatusEnum.COMPLETE.getStatus()));
refundDto.setOrderPayTypeCodes(payTypeList);
List<HardOrderPayTypeVo> refundList = hardOrderMapper.listOrerPayType(refundDto);
// 盈利
HardOrderDto profitDto = BeanUtil.toBean(dto, HardOrderDto.class);
profitDto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
profitDto.setOrderPayTypeCodes(payTypeList);
List<HardOrderPayTypeVo> profitList = hardOrderMapper.listOrerPayType(profitDto);
List<HardOrderPayTypeVo> refundList = hardOrderMapper.listOrerRefundPayType(refundDto);
for (HardOrderPayTypeVo v : totalList) {
// 退款
if (ObjectUtil.isNotEmpty(refundList)) {
@@ -506,12 +520,21 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
v.setTotalRefundCount(i.getTotalPayCount());
});
}
// 盈利
if (ObjectUtil.isNotEmpty(profitList)) {
profitList.stream().filter(i -> ObjectUtil.equals(i.getPayType(), v.getPayType())).findFirst().ifPresent(i -> {
v.setTotalProfitPrice(i.getTotalPayPrice());
v.setTotalProfitCount(i.getTotalPayCount());
});
// 消费净金额
if (ObjectUtil.isNotEmpty(v.getTotalPayPrice())) {
BigDecimal refundPrice = BigDecimal.ZERO;
if (ObjectUtil.isNotEmpty(v.getTotalRefundPrice())) {
refundPrice = v.getTotalRefundPrice();
}
v.setTotalProfitPrice(v.getTotalPayPrice().subtract(refundPrice));
}
// 消费净次数
if (ObjectUtil.isNotEmpty(v.getTotalPayCount())) {
BigDecimal refundCount = BigDecimal.ZERO;
if (ObjectUtil.isNotEmpty(v.getTotalRefundCount())) {
refundCount = v.getTotalRefundCount();
}
v.setTotalProfitCount(v.getTotalPayCount().subtract(refundCount));
}
}
return totalList;
@@ -242,6 +242,38 @@
group by a.hard_id
</select>
<select id="listRefundSb" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo">
select a.hard_id,
a.merchant_id,
a.user_dept_id,
a.merchant_dept_id,
sum(r.refund_price) as totalPayPrice,
count(0) as totalPayCount
from hard_after_sale r
inner join hard_order a on r.order_id = a.id and r.del_flag = '0'
left join hard_manager m on a.hard_id = m.id
<where>
<include refid="whereA"/>
and a.hard_id is not null
<if test="dto.hardTypeCodes != null and dto.hardTypeCodes.size() != 0">
and m.type in
<foreach collection="dto.hardTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.refundTimeList != null and dto.refundTimeList.length == 2">
and r.audit_time between #{dto.refundTimeList[0]} and #{dto.refundTimeList[1]}
</if>
<if test="dto.refundStatusCodes != null and dto.refundStatusCodes.size() != 0">
and r.status in
<foreach collection="dto.refundStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by a.hard_id
</select>
<select id="listCs" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo">
select
a.merchant_id,
@@ -270,6 +302,37 @@
ELSE 5 END
</select>
<select id="listRefundCs" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo">
select a.merchant_id,
a.user_dept_id,
a.merchant_dept_id,
sum(ifnull(r.refund_price, 0)) as totalPayPrice,
count(0) as totalPayCount
from hard_after_sale r
inner join hard_order a on a.id = r.order_id and r.del_flag = '0'
<where>
<include refid="whereA"/>
and a.merchant_id is not null
<if test="dto.refundTimeList != null and dto.refundTimeList.length == 2">
and r.audit_time between #{dto.refundTimeList[0]} and #{dto.refundTimeList[1]}
</if>
<if test="dto.refundStatusCodes != null and dto.refundStatusCodes.size() != 0">
and r.status in
<foreach collection="dto.refundStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by a.merchant_id
order by
CASE a.merchant_type
WHEN 1 THEN 1
WHEN 3 THEN 2
WHEN 0 THEN 3
WHEN 2 THEN 4
ELSE 5 END
</select>
<select id="listCsByDay" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo">
select a.merchant_id,
DATE_FORMAT(a.create_time, '%Y-%m-%d') as day,
@@ -306,6 +369,29 @@
group by a.pay_type
</select>
<select id="listOrerRefundPayType" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderPayTypeVo">
select a.pay_type,
a.merchant_dept_id,
sum(r.refund_price) as totalPayPrice,
count(0) as totalPayCount
from hard_after_sale r
inner join hard_order a
on r.order_id = a.id and r.del_flag = '0' and r.tenant_id = 1 and a.tenant_id = 1
<where>
<include refid="whereA"/>
<if test="dto.refundTimeList != null and dto.refundTimeList.length == 2">
and r.audit_time between #{dto.refundTimeList[0]} and #{dto.refundTimeList[1]}
</if>
<if test="dto.refundStatusCodes != null and dto.refundStatusCodes.size() != 0">
and r.status in
<foreach collection="dto.refundStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
group by a.pay_type
</select>
<select id="sumAndCount" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderSumAndCountVo">
select
a.user_dept_id as deptId,
@@ -366,6 +452,12 @@
<if test="dto.refundTimeList != null and dto.refundTimeList.length == 2">
and a.audit_time between #{dto.refundTimeList[0]} and #{dto.refundTimeList[1]}
</if>
<if test="dto.refundStatusCodes != null and dto.refundStatusCodes.size() != 0">
and a.status in
<foreach collection="dto.refundStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.mchIds != null and dto.mchIds.size() != 0">
and o.merchant_id in
<foreach collection="dto.mchIds" item="v" open="(" close=")" separator=",">