新增对账报表

This commit is contained in:
磷叶 2024-12-02 15:22:11 +08:00
parent 391695de15
commit 7f02aa43a8
13 changed files with 148 additions and 25 deletions

View File

@ -28,6 +28,7 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -200,25 +201,22 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
brief.setAgentCount(userService.selectCount(agentQuery)); brief.setAgentCount(userService.selectCount(agentQuery));
// 充值金额总数 // 充值金额总数
TransactionBillQuery rechargeDto = new TransactionBillQuery(); TransactionBillQuery billQuery = new TransactionBillQuery();
rechargeDto.setStatus(TransactionBillStatus.SUCCESS.getStatus()); billQuery.setStatusList(TransactionBillStatus.payedOrder());
List<BillCountVo> billCount = transactionBillService.selectCount(rechargeDto); billQuery.setType(TransactionBillType.RECHARGE.getType());
if (!CollectionUtils.isEmpty(billCount) && billCount.get(0).getRecharge() != null) { BigDecimal rechargeAmount = transactionBillService.selectSumOfMoneyWithoutRefund(billQuery);
brief.setRechargeAmount(billCount.get(0).getRechargeAmount()); if (rechargeAmount == null) {
} else { rechargeAmount = BigDecimal.ZERO;
brief.setRechargeAmount(BigDecimal.ZERO);
} }
brief.setRechargeAmount(rechargeAmount);
// 今日充值金额总数 // 今日充值金额总数
TransactionBillQuery todayRechargeQuery = new TransactionBillQuery(); billQuery.setCreateDate(now);
todayRechargeQuery.setStatusList(TransactionBillStatus.payedOrder()); BigDecimal todayRechargeAmount = transactionBillService.selectSumOfMoneyWithoutRefund(billQuery);
todayRechargeQuery.setCreateDate(now); if (todayRechargeAmount == null) {
List<BillCountVo> todayBillCount = transactionBillService.selectCount(todayRechargeQuery); todayRechargeAmount = BigDecimal.ZERO;
if (!CollectionUtils.isEmpty(todayBillCount) && todayBillCount.get(0).getRecharge() != null) {
brief.setTodayRechargeAmount(todayBillCount.get(0).getRechargeAmount());
} else {
brief.setTodayRechargeAmount(BigDecimal.ZERO);
} }
brief.setTodayRechargeAmount(todayRechargeAmount);
// 用户总余额 // 用户总余额
brief.setTotalUserBalance(userService.selectSumOfBalance(new SmUserQuery())); brief.setTotalUserBalance(userService.selectSumOfBalance(new SmUserQuery()));

View File

@ -23,12 +23,16 @@ public class StoreOperatorVO {
@ApiModelProperty("注销店铺") @ApiModelProperty("注销店铺")
private Boolean del; private Boolean del;
@ApiModelProperty("添加合伙人")
private Boolean addStaff;
public static StoreOperatorVO defaultInstance() { public static StoreOperatorVO defaultInstance() {
StoreOperatorVO vo = new StoreOperatorVO(); StoreOperatorVO vo = new StoreOperatorVO();
vo.setViewDevice(false); vo.setViewDevice(false);
vo.setUpdate(false); vo.setUpdate(false);
vo.setConfig(false); vo.setConfig(false);
vo.setDel(false); vo.setDel(false);
vo.setAddStaff(false);
return vo; return vo;
} }

View File

@ -258,6 +258,7 @@ public class StoreAssemblerImpl implements StoreAssembler {
if (storeValidator.isMch(store, userId)) { if (storeValidator.isMch(store, userId)) {
vo.setDel(true); vo.setDel(true);
vo.setViewDevice(true); vo.setViewDevice(true);
vo.setAddStaff(true);
} }
store.setOperator(vo); store.setOperator(vo);
} }

View File

@ -0,0 +1,28 @@
package com.ruoyi.ss.transactionBill.domain.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* @author wjh
* 2024/12/2
*/
@Data
public class TransactionDailyAmountVO {
@ApiModelProperty("日期")
private LocalDate date;
@ApiModelProperty("订单总金额")
private BigDecimal total;
@ApiModelProperty("订单退款总金额")
private BigDecimal refund;
@ApiModelProperty("订单总实收金额")
private BigDecimal received;
}

View File

@ -7,6 +7,7 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBill;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionDailyAmountVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -204,4 +205,14 @@ public interface TransactionBillMapper
* 查询统计数量 * 查询统计数量
*/ */
List<JSONObject> selectCountGroupBy(@Param("query") TransactionBillQuery query, @Param("groupBy") String groupBy); List<JSONObject> selectCountGroupBy(@Param("query") TransactionBillQuery query, @Param("groupBy") String groupBy);
/**
* 查询订单总金额不包含退款
*/
BigDecimal selectSumOfMoneyWithoutRefund(@Param("query") TransactionBillQuery query);
/**
* 按日查询金额
*/
List<TransactionDailyAmountVO> selectDailyAmount(@Param("query") TransactionBillQuery query);
} }

