充币送积分活动保留后面用
This commit is contained in:
@@ -1,15 +1,23 @@
|
|||||||
package com.peanut.modules.common.controller;
|
package com.peanut.modules.common.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.peanut.common.utils.R;
|
import com.peanut.common.utils.R;
|
||||||
import com.peanut.modules.common.entity.JfTransactionDetails;
|
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.JfTransactionDetailsService;
|
||||||
|
import com.peanut.modules.common.service.MyUserService;
|
||||||
|
import com.peanut.modules.common.service.TransactionDetailsService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.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.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -23,6 +31,10 @@ public class JfTransactionDetailsController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JfTransactionDetailsService jfService;
|
private JfTransactionDetailsService jfService;
|
||||||
|
@Autowired
|
||||||
|
private TransactionDetailsService transactionDetailsService;
|
||||||
|
@Autowired
|
||||||
|
private MyUserService userService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取记录列表
|
* 获取记录列表
|
||||||
@@ -39,4 +51,97 @@ public class JfTransactionDetailsController {
|
|||||||
return R.ok().put("transactionDetailsList",list);
|
return R.ok().put("transactionDetailsList",list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping("/activityDonateJF")
|
||||||
|
@Transactional
|
||||||
|
public R activityDonateJF(){
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
String startTime = "2025-06-14 00:00:00";
|
||||||
|
String endTime = "2025-06-17 09:30: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())
|
||||||
|
.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()+"特殊情况\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(2200));
|
||||||
|
changeAmount = changeAmount.subtract(new BigDecimal(5000));
|
||||||
|
}else if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(3000))>=0){
|
||||||
|
shouldJf = shouldJf.add(new BigDecimal(1000));
|
||||||
|
changeAmount = changeAmount.subtract(new BigDecimal(3000));
|
||||||
|
}else if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(2000))>=0){
|
||||||
|
shouldJf = shouldJf.add(new BigDecimal(600));
|
||||||
|
changeAmount = changeAmount.subtract(new BigDecimal(2000));
|
||||||
|
}else if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(1000))>=0){
|
||||||
|
shouldJf = shouldJf.add(new BigDecimal(240));
|
||||||
|
changeAmount = changeAmount.subtract(new BigDecimal(1000));
|
||||||
|
}else if (new BigDecimal(changeAmount.toString()).compareTo(new BigDecimal(500))>=0){
|
||||||
|
shouldJf = shouldJf.add(new BigDecimal(100));
|
||||||
|
// changeJf = new BigDecimal(100).subtract(jf);
|
||||||
|
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年618活动赠与");
|
||||||
|
jfService.save(jfTransactionDetails);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user