diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/service/SmBusinessRecordServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/service/SmBusinessRecordServiceImpl.java index 456f6e27..356d17bd 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/service/SmBusinessRecordServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/service/SmBusinessRecordServiceImpl.java @@ -28,6 +28,7 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.time.LocalDate; +import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; @@ -200,25 +201,22 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService brief.setAgentCount(userService.selectCount(agentQuery)); // 充值金额总数 - TransactionBillQuery rechargeDto = new TransactionBillQuery(); - rechargeDto.setStatus(TransactionBillStatus.SUCCESS.getStatus()); - List billCount = transactionBillService.selectCount(rechargeDto); - if (!CollectionUtils.isEmpty(billCount) && billCount.get(0).getRecharge() != null) { - brief.setRechargeAmount(billCount.get(0).getRechargeAmount()); - } else { - brief.setRechargeAmount(BigDecimal.ZERO); + TransactionBillQuery billQuery = new TransactionBillQuery(); + billQuery.setStatusList(TransactionBillStatus.payedOrder()); + billQuery.setType(TransactionBillType.RECHARGE.getType()); + BigDecimal rechargeAmount = transactionBillService.selectSumOfMoneyWithoutRefund(billQuery); + if (rechargeAmount == null) { + rechargeAmount = BigDecimal.ZERO; } + brief.setRechargeAmount(rechargeAmount); // 今日充值金额总数 - TransactionBillQuery todayRechargeQuery = new TransactionBillQuery(); - todayRechargeQuery.setStatusList(TransactionBillStatus.payedOrder()); - todayRechargeQuery.setCreateDate(now); - List todayBillCount = transactionBillService.selectCount(todayRechargeQuery); - if (!CollectionUtils.isEmpty(todayBillCount) && todayBillCount.get(0).getRecharge() != null) { - brief.setTodayRechargeAmount(todayBillCount.get(0).getRechargeAmount()); - } else { - brief.setTodayRechargeAmount(BigDecimal.ZERO); + billQuery.setCreateDate(now); + BigDecimal todayRechargeAmount = transactionBillService.selectSumOfMoneyWithoutRefund(billQuery); + if (todayRechargeAmount == null) { + todayRechargeAmount = BigDecimal.ZERO; } + brief.setTodayRechargeAmount(todayRechargeAmount); // 用户总余额 brief.setTotalUserBalance(userService.selectSumOfBalance(new SmUserQuery())); diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/store/domain/vo/StoreOperatorVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/store/domain/vo/StoreOperatorVO.java index ba6179b0..cab3061f 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/store/domain/vo/StoreOperatorVO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/store/domain/vo/StoreOperatorVO.java @@ -23,12 +23,16 @@ public class StoreOperatorVO { @ApiModelProperty("注销店铺") private Boolean del; + @ApiModelProperty("添加合伙人") + private Boolean addStaff; + public static StoreOperatorVO defaultInstance() { StoreOperatorVO vo = new StoreOperatorVO(); vo.setViewDevice(false); vo.setUpdate(false); vo.setConfig(false); vo.setDel(false); + vo.setAddStaff(false); return vo; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreAssemblerImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreAssemblerImpl.java index 793d2793..ed5f3675 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreAssemblerImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/store/service/impl/StoreAssemblerImpl.java @@ -258,6 +258,7 @@ public class StoreAssemblerImpl implements StoreAssembler { if (storeValidator.isMch(store, userId)) { vo.setDel(true); vo.setViewDevice(true); + vo.setAddStaff(true); } store.setOperator(vo); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionDailyAmountVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionDailyAmountVO.java new file mode 100644 index 00000000..a906e756 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionDailyAmountVO.java @@ -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; + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java index 42a45f86..ca617689 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.java @@ -7,6 +7,7 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBill; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; +import com.ruoyi.ss.transactionBill.domain.vo.TransactionDailyAmountVO; import org.apache.ibatis.annotations.Param; import java.math.BigDecimal; @@ -204,4 +205,14 @@ public interface TransactionBillMapper * 查询统计数量 */ List selectCountGroupBy(@Param("query") TransactionBillQuery query, @Param("groupBy") String groupBy); + + /** + * 查询订单总金额(不包含退款) + */ + BigDecimal selectSumOfMoneyWithoutRefund(@Param("query") TransactionBillQuery query); + + /** + * 按日查询金额 + */ + List selectDailyAmount(@Param("query") TransactionBillQuery query); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml index 59509da8..c33e5f9e 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml @@ -360,7 +360,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" stb.device_id as device_id, - 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 = '2' and stb.status = '14', stb.arrival_amount, 0 )) AS withdraw, SUM(stb.service_charge) AS service_charge, @@ -454,6 +454,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + SELECT LAST_INSERT_ID(); diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java index d6cfd5da..64473eb2 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java @@ -336,4 +336,14 @@ public interface TransactionBillService * 查询员工可见列表 */ List selectStaffDeviceList(TransactionBillQuery query); + + /** + * 查询去除退款金额的订单金额 + */ + BigDecimal selectSumOfMoneyWithoutRefund(TransactionBillQuery query); + + /** + * 按日查询订单金额 + */ + List selectDailyAmount(TransactionBillQuery query); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java index 86fad332..81c1df50 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java @@ -432,6 +432,16 @@ public class TransactionBillServiceImpl implements TransactionBillService, After return this.selectSmTransactionBillList(query); } + @Override + public BigDecimal selectSumOfMoneyWithoutRefund(TransactionBillQuery query) { + return transactionBillMapper.selectSumOfMoneyWithoutRefund(query); + } + + @Override + public List selectDailyAmount(TransactionBillQuery query) { + return transactionBillMapper.selectDailyAmount(query); + } + @Override public List selectCountGroupBy(TransactionBillQuery query, String groupBy) { return transactionBillMapper.selectCountGroupBy(query, groupBy); diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.java index c1b141d8..fdb5698f 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.java @@ -66,7 +66,16 @@ public interface SmUserMapper 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); @@ -97,8 +106,13 @@ public interface SmUserMapper * @param userId 用户id * @param amount 金额 * @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 + ); /** * 更新用户服务费 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml index 67ba795f..4d11b443 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/user/mapper/SmUserMapper.xml @@ -261,7 +261,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update sm_user set balance = balance + #{amount} - where user_id = #{userId} and del_flag = '0' + where user_id = #{userId} and del_flag = '0' and balance = #{beforeBalance} @@ -330,10 +330,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update sm_user set balance = balance - #{amount} - user_id = #{userId} and del_flag = '0' + user_id = #{userId} and del_flag = '0' and balance = #{beforeBalance} and balance >= #{amount} + diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/user/service/impl/SmUserServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/user/service/impl/SmUserServiceImpl.java index 17248707..fdf7b02d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/user/service/impl/SmUserServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/user/service/impl/SmUserServiceImpl.java @@ -211,8 +211,8 @@ public class SmUserServiceImpl implements ISmUserService SmUserVO user = selectSmUserByUserId(userId); // 修改余额 - int updateCount = smUserMapper.addBalance(userId, amount); - ServiceUtil.assertion(updateCount != 1, "增加用户余额失败"); + int updateCount = smUserMapper.addBalance(userId, amount, user.getBalance()); + ServiceUtil.assertion(updateCount != 1, "增加用户余额失败,请重试"); // 余额变动记录 int record = recordBalanceService.record(userId, user.getBalance(), amount, reason, bstType, bstId); @@ -238,8 +238,8 @@ public class SmUserServiceImpl implements ISmUserService SmUserVO user = selectSmUserByUserId(userId); // 更新用户余额 - int updateCount = smUserMapper.subtractBalance(userId, amount, check); - ServiceUtil.assertion(updateCount != 1, "减少用户余额失败:用户不存在或余额不足"); + int updateCount = smUserMapper.subtractBalance(userId, amount, check, user.getBalance()); + ServiceUtil.assertion(updateCount != 1, "减少用户余额失败,请重试"); // 余额变动记录 int record = recordBalanceService.record(userId, user.getBalance(), amount.negate(), reason, bstType, bstId); diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java index 43b11111..fe91250c 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java @@ -178,7 +178,7 @@ public class AppTransactionBillController extends BaseController dto.setEndDate(DateUtils.toLocalDate(DateUtils.getMonthLastDate(dto.getYear(), dto.getMonth()))); } - // FIXME 需要统计退款的订单,并且需要过滤掉退款的金额 + // FIXME 需要过滤掉退款的金额 dto.setMchId(getUserId()); dto.setStatusList(TransactionBillStatus.income()); AjaxResult ajax = AjaxResult.success(transactionBillService.selectLandlordCount(dto)); diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDashboardController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDashboardController.java index 0873c866..02b10b1e 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDashboardController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDashboardController.java @@ -14,6 +14,7 @@ import com.ruoyi.ss.bonus.service.BonusService; import com.ruoyi.ss.businessRecord.service.ISmBusinessRecordService; import com.ruoyi.dashboard.domain.dto.ServiceIncomeQuery; 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.domain.enums.TransactionBillGroupBy; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; @@ -134,4 +135,22 @@ public class SmDashboardController extends BaseController { return success(list); } + /** + * 按天统计订单金额数据 + */ + @GetMapping("/billDailyAmount") + public AjaxResult getBillDailyAmount(TransactionBillQuery query) { + List 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); + } }