Files
TimiServerAPI/src/main/resources/mapper/timi-server/gao/GaoOrderReminderMapper.xml
T
2026-09-22 16:52:18 +08:00

91 lines
3.6 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.imyeyu.api.modules.gao.mapper.GaoOrderReminderMapper">
<sql id="orderReminderSelect">
SELECT
o.`store_id` AS `storeId`,
o.`customer_id` AS `customerId`,
c.`name` AS `customerName`,
o.`id` AS `orderId`,
o.`order_no` AS `orderNo`,
o.`status` AS `orderStatus`,
o.`payment_status` AS `paymentStatus`,
o.`sale_amount` AS `saleAmount`,
o.`pending_paid_amount` AS `pendingPaidAmount`,
o.`paid_amount` AS `paidAmount`,
GREATEST(o.`sale_amount` - o.`paid_amount`, 0) AS `unpaidAmount`,
COALESCE(fr.`pending_receive_count`, 0) AS `pendingReceiveCount`,
COALESCE(fr.`pending_receive_amount`, 0) AS `pendingReceiveAmount`,
COALESCE(ff.`pending_fulfillment_count`, 0) AS `pendingFulfillmentCount`,
COALESCE(ff.`pending_fulfillment_item_count`, 0) AS `pendingFulfillmentItemCount`
</sql>
<sql id="orderReminderJoins">
INNER JOIN `gao_customer` c ON c.`id` = o.`customer_id` AND c.`deleted_at` IS NULL
LEFT JOIN (
SELECT
f.`store_id`,
f.`biz_id`,
COUNT(1) AS `pending_receive_count`,
COALESCE(SUM(f.`amount`), 0) AS `pending_receive_amount`
FROM `gao_fund_record` f
WHERE f.`deleted_at` IS NULL
AND f.`biz_type` = 'SALES_ORDER'
AND f.`operation_type` = 'RECEIVE'
AND f.`status` = 'PENDING'
GROUP BY f.`store_id`, f.`biz_id`
) fr ON fr.`store_id` = o.`store_id` AND fr.`biz_id` = o.`id`
LEFT JOIN (
SELECT
f.`store_id`,
f.`sales_order_id`,
COUNT(DISTINCT f.`id`) AS `pending_fulfillment_count`,
COUNT(fi.`id`) AS `pending_fulfillment_item_count`
FROM `gao_order_fulfillment` f
LEFT JOIN `gao_order_fulfillment_item` fi ON fi.`fulfillment_id` = f.`id`
WHERE f.`status` = 'PENDING'
GROUP BY f.`store_id`, f.`sales_order_id`
) ff ON ff.`store_id` = o.`store_id` AND ff.`sales_order_id` = o.`id`
</sql>
<select id="selectOrderReceiveCustomers" resultType="com.imyeyu.api.modules.gao.vo.GaoOrderReminderCustomer">
<include refid="orderReminderSelect"/>
FROM `gao_sales_order` o
<include refid="orderReminderJoins"/>
WHERE o.`deleted_at` IS NULL
AND o.`status` IN ('ACTIVE', 'FULFILLED')
AND o.`payment_status` IN ('UNPAID', 'PARTIALLY_PAID')
ORDER BY o.`store_id`, c.`name`, o.`customer_id`, o.`purchased_at`, o.`order_no`
</select>
<select id="selectReceiveVerifyCustomers" resultType="com.imyeyu.api.modules.gao.vo.GaoOrderReminderCustomer">
<include refid="orderReminderSelect"/>
FROM `gao_sales_order` o
<include refid="orderReminderJoins"/>
INNER JOIN (
SELECT DISTINCT f.`store_id`, f.`biz_id`
FROM `gao_fund_record` f
WHERE f.`deleted_at` IS NULL
AND f.`biz_type` = 'SALES_ORDER'
AND f.`operation_type` = 'RECEIVE'
AND f.`status` = 'PENDING'
) pendingReceive ON pendingReceive.`store_id` = o.`store_id` AND pendingReceive.`biz_id` = o.`id`
WHERE o.`deleted_at` IS NULL
ORDER BY o.`store_id`, c.`name`, o.`customer_id`, o.`purchased_at`, o.`order_no`
</select>
<select id="selectFulfillmentVerifyCustomers" resultType="com.imyeyu.api.modules.gao.vo.GaoOrderReminderCustomer">
<include refid="orderReminderSelect"/>
FROM `gao_sales_order` o
<include refid="orderReminderJoins"/>
INNER JOIN (
SELECT DISTINCT f.`store_id`, f.`sales_order_id`
FROM `gao_order_fulfillment` f
WHERE f.`status` = 'PENDING'
) pendingFulfillment ON pendingFulfillment.`store_id` = o.`store_id`
AND pendingFulfillment.`sales_order_id` = o.`id`
WHERE o.`deleted_at` IS NULL
ORDER BY o.`store_id`, c.`name`, o.`customer_id`, o.`purchased_at`, o.`order_no`
</select>
</mapper>