| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.member.domain.dto.MerBirthdayEditDto; |
| | | import com.ruoyi.member.domain.dto.MgtBirthdayEditDto; |
| | | import com.ruoyi.member.domain.dto.MgtBirthdayGetDto; |
| | | import com.ruoyi.member.domain.dto.MgtBirthdayGiftDto; |
| | | import com.ruoyi.member.domain.pojo.birthday.BirthdayCard; |
| | | import com.ruoyi.member.domain.pojo.birthday.BirthdayGift; |
| | | import com.ruoyi.member.domain.vo.MerBirthdayEditInfoVo; |
| | | import com.ruoyi.member.domain.vo.MerBirthdayGetVo; |
| | | import com.ruoyi.member.domain.vo.MgtBirthdayGetVo; |
| | | import com.ruoyi.member.domain.vo.MgtBirthdayGiftVo; |
| | | import com.ruoyi.member.mapper.birthday.BirthdayCardMapper; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.StringJoiner; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class BirthdayCardServiceImpl extends ServiceImpl<BirthdayCardMapper, BirthdayCard> implements BirthdayCardService { |
| | | |
| | | @Resource |
| | | private BirthdayCardMapper birthdayCardMapper; |
| | | |
| | | @Resource |
| | | private BirthdayGiftService birthdayGiftService; |
| | |
| | | */ |
| | | @Override |
| | | public void editMgtBirthdayCard(MgtBirthdayEditDto mgtBirthdayEditDto){ |
| | | if(mgtBirthdayEditDto.getCardId()!=null){ |
| | | BirthdayCard birthdayCardOld = this.getById(mgtBirthdayEditDto.getCardId()); |
| | | // 创建查询包装器 |
| | | LambdaQueryWrapper<BirthdayCard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | // 添加查询条件:删除标志为0 |
| | | queryWrapper.eq(BirthdayCard::getDelFlag,0); |
| | | // 如果店铺ID不为空,则添加查询条件:店铺ID |
| | | if(mgtBirthdayEditDto.getShopId()!=null){ |
| | | queryWrapper.eq(BirthdayCard::getShopId,mgtBirthdayEditDto.getShopId()); |
| | | }else{ |
| | | // 否则,添加查询条件:店铺ID为0 |
| | | queryWrapper.eq(BirthdayCard::getShopId,0); |
| | | } |
| | | // 获取查询结果 |
| | | BirthdayCard birthdayCardOld = this.getOne(queryWrapper,false); |
| | | // 如果查询结果不为空,则进行更新操作 |
| | | if (birthdayCardOld!=null) { |
| | | // 设置删除标志为1 |
| | | birthdayCardOld.setDelFlag(1); |
| | | // 保存或更新数据 |
| | | this.saveOrUpdate(birthdayCardOld); |
| | | // 删除旧的生日卡的礼物 |
| | | birthdayGiftService.deleteByCardId(birthdayCardOld.getCardId()); |
| | | } |
| | | // 创建新的生日卡 |
| | | BirthdayCard birthdayCard = new BirthdayCard(); |
| | | birthdayCard.setDelFlag(0); |
| | | birthdayCard.setShopId(0L); |
| | | birthdayCard.setCardStatus(mgtBirthdayEditDto.getCardStatus()); |
| | | // 根据卡状态设置开启或关闭时间 |
| | | if(mgtBirthdayEditDto.getCardStatus()==1){ |
| | | birthdayCard.setOpenTime(new Date()); |
| | | }else{ |
| | | birthdayCard.setCloseTime(new Date()); |
| | | } |
| | | // 设置创建时间 |
| | | birthdayCard.setCreateTime(new Date()); |
| | | birthdayCard.setAreaFlag(mgtBirthdayEditDto.getAreaFlag()); |
| | | if(mgtBirthdayEditDto.getAreaFlag()==2){ |
| | | birthdayCard.setDesignatedArea(mgtBirthdayEditDto.getDesignatedArea()); |
| | | }else{ |
| | | birthdayCard.setDesignatedArea(null); |
| | | // 如果店铺ID不为空,则进行相关设置 |
| | | if(mgtBirthdayEditDto.getShopId()!=null){ |
| | | birthdayCard.setAreaFlag(mgtBirthdayEditDto.getAreaFlag()); |
| | | if(mgtBirthdayEditDto.getAreaFlag()==2){ |
| | | birthdayCard.setDesignatedArea(mgtBirthdayEditDto.getDesignatedArea()); |
| | | }else{ |
| | | birthdayCard.setDesignatedArea(null); |
| | | } |
| | | birthdayCard.setShopFlag(mgtBirthdayEditDto.getShopFlag()); |
| | | if(mgtBirthdayEditDto.getShopFlag()==2){ |
| | | birthdayCard.setApplicableShop(mgtBirthdayEditDto.getApplicableShop()); |
| | | }else{ |
| | | birthdayCard.setApplicableShop(null); |
| | | } |
| | | } |
| | | birthdayCard.setShopFlag(mgtBirthdayEditDto.getShopFlag()); |
| | | if(mgtBirthdayEditDto.getShopFlag()==2){ |
| | | birthdayCard.setApplicableShop(mgtBirthdayEditDto.getApplicableShop()); |
| | | }else{ |
| | | birthdayCard.setApplicableShop(null); |
| | | } |
| | | // 设置创建用户ID |
| | | birthdayCard.setCreateUserId(mgtBirthdayEditDto.getUserId()); |
| | | // 保存或更新数据 |
| | | this.saveOrUpdate(birthdayCard); |
| | | // 获取生日礼物列表 |
| | | List<MgtBirthdayGiftDto> mgtBirthdayGiftDtoList = mgtBirthdayEditDto.getMgtBirthdayGiftDtoList(); |
| | | List<BirthdayGift> birthdayGiftList = new ArrayList<>(); |
| | | if(!mgtBirthdayGiftDtoList.isEmpty()){ |
| | | mgtBirthdayGiftDtoList.forEach( dto->{ |
| | | BirthdayGift birthdayGift = new BirthdayGift(); |
| | | birthdayGift.setDelFlag(0); |
| | | birthdayGift.setCardId(birthdayCard.getCardId()); |
| | | birthdayGift.setGiftType(dto.getGiftType()); |
| | | birthdayGift.setCouponId(dto.getCouponId()); |
| | | birthdayGift.setCouponName(dto.getCouponName()); |
| | | birthdayGift.setCouponNumber(dto.getCouponNumber()); |
| | | birthdayGift.setGoodsId(dto.getGoodsId()); |
| | | birthdayGift.setGoodsName(dto.getGoodsName()); |
| | | birthdayGift.setGoodsNumber(dto.getGoodsNumber()); |
| | | birthdayGift.setGiftName(dto.getGiftName()); |
| | | birthdayGift.setGiftNumber(dto.getGiftNumber()); |
| | | birthdayGift.setMoney(dto.getMoney()); |
| | | birthdayGift.setWinningProbability(dto.getWinningProbability()); |
| | | birthdayGiftList.add(birthdayGift); |
| | | } |
| | | ); |
| | | // 如果生日礼物列表不为空,则进行相关设置 |
| | | if(!mgtBirthdayGiftDtoList.isEmpty()) { |
| | | mgtBirthdayGiftDtoList.forEach(dto -> { |
| | | BirthdayGift birthdayGift = new BirthdayGift(); |
| | | birthdayGift.setDelFlag(0); |
| | | birthdayGift.setCardId(birthdayCard.getCardId()); |
| | | birthdayGift.setGiftType(dto.getGiftType()); |
| | | birthdayGift.setCouponId(dto.getCouponId()); |
| | | birthdayGift.setCouponName(dto.getCouponName()); |
| | | birthdayGift.setCouponNumber(dto.getCouponNumber()); |
| | | birthdayGift.setGoodsId(dto.getGoodsId()); |
| | | birthdayGift.setGoodsName(dto.getGoodsName()); |
| | | birthdayGift.setGoodsNumber(dto.getGoodsNumber()); |
| | | birthdayGift.setGiftName(dto.getGiftName()); |
| | | birthdayGift.setGiftNumber(dto.getGiftNumber()); |
| | | birthdayGift.setMoney(dto.getMoney()); |
| | | birthdayGift.setWinningProbability(dto.getWinningProbability()); |
| | | birthdayGiftList.add(birthdayGift); |
| | | }); |
| | | // 批量保存生日礼物 |
| | | birthdayGiftService.saveBatch(birthdayGiftList); |
| | | } |
| | | } |
| | |
| | | queryWrapper.eq(BirthdayCard::getDelFlag,0); |
| | | if(mgtBirthdayGetDto.getShopId()!=null&&mgtBirthdayGetDto.getShopId()>0){ |
| | | queryWrapper.eq(BirthdayCard::getShopId,mgtBirthdayGetDto.getShopId()); |
| | | }else{ |
| | | queryWrapper.eq(BirthdayCard::getShopId,0); |
| | | } |
| | | BirthdayCard birthdayCard = this.getOne(queryWrapper,false); |
| | | if(birthdayCard!=null){ |
| | |
| | | } |
| | | return mgtBirthdayGetVo; |
| | | } |
| | | |
| | | /** |
| | | * @description 获取平台生日卡 |
| | | * @author jqs |
| | | * @date 2023/7/1 15:25 |
| | | * @param |
| | | * @return MerBirthdayGetVo |
| | | */ |
| | | @Override |
| | | public MerBirthdayGetVo getMerPlatformBirthdayCard(Long shopId){ |
| | | MerBirthdayGetVo birthdayGetVo = new MerBirthdayGetVo(); |
| | | // 获取平台生日卡信息 |
| | | BirthdayCard birthdayCard = birthdayCardMapper.getPlatformBirthdayCard(shopId); |
| | | // 如果生日卡存在 |
| | | if (birthdayCard != null) { |
| | | String giftDesc = ""; |
| | | StringJoiner giftSj = new StringJoiner(","); |
| | | // 获取生日卡对应的生日礼物列表 |
| | | List<BirthdayGift> birthdayGiftList = birthdayGiftService.listByCardId(birthdayCard.getCardId()); |
| | | // 如果生日礼物列表不为空 |
| | | if (!birthdayGiftList.isEmpty()) { |
| | | String giftStr; |
| | | // 遍历生日礼物列表 |
| | | for (BirthdayGift birthdayGift : birthdayGiftList) { |
| | | switch (birthdayGift.getGiftType()) { |
| | | case 1: |
| | | // 礼物类型为1,即优惠券 |
| | | giftStr = birthdayGift.getCouponName() + "*" + birthdayGift.getCouponNumber(); |
| | | giftSj.add(giftStr); |
| | | break; |
| | | case 2: |
| | | // 礼物类型为2,即商品 |
| | | giftStr = birthdayGift.getGoodsName() + "*" + birthdayGift.getGoodsNumber(); |
| | | giftSj.add(giftStr); |
| | | break; |
| | | case 3: |
| | | // 礼物类型为3,即现金 |
| | | giftStr = "¥" + birthdayGift.getMoney() + "现金"; |
| | | giftSj.add(giftStr); |
| | | break; |
| | | case 4: |
| | | // 礼物类型为4,即礼品 |
| | | giftStr = birthdayGift.getGiftName() + "*" + birthdayGift.getGiftNumber(); |
| | | giftSj.add(giftStr); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | // 将礼物描述设置到生日获取VO对象中 |
| | | giftDesc = giftSj.toString(); |
| | | birthdayGetVo.setGiftDesc(giftDesc); |
| | | } |
| | | }else{ |
| | | birthdayGetVo.setCardStatus(2); |
| | | } |
| | | return birthdayGetVo; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @description 获取商户生日卡 |
| | | * @author jqs |
| | | * @date 2023/7/1 15:25 |
| | | * @param |
| | | * @return MerBirthdayGetVo |
| | | */ |
| | | @Override |
| | | public MerBirthdayGetVo getMerShopBirthdayCard(Long shopId){ |
| | | MerBirthdayGetVo birthdayGetVo = new MerBirthdayGetVo(); |
| | | // 获取平台生日卡信息 |
| | | BirthdayCard birthdayCard = birthdayCardMapper.getMerShopBirthdayCard(shopId); |
| | | // 如果生日卡存在 |
| | | if (birthdayCard != null) { |
| | | String giftDesc = ""; |
| | | StringJoiner giftSj = new StringJoiner(","); |
| | | // 获取生日卡对应的生日礼物列表 |
| | | List<BirthdayGift> birthdayGiftList = birthdayGiftService.listByCardId(birthdayCard.getCardId()); |
| | | // 如果生日礼物列表不为空 |
| | | if (!birthdayGiftList.isEmpty()) { |
| | | String giftStr; |
| | | // 遍历生日礼物列表 |
| | | for (BirthdayGift birthdayGift : birthdayGiftList) { |
| | | switch (birthdayGift.getGiftType()) { |
| | | case 1: |
| | | // 礼物类型为1,即优惠券 |
| | | giftStr = birthdayGift.getCouponName() + "*" + birthdayGift.getCouponNumber(); |
| | | giftSj.add(giftStr); |
| | | break; |
| | | case 2: |
| | | // 礼物类型为2,即商品 |
| | | giftStr = birthdayGift.getGoodsName() + "*" + birthdayGift.getGoodsNumber(); |
| | | giftSj.add(giftStr); |
| | | break; |
| | | case 3: |
| | | // 礼物类型为3,即现金 |
| | | giftStr = "¥" + birthdayGift.getMoney() + "现金"; |
| | | giftSj.add(giftStr); |
| | | break; |
| | | case 4: |
| | | // 礼物类型为4,即礼品 |
| | | giftStr = birthdayGift.getGiftName() + "*" + birthdayGift.getGiftNumber(); |
| | | giftSj.add(giftStr); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | // 将礼物描述设置到生日获取VO对象中 |
| | | giftDesc = giftSj.toString(); |
| | | birthdayGetVo.setGiftDesc(giftDesc); |
| | | } |
| | | birthdayGetVo.setCardStatus(birthdayCard.getCardStatus()); |
| | | }else{ |
| | | birthdayGetVo.setCardStatus(2); |
| | | } |
| | | return birthdayGetVo; |
| | | } |
| | | |
| | | /** |
| | | * @description 获取商户生日卡详情 |
| | | * @author jqs |
| | | * @date 2023/7/3 10:58 |
| | | * @param shopId |
| | | * @return MerBirthdayGetVo |
| | | */ |
| | | @Override |
| | | public MerBirthdayEditInfoVo getMerShopBCEditInfo(Long shopId){ |
| | | MerBirthdayEditInfoVo merBirthdayEditInfoVo = new MerBirthdayEditInfoVo(); |
| | | LambdaQueryWrapper<BirthdayCard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(BirthdayCard::getDelFlag,0); |
| | | queryWrapper.eq(BirthdayCard::getShopId,shopId); |
| | | BirthdayCard birthdayCard = this.getOne(queryWrapper,false); |
| | | if(birthdayCard!=null){ |
| | | merBirthdayEditInfoVo.setCardId(birthdayCard.getCardId()); |
| | | merBirthdayEditInfoVo.setCardStatus(birthdayCard.getCardStatus()); |
| | | List<MgtBirthdayGiftVo> mgtBirthdayGiftVoList = birthdayGiftService.listGiftVoByCardId(birthdayCard.getCardId()); |
| | | merBirthdayEditInfoVo.setMgtBirthdayGiftVoList(mgtBirthdayGiftVoList); |
| | | } |
| | | return merBirthdayEditInfoVo; |
| | | } |
| | | |
| | | /** |
| | | * @description 商户编辑生日卡 |
| | | * @author jqs |
| | | * @date 2023/7/3 14:15 |
| | | * @param merBirthdayEditDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void editMerBirthdayCard(MerBirthdayEditDto merBirthdayEditDto){ |
| | | // 创建查询包装器 |
| | | LambdaQueryWrapper<BirthdayCard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(BirthdayCard::getDelFlag,0); |
| | | queryWrapper.eq(BirthdayCard::getShopId,merBirthdayEditDto.getShopId()); |
| | | // 获取查询结果 |
| | | BirthdayCard birthdayCardOld = this.getOne(queryWrapper,false); |
| | | // 如果查询结果不为空,则进行更新操作 |
| | | if (birthdayCardOld!=null) { |
| | | // 设置删除标志为1 |
| | | birthdayCardOld.setDelFlag(1); |
| | | // 保存或更新数据 |
| | | this.saveOrUpdate(birthdayCardOld); |
| | | // 删除旧的生日卡的礼物 |
| | | birthdayGiftService.deleteByCardId(birthdayCardOld.getCardId()); |
| | | } |
| | | // 创建新的生日卡 |
| | | BirthdayCard birthdayCard = new BirthdayCard(); |
| | | birthdayCard.setDelFlag(0); |
| | | birthdayCard.setShopId(0L); |
| | | birthdayCard.setCardStatus(merBirthdayEditDto.getCardStatus()); |
| | | // 根据卡状态设置开启或关闭时间 |
| | | if(merBirthdayEditDto.getCardStatus()==1){ |
| | | birthdayCard.setOpenTime(new Date()); |
| | | }else{ |
| | | birthdayCard.setCloseTime(new Date()); |
| | | } |
| | | // 设置创建时间 |
| | | birthdayCard.setCreateTime(new Date()); |
| | | // 设置创建用户ID |
| | | birthdayCard.setCreateUserId(merBirthdayEditDto.getUserId()); |
| | | // 保存或更新数据 |
| | | this.saveOrUpdate(birthdayCard); |
| | | // 获取生日礼物列表 |
| | | List<MgtBirthdayGiftDto> mgtBirthdayGiftDtoList = merBirthdayEditDto.getMgtBirthdayGiftDtoList(); |
| | | List<BirthdayGift> birthdayGiftList = new ArrayList<>(); |
| | | // 如果生日礼物列表不为空,则进行相关设置 |
| | | if(!mgtBirthdayGiftDtoList.isEmpty()) { |
| | | mgtBirthdayGiftDtoList.forEach(dto -> { |
| | | BirthdayGift birthdayGift = new BirthdayGift(); |
| | | birthdayGift.setDelFlag(0); |
| | | birthdayGift.setCardId(birthdayCard.getCardId()); |
| | | birthdayGift.setGiftType(dto.getGiftType()); |
| | | birthdayGift.setCouponId(dto.getCouponId()); |
| | | birthdayGift.setCouponName(dto.getCouponName()); |
| | | birthdayGift.setCouponNumber(dto.getCouponNumber()); |
| | | birthdayGift.setGoodsId(dto.getGoodsId()); |
| | | birthdayGift.setGoodsName(dto.getGoodsName()); |
| | | birthdayGift.setGoodsNumber(dto.getGoodsNumber()); |
| | | birthdayGift.setGiftName(dto.getGiftName()); |
| | | birthdayGift.setGiftNumber(dto.getGiftNumber()); |
| | | birthdayGift.setMoney(dto.getMoney()); |
| | | birthdayGift.setWinningProbability(dto.getWinningProbability()); |
| | | birthdayGiftList.add(birthdayGift); |
| | | }); |
| | | // 批量保存生日礼物 |
| | | birthdayGiftService.saveBatch(birthdayGiftList); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 开关生日卡成功 |
| | | * @author jqs |
| | | * @date 2023/7/3 14:27 |
| | | * @param merBirthdayEditDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void toggleMerBirthdayCard(MerBirthdayEditDto merBirthdayEditDto){ |
| | | // 创建查询包装器 |
| | | LambdaQueryWrapper<BirthdayCard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(BirthdayCard::getDelFlag,0); |
| | | queryWrapper.eq(BirthdayCard::getShopId,merBirthdayEditDto.getShopId()); |
| | | // 获取查询结果 |
| | | BirthdayCard birthdayCard = this.getOne(queryWrapper,false); |
| | | if(birthdayCard==null){ |
| | | birthdayCard = new BirthdayCard(); |
| | | birthdayCard.setDelFlag(0); |
| | | birthdayCard.setCreateTime(new Date()); |
| | | birthdayCard.setCreateUserId(merBirthdayEditDto.getUserId()); |
| | | } |
| | | birthdayCard.setCardStatus(merBirthdayEditDto.getCardStatus()); |
| | | this.saveOrUpdate(birthdayCard); |
| | | } |
| | | } |