@ -95,6 +95,8 @@
<update id= "updateRefundAmount" >
< ![CDATA[
UPDATE pmt_orders o
LEFT JOIN (
SELECT
@ -113,16 +115,23 @@
THEN 7
END
WHERE o.order_id = #{order_id}
]]>
</update>
<update id= "updateOrderCreationError" >
< ![CDATA[
UPDATE pmt_orders
SET status = #{status}, error_code = #{error_code}, error_message = #{error_message}
WHERE order_id = #{order_id} AND status < = #{status}
]]>
</update>
<select id= "listOrders" resultType= "com.alibaba.fastjson.JSONObject" >
<if test= "bd_user!=null" >
SELECT temp.* FROM (
@ -150,7 +159,8 @@
<bind name= "name_pattern" value= "'%'+search_text+'%'" />
<if test= "text_type=='all'" >
and (p.client_moniker=#{search_text} or p.short_name like #{name_pattern} or o.order_detail like
#{name_pattern} or t.system_transaction_id =#{search_text} or o.channel = #{search_text} or t.order_id =#{search_text})
#{name_pattern} or t.system_transaction_id =#{search_text} or o.channel = #{search_text} or
t.order_id =#{search_text})
</if>
<if test= "text_type=='client_moniker'" >
and p.client_moniker=#{search_text}
@ -177,16 +187,20 @@
</if>
<if test= "org_id!=null and org_ids==null" > and p.org_id=#{org_id}</if>
<if test= "org_ids!=null" > and p.org_id in
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach> </if>
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach>
</if>
<if test= "from!=null" > and o.create_time > = #{from}</if>
<if test= "to!=null" > and o.create_time < #{to}</if>
<if test= "date!=null" > and date(o.create_time)=date(#{date})</if>
<if test= "dev_id!=null" > and o.dev_id=#{dev_id}</if>
<if test= "status!=null" >
and <foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
and
<foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
</if>
<if test= "channel!=null" >
and <foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}</foreach>
and
<foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}
</foreach>
</if>
<if test= "bd_group!=null" > and p.client_id in
(SELECT b.client_id FROM sys_client_bd b
@ -263,7 +277,8 @@
<bind name= "name_pattern" value= "'%'+search_text+'%'" />
<if test= "text_type=='all'" >
and (p.client_moniker=#{search_text} or p.short_name like #{name_pattern} or o.order_detail like
#{name_pattern} or t.system_transaction_id=#{search_text} or o.channel = #{search_text} or t.order_id = #{search_text}
#{name_pattern} or t.system_transaction_id=#{search_text} or o.channel = #{search_text} or
t.order_id = #{search_text}
or o.client_order_id = #{search_text})
</if>
<if test= "text_type=='client_moniker'" >
@ -294,33 +309,42 @@
</if>
<if test= "org_id!=null and org_ids==null" > and p.org_id=#{org_id}</if>
<if test= "org_ids!=null" > and p.org_id in
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach> </if>
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach>
</if>
<if test= "from!=null" > and o.create_time > = #{from}</if>
<if test= "to!=null" > and o.create_time < #{to}</if>
<if test= "date!=null" > and date(o.create_time)=date(#{date})</if>
<if test= "status!=null" >
and <foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
and
<foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
</if>
<if test= "channel!=null" >
and <foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}</foreach>
and
<foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}
</foreach>
</if>
</where>
GROUP BY o.order_id,t.refund_id
</select>
<select id= "analysisOrders" resultType= "com.alibaba.fastjson.JSONObject" >
select
count(DISTINCT l.order_id) order_count,
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null ,l.clearing_amount,0)),0) paid_fee,
ifnull(sum(if(l.transaction_type='Credit',l.clearing_amount,0)),0) paid_fee,
ifnull(sum(if(l.refund_id is not null,if(l.transaction_type='Debit',-l.clearing_amount,l.clearing_amount),0)),0)
refund_fee,
ifnull(sum(if(l.refund_id is not null AND l.pre_authorization=1,l.clearing_amount,0)),0)
pre_refund_fee,
count(DISTINCT l.customer_id) customers,
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null and l.currency!='CNY',l.display_amount,0)),0) display_amount,
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null and l.currency!='CNY' and l.pre_authorization=1,l.display_amount,0)),0) pre_display_amount,
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null and l.currency='CNY',l.display_amount,0)),0) cny_display_amount,
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null and l.currency='CNY' and l.pre_authorization=1,l.display_amount,0)),0) pre_cny_display_amount
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null and l.currency!='CNY',l.display_amount,0)),0)
display_amount,
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null and l.currency!='CNY' and
l.pre_authorization=1,l.display_amount,0)),0) pre_display_amount,
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null and l.currency='CNY',l.display_amount,0)),0)
cny_display_amount,
ifnull(sum(if(l.transaction_type='Credit' and l.refund_id is null and l.currency='CNY' and
l.pre_authorization=1,l.display_amount,0)),0) pre_cny_display_amount
from (
<if test= "bd_user!=null" >
SELECT temp.* FROM (
@ -344,7 +368,8 @@
<bind name= "name_pattern" value= "'%'+search_text+'%'" />
<if test= "text_type=='all'" >
and (p.client_moniker=#{search_text} or p.short_name like #{name_pattern} or o.order_detail like
#{name_pattern} or t.system_transaction_id=#{search_text} or o.channel = #{search_text} or t.order_id = #{search_text}
#{name_pattern} or t.system_transaction_id=#{search_text} or o.channel = #{search_text} or
t.order_id = #{search_text}
or o.client_order_id = #{search_text})
</if>
<if test= "text_type=='client_moniker'" >
@ -373,7 +398,8 @@
</if>
</if>
<if test= "org_ids!=null" > and p.org_id in
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach> </if>
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach>
</if>
<if test= "order_id!=null" > and o.order_id=#{order_id}</if>
<if test= "trade_type!=null" > and o.gateway in
<foreach collection= "trade_type" item= "gateway" open= "(" close= ")" separator= "," > #{gateway}</foreach>
@ -384,10 +410,13 @@
<if test= "date!=null" > and date(o.create_time)=date(#{date})</if>
<if test= "dev_id!=null" > and o.dev_id=#{dev_id}</if>
<if test= "status!=null" >
and <foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
and
<foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
</if>
<if test= "channel!=null" >
and <foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}</foreach>
and
<foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}
</foreach>
</if>
<if test= "bd_group!=null" > and p.client_id in
(SELECT b.client_id FROM sys_client_bd b
@ -449,6 +478,8 @@
</select>
<select id= "listOrdersWithNoTransactions" resultType= "com.alibaba.fastjson.JSONObject" >
< ![CDATA[
SELECT
o.order_id,
o.channel
@ -457,6 +488,8 @@
SELECT DISTINCT order_id
FROM pmt_transactions
WHERE transaction_type = 'Credit') AND o.status >= 5 AND o.customer_payment_amount > 0
]]>
</select>
@ -468,6 +501,7 @@
WHERE o.customer_id = #{customer_id} and t.transaction_time > = '2017-11-07'
</select>
<select id= "listOrderByCustomer" resultType= "com.alibaba.fastjson.JSONObject" >
SELECT o.*,c.short_name,c.client_moniker FROM pmt_orders o
LEFT JOIN sys_clients c on c.client_id = o.client_id
@ -483,7 +517,8 @@
<if test= "to!=null" > and o.create_time < #{to}</if>
<if test= "org_id!=null and org_ids==null" > and c.org_id=#{org_id}</if>
<if test= "org_ids!=null" > and c.org_id in
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach> </if>
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach>
</if>
</where>
</select>
@ -514,7 +549,8 @@
<bind name= "name_pattern" value= "'%'+search_text+'%'" />
<if test= "text_type=='all'" >
and (p.client_moniker=#{search_text} or p.short_name like #{name_pattern} or o.order_detail like
#{name_pattern} or t.system_transaction_id=#{search_text} or o.channel = #{search_text} or t.order_id = #{search_text})
#{name_pattern} or t.system_transaction_id=#{search_text} or o.channel = #{search_text} or
t.order_id = #{search_text})
</if>
<if test= "text_type=='client_moniker'" >
and p.client_moniker=#{search_text}
@ -541,15 +577,19 @@
</if>
<if test= "org_id!=null and org_ids==null" > and p.org_id=#{org_id}</if>
<if test= "org_ids!=null" > and p.org_id in
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach> </if>
<foreach collection= "org_ids" item= "org_id" open= "(" close= ")" separator= "," > #{org_id}</foreach>
</if>
<if test= "from!=null" > and o.create_time > = #{from}</if>
<if test= "to!=null" > and o.create_time < #{to}</if>
<if test= "date!=null" > and date(o.create_time)=date(#{date})</if>
<if test= "status!=null" >
and <foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
and
<foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
</if>
<if test= "channel!=null" >
and <foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}</foreach>
and
<foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}
</foreach>
</if>
</where>
GROUP BY o.order_id,t.refund_id
@ -558,24 +598,24 @@
<select id= "listAnalysisClientCustomer" resultType= "com.alibaba.fastjson.JSONObject" >
SELECT
count(*) payment_times ,
sum(customer_payment_amount) total_amount,
o.client_id client_id,
o.customer_id customer_id,
o.channel channel,
max( o.confirm_time) confirm_time
SELECT
count(*) payment_times ,
sum(customer_payment_amount) total_amount,
o.client_id client_id,
o.customer_id customer_id,
o.channel channel,
max( o.confirm_time) confirm_time
from pmt_orders o
where o.customer_id is not null and o.channel is not null
and client_id = #{client_id}
<if test= "confirm_time" >
and o.confirm_time > #{confirm_time}
</if>
<if test= "include_success_status!=null" >
and o.status >#{include_success_status}
</if>
group by o.customer_id
from pmt_orders o
where o.customer_id is not null and o.channel is not null
and client_id = #{client_id}
<if test= "confirm_time" >
and o.confirm_time > #{confirm_time}
</if>
<if test= "include_success_status!=null" >
and o.status >#{include_success_status}
</if>
group by o.customer_id
</select>
<select id= "listPaid" resultType= "com.alibaba.fastjson.JSONObject" >
SELECT * FROM pmt_orders
@ -585,7 +625,63 @@
and client_id = #{client_id}
</if>
<if test= "channels != null" >
and channel IN <foreach collection= "channels" item= "channel" open= "(" close= ")" separator= "," > #{channel}</foreach>
and channel IN
<foreach collection= "channels" item= "channel" open= "(" close= ")" separator= "," > #{channel}</foreach>
</if>
</where>
</select>
<select id= "listTransactionsForApp" resultType= "com.alibaba.fastjson.JSONObject" >
select
o.order_id,
o.client_id,
o.display_amount,
o.customer_payment_amount,
o.coupon_payment_amount,
o.currency,
o.create_time,
o.confirm_time,
o.status,
o.gateway,
o.channel,
o.pre_authorization,
o.refund_amount refund_fee,
o.customer_id,
t.clearing_amount,
t.refund_id,
t.transaction_time,
t.transaction_type,
t.transaction_id,
t.exchange_rate,
t.clearing_status,
t.settle_amount
from pmt_orders o
left join pmt_transactions t on t.order_id=o.order_id and t.channel!='Settlement' and t.system_generate=0
<where >
<if test= "client_ids!=null" >
AND o.client_id IN
<foreach collection= "client_ids" open= "(" close= ")" separator= "," item= "client_id" >
#{client_id}
</foreach>
</if>
<if test= "client_ids==null and client_id !=null" >
and o.client_id=#{client_id}
</if>
<if test= "from!=null" > and o.create_time > = #{from}</if>
<if test= "to!=null" > and o.create_time < #{to}</if>
<if test= "date!=null" > and date(o.create_time)=date(#{date})
</if>
<if test= "trade_type!=null" > and o.gateway in
<foreach collection= "trade_type" item= "gateway" open= "(" close= ")" separator= "," > #{gateway}</foreach>
</if>
<if test= "status!=null" >
and
<foreach collection= "status" item= "std" open= "(" close= ")" separator= " or " > o.status=#{std}</foreach>
</if>
<if test= "channel!=null" >
and
<foreach collection= "channel" item= "chan" open= "(" close= ")" separator= " or " > o.channel=#{chan}
</foreach>
</if>
</where>
</select>