小程序运营统计

This commit is contained in:
邱贞招 2025-01-13 14:44:34 +08:00
parent 38bc84bab6
commit 2df11d8bf8
20 changed files with 452 additions and 216 deletions

View File

@ -48,6 +48,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import static com.ruoyi.common.constant.ServiceConstants.TIME_LIMIT_7_DAYS;
/**
* app接口需要登录校验的
@ -97,13 +99,10 @@ public class AppVerifyController extends BaseController
* 首页统计
*/
@GetMapping(value = { "/index" })
public AjaxResult index(String startTime,String endTime)
public AjaxResult index(String timeLimit)
{
logger.info("【首页统计/index】参数startTime={},endTime={}", startTime,endTime);
AjaxResult ajax = AjaxResult.success();
IndexAdminVo incomeVos = orderService.indexStatistics(startTime, endTime,getUserId());
ajax.put(AjaxResult.DATA_TAG, incomeVos);
return ajax;
logger.info("【首页统计/index】参数timeLimit={}", timeLimit);
return success(orderService.indexStatistics(timeLimit));
}
/**

View File

@ -1106,5 +1106,39 @@ public class ServiceConstants {
/**----------------------------是否已退款end----------------------------*/
/**----------------------------首页时间范围start----------------------------*/
/**
* 是否已退款: 1-7天
*/
public static final String TIME_LIMIT_7_DAYS = "1";
/**
* 是否已退款: 1-30天
*/
public static final String TIME_LIMIT_30_DAYS = "2";
/**----------------------------首页时间范围end----------------------------*/
/**----------------------------首页时间范围start----------------------------*/
/**
* 时间范围: 今天
*/
public static final String TIME_LIMIT_TODAY = "today";
/**
* 时间范围: 本周
*/
public static final String TIME_LIMIT_WEEK = "week";
/**
* 时间范围: 本月
*/
public static final String TIME_LIMIT_MONTH = "month";
/**----------------------------首页时间范围end----------------------------*/
}

View File

@ -48,6 +48,10 @@ public class DividendDetail extends BaseEntity
@Excel(name = "分账金额")
private BigDecimal dividendAmount;
/** 结算金额 */
@Excel(name = "结算金额")
private BigDecimal settlementAmount;
/** 分红比例 */
@Excel(name = "分红比例")
private BigDecimal dividendProportion;

View File

@ -2,9 +2,17 @@ package com.ruoyi.ss.dividendDetail.domain;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class DividendDetailQuery extends DividendDetail{
/** 代理商名称 */
private String agentName;
/** 开始时间 */
private LocalDateTime startTime;
/** 结束时间 */
private LocalDateTime endTime;
}

View File

@ -5,7 +5,4 @@ import lombok.Data;
@Data
public class DividendDetailVO extends DividendDetail{
/** 代理名称 */
private String agentName;
}

View File

@ -1,9 +1,15 @@
package com.ruoyi.ss.dividendDetail.mapper;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.dividendDetail.domain.DividendDetail;
import com.ruoyi.ss.dividendDetail.domain.DividendDetailQuery;
import com.ruoyi.ss.dividendDetail.domain.DividendDetailVO;
import com.ruoyi.system.domain.vo.InCome;
import com.ruoyi.system.domain.vo.IndexAdminVo;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@ -69,4 +75,19 @@ public interface DividendDetailMapper
* @return
*/
List<DividendDetailVO> selectRlDividendDetailListByOrderNo(String orderNo);
/**
* 根据商户id查询近7天收入
*/
List<InCome> select7DaysIncome(Long merchantId);
/**
* 根据商户id查询近30天收入
*/
List<InCome> select30DaysIncome(Long merchantId);
/**
* 查询收入
*/
BigDecimal getIncome(DividendDetailQuery query );
}

View File

