组合商品 天医币报表、实物报表、课程报表

This commit is contained in:
wyn
2026-08-06 17:24:35 +08:00
parent fdb3e7a4bd
commit 83fc611574
18 changed files with 498 additions and 69 deletions

View File

@@ -50,13 +50,66 @@
<!-- <resultMap id="OrderDetailResult" type="com.peanut.modules.book.entity.BuyOrderDetail">-->
<!-- </resultMap>-->
<!-- 按订单预聚合:纯课程(05)标价合计、书课组合(07)书/课拆分标价合计(避免相关子查询) -->
<sql id="physicalAmountJoins">
left join (
select bop05.order_id,
SUM(IF(sp05.activity_price &lt; sp05.price, sp05.activity_price, sp05.price)) course05Sum
from buy_order_product bop05
inner join shop_product sp05 on sp05.product_id = bop05.product_id and sp05.goods_type = '05'
group by bop05.order_id
) c05 on c05.order_id = t.order_id
left join (
select bop07.order_id,
IFNULL(SUM(spc_sum.s), 0) cs,
IFNULL(SUM(spb_sum.s), 0) bs
from buy_order_product bop07
inner join shop_product sp07 on sp07.product_id = bop07.product_id and sp07.goods_type = '07'
left join (
select product_id, SUM(IFNULL(product_price, 0)) s
from shop_product_course
where del_flag = 0
group by product_id
) spc_sum on spc_sum.product_id = sp07.product_id
left join (
select product_id, SUM(IFNULL(product_price, 0)) s
from shop_product_book
where del_flag = 0
group by product_id
) spb_sum on spb_sum.product_id = sp07.product_id
group by bop07.order_id
) c07 on c07.order_id = t.order_id
</sql>
<!-- 实物金额 = 订单/退款金额 - 纯课程(05)标价 - 书课组合(07)课价分摊部分 -->
<sql id="physicalAmountExpr">
${baseAmount}
- IFNULL(c05.course05Sum, 0)
- IFNULL(ROUND(${baseAmount} * IFNULL(c07.cs, 0) / NULLIF(IFNULL(c07.cs, 0) + IFNULL(c07.bs, 0), 0), 2), 0)
</sql>
<sql id="physicalProductNameExpr">
GROUP_CONCAT(
IF(sp.goods_type = '07',
IFNULL((
select GROUP_CONCAT(bk.name SEPARATOR '/')
from shop_product_book spb
inner join book bk on bk.id = spb.book_id
where spb.product_id = sp.product_id and spb.del_flag = 0
), sp.product_name),
sp.product_name
) SEPARATOR ', '
)
</sql>
<select id="getPhysicalBuyOrderTotal" resultType="map">
select payType,count(1) count,SUM(price) totalPrice from (
select q.*,pzo.trade_no zfbOrder
from (
select t.createTime,t.name,t.tel,t.orderSn,t.orderStatus,t.payType,t.orderPrice,
t.orderPrice-(select IF(SUM(if(sp2.activity_price&lt;sp2.price,sp2.activity_price,sp2.price)) is NULL,0,SUM(if(sp2.activity_price&lt;sp2.price,sp2.activity_price,sp2.price))) from shop_product sp2 where sp2.goods_type = '05' and sp2.product_id in (GROUP_CONCAT(sp.product_id SEPARATOR ','))) price,
GROUP_CONCAT(sp.product_name SEPARATOR ', ') productName,t.remark
MAX(<include refid="physicalAmountExpr"><property name="baseAmount" value="t.orderPrice"/></include>) price,
<include refid="physicalProductNameExpr"/> productName,t.remark
from (
select bo.order_id,DATE_FORMAT(bo.create_time,'%Y-%m-%d %H:%i:%s') createTime,u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,bo.order_sn orderSn,
IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝',IF(bo.payment_method=4,'天医币','0'))) payType,
@@ -84,6 +137,7 @@
) t
left join buy_order_product bop on bop.order_id = t.order_id
left join shop_product sp on sp.product_id = bop.product_id
<include refid="physicalAmountJoins"/>
group by t.orderSn
) q
left join pay_zfb_order pzo on pzo.relevanceOid = q.orderSn and pzo.trade_no is not null
@@ -95,8 +149,8 @@
select q.*,pzo.trade_no zfbOrder
from (
select t.createTime,t.name,t.tel,t.orderSn,t.orderStatus,t.payType,t.refundFee,
t.refundFee-(select IF(SUM(if(sp2.activity_price&lt;sp2.price,sp2.activity_price,sp2.price)) is NULL,0,SUM(if(sp2.activity_price&lt;sp2.price,sp2.activity_price,sp2.price))) from shop_product sp2 where sp2.goods_type = '05' and sp2.product_id in (GROUP_CONCAT(sp.product_id SEPARATOR ','))) price,
GROUP_CONCAT(sp.product_name SEPARATOR ', ') productName,t.remark
MAX(<include refid="physicalAmountExpr"><property name="baseAmount" value="t.refundFee"/></include>) price,
<include refid="physicalProductNameExpr"/> productName,t.remark
from (
select bo.order_id,DATE_FORMAT(bor.create_time,'%Y-%m-%d %H:%i:%s') createTime,u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,bo.order_sn orderSn,
IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝',IF(bo.payment_method=4,'天医币','0'))) payType,
@@ -125,6 +179,7 @@
) t
left join buy_order_product bop on bop.order_id = t.order_id
left join shop_product sp on sp.product_id = bop.product_id
<include refid="physicalAmountJoins"/>
group by t.orderSn
) q
left join pay_zfb_order pzo on pzo.relevanceOid = q.orderSn and pzo.trade_no is not null
@@ -135,8 +190,8 @@
select q.*,pzo.trade_no zfbOrder
from (
select t.createTime,t.name,t.tel,t.orderSn,t.orderStatus,t.payType,t.orderPrice,
t.orderPrice-(select IF(SUM(if(sp2.activity_price&lt;sp2.price,sp2.activity_price,sp2.price)) is NULL,0,SUM(if(sp2.activity_price&lt;sp2.price,sp2.activity_price,sp2.price))) from shop_product sp2 where sp2.goods_type = '05' and sp2.product_id in (GROUP_CONCAT(sp.product_id SEPARATOR ','))) price,
GROUP_CONCAT(sp.product_name SEPARATOR ', ') productName,IF(count(1)=1,bop.quantity,'') quantity,t.remark
MAX(<include refid="physicalAmountExpr"><property name="baseAmount" value="t.orderPrice"/></include>) price,
<include refid="physicalProductNameExpr"/> productName,IF(count(1)=1,bop.quantity,'') quantity,t.remark
from (
select bo.order_id,DATE_FORMAT(bo.create_time,'%Y-%m-%d %H:%i:%s') createTime,u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,bo.order_sn orderSn,
IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝',IF(bo.payment_method=4,'天医币','0'))) payType,
@@ -164,6 +219,7 @@
) t
left join buy_order_product bop on bop.order_id = t.order_id
left join shop_product sp on sp.product_id = bop.product_id
<include refid="physicalAmountJoins"/>
group by t.orderSn
) q
left join pay_zfb_order pzo on pzo.relevanceOid = q.orderSn and pzo.trade_no is not null
@@ -172,8 +228,8 @@
select q.*,pzo.trade_no zfbOrder
from (
select t.createTime,t.name,t.tel,t.orderSn,t.orderStatus,t.payType,t.orderPrice,
t.orderPrice-(select IF(SUM(if(sp2.activity_price&lt;sp2.price,sp2.activity_price,sp2.price)) is NULL,0,SUM(if(sp2.activity_price&lt;sp2.price,sp2.activity_price,sp2.price))) from shop_product sp2 where sp2.goods_type = '05' and sp2.product_id in (GROUP_CONCAT(sp.product_id SEPARATOR ','))) price,
GROUP_CONCAT(sp.product_name SEPARATOR ', ') productName,IF(count(1)=1,bop.quantity,'') quantity,t.remark,t.refund_no
MAX(<include refid="physicalAmountExpr"><property name="baseAmount" value="t.orderPrice"/></include>) price,
<include refid="physicalProductNameExpr"/> productName,IF(count(1)=1,bop.quantity,'') quantity,t.remark,t.refund_no
from (
select bo.order_id,DATE_FORMAT(bor.create_time,'%Y-%m-%d %H:%i:%s') createTime,u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,bo.order_sn orderSn,
IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝',IF(bo.payment_method=4,'天医币','0'))) payType,
@@ -202,6 +258,7 @@
) t
left join buy_order_product bop on bop.order_id = t.order_id
left join shop_product sp on sp.product_id = bop.product_id
<include refid="physicalAmountJoins"/>
group by t.orderSn
) q
left join pay_zfb_order pzo on pzo.relevanceOid = q.orderSn and pzo.trade_no is not null