<?xml version="1.0" encoding="UTF-8"?>
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<mapper namespace="com.ruoyi.system.mapper.OrderMapper">
|
|
|
<select id="getProcessingCommissionPriceByShareUserId" resultType="java.math.BigDecimal">
|
select COALESCE(SUM(commission_price), 0.00) AS total_commission from tb_order where status in (4,5) and share_user_id =#{id}
|
</select>
|
<select id="getOrderPage" resultType="com.ruoyi.system.pojo.vo.OrderPageVO">
|
select
|
c.id,
|
o.order_no,
|
publish.user_name as publishName,
|
publish.phone as publishPhone,
|
o.price,
|
book.user_name as bookName,
|
book.phone as bookPhone,
|
c.create_time as createTime,
|
o.create_time as bookTime,
|
o.finish_time as finishTime,
|
-- 状态映射逻辑
|
CASE
|
WHEN c.status = 1 THEN 1
|
WHEN c.status = 2 THEN 6
|
WHEN c.status = 3 THEN 5
|
WHEN c.status = 4 THEN
|
CASE
|
WHEN o.status = 2 THEN 2
|
WHEN o.status = 3 THEN 3
|
WHEN o.status IN (4, 5) THEN 4
|
ELSE c.status -- 默认保持原状态(可根据需求调整)
|
END
|
ELSE c.status -- 其他状态保持不变
|
END AS status
|
from
|
tb_company c
|
left join tb_order o on c.id = o.company_id and o.status != -1
|
left join (select id,user_name,phone from tb_user group by id) publish on c.user_id = publish.id
|
left join (select id,user_name,phone from tb_user group by id) book on o.user_id = book.id
|
where
|
c.is_delete=0
|
|
<if test="null != dto.orderNo">
|
and o.order_no like concat('%',#{dto.orderNo},'%')
|
</if>
|
<if test="null != dto.publishName and '' != dto.publishName">
|
and publish.user_name like concat('%',#{dto.publishName},'%')
|
</if>
|
<if test="null != dto.publishPhone and '' != dto.publishPhone">
|
and publish.phone like concat('%',#{dto.publishPhone},'%')
|
</if>
|
|
<if test="null != dto.bookName and '' != dto.bookName">
|
and book.user_name like concat('%',#{dto.bookName},'%')
|
</if>
|
<if test="null != dto.bookPhone and '' != dto.bookPhone">
|
and book.phone like concat('%',#{dto.bookPhone},'%')
|
</if>
|
|
<if test="null != dto.createTimeStart and null != dto.createTimeEnd">
|
and c.create_time between #{dto.createTimeStart} and #{dto.createTimeEnd}
|
</if>
|
|
<if test="null != dto.bookTimeStart and null != dto.bookTimeEnd">
|
and o.create_time between #{dto.bookTimeStart} and #{dto.bookTimeEnd}
|
</if>
|
|
<if test="null != dto.finishTimeStart and null != dto.finishTimeEnd">
|
and o.finish_time between #{dto.finishTimeStart} and #{dto.finishTimeEnd}
|
</if>
|
|
<if test="null != dto.status">
|
AND (
|
<!-- 直接匹配原始状态 -->
|
(c.status IN (1,2,3) AND
|
CASE
|
WHEN c.status = 1 THEN 1
|
WHEN c.status = 2 THEN 6
|
WHEN c.status = 3 THEN 5
|
ELSE c.status
|
END = #{dto.status})
|
<!-- 匹配映射后的状态4(c.status=4且o.status=4/5) -->
|
OR (c.status = 4 AND o.status IN (4,5) AND 4 = #{dto.status})
|
<!-- 匹配映射后的状态2(c.status=4且o.status=2) -->
|
OR (c.status = 4 AND o.status = 2 AND 2 = #{dto.status})
|
<!-- 匹配映射后的状态3(c.status=4且o.status=3) -->
|
OR (c.status = 4 AND o.status = 3 AND 3 = #{dto.status})
|
)
|
</if>
|
</select>
|
<select id="getDetailById" resultType="com.ruoyi.system.pojo.vo.OrderDetailVO">
|
|
select
|
c.id,
|
-- 状态映射逻辑
|
CASE
|
WHEN c.status = 1 THEN 1
|
WHEN c.status = 2 THEN 6
|
WHEN c.status = 3 THEN 5
|
WHEN c.status = 4 THEN
|
CASE
|
WHEN o.status = 2 THEN 2
|
WHEN o.status = 3 THEN 3
|
WHEN o.status IN (4, 5) THEN 4
|
ELSE c.status -- 默认保持原状态(可根据需求调整)
|
END
|
ELSE c.status -- 其他状态保持不变
|
END AS status,
|
o.id as orderId,
|
c.company_name,
|
c.establish_time,
|
concat(c.city,c.province,c.area) as place,
|
c.registered_capital,
|
ct.name as companyCategoryName,
|
industry.name as industryName,
|
c.taxpayer_type,
|
c.tax_credit,
|
c.official_seal_num,
|
c.paid_in_funds,
|
c.oper_name,
|
c.scope,
|
c.invoice_limit,
|
c.social_security,
|
c.tendering,
|
c.have_trademark,
|
c.have_patent,
|
c.have_soft_works,
|
info.need_rename,
|
info.new_district,
|
publish.user_name as publishName,
|
publish.phone as publishPhone,
|
c.create_time as createTime,
|
book.user_name as bookName,
|
book.phone as bookPhone,
|
o.create_time as bookTime,
|
o.price as price,
|
o.pay_time as payTime,
|
o.confirm_time,
|
o.seller_finish_time,
|
o.finish_time,
|
-- 计算预计完成时间
|
CASE
|
WHEN
|
(
|
CASE
|
WHEN c.status = 1 THEN 1
|
WHEN c.status = 2 THEN 6
|
WHEN c.status = 3 THEN 5
|
WHEN c.status = 4 THEN
|
CASE
|
WHEN o.status = 2 THEN 2
|
WHEN o.status = 3 THEN 3
|
WHEN o.status IN (4, 5) THEN 4
|
ELSE c.status
|
END
|
ELSE c.status
|
END
|
) IN (3, 4, 5)
|
THEN
|
DATE_ADD(o.pay_time, INTERVAL (c.estimated_days+info.add_day) DAY)
|
ELSE NULL
|
END AS estimateTime
|
from tb_company c
|
left join tb_company_type ct on c.company_category = ct.id
|
left join tb_industry industry on c.company_industry_id = industry.id
|
left join tb_order o on c.id= o.company_id and o.status != -1
|
left join tb_buyer_company_info info on o.id = info.order_id
|
left join tb_user publish on c.user_id = publish.id
|
left join tb_user book on o.user_id = book.id
|
where
|
c.is_delete=0
|
and
|
c.id=#{id}
|
|
|
</select>
|
<select id="today" resultType="com.ruoyi.system.pojo.vo.TodayStatisticsVO">
|
select
|
ifnull(sum(price),0.00)as total,
|
ifnull(sum(commission_platform),0.00) as profit
|
from tb_order
|
where
|
status in (4,5,6) -- 4办理中 5卖家已完成 6买家完成
|
and pay_time between #{startTime} and #{endTime}
|
|
</select>
|
<select id="getDailyStatistics" resultType="com.ruoyi.system.pojo.model.DailyStatistics">
|
SELECT
|
DATE_FORMAT(pay_time, '%Y-%m-%d') as `date`,
|
ifnull(SUM(price),0.00) as totalPrice,
|
ifnull(SUM(commission_platform),0.00) as platformCommission
|
FROM tb_order
|
WHERE pay_time BETWEEN #{startTime} AND #{endTime}
|
AND status IN (4, 5, 6)
|
GROUP BY DATE(pay_time)
|
ORDER BY DATE(pay_time) ASC
|
</select>
|
<select id="financeTop" resultType="com.ruoyi.system.pojo.vo.FinanceFlowsTopVO">
|
SELECT
|
SUM(price) AS totalIncome,
|
SUM(commission_platform) AS totalProfit,
|
SUM(commission_price) AS totalCommission,
|
SUM(price - commission_platform - commission_price) AS sellerIncome
|
FROM tb_order
|
WHERE status IN (4, 5, 6)
|
AND is_refund = 0
|
</select>
|
<select id="flowsPage" resultType="com.ruoyi.system.pojo.vo.FinanceFlowsPageVO">
|
SELECT
|
order_no,
|
price,
|
commission_price,
|
commission_platform,
|
pay_time AS operateTime,
|
(price - commission_platform - commission_price) as seller,
|
1 AS type -- 收入类型
|
FROM tb_order
|
WHERE
|
((status IN (4, 5, 6)) -- 只查询已支付订单
|
or
|
(status=-1 and is_refund =1)) -- 已取消且已退款的订单
|
<if test="null != dto.orderNo and '' != dto.orderNo">
|
and order_no LIKE CONCAT('%', #{dto.orderNo}, '%')
|
</if>
|
<if test="null != dto.operateTimeStart and null != dto.operateTimeEnd">
|
and pay_time between #{dto.operateTimeStart} and #{dto.operateTimeEnd}
|
</if>
|
AND ( #{dto.type} IS NULL OR 1 = #{dto.type} )
|
UNION ALL
|
SELECT
|
order_no,
|
0 AS price,
|
0 AS commission_price,
|
0 AS commission_platform,
|
refund_time AS operateTime,
|
0 as seller,
|
2 AS type -- 退款类型
|
FROM tb_order
|
WHERE is_refund = 1 -- 只查询已退款订单
|
<if test="null != dto.orderNo and '' != dto.orderNo">
|
and order_no LIKE CONCAT('%', #{dto.orderNo}, '%')
|
</if>
|
<if test="null != dto.operateTimeStart and null != dto.operateTimeEnd">
|
and refund_time between #{dto.operateTimeStart} and #{dto.operateTimeEnd}
|
</if>
|
AND ( #{dto.type} IS NULL OR 2 = #{dto.type} )
|
ORDER BY operateTime DESC
|
LIMIT #{dto.pageNum}, #{dto.pageSize};
|
</select>
|
<select id="countFlowsPage" resultType="java.lang.Long">
|
SELECT COUNT(*) FROM (
|
select 1
|
from
|
tb_order
|
WHERE
|
((status IN (4, 5, 6)) -- 只查询已支付订单
|
or
|
(status=-1 and is_refund =1)) -- 已取消且已退款的订单
|
<if test="null != dto.orderNo and '' != dto.orderNo">
|
and order_no LIKE CONCAT('%', #{dto.orderNo}, '%')
|
</if>
|
<if test="null != dto.operateTimeStart and null != dto.operateTimeEnd">
|
and pay_time between #{dto.operateTimeStart} and #{dto.operateTimeEnd}
|
</if>
|
AND ( #{dto.type} IS NULL OR 1 = #{dto.type} )
|
UNION ALL
|
select 1
|
FROM tb_order
|
WHERE is_refund = 1 -- 只查询已退款订单
|
<if test="null != dto.orderNo and '' != dto.orderNo">
|
and order_no LIKE CONCAT('%', #{dto.orderNo}, '%')
|
</if>
|
<if test="null != dto.operateTimeStart and null != dto.operateTimeEnd">
|
and refund_time between #{dto.operateTimeStart} and #{dto.operateTimeEnd}
|
</if>
|
AND ( #{dto.type} IS NULL OR 2 = #{dto.type} )
|
) AS t
|
</select>
|
</mapper>
|