312 lines
19 KiB
XML
312 lines
19 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.BuyOrderDao">
|
|
|
|
<!-- 可根据自己的需求,是否要使用 -->
|
|
<resultMap type="com.peanut.modules.common.entity.BuyOrder" id="buyOrderMap">
|
|
<result property="orderId" column="order_id"/>
|
|
<result property="orderSn" column="order_sn"/>
|
|
<result property="userId" column="user_id"/>
|
|
<result property="shippingUser" column="shipping_user"/>
|
|
<result property="province" column="province"/>
|
|
<result property="city" column="city"/>
|
|
<result property="district" column="district"/>
|
|
<result property="address" column="address"/>
|
|
<result property="paymentMethod" column="payment_method"/>
|
|
<result property="orderMoney" column="order_money"/>
|
|
<result property="districtMoney" column="district_money"/>
|
|
<result property="realMoney" column="real_money"/>
|
|
<result property="shippingMoney" column="shipping_money"/>
|
|
<result property="shippingCompName" column="shipping_comp_name"/>
|
|
<result property="shippingSn" column="shipping_sn"/>
|
|
<result property="createTime" column="create_time"/>
|
|
<result property="shippingTime" column="shipping_time"/>
|
|
<result property="orderStatus" column="order_status"/>
|
|
<result property="successTime" column="success_time"/>
|
|
<result property="couponId" column="coupon_id"/>
|
|
<result property="couponName" column="coupon_name"/>
|
|
<result property="userPhone" column="user_phone"/>
|
|
<result property="orderType" column="order_type"/>
|
|
<result property="delFlag" column="del_flag"/>
|
|
<result property="expNo" column="exp_no"/>
|
|
<result property="isSend" column="is_send"/>
|
|
<result property="addressId" column="address_id"/>
|
|
<result property="remark" column="remark"/>
|
|
<result property="orderCode" column="order_code"/>
|
|
<result property="paymentDate" column="payment_date"/>
|
|
|
|
|
|
<collection property="products" ofType="com.peanut.modules.common.entity.BuyOrderDetail">
|
|
<result property="orderId" column="order_id"/>
|
|
<result property="productName" column="product_name"/>
|
|
<result property="quantity" column="quantity"/>
|
|
<result property="productPrice" column="product_price"/>
|
|
<result property="weight" column="weight"/>
|
|
<result property="remark" column="remark"/>
|
|
</collection>
|
|
</resultMap>
|
|
|
|
<!-- <resultMap id="OrderDetailResult" type="com.peanut.modules.book.entity.BuyOrderDetail">-->
|
|
|
|
<!-- </resultMap>-->
|
|
<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<sp2.price,sp2.activity_price,sp2.price)) is NULL,0,SUM(if(sp2.activity_price<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
|
|
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,
|
|
IF(bo.order_status = 4,'已删除',IF(bo.order_status = 3,'已完成',IF(bo.order_status = 2,'已发货','已付款'))) orderStatus,bo.real_money orderPrice,if(bo.remark like '%退%',bo.remark,'') remark
|
|
from buy_order bo
|
|
left join user u on u.id = bo.user_id
|
|
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
|
|
where
|
|
( 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 (bo.payment_method='1' or bo.payment_method='2') and bo.create_time>='2026-05-06 00:00:00') )
|
|
and bo.order_status in (1,2,3,4,6) and sp.goods_type != '05' and bo.real_money > 0
|
|
<if test="orderType != null and orderType!= ''">
|
|
<if test="orderType == 'lsorder' ">
|
|
and (bo.payment_method = '1' or (bo.payment_method = '2' and bo.order_id >= 37867))
|
|
and bo.order_type = 'lsorder'
|
|
</if>
|
|
<if test="orderType == 'order' ">
|
|
and (bo.order_type = 'order'
|
|
or (bo.order_type = 'lsorder' and bo.payment_method = '4')
|
|
or (bo.order_type = 'lsorder' and bo.payment_method = '2' and bo.order_id < 37867))
|
|
</if>
|
|
</if>
|
|
and DATE_FORMAT(bo.create_time,'%Y-%m') = SUBSTR(#{date},1,7)
|
|
group by bo.order_sn
|
|
) 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
|
|
group by t.orderSn
|
|
) q
|
|
left join pay_zfb_order pzo on pzo.relevanceOid = q.orderSn and pzo.trade_no is not null
|
|
) s
|
|
group by payType
|
|
</select>
|
|
<select id="getRefund" 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.refundFee,
|
|
t.refundFee-(select IF(SUM(if(sp2.activity_price<sp2.price,sp2.activity_price,sp2.price)) is NULL,0,SUM(if(sp2.activity_price<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
|
|
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,
|
|
'已退款' orderStatus,bor.fee refundFee,if(bo.remark like '%退%',bo.remark,'') remark
|
|
from buy_order_refund bor
|
|
inner join buy_order bo on bo.order_id = bor.order_id and bo.del_flag = 0
|
|
left join user u on u.id = bo.user_id
|
|
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
|
|
where
|
|
( 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 (bo.payment_method='1' or bo.payment_method='2') and bo.create_time>='2026-05-06 00:00:00') )
|
|
and bo.order_status = '6' and sp.goods_type != '05' and bo.real_money > 0
|
|
<if test="orderType != null and orderType!= ''">
|
|
<if test="orderType == 'lsorder' ">
|
|
and (bo.payment_method = '1' or (bo.payment_method = '2' and bo.order_id >= 37867))
|
|
and bo.order_type = 'lsorder'
|
|
</if>
|
|
<if test="orderType == 'order' ">
|
|
and (bo.order_type = 'order'
|
|
or (bo.order_type = 'lsorder' and bo.payment_method = '4')
|
|
or (bo.order_type = 'lsorder' and bo.payment_method = '2' and bo.order_id < 37867))
|
|
</if>
|
|
</if>
|
|
and DATE_FORMAT(bor.create_time,'%Y-%m') = SUBSTR(#{date},1,7)
|
|
group by bo.order_sn
|
|
) 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
|
|
group by t.orderSn
|
|
) q
|
|
left join pay_zfb_order pzo on pzo.relevanceOid = q.orderSn and pzo.trade_no is not null
|
|
) s
|
|
group by payType
|
|
</select>
|
|
<select id="exportPhysicalBuyOrderInfo" resultType="map">
|
|
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<sp2.price,sp2.activity_price,sp2.price)) is NULL,0,SUM(if(sp2.activity_price<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
|
|
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,
|
|
IF(bo.order_status = 4,'已删除',IF(bo.order_status = 3,'已完成',IF(bo.order_status = 2,'已发货',IF(bo.order_status = 6,'已退款','已付款')))) orderStatus,bo.real_money orderPrice,if(bo.remark like '%退%',bo.remark,'') remark
|
|
from buy_order bo
|
|
left join user u on u.id = bo.user_id
|
|
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
|
|
where
|
|
( 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 (bo.payment_method='1' or bo.payment_method='2') and bo.create_time>='2026-05-06 00:00:00') )
|
|
and bo.order_status in (1,2,3,4,6) and sp.goods_type != '05' and bo.real_money > 0
|
|
<if test="orderType != null and orderType!= ''">
|
|
<if test="orderType == 'lsorder' ">
|
|
and (bo.payment_method = '1' or (bo.payment_method = '2' and bo.order_id >= 37867))
|
|
and bo.order_type = 'lsorder'
|
|
</if>
|
|
<if test="orderType == 'order' ">
|
|
and (bo.order_type = 'order'
|
|
or (bo.order_type = 'lsorder' and bo.payment_method = '4')
|
|
or (bo.order_type = 'lsorder' and bo.payment_method = '2' and bo.order_id < 37867))
|
|
</if>
|
|
</if>
|
|
and DATE_FORMAT(bo.create_time,'%Y-%m') = SUBSTR(#{date},1,7)
|
|
group by bo.order_sn
|
|
) 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
|
|
group by t.orderSn
|
|
) q
|
|
left join pay_zfb_order pzo on pzo.relevanceOid = q.orderSn and pzo.trade_no is not null
|
|
</select>
|
|
<select id="exportPhysicalBuyOrderRefundInfo" resultType="map">
|
|
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<sp2.price,sp2.activity_price,sp2.price)) is NULL,0,SUM(if(sp2.activity_price<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
|
|
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,
|
|
'已退款' orderStatus,bor.fee orderPrice,if(bo.remark like '%退%',bo.remark,'') remark,IFNULL(bor.wx_refund_no,bor.refund_no) as refund_no
|
|
from buy_order_refund bor
|
|
inner join buy_order bo on bo.order_id = bor.order_id and bo.del_flag = 0
|
|
left join user u on u.id = bo.user_id
|
|
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
|
|
where
|
|
( 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 (bo.payment_method='1' or bo.payment_method='2') and bo.create_time>='2026-05-06 00:00:00') )
|
|
and bo.order_status = '6' and sp.goods_type != '05' and bo.real_money > 0
|
|
<if test="orderType != null and orderType!= ''">
|
|
<if test="orderType == 'lsorder' ">
|
|
and (bo.payment_method = '1' or (bo.payment_method = '2' and bo.order_id >= 37867))
|
|
and bo.order_type = 'lsorder'
|
|
</if>
|
|
<if test="orderType == 'order' ">
|
|
and (bo.order_type = 'order'
|
|
or (bo.order_type = 'lsorder' and bo.payment_method = '4')
|
|
or (bo.order_type = 'lsorder' and bo.payment_method = '2' and bo.order_id < 37867))
|
|
</if>
|
|
</if>
|
|
and DATE_FORMAT(bor.create_time,'%Y-%m') = SUBSTR(#{date},1,7)
|
|
group by bo.order_sn
|
|
) 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
|
|
group by t.orderSn
|
|
) q
|
|
left join pay_zfb_order pzo on pzo.relevanceOid = q.orderSn and pzo.trade_no is not null
|
|
</select>
|
|
|
|
|
|
<select id="queryListByOrderIds" resultType="com.peanut.modules.common.entity.BuyOrder">
|
|
select
|
|
*,
|
|
buy_order_detail.order_id,
|
|
buy_order_detail.product_name,
|
|
buy_order_detail.quantity,
|
|
buy_order_detail.product_price,
|
|
buy_order_detail.weight,
|
|
buy_order_detail.remark
|
|
from buy_order
|
|
left join buy_order_detail on buy_order.order_id = buy_order_detail.order_id
|
|
where buy_order.order_id in
|
|
<foreach collection="array" item="id" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
and del_flag = 0
|
|
</select>
|
|
|
|
<select id="orderStatusNum" resultType="com.peanut.modules.common.entity.BuyOrder">
|
|
select *,count(*) as statusNum
|
|
from buy_order
|
|
where
|
|
user_id = #{userId}
|
|
and del_flag = 0
|
|
and order_status in (0,1,2,3)
|
|
group by
|
|
order_status
|
|
|
|
</select>
|
|
|
|
<select id="orderListCount" resultType="int" parameterType="com.peanut.modules.book.vo.request.BuyOrderListRequestVo">
|
|
select count(1) from (
|
|
select b.*
|
|
from buy_order b
|
|
<if test="productName != null and productName!= ''">left join buy_order_product p on b.order_id = p.order_id
|
|
left join
|
|
shop_product s on s.product_id = p.product_id
|
|
</if>
|
|
<where>
|
|
<if test="searchKeyWord != null and searchKeyWord!= ''">
|
|
and (b.order_sn like concat('%',concat(#{searchKeyWord},'%'))
|
|
or b.shipping_user like concat('%',concat(#{searchKeyWord},'%'))
|
|
or b.user_phone like concat('%',concat(#{searchKeyWord},'%')))
|
|
</if>
|
|
<if test="productName != null and productName!= ''">
|
|
and (s.product_name like concat('%',concat(#{productName},'%')))
|
|
</if>
|
|
<if test="orderStatus != null and orderStatus!= ''">
|
|
and b.order_status = #{orderStatus}
|
|
</if>
|
|
<if test="startTime != null">
|
|
and b.create_time >= #{startTime}
|
|
</if>
|
|
<if test="endTime != null">
|
|
and b.create_time <= #{endTime}
|
|
</if>
|
|
and b.order_type = 'order'
|
|
and b.del_flag = 0
|
|
</where>
|
|
<if test="productName != null and productName!= ''">
|
|
group by b.order_id
|
|
</if>
|
|
) t
|
|
</select>
|
|
|
|
<select id="orderList" resultType="com.peanut.modules.common.entity.BuyOrder"
|
|
parameterType="com.peanut.modules.book.vo.request.BuyOrderListRequestVo" resultMap="buyOrderMap">
|
|
select b.*
|
|
from buy_order b
|
|
<if test="productName != null and productName!= ''">
|
|
left join buy_order_product p on b.order_id = p.order_id
|
|
left join shop_product s on s.product_id = p.product_id
|
|
</if>
|
|
<where>
|
|
<if test="searchKeyWord != null and searchKeyWord!= ''">
|
|
and (b.order_sn like concat('%',concat(#{searchKeyWord},'%'))
|
|
or b.shipping_user like concat('%',concat(#{searchKeyWord},'%'))
|
|
or b.user_phone like concat('%',concat(#{searchKeyWord},'%')))
|
|
</if>
|
|
<if test="productName != null and productName!= ''">
|
|
and (s.product_name like concat('%',concat(#{productName},'%')))
|
|
</if>
|
|
<if test="orderStatus != null and orderStatus!= ''">
|
|
and b.order_status = #{orderStatus}
|
|
</if>
|
|
<if test="startTime != null">
|
|
and b.create_time >= #{startTime}
|
|
</if>
|
|
<if test="endTime != null">
|
|
and b.create_time <= #{endTime}
|
|
</if>
|
|
and b.order_type = 'order'
|
|
and b.del_flag = 0
|
|
</where>
|
|
<if test="productName != null and productName!= ''">
|
|
group by b.order_id
|
|
</if>
|
|
order by b.create_time desc
|
|
limit #{index},#{pageSize}
|
|
</select>
|
|
|
|
</mapper> |