@ -7,16 +7,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="DividendDetailVO" id="RlDividendDetailResult" autoMapping="true" />
<sql id="selectRlDividendDetailVo">
select dd.id, dd.partner_id, dd.partner_name, dd.partner_phone, dd.partner_type, dd.order_no,dd.status,dd.refund_amount,
dd.total_amount, dd.dividend_amount, dd.dividend_proportion, dd.create_time from ss_dividend_detail dd
select dd.id,
dd.partner_id,
dd.partner_name,
dd.partner_phone,
dd.partner_type,
dd.order_no,
dd.status,
dd.refund_amount,
dd.total_amount,
dd.dividend_amount,
dd.settlement_amount,
dd.dividend_proportion,
dd.create_time
from ss_dividend_detail dd
left join ss_user u on u.user_id = dd.partner_id
</sql>
<select id="selectRlDividendDetailList" parameterType="DividendDetailQuery" resultMap="RlDividendDetailResult">
<include refid="selectRlDividendDetailVo"/>
where 1=1
<sql id="searchCondition">
<if test="agentName != null "> and a.name like concat('%', #{agentName}, '%')</if>
<if test="partnerId != null "> and dd.partner_id = #{partnerId}</if>
<if test="status != null "> and dd.status = #{status}</if>
<if test="partnerName != null "> and dd.partner_name like concat('%', #{partnerName}, '%')</if>
<if test="partnerPhone != null "> and dd.partner_phone like concat('%', #{partnerPhone}, '%')</if>
<if test="partnerType != null "> and dd.partner_type = #{partnerType}</if>
@ -24,6 +35,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="totalAmount != null "> and dd.total_amount = #{totalAmount}</if>
<if test="dividendAmount != null "> and dd.dividend_amount = #{dividendAmount}</if>
<if test="dividendProportion != null "> and dd.dividend_proportion = #{dividendProportion}</if>
<if test="startTime != null"> and dd.create_time >= #{startTime}</if>
<if test="endTime != null"> and dd.create_time &lt;= #{endTime}</if>
</sql>
<select id="selectRlDividendDetailList" parameterType="DividendDetailQuery" resultMap="RlDividendDetailResult">
<include refid="selectRlDividendDetailVo"/>
where 1=1
<include refid="searchCondition"/>
${params.dataScope}
order by dd.create_time desc
</select>
@ -39,6 +58,63 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where dd.order_no = #{orderNo}
</select>
<select id="select7DaysIncome" resultType="com.ruoyi.system.domain.vo.InCome">
SELECT
date_list.day,
COALESCE(SUM(s.settlement_amount), 0) as orderIncome,
COALESCE(COUNT(DISTINCT s.order_no), 0) as orderNum
FROM (
SELECT DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL n DAY), '%Y-%m-%d') as day
FROM (
SELECT 0 as n UNION ALL
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 4 UNION ALL
SELECT 5 UNION ALL
SELECT 6
) nums
) date_list
LEFT JOIN ss_dividend_detail s ON DATE_FORMAT(s.create_time, '%Y-%m-%d') = date_list.day
AND s.partner_id = #{merchantId}
AND s.status = '1'
GROUP BY date_list.day
ORDER BY date_list.day DESC
</select>
<select id="select30DaysIncome" resultType="com.ruoyi.system.domain.vo.InCome">
SELECT
date_list.day,
COALESCE(SUM(s.settlement_amount), 0) as orderIncome,
COALESCE(COUNT(DISTINCT s.order_no), 0) as orderNum
FROM (
SELECT DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL n DAY), '%Y-%m-%d') as day
FROM (
SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9
UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14
UNION ALL SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19
UNION ALL SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23 UNION ALL SELECT 24
UNION ALL SELECT 25 UNION ALL SELECT 26 UNION ALL SELECT 27 UNION ALL SELECT 28 UNION ALL SELECT 29
) nums
) date_list
LEFT JOIN ss_dividend_detail s ON DATE_FORMAT(s.create_time, '%Y-%m-%d') = date_list.day
AND s.partner_id = #{merchantId}
AND s.status = '1'
GROUP BY date_list.day
ORDER BY date_list.day DESC
</select>
<select id="getIncome" resultType="java.math.BigDecimal">
SELECT
COALESCE(SUM(dd.settlement_amount), 0) as income
FROM ss_dividend_detail dd
<where>
<include refid="searchCondition"/>
</where>
</select>
<insert id="insertRlDividendDetail" parameterType="DividendDetail" useGeneratedKeys="true" keyProperty="id">
insert into ss_dividend_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -49,6 +125,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderNo != null and orderNo != ''">order_no,</if>
<if test="totalAmount != null">total_amount,</if>
<if test="dividendAmount != null">dividend_amount,</if>
<if test="settlementAmount != null">settlement_amount,</if>
<if test="dividendProportion != null">dividend_proportion,</if>
<if test="createTime != null">create_time,</if>
<if test="status != null">status,</if>
@ -61,6 +138,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderNo != null and orderNo != ''">#{orderNo},</if>
<if test="totalAmount != null">#{totalAmount},</if>
<if test="dividendAmount != null">#{dividendAmount},</if>
<if test="settlementAmount != null">#{settlementAmount},</if>
<if test="dividendProportion != null">#{dividendProportion},</if>
<if test="createTime != null">#{createTime},</if>
<if test="status != null">#{status},</if>
@ -77,6 +155,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
<if test="totalAmount != null">total_amount = #{totalAmount},</if>
<if test="dividendAmount != null">dividend_amount = #{dividendAmount},</if>
<if test="settlementAmount != null">settlement_amount = #{settlementAmount},</if>
<if test="dividendProportion != null">dividend_proportion = #{dividendProportion},</if>
<if test="refundAmount != null">refund_amount = #{refundAmount},</if>
<if test="createTime != null">create_time = #{createTime},</if>

