410 lines
17 KiB
XML
Raw Permalink Normal View History

2026-03-10 14:30:24 +08:00
<?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="OrderInfo">
<insert id="insertOrderInfo" parameterType="OrderInfo">
INSERT INTO OrderInfo ( orderInfoId, uid, amount, isPayed,
isDeleted, payWay, description, gains, fees,
created, payTime , areaid , channel ,orderNo)
Values ( #{orderInfoId}, #{uid}, #{amount}, #{isPayed},
#{isDeleted}, #{payWay}, #{description}, #{gains}, #{fees},
current_timestamp, #{payTime} , #{areaid} , #{channel} , #{orderNo})
</insert>
<update id="updateOrderInfo" parameterType="OrderInfo">
UPDATE OrderInfo
SET orderInfoId = #{orderInfoId}, uid = #{uid}, amount = #{amount},
isPayed = #{isPayed}, isDeleted = #{isDeleted}, payWay = #{payWay},
description = #{description}, gains = #{gains}, fees = #{fees},
created = #{created}, payTime = #{payTime} , areaid = #{areaid} ,
payNumber = #{payNumber} , orderNo = #{orderNo}
where orderInfoId=#{orderInfoId}
and areaid = #{areaid} and uid=#{uid}
</update>
<!--区级-->
<select id="getAmountByAreaid" parameterType="java.util.Map" resultType="OrderInfo">
select o1.amount from OrderInfo as o1 INNER JOIN OrderOwnGoods as og on o1.orderInfoId = og.orderInfoId INNER JOIN StudentOwnClass as sc ON o1.uid = sc.studentId INNER JOIN Classes c ON sc.classesId = c.classesId and c.status = 1 and c.classtype = 1 WHERE o1.areaId = #{areaId} and ispayed = 1 and payway &gt; 0
<if test="startTime!=null">
<![CDATA[
and o1.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and o1.created < #{endTime}
]]>
</if>
<if test="areaIds!=null">
and a1.areaId in
<foreach collection="areaIds" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</if>
GROUP BY o1.amount
</select>
<!-- 市级 -->
<select id="getAmountByParentId" parameterType="java.util.Map" resultType="OrderInfo">
select o1.amount from OrderInfo as o1 INNER JOIN OrderOwnGoods as og on o1.orderInfoId = og.orderInfoId INNER JOIN Area as a1 on o1.areaId = a1.areaId WHERE a1.parentId = #{areaId} and ispayed = 1 and payway &gt; 0
<if test="startTime!=null">
<![CDATA[
and o1.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and o1.created < #{endTime}
]]>
</if>
<if test="areaIds!=null">
and a1.areaId in
<foreach collection="areaIds" item="item" separator="," close=")" open="(">
#{item}
</foreach>
</if>
GROUP BY o1.amount;
</select>
<!--学校-->
<select id="getAmountBySchoolId" parameterType="java.util.Map" resultType="OrderInfo">
select o1.amount from OrderInfo as o1 INNER JOIN OrderOwnGoods as og on o1.orderInfoId = og.orderInfoId INNER JOIN StudentOwnClass as sc on o1.uid = sc.studentId and sc.status = 1 INNER JOIN Classes as c on sc.classesId = c.classesId and c.status=1
WHERE c.schoolId = #{schoolId} and ispayed = 1 and payway &gt; 0
<if test="startTime!=null">
<![CDATA[
and o1.created > #{startTime}
]]>
</if>
<if test="endTime!=null">
<![CDATA[
and o1.created < #{endTime}
]]>
</if>
GROUP BY o1.amount
</select>
<select id="getOrderInfoByKey" parameterType="java.util.Map" resultType="OrderInfo">
SELECT orderInfoId , uid , amount , isPayed , isDeleted , payWay ,
description , gains , fees , created , payTime , areaid ,
payNumber , channel , orderNo
FROM OrderInfo
WHERE orderInfoId=#{orderInfoId}
and uid=#{uid} and areaid = #{areaid}
</select>
<select id="getOrderInfoByOrderNo" parameterType="String" resultType="OrderInfo">
SELECT orderInfoId , uid , amount , isPayed , isDeleted , payWay ,
description , gains , fees , created , payTime , areaid ,
payNumber , channel , orderNo
FROM OrderInfo
WHERE orderNo = #{_parameter}
</select>
<select id="getRefundInfoByOrderNoOfVerify" parameterType="String" resultType="java.util.HashMap">
SELECT oi.orderInfoId , oi.uid , oi.amount , oi.isPayed , oi.isDeleted , oi.payWay ,
oi.description , oi.gains , oi.fees , to_char(oi.created,'yyyy-MM-dd HH24:MI:SS') created ,
to_char(oi.payTime,'yyyy-MM-dd HH24:MI:SS') payTime , oi.areaid ,
oi.payNumber , oi.channel , oi.orderNo ,oo.years
FROM OrderInfo oi inner join orderowngoods oo on oi.orderInfoid=oo.orderinfoid
WHERE orderNo = #{_parameter} and oi.isPayed=1 limit 1
</select>
<!-- 查询现金支付记录 -->
<select id="getOrderInfoByUidAndOrderNo" parameterType="java.util.Map" resultType="OrderInfo">
SELECT orderInfoId , uid , amount , isPayed , isDeleted , payWay ,
description , gains , fees , created , payTime , areaid ,
payNumber , channel , orderNo
FROM OrderInfo
WHERE orderNo = #{orderNo} and uid=#{uid} and ispayed !=0
</select>
<select id="getSeqOrderInfo" resultType="Integer" useCache="false" flushCache="true">
SELECT nextval('seq_orderInfoId')
</select>
<select id="getOrderInfoCountByUid" parameterType="java.util.Map" resultType="Integer">
SELECT count(*) from OrderInfo
WHERE uid=#{uid} and areaid = #{areaid} and isPayed!=0 and payway!=0
<if test="payWay == -2">
AND ( ( payWay &gt; 0 ) or ( payWay is null ) or (payWay=-100) )
</if>
<if test="payWay>-1">
AND payWay = #{payWay}
</if>
<if test="payWay == -100">
AND payWay=-100
</if>
</select>
<select id="getOrderInfosByUid" parameterType="java.util.Map" resultType="OrderInfo">
SELECT orderInfoId , uid , amount , isPayed , isDeleted , payWay ,
description , gains , fees , created , payTime , areaid , payNumber , channel , orderNo
FROM OrderInfo
WHERE uid=#{uid} and areaid = #{areaid} and isPayed!=0 and payway!=0
<if test="payWay == -2">AND
( ( payWay &gt; 0 ) or ( payWay is null ) or (payWay=-100) )
</if>
<if test="payWay>-1">AND
payWay = #{payWay}
</if>
<if test="payWay == -100">AND
payWay=-100
</if>
order by created desc
<if test="pageSize!=null">
LIMIT #{pageSize}
</if>
<if test="offset!=null">
OFFSET #{offset}
</if>
</select>
<insert id="sendOrderInfosToClass" parameterType="java.util.Map" flushCache="true">
INSERT INTO OrderInfo ( orderInfoId, uid, amount , isPayed,
isDeleted, payWay, description , gains ,
fees , created , payTime , areaid )
SELECT nextval('seq_orderInfoId') , studentId , 0 , 1 ,
0 , 0, '赠送的商品' , 0 , 0 ,
current_timestamp , current_timestamp , #{areaid}
FROM StudentOwnClass
WHERE classesId = #{classesId}
</insert>
<insert id="sendOrderInfoToUser" parameterType="java.util.Map" flushCache="true">
INSERT INTO OrderInfo ( orderInfoId, uid, amount , isPayed,
isDeleted, payWay, description , gains , fees ,
created , payTime ,areaid )
SELECT nextval('seq_orderInfoId') , #{userId} , 0 , 1 ,
0 , 0, '赠送的商品' , 0 , 0 ,
current_timestamp , current_timestamp ,#{areaid}
</insert>
<insert id="insertOrderInfoBatch" parameterType="java.util.List">
INSERT INTO OrderInfo ( orderInfoId, uid, amount, isPayed, isDeleted,
payWay, description, gains, fees, created, payTime , areaid ) Values
<foreach collection="list" index="index" item="item" separator=",">
( #{item.orderInfoId}, #{item.uid}, #{item.amount},
#{item.isPayed}, #{item.isDeleted}, #{item.payWay},
#{item.description}, #{item.gains}, #{item.fees},
#{item.created}, #{item.payTime} , #{item.areaid})
</foreach>
</insert>
<select id="payedFee" parameterType="java.lang.Long" resultType="PayedFeeDto">
SELECT a.uid , a.created, a.amount , b.goodsid , b.years
FROM ( SELECT orderinfoid , uid , created , amount
FROM OrderInfo
WHERE uid = #{uid} AND ispayed =1
AND payway &gt; 0 AND amount &gt;= 100
) a
INNER JOIN orderowngoods b
ON a.orderInfoId = b.orderInfoId
WHERE b.goodsId = 0
UNION
SELECT b.uid , b.created, b.amount , 0 as goodsid , 0 as years
FROM OrderInfo b
WHERE b.uid = #{uid} and b.ispayed = -1 and payway = -100
ORDER BY created asc
</select>
<select id="userAuthCountByBreakPoint" resultType="java.lang.Integer">
select count(distinct uid) from orderinfo where ispayed=1 and payway=0 and
paytime &lt; '2016-10-27 15:25:32'
</select>
<select id="userAuthCountTotalByEndTime" parameterType="java.util.Date" resultType="java.lang.Integer">
select count(distinct uid) from orderinfo where ispayed=1 and payway=0 and
paytime &lt; #{endTime}
</select>
<select id="userPayCountTotalByEndTime" parameterType="java.util.Date" resultType="java.lang.Integer">
select count(distinct uid) from orderinfo where ispayed in ( 1 ,-1) and ( payway&gt;0 or payway=-100) and
paytime &lt; #{endTime}
</select>
<select id="userRenewCountTotalByEndTime" parameterType="java.util.Date" resultType="java.lang.Integer">
select sum(renew) from (select case when count(uid)&gt;1 then 1 else 0 end as renew
from orderinfo where ispayed in ( 1 ,-1) and ( payway&gt;0 or payway=-100)
and paytime &lt; #{endTime} group by uid) as a
</select>
<select id="getOrderInfoByendTimeAndAreaId" parameterType="java.util.Map" resultType="OrderInfo">
SELECT orderInfoId , uid , amount , isPayed , isDeleted , payWay ,
description , gains , fees , created , payTime , areaid ,
payNumber , channel , orderNo
FROM OrderInfo
WHERE areaId=#{areaId} and isPayed=1 and isdeleted=0
and payway&gt;0 and
payTime&gt;=#{endTime}
</select>
<select id="getOrderInfoByendTimeAndParentId" parameterType="java.util.Map" resultType="OrderInfo">
SELECT orderInfoId , uid , amount , isPayed , isDeleted , payWay ,
description , gains , fees , created , payTime , areaid ,
payNumber , channel , orderNo
FROM OrderInfo
WHERE areaId in (select areaId from area where parentid=#{parentId}) and isPayed=1 and isdeleted=0
and payway&gt;0 and
payTime&gt;=#{endTime}
</select>
<select id="getOrderInfoByCompPayInfoId" parameterType="java.lang.String" resultType="OrderInfo">
SELECT orderInfoId , uid , amount , isPayed , isDeleted , payWay ,
description , gains , fees , created , payTime , areaid ,
payNumber , channel , orderNo
FROM OrderInfo
WHERE OrderNo = #{_parameter} and isPayed=-1 and payway=-100
</select>
<select id="getOrderInfoAndSchoolUserCountAll" parameterType="java.util.Map" resultType="java.util.HashMap">
<![CDATA[
with area1 as (select areaId,areaname from area where parentId=0),
area2 as (select areaId,parentId from area where parentId in (select areaId from area1)),
area3 as (select areaId,parentId from area where parentId in (select areaId from area2)),
temp as (select a3.areaId,a3.parentId,a2.parentid grandparentId from area2 a2 inner join area3 a3 on a2.areaId=a3.parentId)
select t.areaId,t.areaname,cashAmount,cashFees ,cashCount,netAmount,netFees,netCount,schooluserCount from(
select sum(cashAmount) cashAmount,sum( cashFees) cashFees ,sum (cashCount) cashCount,a.grandparentId areaId,
sum (netAmount) netAmount,sum( netFees) netFees, sum( netCount) netCount,sum( schooluserCount) schooluserCount
from (
select sum(o.amount) cashAmount,sum(o.fees) cashFees ,count(o.orderinfoid) cashCount,t.grandparentId ,
0 as netAmount,0 as netFees , 0 as netCount,0 as schooluserCount from orderinfo o
inner join temp t on o.areaid=t.areaid and paytime >=#{startTime} and paytime < #{endTime}
and isdeleted=0 and ispayed = -1 and payway=-100
group by grandparentId
union all
select 0 cashAmount,0 cashFees ,0 cashCount,t.grandparentId ,sum(o.amount) as netAmount,sum(o.fees) as netFees ,
count(o.orderinfoid) as netCount,0 as schooluserCount from orderinfo o
inner join temp t on o.areaid=t.areaid and paytime >=#{startTime} and paytime < #{endTime}
and isdeleted=0 and ispayed = 1 and payway>0
group by grandparentId
union all
select 0 cashAmount,0 cashFees ,0 cashCount,t.grandparentId ,0 as netAmount,0 as netFees , 0 as netCount,
count(schooluserId) as schooluserCount from schooluser o
inner join temp t on o.areaid=t.areaid and activitytime >=#{startTime} and activitytime < #{endTime} and status=1 and ifactivity=1
group by grandparentId
) a group by grandparentId
) b right join area1 t on b.areaId = t.areaId
order by t.areaId
]]>
</select>
<select id="getOrderInfoAndSchoolUserCountByGrandParentId" parameterType="java.util.Map" resultType="java.util.HashMap">
<![CDATA[
with area1 as (select areaId,areaname from area where parentId=#{areaId}),
temp as (select areaId,parentId from area where parentId in (select areaId from area1))
select t.areaId,t.areaname,cashAmount,cashFees ,cashCount,netAmount,netFees,netCount,schooluserCount from(
select sum(cashAmount) cashAmount,sum( cashFees) cashFees ,sum (cashCount) cashCount,a.parentId areaId,sum (netAmount) netAmount,sum( netFees) netFees, sum( netCount) netCount,sum( schooluserCount) schooluserCount
from (
select sum(o.amount) cashAmount,sum(o.fees) cashFees ,count(o.orderinfoid) cashCount,t.parentId ,0 as netAmount,0 as netFees , 0 as netCount,0 as schooluserCount from orderinfo o
inner join temp t on o.areaid=t.areaid and paytime >=#{startTime} and paytime < #{endTime}
and isdeleted=0 and ispayed = -1 and payway=-100
group by parentId
union all
select 0 cashAmount,0 cashFees ,0 cashCount,t.parentId ,sum(o.amount) as netAmount,sum(o.fees) as netFees , count(o.orderinfoid) as netCount,0 as schooluserCount from orderinfo o
inner join temp t on o.areaid=t.areaid and paytime>=#{startTime} and paytime < #{endTime}
and isdeleted=0 and ispayed = 1 and payway>0
group by parentId
union all
select 0 cashAmount,0 cashFees ,0 cashCount,t.parentId ,0 as netAmount,0 as netFees , 0 as netCount,count(schooluserId) as schooluserCount from schooluser o
inner join temp t on o.areaid=t.areaid and activitytime >=#{startTime} and activitytime <#{endTime} and status=1 and ifactivity=1
group by parentId
) a group by parentId
) b right join area1 t on b.areaId = t.areaId
]]>
</select>
<select id="getOrderInfoAndSchoolUserCountByParentId" parameterType="java.util.Map" resultType="java.util.HashMap">
with temp as (select areaId,areaname from area where
<if test="parentId!=null">
parentId=#{parentId}
</if>
<if test="areaId!=null">
areaid=#{areaId}
</if>
)
<![CDATA[
select t.areaId,t.areaname,cashAmount,cashFees ,cashCount,netAmount,netFees,netCount,schooluserCount from(
select sum(cashAmount) cashAmount,sum( cashFees) cashFees ,sum (cashCount) cashCount,a.areaId areaId,sum (netAmount) netAmount,sum( netFees) netFees, sum( netCount) netCount,sum( schooluserCount) schooluserCount
from (
select sum(o.amount) cashAmount,sum(o.fees) cashFees ,count(o.orderinfoid) cashCount,t.areaId ,0 as netAmount,0 as netFees , 0 as netCount,0 as schooluserCount from orderinfo o
inner join temp t on o.areaid=t.areaid and paytime >=#{startTime} and paytime <#{endTime}
and isdeleted=0 and ispayed = -1 and payway=-100
group by t.areaId
union all
select 0 cashAmount,0 cashFees ,0 cashCount,t.areaId ,sum(o.amount) as netAmount,sum(o.fees) as netFees , count(o.orderinfoid) as netCount,0 as schooluserCount from orderinfo o
inner join temp t on o.areaid=t.areaid and paytime >=#{startTime} and paytime <#{endTime}
and isdeleted=0 and ispayed = 1 and payway>0
group by t.areaId
union all
select 0 cashAmount,0 cashFees ,0 cashCount,t.areaId ,0 as netAmount,0 as netFees , 0 as netCount,count(schooluserId) as schooluserCount from schooluser o
inner join temp t on o.areaid=t.areaid and activitytime >=#{startTime} and activitytime < #{endTime} and status=1 and ifactivity=1
group by t.areaId
) a group by areaId
) b right join temp t on b.areaId = t.areaId
]]>
</select>
</mapper>