View File

@ -360,7 +360,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.groupBy == 'device_id'"> <if test="query.groupBy == 'device_id'">
stb.device_id as device_id, stb.device_id as device_id,
</if> </if>
SUM(IF( stb.type = '1' and stb.status = '2', stb.arrival_amount, 0 )) AS recharge, 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 = '2', stb.money, 0 )) AS recharge_amount,
SUM(IF( stb.type = '2' and stb.status = '14', stb.arrival_amount, 0 )) AS withdraw, SUM(IF( stb.type = '2' and stb.status = '14', stb.arrival_amount, 0 )) AS withdraw,
SUM(stb.service_charge) AS service_charge, SUM(stb.service_charge) AS service_charge,
@ -454,6 +454,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
</select> </select>
<select id="selectSumOfMoneyWithoutRefund" resultType="java.math.BigDecimal">
select sum(stb.money) - sum(stb.refund_amount)
from sm_transaction_bill stb
<where>
<include refid="searchCondition"/>
</where>
</select>
<resultMap id="TransactionDailyAmountVO" type="TransactionDailyAmountVO">
<result property="date" column="date"/>
<result property="total" column="total" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="refund" column="refund" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="received" column="received" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
</resultMap>
<select id="selectDailyAmount" resultMap="TransactionDailyAmountVO">
select
date(stb.create_time) as `date`,
sum(stb.money) as `total`,
sum(stb.refund_amount) as `refund`,
sum(stb.money) - sum(stb.refund_amount) as `received`
from sm_transaction_bill stb
<where>
<include refid="searchCondition"/>
</where>
group by `date`
</select>
<insert id="insertSmTransactionBill" parameterType="TransactionBill" useGeneratedKeys="true" keyProperty="billId"> <insert id="insertSmTransactionBill" parameterType="TransactionBill" useGeneratedKeys="true" keyProperty="billId">
<selectKey resultType="Long" order="AFTER" keyProperty="billId"> <selectKey resultType="Long" order="AFTER" keyProperty="billId">
SELECT LAST_INSERT_ID(); SELECT LAST_INSERT_ID();

View File

@ -336,4 +336,14 @@ public interface TransactionBillService
* 查询员工可见列表 * 查询员工可见列表
*/ */
List<TransactionBillVO> selectStaffDeviceList(TransactionBillQuery query); List<TransactionBillVO> selectStaffDeviceList(TransactionBillQuery query);
/**
* 查询去除退款金额的订单金额
*/
BigDecimal selectSumOfMoneyWithoutRefund(TransactionBillQuery query);
/**
* 按日查询订单金额
*/
List<TransactionDailyAmountVO> selectDailyAmount(TransactionBillQuery query);
} }

View File