View File

@ -3,8 +3,11 @@ package com.ruoyi.ss.dividendDetail.service;
import com.ruoyi.ss.dividendDetail.domain.DividendDetail;
import com.ruoyi.ss.dividendDetail.domain.DividendDetailQuery;
import com.ruoyi.ss.dividendDetail.domain.DividendDetailVO;
import com.ruoyi.system.domain.vo.InCome;
import com.ruoyi.system.domain.vo.IndexAdminVo;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -96,4 +99,24 @@ public interface IDividendDetailService
* @return 结果
*/
public int updateRefundAmount(Long id, BigDecimal userRefundAmount);
/**
* 查询近7天收入
* @param merchantId 商户id
* @return 结果
*/
List<InCome> select7DaysIncome(Long merchantId);
/**
* 查询近30天收入
* @param merchantId 商户id
* @return 结果
*/
List<InCome> select30DaysIncome(Long merchantId);
/**
* 获取指定时间范围的收入
* @return 收入金额
*/
BigDecimal getIncome(DividendDetailQuery query);
}

View File

@ -1,6 +1,5 @@
package com.ruoyi.ss.dividendDetail.service.impl;
//import com.ruoyi.common.core.domain.entity.RlUser;
import com.ruoyi.common.utils.DateUtils;
//import com.ruoyi.system.domain.agent.RlAgentVO;
import com.ruoyi.ss.dividendDetail.domain.DividendDetail;
@ -10,12 +9,16 @@ import com.ruoyi.ss.dividendDetail.domain.DividendDetailVO;
//import com.ruoyi.system.domain.userExt.RlUserExt;
import com.ruoyi.ss.dividendDetail.mapper.DividendDetailMapper;
import com.ruoyi.ss.dividendDetail.service.IDividendDetailService;
import com.ruoyi.system.domain.vo.InCome;
import com.ruoyi.system.domain.vo.IndexAdminVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
/**
* 分账明细Service业务层处理
@ -28,19 +31,7 @@ import java.math.BigDecimal;
public class DividendDetailServiceImpl implements IDividendDetailService
{
@Resource
private DividendDetailMapper rlDividendDetailMapper;
// @Resource
// private IRlUserExtService userExtService;
//
// @Autowired
// private IRlUserService userService;
//
// @Autowired
// private IRlAgentService agentService;
//
// @Autowired
// private IRlChangeBalanceService changeBalanceService;
private DividendDetailMapper dividendDetailMapper;
/**
* 查询分账明细
@ -51,7 +42,7 @@ public class DividendDetailServiceImpl implements IDividendDetailService
@Override
public DividendDetail selectRlDividendDetailById(Long id)
{
return rlDividendDetailMapper.selectRlDividendDetailById(id);
return dividendDetailMapper.selectRlDividendDetailById(id);
}
/**
@ -64,7 +55,7 @@ public class DividendDetailServiceImpl implements IDividendDetailService
// @DataScope(agentAlias = "a",userAlias = "u")
public List<DividendDetailVO> selectRlDividendDetailList(DividendDetailQuery rlDividendDetail)
{
return rlDividendDetailMapper.selectRlDividendDetailList(rlDividendDetail);
return dividendDetailMapper.selectRlDividendDetailList(rlDividendDetail);
}
/**
@ -74,7 +65,7 @@ public class DividendDetailServiceImpl implements IDividendDetailService
*/
@Override
public List<DividendDetailVO> selectRlDividendDetailListByOrderNo(String orderNo) {
return rlDividendDetailMapper.selectRlDividendDetailListByOrderNo(orderNo);
return dividendDetailMapper.selectRlDividendDetailListByOrderNo(orderNo);
}
/**
@ -87,7 +78,7 @@ public class DividendDetailServiceImpl implements IDividendDetailService
public int insertRlDividendDetail(DividendDetail rlDividendDetail)
{
rlDividendDetail.setCreateTime(DateUtils.getNowDate());
return rlDividendDetailMapper.insertRlDividendDetail(rlDividendDetail);
return dividendDetailMapper.insertRlDividendDetail(rlDividendDetail);
}
/**
@ -99,7 +90,7 @@ public class DividendDetailServiceImpl implements IDividendDetailService
@Override
public int updateRlDividendDetail(DividendDetail rlDividendDetail)
{
return rlDividendDetailMapper.updateRlDividendDetail(rlDividendDetail);
return dividendDetailMapper.updateRlDividendDetail(rlDividendDetail);
}
/**
@ -111,7 +102,7 @@ public class DividendDetailServiceImpl implements IDividendDetailService
@Override
public int deleteRlDividendDetailByIds(Long[] ids)
{
return rlDividendDetailMapper.deleteRlDividendDetailByIds(ids);
return dividendDetailMapper.deleteRlDividendDetailByIds(ids);
}
/**
@ -123,72 +114,10 @@ public class DividendDetailServiceImpl implements IDividendDetailService
@Override
public int deleteRlDividendDetailById(Long id)
{
return rlDividendDetailMapper.deleteRlDividendDetailById(id);
return dividendDetailMapper.deleteRlDividendDetailById(id);
}
// /**
// * 计算分账金额
// * @param originalOrder
// * @return
// */
// @Override
// public int calculationDividend(RlOrder originalOrder,String userType) {
// RlUserExt rlUserExt;
// RlUser rlUser ;
// RlDividendDetail rlDividendDetail = new RlDividendDetail();
// if(userType.equals(ServiceConstants.USER_TYPE_MERCHANT)){
// rlUserExt = userExtService.selectRlUserExtByUserId(originalOrder.getMerchantId());
// rlUser = userService.selectUserById(rlUserExt.getUserId());
// }else if(userType.equals(ServiceConstants.USER_TYPE_AGENT)){
// RlAgentVO rlAgentVO = agentService.selectRlAgentByAgentId(originalOrder.getAgentId());
// rlUserExt = userExtService.selectRlUserExtByUserId(rlAgentVO.getUserid());
// rlUser = userService.selectUserById(rlUserExt.getUserId());
// rlDividendDetail.setDividendProportion(rlAgentVO.getDividendProportion());
// }else{
// throw new ServiceException("用户类型有误");
// }
// rlDividendDetail.setAgentId(originalOrder.getAgentId());
// rlDividendDetail.setPartnerId(rlUserExt.getUserId());
// rlDividendDetail.setOrderNo(originalOrder.getOrderNo());
// rlDividendDetail.setTotalAmount(originalOrder.getPayFee());
// rlDividendDetail.setCreateTime(DateUtils.getNowDate());
// rlDividendDetail.setPartnerName(rlUser.getUserName());
// rlDividendDetail.setPartnerPhone(rlUser.getPhonenumber());
// rlDividendDetail.setPartnerType(rlUser.getUserType());
// rlDividendDetail.setStatus(ServiceConstants.DIVIDEND_STATUS_NOT_SETTLED);
// int i = insertRlDividendDetail(rlDividendDetail);
// if(i>0){
// log.info("=================【微信支付回调】计算合作人分成成功==================");
// }
// return i;
// }
/**
* 计算分账金额
* @param rlDividendDetails 分账明细
* @return
*/
// @Override
// public int calculationAmount(List<DividendDetailVO> rlDividendDetails,BigDecimal totalDividendAmount) {
// log.info("【计算分账金额】计算分账金额开始============");
// for(DividendDetailVO dividendDetail:rlDividendDetails){
// log.info("【计算分账金额】租赁费和逾期费进行分成============"+totalDividendAmount);
// RlUserExt rlUserExt = userExtService.selectRlUserExtByUserId(dividendDetail.getPartnerId());
// if(ObjectUtil.isNull(rlUserExt)){
// throw new ServiceException("用户【"+dividendDetail.getPartnerName()+"】不存在");
// }
// if(rlUserExt.getDividendProportion().compareTo(BigDecimal.ZERO)==0 || ObjectUtil.isNull(rlUserExt.getDividendProportion())){
// throw new ServiceException("用户【"+dividendDetail.getPartnerName()+"】分账比例不能为空");
// }
// // 保留两位小数点
// BigDecimal dividendAmount = rlUserExt.getDividendProportion().multiply(totalDividendAmount)
// .setScale(2, RoundingMode.HALF_UP);
// dividendDetail.setDividendAmount(dividendAmount);
// dividendDetail.setStatus(ServiceConstants.DIVIDEND_STATUS_SETTLED);
// updateRlDividendDetail(dividendDetail);
// }
// return 1;
// }
/**
* 更新退款金额
@ -202,7 +131,36 @@ public class DividendDetailServiceImpl implements IDividendDetailService
DividendDetail rlDividendDetail = new DividendDetail();
rlDividendDetail.setRefundAmount(userRefundAmount);
rlDividendDetail.setId(id);
return rlDividendDetailMapper.updateRlDividendDetail(rlDividendDetail);
return dividendDetailMapper.updateRlDividendDetail(rlDividendDetail);
}
/**
* 查询近7天收入
* @param merchantId 商户id
* @return 结果
*/
@Override
public List<InCome> select7DaysIncome(Long merchantId) {
return dividendDetailMapper.select7DaysIncome(merchantId);
}
/**
* 查询近30天收入
* @param merchantId 商户id
* @return 结果
*/
@Override
public List<InCome> select30DaysIncome(Long merchantId) {
return dividendDetailMapper.select30DaysIncome(merchantId);
}
/**
* 查询收入
* @return 结果
*/
@Override
public BigDecimal getIncome(DividendDetailQuery query) {
return dividendDetailMapper.getIncome(query);
}

