diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java index 0ecdc89..da34b0e 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java @@ -2329,13 +2329,65 @@ public class OrderStatService { cidsql = " c.id in(" + StrKit.join(ids, ",") + ") or "; } + List customer_pre_list_params = new ArrayList<>(); + customer_pre_list_params.add(tm); + customer_pre_list_params.add(tm); + customer_pre_list_params.add(tm); + customer_pre_list_params.add(tm); + customer_pre_list_params.add(tm); + + String preCustomerSurplusSql = "select \n" + + " t.customer_id,\n" + + " c.`name`,\n" + + " IFNULL(a.total_price, 0) total_price,\n" + + " b.amount,\n" + + " b.refund_amount,\n" + + " ifnull(p.presell_amount,0) presell_amount,\n" + + " b.amount - ifnull(a.total_price,0) - b.refund_amount - ifnull(p.presell_amount,0) then_surplus\n" + + " from prepay_customer t\n" + + " left join customer c on c.id = t.customer_id\n" + + " left join (\n" + + " select t.customer_id, sum(t.total_price) total_price\n" + + " from order_temp t\n" + + " where t.customer_id is not null\n" + + " and t.create_time <= ?\n" + + " and t.state = 5\n" + + " and t.sale_type = 0\n" + + " group by t.customer_id\n" + + " ) a on a.customer_id = t.customer_id\n" + + " left join(\n" + + " select a.customer_id, a.amount, ifnull(b.amount, 0) refund_amount\n" + + " from(\n" + + " select t.customer_id, sum(t.amount) amount\n" + + " from prepay_detail t\n" + + " where t.state= 2\n" + + " and t.verify_time <= ?\n" + + " group by t.customer_id\n" + + " ) a\n" + + " left join(\n" + + " select t.customer_id, sum(t.amount) amount from refund_detail t\n" + + " left join (\n" + + " select max(t.change_time) confirm_time, t.refund_detail_id \n" + + " from refund_detail_state_history t\n" + + " where t.state = 3\n" + + " group by t.refund_detail_id\n" + + " ) a on t.id = a.refund_detail_id\n" + + " where t.state = 3\n" + + " and a.confirm_time <= ?\n" + + " group by t.customer_id\n" + + " ) b on b.customer_id= a.customer_id\n" + + " ) b on b.customer_id= t.customer_id\n" + + " left join (select customer_id, ifnull(sum(presell_amount), 0) presell_amount from presell_order where del = 0 group by customer_id) p\n" + + " on p.customer_id = t.customer_id\n" + + " order by t.customer_id"; + List customer_pre_list = Db.find("select\n" + " c.id customer_id,\n" + " tp.id customer_type_id,\n" + " tp.name customer_type_name,\n" + " c.name customer_name,\n" + " c.name,\n" + - " ifnull(a.total_amount, 0) prepay_total_amount, \n" + + " ifnull(a.total_amount, 0) + ifnull(g.then_surplus,0) prepay_total_amount, \n" + " ifnull(b.total_amount, 0) refund_total_amount, \n" + " p.surplus prepay_surplus\n" + " from customer c \n" + @@ -2353,6 +2405,7 @@ public class OrderStatService { " ) b on c.id = b.customer_id " + " left join customer_type tp on tp.id = c.customer_type_id\n" + " left join prepay_customer p on p.customer_id = c.id\n" + + " left join (\n" + preCustomerSurplusSql + "\n) g on g.customer_id = c.id\n" + " where " + cidsql + " a.customer_id is not null \n" + // 查询时间段内有购砂、起始时间年内有充值的 " union\n" + " select " + @@ -2363,7 +2416,7 @@ public class OrderStatService { " '零散客户' name, " + " null prepay_total_amount, " + " null refund_total_amount, " + - " null prepay_surplus ", tm, tm); + " null prepay_surplus ", customer_pre_list_params.toArray()); customer_pre_list.sort(new Comparator() { @Override