2025-07-30 14:54:23 +08:00

66 lines
3.0 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.red.circle.console.infra.database.rds.dao.count.StatisticsDailyPurchaseAmountDAO">
<select id="countInAppPurchaseOrRefund">
INSERT INTO statistics_daily_purchase_amount (platform, area_code, purchase, refund, statistics_time)
SELECT platform,
'DAILY',
SUM(IF(status = 'COMPLETE', quantity, 0)) AS 'purchase', SUM(IF(status = 'REIMBURSE', quantity, 0)) AS 'refund', #{countTime}
FROM (SELECT platform, SUM(unit_price) AS quantity, status
FROM order_purchase_history
WHERE evn = 'PROD'
AND create_time >= #{countTime}
AND create_time &lt;= #{endCountTime}
GROUP BY platform, status) tmp
GROUP BY platform
</select>
<select id="countInAppPurchaseOrRefundRegion">
INSERT INTO statistics_daily_purchase_amount (platform, area_code, purchase, refund, statistics_time)
SELECT platform,
areaCode,
SUM(IF(status = 'COMPLETE', quantity, 0)) AS 'purchase', SUM(IF(status = 'REIMBURSE', quantity, 0)) AS 'refund', #{countTime}
FROM (SELECT oph.platform, oph.status, ue.language AS areaCode, SUM(oph.unit_price) AS quantity
FROM order_purchase_history oph
INNER JOIN user_expand ue ON oph.user_id = ue.user_id
WHERE evn = 'PROD'
AND oph.create_time >= #{countTime}
AND oph.create_time &lt;= #{endCountTime}
AND ue.language IN ('ar', 'tr')
GROUP BY oph.platform, oph.status, ue.language) tmp
GROUP BY platform, areaCode
</select>
<select id="countInAppPurchaseOrRefundOther">
INSERT INTO statistics_daily_purchase_amount (platform, area_code, purchase, refund, statistics_time)
SELECT platform,
'OTHER',
SUM(IF(status = 'COMPLETE', quantity, 0)) AS 'purchase', SUM(IF(status = 'REIMBURSE', quantity, 0)) AS 'refund', #{countTime}
FROM (SELECT oph.platform, oph.status, SUM(oph.unit_price) AS quantity
FROM order_purchase_history oph
INNER JOIN user_expand ue ON oph.user_id = ue.user_id
WHERE evn = 'PROD'
AND oph.create_time >= #{countTime}
AND oph.create_time &lt;= #{endCountTime}
AND ue.language NOT IN ('ar', 'tr')
GROUP BY oph.platform, oph.status, ue.language) tmp
GROUP BY platform
</select>
<select id="countInAppPurchaseOrRefundOffline">
INSERT INTO statistics_daily_purchase_amount (platform, area_code, purchase, refund, statistics_time)
SELECT 'Offline' AS platform,
'DAILY',
IF(quantity IS NULL, 0, quantity) AS 'purchase', 0 AS refund,
#{countTime} AS statistics_time
FROM (SELECT SUM(amount) AS quantity
FROM order_other_recharge
WHERE payment_date_number >= DATE_FORMAT(#{countTime}, '%Y%m%d')
AND payment_date_number &lt;= DATE_FORMAT(#{endCountTime}, '%Y%m%d')) tmp
</select>
</mapper>