View File

@ -7,6 +7,7 @@ import com.ruoyi.ss.order.domain.vo.ReservedTimePeriod;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@ -128,7 +129,7 @@ public interface OrderMapper
/**
* 订单数量
*/
Integer getOrderNum(@Param("startDateStr") String startDateStr , @Param("endDateStr") String endDateStr ,@Param("merchantId") Long merchantId);
Integer getOrderNum(@Param("merchantId") Long merchantId, @Param("startTime") LocalDateTime startDateStr , @Param("endTime") LocalDateTime endDateStr);
/**
* 已售数量

View File

@ -254,12 +254,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="getOrderNum" resultType="java.lang.Integer">
select count(1) from ss_order where status = 8
<if test="startDateStr != null and startDateStr != ''">
AND date_format(pay_time,'%Y%m%d%H%i%s') &gt;= date_format(#{startDateStr},'%Y%m%d%H%i%s')
select count(DISTINCT order_id) from ss_order where status not in('5', '6') and paid = 1
<if test="startTime != null">
AND pay_time >= #{startTime}
</if>
<if test="endDateStr != null and endDateStr != ''">
AND date_format(pay_time,'%Y%m%d%H%i%s') &lt;= date_format(#{endDateStr},'%Y%m%d%H%i%s')
<if test="endTime != null">
AND pay_time &lt; #{endTime}
</if>
<if test="merchantId != null">and merchant_id = #{merchantId}</if>
</select>

View File

@ -210,7 +210,7 @@ public interface IOrderService
/**
* app首页统计
*/
IndexAdminVo indexStatistics(String startTime, String endTime, Long userId);
IndexAdminVo indexStatistics(String timeLimit);
/**
* 已售数量

View File

@ -1,5 +1,6 @@
package com.ruoyi.ss.order.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.annotation.DataScope;
@ -13,7 +14,11 @@ import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.common.utils.wx.vo.PrepayResponseVO;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.enums.DeviceStatus;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.dividendDetail.domain.DividendDetail;
import com.ruoyi.ss.dividendDetail.domain.DividendDetailQuery;
import com.ruoyi.ss.dividendDetail.service.IDividendDetailService;
import com.ruoyi.ss.feeRule.domain.FeeRuleVO;
import com.ruoyi.ss.feeRule.service.IFeeRuleService;
@ -35,10 +40,13 @@ import com.ruoyi.ss.orderOper.service.IOrderOperService;
import com.ruoyi.ss.product.service.IProductService;
import com.ruoyi.ss.refund.domain.Refund;
import com.ruoyi.ss.refund.service.IRefundService;
import com.ruoyi.ss.room.domain.RoomQuery;
import com.ruoyi.ss.room.service.IRoomService;
import com.ruoyi.ss.store.domain.StoreVO;
import com.ruoyi.ss.store.service.IStoreService;
import com.ruoyi.ss.user.domain.UserVO;
import com.ruoyi.ss.user.service.IUserService;
import com.ruoyi.system.domain.vo.InCome;
import com.ruoyi.system.domain.vo.IndexAdminVo;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.ss.pay.service.IWxPayService;
@ -55,9 +63,13 @@ import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import static com.ruoyi.common.constant.ServiceConstants.*;
@ -105,6 +117,9 @@ public class OrderServiceImpl implements IOrderService
@Autowired
private IOrderOperService rlOrderOperService;
@Autowired
private DeviceService deviceService;
@Autowired
private IOrderOperService orderOperService;
@ -115,7 +130,7 @@ public class OrderServiceImpl implements IOrderService
private IDividendDetailService dividendDetailService;
@Autowired
private IMsgLogService msgLogService;
private IRoomService roomService;
@Autowired
private IProductService productService;
@ -1131,15 +1146,8 @@ public class OrderServiceImpl implements IOrderService
* 首页统计
*/
@Override
public IndexAdminVo indexStatistics(String startTime,String endTime,Long userId) {
// 定义统一的日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// 根据用户id查询代理商根据代理商做数据权限隔离
User rlUser = userService.selectUserById(userId);
if(!USER_TYPE_MERCHANT.equals(rlUser.getUserType())){
throw new ServiceException("您没有权限访问");
}
return getIndexAdminVoByAgentId(startTime, endTime, formatter,rlUser.getUserId());
public IndexAdminVo indexStatistics(String timeLimit) {
return getIndexAdminVoByAgentId(timeLimit);
}
/**
@ -1168,78 +1176,132 @@ public class OrderServiceImpl implements IOrderService
@NotNull
private IndexAdminVo getIndexAdminVoByAgentId(String startTime, String endTime, DateTimeFormatter formatter,Long merchantId) {
// 校验输入时间格式并判断时间区间是否超过15天
if (StrUtil.isBlank(startTime) && StrUtil.isBlank(endTime)) {
// 获取今日订单数量和收入
startTime = DateUtils.getYYYY_MM_DD(DateUtils.getNowDate());
endTime = DateUtils.getYYYY_MM_DD(DateUtils.getNowDate());
}
// 使用LocalDate统一日期处理
LocalDate startDate = LocalDate.parse(startTime, formatter);
LocalDate endDate = LocalDate.parse(endTime, formatter);
// 计算两者之间的天数差异
long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
if (daysBetween > 15) {
throw new ServiceException("时间范围不能超过15天");
}
// 创建结果对象
private IndexAdminVo getIndexAdminVoByAgentId(String timeLimit) {
Long merchantId = getUserId();
IndexAdminVo indexAdminVo = new IndexAdminVo();
ArrayList<IndexAdminVo.IncomeVo> incomeVos = new ArrayList<>();
// 遍历从 startDate endDate 的每一天生成订单数据
for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) {
IndexAdminVo.IncomeVo orderFee = new IndexAdminVo.IncomeVo();
String day = date.format(formatter);
String startDateStr = day + " "+ Constants.DATE_FORMAT_START_PEREND;
String endDateStr = day + " " +Constants.DATE_FORMAT_END_PEREND;
orderFee.setDay(day); // 设置每一天的日期
BigDecimal orderFee1 = orderMapper.getOrderFee(startDateStr, endDateStr, merchantId);//订单金额
orderFee.setOrderFee(orderFee1);
orderFee.setOrderNum(orderMapper.getOrderNum(startDateStr, endDateStr, merchantId));//订单数量
/** 收入统计 */
setIncome(merchantId,indexAdminVo);
incomeVos.add(orderFee);
}
// 设置收入数据
indexAdminVo.setIncomeVoList(incomeVos);
// 获取今日订单数量和收入
String todayStart = DateUtils.getYYYY_MM_DD(DateUtils.getNowDate()) + " " + Constants.DATE_FORMAT_START_PEREND;
String todayEnd = DateUtils.getYYYY_MM_DD(DateUtils.getNowDate()) + " " + Constants.DATE_FORMAT_END_PEREND;
/** 运营概况 */
setOperateOverview(timeLimit, merchantId, indexAdminVo);
// 查询今日的订单数和营收
Integer todayOrderNum = orderMapper.getOrderNum(todayStart, todayEnd, merchantId);
BigDecimal todayIncome = orderMapper.getOrderFee(todayStart, todayEnd, merchantId);
// 设置今日的订单数和营收
indexAdminVo.setTodayOrderNum(todayOrderNum);
indexAdminVo.setTodayIncome(todayIncome);
String yesterdayStart = DateUtils.getYYYY_MM_DD(DateUtils.addDays(DateUtils.getNowDate(), -1)) + " " + Constants.DATE_FORMAT_START_PEREND;
String yesterdayEnd = DateUtils.getYYYY_MM_DD(DateUtils.addDays(DateUtils.getNowDate(), -1)) + " " + Constants.DATE_FORMAT_END_PEREND;
// 查询昨日的订单数和营收
Integer yesterdayOrderNum = orderMapper.getOrderNum(yesterdayStart, yesterdayEnd, merchantId);
BigDecimal yesterdayIncome = orderMapper.getOrderFee(yesterdayStart, yesterdayEnd, merchantId);
// 计算较昨日的营收和订单数
BigDecimal comparedYesterdayIncome = todayIncome.subtract(yesterdayIncome);
BigDecimal comparedYesterdayOrderNum = new BigDecimal(todayOrderNum - yesterdayOrderNum);
// 设置较昨日的营收和订单数
indexAdminVo.setComparedYesterdayIncome(comparedYesterdayIncome);
indexAdminVo.setComparedYesterdayOrderNum(comparedYesterdayOrderNum);
/** 当前营运情况 */
setDeviceOverview(merchantId,indexAdminVo);
// 设置车辆统计数据
IndexAdminVo.DeviceVO deviceVO = new IndexAdminVo.DeviceVO();
// deviceVO.setTotal(deviceService.getTatalDeviceCount(merchantId,null,null));
// deviceVO.setIdle(deviceService.getTatalDeviceCount(merchantId,ServiceConstants.VEHICLE_STATUS_NORMAL,null));
String[] statusList = new String[] { VEHICLE_STATUS_IN_USING, VEHICLE_STATUS_TEMPORARILY_LOCK };
// deviceVO.setRent(deviceService.getTatalDeviceCount(merchantId,null,statusList));
indexAdminVo.setDeviceVO(deviceVO);
return indexAdminVo;
}
private void setDeviceOverview(Long merchantId, IndexAdminVo indexAdminVo) {
RoomQuery query = new RoomQuery();
query.setMerchantId(merchantId);
query.setType2(ROOM_TYPE2_PRIVATE_ROOM);
query.setStatus(ROOM_STATUS_INUSE);
indexAdminVo.setInUseRoomNum(roomService.getCount(query));
query.setStatus(null);
indexAdminVo.setTotalRoomNum(roomService.getCount(query));
query.setType2(ROOM_TYPE2_LOBBY_DEVICE);
indexAdminVo.setTotalEquNum(roomService.getCount(query));
query.setStatus(ROOM_STATUS_INUSE);
indexAdminVo.setInUseEquNum(roomService.getCount(query));
DeviceQuery deviceQuery = new DeviceQuery();
deviceQuery.setUserId(merchantId);
indexAdminVo.setTotalDeviceNum(deviceService.selectCount(deviceQuery));
deviceQuery.setStatus(DeviceStatus.USING.getStatus());
indexAdminVo.setInUseDeviceNum(deviceService.selectCount(deviceQuery));
}
private void setOperateOverview(String timeLimit, Long merchantId, IndexAdminVo indexAdminVo) {
List<InCome> incomeVos;
if(TIME_LIMIT_30_DAYS.equals(timeLimit)){
incomeVos = dividendDetailService.select30DaysIncome(merchantId);
}else{
// 查询7天的数据
incomeVos = dividendDetailService.select7DaysIncome(merchantId);
}
indexAdminVo.setIncomeVoList(incomeVos);
// 根据查询出来的incomeVos合计订单金额和订单数,保存到 indexAdminVo中
indexAdminVo.setTotalIncome(incomeVos.stream().map(InCome::getOrderIncome).reduce(BigDecimal.ZERO, BigDecimal::add));
indexAdminVo.setTotalOrderNum(incomeVos.stream().map(InCome::getOrderNum).reduce(0, Integer::sum));
}
private void setIncome(Long merchantId, IndexAdminVo indexAdminVo) {
// 获取今日收入和订单数
indexAdminVo.setTodayIncome(getIncomeByTimeType(merchantId, TIME_LIMIT_TODAY));
indexAdminVo.setTodayOrderNum(getOrderCountByTimeType(merchantId, TIME_LIMIT_TODAY));
// 获取本周收入和订单数
indexAdminVo.setWeekIncome(getIncomeByTimeType(merchantId, TIME_LIMIT_WEEK));
indexAdminVo.setWeekOrderNum(getOrderCountByTimeType(merchantId, TIME_LIMIT_WEEK));
// 获取本月收入和订单数
indexAdminVo.setMonthIncome(getIncomeByTimeType(merchantId, TIME_LIMIT_MONTH));
indexAdminVo.setMonthOrderNum(getOrderCountByTimeType(merchantId, TIME_LIMIT_MONTH));
}
// 根据时间差收入
public BigDecimal getIncomeByTimeType(Long merchantId, String timeType) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime;
switch (timeType) {
case TIME_LIMIT_TODAY:
// 今日收入
startTime = now.with(LocalTime.MIN);
break;
case TIME_LIMIT_WEEK:
// 本周收入周一到现在
startTime = now.with(LocalTime.MIN).with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
break;
case TIME_LIMIT_MONTH:
// 本月收入
startTime = now.with(TemporalAdjusters.firstDayOfMonth()).with(LocalTime.MIN);
break;
default:
throw new IllegalArgumentException("时间类型无效");
}
DividendDetailQuery dividendDetailQuery = new DividendDetailQuery();
dividendDetailQuery.setStatus(DIVIDEND_STATUS_PAID);
dividendDetailQuery.setPartnerId(merchantId);
dividendDetailQuery.setStartTime(startTime);
dividendDetailQuery.setEndTime(now);
return dividendDetailService.getIncome(dividendDetailQuery);
}
public Integer getOrderCountByTimeType(Long merchantId, String timeType) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime;
switch (timeType) {
case TIME_LIMIT_TODAY:
// 今日订单数
startTime = now.with(LocalTime.MIN);
break;
case TIME_LIMIT_WEEK:
// 本周订单数
startTime = now.with(LocalTime.MIN)
.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
break;
case TIME_LIMIT_MONTH:
// 本月订单数
startTime = now.with(TemporalAdjusters.firstDayOfMonth())
.with(LocalTime.MIN);
break;
default:
throw new IllegalArgumentException("时间类型无效");
}
return orderMapper.getOrderNum(merchantId, startTime, now);
}
/**
* 进行中的订单
*/

