diff --git a/src/db/modify.sql b/src/db/modify.sql index 1a26ebc08..b194d6018 100644 --- a/src/db/modify.sql +++ b/src/db/modify.sql @@ -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`; + diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java index d28c2ff4a..67b3206ca 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/core/impls/DashboardServiceImpl.java @@ -53,12 +53,10 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT @Override public JSONObject getCommonAnalysis1(JSONObject params) { - JSONObject res = new JSONObject(); + JSONObject res = transactionAnalysisMapper.getClientTransaction(params); res.put("new_partners", clientAnalysisMapper.countNewClients(params)); res.put("total_partners", clientAnalysisMapper.countClients(params)); res.put("traded_partners", clientAnalysisMapper.countTradedPartners(params)); - res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params)); -// res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params)); // List topOrders = transactionAnalysisMapper.getTopOrders(params, new PageBounds(1, 1, Order.formString("aud_fee.desc"))); // if (!topOrders.isEmpty()) { // res.put("top_amount_order", topOrders.get(0)); @@ -75,7 +73,7 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT // res.put("total_partners", clientAnalysisMapper.countClients(params)); // res.put("traded_partners", clientAnalysisMapper.countTradedPartners(params)); // res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params)); - res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params)); +// res.put("trade_count", transactionAnalysisMapper.getClientTransaction(params).getIntValue("trade_count")); List topOrders = transactionAnalysisMapper.getTopOrders(params, new PageBounds(1, 1, Order.formString("aud_fee.desc"))); if (!topOrders.isEmpty()) { res.put("top_amount_order", topOrders.get(0)); @@ -212,7 +210,10 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT @Override public List getTradeAnalysisInDays(JSONObject params) { - return transactionAnalysisMapper.tradeAnalysisInDays(params); + if (!params.containsKey("client_ids") && !params.containsKey("org_id")) { + params.put("client_id", 0); + } + return customerAndOrdersStatisticsMapper.getSumCustomersAnalysis(params); } @Override @@ -227,9 +228,10 @@ public class DashboardServiceImpl implements DashboardService,DashboardAnalysisT } JSONObject res = new JSONObject(); params.put("client_id", partner.getIntValue("client_id")); - res.put("trade_amount", transactionAnalysisMapper.analysisTotalAmount(params)); - res.put("trade_count", transactionAnalysisMapper.analysisTotalCount(params)); - res.put("refund_amount", transactionAnalysisMapper.analysisRefundAmount(params)); + JSONObject object = transactionAnalysisMapper.getClientTransaction(params); + res.put("trade_amount", object.getBigDecimal("trade_amount")); + res.put("trade_count", object.getIntValue("trade_count")); + res.put("refund_amount", object.getBigDecimal("refund_amount")); res.put("not_settled", transactionAnalysisMapper.analysisNotSettled(params)); res.put("pre_amount", transactionAnalysisMapper.analysisPreAmount(params)); List topOrders = transactionAnalysisMapper.getTopOrders(params, new PageBounds(1, 1, Order.formString("aud_fee.desc"))); diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.java b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.java index 3e83dc242..99b8af194 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/mappers/TransactionAnalysisMapper.java @@ -71,4 +71,5 @@ public interface TransactionAnalysisMapper { int getCountCustomers(@Param("date") Date date); + JSONObject getClientTransaction(JSONObject params); } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java index 2029c8870..9c0ec74d3 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java @@ -24,6 +24,8 @@ public interface RetailAppService { JSONObject listOrders(JSONObject device, AppQueryBean query); + JSONObject listOrdersNew(JSONObject device, AppQueryBean query); + JSONObject listOrdersShareCode(JSONObject device, AppQueryBean query); void updateDevToken(JSONObject device, String devToken); diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java index d216cdea7..c55d4b6a7 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java @@ -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,6 +357,7 @@ public class RetailAppServiceImp implements RetailAppService { params.put("dev_id", device.getString("dev_id")); } params.put("client_id", client_id); + PageList orders = orderMapper.listOrdersByClients(params, new PageBounds(query.getPage(), query.getLimit(), Order.formString("create_time.desc"))); TimeZoneUtils.switchTimeZone(orders, query.getTimezone(), "create_time", "transaction_time", "confirm_time"); @@ -387,6 +389,70 @@ public class RetailAppServiceImp implements RetailAppService { return PageListUtils.buildPageListResult(orders); } + @Override + public JSONObject listOrdersNew(JSONObject device, AppQueryBean query) { + String clientType = device.getString("client_type"); + DeviceRegister register = deviceSupport.findRegister(clientType); + int client_id = device.getIntValue("client_id"); + JSONObject client = clientManager.getClientInfo(client_id); + String timezone = client.getString("timezone"); + if (timezone != null && !timezone.isEmpty()) { + query.setTimezone(timezone); + } + JSONObject params = query.toParams(); + setAllClientIds(params, client_id); + if (register.includeDevId()) { + params.put("dev_id", device.getString("dev_id")); + } + params.put("client_id", client_id); + + PageList 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 date_contains = new ArrayList<>(); + for (JSONObject order : orders) { + String customer_id = order.getString("customer_id"); + if (StringUtils.isEmpty(customer_id)) { + continue; + } + switch (order.getString("channel")) { + case "Alipay": + JSONObject alipayUser = customerRelationAlipayMapper.findCustomerByUserId(customer_id); + order.put("nickname", alipayUser.getString("nickname")); + order.put("headimg", alipayUser.getString("headimg")); + break; + case "Wechat": + JSONObject weUser = customerMapper.findCustomerByOpenId(customer_id); + order.put("nickname", weUser.getString("nickname")); + order.put("headimg", weUser.getString("headimg")); + break; + default: + break; + } + Calendar calendar = (Calendar) order.get("create_time"); + String trade_date = DateFormatUtils.format(calendar, "yyyy-MM-dd"); + String trade_time = DateFormatUtils.format(calendar, "HH:mm:ss"); + order.put("trade_date", trade_date); + order.put("trade_time", trade_time); + if (!date_contains.contains(trade_date)) { + String re_date = trade_date.replaceAll("-", ""); + TradeLogQuery date_query = new TradeLogQuery(); + date_query.setDatefrom(re_date); + date_query.setDateto(re_date); + // date_query.setStatus(OrderStatus.ALL); + if (params.containsKey("client_ids")) { + date_query.setClient_ids((String[]) params.get("client_ids")); + } + JSONObject date_params = date_query.toParams(query.getTimezone()); + date_params.put("client_id", device.getIntValue("client_id")); + JSONObject analysis = orderMapper.analysisOrders(date_params); + order.put("date_total", analysis); + date_contains.add(trade_date); + } + } + return PageListUtils.buildPageListResult(orders); + } + @Override public JSONObject listOrdersShareCode(JSONObject device, AppQueryBean query) { query.setGateway_app("11"); diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java index 770457c89..c5c985f3c 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java @@ -87,6 +87,11 @@ public class RetailAppController { return retailAppService.listOrders(device, query); } + @RequestMapping(value = "/orders_new", method = RequestMethod.GET) + public JSONObject listOrdersNew(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, AppQueryBean query) { + return retailAppService.listOrdersNew(device, query); + } + @RequestMapping(value = "/orders/share_code", method = RequestMethod.GET) public JSONObject listOrdersShareCode(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, AppQueryBean query) { return retailAppService.listOrdersShareCode(device, query); diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java index 3c7f8f001..7c351ef10 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.java @@ -77,4 +77,6 @@ public interface OrderMapper { List listOrdersByClientsNoPages(JSONObject params); List listAnalysisClientCustomer(JSONObject params); + + PageList listTransactionsForApp(JSONObject params, PageBounds pageBounds); } diff --git a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/ClientAnalysisMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/ClientAnalysisMapper.xml index 4f33ecef3..99601e10b 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/ClientAnalysisMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/analysis/mappers/ClientAnalysisMapper.xml @@ -87,7 +87,7 @@ --> - - - + + + + + 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 @@ -629,9 +635,10 @@ #{org_id} GROUP BY date , channel ORDER BY date DESC + + = #{begin} AND @@ -709,6 +718,8 @@ and t.clearing_amount < #{amount_to} + + + + + \ No newline at end of file diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml index 784b43597..6e85a145e 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/OrderMapper.xml @@ -95,6 +95,8 @@ + + @@ -468,6 +501,7 @@ WHERE o.customer_id = #{customer_id} and t.transaction_time >= '2017-11-07' + @@ -514,7 +549,8 @@ 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}) and p.client_moniker=#{search_text} @@ -541,15 +577,19 @@ and p.org_id=#{org_id} and p.org_id in - #{org_id} + #{org_id} + and o.create_time >= #{from} and o.create_time < #{to} and date(o.create_time)=date(#{date}) - and o.status=#{std} + and + o.status=#{std} - and o.channel=#{chan} + and + o.channel=#{chan} + GROUP BY o.order_id,t.refund_id @@ -558,24 +598,24 @@ + + diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml index 8614b539a..7c6869c44 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml @@ -158,6 +158,7 @@ FROM pmt_transactions WHERE clearing_status = 0 AND client_id = #{client_id} + + SELECT sum(if(t.transaction_type = 'Credit', t.clearing_amount, -t.clearing_amount)) diff --git a/src/main/ui/static/dashboard/dashboard.js b/src/main/ui/static/dashboard/dashboard.js index e00797903..7e46e827b 100644 --- a/src/main/ui/static/dashboard/dashboard.js +++ b/src/main/ui/static/dashboard/dashboard.js @@ -128,6 +128,8 @@ define(['angular', 'uiRouter', 'uiBootstrap', 'angularEcharts'], function (angul $scope.analysis.total_partners = resp.data.total_partners; $scope.analysis.traded_partners = resp.data.traded_partners; $scope.analysis.trade_amount = resp.data.trade_amount; + $scope.analysis.trade_count = resp.data.trade_count; + // $scope.analysis.top_amount_order = resp.data.top_amount_order; // $scope.analysis.trade_count = resp.data.trade_count; // $scope.analysis.total_customers = resp.data.total_customers; @@ -140,7 +142,7 @@ define(['angular', 'uiRouter', 'uiBootstrap', 'angularEcharts'], function (angul // $scope.analysis.traded_partners = resp.data.traded_partners; // $scope.analysis.trade_amount = resp.data.trade_amount; $scope.analysis.top_amount_order = resp.data.top_amount_order; - $scope.analysis.trade_count = resp.data.trade_count; + // $scope.analysis.trade_count = resp.data.trade_count; $scope.analysis.total_customers = resp.data.total_customers; $scope.analysis.new_customers = resp.data.total_customers - resp.data.old_customers; $scope.analysis.old_customers = resp.data.old_customers; @@ -444,15 +446,21 @@ define(['angular', 'uiRouter', 'uiBootstrap', 'angularEcharts'], function (angul type: 'category', boundaryGap: false }, - key: 'date_str' + key: 'trade_date' }, series: [ { basic: {type: 'line', label: {normal: {show: true}}, showAllSymbols: true}, - column: {key: 'aud_fee'} + column: {key: 'total'} } ] }; + params.end = new Date(); + var day = new Date(); + day.setDate(day.getDate() - 7); + params.begin = day; + params.begin = $filter('date')(params.begin, 'yyyyMMdd'); + params.end = $filter('date')(params.end, 'yyyyMMdd'); $http.get('/dashboard/system/fee_analysis', {params: params}).then(function (resp) { $scope.analysis.trade_line = chartParser.parse(analysisConfig, resp.data); })