数据统计加退款和充值 修改
This commit is contained in:
parent
4ed4a68608
commit
2a52961024
|
|
@ -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")
|
||||
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.enums.PayTypeEnum;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbMemberIn;
|
||||
import cn.ysk.cashier.mybatis.service.TbMemberInService;
|
||||
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyRepository;
|
||||
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.FileUtil;
|
||||
import cn.ysk.cashier.vo.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -55,7 +53,8 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
private TbTokenRepository tbTokenRepository;
|
||||
|
||||
@Resource
|
||||
private TbMemberInService tbMemberInService;
|
||||
private TbShopUserFlowService tbShopUserFlowService;
|
||||
|
||||
|
||||
@Override
|
||||
public SummaryVO selectSummary(Integer shopId) {
|
||||
|
|
@ -368,19 +367,18 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
tPage.getContent().forEach(t -> {
|
||||
TbOrderPayCountByDayVo tbOrderPayCountByDayVo = (TbOrderPayCountByDayVo) t;
|
||||
|
||||
QueryWrapper<TbMemberIn> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("status", "7");
|
||||
queryWrapper.eq("shop_id", summaryDto.getShopId());
|
||||
queryWrapper.ge("create_time", tbOrderPayCountByDayVo.getTradeDay() + " 00:00:00");
|
||||
queryWrapper.le("create_time", tbOrderPayCountByDayVo.getTradeDay() + " 23:59:59");
|
||||
// 会员充值金额 amount 求和
|
||||
queryWrapper.select("IFNULL (sum(amount), 0) AS amountTotal");
|
||||
BigDecimal recharge = tbShopUserFlowService.sumUserFlowAmountByConditions(Long.valueOf(summaryDto.getShopId()),
|
||||
tbOrderPayCountByDayVo.getTradeDay() + " 00:00:00",
|
||||
tbOrderPayCountByDayVo.getTradeDay() + " 23:59:59",
|
||||
Arrays.asList("cashMemberIn", "scanMemberIn"));
|
||||
tbOrderPayCountByDayVo.setRecharge(recharge);
|
||||
|
||||
Map<String, Object> map = tbMemberInService.getMap(queryWrapper);
|
||||
|
||||
tbOrderPayCountByDayVo.setRecharge(new BigDecimal(map.get("amountTotal").toString()));
|
||||
BigDecimal decimal = tbOrderInfoRepository.queryRefundOrderAmountByTradeDay(summaryDto.getShopId(), tbOrderPayCountByDayVo.getTradeDay());
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue