feat: add dashboard and virtual pay enhancements

This commit is contained in:
王鹏
2026-07-29 14:34:54 +08:00
parent 2250f744d1
commit 349f1c0374
55 changed files with 3085 additions and 213 deletions

View File

@@ -0,0 +1,78 @@
<?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.app.mapper.AppDashboardMapper">
<resultMap id="AppDashboardSummaryResult" type="AppDashboardSummary">
<result property="resourceTotal" column="resource_total"/>
<result property="resourceToday" column="resource_today"/>
<result property="userTotal" column="user_total"/>
<result property="userToday" column="user_today"/>
<result property="orderTotal" column="order_total"/>
<result property="orderToday" column="order_today"/>
<result property="amountTotal" column="amount_total"/>
<result property="amountToday" column="amount_today"/>
</resultMap>
<select id="selectDashboardSummary" resultMap="AppDashboardSummaryResult">
SELECT
(SELECT COUNT(1)
FROM app_resource
WHERE del_flag = 0) AS resource_total,
(SELECT COUNT(1)
FROM app_resource
WHERE del_flag = 0
AND create_time &gt;= CURDATE()
AND create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)) AS resource_today,
(SELECT COUNT(1)
FROM sys_user
WHERE del_flag = '0') AS user_total,
(SELECT COUNT(1)
FROM sys_user
WHERE del_flag = '0'
AND create_time &gt;= CURDATE()
AND create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)) AS user_today,
((SELECT COUNT(1)
FROM app_pay_order
WHERE status = 1)
+
(SELECT COUNT(1)
FROM app_virtual_order
WHERE status = 1)) AS order_total,
((SELECT COUNT(1)
FROM app_pay_order
WHERE status = 1
AND pay_time &gt;= CURDATE()
AND pay_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY))
+
(SELECT COUNT(1)
FROM app_virtual_order
WHERE status = 1
AND pay_time &gt;= CURDATE()
AND pay_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY))) AS order_today,
CAST(
COALESCE((SELECT SUM(amount)
FROM app_pay_order
WHERE status = 1), 0)
+
COALESCE((SELECT SUM(price_fen)
FROM app_virtual_order
WHERE status = 1), 0) / 100
AS DECIMAL(20, 2)
) AS amount_total,
CAST(
COALESCE((SELECT SUM(amount)
FROM app_pay_order
WHERE status = 1
AND pay_time &gt;= CURDATE()
AND pay_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)), 0)
+
COALESCE((SELECT SUM(price_fen)
FROM app_virtual_order
WHERE status = 1
AND pay_time &gt;= CURDATE()
AND pay_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)), 0) / 100
AS DECIMAL(20, 2)
) AS amount_today
</select>
</mapper>

View File

@@ -36,6 +36,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where> ORDER BY a.integral_time desc
</select>
<select id="selectMyIntegralRecordList" resultMap="AppIntegralRecordResult">
<include refid="selectAppIntegralRecordVo"/>
where a.user_id = #{userId}
and a.is_add in (0, 1)
order by a.integral_time desc, a.id desc
</select>
<select id="selectAppIntegralRecordCount" parameterType="AppIntegralRecord" resultType="int">
SELECT COUNT(0) FROM app_integral_record a
<where>
@@ -96,4 +103,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
</mapper>
</mapper>

View File

@@ -119,13 +119,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN (
SELECT
DATE_FORMAT(pay_time, '%Y-%m-%d') AS date,
amount
CAST(amount AS DECIMAL(18, 2)) AS amount
FROM app_pay_order
WHERE pay_time >= DATE_SUB(CURDATE(), INTERVAL #{days} DAY)
AND status = 1
UNION ALL
SELECT
DATE_FORMAT(pay_time, '%Y-%m-%d') AS date,
CAST(price_fen AS DECIMAL(18, 2)) / 100 AS amount
FROM app_virtual_order
WHERE pay_time >= DATE_SUB(CURDATE(), INTERVAL #{days} DAY)
AND status = 1
) AS pay ON dates.date = pay.date
WHERE dates.date >= DATE_SUB(CURDATE(), INTERVAL #{days} DAY)
GROUP BY dates.date
ORDER BY dates.date
</select>
</mapper>
</mapper>

View File

@@ -33,6 +33,10 @@
<result property="listName" column="sub_list_name" />
<result property="listUrl" column="sub_list_url" />
<result property="password" column="sub_password" />
<result property="priceFen" column="sub_price_fen" />
<result property="status" column="sub_status" />
<result property="sortOrder" column="sub_sort_order" />
<result property="purchased" column="sub_purchased" />
<result property="appResourceId" column="sub_app_resource_id" />
</resultMap>
@@ -65,10 +69,36 @@
select a.id, a.resource_title, a.show_img, a.`explain`,a.`keyword`, a.resource_type, a.is_show, a.is_ad, a.ad_number, a.price_fen,
(select vp.product_id from app_virtual_product vp where vp.price_fen = a.price_fen and vp.status = 1 limit 1) as virtual_product_id,
a.down_num, a.weight, a.del_flag, a.create_by, a.create_time, a.remark,
b.id as sub_id, b.list_name as sub_list_name, b.list_url as sub_list_url, b.password as sub_password, b.app_resource_id as sub_app_resource_id
b.id as sub_id, b.list_name as sub_list_name, b.list_url as sub_list_url,
b.password as sub_password, b.price_fen as sub_price_fen,
b.status as sub_status, b.sort_order as sub_sort_order,
0 as sub_purchased, b.app_resource_id as sub_app_resource_id
from app_resource a
left join app_resource_list b on b.app_resource_id = a.id
where a.id = #{id}
order by b.sort_order asc, b.id asc
</select>
<select id="selectAppResourceListById" parameterType="Long" resultType="AppResourceList">
select id, list_name as listName, list_url as listUrl, password,
price_fen as priceFen, status, sort_order as sortOrder,
app_resource_id as appResourceId
from app_resource_list
where id = #{id}
limit 1
</select>
<select id="selectHighestEntitledResourceList" resultType="AppResourceList">
select rl.id, rl.list_name as listName, rl.list_url as listUrl, rl.password,
rl.price_fen as priceFen, rl.status, rl.sort_order as sortOrder,
rl.app_resource_id as appResourceId
from app_resource_entitlement re
inner join app_resource_list rl on rl.id = re.resource_list_id
where re.user_id = #{userId}
and re.resource_id = #{resourceId}
and re.status = 1
order by rl.sort_order desc, rl.id desc
limit 1
</select>
<insert id="insertAppResource" parameterType="AppResource" useGeneratedKeys="true" keyProperty="id">
@@ -154,42 +184,129 @@
</delete>
<insert id="batchAppResourceList">
insert into app_resource_list( id, list_name, list_url, password, app_resource_id) values
insert into app_resource_list
(id, list_name, list_url, password, price_fen, status, sort_order, app_resource_id) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.id}, #{item.listName}, #{item.listUrl}, #{item.password}, #{item.appResourceId})
(#{item.id}, #{item.listName}, #{item.listUrl}, #{item.password},
#{item.priceFen}, #{item.status}, #{item.sortOrder}, #{item.appResourceId})
</foreach>
</insert>
<select id="countOrderedRemovedResourceLists" resultType="int">
select count(1)
from app_virtual_order vo
inner join app_resource_list rl on rl.id = vo.resource_list_id
where rl.app_resource_id = #{resourceId}
<if test="retainedIds != null and retainedIds.size() > 0">
and rl.id not in
<foreach item="id" collection="retainedIds" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="countVirtualOrdersByResourceId" parameterType="Long" resultType="int">
select count(1) from app_virtual_order where resource_id = #{resourceId}
</select>
<select id="selectAppResourceByIdAndUserId" resultMap="AppResourceAppResourceListResult">
select a.id, a.resource_title, a.show_img, a.`explain`, a.`keyword`, a.resource_type, a.is_show,
CASE
WHEN #{userId} is not null and (
(SELECT COUNT(1) FROM app_integral_record
WHERE resource_id = #{id} AND user_id = #{userId}
AND source = '资源兑换' AND is_add = 1) > 0
OR
(SELECT COUNT(1) FROM app_resource_entitlement WHERE resource_id = #{id} AND user_id = #{userId} AND status = 1) > 0
) THEN 0
ELSE a.is_ad
END as is_ad,
case
when #{userId} is not null
and (
(a.is_ad in (2, 3)
and exists(select 1 from app_integral_record ir
where ir.resource_id = a.id and ir.user_id = #{userId}
and ir.source = '资源兑换' and ir.is_add = 1))
or
(a.is_ad = 3
and exists(select 1 from app_resource_entitlement re
where re.resource_id = a.id and re.user_id = #{userId}
and re.status = 1 and re.resource_list_id is null))
)
then 0
else a.is_ad
end as is_ad,
a.ad_number, a.price_fen,
(select vp.product_id from app_virtual_product vp where vp.price_fen = a.price_fen and vp.status = 1 limit 1) as virtual_product_id,
(select vp.product_id from app_virtual_product vp
where vp.price_fen = a.price_fen and vp.status = 1 limit 1) as virtual_product_id,
a.down_num, a.weight, a.del_flag, a.create_by, a.create_time, a.remark,
b.id as sub_id, b.list_name as sub_list_name, b.list_url as sub_list_url,
b.password as sub_password, b.app_resource_id as sub_app_resource_id
b.id as sub_id, b.list_name as sub_list_name,
case when
a.is_ad not in (2, 3)
or (
#{userId} is not null and (
exists(select 1 from app_integral_record ir
where ir.resource_id = a.id and ir.user_id = #{userId}
and ir.source = '资源兑换' and ir.is_add = 1)
or exists(select 1 from app_resource_entitlement re
left join app_resource_list owned_rl
on owned_rl.id = re.resource_list_id
where re.resource_id = a.id and re.user_id = #{userId}
and re.status = 1
and (re.resource_list_id is null
or (owned_rl.app_resource_id = a.id
and owned_rl.sort_order &gt;= b.sort_order)))
)
)
then b.list_url else null end as sub_list_url,
case when
a.is_ad not in (2, 3)
or (
#{userId} is not null and (
exists(select 1 from app_integral_record ir
where ir.resource_id = a.id and ir.user_id = #{userId}
and ir.source = '资源兑换' and ir.is_add = 1)
or exists(select 1 from app_resource_entitlement re
left join app_resource_list owned_rl
on owned_rl.id = re.resource_list_id
where re.resource_id = a.id and re.user_id = #{userId}
and re.status = 1
and (re.resource_list_id is null
or (owned_rl.app_resource_id = a.id
and owned_rl.sort_order &gt;= b.sort_order)))
)
)
then b.password else null end as sub_password,
b.price_fen as sub_price_fen, b.status as sub_status,
b.sort_order as sub_sort_order,
case when
a.is_ad not in (2, 3)
or (
#{userId} is not null and (
exists(select 1 from app_integral_record ir
where ir.resource_id = a.id and ir.user_id = #{userId}
and ir.source = '资源兑换' and ir.is_add = 1)
or exists(select 1 from app_resource_entitlement re
left join app_resource_list owned_rl
on owned_rl.id = re.resource_list_id
where re.resource_id = a.id and re.user_id = #{userId}
and re.status = 1
and (re.resource_list_id is null
or (owned_rl.app_resource_id = a.id
and owned_rl.sort_order &gt;= b.sort_order)))
)
)
then 1 else 0 end as sub_purchased,
b.app_resource_id as sub_app_resource_id
from app_resource a
left join app_resource_list b on b.app_resource_id = a.id
and (
a.is_ad not in (2, 3)
or (
#{userId} is not null and (
exists(select 1 from app_integral_record ir
where ir.resource_id = a.id and ir.user_id = #{userId}
and ir.source = '资源兑换' and ir.is_add = 1)
or exists(select 1 from app_resource_entitlement re where re.resource_id = a.id and re.user_id = #{userId} and re.status = 1)
a.is_ad != 3
or b.status = 1
or (
#{userId} is not null
and exists(select 1 from app_resource_entitlement re
left join app_resource_list owned_rl
on owned_rl.id = re.resource_list_id
where re.resource_id = a.id and re.user_id = #{userId}
and re.status = 1
and (re.resource_list_id is null
or (owned_rl.app_resource_id = a.id
and owned_rl.sort_order &gt;= b.sort_order)))
)
)
)
where a.id = #{id}
order by b.sort_order asc, b.id asc
</select>
</mapper>

View File

@@ -11,6 +11,8 @@
<result property="nickName" column="nick_name"/>
<result property="resourceId" column="resource_id"/>
<result property="resourceTitle" column="resource_title"/>
<result property="resourceListId" column="resource_list_id"/>
<result property="specName" column="spec_name"/>
<result property="productId" column="product_id"/>
<result property="priceFen" column="price_fen"/>
<result property="openId" column="open_id"/>
@@ -24,31 +26,77 @@
<result property="lastQueryTime" column="last_query_time"/>
</resultMap>
<resultMap id="AppVirtualOrderSummaryResult" type="com.ruoyi.app.domain.AppVirtualOrderSummary">
<result property="orderNo" column="order_no"/>
<result property="resourceId" column="resource_id"/>
<result property="resourceTitle" column="resource_title"/>
<result property="resourceListId" column="resource_list_id"/>
<result property="specName" column="spec_name"/>
<result property="priceFen" column="price_fen"/>
<result property="status" column="status"/>
<result property="createTime" column="create_time"/>
<result property="payTime" column="pay_time"/>
<result property="refundTime" column="refund_time"/>
</resultMap>
<sql id="selectAppVirtualOrderVo">
select vo.id, vo.order_no, vo.user_id, u.user_name, u.nick_name,
vo.resource_id, r.resource_title, vo.product_id, vo.price_fen,
vo.resource_id, r.resource_title, vo.resource_list_id,
coalesce(vo.spec_name_snapshot, rl.list_name, '旧版整项资源') as spec_name,
vo.product_id, vo.price_fen,
vo.open_id, vo.status, vo.wx_order_no, vo.transaction_id,
vo.create_time, vo.pay_time, vo.provide_time, vo.refund_time, vo.last_query_time
from app_virtual_order vo
left join sys_user u on u.user_id = vo.user_id
left join app_resource r on r.id = vo.resource_id
left join app_resource_list rl on rl.id = vo.resource_list_id
</sql>
<select id="lockOpenIdForOrder" parameterType="Long" resultType="java.lang.String">
select open_id
from sys_user
where user_id = #{userId} and del_flag = '0'
for update
</select>
<insert id="insertAppVirtualOrder" parameterType="AppVirtualOrder" useGeneratedKeys="true" keyProperty="id">
insert into app_virtual_order
(order_no, user_id, resource_id, product_id, price_fen, open_id, status, create_time)
(order_no, user_id, resource_id, resource_list_id, spec_name_snapshot,
product_id, price_fen, open_id, status, create_time)
values
(#{orderNo}, #{userId}, #{resourceId}, #{productId}, #{priceFen}, #{openId}, #{status}, #{createTime})
(#{orderNo}, #{userId}, #{resourceId}, #{resourceListId}, #{specName},
#{productId}, #{priceFen}, #{openId}, #{status}, #{createTime})
</insert>
<select id="selectByOrderNo" resultMap="AppVirtualOrderResult">
select id, order_no, user_id, resource_id, product_id, price_fen, open_id, status,
select id, order_no, user_id, resource_id, resource_list_id,
spec_name_snapshot as spec_name, product_id, price_fen, open_id, status,
wx_order_no, transaction_id, create_time, pay_time, provide_time, refund_time, last_query_time
from app_virtual_order
where order_no = #{orderNo}
limit 1
</select>
<select id="selectPendingByPurchase" resultMap="AppVirtualOrderResult">
select id, order_no, user_id, resource_id, resource_list_id,
spec_name_snapshot as spec_name, product_id, price_fen, open_id, status,
wx_order_no, transaction_id, create_time, pay_time, provide_time, refund_time, last_query_time
from app_virtual_order
where user_id = #{userId}
and resource_id = #{resourceId}
and status = 0
<choose>
<when test="resourceListId != null">
and (resource_list_id = #{resourceListId} or resource_list_id is null)
</when>
<otherwise>
and resource_list_id is null
</otherwise>
</choose>
order by id desc
limit 1
</select>
<select id="selectAppVirtualOrderById" parameterType="Long" resultMap="AppVirtualOrderResult">
<include refid="selectAppVirtualOrderVo"/>
where vo.id = #{id}
@@ -72,6 +120,7 @@
or u.nick_name like concat('%', #{userName}, '%'))
</if>
<if test="resourceId != null">and vo.resource_id = #{resourceId}</if>
<if test="resourceListId != null">and vo.resource_list_id = #{resourceListId}</if>
<if test="productId != null and productId != ''">
and vo.product_id like concat('%', #{productId}, '%')
</if>
@@ -89,10 +138,30 @@
order by vo.create_time desc, vo.id desc
</select>
<select id="selectMyOrderList" resultMap="AppVirtualOrderSummaryResult">
select vo.order_no, vo.resource_id, coalesce(r.resource_title, '资源已删除') as resource_title,
vo.resource_list_id,
coalesce(vo.spec_name_snapshot, rl.list_name, '旧版整项资源') as spec_name,
vo.price_fen, vo.status, vo.create_time, vo.pay_time, vo.refund_time
from app_virtual_order vo
left join app_resource r on r.id = vo.resource_id
left join app_resource_list rl on rl.id = vo.resource_list_id
where vo.user_id = #{userId}
order by vo.create_time desc, vo.id desc
</select>
<select id="countAnyEntitlement" resultType="int">
select
(select count(1) from app_resource_entitlement
where user_id = #{userId} and resource_id = #{resourceId} and status = 1)
where user_id = #{userId} and resource_id = #{resourceId} and status = 1
<choose>
<when test="resourceListId != null">
and (resource_list_id is null or resource_list_id = #{resourceListId})
</when>
<otherwise>
and resource_list_id is null
</otherwise>
</choose>)
+
(select count(1) from app_integral_record
where user_id = #{userId}
@@ -108,14 +177,14 @@
transaction_id = coalesce(#{transactionId}, transaction_id),
pay_time = coalesce(#{payTime}, pay_time),
provide_time = now()
where order_no = #{orderNo} and status = 0
where order_no = #{orderNo} and status in (0, 3)
</update>
<insert id="insertEntitlement" parameterType="AppVirtualOrder">
insert into app_resource_entitlement
(user_id, resource_id, order_no, status, granted_time)
(user_id, resource_id, resource_list_id, order_no, status, granted_time)
values
(#{userId}, #{resourceId}, #{orderNo}, 1, now())
(#{userId}, #{resourceId}, #{resourceListId}, #{orderNo}, 1, now())
on duplicate key update
order_no = values(order_no),
status = 1,
@@ -140,6 +209,14 @@
where order_no = #{orderNo} and status = 0
</update>
<update id="cancelPendingOrder">
update app_virtual_order
set status = 3
where order_no = #{orderNo}
and user_id = #{userId}
and status = 0
</update>
<update id="markQuerying">
update app_virtual_order
set last_query_time = now()