package cc.mrbird.febs.mall.service.impl;
|
|
import cc.mrbird.febs.common.entity.FebsResponse;
|
import cc.mrbird.febs.common.entity.QueryRequest;
|
import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
|
import cc.mrbird.febs.mall.dto.*;
|
import cc.mrbird.febs.mall.entity.*;
|
import cc.mrbird.febs.mall.mapper.*;
|
import cc.mrbird.febs.mall.service.IAdminMallActService;
|
import cc.mrbird.febs.mall.vo.AdminMallActLuckdrawRecordVo;
|
import cc.mrbird.febs.mall.vo.AdminMallActSetVo;
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
import java.util.List;
|
|
@Slf4j
|
@Service
|
@RequiredArgsConstructor
|
@Transactional
|
public class AdminMallActServiceImpl extends ServiceImpl<MallActSetMapper, MallActSet> implements IAdminMallActService {
|
|
private final MallActAwardSetMapper mallActAwardSetMapper;
|
private final MallActLuckdrawRecordMapper mallActLuckdrawRecordMapper;
|
private final MallActWinRecordMapper mallActWinRecordMapper;
|
private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
|
|
@Override
|
public IPage<AdminMallActSetVo> getActListInPage(MallActSet mallActSet, QueryRequest request) {
|
Page<AdminMallActSetVo> page = new Page<>(request.getPageNum(), request.getPageSize());
|
IPage<AdminMallActSetVo> adminMallActSetVos = this.baseMapper.selectMallActsInPage(page, mallActSet);
|
return adminMallActSetVos;
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse addMallAct(AddMallActDto addMallActDto) {
|
String actName = addMallActDto.getActName();
|
if (StrUtil.isEmpty(actName)) {
|
return new FebsResponse().fail().message("活动名称不能为空");
|
}
|
String actCode = addMallActDto.getActCode();
|
if (StrUtil.isEmpty(actCode)) {
|
return new FebsResponse().fail().message("活动编码不能为空");
|
}
|
String actImage = addMallActDto.getActImage();
|
if (StrUtil.isEmpty(actImage)) {
|
return new FebsResponse().fail().message("活动图片不能为空");
|
}
|
Date actStartTime = addMallActDto.getActStartTime();
|
if(ObjectUtil.isEmpty(actStartTime)){
|
return new FebsResponse().fail().message("开始日期不能为空");
|
}
|
Date actEndTime = addMallActDto.getActEndTime();
|
if(ObjectUtil.isEmpty(actEndTime)){
|
return new FebsResponse().fail().message("结束日期不能为空");
|
}
|
int compare = DateUtil.compare(actStartTime, actEndTime);
|
if(compare >= 0){
|
return new FebsResponse().fail().message("开始日期要小于结束日期");
|
}
|
Integer actScoreCnt = addMallActDto.getActScoreCnt()==null?0:addMallActDto.getActScoreCnt();
|
if(actScoreCnt <= 0){
|
return new FebsResponse().fail().message("请输入正整数");
|
}
|
List<AddMallActAwardDto> addMallActAwardDtos = addMallActDto.getAddMallActAwardDtos();
|
if(CollUtil.isEmpty(addMallActAwardDtos)){
|
return new FebsResponse().fail().message("请设置奖品");
|
}
|
for(AddMallActAwardDto addMallActAwardDto : addMallActAwardDtos){
|
String awardName = addMallActAwardDto.getAwardName();
|
if (StrUtil.isEmpty(awardName)) {
|
return new FebsResponse().fail().message("奖品名称不能为空");
|
}
|
String awardImage = addMallActAwardDto.getAwardImage();
|
if (StrUtil.isEmpty(awardImage)) {
|
return new FebsResponse().fail().message("奖品图不能为空");
|
}
|
Integer awardTotal = addMallActAwardDto.getAwardTotal()==null?0:addMallActAwardDto.getAwardTotal();
|
if(awardTotal <= 0){
|
return new FebsResponse().fail().message("奖品总数要大于零");
|
}
|
Integer awardCnt = addMallActAwardDto.getAwardCnt()==null?0:addMallActAwardDto.getAwardCnt();
|
if(awardCnt < 0){
|
return new FebsResponse().fail().message("请输入正整数");
|
}
|
if(awardCnt > awardTotal){
|
return new FebsResponse().fail().message("要小于奖品总数");
|
}
|
Integer awardType = addMallActAwardDto.getAwardType();
|
if(awardType != MallActAwardSet.AWARD_TYPE_JF && awardType != MallActAwardSet.AWARD_TYPE_YJ && awardType != MallActAwardSet.AWARD_TYPE_XXCY){
|
return new FebsResponse().fail().message("请选择正确的奖品类型");
|
}
|
Integer awardValue = addMallActAwardDto.getAwardValue()==null?0:addMallActAwardDto.getAwardValue();
|
if(awardValue < 0){
|
return new FebsResponse().fail().message("奖金数量不能小于零");
|
}
|
}
|
MallActSet mallActSet = new MallActSet();
|
mallActSet.setActCode(actCode);
|
mallActSet.setActName(actName);
|
mallActSet.setActImage(actImage);
|
mallActSet.setActStartTime(actStartTime);
|
mallActSet.setActEndTime(actEndTime);
|
mallActSet.setActScoreCnt(actScoreCnt);
|
mallActSet.setActStatus(MallActSet.ACT_STATUS_DISABLED);
|
String actRemark = addMallActDto.getActRemark();
|
if(StrUtil.isNotEmpty(actRemark)){
|
mallActSet.setActRemark(actRemark);
|
}
|
this.baseMapper.insert(mallActSet);
|
|
//新增奖品
|
for(AddMallActAwardDto addMallActAwardDto : addMallActAwardDtos){
|
String awardName = addMallActAwardDto.getAwardName();
|
Integer awardTotal = addMallActAwardDto.getAwardTotal();
|
Integer awardCnt = addMallActAwardDto.getAwardCnt();
|
Integer awardType = addMallActAwardDto.getAwardType();
|
Integer awardValue = addMallActAwardDto.getAwardValue();
|
String awardImage = addMallActAwardDto.getAwardImage();
|
Long actId = mallActSet.getId();
|
MallActAwardSet mallActAwardSet = new MallActAwardSet();
|
mallActAwardSet.setActId(actId);
|
mallActAwardSet.setAwardName(awardName);
|
mallActAwardSet.setAwardTotal(awardTotal);
|
mallActAwardSet.setAwardCnt(awardCnt);
|
mallActAwardSet.setAwardType(awardType);
|
mallActAwardSet.setAwardValue(awardValue);
|
mallActAwardSet.setAwardImage(awardImage);
|
mallActAwardSetMapper.insert(mallActAwardSet);
|
}
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse startMallAct(Long id) {
|
MallActSet mallActSet = this.baseMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallActSet)) {
|
return new FebsResponse().fail().message("活动不存在,请刷新当前页面");
|
}
|
Date date = new Date();
|
int compareStart = DateUtil.compare(date, mallActSet.getActStartTime());
|
if(compareStart < 0){
|
return new FebsResponse().fail().message("活动还未开始");
|
}
|
int compareEnd = DateUtil.compare(date, mallActSet.getActEndTime());
|
if(compareEnd > 0){
|
return new FebsResponse().fail().message("活动已结束");
|
}
|
mallActSet.setActStatus(MallActSet.ACT_STATUS_ENABLE);
|
this.baseMapper.updateById(mallActSet);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse closeMallAct(Long id) {
|
MallActSet mallActSet = this.baseMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallActSet)) {
|
return new FebsResponse().fail().message("活动不存在,请刷新当前页面");
|
}
|
mallActSet.setActStatus(MallActSet.ACT_STATUS_DISABLED);
|
this.baseMapper.updateById(mallActSet);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse delMallAct(Long id) {
|
MallActSet mallActSet = this.baseMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallActSet)) {
|
return new FebsResponse().fail().message("活动不存在,请刷新当前页面");
|
}
|
Integer actStatus = mallActSet.getActStatus();
|
if (MallActSet.ACT_STATUS_ENABLE == actStatus) {
|
return new FebsResponse().fail().message("请先关闭该活动");
|
}
|
this.baseMapper.deleteById(id);
|
mallActAwardSetMapper.deleteByActId(id);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
public MallActSet selectMallActById(long id) {
|
MallActSet mallActSet = this.baseMapper.selectById(id);
|
List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActId(id);
|
mallActSet.setMallActAwardSets(mallActAwardSets);
|
return mallActSet;
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse updateMallAct(MallActUpdateDto mallActUpdateDto) {
|
Long id = mallActUpdateDto.getId()==null?0:mallActUpdateDto.getId();
|
MallActSet mallActSet = this.baseMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallActSet)) {
|
return new FebsResponse().fail().message("活动不存在,请刷新当前页面");
|
}
|
String actName = mallActUpdateDto.getActName();
|
if (StrUtil.isEmpty(actName)) {
|
return new FebsResponse().fail().message("活动名称不能为空");
|
}
|
String actCode = mallActUpdateDto.getActCode();
|
if (StrUtil.isEmpty(actCode)) {
|
return new FebsResponse().fail().message("活动编码不能为空");
|
}
|
String actImage = mallActUpdateDto.getActImage();
|
if (StrUtil.isEmpty(actImage)) {
|
return new FebsResponse().fail().message("活动图片不能为空");
|
}
|
Date actStartTime = mallActUpdateDto.getActStartTime();
|
if(ObjectUtil.isEmpty(actStartTime)){
|
return new FebsResponse().fail().message("开始日期不能为空");
|
}
|
Date actEndTime = mallActUpdateDto.getActEndTime();
|
if(ObjectUtil.isEmpty(actEndTime)){
|
return new FebsResponse().fail().message("结束日期不能为空");
|
}
|
int compare = DateUtil.compare(actStartTime, actEndTime);
|
if(compare >= 0){
|
return new FebsResponse().fail().message("开始日期要小于结束日期");
|
}
|
Integer actScoreCnt = mallActUpdateDto.getActScoreCnt()==null?0:mallActUpdateDto.getActScoreCnt();
|
if(actScoreCnt <= 0){
|
return new FebsResponse().fail().message("请输入正整数");
|
}
|
List<MallActAwardUpdateDto> mallActAwardUpdateDtos = mallActUpdateDto.getUpdateMallActAwardDtos();
|
if(CollUtil.isEmpty(mallActAwardUpdateDtos)){
|
return new FebsResponse().fail().message("请设置奖品");
|
}
|
for(MallActAwardUpdateDto mallActAwardUpdateDto : mallActAwardUpdateDtos){
|
String awardName = mallActAwardUpdateDto.getAwardName();
|
if (StrUtil.isEmpty(awardName)) {
|
return new FebsResponse().fail().message("奖品名称不能为空");
|
}
|
String awardImage = mallActAwardUpdateDto.getAwardImage();
|
if (StrUtil.isEmpty(awardImage)) {
|
return new FebsResponse().fail().message("奖品图不能为空");
|
}
|
Integer awardTotal = mallActAwardUpdateDto.getAwardTotal()==null?0:mallActAwardUpdateDto.getAwardTotal();
|
if(awardTotal <= 0){
|
return new FebsResponse().fail().message("奖品总数要大于零");
|
}
|
Integer awardCnt = mallActAwardUpdateDto.getAwardCnt()==null?0:mallActAwardUpdateDto.getAwardCnt();
|
if(awardCnt < 0){
|
return new FebsResponse().fail().message("请输入正整数");
|
}
|
if(awardCnt > awardTotal){
|
return new FebsResponse().fail().message("要小于奖品总数");
|
}
|
Integer awardType = mallActAwardUpdateDto.getAwardType();
|
if(awardType != MallActAwardSet.AWARD_TYPE_JF && awardType != MallActAwardSet.AWARD_TYPE_YJ && awardType != MallActAwardSet.AWARD_TYPE_XXCY){
|
return new FebsResponse().fail().message("请选择正确的奖品类型");
|
}
|
Integer awardValue = mallActAwardUpdateDto.getAwardValue()==null?0:mallActAwardUpdateDto.getAwardValue();
|
if(awardValue < 0){
|
return new FebsResponse().fail().message("奖金数量不能小于零");
|
}
|
}
|
mallActSet.setActCode(actCode);
|
mallActSet.setActName(actName);
|
mallActSet.setActImage(actImage);
|
mallActSet.setActStartTime(actStartTime);
|
mallActSet.setActEndTime(actEndTime);
|
mallActSet.setActScoreCnt(actScoreCnt);
|
mallActSet.setActStatus(MallActSet.ACT_STATUS_DISABLED);
|
String actRemark = mallActUpdateDto.getActRemark();
|
if(StrUtil.isNotEmpty(actRemark)){
|
mallActSet.setActRemark(actRemark);
|
}
|
this.baseMapper.updateById(mallActSet);
|
//新增奖品
|
for(MallActAwardUpdateDto mallActAwardUpdateDto : mallActAwardUpdateDtos){
|
String awardName = mallActAwardUpdateDto.getAwardName();
|
Integer awardTotal = mallActAwardUpdateDto.getAwardTotal();
|
Integer awardCnt = mallActAwardUpdateDto.getAwardCnt();
|
Integer awardType = mallActAwardUpdateDto.getAwardType();
|
Integer awardValue = mallActAwardUpdateDto.getAwardValue();
|
String awardImage = mallActAwardUpdateDto.getAwardImage();
|
if(ObjectUtil.isEmpty(mallActAwardUpdateDto.getId())){
|
MallActAwardSet mallActAwardSet = new MallActAwardSet();
|
mallActAwardSet.setActId(id);
|
mallActAwardSet.setAwardName(awardName);
|
mallActAwardSet.setAwardTotal(awardTotal);
|
mallActAwardSet.setAwardCnt(awardCnt);
|
mallActAwardSet.setAwardType(awardType);
|
mallActAwardSet.setAwardValue(awardValue);
|
mallActAwardSet.setAwardImage(awardImage);
|
mallActAwardSetMapper.insert(mallActAwardSet);
|
}else{
|
MallActAwardSet mallActAwardSet = mallActAwardSetMapper.selectById(mallActAwardUpdateDto.getId());
|
mallActAwardSet.setActId(id);
|
mallActAwardSet.setAwardName(awardName);
|
mallActAwardSet.setAwardTotal(awardTotal);
|
mallActAwardSet.setAwardCnt(awardCnt);
|
mallActAwardSet.setAwardType(awardType);
|
mallActAwardSet.setAwardValue(awardValue);
|
mallActAwardSet.setAwardImage(awardImage);
|
mallActAwardSetMapper.updateById(mallActAwardSet);
|
}
|
}
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public IPage<AdminMallActLuckdrawRecordVo> getLuckdrawListInPage(MallActLuckdrawRecord mallActLuckdrawRecord, QueryRequest request) {
|
Page<AdminMallActLuckdrawRecordVo> page = new Page<>(request.getPageNum(), request.getPageSize());
|
IPage<AdminMallActLuckdrawRecordVo> adminMallActLuckdrawRecordVos = mallActLuckdrawRecordMapper.selectMallActLuckdrawsInPage(page, mallActLuckdrawRecord);
|
return adminMallActLuckdrawRecordVos;
|
}
|
|
@Override
|
public MallActWinRecord selectMallActWinInfoById(long id) {
|
MallActWinRecord mallActWinRecord = mallActWinRecordMapper.selectByLuckDrawId(id);
|
return mallActWinRecord;
|
}
|
|
@Override
|
public FebsResponse addSetting(LuckDrawSettingDto luckDrawSettingDto) {
|
|
if(Double.parseDouble(luckDrawSettingDto.getScoreSet())>1 || Double.parseDouble(luckDrawSettingDto.getScoreSet()) <0){
|
return new FebsResponse().fail().message("中奖概率必须是一个在零和一之间的小数");
|
}
|
|
if(Double.parseDouble(luckDrawSettingDto.getCashSet())>1 || Double.parseDouble(luckDrawSettingDto.getCashSet()) <0){
|
return new FebsResponse().fail().message("中奖概率必须是一个在零和一之间的小数");
|
}
|
|
DataDictionaryCustom scoreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
|
DataDictionaryEnum.WIN_SCORE.getType(),
|
DataDictionaryEnum.WIN_SCORE.getCode());
|
DataDictionaryCustom cashDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
|
DataDictionaryEnum.WIN_CASH.getType(),
|
DataDictionaryEnum.WIN_CASH.getCode());
|
|
if (ObjectUtil.isNotEmpty(scoreDic)) {
|
scoreDic.setValue(luckDrawSettingDto.getScoreSet().toString());
|
dataDictionaryCustomMapper.updateById(scoreDic);
|
}else{
|
DataDictionaryCustom dataDictionaryCustom = new DataDictionaryCustom();
|
dataDictionaryCustom.setCode(DataDictionaryEnum.WIN_SCORE.getCode());
|
dataDictionaryCustom.setType(DataDictionaryEnum.WIN_SCORE.getType());
|
dataDictionaryCustom.setValue(luckDrawSettingDto.getScoreSet().toString());
|
dataDictionaryCustom.setDescription("积分中奖概率");
|
dataDictionaryCustomMapper.insert(dataDictionaryCustom);
|
}
|
if (ObjectUtil.isNotEmpty(cashDic)) {
|
cashDic.setValue(luckDrawSettingDto.getCashSet().toString());
|
dataDictionaryCustomMapper.updateById(cashDic);
|
}else{
|
DataDictionaryCustom dataDictionaryCustom = new DataDictionaryCustom();
|
dataDictionaryCustom.setCode(DataDictionaryEnum.WIN_CASH.getCode());
|
dataDictionaryCustom.setType(DataDictionaryEnum.WIN_CASH.getType());
|
dataDictionaryCustom.setValue(luckDrawSettingDto.getScoreSet().toString());
|
dataDictionaryCustom.setDescription("佣金中奖概率");
|
dataDictionaryCustomMapper.insert(dataDictionaryCustom);
|
}
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
}
|