java-mall/mall-shop/target/classes/mapper/order/ShopOrderBaseMapper.xml
2024-10-26 20:16:13 +08:00

523 lines
21 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.suisung.mall.shop.order.mapper.ShopOrderBaseMapper">
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
order_id
, order_number, order_time, order_payment_amount, currency_id, currency_symbol_left, store_id, store_name,
buyer_user_id, buyer_user_name, order_state_id, easy_pay_id
</sql>
<select id="getList" resultType="java.util.Map">
SELECT a.order_id,
a.order_time,
c.order_is_transfer,
c.payment_type_id,
c.activity_type_id,
c.order_is_review,
c.order_finance_review,
c.order_is_out,
c.order_is_shipped,
c.order_is_cb_sync,
c.order_deal_time,
c.order_is_paid,
c.order_is_received,
c.order_express_print,
a.order_payment_amount,
b.order_message,
b.order_shipping_fee_amount,
b.order_commission_fee,
b.order_commission_fee_refund,
b.order_refund_amount,
b.order_return_status,
b.order_refund_status,
d.delivery_time_text,
a.store_id,
a.store_name,
a.buyer_user_id,
a.buyer_user_name,
a.order_state_id,
e.da_address
FROM shop_order_base a
LEFT JOIN shop_order_data b ON a.order_id = b.order_id
LEFT JOIN shop_order_info c ON a.order_id = c.order_id
LEFT JOIN shop_base_delivery_time d ON b.delivery_time_id = d.delivery_time_id
LEFT JOIN shop_order_delivery_address e ON a.order_id = e.order_id
<where>
<if test="map.order_id != null">
a.order_id like concat('%', #{map.order_id}, '%')
</if>
<if test="map.order_title != null and map.order_title !=''">
AND c.order_title like concat('%', #{map.order_title}, '%')
</if>
<if test="map.order_time !=null">
<![CDATA[ AND DATE_FORMAT(a.order_time, '%Y-%m-%d') = DATE_FORMAT(#{map.order_time}, '%Y-%m-%d') ]]>
</if>
<if test="map.buyer_user_id != null">
AND a.buyer_user_id = #{map.buyer_user_id}
</if>
<if test="map.store_is_selfsupport != null">
AND c.store_is_selfsupport = #{map.store_is_selfsupport}
</if>
<if test="map.order_state_id != null">
AND c.order_state_id = #{map.order_state_id}
</if>
<if test="map.store_id != null">
AND a.store_id = #{map.store_id}
</if>
</where>
order by a.order_time ASC
</select>
<select id="statisticState" resultType="java.util.Map">
select COALESCE(order_state_id, 'total') state, count(*) count
from shop_order_base
group by order_state_id
WITH ROLLUP
</select>
<select id="statisticStateSeller" resultType="java.util.Map">
select COALESCE(order_state_id, 'total') state, count(*) count
from shop_order_info
<where>
<if test="store_id!=null">
AND store_id = #{store_id}
</if>
<if test="chain_id!=null">
AND chain_id = #{chain_id}
</if>
<if test="subsite_id!=null">
AND subsite_id = #{subsite_id}
</if>
</where>
group by order_state_id
WITH ROLLUP
</select>
<select id="getPaymentTimeline" resultType="java.util.Map">
SELECT count(*),
order_year,
order_month,
order_day,
sum(order_payment_amount) AS num
FROM shop_order_info
LEFT JOIN shop_order_base ON shop_order_info.order_id = shop_order_base.order_id
<where>
<if test="queryParams.start_time!=null">
shop_order_info.order_time>#{queryParams.start_time}
</if>
<if test="queryParams.store_id!=null">
and shop_order_info.store_id=#{queryParams.store_id}
</if>
<if test="queryParams.chain_id!=null">
and shop_order_info.chain_id=#{queryParams.chain_id}
</if>
<if test="queryParams.subsite_id!=null">
and shop_order_info.subsite_id=#{queryParams.subsite_id}
</if>
<if test="queryParams.order_is_paid!=null">
and shop_order_info.order_is_paid=#{queryParams.order_is_paid}
</if>
</where>
GROUP BY order_year, order_month, order_day
</select>
<select id="statisticCountSeller" resultType="java.util.Map">
SELECT t1.curr_date,
ifnull(t2.effective_count, 0) AS effective_count,
ifnull(t3.cancel_count, 0) AS cancel_count
FROM (
SELECT @num := @num + 1 AS num,
date_format( date_add( #{end}, INTERVAL - @num DAY ), '%m/%d' ) AS curr_date
FROM account_base_config, ( SELECT @num := -1 ) t
WHERE @num + 1 &lt;= ( #{days} - 1)) t1
LEFT JOIN (
SELECT date_format(FROM_UNIXTIME( order_time / 1000 ) , '%m/%d') AS curr_date,
count(order_id) AS effective_count
FROM shop_order_info
<where>
order_state_id != '2070'
<if test="store_id!=null">
and store_id=#{store_id}
</if>
<if test="chain_id!=null">
and chain_id=#{chain_id}
</if>
<if test="subsite_id!=null">
and subsite_id=#{subsite_id}
</if>
GROUP BY date_format(FROM_UNIXTIME( order_time / 1000 ), '%m/%d')
</where>
) t2
ON t1.curr_date = t2.curr_date
LEFT JOIN (SELECT date_format(FROM_UNIXTIME( order_time / 1000 ) , '%m/%d') AS curr_date2, count(order_id) AS
cancel_count
FROM shop_order_info
<where>
order_state_id = '2070'
<if test="store_id!=null">
and store_id=#{store_id}
</if>
<if test="chain_id!=null">
and chain_id=#{chain_id}
</if>
GROUP BY date_format(FROM_UNIXTIME( order_time / 1000 ), '%m/%d')
</where>
) t3
ON t1.curr_date = t3.curr_date2
ORDER BY num desc
</select>
<select id="statisticCount" resultType="java.util.Map">
SELECT t1.curr_date,
ifnull(t2.effective_count, 0) AS effective_count,
ifnull(t3.cancel_count, 0) AS cancel_count
FROM (
SELECT @num := @num + 1 AS num,date_format( date_add( #{end}, INTERVAL - @num DAY ), '%m/%d' ) AS curr_date
FROM account_base_config, ( SELECT @num := -1 ) t
WHERE @num + 1 &lt;= ( #{days} - 1)) t1
LEFT JOIN (SELECT date_format(order_time, '%m/%d') AS curr_date, count(order_id) AS effective_count
FROM shop_order_base
where order_state_id != '2070'
GROUP BY date_format(order_time, '%m/%d')
) t2
ON t1.curr_date = t2.curr_date
LEFT JOIN (SELECT date_format(order_time, '%m/%d') AS curr_date2, count(order_id) AS cancel_count
FROM shop_order_base
where order_state_id = '2070'
GROUP BY date_format(order_time, '%m/%d')
) t3
ON t1.curr_date = t3.curr_date2
ORDER BY num desc
</select>
<select id="statisticAmount" resultType="java.util.Map">
SELECT t1.curr_date,
ifnull(t2.amount, 0) AS amount
FROM (
SELECT @num := @num + 1 AS num,date_format( date_add( #{end}, INTERVAL - @num DAY ), '%m/%d' ) AS curr_date
FROM account_base_config, ( SELECT @num := -1 ) t
WHERE @num + 1 &lt;= ( #{days} - 1)) t1
LEFT JOIN (SELECT date_format(shop_order_base.order_time, '%m/%d') AS curr_date, sum(order_payment_amount) AS
amount
FROM shop_order_base LEFT JOIN shop_order_info ON shop_order_base.order_id = shop_order_info.order_id
<where>
shop_order_info.order_is_paid = 3013
<if test="store_id!=null">
AND shop_order_base.store_id=#{store_id}
</if>
<if test="chain_id!=null">
AND shop_order_info.chain_id=#{chain_id}
</if>
<if test="subsite_id!=null">
AND shop_order_info.subsite_id=#{subsite_id}
</if>
</where>
GROUP BY date_format(shop_order_base.order_time, '%m/%d')) t2
ON t1.curr_date = t2.curr_date
ORDER BY num desc
</select>
<select id="getCustomerDate" resultType="java.util.Map">
SELECT t1.curr_date,
ifnull(t2.num, 0) AS num
FROM (
SELECT @num := @num + 1 AS num,date_format( date_add( #{end}, INTERVAL - @num DAY ), '%m/%d' ) AS curr_date
FROM account_base_config, ( SELECT @num := - 1 ) t
WHERE @num + 1 &lt;= ( #{days} - 1 )) t1
LEFT JOIN (SELECT date_format( FROM_UNIXTIME(left(order_time,10)), '%m/%d' ) AS curr_date,
count( DISTINCT(buyer_user_id) ) AS num
FROM
shop_order_info
<where>
<if test="store_id!=null">
shop_order_info.store_id=#{store_id}
</if>
<if test="subsite_id!=null">
shop_order_info.subsite_id=#{subsite_id}
</if>
</where>
GROUP BY
date_format( FROM_UNIXTIME(left(order_time,10)), '%m/%d' )) t2 ON t1.curr_date = t2.curr_date
ORDER BY t1.curr_date
</select>
<select id="getOrderNumTimeline" resultType="java.util.Map">
SELECT
count(*) AS num,
order_year,
order_month,
order_day
FROM
shop_order_info
<where>
<if test="queryParams.order_state_id!=null">
shop_order_info.order_state_id!=#{queryParams.order_state_id}
</if>
<if test="queryParams.chain_id!=null">
and shop_order_info.chain_id=#{queryParams.chain_id}
</if>
<if test="queryParams.subsite_id!=null">
and shop_order_info.subsite_id=#{queryParams.subsite_id}
</if>
<if test="queryParams.order_time!=null">
and shop_order_info.order_time &gt; #{queryParams.order_time}
</if>
</where>
GROUP BY
order_year,
order_month,
order_day
</select>
<select id="getCustomerTimeline" resultType="java.util.Map">
SELECT
count(*) AS num,
order_year,
order_month,
order_day
FROM
(
SELECT
count(*) AS num,
order_year,
order_month,
order_day,
buyer_user_id
FROM
shop_order_info
WHERE
shop_order_info.order_time > #{queryParams.order_time}
<if test="queryParams.store_id!=null">
AND shop_order_info.store_id=#{queryParams.store_id}
</if>
<if test="queryParams.chain_id!=null">
AND shop_order_info.chain_id=#{queryParams.chain_id}
</if>
<if test="queryParams.subsite_id!=null">
AND shop_order_info.subsite_id=#{queryParams.subsite_id}
</if>
GROUP BY order_year, order_month, order_day, buyer_user_id
) temp
GROUP BY order_year, order_month, order_day
</select>
<select id="getReturnOrder" resultType="java.util.Map">
SELECT shop_order_info.order_id,
shop_order_return.return_refund_amount,
shop_order_return.return_state_id,
shop_order_return.return_id,
shop_order_return.return_refund_amount,
shop_order_return.return_commision_fee
FROM shop_order_return
LEFT JOIN shop_order_info ON shop_order_info.order_id = shop_order_return.order_id
<where>
<if test="return_where.store_id!=null">
and shop_order_return.store_id=#{return_where.store_id}
</if>
<if test="return_where.return_is_settlemented!=null">
and shop_order_return.return_is_settlemented=#{return_where.return_is_settlemented}
</if>
<if test="return_where.return_state_id!=null">
and shop_order_return.return_state_id in
<foreach collection="return_where.return_state_id" item="id" index="index" open="(" close=")"
separator=",">
#{id}
</foreach>
</if>
<if test="return_where.order_state_id!=null">
and shop_order_info.order_state_id=#{return_where.order_state_id}
</if>
<if test="return_where.order_is_paid!=null">
and shop_order_info.order_is_paid=#{return_where.order_is_paid}
</if>
<if test="return_where.order_deal_time!=null">
and shop_order_info.order_deal_time &lt; #{return_where.order_deal_time}
</if>
</where>
</select>
<select id="getOrderItemLists" resultType="java.util.Map">
SELECT
shop_order_base.order_id,
shop_order_item.order_item_id,
shop_order_base.buyer_user_id,
shop_order_base.buyer_user_name,
shop_product_base.product_name,
shop_base_product_unit.unit_name,
shop_order_item.item_id,
shop_order_item.item_name,
shop_product_item.item_number,
shop_base_product_category.category_name,
shop_order_item.order_item_unit_price,
shop_order_item.order_item_quantity,
shop_order_item.order_item_payment_amount,
shop_order_item.order_item_amount,
shop_order_item.order_item_discount_amount,
shop_order_item.item_channel_type,
case shop_order_info.order_is_paid
when 3010 then '未付款'
when 3011 then '付款待审核'
when 3012 then '部分付款'
when 3013 then '已付款'
else '未知'
end as order_is_paid,
pay_consume_deposit.deposit_trade_no,
if(pay_consume_trade_combine.ctc_id IS NOT NULL, pay_consume_trade_combine.ctc_id, shop_order_base.order_id) as
consume_trade_id,
shop_order_base.order_payment_amount,
shop_order_base.order_time,
shop_order_data.order_shipping_fee,
shop_order_item.order_item_commission_rate,
shop_order_item.order_item_commission_fee,
shop_order_item.order_item_return_agree_amount,
shop_order_item.order_item_commission_fee_refund,
shop_order_return.payment_channel_id,
case shop_order_return.payment_channel_id
when 'money' then '余额'
when 'alipay' then '支付宝'
when 'wx_native' then '微信'
else '未知'
end as payment_channel_name,
shop_order_return.return_refund_amount as refund_shipping_fee,
shop_order_return.return_id,
shop_order_return.return_finish_time,
case shop_order_return.return_channel_flag
when 0 then '待退'
when 1 then '已退'
when 2 then '异常'
else '未知'
end as return_channel_flag,
case shop_order_return.return_channel_code
when 'money' then '余额'
when 'alipay' then '支付宝'
when 'wx_native' then '微信'
else '未知'
end as return_channel_code,
shop_order_info.order_state_id,
shop_order_info.order_deal_time,
shop_product_analytics.product_sale_num,
case shop_order_info.order_state_id
when 2010 then '待付款'
when 2016 then '已经付款'
when 2011 then '待订单审核'
when 2013 then '待财务审核'
when 2020 then '待配货'
when 2030 then '待发货'
when 2040 then '已发货'
when 2050 then '已签收'
when 2060 then '已完成'
when 2070 then '已取消'
when 2080 then '自提'
when 2090 then '异常订单'
when 2091 then '退回订单'
else '未知'
end as order_state_name,
shop_order_data.order_message,
shop_order_data.order_discount_amount,
shop_order_delivery_address.da_name,
shop_order_delivery_address.da_mobile,
shop_order_delivery_address.da_province,
shop_order_delivery_address.da_city,
shop_order_delivery_address.da_county,
shop_order_delivery_address.da_address,
FROM_UNIXTIME(shop_order_info.order_time) order_time,
shop_order_info.payment_time,
shop_order_base.store_id,
shop_order_base.store_name,
shop_order_invoice.order_invoice_id,
shop_order_invoice.invoice_type,
shop_order_invoice.invoice_kind,
shop_purchase_invoice.supply_user_name,
case shop_order_info.payment_type_id
when 1301 then '货到付款'
when 1302 then '在线支付'
when 1303 then '白条支付'
when 1304 then '现金支付'
when 1305 then '线下支付'
else '未知'
end as payment_type_id,
FROM_UNIXTIME(shop_order_info.order_deal_time) order_deal_time
FROM
shop_order_info
LEFT JOIN shop_order_base ON shop_order_base.order_id = shop_order_info.order_id
LEFT JOIN shop_order_data ON shop_order_data.order_id = shop_order_info.order_id
LEFT JOIN pay_consume_deposit ON shop_order_info.order_id = pay_consume_deposit.order_id
LEFT JOIN pay_consume_trade_combine ON FIND_IN_SET(shop_order_info.order_id,
pay_consume_trade_combine.order_ids)
LEFT JOIN shop_order_delivery_address ON shop_order_delivery_address.order_id = shop_order_info.order_id
LEFT JOIN shop_order_return ON shop_order_return.order_id = shop_order_info.order_id AND
shop_order_return.return_state_id IN (3110, 3115, 3120, 3125) AND shop_order_return.return_is_shipping_fee = 1
LEFT JOIN shop_order_item ON shop_order_info.order_id = shop_order_item.order_id
LEFT JOIN shop_product_item ON shop_order_item.item_id = shop_product_item.item_id
LEFT JOIN shop_product_base ON shop_product_item.product_id = shop_product_base.product_id
LEFT JOIN shop_base_product_unit ON shop_product_base.unit_id = shop_base_product_unit.unit_id
LEFT JOIN shop_base_product_category ON shop_base_product_category.category_id = shop_product_item.category_id
LEFT JOIN shop_order_invoice ON shop_order_invoice.order_id = shop_order_info.order_id
LEFT JOIN shop_purchase_invoice ON shop_purchase_invoice.order_id = shop_order_info.order_id
LEFT JOIN shop_product_analytics ON shop_product_analytics.product_id = shop_order_item.product_id
<where>
<if test="queryParams.order_state_id!=null">
and shop_order_info.order_state_id=#{queryParams.order_state_id}
</if>
<if test="queryParams.order_title!=null">
and shop_order_info.order_title like concat('%', #{queryParams.order_title}, '%')
</if>
<if test="queryParams.order_id!=null">
and shop_order_info.order_id=#{queryParams.order_id}
</if>
<if test="queryParams.buyer_user_id!=null">
and shop_order_info.buyer_user_id=#{queryParams.buyer_user_id}
</if>
<if test="queryParams.store_is_selfsupport!=null">
and shop_order_info.store_is_selfsupport=#{queryParams.store_is_selfsupport}
</if>
<if test="queryParams.order_year!=null">
and shop_order_info.order_year=#{queryParams.order_year}
</if>
<if test="queryParams.order_month!=null">
and shop_order_info.order_month=#{queryParams.order_month}
</if>
<if test="queryParams.order_day!=null">
and shop_order_info.order_day=#{queryParams.order_day}
</if>
<if test="queryParams.order_is_offline!=null">
and shop_order_info.order_is_offline=#{queryParams.order_is_offline}
</if>
<if test="queryParams.kind_id!=null">
and shop_order_info.kind_id=#{queryParams.kind_id}
</if>
<if test="queryParams.order_ids!=null">
shop_order_info.order_id in
<foreach collection="queryParams.order_ids" item="order_id" separator="," open="(" close=")" index="">
#{order_id}
</foreach>
</if>
</where>
</select>
<!-- 已完成订单总金额-->
<select id="getOrderPaymentAmount" resultType="java.util.Map">
SELECT sum(order_payment_amount) as paymentAmount
FROM shop_order_base LEFT JOIN shop_order_info ON shop_order_base.order_id = shop_order_info.order_id
<where>
<if test="order_state_id!=null ">
and shop_order_base.order_state_id=#{order_state_id}
</if>
<if test="store_id!=null and store_id!= 0">
and shop_order_base.store_id=#{store_id}
</if>
<if test="order_time!=null">
and shop_order_info.order_time>=#{order_time}
</if>
<if test="order_is_paid!=null">
and shop_order_info.order_is_paid=#{order_is_paid}
</if>
<if test="subsite_id!=null and subsite_id!=0">
and shop_order_info.subsite_id=#{subsite_id}
</if>
</where>
</select>
</mapper>