管理端VIP延期功能
This commit is contained in:
@@ -15,7 +15,7 @@ public interface UserVipLogService extends IService<UserVipLog> {
|
||||
|
||||
boolean addUserVipLogOrder(int userId, int userVipId,String orderSn, Date startTime, Date endTime, BigDecimal fee, BigDecimal jf, String payType);
|
||||
|
||||
boolean addUserVipLog(Map<String, Object> params, UserVip userVip);
|
||||
boolean addUserVipLog(Map<String, Object> params,int userId,int userVipId,Date startTime,Date endTime);
|
||||
|
||||
BigDecimal countDayAmount(UserVipLog userVipLog);
|
||||
|
||||
|
||||
@@ -43,15 +43,15 @@ public class UserVipLogServiceImpl extends ServiceImpl<UserVipLogDao, UserVipLog
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addUserVipLog(Map<String, Object> params, UserVip userVip) {
|
||||
public boolean addUserVipLog(Map<String, Object> params, int userId,int userVipId,Date startTime,Date endTime) {
|
||||
UserVipLog userVipLog = new UserVipLog();
|
||||
userVipLog.setUserId(userVip.getUserId());
|
||||
userVipLog.setUserVipId(userVip.getId());
|
||||
userVipLog.setUserId(userId);
|
||||
userVipLog.setUserVipId(userVipId);
|
||||
userVipLog.setType(params.get("userVipType").toString());
|
||||
userVipLog.setPayTime(DateUtils.stringToDate(params.get("payTime").toString(),"yyyy-MM-dd HH:mm:ss"));
|
||||
userVipLog.setAdminId(Integer.parseInt(params.get("adminId").toString()));
|
||||
userVipLog.setStartTime(userVip.getStartTime());
|
||||
userVipLog.setEndTime(userVip.getEndTime());
|
||||
userVipLog.setStartTime(startTime);
|
||||
userVipLog.setEndTime(endTime);
|
||||
userVipLog.setPrice(new BigDecimal(params.get("fee").toString()));
|
||||
userVipLog.setFee(new BigDecimal(params.get("fee").toString()));
|
||||
userVipLog.setJf(new BigDecimal(StringUtils.isEmpty(params.get("jf").toString()) ? "0" : params.get("jf").toString()));
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 超V管理
|
||||
@@ -89,12 +90,32 @@ public class UserVipController {
|
||||
public R addUserVipByAdmin(@RequestBody Map<String, Object> params) {
|
||||
params.put("userVipType","master");
|
||||
Date startTime = new Date();
|
||||
Date endTime = DateUtils.addDateYears(startTime, Integer.parseInt(params.get("year").toString()));
|
||||
int year = Integer.parseInt(params.get("year").toString());
|
||||
Date endTime = DateUtils.addDateYears(startTime, year);
|
||||
BigDecimal fee = new BigDecimal(params.get("fee").toString());
|
||||
BigDecimal jf = new BigDecimal(StringUtils.isEmpty(params.get("jf").toString()) ? "0" : params.get("jf").toString());
|
||||
if ("天医币".equals(params.get("payType"))){
|
||||
MyUserEntity user = userService.getById(params.get("userId").toString());
|
||||
if(user.getPeanutCoin().compareTo(fee)>=0){
|
||||
if(fee.compareTo(BigDecimal.ZERO)>=0){
|
||||
if(user.getPeanutCoin().compareTo(fee)<0){
|
||||
return R.error("天医币不足");
|
||||
}
|
||||
}
|
||||
if(jf.compareTo(BigDecimal.ZERO)>=0){
|
||||
if(user.getJf().compareTo(jf)<0){
|
||||
return R.error("积分不足");
|
||||
}
|
||||
}
|
||||
String vipType = "11".equals(params.get("type").toString())?"超级VIP":
|
||||
"12".equals(params.get("type").toString())?"开通简易超v":
|
||||
"1".equals(params.get("type").toString())?"开通医学超级VIP":
|
||||
"2".equals(params.get("type").toString())?"开通国心超级VIP":
|
||||
"4".equals(params.get("type").toString())?"开通中医学VIP":
|
||||
"5".equals(params.get("type").toString())?"开通针灸学VIP":
|
||||
"6".equals(params.get("type").toString())?"开通肿瘤学VIP":
|
||||
"7".equals(params.get("type").toString())?"开通国学VIP":
|
||||
"8".equals(params.get("type").toString())?"开通心理学VIP":"开通中西汇通VIP";
|
||||
if(fee.compareTo(BigDecimal.ZERO)>0){
|
||||
user.setPeanutCoin(user.getPeanutCoin().subtract(fee));
|
||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
transactionDetailsEntity.setUserId(user.getId());
|
||||
@@ -103,24 +124,18 @@ public class UserVipController {
|
||||
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
|
||||
transactionDetailsEntity.setTel(user.getTel());
|
||||
transactionDetailsEntity.setOrderType("后台扣费");
|
||||
transactionDetailsEntity.setNote(params.get("remark").toString());
|
||||
transactionDetailsEntity.setNote(vipType+year+"年"+params.get("remark").toString());
|
||||
transactionDetailsService.save(transactionDetailsEntity);
|
||||
}else {
|
||||
return R.error("天医币不足");
|
||||
}
|
||||
if (jf.compareTo(BigDecimal.ZERO)>0){
|
||||
if(user.getJf().compareTo(jf)>=0){
|
||||
user.setJf(user.getJf().subtract(jf));
|
||||
JfTransactionDetails jfDetail = new JfTransactionDetails();
|
||||
jfDetail.setUserId(user.getId());
|
||||
jfDetail.setActType(1);
|
||||
jfDetail.setChangeAmount(jf.negate());
|
||||
jfDetail.setUserBalance(user.getJf());
|
||||
jfDetail.setRemark("购买VIP扣除");
|
||||
jfTransactionDetailsService.save(jfDetail);
|
||||
}else {
|
||||
return R.error("积分不足");
|
||||
}
|
||||
if(jf.compareTo(BigDecimal.ZERO)>0){
|
||||
user.setJf(user.getJf().subtract(jf));
|
||||
JfTransactionDetails jfDetail = new JfTransactionDetails();
|
||||
jfDetail.setUserId(user.getId());
|
||||
jfDetail.setActType(1);
|
||||
jfDetail.setChangeAmount(jf.negate());
|
||||
jfDetail.setUserBalance(user.getJf());
|
||||
jfDetail.setRemark(vipType+year+"年");
|
||||
jfTransactionDetailsService.save(jfDetail);
|
||||
}
|
||||
userService.updateById(user);
|
||||
}
|
||||
@@ -164,7 +179,119 @@ public class UserVipController {
|
||||
userVipService.save(userVip);
|
||||
params.put("fee",fee.divide(new BigDecimal(count),2, BigDecimal.ROUND_HALF_UP));
|
||||
params.put("jf",jf.divide(new BigDecimal(count),2, BigDecimal.ROUND_HALF_UP));
|
||||
userVipLogService.addUserVipLog(params, userVip);
|
||||
userVipLogService.addUserVipLog(params, userVip.getUserId(),userVip.getId(),userVip.getStartTime(),userVip.getEndTime());
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/renewUserVipByAdmin")
|
||||
@Transactional
|
||||
public R renewUserVipByAdmin(@RequestBody Map<String, Object> params) {
|
||||
params.put("userVipType","master");
|
||||
Date startTime = new Date();
|
||||
int year = Integer.parseInt(params.get("year").toString());
|
||||
Date endTime = DateUtils.addDateYears(startTime, year);
|
||||
BigDecimal fee = new BigDecimal(params.get("fee").toString());
|
||||
BigDecimal jf = new BigDecimal(StringUtils.isEmpty(params.get("jf").toString()) ? "0" : params.get("jf").toString());
|
||||
MyUserEntity user = userService.getById(params.get("userId").toString());
|
||||
if ("天医币".equals(params.get("payType"))){
|
||||
if(fee.compareTo(BigDecimal.ZERO)>=0){
|
||||
if(user.getPeanutCoin().compareTo(fee)<0){
|
||||
return R.error("天医币不足");
|
||||
}
|
||||
}
|
||||
if(jf.compareTo(BigDecimal.ZERO)>=0){
|
||||
if(user.getJf().compareTo(jf)<0){
|
||||
return R.error("积分不足");
|
||||
}
|
||||
}
|
||||
String vipType = "11".equals(params.get("type").toString())?"延期超级VIP":
|
||||
"12".equals(params.get("type").toString())?"延期简易超v":
|
||||
"1".equals(params.get("type").toString())?"延期医学超级VIP":
|
||||
"2".equals(params.get("type").toString())?"延期国心超级VIP":
|
||||
"4".equals(params.get("type").toString())?"延期中医学VIP":
|
||||
"5".equals(params.get("type").toString())?"延期针灸学VIP":
|
||||
"6".equals(params.get("type").toString())?"延期肿瘤学VIP":
|
||||
"7".equals(params.get("type").toString())?"延期国学VIP":
|
||||
"8".equals(params.get("type").toString())?"延期心理学VIP":"延期中西汇通VIP";
|
||||
if(fee.compareTo(BigDecimal.ZERO)>0){
|
||||
user.setPeanutCoin(user.getPeanutCoin().subtract(fee));
|
||||
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
|
||||
transactionDetailsEntity.setUserId(user.getId());
|
||||
transactionDetailsEntity.setUserName(user.getNickname());
|
||||
transactionDetailsEntity.setChangeAmount(fee.negate());
|
||||
transactionDetailsEntity.setUserBalance(user.getPeanutCoin());
|
||||
transactionDetailsEntity.setTel(user.getTel());
|
||||
transactionDetailsEntity.setOrderType("后台扣费");
|
||||
transactionDetailsEntity.setNote(vipType+year+"年"+params.get("remark").toString());
|
||||
transactionDetailsService.save(transactionDetailsEntity);
|
||||
}
|
||||
if(jf.compareTo(BigDecimal.ZERO)>0){
|
||||
user.setJf(user.getJf().subtract(jf));
|
||||
JfTransactionDetails jfDetail = new JfTransactionDetails();
|
||||
jfDetail.setUserId(user.getId());
|
||||
jfDetail.setActType(1);
|
||||
jfDetail.setChangeAmount(jf.negate());
|
||||
jfDetail.setUserBalance(user.getJf());
|
||||
jfDetail.setRemark(vipType+year+"年");
|
||||
jfTransactionDetailsService.save(jfDetail);
|
||||
}
|
||||
userService.updateById(user);
|
||||
}
|
||||
List<Integer> typeList = new ArrayList<>();
|
||||
int count = 1;
|
||||
if ("11".equals(params.get("type").toString())) {//超v
|
||||
count = 6;
|
||||
for (int i=4;i<10;i++){
|
||||
typeList.add(i);
|
||||
}
|
||||
}else if ("12".equals(params.get("type").toString())) {//简易超v
|
||||
count = 5;
|
||||
for (int i=4;i<10;i++){
|
||||
if (i==7){
|
||||
continue;
|
||||
}
|
||||
typeList.add(i);
|
||||
}
|
||||
}else if ("1".equals(params.get("type").toString())) {//医学超级
|
||||
count = 4;
|
||||
for (int i=4;i<8;i++){
|
||||
if (i==7){
|
||||
i = 9;
|
||||
}
|
||||
typeList.add(i);
|
||||
}
|
||||
}else if ("2".equals(params.get("type").toString())) {//国心超级
|
||||
count = 2;
|
||||
for (int i=7;i<9;i++){
|
||||
typeList.add(i);
|
||||
}
|
||||
}else {
|
||||
typeList.add(Integer.parseInt(params.get("type").toString()));
|
||||
}
|
||||
for (Integer t : typeList) {
|
||||
UserVip userVip = userVipService.getOne(new LambdaQueryWrapper<UserVip>()
|
||||
.eq(UserVip::getUserId,user.getId())
|
||||
.eq(UserVip::getType,t)
|
||||
.eq(UserVip::getState,0));
|
||||
if (userVip!=null){
|
||||
Date oldEndTime = userVip.getEndTime();
|
||||
userVip.setEndTime(DateUtils.addDateYears(oldEndTime,year));
|
||||
userVipService.updateById(userVip);
|
||||
params.put("fee",fee.divide(new BigDecimal(count),2, BigDecimal.ROUND_HALF_UP));
|
||||
params.put("jf",jf.divide(new BigDecimal(count),2, BigDecimal.ROUND_HALF_UP));
|
||||
userVipLogService.addUserVipLog(params, userVip.getUserId(),userVip.getId(),oldEndTime,userVip.getEndTime());
|
||||
}else {
|
||||
userVip = new UserVip();
|
||||
userVip.setUserId(Integer.parseInt(params.get("userId").toString()));
|
||||
userVip.setStartTime(startTime);
|
||||
userVip.setEndTime(endTime);
|
||||
userVip.setType(t);
|
||||
userVipService.save(userVip);
|
||||
params.put("fee",fee.divide(new BigDecimal(count),2, BigDecimal.ROUND_HALF_UP));
|
||||
params.put("jf",jf.divide(new BigDecimal(count),2, BigDecimal.ROUND_HALF_UP));
|
||||
userVipLogService.addUserVipLog(params, userVip.getUserId(),userVip.getId(),userVip.getStartTime(),userVip.getEndTime());
|
||||
}
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
@@ -189,7 +316,9 @@ public class UserVipController {
|
||||
List<UserVipLog> list = uv.getUserVipLogs();
|
||||
list.addAll(userVipLogService.list(new LambdaQueryWrapper<UserVipLog>()
|
||||
.eq(UserVipLog::getUserVipId,userVip.getId())));
|
||||
uv.setUserVipLogs(list);
|
||||
uv.setUserVipLogs(list.stream().sorted((UserVipLog uvl1,UserVipLog uvl2)->{
|
||||
return uvl1.getEndTime().compareTo(uvl2.getEndTime());
|
||||
}).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
return R.ok().put("userVips", resUserVips);
|
||||
|
||||
Reference in New Issue
Block a user