交易额+退款+退款+退款笔数+App流水接口、交易额相关接口调整

master
macminiuser 7 years ago
parent d4a251a395
commit 8bacdb61ea

@ -231,3 +231,7 @@ CREATE TABLE `sys_wx_merchant_apply` (
`operator` varchar(50) DEFAULT NULL,
PRIMARY KEY (`merchant_app_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
alter table statistics_customer_order add column refund_orders int(10) DEFAULT NULL COMMENT '' AFTER `orders`;
alter table statistics_customer_order add column refund_amount DECIMAL(20,2) DEFAULT NULL COMMENT '' AFTER `total`;

@ -71,4 +71,5 @@ public interface TransactionAnalysisMapper {
int getCountCustomers(@Param("date") Date date);
JSONObject getClientTransaction(JSONObject params);
}

@ -173,10 +173,10 @@ public class RetailAppServiceImp implements RetailAppService {
}
JSONObject params = appQueryBean.toParams();
setAllClientIds(params, client_id);
JSONObject res = new JSONObject();
params.put("client_id", client_id);
res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params));
res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params));
JSONObject res = transactionAnalysisMapper.getClientTransaction(params);
// res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params));
// res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params));
// res.put("refund_amount", transactionAnalysisMapper.analysisRefundAmount(params));
res.put("not_settled", transactionAnalysisMapper.analysisNotSettled(params));
res.put("old_customers", transactionAnalysisMapper.countOldCustomers(params));
@ -199,10 +199,11 @@ public class RetailAppServiceImp implements RetailAppService {
}
JSONObject params = appQueryBean.toParams();
setAllClientIds(params, client_id);
JSONObject res = new JSONObject();
params.put("client_id", client_id);
res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params));
res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params));
JSONObject res = transactionAnalysisMapper.getClientTransaction(params);
// res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params));
// res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params));
res.put("not_settled", transactionAnalysisMapper.analysisNotSettled(params));
return res;
}
@ -356,7 +357,10 @@ public class RetailAppServiceImp implements RetailAppService {
params.put("dev_id", device.getString("dev_id"));
}
params.put("client_id", client_id);
PageList<JSONObject> orders = orderMapper.listOrdersByClients(params,
// PageList<JSONObject> orders = orderMapper.listOrdersByClients(params,
// new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
PageList<JSONObject> orders = orderMapper.listTransactionsForApp(params,
new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc")));
TimeZoneUtils.switchTimeZone(orders, query.getTimezone(), "create_time", "transaction_time", "confirm_time");
ArrayList<String> date_contains = new ArrayList<>();

@ -77,4 +77,6 @@ public interface OrderMapper {
List<JSONObject> listOrdersByClientsNoPages(JSONObject params);
List<JSONObject> listAnalysisClientCustomer(JSONObject params);
PageList<JSONObject> listTransactionsForApp(JSONObject params, PageBounds pageBounds);
}

@ -39,6 +39,7 @@
<select id="getSumOrdersAndCustomersDaily" resultType="com.alibaba.fastjson.JSONObject">
SELECT sum(s.customers) customers,sum(s.orders) orders,sum(s.new_customers) new_customers,
sum(s.old_customers) old_customers,sum(s.total) total, sum(s.total)/sum(s.customers) single_amount,
ifnull(sum(s.refund_amount),0) refund_amount,ifnull(sum(s.refund_orders),0) refund_orders,
date_format(s.date,'%d/%m/%Y') trade_date
FROM statistics_customer_order s
<where>

@ -607,7 +607,9 @@
COUNT(DISTINCT o.order_id) AS orders,
COUNT(DISTINCT o.customer_id) AS customers,
o.channel AS channel,
ifnull(SUM(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)), 0) AS total,
ifnull(SUM(if(t.transaction_type = 'Credit', t.clearing_amount, 0)), 0) AS total,
ifnull(SUM(if(t.refund_id>0, t.clearing_amount, 0)), 0) AS refund_amount,
SUM(if(t.refund_id>0, 1, 0)) AS refund_orders,
round(SUM(if(t.transaction_type='Credit',t.clearing_amount,0))/COUNT(DISTINCT o.customer_id),2) single_amount
FROM pmt_transactions t
INNER JOIN pmt_orders o ON o.order_id = t.order_id
@ -729,4 +731,28 @@
<if test="client_moniker!=null">and c.client_moniker=#{client_moniker}</if>
<if test="channel!=null">and t.channel=#{channel}</if>
</select>
<select id="getClientTransaction" resultType="com.alibaba.fastjson.JSONObject">
select
IFNULL(sum(if(l.transaction_type='credit',l.clearing_amount,0)),0) trade_amount,
ifnull(sum(if(l.refund_id>0,l.clearing_amount,0)),0) refund_amount,
sum(if(l.transaction_type='Credit',1,0)) trade_count,
sum(if(l.refund_id>0,1,0)) refund_orders,
FROM pmt_transactions l
where l.channel!='Settlement' and t.system_generate=0
<if test="client_ids!=null">
AND l.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 l.client_id=#{client_id}
</if>
<if test="begin!=null">and l.transaction &gt;= #{begin}</if>
<if test="end!=null">and l.transaction &lt; #{end}</if>
<if test="org_id!=null and org_ids==null">and l.org_id=#{org_id}</if>
<if test="org_ids!=null">and l.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if>
</select>
</mapper>

@ -95,6 +95,8 @@
<update id="updateRefundAmount">
<![CDATA[
UPDATE pmt_orders o
LEFT JOIN (
SELECT
@ -113,14 +115,20 @@
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">
@ -150,7 +158,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 +186,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 &gt;= #{from}</if>
<if test="to!=null">and o.create_time &lt; #{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 +276,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,15 +308,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 &gt;= #{from}</if>
<if test="to!=null">and o.create_time &lt; #{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
@ -317,10 +335,14 @@
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 +366,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 +396,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 +408,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 +476,8 @@
</select>
<select id="listOrdersWithNoTransactions" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[
SELECT
o.order_id,
o.channel
@ -457,6 +486,8 @@
SELECT DISTINCT order_id
FROM pmt_transactions
WHERE transaction_type = 'Credit') AND o.status >= 5 AND o.customer_payment_amount > 0
]]>
</select>
@ -483,7 +514,8 @@
<if test="to!=null">and o.create_time &lt; #{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 +546,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 +574,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 &gt;= #{from}</if>
<if test="to!=null">and o.create_time &lt; #{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 +595,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 +622,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 &gt;= #{from}</if>
<if test="to!=null">and o.create_time &lt; #{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>

Loading…
Cancel
Save