151 lines
7.9 KiB
Java
151 lines
7.9 KiB
Java
package com.peanut.modules.common.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
import com.peanut.common.utils.R;
|
|
import com.peanut.modules.common.entity.JfTransactionDetails;
|
|
import com.peanut.modules.common.entity.MyUserEntity;
|
|
import com.peanut.modules.common.entity.TransactionDetailsEntity;
|
|
import com.peanut.modules.common.service.JfTransactionDetailsService;
|
|
import com.peanut.modules.common.service.MyUserService;
|
|
import com.peanut.modules.common.service.TransactionDetailsService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @Description: 积分记录
|
|
*/
|
|
@Slf4j
|
|
@RestController("commonJfTransactionDetails")
|
|
@RequestMapping("common/jfTransactionDetails")
|
|
public class JfTransactionDetailsController {
|
|
|
|
@Autowired
|
|
private JfTransactionDetailsService jfService;
|
|
@Autowired
|
|
private TransactionDetailsService transactionDetailsService;
|
|
@Autowired
|
|
private MyUserService userService;
|
|
|
|
/**
|
|
* 获取记录列表
|
|
* @return
|
|
*/
|
|
@RequestMapping("/getJfTransactionDetailsList")
|
|
public R getTransactionDetailsList(@RequestBody Map params){
|
|
LambdaQueryWrapper<JfTransactionDetails> wrapper = new LambdaQueryWrapper<>();
|
|
if (params.containsKey("userId")&& StringUtils.isNotEmpty(params.get("userId").toString())){
|
|
wrapper.eq(JfTransactionDetails::getUserId,params.get("userId"));
|
|
}
|
|
wrapper.orderByDesc(JfTransactionDetails::getCreateTime);
|
|
List<JfTransactionDetails> list = jfService.list(wrapper);
|
|
return R.ok().put("transactionDetailsList",list);
|
|
}
|
|
|
|
|
|
@RequestMapping("/activityDonateJF")
|
|
@Transactional
|
|
public R activityDonateJF(){
|
|
StringBuffer sb = new StringBuffer();
|
|
String startTime = "2025-11-08 00:00:00";
|
|
String endTime = "2025-11-13 09:22:00";
|
|
//查询时间段内所有充值的人
|
|
List<TransactionDetailsEntity> list = transactionDetailsService.list(new LambdaQueryWrapper<TransactionDetailsEntity>()
|
|
.between(TransactionDetailsEntity::getCreateTime,startTime,endTime)
|
|
.gt(TransactionDetailsEntity::getChangeAmount,0)
|
|
.groupBy(TransactionDetailsEntity::getUserId)
|
|
.orderByDesc(TransactionDetailsEntity::getCreateTime));
|
|
for (TransactionDetailsEntity transactionDetail : list) {
|
|
MyUserEntity user = userService.getById(transactionDetail.getUserId());
|
|
//时间段内充值总值
|
|
Map<String,Object> td = transactionDetailsService.getMap(new MPJLambdaWrapper<TransactionDetailsEntity>()
|
|
.eq(TransactionDetailsEntity::getUserId,transactionDetail.getUserId())
|
|
.between(TransactionDetailsEntity::getCreateTime,startTime,endTime)
|
|
.gt(TransactionDetailsEntity::getChangeAmount,0)
|
|
.selectSum(TransactionDetailsEntity::getChangeAmount));
|
|
if(new BigDecimal(td.get("changeAmount").toString()).compareTo(new BigDecimal(500))>=0){
|
|
//时间段内获得的积分
|
|
Map<String,Object> jftd = jfService.getMap(new MPJLambdaWrapper<JfTransactionDetails>()
|
|
.eq(JfTransactionDetails::getUserId,transactionDetail.getUserId())
|
|
.like(JfTransactionDetails::getRemark,"双11")
|
|
.between(JfTransactionDetails::getCreateTime,startTime,endTime)
|
|
.gt(TransactionDetailsEntity::getChangeAmount,0)
|
|
.selectSum(TransactionDetailsEntity::getChangeAmount));
|
|
BigDecimal jf = BigDecimal.ZERO;
|
|
BigDecimal changeJf = BigDecimal.ZERO;
|
|
BigDecimal shouldJf = BigDecimal.ZERO;
|
|
if (jftd!=null){
|
|
jf = new BigDecimal(jftd.get("changeAmount").toString());
|
|
}
|
|
changeJf = chgf(changeJf,shouldJf,new BigDecimal(td.get("changeAmount").toString()),jf);
|
|
if (changeJf.compareTo(BigDecimal.ZERO)>0){
|
|
sb.append((StringUtils.isEmpty(user.getName())?"无名氏":user.getName())+"-"+user.getTel()+"充值"+td.get("changeAmount").toString()+
|
|
"获得积分"+jf+"补积分"+changeJf+"\n");
|
|
user.setJf(user.getJf().add(changeJf));
|
|
userService.updateById(user);
|
|
addJf(user,changeJf);
|
|
}else if (changeJf.compareTo(BigDecimal.ZERO)==0){
|
|
sb.append((StringUtils.isEmpty(user.getName())?"无名氏":user.getName())+"-"+user.getTel()+"充值"+td.get("changeAmount").toString()+
|
|
"获得积分"+jf+"补积分"+changeJf+"\n");
|
|
}else if (changeJf.compareTo(BigDecimal.ZERO)<0){
|
|
sb.append((StringUtils.isEmpty(user.getName())?"无名氏":user.getName())+"-"+user.getTel()+"特殊情况\n");
|
|
}
|
|
}else {
|
|
sb.append((StringUtils.isEmpty(user.getName())?"无名氏":user.getName())+"-"+user.getTel()+"充值"+td.get("changeAmount").toString()+"未达标\n");
|
|
}
|
|
}
|
|
System.out.println(sb.toString());
|
|
return R.ok();
|
|
}
|
|
|
|
public BigDecimal chgf(BigDecimal changeJf,BigDecimal shouldJf,BigDecimal changeAmount,BigDecimal jf){
|
|
if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(5000))>=0||
|
|
new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(3000))>=0||
|
|
new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(2000))>=0||
|
|
new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(1000))>=0||
|
|
new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(500))>=0){
|
|
if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(5000))>=0){
|
|
shouldJf = shouldJf.add(new BigDecimal(2500));
|
|
changeAmount = changeAmount.subtract(new BigDecimal(5000));
|
|
}else if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(3000))>=0){
|
|
shouldJf = shouldJf.add(new BigDecimal(1300));
|
|
changeAmount = changeAmount.subtract(new BigDecimal(3000));
|
|
}else if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(2000))>=0){
|
|
shouldJf = shouldJf.add(new BigDecimal(800));
|
|
changeAmount = changeAmount.subtract(new BigDecimal(2000));
|
|
}else if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(1000))>=0){
|
|
shouldJf = shouldJf.add(new BigDecimal(300));
|
|
changeAmount = changeAmount.subtract(new BigDecimal(1000));
|
|
}else if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(500))>=0){
|
|
shouldJf = shouldJf.add(new BigDecimal(120));
|
|
changeAmount = changeAmount.subtract(new BigDecimal(500));
|
|
}
|
|
return chgf(changeJf,shouldJf,changeAmount,jf);
|
|
}
|
|
changeJf = shouldJf.subtract(jf);
|
|
return changeJf;
|
|
}
|
|
|
|
|
|
|
|
public void addJf(MyUserEntity user,BigDecimal changeAmount){
|
|
JfTransactionDetails jfTransactionDetails = new JfTransactionDetails();
|
|
jfTransactionDetails.setUserId(user.getId());
|
|
jfTransactionDetails.setActType(0);
|
|
jfTransactionDetails.setChangeAmount(changeAmount);
|
|
jfTransactionDetails.setUserBalance(user.getJf());
|
|
jfTransactionDetails.setRemark("2025年双11活动赠与补送");
|
|
jfService.save(jfTransactionDetails);
|
|
}
|
|
|
|
}
|