店铺报表修改

This commit is contained in:
磷叶 2025-02-01 20:35:46 +08:00
parent 2669b9a2f2
commit e9c06867d6
15 changed files with 408 additions and 177 deletions

View File

@ -13,7 +13,7 @@ import java.sql.SQLException;
* @author wjh
* 2024/4/12
*/
public class NonNullIntegerTyperHandler extends BaseTypeHandler<Integer> {
public class NonNullIntegerTypeHandler extends BaseTypeHandler<Integer> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Integer parameter, JdbcType jdbcType) throws SQLException {

View File

@ -13,7 +13,7 @@ import java.sql.SQLException;
* @author wjh
* 2024/4/12
*/
public class NonNullLongTyperHandler extends BaseTypeHandler<Long> {
public class NonNullLongTypeHandler extends BaseTypeHandler<Long> {
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Long parameter, JdbcType jdbcType) throws SQLException {

View File

@ -1,13 +1,13 @@
package com.ruoyi.common.domain.vo;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import lombok.Data;
/**
* @author wjh
* 2024/12/2
* 2024/12/2
*/
@Data
public class LocalDateDecimalVO {

View File

@ -0,0 +1,11 @@
package com.ruoyi.common.domain.vo;
import lombok.Data;
@Data
public class LongIntegerVO {
private Long key;
private Integer value;
}

View File

@ -1,14 +1,15 @@
package com.ruoyi.dashboard.domain.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import org.springframework.format.annotation.DateTimeFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author wjh
* 2024/12/3
* 2024/12/3
*/
@Data
public class BillDailyAmountQuery {
@ -24,4 +25,7 @@ public class BillDailyAmountQuery {
@ApiModelProperty("渠道ID")
private Long channelId;
@ApiModelProperty("店铺ID")
private Long storeId;
}

View File

@ -5,8 +5,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.ruoyi.dashboard.mapper.DashboardMapper">
<resultMap id="BusinessStatisticsStoreVO" type="BusinessStatisticsVO" autoMapping="true">
<result property="deviceCount" column="device_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="orderCount" column="order_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="deviceCount" column="device_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
<result property="orderCount" column="order_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
<result property="seconds" column="seconds" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="ele" column="ele" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="arrivalAmount" column="arrival_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>

View File

@ -3,6 +3,7 @@ package com.ruoyi.dashboard.service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
@ -16,11 +17,13 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.dashboard.domain.dto.BusinessStatisticsQuery;
import com.ruoyi.dashboard.domain.dto.DailyIncomeGroupByStoreQuery;
import com.ruoyi.dashboard.domain.dto.ServiceIncomeQuery;
import com.ruoyi.dashboard.domain.vo.BonusTrendDetailVO;
import com.ruoyi.dashboard.domain.vo.BonusTrendVO;
import com.ruoyi.dashboard.domain.vo.BusinessStatisticsByStoreVO;
import com.ruoyi.dashboard.domain.vo.BusinessStatisticsVO;
import com.ruoyi.dashboard.domain.vo.DailyIncomeGroupByStoreVO;
import com.ruoyi.dashboard.domain.vo.DashboardBonusGroupByMchVO;
import com.ruoyi.dashboard.domain.vo.MchRevenueVO;
import com.ruoyi.dashboard.domain.vo.ServiceIncomeVO;
@ -76,7 +79,7 @@ import com.ruoyi.ss.user.service.UserService;
/**
* @author wjh
* 2024/8/6
* 2024/8/6
*/
@Service
public class DashboardService {
@ -188,18 +191,21 @@ public class DashboardService {
billQuery.setStartDate(query.getStartDate());
billQuery.setEndDate(query.getEndDate());
billQuery.setStatusList(TransactionBillStatus.validWithdrawList());
List<TransactionAmountVO<Date>> withdrawList = transactionBillService.selectCommonSumOfMoney(billQuery, TransactionBillGroupBy.create_date.name());
List<TransactionAmountVO<Date>> withdrawList = transactionBillService.selectCommonSumOfMoney(billQuery,
TransactionBillGroupBy.create_date.name());
// 查询月费收入
ReceiveBillQuery receiveQuery = new ReceiveBillQuery();
receiveQuery.setStartDate(query.getStartDate());
receiveQuery.setEndDate(query.getEndDate());
receiveQuery.setType(ReceiveBillType.MONTH.getType());
List<ReceiveAmountVO<Date>> receiveList = receiveBillService.selectCommonSumOfAmount(receiveQuery, ReceiveBillGroupBy.create_date.name());
List<ReceiveAmountVO<Date>> receiveList = receiveBillService.selectCommonSumOfAmount(receiveQuery,
ReceiveBillGroupBy.create_date.name());
// 查询订单手机号收入
receiveQuery.setType(ReceiveBillType.MOBILE.getType());
List<ReceiveAmountVO<Date>> mobileList = receiveBillService.selectCommonSumOfAmount(receiveQuery, ReceiveBillGroupBy.create_date.name());
List<ReceiveAmountVO<Date>> mobileList = receiveBillService.selectCommonSumOfAmount(receiveQuery,
ReceiveBillGroupBy.create_date.name());
// 拼接结果集
List<ServiceIncomeVO> result = new ArrayList<>();
@ -283,7 +289,6 @@ public class DashboardService {
return vo;
}
public List<BusinessStatisticsVO> businessStatisticsByDevice(BusinessStatisticsQuery query) {
query.setBillType(TransactionBillType.RECHARGE.getType());
query.setBillStatusList(TransactionBillStatus.payedOrder());
@ -459,7 +464,7 @@ public class DashboardService {
ReceiveBillQuery receiveQuery = new ReceiveBillQuery();
receiveQuery.setBillDate(date);
result.setReceiveAmount(receiveBillService.selectSumOfReceivedAmount(receiveQuery));
// 总分成
result.setTotalBonus(MathUtils.addDecimal(result.getUserBonus(), result.getPlatformBonus()));
// 分成总退款
@ -473,11 +478,56 @@ public class DashboardService {
// 订单实收和实际分成差额
result.setDifference(MathUtils.subtractDecimal(result.getOrderReceiveAmount(), result.getActualBonus()));
// 平台收益 = 平台分成 + 应收账 + 提现服务费 - 平台分成退款 - 渠道成本
BigDecimal add = MathUtils.addDecimal(result.getPlatformBonus(), result.getReceiveAmount(), result.getWithdrawServiceFee());
result.setPlatformIncome(MathUtils.subtractDecimal(add, result.getPlatformBonusRefund(), result.getChannelCost()));
BigDecimal add = MathUtils.addDecimal(result.getPlatformBonus(), result.getReceiveAmount(),
result.getWithdrawServiceFee());
result.setPlatformIncome(
MathUtils.subtractDecimal(add, result.getPlatformBonusRefund(), result.getChannelCost()));
return result;
}
}
public List<DailyIncomeGroupByStoreVO> getDailyIncomeGroupByStore(DailyIncomeGroupByStoreQuery query) {
// 查询订单列表
TransactionBillQuery billQuery = new TransactionBillQuery();
billQuery.setCreateDateRange(Arrays.asList(query.getDateStart(), query.getDateEnd()));
billQuery.setStatusList(TransactionBillStatus.payedOrder());
billQuery.setType(TransactionBillType.RECHARGE.getType());
List<LocalDateDecimalVO> billList = transactionBillService.selectDailyMoney(billQuery);
// 查询退款列表
RefundQuery refundQuery = new RefundQuery();
refundQuery.setCreateDateStart(query.getDateStart());
refundQuery.setCreateDateEnd(query.getDateEnd());
refundQuery.setStatusList(RefundStatus.successList());
refundQuery.setPayBillBstType(PayBillBstType.RECHARGE_ORDER.getType());
List<LocalDateDecimalVO> refundList = refundService.selectDailyAmount(refundQuery);
List<DailyIncomeGroupByStoreVO> result = new ArrayList<>();
if (query.getDateStart() != null && query.getDateEnd() != null) {
result = CollectionUtils.fillVoids(result, DailyIncomeGroupByStoreVO::getDate, (date) -> {
DailyIncomeGroupByStoreVO vo = new DailyIncomeGroupByStoreVO();
vo.setDate(date);
// 订单金额
LocalDateDecimalVO dailyBill = billList.stream().filter(item -> item.getKey().isEqual(date))
.findFirst().orElse(null);
if (dailyBill == null || dailyBill.getValue() == null) {
vo.setBillMoney(BigDecimal.ZERO);
} else {
vo.setBillMoney(dailyBill.getValue());
}
// 退款金额
LocalDateDecimalVO dailyRefund = refundList.stream().filter(item -> item.getKey().isEqual(date))
.findFirst().orElse(null);
if (dailyRefund == null || dailyRefund.getValue() == null) {
vo.setRefundMoney(BigDecimal.ZERO);
} else {
vo.setRefundMoney(dailyRefund.getValue());
}
// 实收金额
vo.setRealAmount(MathUtils.subtractDecimal(vo.getBillMoney(), vo.getRefundMoney()));
return vo;
}, query.getDateStart(), query.getDateEnd());
}
return result;
}
}

View File

@ -5,17 +5,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.ruoyi.ss.businessRecord.mapper.SmBusinessRecordMapper">
<resultMap type="SmBusinessRecordVo" id="SmBusinessRecordResult" autoMapping="true">
<result property="totalDevice" column="total_device" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="totalModel" column="total_model" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="totalOnline" column="total_online" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="totalUser" column="total_user" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="totalDevice" column="total_device" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
<result property="totalModel" column="total_model" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
<result property="totalOnline" column="total_online" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
<result property="totalUser" column="total_user" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
<result property="totalRecharge" column="total_recharge" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="rechargeCount" column="recharge_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="rechargeCount" column="recharge_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
<result property="totalMonth" column="total_month" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="userBalance" column="user_balance" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="todayRechargeCount" column="today_recharge_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler" />
<result property="todayRechargeCount" column="today_recharge_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler" />
<result property="todayRechargeAmount" column="today_recharge_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler" />
<result property="deviceCount" column="device_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler" />
<result property="deviceCount" column="device_count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler" />
</resultMap>
<sql id="selectSmBusinessRecordVo">

View File

@ -272,7 +272,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<resultMap id="DeviceCount" type="DeviceCountVO" autoMapping="true">
<result property="count" column="count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="count" column="count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
</resultMap>
<select id="selectCommonCount" resultMap="DeviceCount">

View File

@ -11,8 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.domain.vo.LongDecimalVO;
import com.ruoyi.common.domain.vo.LongIntegerVO;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.dashboard.domain.vo.BillCountVo;
import com.ruoyi.ss.bonus.domain.Bonus;
import com.ruoyi.ss.bonus.service.BonusConverter;
import com.ruoyi.ss.device.domain.DeviceCountVO;
@ -32,7 +32,6 @@ import com.ruoyi.ss.store.service.StoreValidator;
import com.ruoyi.ss.storeStaff.domain.StoreStaffVO;
import com.ruoyi.ss.storeStaff.service.StoreStaffService;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillType;
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
@ -117,13 +116,13 @@ public class StoreAssemblerImpl implements StoreAssembler {
// 查询订单信息
TransactionBillQuery query = new TransactionBillQuery();
LocalDate now = LocalDate.now();
query.setGroupBy(TransactionBillGroupBy.store_id.name());
query.setStoreIds(CollectionUtils.map(list, StoreVo::getStoreId));
query.setStatusList(TransactionBillStatus.payedOrder());
query.setType(TransactionBillType.RECHARGE.getType());
query.setMonth(now.getMonthValue());
query.setYear(now.getYear());
Map<Long, BillCountVo> map = transactionBillService.selectCountMap(query, BillCountVo::getStoreId);
Map<Long, BigDecimal> billMap = transactionBillService.selectSumOfMoneyGroupByStoreId(query)
.stream().collect(Collectors.toMap(LongDecimalVO::getKey, LongDecimalVO::getValue));
// 查询退款信息
RefundQuery refundQuery = new RefundQuery();
@ -136,11 +135,10 @@ public class StoreAssemblerImpl implements StoreAssembler {
.stream().collect(Collectors.toMap(LongDecimalVO::getKey, LongDecimalVO::getValue));
for (StoreVo store : list) {
BillCountVo count = map.get(store.getStoreId());
BigDecimal monthIncome = billMap.get(store.getStoreId());
BigDecimal refundAmount = refundMap.get(store.getStoreId());
BigDecimal monthIncome = BigDecimal.ZERO;
if (count != null) {
monthIncome = count.getRecharge();
if (monthIncome == null) {
monthIncome = BigDecimal.ZERO;
}
if (refundAmount != null) {
monthIncome = monthIncome.subtract(refundAmount);
@ -163,13 +161,17 @@ public class StoreAssemblerImpl implements StoreAssembler {
// 查询订单信息
TransactionBillQuery query = new TransactionBillQuery();
query.setGroupBy(TransactionBillGroupBy.store_id.name());
query.setStoreIds(list.stream().map(StoreVo::getStoreId).filter(Objects::nonNull).distinct()
.collect(Collectors.toList()));
query.setStatusList(TransactionBillStatus.payedOrder());
query.setType(TransactionBillType.RECHARGE.getType());
query.setCreateDate(now);
Map<Long, BillCountVo> map = transactionBillService.selectCountMap(query, BillCountVo::getStoreId);
Map<Long, BigDecimal> billMap = transactionBillService.selectSumOfMoneyGroupByStoreId(query)
.stream().collect(Collectors.toMap(LongDecimalVO::getKey, LongDecimalVO::getValue));
// 查询订单量
Map<Long, Integer> countMap = transactionBillService.selectCountGroupByStoreId(query)
.stream().collect(Collectors.toMap(LongIntegerVO::getKey, LongIntegerVO::getValue));
// 查询退款信息
RefundQuery refundQuery = new RefundQuery();
@ -181,23 +183,24 @@ public class StoreAssemblerImpl implements StoreAssembler {
.stream().collect(Collectors.toMap(LongDecimalVO::getKey, LongDecimalVO::getValue));
for (StoreVo store : list) {
BillCountVo count = map.get(store.getStoreId());
// 本日收入
BigDecimal todayIncome = BigDecimal.ZERO;
BigDecimal todayIncome = billMap.get(store.getStoreId());
BigDecimal refundAmount = refundMap.get(store.getStoreId());
Integer count = countMap.get(store.getStoreId());
// 订单量
if (count != null) {
todayIncome = count.getRecharge();
store.setTodayOrderCount(count.getCount());
store.setTodayOrderCount(count);
} else {
store.setTodayOrderCount(0);
}
// 退款金额
BigDecimal refundAmount = refundMap.get(store.getStoreId());
if (refundAmount != null) {
todayIncome = todayIncome.subtract(refundAmount);
// 订单金额
if (todayIncome == null) {
todayIncome = BigDecimal.ZERO;
}
store.setTodayIncome(todayIncome);
// 退款金额
if (refundAmount == null) {
refundAmount = BigDecimal.ZERO;
}
store.setTodayIncome(todayIncome.subtract(refundAmount));
}
}
@ -216,14 +219,14 @@ public class StoreAssemblerImpl implements StoreAssembler {
// 查询订单信息
TransactionBillQuery query = new TransactionBillQuery();
query.setGroupBy(TransactionBillGroupBy.store_id.name());
query.setStoreIds(list.stream().map(StoreVo::getStoreId).filter(Objects::nonNull).distinct()
.collect(Collectors.toList()));
query.setStatusList(TransactionBillStatus.payedOrder());
query.setType(TransactionBillType.RECHARGE.getType());
query.setMonth(lastMonth.getMonthValue());
query.setYear(lastMonth.getYear());
Map<Long, BillCountVo> map = transactionBillService.selectCountMap(query, BillCountVo::getStoreId);
Map<Long, BigDecimal> billMap = transactionBillService.selectSumOfMoneyGroupByStoreId(query)
.stream().collect(Collectors.toMap(LongDecimalVO::getKey, LongDecimalVO::getValue));
// 查询退款信息
RefundQuery refundQuery = new RefundQuery();
@ -236,11 +239,10 @@ public class StoreAssemblerImpl implements StoreAssembler {
.stream().collect(Collectors.toMap(LongDecimalVO::getKey, LongDecimalVO::getValue));
for (StoreVo store : list) {
BillCountVo count = map.get(store.getStoreId());
BigDecimal lastMonthIncome = billMap.get(store.getStoreId());
BigDecimal refundAmount = refundMap.get(store.getStoreId());
BigDecimal lastMonthIncome = BigDecimal.ZERO;
if (count != null) {
lastMonthIncome = count.getRecharge();
if (lastMonthIncome == null) {
lastMonthIncome = BigDecimal.ZERO;
}
if (refundAmount != null) {
lastMonthIncome = lastMonthIncome.subtract(refundAmount);

View File

@ -8,7 +8,9 @@ import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.domain.vo.LocalDateDecimalVO;
import com.ruoyi.common.domain.vo.LongDecimalVO;
import com.ruoyi.common.domain.vo.LongIntegerVO;
import com.ruoyi.dashboard.domain.vo.BillCountVo;
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
@ -22,8 +24,7 @@ import com.ruoyi.ss.transactionBill.domain.vo.TransactionDailyAmountVO;
* @author 邱贞招
* @date 2024-02-21
*/
public interface TransactionBillMapper
{
public interface TransactionBillMapper {
/**
* 查询充值记录
*
@ -54,7 +55,7 @@ public interface TransactionBillMapper
* @param transactionBill 充值记录
* @return 结果
*/
public int updateSmTransactionBill(@Param("data")TransactionBill transactionBill);
public int updateSmTransactionBill(@Param("data") TransactionBill transactionBill);
/**
* 删除充值记录
@ -74,18 +75,21 @@ public interface TransactionBillMapper
/**
* 获取账单统计数据
*
* @param dto 查询条件
*/
List<BillCountVo> selectCount(@Param("query")TransactionBillQuery dto);
List<BillCountVo> selectCount(@Param("query") TransactionBillQuery dto);
/**
* 充值成功
*
* @param billId 订单id
*/
int rechargeSuccess(@Param("billId") Long billId, @Param("payTime") Date payTime);
/**
* 通过订单编号查询订单
*
* @param billNo 订单编号
* @return
*/
@ -93,6 +97,7 @@ public interface TransactionBillMapper
/**
* 订单取消
*
* @param billNo 订单编号
* @param status 订单取消后的状态
* @return 影响的行数
@ -101,6 +106,7 @@ public interface TransactionBillMapper
/**
* 审核通过
*
* @param billId id
* @param remark 审核意见
*/
@ -108,6 +114,7 @@ public interface TransactionBillMapper
/**
* 拒绝提现
*
* @param billId id
* @param remark 审核意见
*/
@ -115,35 +122,41 @@ public interface TransactionBillMapper
/**
* 发起提现打款打款中...
*
* @param billId 提现订单id
*/
int doPayWithdraw(Long billId);
/**
* 提现成功
*
* @param billId id
*/
int withdrawSuccess(@Param("billId") Long billId, @Param("payTime")LocalDateTime payTime);
int withdrawSuccess(@Param("billId") Long billId, @Param("payTime") LocalDateTime payTime);
/**
* 提现失败
*
* @param billId id
*/
int withdrawFailed(Long billId);
/**
* 更新状态为支付中
*
* @param billId
* @return
*/
int paying(Long billId);
int updateDeviceRechargeStatus(@Param("billId") Long billId, @Param("status") String status, @Param("openMsg") String openMsg);
int updateDeviceRechargeStatus(@Param("billId") Long billId, @Param("status") String status,
@Param("openMsg") String openMsg);
/**
* 修改设备充值状态
*
* @param billIds 需要修改的ID
* @param status 修改后的设备充值状态
* @param status 修改后的设备充值状态
*/
int updateDeviceRechargeStatusByIds(@Param("billIds") List<Long> billIds, @Param("status") String status);
@ -159,16 +172,17 @@ public interface TransactionBillMapper
/**
* 添加退款金额
* @param billId 订单ID
*
* @param billId 订单ID
* @param refundAmount 退款金额
*/
int addRefundAmount(@Param("billId") Long billId,
@Param("refundAmount") BigDecimal refundAmount);
@Param("refundAmount") BigDecimal refundAmount);
/**
* 批量更新套餐结束时间
*/
int batchUpdateSuitEndTime(@Param("billIds") List<Long> billIds,@Param("time") LocalDateTime time);
int batchUpdateSuitEndTime(@Param("billIds") List<Long> billIds, @Param("time") LocalDateTime time);
/**
* 查询提现列表
@ -187,6 +201,7 @@ public interface TransactionBillMapper
/**
* 查询订单总金额
*
* @param query
* @return
*/
@ -195,7 +210,8 @@ public interface TransactionBillMapper
/**
* 查询金额统计
*/
<T> List<TransactionAmountVO<T>> selectCommonSumOfMoney(@Param("query") TransactionBillQuery query, @Param("groupBy") String groupBy);
<T> List<TransactionAmountVO<T>> selectCommonSumOfMoney(@Param("query") TransactionBillQuery query,
@Param("groupBy") String groupBy);
/**
* 查询统计数量
@ -226,4 +242,19 @@ public interface TransactionBillMapper
* 查询服务费
*/
BigDecimal selectSumOfServiceCharge(@Param("query") TransactionBillQuery query);
/**
* 查询订单金额并按店铺分组
*/
List<LongDecimalVO> selectSumOfMoneyGroupByStoreId(@Param("query") TransactionBillQuery query);
/**
* 查询订单量并按店铺分组
*/
List<LongIntegerVO> selectCountGroupByStoreId(@Param("query") TransactionBillQuery query);
/**
* 查询每日订单金额
*/
List<LocalDateDecimalVO> selectDailyMoney(@Param("query") TransactionBillQuery query);
}

View File

@ -359,7 +359,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createYearMonth" column="create_year_month"/>
<result property="storeId" column="store_id"/>
<result property="deviceId" column="device_id"/>
<result property="count" column="count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTyperHandler"/>
<result property="count" column="count" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
<result property="serviceCharge" column="service_charge" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="channelCost" column="channel_cost" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="profit" column="profit" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
@ -393,7 +393,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
stb.device_id as device_id,
</if>
SUM(IF( stb.type = '1' and stb.status in('2', '3', '7'), stb.arrival_amount, 0 )) AS recharge,
SUM(IF( stb.type = '1' and stb.status = '2', stb.money, 0 )) AS recharge_amount,
SUM(IF( stb.type = '1' and stb.status in('2', '3', '7'), stb.money, 0 )) AS recharge_amount,
SUM(IF( stb.type = '2' and stb.status = '14', stb.arrival_amount, 0 )) AS withdraw,
SUM(stb.service_charge) AS service_charge,
SUM(stb.channel_cost) AS channel_cost,
@ -539,6 +539,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
group by `key`
</select>
<select id="selectSumOfMoneyGroupByStoreId" resultMap="LongDecimalVO">
select
stb.store_id as `key`,
sum(stb.money) as `value`
from sm_transaction_bill stb
<where>
<include refid="searchCondition"/>
</where>
group by `key`
</select>
<!-- selectCountGroupByStoreId -->
<resultMap id="LongIntegerVO" type="LongIntegerVO">
<result property="value" column="value" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullIntegerTypeHandler"/>
</resultMap>
<select id="selectCountGroupByStoreId" resultMap="LongIntegerVO">
select
stb.store_id as `key`,
count(stb.bill_id) as `value`
from sm_transaction_bill stb
<where>
<include refid="searchCondition"/>
</where>
group by `key`
</select>
<insert id="insertSmTransactionBill" parameterType="TransactionBill" useGeneratedKeys="true" keyProperty="billId">
<selectKey resultType="Long" order="AFTER" keyProperty="billId">
SELECT LAST_INSERT_ID();
@ -913,7 +940,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and suit_end_time is null
</update>
<!-- selectSumOfServiceCharge -->
<!-- selectSumOfServiceCharge -->
<select id="selectSumOfServiceCharge" resultType="BigDecimal">
select sum(stb.service_charge)
@ -923,4 +950,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<!-- selectDailyMoney -->
<resultMap id="LocalDateDecimalVOMap" type="LocalDateDecimalVO">
<result property="value" column="value" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
</resultMap>
<select id="selectDailyMoney" resultMap="LocalDateDecimalVOMap">
select
date(create_time) as `key`,
sum(money) as `value`
from sm_transaction_bill
<where>
<include refid="searchCondition"/>
</where>
group by `key`
</select>
</mapper>

View File

@ -8,7 +8,9 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.domain.vo.LocalDateDecimalVO;
import com.ruoyi.common.domain.vo.LongDecimalVO;
import com.ruoyi.common.domain.vo.LongIntegerVO;
import com.ruoyi.dashboard.domain.vo.BillCountVo;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.payBill.domain.vo.DoPayVO;
@ -33,8 +35,7 @@ import com.ruoyi.ss.transactionBill.domain.vo.UserWithdrawServiceVO;
* @author 邱贞招
* @date 2024-02-21
*/
public interface TransactionBillService
{
public interface TransactionBillService {
/**
* 查询充值记录
*
@ -85,6 +86,7 @@ public interface TransactionBillService
/**
* 获取账单统计
*
* @param dto
* @return
*/
@ -100,6 +102,7 @@ public interface TransactionBillService
/**
* 取消充值订单
*
* @param billNo 订单编号
* @param status 取消后的状态
*/
@ -114,6 +117,7 @@ public interface TransactionBillService
/**
* 获取未支付的充值订单
*
* @return 订单列表
*/
List<TransactionBillVO> selectNoPayedRecharge();
@ -139,6 +143,7 @@ public interface TransactionBillService
/**
* 查询商户统计信息
*
* @param dto 查询条件
* @return 统计信息
*/
@ -146,6 +151,7 @@ public interface TransactionBillService
/**
* 刷新订单支付结果
*
* @param billId
*/
int refreshPayResult(Long billId);
@ -159,6 +165,7 @@ public interface TransactionBillService
/**
* 查询设备充值失败列表
*
* @param userId
* @return
*/
@ -175,13 +182,16 @@ public interface TransactionBillService
/**
* 查询数量并映射
* @param query 查询条件
*
* @param query 查询条件
* @param keyMapper 映射方法
*/
<K> Map<K, BillCountVo> selectCountMap(TransactionBillQuery query, Function<? super BillCountVo, ? extends K> keyMapper);
<K> Map<K, BillCountVo> selectCountMap(TransactionBillQuery query,
Function<? super BillCountVo, ? extends K> keyMapper);
/**
* 蓝牙充值成功
*
* @param billNo
* @return
*/
@ -194,6 +204,7 @@ public interface TransactionBillService
/**
* 根据条件更新
*
* @param data
* @param query
*/
@ -259,10 +270,10 @@ public interface TransactionBillService
*/
int selectSimpleCount(TransactionBillQuery query);
// /**
// * 支付押金
// */
// DoPayVO payDeposit(RechargePayDepositBO bo);
// /**
// * 支付押金
// */
// DoPayVO payDeposit(RechargePayDepositBO bo);
/**
* 查询未支付的分时段订单
@ -276,12 +287,12 @@ public interface TransactionBillService
/**
* 查询订单总金额
*
* @param query
* @return
*/
BigDecimal selectSumOfMoney(TransactionBillQuery query);
/**
* 结束使用订单
*/
@ -306,6 +317,7 @@ public interface TransactionBillService
/**
* 收取商户查看用户手机号的价格
*
* @param bill
* @return
*/
@ -352,4 +364,19 @@ public interface TransactionBillService
* 查询服务费
*/
BigDecimal selectSumOfServiceCharge(TransactionBillQuery query);
/**
* 查询订单金额并按店铺分组
*/
List<LongDecimalVO> selectSumOfMoneyGroupByStoreId(TransactionBillQuery query);
/**
* 查询订单量并按店铺分组
*/
List<LongIntegerVO> selectCountGroupByStoreId(TransactionBillQuery query);
/**
* 查询每日订单金额
*/
List<LocalDateDecimalVO> selectDailyMoney(TransactionBillQuery query);
}

View File

@ -28,7 +28,9 @@ import com.github.pagehelper.PageHelper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.common.core.redis.enums.RedisLockKey;
import com.ruoyi.common.domain.vo.LocalDateDecimalVO;
import com.ruoyi.common.domain.vo.LongDecimalVO;
import com.ruoyi.common.domain.vo.LongIntegerVO;
import com.ruoyi.common.enums.ServiceCode;
import com.ruoyi.common.enums.WithdrawServiceType;
import com.ruoyi.common.exception.ServiceException;
@ -152,7 +154,6 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
@Autowired
private BillDelayedManager billDelayedManager;
@Autowired
private RedisLock redisLock;
@ -214,8 +215,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* @return 充值记录
*/
@Override
public TransactionBillVO selectSmTransactionBillByBillId(Long billId)
{
public TransactionBillVO selectSmTransactionBillByBillId(Long billId) {
return transactionBillMapper.selectSmTransactionBillByBillId(billId);
}
@ -226,8 +226,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* @return 充值记录
*/
@Override
public List<TransactionBillVO> selectSmTransactionBillList(TransactionBillQuery smTransactionBillQuery)
{
public List<TransactionBillVO> selectSmTransactionBillList(TransactionBillQuery smTransactionBillQuery) {
return transactionBillMapper.selectSmTransactionBillList(smTransactionBillQuery);
}
@ -238,8 +237,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* @return 结果
*/
@Override
public int insertSmTransactionBill(TransactionBill transactionBill)
{
public int insertSmTransactionBill(TransactionBill transactionBill) {
transactionBill.setCreateTime(DateUtils.getNowDate());
transactionBill.setBillNo(String.valueOf(SnowFlakeUtil.newId()));
return transactionBillMapper.insertSmTransactionBill(transactionBill);
@ -252,8 +250,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* @return 结果
*/
@Override
public int updateSmTransactionBill(TransactionBill transactionBill)
{
public int updateSmTransactionBill(TransactionBill transactionBill) {
return transactionBillMapper.updateSmTransactionBill(transactionBill);
}
@ -264,8 +261,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* @return 结果
*/
@Override
public int deleteSmTransactionBillByBillIds(Long[] billIds)
{
public int deleteSmTransactionBillByBillIds(Long[] billIds) {
return transactionBillMapper.deleteSmTransactionBillByBillIds(billIds);
}
@ -276,13 +272,13 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* @return 结果
*/
@Override
public int deleteSmTransactionBillByBillId(Long billId)
{
public int deleteSmTransactionBillByBillId(Long billId) {
return transactionBillMapper.deleteSmTransactionBillByBillId(billId);
}
/**
* 查询账单统计
*
* @param dto
* @return
*/
@ -362,8 +358,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
false,
receive.getDescription(),
RecordBalanceBstType.RECEIVABLE,
receive.getBillId()
);
receive.getBillId());
// 修改订单缴费状态
TransactionBill data = new TransactionBill();
@ -377,7 +372,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return update;
});
return result == null ? 0 :result;
return result == null ? 0 : result;
}
@Override
@ -434,12 +429,12 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
bo.setOrder(order);
// 基础信息
order.setType(TransactionBillType.RECHARGE.getType()); // 类型充值订单
order.setType(TransactionBillType.RECHARGE.getType()); // 类型充值订单
order.setDeviceRechargeStatus(TransactionBillDeviceRechargeStatus.UN_RECHARGE.getStatus()); // 设备状态未充值
order.setVersion(2); // 订单版本
order.setVersion(2); // 订单版本
order.setCloseStatus(RechargeCloseStatus.SUCCESS.getStatus());
order.setCloseResult("预计成功");
order.setStatus(TransactionBillStatus.UNPAID.getStatus()); // 状态未支付
order.setStatus(TransactionBillStatus.UNPAID.getStatus()); // 状态未支付
// 订单金额
order.setMoney(price.getPayPrice());
order.setDiscountAmount(price.getDiscountAmount());
@ -492,11 +487,13 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
if (store != null) {
order.setStoreId(store.getStoreId());
order.setStoreName(store.getName());
order.setStoreAddress(String.format("%s%s%s%s", store.getProvince(), store.getCity(), store.getCounty(), store.getAddress()));
order.setStoreAddress(String.format("%s%s%s%s", store.getProvince(), store.getCity(), store.getCounty(),
store.getAddress()));
}
// 支付过期时间 5min
long expireTime = TimeUnit.MILLISECONDS.convert(Constants.BILL_UNPAID_TIMEOUT, Constants.BILL_UNPAID_TIMEUNIT) + System.currentTimeMillis();
long expireTime = TimeUnit.MILLISECONDS.convert(Constants.BILL_UNPAID_TIMEOUT, Constants.BILL_UNPAID_TIMEUNIT)
+ System.currentTimeMillis();
order.setExpireTime(new Date(expireTime));
return order;
@ -554,7 +551,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
if (current == null) {
current = BigDecimal.ZERO;
}
ServiceUtil.assertion(current.add(dto.getMoney()).compareTo(dailyLimit) > 0, "当前用户提现金额已超过每日限额:" + dailyLimit + "");
ServiceUtil.assertion(current.add(dto.getMoney()).compareTo(dailyLimit) > 0,
"当前用户提现金额已超过每日限额:" + dailyLimit + "");
}
// 每日限次
if (StringUtils.hasText(dailyLimitCountStr)) {
@ -567,13 +565,16 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 处理提现手续费
ServiceUtil.assertion(channel == null, "提现渠道不存在");
ServiceUtil.assertion(channel.getEnabled() == null || !channel.getEnabled(), "提现渠道不可用");
ServiceUtil.assertion(channel.getMinAmount().compareTo(dto.getMoney()) > 0, String.format("提现金额不能低于%s元", channel.getMinAmount()));
ServiceUtil.assertion(channel.getMaxAmount().compareTo(dto.getMoney()) < 0, String.format("提现金额不能高于%s元", channel.getMaxAmount()));
ServiceUtil.assertion(channel.getMinAmount().compareTo(dto.getMoney()) > 0,
String.format("提现金额不能低于%s元", channel.getMinAmount()));
ServiceUtil.assertion(channel.getMaxAmount().compareTo(dto.getMoney()) < 0,
String.format("提现金额不能高于%s元", channel.getMaxAmount()));
UserWithdrawServiceVO serviceInfo = this.getUserWithdrawService(user, channel);
ServiceUtil.assertion(serviceInfo == null, "服务费配置出错,请联系管理员处理");
ServiceUtil.assertion(StringUtils.isBlank(serviceInfo.getServiceType()), "服务费配置出错,请联系管理员处理");
ServiceUtil.assertion(serviceInfo.getServiceRate() == null, "服务费配置出错,请联系管理员处理");
ServiceUtil.assertion(!Objects.equals(serviceInfo.getServiceType(), dto.getServiceType()), "服务费收取方式发生变化,请刷新后重试");
ServiceUtil.assertion(!Objects.equals(serviceInfo.getServiceType(), dto.getServiceType()),
"服务费收取方式发生变化,请刷新后重试");
ServiceUtil.assertion(serviceInfo.getServiceRate().compareTo(dto.getServiceRate()) != 0, "服务费发生变化,请刷新后重试");
// 计算服务费
@ -581,7 +582,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
ServiceUtil.assertion(BigDecimal.ZERO.compareTo(serviceRecharge) > 0, "服务费不允许小于0");
ServiceUtil.assertion(serviceRecharge.compareTo(dto.getServiceCharge()) != 0, "服务费计算不一致,请重新申请");
// 到账金额
BigDecimal arrivalAmount = dto.getMoney().subtract(serviceRecharge); // 到账金额
BigDecimal arrivalAmount = dto.getMoney().subtract(serviceRecharge); // 到账金额
ServiceUtil.assertion(arrivalAmount.compareTo(dto.getArrivalAmount()) != 0, "到账金额计算不一致,请重新申请");
// 创建申请订单
@ -592,11 +593,12 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
bill.setMoney(dto.getMoney());
bill.setArrivalAmount(arrivalAmount);
bill.setServiceCharge(serviceRecharge);
bill.setStatus(TransactionBillStatus.WITHDRAW_APPROVING.getStatus()); // 审核中
bill.setStatus(TransactionBillStatus.WITHDRAW_APPROVING.getStatus()); // 审核中
bill.setAccountNo(account.getAccountNo());
bill.setChannelId(channel.getChannelId());
bill.setWithdrawType(WithdrawType.ONLINE.getType());
bill.setChannelCost(channel.getCostRate().multiply(bill.getMoney()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP)); // 渠道成本
bill.setChannelCost(channel.getCostRate().multiply(bill.getMoney()).divide(new BigDecimal(100), 2,
RoundingMode.HALF_UP)); // 渠道成本
bill.setAfterBalance(user.getBalance().subtract(dto.getMoney())); // 剩余金额
transactionTemplate.execute(status -> {
@ -605,7 +607,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
ServiceUtil.assertion(insert != 1, "提现申请失败");
// 减少余额并判断提现金额是否超额减少的是交易金额
userService.subtractBalance(userId, bill.getMoney(), String.format("提现申请:%s", bill.getBillNo()), RecordBalanceBstType.WITHDRAW, bill.getBillId());
userService.subtractBalance(userId, bill.getMoney(), String.format("提现申请:%s", bill.getBillNo()),
RecordBalanceBstType.WITHDRAW, bill.getBillId());
// 若本次提现具有风险则累计一次风险次数
if (hasRisk) {
@ -616,7 +619,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 异步操作当提现申请金额免审核且为线上打款时直接通过
try {
String noverifyAmountStr = sysConfigService.selectConfigByKey(ConfigKey.NOVERIFY_WITHDRAW_SINGLE.getKey());
String noverifyAmountStr = sysConfigService
.selectConfigByKey(ConfigKey.NOVERIFY_WITHDRAW_SINGLE.getKey());
if (StringUtils.hasText(noverifyAmountStr)) {
BigDecimal noverifyAmount = new BigDecimal(noverifyAmountStr);
if (noverifyAmount.compareTo(bill.getMoney()) >= 0) {
@ -643,7 +647,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
private BigDecimal calcWithdrawServiceCharge(UserWithdrawServiceVO serviceInfo, BigDecimal money) {
BigDecimal serviceRecharge;
if (WithdrawServiceType.PERCENT.getType().equals(serviceInfo.getServiceType())) {
serviceRecharge = money.multiply(serviceInfo.getServiceRate()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); // 服务费
serviceRecharge = money.multiply(serviceInfo.getServiceRate()).divide(new BigDecimal(100), 2,
RoundingMode.HALF_UP); // 服务费
} else if (WithdrawServiceType.FIXED.getType().equals(serviceInfo.getServiceType())) {
serviceRecharge = serviceInfo.getServiceRate();
} else {
@ -657,9 +662,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* 用户 > 渠道
*/
private UserWithdrawServiceVO getUserWithdrawService(SmUserVO user, ChannelWithdrawVO channel) {
if (user != null && StringUtils.hasText(user.getWithdrawServiceType()) && user.getWithdrawServiceRate() != null ) {
if (user != null && StringUtils.hasText(user.getWithdrawServiceType())
&& user.getWithdrawServiceRate() != null) {
return new UserWithdrawServiceVO(user.getWithdrawServiceType(), user.getWithdrawServiceRate());
} else if (channel != null && StringUtils.hasText(channel.getServiceType()) && channel.getServiceRate() != null) {
} else if (channel != null && StringUtils.hasText(channel.getServiceType())
&& channel.getServiceRate() != null) {
return new UserWithdrawServiceVO(channel.getServiceType(), channel.getServiceRate());
}
return null;
@ -745,7 +752,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
data.setOfflineImage(dto.getOfflineImage());
// 线下打款并且状态为已打款则修改支付时间为当前
if (WithdrawType.OFFLINE.getType().equals(dto.getWithdrawType()) && TransactionBillStatus.WITHDRAW_SUCCESS.equals(status)) {
if (WithdrawType.OFFLINE.getType().equals(dto.getWithdrawType())
&& TransactionBillStatus.WITHDRAW_SUCCESS.equals(status)) {
data.setPayTime(DateUtils.getNowDate());
}
@ -776,7 +784,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 返还客户余额
TransactionBill bill = transactionBillMapper.selectSmTransactionBillByBillId(dto.getBillId());
ServiceUtil.assertion(bill == null || bill.getUserId() == null, "数据不存在");
userService.addBalance(bill.getUserId(), bill.getMoney(), String.format("提现驳回: %s", bill.getBillNo()), RecordBalanceBstType.WITHDRAW, bill.getBillId());
userService.addBalance(bill.getUserId(), bill.getMoney(), String.format("提现驳回: %s", bill.getBillNo()),
RecordBalanceBstType.WITHDRAW, bill.getBillId());
return updateCount;
});
@ -792,12 +801,15 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
List<BillCountVo> list = this.selectCount(dto);
// 若startDate与endDate不为空则将其中间数据补全不让其为空
if (dto.getStartDate() != null && dto.getEndDate() != null && Objects.equals(dto.getGroupBy(), TransactionBillGroupBy.create_date.name())) {
if (dto.getStartDate() != null && dto.getEndDate() != null
&& Objects.equals(dto.getGroupBy(), TransactionBillGroupBy.create_date.name())) {
List<BillCountVo> newList = new ArrayList<>();
LocalDate i = dto.getStartDate();
while (!i.isAfter(dto.getEndDate())) {
Date finalI = DateUtils.toDate(i);
BillCountVo count = list.stream().filter(item -> DateUtils.getYYYY_MM_DD(item.getCreateDate()).equals(DateUtils.getYYYY_MM_DD(finalI))).findFirst().orElse(null);
BillCountVo count = list.stream().filter(
item -> DateUtils.getYYYY_MM_DD(item.getCreateDate()).equals(DateUtils.getYYYY_MM_DD(finalI)))
.findFirst().orElse(null);
if (count == null) {
count = new BillCountVo();
count.setCreateDate(finalI);
@ -846,9 +858,13 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
ServiceUtil.assertion(billId == null, "参数错误,billId不允许为空");
TransactionBillVO bill = transactionBillMapper.selectSmTransactionBillByBillId(billId);
ServiceUtil.assertion(bill == null || !TransactionBillType.RECHARGE.getType().equals(bill.getType()), "不存在ID为%s的充值订单", billId);
ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(bill.getStatus()), "订单%s未支付", bill.getBillNo());
ServiceUtil.assertion(!TransactionBillDeviceRechargeStatus.canRecharge().contains(bill.getDeviceRechargeStatus()), "订单%s当前设备状态不允许充值", bill.getBillNo());
ServiceUtil.assertion(bill == null || !TransactionBillType.RECHARGE.getType().equals(bill.getType()),
"不存在ID为%s的充值订单", billId);
ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(bill.getStatus()), "订单%s未支付",
bill.getBillNo());
ServiceUtil.assertion(
!TransactionBillDeviceRechargeStatus.canRecharge().contains(bill.getDeviceRechargeStatus()),
"订单%s当前设备状态不允许充值", bill.getBillNo());
// 获取最新设备信息
DeviceVO device = deviceService.selectById(bill.getDeviceId());
@ -901,7 +917,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
}
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = device.getExpireTime() == null || now.isAfter(device.getExpireTime()) ? now : device.getExpireTime();
LocalDateTime startTime = device.getExpireTime() == null || now.isAfter(device.getExpireTime()) ? now
: device.getExpireTime();
BigDecimal startEle = device.getTotalElectriQuantity();
TransactionBill data = new TransactionBill();
@ -940,10 +957,13 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 发送命令
boolean res = false;
if (bill.getSuitEnabledVoid() == null || !bill.getSuitEnabledVoid() || bill.getSuitVoidMinute() == null) {
if (bill.getSuitEnabledVoid() == null || !bill.getSuitEnabledVoid()
|| bill.getSuitVoidMinute() == null) {
res = iotService.setVoice(bill, 0L, "关闭订单语音:" + bill.getBillNo());
} else {
res = iotService.setVoice(bill, bill.getSuitVoidMinute().multiply(BigDecimal.valueOf(60)).longValue(), "开启订单语音:" + bill.getBillNo());
res = iotService.setVoice(bill,
bill.getSuitVoidMinute().multiply(BigDecimal.valueOf(60)).longValue(),
"开启订单语音:" + bill.getBillNo());
}
ServiceUtil.assertion(!res, "设备设置语音失败");
@ -997,7 +1017,6 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return totalAmount;
}
@Override
public int endUse(EndUseBO bo) {
if (bo == null) {
@ -1010,7 +1029,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(order.getStatus()), "当前订单状态不允许结束");
ServiceUtil.assertion(device == null, "设备不存在");
LocalDateTime now = LocalDateTime.now(); // 结束使用的时间
LocalDateTime now = LocalDateTime.now(); // 结束使用的时间
// 结束使用的电量若蓝牙传过来的值为空或者小于当前电量则使用当前电量否则使用蓝牙传输的电量谁大用谁
BigDecimal totalEle = this.calcTotalEle(device, bo.getTotalEle());
@ -1040,10 +1059,10 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return update;
});
boolean success = result != null && result == 1; // 是否成功
boolean success = result != null && result == 1; // 是否成功
// 若成功且为智能模式则计算需要退款的金额, 若金额 > 0.01 则申请退款
if ( success && SuitFeeMode.SMART.getMode().equals(order.getSuitFeeMode())) {
if (success && SuitFeeMode.SMART.getMode().equals(order.getSuitFeeMode())) {
BigDecimal refundAmount = this.calcRefundAmount(order, now, totalEle);
if (BigDecimal.valueOf(0.01).compareTo(refundAmount) < 0) {
scheduledExecutorService.schedule(() -> {
@ -1080,7 +1099,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
private BigDecimal calcAmount(TransactionBillVO bill, LocalDateTime endTime, BigDecimal totalEle) {
// 计量收费则获取最新的设备信息
if(SuitFeeType.COUNT.getType().equals(bill.getSuitFeeType()) || SuitFeeType.TIMING_COUNT.getType().equals(bill.getSuitFeeType())) {
if (SuitFeeType.COUNT.getType().equals(bill.getSuitFeeType())
|| SuitFeeType.TIMING_COUNT.getType().equals(bill.getSuitFeeType())) {
DeviceVO device = deviceService.selectById(bill.getDeviceId());
deviceService.pullDeviceInfo(device, null);
totalEle = this.calcTotalEle(device, totalEle);
@ -1128,8 +1148,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
*/
private BigDecimal calcRefundAmount(TransactionBillVO order, LocalDateTime endTime, BigDecimal totalEle) {
BigDecimal needAmount = this.calcAmount(order, endTime, totalEle); // 需要的金额
BigDecimal refundAmount = order.getMoney().subtract(needAmount); // 退款金额
BigDecimal needAmount = this.calcAmount(order, endTime, totalEle); // 需要的金额
BigDecimal refundAmount = order.getMoney().subtract(needAmount); // 退款金额
// 退款金额不允许大于订单金额
if (refundAmount.compareTo(order.getMoney()) > 0) {
@ -1153,8 +1173,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 智能收费计量收费
else if (SuitFeeType.COUNT.getType().equals(order.getSuitFeeType())) {
return this.calcSmartCountAmount(order, totalEle);
}
else {
} else {
throw new ServiceException("不支持的智能收费方式");
}
}
@ -1174,15 +1193,15 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return BigDecimal.ZERO;
}
BigDecimal startEle = order.getSuitStartEle();
BigDecimal usedEle = totalEle.subtract(startEle); // 已使用的电量
BigDecimal suitEle = new BigDecimal(order.getSuitTime()); // 套餐每周期的电量
BigDecimal usedEle = totalEle.subtract(startEle); // 已使用的电量
BigDecimal suitEle = new BigDecimal(order.getSuitTime()); // 套餐每周期的电量
// 计算总使用的周期数不满足一个周期也算一个周期
BigDecimal totalRound = usedEle.divide(suitEle, 0, RoundingMode.UP);
if (totalRound.compareTo(BigDecimal.ZERO) <= 0 ) {
if (totalRound.compareTo(BigDecimal.ZERO) <= 0) {
totalRound = BigDecimal.ONE;
}
// 使用金额 = 使用周期数 * 单价
// 使用金额 = 使用周期数 * 单价
return totalRound.multiply(order.getSuitPrice());
}
@ -1241,7 +1260,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
LocalDateTime plusI = i.plusHours(1);
// 当前每分钟平均金额
BigDecimal minuteAmount = suitGearAmount.get(suitGearTime.get(i.getHour())).divide(BigDecimal.valueOf(60), 2, RoundingMode.HALF_UP);
BigDecimal minuteAmount = suitGearAmount.get(suitGearTime.get(i.getHour())).divide(BigDecimal.valueOf(60),
2, RoundingMode.HALF_UP);
// 计算时间段的金额
LocalDateTime timeA = i.isAfter(startTime) ? i : startTime;
@ -1249,7 +1269,6 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
Duration between = Duration.between(timeA, timeB);
total = total.add(minuteAmount.multiply(BigDecimal.valueOf(between.toMinutes())));
i = plusI;
}
@ -1258,7 +1277,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
/**
* 记录下操作后的余额
* @param billId 订单id
*
* @param billId 订单id
* @param balance 余额
*/
private void updateAfterBalance(Long billId, BigDecimal balance) {
@ -1270,6 +1290,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
/**
* 取消充值订单
*
* @param billNo 订单编号
* @param status 取消后的状态
*/
@ -1288,8 +1309,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 允许取消的状态
List<String> allowCancel = Arrays.asList(
TransactionBillStatus.UNPAID.getStatus(),
TransactionBillStatus.UNPAID_DEPOSIT.getStatus()
);
TransactionBillStatus.UNPAID_DEPOSIT.getStatus());
ServiceUtil.assertion(!allowCancel.contains(bill.getStatus()), "当前订单状态不允许取消");
Integer result = transactionTemplate.execute(s -> {
@ -1313,7 +1333,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
if (TransactionBillStatus.UNPAID.getStatus().equals(bill.getStatus())) {
cancelPay = payBillService.closeByBstId(bill.getBillId(), PayBillBstType.RECHARGE_ORDER.getType());
} else if (TransactionBillStatus.UNPAID_DEPOSIT.getStatus().equals(bill.getStatus())) {
cancelPay = payBillService.closeByBstId(bill.getBillId(), PayBillBstType.RECHARGE_ORDER_DEPOSIT.getType());
cancelPay = payBillService.closeByBstId(bill.getBillId(),
PayBillBstType.RECHARGE_ORDER_DEPOSIT.getType());
}
ServiceUtil.assertion(!cancelPay, "取消支付订单失败");
@ -1331,7 +1352,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
@Override
public List<TransactionBillVO> selectNoPayedRecharge() {
TransactionBillQuery dto = new TransactionBillQuery();
dto.setStatusList(Arrays.asList(TransactionBillStatus.UNPAID.getStatus(), TransactionBillStatus.PAYING.getStatus(), TransactionBillStatus.UNPAID_DEPOSIT.getStatus()));
dto.setStatusList(Arrays.asList(TransactionBillStatus.UNPAID.getStatus(),
TransactionBillStatus.PAYING.getStatus(), TransactionBillStatus.UNPAID_DEPOSIT.getStatus()));
dto.setType(TransactionBillType.RECHARGE.getType());
return this.selectSmTransactionBillList(dto);
}
@ -1368,7 +1390,6 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return selectSmTransactionBillList(dto);
}
/**
* 查询支付结果直到过期
*
@ -1390,13 +1411,14 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
}
// 未支付成功
List<String> successList = TransactionBillStatus.asList(TransactionBillStatus.SUCCESS, TransactionBillStatus.SUCCESS_DEPOSIT);
List<String> successList = TransactionBillStatus.asList(TransactionBillStatus.SUCCESS,
TransactionBillStatus.SUCCESS_DEPOSIT);
if (!successList.contains(newBill.getStatus())) {
if (newBill.getExpireTime() != null && new Date().compareTo(newBill.getExpireTime()) < 0) {
// 未过期继续延迟查询
log.info("{}支付失败,未过期,继续延迟刷新", newBill);
scheduledExecutorService.schedule(() -> {
this.refreshPayResultBeforeExpire(newBill, delay , timeUnit);
this.refreshPayResultBeforeExpire(newBill, delay, timeUnit);
}, delay, timeUnit);
} else {
log.info("{}支付失败,过期取消订单", newBill);
@ -1412,7 +1434,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
* @param keyMapper 映射方法
*/
@Override
public <K> Map<K, BillCountVo> selectCountMap(TransactionBillQuery query, Function<? super BillCountVo, ? extends K> keyMapper) {
public <K> Map<K, BillCountVo> selectCountMap(TransactionBillQuery query,
Function<? super BillCountVo, ? extends K> keyMapper) {
List<BillCountVo> list = this.selectCount(query);
if (CollectionUtils.isEmptyElement(list)) {
return Collections.emptyMap();
@ -1445,12 +1468,15 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 校验订单
TransactionBillVO bill = this.selectSmTransactionBillByBillId(dto.getBillId());
ServiceUtil.assertion(bill == null, "ID为%s的订单不存在", dto.getBillId());
ServiceUtil.assertion(dto.getRefundAmount().compareTo(bill.getMoney()) > 0, "订单编号为%s的订单退款金额不允许大于订单金额", bill.getBillNo());
ServiceUtil.assertion(!TransactionBillStatus.canRefund().contains(bill.getStatus()), "订单编号为%s的订单状态不允许退款", bill.getBillNo());
ServiceUtil.assertion(dto.getRefundAmount().compareTo(bill.getMoney()) > 0, "订单编号为%s的订单退款金额不允许大于订单金额",
bill.getBillNo());
ServiceUtil.assertion(!TransactionBillStatus.canRefund().contains(bill.getStatus()), "订单编号为%s的订单状态不允许退款",
bill.getBillNo());
// 是否判断订单已完成
if (dto.getCheckFinish() != null && dto.getCheckFinish()) {
ServiceUtil.assertion(bill.getIsFinished() == null || !bill.getIsFinished(), "订单编号为%s的订单未完成不允许退款", bill.getBillNo());
ServiceUtil.assertion(bill.getIsFinished() == null || !bill.getIsFinished(), "订单编号为%s的订单未完成不允许退款",
bill.getBillNo());
}
// 拼接分成列表
@ -1460,7 +1486,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
Integer result = transactionTemplate.execute(status -> {
// 分成方按照比例扣减余额
BigDecimal refundAmount = dto.getRefundAmount(); // 总退款金额
BigDecimal refundAmount = dto.getRefundAmount(); // 总退款金额
int updateRefundBonus = this.updateRefundBonus(bonusList, refundAmount, bill.getMoney());
ServiceUtil.assertion(updateRefundBonus == 0 || updateRefundBonus > bonusList.size(), "商户余额更新失败");
@ -1480,9 +1506,10 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
/**
* 更新分成的退款金额
* @param bonusList 分成列表
*
* @param bonusList 分成列表
* @param refundAmount 本次退款金额
* @param billAmount 订单总金额
* @param billAmount 订单总金额
*/
private int updateRefundBonus(List<BonusVO> bonusList, BigDecimal refundAmount, BigDecimal billAmount) {
if (CollectionUtils.isEmptyElement(bonusList)) {
@ -1499,7 +1526,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
}
// 计算该分成记录的可退金额 = 分配金额 - 已退金额
BigDecimal availableRefund = bonus.getAmount().subtract(bonus.getRefundAmount() == null ? BigDecimal.ZERO : bonus.getRefundAmount());
BigDecimal availableRefund = bonus.getAmount()
.subtract(bonus.getRefundAmount() == null ? BigDecimal.ZERO : bonus.getRefundAmount());
if (availableRefund.compareTo(BigDecimal.ZERO) <= 0) {
continue; // 跳过已无可退金额的记录
}
@ -1556,12 +1584,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
if (bonus.getToBalance() != null && bonus.getToBalance()) {
if (BonusArrivalType.userList().contains(bonus.getArrivalType())) {
userService.subtractBalance(
bonus.getArrivalId(),
bonus.getRefundAmount(),
String.format("订单退款:%s", bonus.getBillNo()),
RecordBalanceBstType.RECHARGE,
bonus.getBillId()
);
bonus.getArrivalId(),
bonus.getRefundAmount(),
String.format("订单退款:%s", bonus.getBillNo()),
RecordBalanceBstType.RECHARGE,
bonus.getBillId());
} else if (BonusArrivalType.deptList().contains(bonus.getArrivalType())) {
// deptService相关逻辑暂时不处理
}
@ -1569,7 +1596,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
}
update++;
}
// 创建分成退款记录
List<BonusRefund> bonusRefundList = bonusRefundConverter.toPo(refundList);
int insertBonusRefund = bonusRefundService.batchInsert(bonusRefundList);
@ -1692,7 +1719,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
}
// 其余订单同步时长
else {
CommandResponse res = deviceService.syncTime(device.getDeviceId(), LocalDateTime.now(), "时长订单" + bill.getBillNo() + "临时开启");
CommandResponse res = deviceService.syncTime(device.getDeviceId(), LocalDateTime.now(),
"时长订单" + bill.getBillNo() + "临时开启");
return res != null && res.isSuccess() ? 1 : 0;
}
} else {
@ -1808,7 +1836,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
ServiceUtil.assertion(update != 1, "修改提现状态失败,提现状态已发生改变");
// 将提现金额退回用户
userService.addBalance(withdraw.getUserId(), withdraw.getMoney(), String.format("提现%s打款失败", withdraw.getBillNo()), RecordBalanceBstType.WITHDRAW, transfer.getBstId());
userService.addBalance(withdraw.getUserId(), withdraw.getMoney(),
String.format("提现%s打款失败", withdraw.getBillNo()), RecordBalanceBstType.WITHDRAW,
transfer.getBstId());
return update;
});
@ -1829,4 +1859,19 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
public BigDecimal selectSumOfServiceCharge(TransactionBillQuery query) {
return transactionBillMapper.selectSumOfServiceCharge(query);
}
@Override
public List<LongDecimalVO> selectSumOfMoneyGroupByStoreId(TransactionBillQuery query) {
return transactionBillMapper.selectSumOfMoneyGroupByStoreId(query);
}
@Override
public List<LongIntegerVO> selectCountGroupByStoreId(TransactionBillQuery query) {
return transactionBillMapper.selectCountGroupByStoreId(query);
}
@Override
public List<LocalDateDecimalVO> selectDailyMoney(TransactionBillQuery query) {
return transactionBillMapper.selectDailyMoney(query);
}
}

View File

@ -1,5 +1,16 @@
package com.ruoyi.web.controller.ss;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.ValidGroup;
@ -8,6 +19,7 @@ import com.ruoyi.common.domain.vo.LocalDateDecimalVO;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.dashboard.domain.dto.BillDailyAmountQuery;
import com.ruoyi.dashboard.domain.dto.DailyIncomeGroupByStoreQuery;
import com.ruoyi.dashboard.domain.dto.ServiceIncomeQuery;
import com.ruoyi.dashboard.domain.vo.BriefVo;
import com.ruoyi.dashboard.domain.vo.DashboardBonusGroupByMchVO;
@ -29,22 +41,14 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import io.swagger.annotations.ApiOperation;
/**
* 报表Controller
*
* @author
* 2024/3/6
* 2024/3/6
*/
@RestController
@RequestMapping("/system/dashboard")
@ -90,6 +94,7 @@ public class SmDashboardController extends BaseController {
/**
* 获取账单分时统计数据
*
* @param dto 查询条件
* @return 统计数据
*/
@ -161,6 +166,7 @@ public class SmDashboardController extends BaseController {
payQuery.setPayDateEnd(query.getDateEnd());
payQuery.setStatusList(PayBillStatus.payedList());
payQuery.setChannelId(query.getChannelId());
payQuery.setStoreId(query.getStoreId());
List<LocalDateDecimalVO> payList = payBillService.selectDailyAmount(payQuery);
RefundQuery refundQuery = new RefundQuery();
@ -168,6 +174,7 @@ public class SmDashboardController extends BaseController {
refundQuery.setCreateDateEnd(query.getDateEnd());
refundQuery.setStatusList(RefundStatus.successList());
refundQuery.setChannelId(query.getChannelId());
refundQuery.setStoreId(query.getStoreId());
List<LocalDateDecimalVO> refundList = refundService.selectDailyAmount(refundQuery);
List<PayDailyAmountVO> list = new ArrayList<>();
@ -176,14 +183,16 @@ public class SmDashboardController extends BaseController {
PayDailyAmountVO vo = new PayDailyAmountVO();
vo.setDate(date);
LocalDateDecimalVO pay = payList.stream().filter(item -> date.isEqual(item.getKey())).findFirst().orElse(null);
LocalDateDecimalVO pay = payList.stream().filter(item -> date.isEqual(item.getKey())).findFirst()
.orElse(null);
if (pay == null) {
vo.setTotal(BigDecimal.ZERO);
} else {
vo.setTotal(pay.getValue());
}
LocalDateDecimalVO refund = refundList.stream().filter(item -> date.isEqual(item.getKey())).findFirst().orElse(null);
LocalDateDecimalVO refund = refundList.stream().filter(item -> date.isEqual(item.getKey())).findFirst()
.orElse(null);
if (refund == null) {
vo.setRefund(BigDecimal.ZERO);
} else {
@ -207,4 +216,13 @@ public class SmDashboardController extends BaseController {
List<DashboardBonusGroupByMchVO> list = dashboardService.selectBonusGroupByMch(query);
return getDataTable(list);
}
/**
* 按店铺统计营收
*/
@GetMapping("/dailyIncomeGroupByStore")
public AjaxResult getDailyIncomeGroupByStore(DailyIncomeGroupByStoreQuery query) {
return success(dashboardService.getDailyIncomeGroupByStore(query));
}
}