财务统计

This commit is contained in:
wuchunlei
2025-09-26 20:37:09 +08:00
parent d5598218d8
commit a1b5e49ee8
33 changed files with 690 additions and 101 deletions

View File

@@ -21,6 +21,102 @@ public class UserCourseBuyUtil {
// userCourseBuyOnload();
// userCourseBuyOnload2();
// userVipUpdate();
// distinctUserCourseBuy();
// addUserCourseBuyLog();
}
public static void addUserCourseBuyLog() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
PreparedStatement addUserCourseBuyLogStatement = fzdsconn.prepareStatement(
"INSERT ignore INTO user_course_buy_log (user_course_buy_id,user_id,type,pay_type,pay_time,order_sn,days,fee) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement statement = fzdsconn.prepareStatement("""
select t.*,ucb.id,ROUND(orderPrice/t.productCount,2) price,ucb.days,ucb.come,ucb.start_time startTime,ucb.end_time endTime
from
(
select bo.order_sn orderSn,bo.create_time createTime,IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝','天医币')) payType,sp.product_name title,
(select count(1) from shop_product_course where del_flag = 0 and product_id = bop.product_id) productCount,
bo.real_money orderPrice,bo.user_id userId,spc.course_id courseId,spc.catalogue_id catalogueId
from buy_order bo
left join buy_order_product bop on bop.order_id = bo.order_id
left join shop_product sp on sp.product_id = bop.product_id
left join shop_product_course spc on spc.product_id = sp.product_id
where bo.del_flag = 0 and bo.order_status = 3 and bo.order_type = 'order' and real_money > 0
and sp.goods_type = '05' and spc.del_flag = 0 and sp.product_id not in (1759,1758,1743,1741,1740,1739,1738,1737,1736,1735,1734,17331732,1731)
and bo.user_id not in (select id from user where tel in ('18812616272','13110039505','18526084267','12222222222','13333333333','14444444444','15555555555','16666666666','17777777777','18888888888','1774455','15533','165965','164964','54321','111','13662001490','15505153873','18834844847','17602219785','19999999999','12299','166933','16855','17602634511','16161616161','17171717171','112112112','21212121211','222222','666666','123123','789789','96','25252525','3434343434','123789','124789','789789','163963','5656','19966','1664455','15151515151','256366','986986','18834844846','18834844849','15611027864','18047689535','18834844848','456456456'))
) t
left join user_course_buy ucb on ucb.user_id = t.userId and ucb.course_id = t.courseId and ucb.catalogue_id = t.catalogueId and ucb.come like CONCAT('%',t.orderSn,'%')
where ucb.del_flag = 0
union
select t.*,ucb.id,t.orderPrice price,ucb.days,ucb.come,ucb.start_time startTime,ucb.end_time endTime
from
(
select bo.order_sn orderSn,bo.create_time createTime,IF(bo.payment_method=1,'微信',IF(bo.payment_method=2,'支付宝','天医币')) payType,bo.remark title,1 productCount,bo.real_money orderPrice,bo.user_id userId,spc.course_id courseId,spc.catalogue_id catalogueId
from buy_order bo
left join shop_product sp on sp.product_id = SUBSTR(bo.remark FROM 1 FOR 4)
left join shop_product_course spc on spc.product_id = sp.product_id
where bo.del_flag = 0 and bo.order_status = 3 and bo.order_type = 'relearn' and real_money > 0
and sp.goods_type = '05' and spc.del_flag = 0 and sp.product_id not in (1759,1758,1743,1741,1740,1739,1738,1737,1736,1735,1734,17331732,1731)
and bo.user_id not in (select id from user where tel in ('18812616272','13110039505','18526084267','12222222222','13333333333','14444444444','15555555555','16666666666','17777777777','18888888888','1774455','15533','165965','164964','54321','111','13662001490','15505153873','18834844847','17602219785','19999999999','12299','166933','16855','17602634511','16161616161','17171717171','112112112','21212121211','222222','666666','123123','789789','96','25252525','3434343434','123789','124789','789789','163963','5656','19966','1664455','15151515151','256366','986986','18834844846','18834844849','15611027864','18047689535','18834844848','456456456'))
) t
left join user_course_buy ucb on ucb.user_id = t.userId and ucb.course_id = t.courseId and ucb.catalogue_id = t.catalogueId and ucb.come like CONCAT('%',t.orderSn,'%')
where ucb.del_flag = 0
order by orderSn
""");
ResultSet resultSet = statement.executeQuery();
while(resultSet.next()){
addUserCourseBuyLogStatement.setString(1,resultSet.getString("id"));
addUserCourseBuyLogStatement.setString(2,resultSet.getString("userId"));
addUserCourseBuyLogStatement.setString(3,"order");
addUserCourseBuyLogStatement.setString(4,resultSet.getString("payType"));
addUserCourseBuyLogStatement.setTimestamp(5,resultSet.getTimestamp("createTime"));
addUserCourseBuyLogStatement.setString(6,resultSet.getString("orderSn"));
addUserCourseBuyLogStatement.setString(7,resultSet.getString("days"));
addUserCourseBuyLogStatement.setString(8,resultSet.getString("price"));
addUserCourseBuyLogStatement.addBatch();
}
addUserCourseBuyLogStatement.executeBatch();
} catch (Exception e) {
System.out.println(e);
}
}
public static void distinctUserCourseBuy() {
try {
Connection fzdsconn = DriverManager.getConnection(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true",
"nuttyreading", "Wu751019!");
PreparedStatement statement = fzdsconn.prepareStatement("""
select user_id,course_id,catalogue_id,count(1) c from user_course_buy where del_flag = 0
group by user_id,course_id,catalogue_id
HAVING c > 1
order by c desc
""");
ResultSet resultSet = statement.executeQuery();
while(resultSet.next()){
System.out.println(resultSet.getString("user_id"));
PreparedStatement ucbStatement = fzdsconn.prepareStatement("select * from user_course_buy where del_flag = 0 " +
"and user_id = "+resultSet.getString("user_id")+" " +
"and course_id = "+resultSet.getString("course_id")+" " +
"and catalogue_id = "+resultSet.getString("catalogue_id")+"");
ResultSet ucbResultSet = ucbStatement.executeQuery();
int i=0;
while(ucbResultSet.next()){
if(i!=0){
PreparedStatement delStatement = fzdsconn.prepareStatement(
"update user_course_buy set del_flag = -1 where id = "+ucbResultSet.getString("id"));
delStatement.executeUpdate();
}
i++;
}
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void userEbookBuy250410() {