数据统计加退款和充值 修改
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package cn.ysk.cashier.mybatis.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author GYJ
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("tb_shop_user_flow")
|
||||||
|
public class TbShopUserFlow extends Model<TbShopUserFlow> {
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private Integer shopUserId;
|
||||||
|
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
private BigDecimal balance;
|
||||||
|
|
||||||
|
private String bizCode;
|
||||||
|
|
||||||
|
private String bizName;
|
||||||
|
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package cn.ysk.cashier.mybatis.mapper;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbShopUserFlow;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author GYJ
|
||||||
|
*/
|
||||||
|
public interface TbShopUserFlowMapper extends BaseMapper<TbShopUserFlow> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据条件查询用户流水总金额
|
||||||
|
*
|
||||||
|
* @param shopId 店铺ID
|
||||||
|
* @param startTime 开始时间
|
||||||
|
* @param endTime 结束时间
|
||||||
|
* @param types 流水类型
|
||||||
|
* @return 用户流水总金额
|
||||||
|
*/
|
||||||
|
@Select("<script>" +
|
||||||
|
"SELECT IFNULL(SUM(uf.amount), 0) FROM tb_shop_user_flow as uf " +
|
||||||
|
"JOIN tb_shop_user su ON uf.shop_user_id = su.user_id " +
|
||||||
|
"WHERE su.shop_id = #{shopId} " +
|
||||||
|
"AND uf.create_time BETWEEN #{startTime} AND #{endTime} " +
|
||||||
|
"AND uf.biz_code IN " +
|
||||||
|
"<foreach collection='types' item='type' open='(' separator=',' close=')'> " +
|
||||||
|
"#{type} " +
|
||||||
|
"</foreach> " +
|
||||||
|
"</script>")
|
||||||
|
BigDecimal sumUserFlowAmountByConditions(@Param("shopId") Long shopId,
|
||||||
|
@Param("startTime") String startTime,
|
||||||
|
@Param("endTime") String endTime,
|
||||||
|
@Param("types") List<String> types);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package cn.ysk.cashier.mybatis.service;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbShopUserFlow;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author GYJ
|
||||||
|
*/
|
||||||
|
public interface TbShopUserFlowService extends IService<TbShopUserFlow> {
|
||||||
|
|
||||||
|
BigDecimal sumUserFlowAmountByConditions(Long shopId, String startTime, String endTime, List<String> types);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package cn.ysk.cashier.mybatis.service.impl;
|
||||||
|
|
||||||
|
import cn.ysk.cashier.mybatis.entity.TbShopUserFlow;
|
||||||
|
import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper;
|
||||||
|
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author GYJ
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TbShopUserFlowServiceImpl extends ServiceImpl<TbShopUserFlowMapper, TbShopUserFlow> implements TbShopUserFlowService {
|
||||||
|
@Override
|
||||||
|
public BigDecimal sumUserFlowAmountByConditions(Long shopId, String startTime, String endTime, List<String> types) {
|
||||||
|
return baseMapper.sumUserFlowAmountByConditions(shopId, startTime, endTime, types);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,4 +44,7 @@ public interface TbShopUserRepository extends JpaRepository<TbShopUser, Integer>
|
|||||||
@Query("SELECT count(0) from TbShopUser user where user.shopId = :shopId and user.createdAt BETWEEN :startTime AND :endTime")
|
@Query("SELECT count(0) from TbShopUser user where user.shopId = :shopId and user.createdAt BETWEEN :startTime AND :endTime")
|
||||||
List<Object[]> CountTodayGroup(@Param("shopId") String shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
List<Object[]> CountTodayGroup(@Param("shopId") String shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||||
|
|
||||||
}
|
@Query("SELECT user.userId from TbShopUser user where user.shopId = :shopId")
|
||||||
|
List<Integer> getUserIdByShopId(String shopId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ package cn.ysk.cashier.service.impl;
|
|||||||
import cn.ysk.cashier.dto.ShopSummaryDto;
|
import cn.ysk.cashier.dto.ShopSummaryDto;
|
||||||
import cn.ysk.cashier.enums.PayTypeEnum;
|
import cn.ysk.cashier.enums.PayTypeEnum;
|
||||||
import cn.ysk.cashier.exception.BadRequestException;
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
import cn.ysk.cashier.mybatis.entity.TbMemberIn;
|
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
|
||||||
import cn.ysk.cashier.mybatis.service.TbMemberInService;
|
|
||||||
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
|
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
|
||||||
import cn.ysk.cashier.repository.ShopUserDutyRepository;
|
import cn.ysk.cashier.repository.ShopUserDutyRepository;
|
||||||
import cn.ysk.cashier.repository.TbTokenRepository;
|
import cn.ysk.cashier.repository.TbTokenRepository;
|
||||||
@@ -15,7 +14,6 @@ import cn.ysk.cashier.service.SummaryService;
|
|||||||
import cn.ysk.cashier.utils.DateUtil;
|
import cn.ysk.cashier.utils.DateUtil;
|
||||||
import cn.ysk.cashier.utils.FileUtil;
|
import cn.ysk.cashier.utils.FileUtil;
|
||||||
import cn.ysk.cashier.vo.*;
|
import cn.ysk.cashier.vo.*;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -55,7 +53,8 @@ public class SummaryServiceImpl implements SummaryService {
|
|||||||
private TbTokenRepository tbTokenRepository;
|
private TbTokenRepository tbTokenRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TbMemberInService tbMemberInService;
|
private TbShopUserFlowService tbShopUserFlowService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SummaryVO selectSummary(Integer shopId) {
|
public SummaryVO selectSummary(Integer shopId) {
|
||||||
@@ -368,19 +367,18 @@ public class SummaryServiceImpl implements SummaryService {
|
|||||||
tPage.getContent().forEach(t -> {
|
tPage.getContent().forEach(t -> {
|
||||||
TbOrderPayCountByDayVo tbOrderPayCountByDayVo = (TbOrderPayCountByDayVo) t;
|
TbOrderPayCountByDayVo tbOrderPayCountByDayVo = (TbOrderPayCountByDayVo) t;
|
||||||
|
|
||||||
QueryWrapper<TbMemberIn> queryWrapper = new QueryWrapper<>();
|
BigDecimal recharge = tbShopUserFlowService.sumUserFlowAmountByConditions(Long.valueOf(summaryDto.getShopId()),
|
||||||
queryWrapper.eq("status", "7");
|
tbOrderPayCountByDayVo.getTradeDay() + " 00:00:00",
|
||||||
queryWrapper.eq("shop_id", summaryDto.getShopId());
|
tbOrderPayCountByDayVo.getTradeDay() + " 23:59:59",
|
||||||
queryWrapper.ge("create_time", tbOrderPayCountByDayVo.getTradeDay() + " 00:00:00");
|
Arrays.asList("cashMemberIn", "scanMemberIn"));
|
||||||
queryWrapper.le("create_time", tbOrderPayCountByDayVo.getTradeDay() + " 23:59:59");
|
tbOrderPayCountByDayVo.setRecharge(recharge);
|
||||||
// 会员充值金额 amount 求和
|
|
||||||
queryWrapper.select("IFNULL (sum(amount), 0) AS amountTotal");
|
|
||||||
|
|
||||||
Map<String, Object> map = tbMemberInService.getMap(queryWrapper);
|
|
||||||
|
|
||||||
tbOrderPayCountByDayVo.setRecharge(new BigDecimal(map.get("amountTotal").toString()));
|
|
||||||
BigDecimal decimal = tbOrderInfoRepository.queryRefundOrderAmountByTradeDay(summaryDto.getShopId(), tbOrderPayCountByDayVo.getTradeDay());
|
BigDecimal decimal = tbOrderInfoRepository.queryRefundOrderAmountByTradeDay(summaryDto.getShopId(), tbOrderPayCountByDayVo.getTradeDay());
|
||||||
tbOrderPayCountByDayVo.setRefund(decimal == null ? new BigDecimal("0.00") : decimal);
|
tbOrderPayCountByDayVo.setRefund(decimal == null ? new BigDecimal("0.00") : decimal);
|
||||||
|
|
||||||
|
BigDecimal total = (BigDecimal) tbOrderPayCountByDayVo.getTotal();
|
||||||
|
BigDecimal refund = (BigDecimal) tbOrderPayCountByDayVo.getRefund();
|
||||||
|
tbOrderPayCountByDayVo.setTotal(total.subtract(refund));
|
||||||
});
|
});
|
||||||
|
|
||||||
return tPage;
|
return tPage;
|
||||||
|
|||||||
Reference in New Issue
Block a user