@ -432,6 +432,16 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return this.selectSmTransactionBillList(query); return this.selectSmTransactionBillList(query);
} }
@Override
public BigDecimal selectSumOfMoneyWithoutRefund(TransactionBillQuery query) {
return transactionBillMapper.selectSumOfMoneyWithoutRefund(query);
}
@Override
public List<TransactionDailyAmountVO> selectDailyAmount(TransactionBillQuery query) {
return transactionBillMapper.selectDailyAmount(query);
}
@Override @Override
public List<JSONObject> selectCountGroupBy(TransactionBillQuery query, String groupBy) { public List<JSONObject> selectCountGroupBy(TransactionBillQuery query, String groupBy) {
return transactionBillMapper.selectCountGroupBy(query, groupBy); return transactionBillMapper.selectCountGroupBy(query, groupBy);

View File

@ -66,7 +66,16 @@ public interface SmUserMapper
int selectCount(SmUserQuery dto); int selectCount(SmUserQuery dto);
int addBalance(@Param("userId") Long userId, @Param("amount") BigDecimal amount); /**
* 增加余额
* @param userId 用户id
* @param amount 金额
* @param beforeBalance 变动前的余额并发
*/
int addBalance(@Param("userId") Long userId,
@Param("amount") BigDecimal amount,
@Param("beforeBalance") BigDecimal beforeBalance
);
SmUserVO selectSmUserByWxOpenId(String openId); SmUserVO selectSmUserByWxOpenId(String openId);
@ -97,8 +106,13 @@ public interface SmUserMapper
* @param userId 用户id * @param userId 用户id
* @param amount 金额 * @param amount 金额
* @param check 校验余额是否充足 * @param check 校验余额是否充足
* @param beforeBalance 变动前的余额并发
*/ */
int subtractBalance(@Param("userId") Long userId, @Param("amount") BigDecimal amount, @Param("check") boolean check); int subtractBalance(@Param("userId") Long userId,
@Param("amount") BigDecimal amount,
@Param("check") boolean check,
@Param("beforeBalance") BigDecimal beforeBalance
);
/** /**
* 更新用户服务费 * 更新用户服务费

View File

@ -261,7 +261,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="addBalance"> <update id="addBalance">
update sm_user update sm_user
set balance = balance + #{amount} set balance = balance + #{amount}
where user_id = #{userId} and del_flag = '0' where user_id = #{userId} and del_flag = '0' and balance = #{beforeBalance}
</update> </update>
<update id="updateSmUser" parameterType="SmUser"> <update id="updateSmUser" parameterType="SmUser">
@ -330,10 +330,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update sm_user update sm_user
set balance = balance - #{amount} set balance = balance - #{amount}
<where> <where>
user_id = #{userId} and del_flag = '0' user_id = #{userId} and del_flag = '0' and balance = #{beforeBalance}
<if test="check"> <if test="check">
and balance >= #{amount} and balance >= #{amount}
</if> </if>
</where> </where>
</update> </update>

View File

@ -211,8 +211,8 @@ public class SmUserServiceImpl implements ISmUserService
SmUserVO user = selectSmUserByUserId(userId); SmUserVO user = selectSmUserByUserId(userId);
// 修改余额 // 修改余额
int updateCount = smUserMapper.addBalance(userId, amount); int updateCount = smUserMapper.addBalance(userId, amount, user.getBalance());
ServiceUtil.assertion(updateCount != 1, "增加用户余额失败"); ServiceUtil.assertion(updateCount != 1, "增加用户余额失败,请重试");
// 余额变动记录 // 余额变动记录
int record = recordBalanceService.record(userId, user.getBalance(), amount, reason, bstType, bstId); int record = recordBalanceService.record(userId, user.getBalance(), amount, reason, bstType, bstId);
@ -238,8 +238,8 @@ public class SmUserServiceImpl implements ISmUserService
SmUserVO user = selectSmUserByUserId(userId); SmUserVO user = selectSmUserByUserId(userId);
// 更新用户余额 // 更新用户余额
int updateCount = smUserMapper.subtractBalance(userId, amount, check); int updateCount = smUserMapper.subtractBalance(userId, amount, check, user.getBalance());
ServiceUtil.assertion(updateCount != 1, "减少用户余额失败:用户不存在或余额不足"); ServiceUtil.assertion(updateCount != 1, "减少用户余额失败,请重试");
// 余额变动记录 // 余额变动记录
int record = recordBalanceService.record(userId, user.getBalance(), amount.negate(), reason, bstType, bstId); int record = recordBalanceService.record(userId, user.getBalance(), amount.negate(), reason, bstType, bstId);

View File

@ -178,7 +178,7 @@ public class AppTransactionBillController extends BaseController
dto.setEndDate(DateUtils.toLocalDate(DateUtils.getMonthLastDate(dto.getYear(), dto.getMonth()))); dto.setEndDate(DateUtils.toLocalDate(DateUtils.getMonthLastDate(dto.getYear(), dto.getMonth())));
} }
// FIXME 需要统计退款的订单并且需要过滤掉退款的金额 // FIXME 需要过滤掉退款的金额
dto.setMchId(getUserId()); dto.setMchId(getUserId());
dto.setStatusList(TransactionBillStatus.income()); dto.setStatusList(TransactionBillStatus.income());
AjaxResult ajax = AjaxResult.success(transactionBillService.selectLandlordCount(dto)); AjaxResult ajax = AjaxResult.success(transactionBillService.selectLandlordCount(dto));

View File

@ -14,6 +14,7 @@ import com.ruoyi.ss.bonus.service.BonusService;
import com.ruoyi.ss.businessRecord.service.ISmBusinessRecordService; import com.ruoyi.ss.businessRecord.service.ISmBusinessRecordService;
import com.ruoyi.dashboard.domain.dto.ServiceIncomeQuery; import com.ruoyi.dashboard.domain.dto.ServiceIncomeQuery;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionDailyAmountVO;
import com.ruoyi.ss.transactionBill.service.TransactionBillService; import com.ruoyi.ss.transactionBill.service.TransactionBillService;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillGroupBy;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
@ -134,4 +135,22 @@ public class SmDashboardController extends BaseController {
return success(list); return success(list);
} }
/**
* 按天统计订单金额数据
*/
@GetMapping("/billDailyAmount")
public AjaxResult getBillDailyAmount(TransactionBillQuery query) {
List<TransactionDailyAmountVO> list = transactionBillService.selectDailyAmount(query);
if (query.getStartDate() != null && query.getEndDate() != null) {
CollectionUtils.fillVoids(list, TransactionDailyAmountVO::getDate, (date) -> {
TransactionDailyAmountVO vo = new TransactionDailyAmountVO();
vo.setDate(date);
vo.setTotal(BigDecimal.ZERO);
vo.setRefund(BigDecimal.ZERO);
vo.setReceived(BigDecimal.ZERO);
return vo;
}, query.getStartDate(), query.getEndDate());
}
return success(list);
}
} }