182 lines
16 KiB
XML
182 lines
16 KiB
XML
<?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.peanut.modules.common.dao.UserCourseBuyDao">
|
|
|
|
<select id="getUserCourseBuyInfo" resultType="map">
|
|
select r.*
|
|
,ROUND(fee-alreadyTanxiao-currentTanxiao,2) surplusTanxiao
|
|
from (select e.*
|
|
,ROUND(if(alreadyDay+currentDay>=days,fee-alreadyTanxiao,if(alreadyTanxiao+currentDay*dayAmount>fee,fee-alreadyTanxiao,currentDay*dayAmount)),2) currentTanxiao
|
|
from (select w.name,w.tel,w.ctitle,w.cctitle,if(w.startTime is null,'',w.startTime) startTime,if(w.endTime is null,'',w.endTime) endTime,w.totalDays
|
|
,w.type,w.payType,w.payTime,w.orderSn,w.zfbOrder,w.days,w.fee,w.remark,w.dayAmount,w.alreadyDay,w.currentDay
|
|
,IF(beginDay=0,startTime,IF(startTime is NULL,startTime,DATE_ADD(startTime,INTERVAL beginDay-1 day))) startTanxiaoTime
|
|
,ROUND(if(alreadyDay=days,fee,if(alreadyDayAmount>fee,fee,alreadyDayAmount)),2) alreadyTanxiao
|
|
from (
|
|
select q.*,alreadyDay*dayAmount alreadyDayAmount
|
|
,IF(days-alreadyDay=0,0,IF(beginDay=0,IF(startTime is NULL,0,IF(days-alreadyDay>=monthDays,if(DATE_FORMAT(startTime,'%Y-%m')=SUBSTR(#{date},1,7),DATEDIFF(#{date},startTime)+1,if(DATE_FORMAT(startTime,'%Y-%m')>SUBSTR(#{date},1,7),0,monthDays)),if(DATE_FORMAT(startTime, '%Y-%m')=SUBSTR(#{date},1,7),if(DATEDIFF(#{date},startTime)+1>days,days,DATEDIFF(#{date},startTime)+1),if(DATE_FORMAT(startTime, '%Y-%m') < SUBSTR(#{date},1,7),days-alreadyDay,0)))), if(alreadyTotalDay+monthDays>beginDay,if(alreadyDay>0,if(days-alreadyDay>monthDays,monthDays,monthDays-(days-alreadyDay)),monthDays-(totalDays-days-alreadyTotalDay)),0) )) currentDay
|
|
from (
|
|
select s.*
|
|
,IF(alreadyTotalDay>beginDay,IF(beginDay=0,IF(alreadyTotalDay < days,alreadyTotalDay,days),alreadyTotalDay-beginDay+1),0) alreadyDay
|
|
,SUBSTR(#{date},9) monthDays
|
|
from (
|
|
select t.*
|
|
,IF(startTime is NULL,0,ROUND(fee/days,2)) dayAmount
|
|
,IF(startTime is NULL,0,IF(DATE_FORMAT(startTime,'%Y-%m')>=SUBSTR(#{date},1,7),0,IF(DATE_FORMAT(endTime,'%Y-%m') < SUBSTR(#{date},1,7),days,DATEDIFF(CONCAT(SUBSTR(#{date},1,7),'-01'),startTime)))) alreadyTotalDay
|
|
from (
|
|
select u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,c.title ctitle,cc.title cctitle,
|
|
ucb.days totalDays,ucb.start_time startTime,ucb.end_time endTime,
|
|
ucbl.type,ucbl.pay_type payType,ucbl.pay_time payTime,ucbl.order_sn orderSn,pzo.trade_no zfbOrder,
|
|
ucbl.begin_day beginDay,ucbl.days days,ucbl.fee,ucbl.remark
|
|
from user_course_buy_log ucbl
|
|
left join user_course_buy ucb on ucb.id = ucbl.user_course_buy_id
|
|
left join user u on u.id = ucb.user_id
|
|
left join course c on c.id = ucb.course_id
|
|
left join course_catalogue cc on cc.id = ucb.catalogue_id
|
|
left join pay_zfb_order pzo on pzo.relevanceOid = ucbl.order_sn and pzo.trade_no is not null
|
|
where ucbl.del_flag = 0 and ucbl.fee > 0 and DATE_FORMAT(ucbl.pay_time,'%Y-%m-%d') <= #{date}
|
|
and (u.id not in (select id from user where tester_flag = 1) or (u.id in (select id from user where tester_flag = 1 and ( ucbl.pay_type in ('微信','支付宝') and ucbl.create_time>='2026-05-06 00:00:00'))))
|
|
order by ucb.id
|
|
) t) s) q) w) e) r
|
|
</select>
|
|
|
|
<select id="getIncome" resultType="map">
|
|
select ucbl.pay_type,SUM(ucbl.fee) fee
|
|
from user_course_buy_log ucbl
|
|
left join buy_order bo on bo.order_sn = ucbl.order_sn
|
|
where DATE_FORMAT(ucbl.pay_time,'%Y-%m') = SUBSTR(#{date},1,7) and ucbl.del_flag = 0
|
|
and (ucbl.user_id not in (select id from user where tester_flag = 1) or ( ucbl.user_id in (select id from user where tester_flag = 1) and ucbl.pay_type in ('微信','支付宝') and ucbl.create_time>='2026-05-06 00:00:00'))
|
|
GROUP BY ucbl.pay_type
|
|
</select>
|
|
<select id="getRefund" resultType="map">
|
|
select pay_type,SUM(fee) fee
|
|
from (
|
|
select IF(bo.payment_method='1','App微信',IF(bo.payment_method='2','App支付宝',IF(bo.payment_method='4','App天医币','其他'))) pay_type,
|
|
bor.fee
|
|
from buy_order_refund bor
|
|
inner join buy_order bo on bo.order_id = bor.order_id and bo.del_flag = 0
|
|
where bo.order_status = '6'
|
|
and DATE_FORMAT(bor.create_time,'%Y-%m') = SUBSTR(#{date},1,7)
|
|
and (bo.user_id not in (select id from user where tester_flag = 1)
|
|
or (bo.user_id in (select id from user where tester_flag = 1) and bo.payment_method in ('1','2') and bo.create_time>='2026-05-06 00:00:00'))
|
|
and exists (
|
|
select 1 from buy_order_product bop
|
|
inner join shop_product sp on sp.product_id = bop.product_id
|
|
where bop.order_id = bo.order_id and sp.goods_type = '05'
|
|
)
|
|
) t
|
|
GROUP BY pay_type
|
|
</select>
|
|
<select id="getSameMonthRefund" resultType="map">
|
|
select pay_type,SUM(fee) fee
|
|
from (
|
|
select IF(bo.payment_method='1','微信',IF(bo.payment_method='2','支付宝',IF(bo.payment_method='4','天医币','其他'))) pay_type,
|
|
bor.fee
|
|
from buy_order_refund bor
|
|
inner join buy_order bo on bo.order_id = bor.order_id and bo.del_flag = 0
|
|
where bo.order_status = '6'
|
|
and DATE_FORMAT(bor.create_time,'%Y-%m') = SUBSTR(#{date},1,7)
|
|
and DATE_FORMAT(IF(bo.success_time is null,bo.create_time,bo.success_time),'%Y-%m') = SUBSTR(#{date},1,7)
|
|
and (bo.user_id not in (select id from user where tester_flag = 1)
|
|
or (bo.user_id in (select id from user where tester_flag = 1) and bo.payment_method in ('1','2') and bo.create_time>='2026-05-06 00:00:00'))
|
|
and exists (
|
|
select 1 from buy_order_product bop
|
|
inner join shop_product sp on sp.product_id = bop.product_id
|
|
where bop.order_id = bo.order_id and sp.goods_type = '05'
|
|
)
|
|
) t
|
|
GROUP BY pay_type
|
|
</select>
|
|
<select id="getRefundInfo" resultType="map">
|
|
select IFNULL(bor.wx_refund_no,bor.refund_no) as refund_no,u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,
|
|
IFNULL(c.title,IFNULL(sp.product_name,'')) ctitle,IFNULL(cc.title,'') cctitle,
|
|
IFNULL(spc.days,0) totalDays,'' startTime,'' endTime,
|
|
IF(bo.order_type='relearn','复读','order') type,
|
|
IF(bo.payment_method='1','微信',IF(bo.payment_method='2','支付宝',IF(bo.payment_method='4','天医币','其他'))) payType,
|
|
DATE_FORMAT(IF(bo.success_time is null,bo.create_time,bo.success_time),'%Y-%m-%d %H:%i:%s') payTime,
|
|
bo.order_sn orderSn,pzo.trade_no zfbOrder,
|
|
0 beginDay,IFNULL(spc.days,0) days,
|
|
ROUND(bor.fee/(select count(1) from buy_order_product bop2
|
|
inner join shop_product sp2 on sp2.product_id = bop2.product_id
|
|
where bop2.order_id = bo.order_id and sp2.goods_type = '05'),2) fee,
|
|
if(bo.remark like '%退%',bo.remark,if(bor.remark is null,'',bor.remark)) remark,
|
|
DATE_FORMAT(bor.create_time,'%Y-%m-%d %H:%i:%s') refundTime,
|
|
'已退款' orderStatus
|
|
from buy_order_refund bor
|
|
inner join buy_order bo on bo.order_id = bor.order_id and bo.del_flag = 0
|
|
inner join buy_order_product bop on bop.order_id = bo.order_id
|
|
inner join shop_product sp on sp.product_id = bop.product_id and sp.goods_type = '05'
|
|
left join shop_product_course spc on spc.product_id = sp.product_id and spc.del_flag = 0
|
|
left join course c on c.id = spc.course_id
|
|
left join course_catalogue cc on cc.id = spc.catalogue_id
|
|
left join user u on u.id = bo.user_id
|
|
left join pay_zfb_order pzo on pzo.relevanceOid = bo.order_sn and pzo.trade_no is not null
|
|
where bo.order_status = '6'
|
|
and DATE_FORMAT(bor.create_time,'%Y-%m') = SUBSTR(#{date},1,7)
|
|
and (bo.user_id not in (select id from user where tester_flag = 1)
|
|
or (bo.user_id in (select id from user where tester_flag = 1) and bo.payment_method in ('1','2') and bo.create_time>='2026-05-06 00:00:00'))
|
|
order by bor.create_time asc
|
|
</select>
|
|
<select id="getUserCourseBuyInfoTotal" resultType="map">
|
|
select if(ROUND(SUM(fee),2) is null,0,ROUND(SUM(fee),2)) fee,
|
|
if(ROUND(SUM(alreadyTanxiao),2) is null,0,ROUND(SUM(alreadyTanxiao),2)) alreadyTanxiao,
|
|
if(ROUND(SUM(currentTanxiao),2) is null,0,ROUND(SUM(currentTanxiao),2)) currentTanxiao,
|
|
if(ROUND(SUM(surplusTanxiao),2) is null,0,ROUND(SUM(surplusTanxiao),2)) surplusTanxiao
|
|
from (
|
|
select r.*
|
|
,ROUND(fee-alreadyTanxiao-currentTanxiao,2) surplusTanxiao
|
|
from (select e.*
|
|
,ROUND(if(alreadyDay+currentDay>=days,fee-alreadyTanxiao,if(alreadyTanxiao+currentDay*dayAmount>fee,fee-alreadyTanxiao,currentDay*dayAmount)),2) currentTanxiao
|
|
from (select w.name,w.tel,w.ctitle,w.cctitle,if(w.startTime is null,'',w.startTime) startTime,if(w.endTime is null,'',w.endTime) endTime,w.totalDays
|
|
,w.type,w.payType,w.payTime,w.orderSn,w.zfbOrder,w.days,w.fee,w.remark,w.dayAmount,w.alreadyDay,w.currentDay
|
|
,IF(beginDay=0,startTime,IF(startTime is NULL,startTime,DATE_ADD(startTime,INTERVAL beginDay-1 day))) startTanxiaoTime
|
|
,ROUND(if(alreadyDay=days,fee,if(alreadyDayAmount>fee,fee,alreadyDayAmount)),2) alreadyTanxiao
|
|
from (
|
|
select q.*,alreadyDay*dayAmount alreadyDayAmount
|
|
,IF(days-alreadyDay=0,0,IF(beginDay=0,IF(startTime is NULL,0,IF(days-alreadyDay>=monthDays,if(DATE_FORMAT(startTime,'%Y-%m')=SUBSTR(#{date},1,7),DATEDIFF(#{date},startTime)+1,if(DATE_FORMAT(startTime,'%Y-%m')>SUBSTR(#{date},1,7),0,monthDays)),if(DATE_FORMAT(startTime, '%Y-%m')=SUBSTR(#{date},1,7),if(DATEDIFF(#{date},startTime)+1>days,days,DATEDIFF(#{date},startTime)+1),if(DATE_FORMAT(startTime, '%Y-%m') < SUBSTR(#{date},1,7),days-alreadyDay,0)))), if(alreadyTotalDay+monthDays>beginDay,if(alreadyDay>0,if(days-alreadyDay>monthDays,monthDays,monthDays-(days-alreadyDay)),monthDays-(totalDays-days-alreadyTotalDay)),0) )) currentDay
|
|
from (
|
|
select s.*
|
|
,IF(alreadyTotalDay>beginDay,IF(beginDay=0,IF(alreadyTotalDay < days,alreadyTotalDay,days),alreadyTotalDay-beginDay+1),0) alreadyDay
|
|
,SUBSTR(#{date},9) monthDays
|
|
from (
|
|
select t.*
|
|
,IF(startTime is NULL,0,ROUND(fee/days,2)) dayAmount
|
|
,IF(startTime is NULL,0,IF(DATE_FORMAT(startTime,'%Y-%m')>=SUBSTR(#{date},1,7),0,IF(DATE_FORMAT(endTime,'%Y-%m') < SUBSTR(#{date},1,7),days,DATEDIFF(CONCAT(SUBSTR(#{date},1,7),'-01'),startTime)))) alreadyTotalDay
|
|
from (
|
|
select u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,c.title ctitle,cc.title cctitle,
|
|
ucb.days totalDays,ucb.start_time startTime,ucb.end_time endTime,
|
|
ucbl.type,ucbl.pay_type payType,ucbl.pay_time payTime,ucbl.order_sn orderSn,pzo.trade_no zfbOrder,
|
|
ucbl.begin_day beginDay,ucbl.days days,ucbl.fee,ucbl.remark
|
|
from user_course_buy_log ucbl
|
|
left join user_course_buy ucb on ucb.id = ucbl.user_course_buy_id
|
|
left join user u on u.id = ucb.user_id
|
|
left join course c on c.id = ucb.course_id
|
|
left join course_catalogue cc on cc.id = ucb.catalogue_id
|
|
left join pay_zfb_order pzo on pzo.relevanceOid = ucbl.order_sn and pzo.trade_no is not null
|
|
where ucbl.del_flag = 0 and ucbl.fee > 0 and DATE_FORMAT(ucbl.pay_time,'%Y-%m-%d') <= #{date}
|
|
and u.id not in (select id from user where tester_flag = 1)
|
|
order by ucb.id
|
|
) t) s) q) w) e) r
|
|
) t
|
|
</select>
|
|
|
|
<select id="getCoursePurchaseDetails" resultType="map">
|
|
select u.name,IF(u.tel is NULL,u.email,u.tel) tel,ucbl.order_sn orderSn,
|
|
DATE_FORMAT(IF(ucbl.pay_time is NULL,ucb.create_time,ucbl.pay_time),'%Y-%m-%d %H:%i:%s') payTime,
|
|
ucb.days allDays,IF(bo.order_type = 'relearn','复读',sp.product_name) productName,ucbl.type,ucbl.pay_type payType,
|
|
ucbl.days,ucbl.fee,ucbl.jf,ucb.come,ucbl.remark
|
|
from user_course_buy ucb
|
|
left join user u on u.id = ucb.user_id
|
|
left join user_course_buy_log ucbl on ucbl.user_course_buy_id = ucb.id
|
|
left join buy_order bo on bo.order_sn = ucbl.order_sn
|
|
left join buy_order_product bop on bop.order_id = bo.order_id
|
|
left join shop_product sp on sp.product_id = bop.product_id and sp.goods_type = '05'
|
|
where u.del_flag = 0 and u.tester_flag = 0
|
|
and ucb.course_id = #{courseId} and catalogue_id = #{catalogueId}
|
|
order by pay_time desc
|
|
<if test="limit !=null and limit != ''">
|
|
limit #{offset},#{limit}
|
|
</if>
|
|
</select>
|
|
|
|
</mapper> |