VIP统计

This commit is contained in:
wuchunlei
2026-01-14 15:16:38 +08:00
parent eb17acc1c3
commit 5c756366c7

View File

@@ -1,20 +1,22 @@
package com.zmzm.finance.common.controller; package com.zmzm.finance.common.controller;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.zmzm.finance.common.entity.Orders; import com.zmzm.finance.common.entity.*;
import com.zmzm.finance.common.entity.Payment;
import com.zmzm.finance.common.entity.User;
import com.zmzm.finance.common.service.IOrdersService; import com.zmzm.finance.common.service.IOrdersService;
import com.zmzm.finance.common.service.IPaymentService; import com.zmzm.finance.common.service.IPaymentService;
import com.zmzm.finance.common.service.IUserService; import com.zmzm.finance.common.service.IUserService;
import com.zmzm.finance.common.service.IUserVipLogService;
import com.zmzm.finance.util.R; import com.zmzm.finance.util.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -29,28 +31,100 @@ public class StatisticsController {
@Autowired @Autowired
private IOrdersService ordersService; private IOrdersService ordersService;
@Autowired @Autowired
private IPaymentService paymentService; private IUserVipLogService userVipLogService;
//天医币统计 //天医币统计
@RequestMapping("/pointStatistics") @RequestMapping("/pointStatistics")
public R pointStatistics(@RequestBody Map<String,Object> params){ public R pointStatistics(@RequestBody Map<String,Object> params){
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
map.put("income",0); //收入
map.putAll(userService.getMap(new MPJLambdaWrapper<User>() List<Map<String,Object>> incomes = ordersService.listMaps(new MPJLambdaWrapper<Orders>()
.selectSum(User::getPoint,"totalPoint"))); .rightJoin(PaymentToOrder.class,PaymentToOrder::getOrderId,Orders::getId)
Map<String,Object> income = ordersService.getMap(new MPJLambdaWrapper<Orders>() .leftJoin(Payment.class,Payment::getId,PaymentToOrder::getPaymentId)
.eq(Orders::getType,0).eq(Orders::getUseFlag,1) .eq(Orders::getType,0)
.apply("DATE_FORMAT(t.order_time, '%Y-%m') = '"+params.get("year")+"-"+params.get("month")+"'") .apply("DATE_FORMAT(t.order_time, '%Y-%m') = '"+params.get("year")+"-"+params.get("month")+"'")
.selectSum(Orders::getFee,"income")); .groupBy(Payment::getType)
if (income!=null){ .select("IF(t2.type=0,'微信',IF(t2.type=1,'支付宝','银行')) type")
map.putAll(income); .selectSum(Orders::getFee,"fee"));
map.put("incomes",incomes);
//消费
List<Map<String,Object>> consumes = ordersService.listMaps(new MPJLambdaWrapper<Orders>()
.eq(Orders::getUseFlag,1).eq(Orders::getPayType,1)
.apply("DATE_FORMAT(t.order_time, '%Y-%m') = '"+params.get("year")+"-"+params.get("month")+"'")
.groupBy(Orders::getType)
.select("IF(type=1,'vip',IF(type=2,'课程',IF(type=3,'实物','培训班'))) type")
.selectSum(Orders::getFee,"fee"));
map.put("consumes",consumes);
//总额
Map<String,Object> totalPoint = userService.getMap(new MPJLambdaWrapper<User>()
.selectSum(User::getPoint,"totalPoint"));
//指定月份以后的冲销差额
Map<String,Object> diff = ordersService.getMap(new MPJLambdaWrapper<Orders>()
.eq(Orders::getUseFlag,1).and(t->t.eq(Orders::getType,0).or().eq(Orders::getPayType,1))
.apply("DATE_FORMAT(t.order_time, '%Y-%m') > '"+params.get("year")+"-"+params.get("month")+"'")
.select("SUM(IF(type=0,fee,fee*-1)) diff"));
//目前总额+差额
map.put("surplus",new BigDecimal(totalPoint.get("totalPoint").toString()).add(diff==null?BigDecimal.ZERO:new BigDecimal(diff.get("diff").toString())));
return R.ok().putData("map",map);
}
//vip
@RequestMapping("/vipStatistics")
public R vipStatistics(@RequestBody Map<String,Object> params){
//收入
List<Map<String,Object>> incomes = ordersService.listMaps(new MPJLambdaWrapper<Orders>()
.leftJoin(PaymentToOrder.class,PaymentToOrder::getOrderId,Orders::getId)
.leftJoin(Payment.class,Payment::getId,PaymentToOrder::getPaymentId)
.disableSubLogicDel()
.eq(Orders::getUseFlag,1).eq(Orders::getType,1)
.apply("DATE_FORMAT(t.order_time, '%Y-%m') = '"+params.get("year")+"-"+params.get("month")+"'")
.select("IF(t.pay_type=1,'天医币',IF(t2.type=0,'微信',IF(t2.type=1,'支付宝','银行'))) type,SUM(t.fee) fee")
.groupBy(Payment::getType));
//所有vip订单
List<Orders> vipOrders = ordersService.list(new MPJLambdaWrapper<Orders>()
.eq(Orders::getUseFlag,1).eq(Orders::getType,1));
String date = DateUtils.formatDate(new Date(),"yyyy-MM-dd");
for(Orders vipOrder:vipOrders){
if (vipOrder.getSource()==1){
Map<String,Object> wumenVipLog = userVipLogService.getMap(new MPJLambdaWrapper<UserVipLog>()
.eq(UserVipLog::getOrderSn,vipOrder.getOrderSn())
.apply("DATE_FORMAT(start_time, '%Y-%m') <= DATE_FORMAT('"+date+"', '%Y-%m') and DATE_FORMAT(end_time, '%Y-%m') >= DATE_FORMAT('"+date+"', '%Y-%m')")
.select("sum(fee) fee,start_time,end_time")
.groupBy(UserVipLog::getOrderSn));
}
} }
return R.ok().putData("incomes",incomes);
}
//实物统计
@RequestMapping("/physicalStatistics")
public R physicalStatistics(@RequestBody Map<String,Object> params){
List<Map<String,Object>> physical = ordersService.listMaps(new MPJLambdaWrapper<Orders>()
.leftJoin(PaymentToOrder.class,PaymentToOrder::getOrderId,Orders::getId)
.leftJoin(Payment.class,Payment::getId,PaymentToOrder::getPaymentId)
.disableSubLogicDel()
.eq(Orders::getUseFlag,1).eq(Orders::getType,3)
.apply("DATE_FORMAT(t.order_time, '%Y-%m') = '"+params.get("year")+"-"+params.get("month")+"'")
.select("IF(t.pay_type=1,'天医币',IF(t2.type=0,'微信',IF(t2.type=1,'支付宝','银行'))) type,SUM(t.fee) fee")
.groupBy(Payment::getType));
return R.ok().putData("map",physical);
}
//培训班
return R.ok().putData("map",map); @RequestMapping("/trainingClassStatistics")
public R trainingClassStatistics(@RequestBody Map<String,Object> params){
List<Map<String,Object>> trainingClass = ordersService.listMaps(new MPJLambdaWrapper<Orders>()
.leftJoin(PaymentToOrder.class,PaymentToOrder::getOrderId,Orders::getId)
.leftJoin(Payment.class,Payment::getId,PaymentToOrder::getPaymentId)
.disableSubLogicDel()
.eq(Orders::getUseFlag,1).eq(Orders::getType,4)
.apply("DATE_FORMAT(t.order_time, '%Y-%m') = '"+params.get("year")+"-"+params.get("month")+"'")
.select("IF(t.pay_type=1,'天医币',IF(t2.type=0,'微信',IF(t2.type=1,'支付宝','银行'))) type,SUM(t.fee) fee")
.groupBy(Payment::getType));
return R.ok().putData("map",trainingClass);
} }