View File

@ -20,11 +20,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
r.refund_result,
r.merchant_id,
r.oper_time,
o.pay_type,
o.store_name,
p.amount
from ss_refund r
left join ss_pay_bill p on p.pay_id = o.pay_id
left join ss_pay_bill p on p.pay_id = r.pay_id
left join ss_user m on m.user_id = r.merchant_id
</sql>

View File

@ -117,4 +117,9 @@ public interface RoomMapper
* @return boolean
*/
List<String> selectIsExistRule(Long ruleId);
/**
* 获取房间数
*/
int getCount(@Param("query") RoomQuery query);
}

View File

@ -107,6 +107,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select room_name from ss_room where FIND_IN_SET( #{ruleId}, rule_ids )
</select>
<select id="getCount" resultType="java.lang.Integer">
select count(1) from ss_room r
<where>
<include refid="searchCondition"/>
</where>
</select>
<insert id="insertERoom" parameterType="Room" useGeneratedKeys="true" keyProperty="roomId">
insert into ss_room
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@ -171,4 +171,8 @@ public interface IRoomService
List<WifiObjVO> selectWifiObjList();
/**
* 获取房间数
*/
int getCount(RoomQuery query);
}

View File

@ -400,4 +400,12 @@ public class RoomServiceImpl implements IRoomService
return wifiObjVOS;
}
/**
* 获取房间数
*/
@Override
public int getCount(RoomQuery query) {
return roomMapper.getCount(query);
}
}

