<?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.tcm.training.admin.trade.mapper.PaymentFlowMapper">
|
|
<sql id="PaymentFlowWhere">
|
WHERE f.deleted = 0
|
<if test="flowNo != null and flowNo.trim() != ''">
|
AND f.flow_no LIKE CONCAT('%', #{flowNo}, '%')
|
</if>
|
<if test="businessOrderNo != null and businessOrderNo.trim() != ''">
|
AND f.business_order_no LIKE CONCAT('%', #{businessOrderNo}, '%')
|
</if>
|
<if test="userPhone != null and userPhone.trim() != ''">
|
AND f.user_phone LIKE CONCAT('%', #{userPhone}, '%')
|
</if>
|
<if test="productKeyword != null and productKeyword.trim() != ''">
|
AND f.product_name_snapshot LIKE CONCAT('%', #{productKeyword}, '%')
|
</if>
|
<if test="businessType != null and businessType.trim() != ''">
|
AND f.business_type = #{businessType}
|
</if>
|
<if test="flowType != null and flowType.trim() != ''">
|
AND f.flow_type = #{flowType}
|
</if>
|
<if test="paymentMethod != null and paymentMethod.trim() != ''">
|
AND f.payment_method = #{paymentMethod}
|
</if>
|
<if test="tradeStatus != null and tradeStatus.trim() != ''">
|
AND f.trade_status = #{tradeStatus}
|
</if>
|
<if test="tradeFrom != null">
|
AND f.trade_time <![CDATA[>=]]> #{tradeFrom}
|
</if>
|
<if test="tradeTo != null">
|
AND f.trade_time <![CDATA[<=]]> #{tradeTo}
|
</if>
|
</sql>
|
|
<sql id="PaymentFlowColumns">
|
f.id,
|
f.flow_no AS flowNo,
|
f.business_type AS businessType,
|
f.business_order_id AS businessOrderId,
|
f.business_order_no AS businessOrderNo,
|
f.flow_type AS flowType,
|
f.trade_status AS tradeStatus,
|
f.user_nickname AS userNickname,
|
f.user_phone AS userPhone,
|
f.product_name_snapshot AS productNameSnapshot,
|
f.payment_method AS paymentMethod,
|
f.transaction_amount AS transactionAmount,
|
CASE
|
WHEN f.flow_type = 'REFUND' THEN COALESCE(f.third_party_refund_no, f.third_party_trade_no)
|
ELSE COALESCE(f.third_party_trade_no, f.third_party_refund_no)
|
END AS thirdPartyNo,
|
f.remark AS remark,
|
f.trade_time AS tradeTime
|
</sql>
|
|
<select id="selectPaymentFlowPage" resultType="com.tcm.training.admin.trade.row.PaymentFlowRow">
|
SELECT
|
<include refid="PaymentFlowColumns"/>
|
FROM tcm_payment_flow f
|
<include refid="PaymentFlowWhere"/>
|
ORDER BY f.trade_time DESC, f.id DESC
|
</select>
|
|
<select id="selectPaymentFlowList" resultType="com.tcm.training.admin.trade.row.PaymentFlowRow">
|
SELECT
|
<include refid="PaymentFlowColumns"/>
|
FROM tcm_payment_flow f
|
<include refid="PaymentFlowWhere"/>
|
ORDER BY f.trade_time DESC, f.id DESC
|
</select>
|
|
<select id="selectMissingCoursePaymentRows" resultType="com.tcm.training.admin.trade.row.PaymentFlowSyncRow">
|
SELECT
|
o.id AS sourceId,
|
o.id AS businessOrderId,
|
o.order_no AS businessOrderNo,
|
o.app_user_id AS appUserId,
|
o.user_nickname AS userNickname,
|
o.user_phone AS userPhone,
|
o.product_name_snapshot AS productNameSnapshot,
|
o.payment_method AS paymentMethod,
|
o.order_amount AS transactionAmount,
|
NULL AS remark,
|
o.paid_at AS tradeTime
|
FROM tcm_course_purchase_order o
|
LEFT JOIN tcm_payment_flow f ON f.source_type = 'COURSE_PAYMENT' AND f.source_id = o.id AND f.deleted = 0
|
WHERE o.deleted = 0
|
AND o.paid_at IS NOT NULL
|
AND o.status IN ('PAID', 'REFUNDED')
|
AND f.id IS NULL
|
ORDER BY o.id ASC
|
</select>
|
|
<select id="selectMissingCourseRefundRows" resultType="com.tcm.training.admin.trade.row.PaymentFlowSyncRow">
|
SELECT
|
o.id AS sourceId,
|
o.id AS businessOrderId,
|
o.order_no AS businessOrderNo,
|
o.app_user_id AS appUserId,
|
o.user_nickname AS userNickname,
|
o.user_phone AS userPhone,
|
o.product_name_snapshot AS productNameSnapshot,
|
o.payment_method AS paymentMethod,
|
COALESCE(o.refund_amount, o.order_amount) AS transactionAmount,
|
o.refund_remark AS remark,
|
o.refunded_at AS tradeTime
|
FROM tcm_course_purchase_order o
|
LEFT JOIN tcm_payment_flow f ON f.source_type = 'COURSE_REFUND' AND f.source_id = o.id AND f.deleted = 0
|
WHERE o.deleted = 0
|
AND o.status = 'REFUNDED'
|
AND o.refunded_at IS NOT NULL
|
AND f.id IS NULL
|
ORDER BY o.id ASC
|
</select>
|
|
<select id="selectMissingMemberPaymentRows" resultType="com.tcm.training.admin.trade.row.PaymentFlowSyncRow">
|
SELECT
|
o.id AS sourceId,
|
o.id AS businessOrderId,
|
o.order_no AS businessOrderNo,
|
o.app_user_id AS appUserId,
|
o.user_nickname AS userNickname,
|
o.user_phone AS userPhone,
|
CASE
|
WHEN o.member_type = 'MONTH_CARD' THEN '月卡会员'
|
WHEN o.member_type = 'QUARTER_CARD' THEN '季卡会员'
|
ELSE '会员购买'
|
END AS productNameSnapshot,
|
o.payment_method AS paymentMethod,
|
o.order_amount AS transactionAmount,
|
NULL AS remark,
|
o.paid_at AS tradeTime
|
FROM tcm_member_purchase_order o
|
LEFT JOIN tcm_payment_flow f ON f.source_type = 'MEMBER_PAYMENT' AND f.source_id = o.id AND f.deleted = 0
|
WHERE o.deleted = 0
|
AND o.paid_at IS NOT NULL
|
AND o.status IN ('PAID', 'REFUNDED')
|
AND f.id IS NULL
|
ORDER BY o.id ASC
|
</select>
|
|
<select id="selectMissingMemberRefundRows" resultType="com.tcm.training.admin.trade.row.PaymentFlowSyncRow">
|
SELECT
|
o.id AS sourceId,
|
o.id AS businessOrderId,
|
o.order_no AS businessOrderNo,
|
o.app_user_id AS appUserId,
|
o.user_nickname AS userNickname,
|
o.user_phone AS userPhone,
|
CASE
|
WHEN o.member_type = 'MONTH_CARD' THEN '月卡会员'
|
WHEN o.member_type = 'QUARTER_CARD' THEN '季卡会员'
|
ELSE '会员购买'
|
END AS productNameSnapshot,
|
o.payment_method AS paymentMethod,
|
COALESCE(o.refund_amount, o.order_amount) AS transactionAmount,
|
o.refund_remark AS remark,
|
o.refunded_at AS tradeTime
|
FROM tcm_member_purchase_order o
|
LEFT JOIN tcm_payment_flow f ON f.source_type = 'MEMBER_REFUND' AND f.source_id = o.id AND f.deleted = 0
|
WHERE o.deleted = 0
|
AND o.status = 'REFUNDED'
|
AND o.refunded_at IS NOT NULL
|
AND f.id IS NULL
|
ORDER BY o.id ASC
|
</select>
|
|
</mapper>
|