View File

@ -0,0 +1,19 @@
package com.ruoyi.system.domain.vo;
import lombok.Data;
import java.math.BigDecimal;
/**
* 经营概况7天30天
*/
@Data
public class InCome {
/** 日期 */
private String day;
/** 订单营收 */
private BigDecimal orderIncome;
/** 订单数 */
private Integer orderNum;
}

View File

@ -14,45 +14,54 @@ import java.util.List;
@Data
public class IndexAdminVo {
/** 收入统计list */
private List<IncomeVo> incomeVoList;
/** 车辆统计 */
private DeviceVO deviceVO;
/**
* 7日营收
*/
@Data
public static class IncomeVo {
/** 日期 */
private String day;
/** 订单金额 */
private BigDecimal orderFee;
/** 订单数 */
private Integer orderNum;
}
@Data
public static class DeviceVO {
/** 车辆总数 */
private Integer total;
/** 空闲中 */
private Integer idle;
/** 出租中 */
private Integer rent;
}
/** 今日营收 */
/** 今日收入 */
private BigDecimal todayIncome;
/** 今日订单数 */
private Integer todayOrderNum;
/** 较昨日营收 */
private BigDecimal comparedYesterdayIncome;
/** 本周收入 */
private BigDecimal weekIncome;
/** 本周订单 */
private Integer weekOrderNum;
/** 本月收入 */
private BigDecimal monthIncome;
/** 本月订单 */
private Integer monthOrderNum;
/** 收入统计list */
private List<InCome> incomeVoList;
/** 营收合计*/
private BigDecimal totalIncome;
/** 营收合计*/
private Integer totalOrderNum;
/**
* 当前营运情况
*/
/** 使用中房间 */
private Integer inUseRoomNum;
/** 总房间 */
private Integer totalRoomNum;
/** 使用中大厅设施 */
private Integer inUseEquNum;
/** 总大厅设施 */
private Integer totalEquNum;
/** 使用中大厅设施 */
private Integer inUseDeviceNum;
/** 总大厅设施 */
private Integer totalDeviceNum;
/** 较昨日订单数 */
private BigDecimal comparedYesterdayOrderNum;
}