| | |
| | | package com.ruoyi.member.service.impl.birthday; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | 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.MgtBirthdayGetVo; |
| | | import com.ruoyi.member.domain.vo.MgtBirthdayGiftVo; |
| | | import com.ruoyi.member.domain.vo.*; |
| | | import com.ruoyi.member.mapper.birthday.BirthdayCardMapper; |
| | | import com.ruoyi.member.service.birthday.BirthdayCardService; |
| | | import com.ruoyi.member.service.birthday.BirthdayGiftService; |
| | | import com.ruoyi.member.service.member.MemberGiftRecordService; |
| | | import com.ruoyi.member.service.member.MemberService; |
| | | import com.ruoyi.system.api.constant.AppErrorConstant; |
| | | import com.ruoyi.system.api.domain.dto.BirthdayGiftSendDto; |
| | | import com.ruoyi.system.api.domain.dto.MgtBaseBathDto; |
| | | import com.ruoyi.system.api.domain.poji.member.BirthdayCard; |
| | | import com.ruoyi.system.api.domain.poji.member.Member; |
| | | import com.ruoyi.system.api.domain.poji.member.MemberGiftRecord; |
| | | import com.ruoyi.system.api.domain.poji.shop.Shop; |
| | | import com.ruoyi.system.api.domain.vo.MgtSimpleShopVo; |
| | | import com.ruoyi.system.api.service.RemoteShopService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class BirthdayCardServiceImpl extends ServiceImpl<BirthdayCardMapper, BirthdayCard> implements BirthdayCardService { |
| | | |
| | | @Resource |
| | | private BirthdayCardMapper birthdayCardMapper; |
| | | |
| | | @Resource |
| | | private BirthdayGiftService birthdayGiftService; |
| | | |
| | | @Resource |
| | | private RemoteShopService remoteShopService; |
| | | |
| | | @Resource |
| | | private MemberGiftRecordService memberGiftRecordService; |
| | | |
| | | @Resource |
| | | private MemberService memberService; |
| | | |
| | | |
| | | |
| | | /** |
| | | * @description 平台编辑生日卡 |
| | |
| | | */ |
| | | @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); |
| | | if(mgtBirthdayEditDto.getShopId()!=null){ |
| | | birthdayCard.setShopId(mgtBirthdayEditDto.getShopId()); |
| | | }else{ |
| | | 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()!=null&&mgtBirthdayEditDto.getAreaFlag()==2){ |
| | | birthdayCard.setDesignatedArea(mgtBirthdayEditDto.getDesignatedArea()); |
| | | }else{ |
| | | birthdayCard.setDesignatedArea(null); |
| | | } |
| | | birthdayCard.setShopFlag(mgtBirthdayEditDto.getShopFlag()); |
| | | if(mgtBirthdayEditDto.getShopFlag()!=null&&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!=null&&!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); |
| | | Shop shop = remoteShopService.getShop(shopId).getData(); |
| | | if(birthdayCard.getAreaFlag()==2&&birthdayCard.getShopFlag()==1&&!StringUtils.checkString(birthdayCard.getDesignatedArea(),shop.getShopCityCode())){ |
| | | birthdayCard = null; |
| | | } |
| | | // 如果生日卡存在 |
| | | 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/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(merBirthdayEditDto.getShopId()); |
| | | 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(new BigDecimal("100.00")); |
| | | 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()); |
| | | } |
| | | List<BirthdayGift> birthdayGiftList = birthdayGiftService.listByCardId(birthdayCard.getCardId()); |
| | | if(merBirthdayEditDto.getCardStatus()==1){ |
| | | if(birthdayGiftList==null||birthdayGiftList.isEmpty()){ |
| | | throw new ServiceException(AppErrorConstant.BIRTHDAYCARD_NO_GIFT); |
| | | } |
| | | } |
| | | birthdayCard.setCardStatus(merBirthdayEditDto.getCardStatus()); |
| | | this.saveOrUpdate(birthdayCard); |
| | | } |
| | | |
| | | /** |
| | | * @description 获取用户生日礼物 |
| | | * @author jqs |
| | | * @date 2023/7/7 10:55 |
| | | * @param shopId |
| | | * @return AppBirthdayCardVo |
| | | */ |
| | | @Override |
| | | public AppBirthdayCardVo getUserBirthdayCard(Long userId,Long shopId){ |
| | | AppBirthdayCardVo appBirthdayCardVo = new AppBirthdayCardVo(); |
| | | String currentYear = String.valueOf(LocalDate.now().getYear()); |
| | | List<MemberGiftRecord> memberGiftRecordList = memberGiftRecordService.listByUserIdAndYear(userId,currentYear); |
| | | if(memberGiftRecordList!=null&&!memberGiftRecordList.isEmpty()){ |
| | | List<AppBirthdayGiftVo> birthdayGiftVoList = memberGiftRecordList.stream().map( |
| | | memberGiftRecord -> { |
| | | AppBirthdayGiftVo appBirthdayGiftVo = new AppBirthdayGiftVo(); |
| | | switch (memberGiftRecord.getGiftType()) { |
| | | case 1: |
| | | // 礼物类型为1,即优惠券 |
| | | appBirthdayGiftVo.setGiftName(memberGiftRecord.getCouponName()); |
| | | appBirthdayGiftVo.setGiftNumber(memberGiftRecord.getCouponNumber()); |
| | | break; |
| | | case 2: |
| | | // 礼物类型为2,即商品 |
| | | appBirthdayGiftVo.setGiftName(memberGiftRecord.getGoodsName()); |
| | | appBirthdayGiftVo.setGiftNumber(memberGiftRecord.getGoodsNumber()); |
| | | break; |
| | | case 3: |
| | | // 礼物类型为3,即现金 |
| | | appBirthdayGiftVo.setGiftName("现金"); |
| | | appBirthdayGiftVo.setGiftNumber(memberGiftRecord.getMoney().doubleValue()); |
| | | break; |
| | | case 4: |
| | | // 礼物类型为4,即礼品 |
| | | appBirthdayGiftVo.setGiftName(memberGiftRecord.getGiftName()); |
| | | appBirthdayGiftVo.setGiftNumber(memberGiftRecord.getGiftNumber()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return appBirthdayGiftVo; |
| | | } |
| | | ).collect(Collectors.toList()); |
| | | appBirthdayCardVo.setGetGiftFlag(1); |
| | | appBirthdayCardVo.setBirthdayGiftVoList(birthdayGiftVoList); |
| | | }else{ |
| | | appBirthdayCardVo.setGetGiftFlag(0); |
| | | } |
| | | |
| | | return appBirthdayCardVo; |
| | | } |
| | | |
| | | /** |
| | | * @description 获取用户生日礼物 |
| | | * @author jqs |
| | | * @date 2023/7/7 10:55 |
| | | * @param shopId |
| | | * @return AppBirthdayCardVo |
| | | */ |
| | | @Override |
| | | public AppBirthdayCardVo getBirthdayGift(Long userId, Long shopId){ |
| | | AppBirthdayCardVo appBirthdayCardVo = new AppBirthdayCardVo(); |
| | | List<AppBirthdayGiftVo> birthdayGiftVoList = new ArrayList<>(); |
| | | List<MemberGiftRecord> memberGiftRecordList = new ArrayList<>(); |
| | | List<BirthdayGiftSendDto> sendGoodsList = new ArrayList<>(); |
| | | List<BirthdayGiftSendDto> sendCouponList = new ArrayList<>(); |
| | | AppBirthdayGiftVo appBirthdayGiftVo; |
| | | MemberGiftRecord memberGiftRecord; |
| | | BigDecimal winningProbability; |
| | | BigDecimal randomProbability; |
| | | BirthdayGiftSendDto birthdayGiftSendDto; |
| | | String prizeId; |
| | | String currentYear = String.valueOf(LocalDate.now().getYear()); |
| | | Member member = memberService.getByUserId(userId); |
| | | // 获取平台生日卡信息 |
| | | BirthdayCard plBirthdayCard = this.getBirthdayCard(); |
| | | //绑定的时候需要判断范围 |
| | | if(member.getBindingFlag()==1){ |
| | | //判断指定区域全部店铺 |
| | | if(plBirthdayCard.getShopFlag()==1&&plBirthdayCard.getAreaFlag()==2){ |
| | | Shop shop = remoteShopService.getShop(member.getRelationShopId()).getData(); |
| | | if(!StringUtils.checkString(plBirthdayCard.getDesignatedArea(),shop.getShopCityCode())){ |
| | | plBirthdayCard = null; |
| | | } |
| | | } |
| | | //判断指定店铺 |
| | | if(plBirthdayCard.getShopFlag()==2&&!StringUtils.checkString(plBirthdayCard.getApplicableShop(),shopId.toString())){ |
| | | plBirthdayCard = null; |
| | | } |
| | | } |
| | | // 如果生日卡存在 |
| | | if (plBirthdayCard != null && plBirthdayCard.getCardStatus()==1) { |
| | | // 获取生日卡对应的生日礼物列表 |
| | | List<BirthdayGift> birthdayGiftList = birthdayGiftService.listByCardId(plBirthdayCard.getCardId()); |
| | | if(birthdayGiftList!=null&&!birthdayGiftList.isEmpty()){ |
| | | // 遍历生日礼物列表 |
| | | for (BirthdayGift birthdayGift : birthdayGiftList) { |
| | | winningProbability = birthdayGift.getWinningProbability(); |
| | | randomProbability = new BigDecimal(new Random().nextInt(100)); |
| | | if(winningProbability.compareTo(randomProbability)>0){ |
| | | appBirthdayGiftVo = new AppBirthdayGiftVo(); |
| | | memberGiftRecord = new MemberGiftRecord(); |
| | | birthdayGiftSendDto = new BirthdayGiftSendDto(); |
| | | BeanUtils.copyProperties(birthdayGift, memberGiftRecord); |
| | | prizeId = IdUtils.simpleUUID(); |
| | | memberGiftRecord.setPrizeId(prizeId); |
| | | memberGiftRecord.setDelFlag(0); |
| | | memberGiftRecord.setVerifyStatus(1); |
| | | memberGiftRecord.setGiftFrom(1); |
| | | memberGiftRecord.setPrizeFrom(1); |
| | | memberGiftRecord.setGiftYear(currentYear); |
| | | memberGiftRecord.setCreateTime(new Date()); |
| | | memberGiftRecord.setUserId(userId); |
| | | birthdayGiftSendDto.setUserId(userId); |
| | | birthdayGiftSendDto.setGiftFrom(1); |
| | | birthdayGiftSendDto.setGiftType(birthdayGift.getGiftType()); |
| | | switch (birthdayGift.getGiftType()) { |
| | | case 1: |
| | | // 礼物类型为1,即优惠券 |
| | | appBirthdayGiftVo.setGiftName(birthdayGift.getCouponName()); |
| | | appBirthdayGiftVo.setGiftNumber(birthdayGift.getCouponNumber()); |
| | | birthdayGiftSendDto.setCouponId(birthdayGift.getCouponId()); |
| | | birthdayGiftSendDto.setCouponNumber(birthdayGift.getCouponNumber()); |
| | | sendGoodsList.add(birthdayGiftSendDto); |
| | | memberGiftRecord.setCouponId(birthdayGift.getCouponId()); |
| | | memberGiftRecord.setCouponName(birthdayGift.getCouponName()); |
| | | memberGiftRecord.setCouponNumber(birthdayGift.getCouponNumber()); |
| | | break; |
| | | case 2: |
| | | // 礼物类型为2,即商品 |
| | | appBirthdayGiftVo.setGiftName(birthdayGift.getGoodsName()); |
| | | appBirthdayGiftVo.setGiftNumber(birthdayGift.getGoodsNumber()); |
| | | birthdayGiftSendDto.setGoodsId(birthdayGift.getGoodsId()); |
| | | birthdayGiftSendDto.setCouponNumber(birthdayGift.getGoodsNumber()); |
| | | sendCouponList.add(birthdayGiftSendDto); |
| | | memberGiftRecord.setGoodsId(birthdayGift.getGoodsId()); |
| | | memberGiftRecord.setGoodsName(birthdayGift.getGoodsName()); |
| | | memberGiftRecord.setGoodsNumber(birthdayGift.getGoodsNumber()); |
| | | break; |
| | | case 3: |
| | | // 礼物类型为3,即现金 |
| | | appBirthdayGiftVo.setGiftName("现金"); |
| | | appBirthdayGiftVo.setGiftNumber(memberGiftRecord.getMoney().doubleValue()); |
| | | memberGiftRecord.setMoney(birthdayGift.getMoney()); |
| | | break; |
| | | case 4: |
| | | // 礼物类型为4,即礼品 |
| | | appBirthdayGiftVo.setGiftName(birthdayGift.getGiftName()); |
| | | appBirthdayGiftVo.setGiftNumber(birthdayGift.getGiftNumber()); |
| | | memberGiftRecord.setGiftName(birthdayGift.getGiftName()); |
| | | memberGiftRecord.setGiftNumber(birthdayGift.getGiftNumber()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | birthdayGiftVoList.add(appBirthdayGiftVo); |
| | | memberGiftRecordList.add(memberGiftRecord); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //获取商户营销开关状态 |
| | | if(member.getBindingFlag()==1){ |
| | | Integer marketingStatus = remoteShopService.getShopMarketingStatus(shopId).getData(); |
| | | if(marketingStatus>1){ |
| | | //获取商户生日卡 |
| | | LambdaQueryWrapper<BirthdayCard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(BirthdayCard::getDelFlag,0); |
| | | queryWrapper.eq(BirthdayCard::getShopId,shopId); |
| | | BirthdayCard shopBirthdayCard = this.getOne(queryWrapper,false); |
| | | // 如果生日卡存在 |
| | | if (shopBirthdayCard != null && shopBirthdayCard.getCardStatus()==1) { |
| | | // 获取生日卡对应的生日礼物列表 |
| | | List<BirthdayGift> birthdayGiftList = birthdayGiftService.listByCardId(shopBirthdayCard.getCardId()); |
| | | if(!birthdayGiftList.isEmpty()){ |
| | | // 遍历生日礼物列表 |
| | | for (BirthdayGift birthdayGift : birthdayGiftList) { |
| | | winningProbability = birthdayGift.getWinningProbability(); |
| | | randomProbability = new BigDecimal(new Random().nextInt(100)); |
| | | if(winningProbability.compareTo(randomProbability)>0){ |
| | | appBirthdayGiftVo = new AppBirthdayGiftVo(); |
| | | memberGiftRecord = new MemberGiftRecord(); |
| | | birthdayGiftSendDto = new BirthdayGiftSendDto(); |
| | | BeanUtils.copyProperties(birthdayGift, memberGiftRecord); |
| | | prizeId = IdUtils.simpleUUID(); |
| | | memberGiftRecord.setPrizeId(prizeId); |
| | | memberGiftRecord.setDelFlag(0); |
| | | memberGiftRecord.setVerifyStatus(1); |
| | | memberGiftRecord.setGiftFrom(2); |
| | | memberGiftRecord.setPrizeFrom(1); |
| | | memberGiftRecord.setShopId(shopId); |
| | | memberGiftRecord.setGiftYear(currentYear); |
| | | memberGiftRecord.setCreateTime(new Date()); |
| | | memberGiftRecord.setUserId(userId); |
| | | birthdayGiftSendDto.setUserId(userId); |
| | | birthdayGiftSendDto.setGiftFrom(2); |
| | | birthdayGiftSendDto.setShopId(shopId); |
| | | birthdayGiftSendDto.setGiftType(birthdayGift.getGiftType()); |
| | | switch (birthdayGift.getGiftType()) { |
| | | case 1: |
| | | // 礼物类型为1,即优惠券 |
| | | appBirthdayGiftVo.setGiftName(birthdayGift.getCouponName()); |
| | | appBirthdayGiftVo.setGiftNumber(birthdayGift.getCouponNumber()); |
| | | birthdayGiftSendDto.setCouponId(birthdayGift.getCouponId()); |
| | | birthdayGiftSendDto.setCouponNumber(birthdayGift.getCouponNumber()); |
| | | sendGoodsList.add(birthdayGiftSendDto); |
| | | memberGiftRecord.setCouponId(birthdayGift.getCouponId()); |
| | | memberGiftRecord.setCouponName(birthdayGift.getCouponName()); |
| | | memberGiftRecord.setCouponNumber(birthdayGift.getCouponNumber()); |
| | | break; |
| | | case 2: |
| | | // 礼物类型为2,即商品 |
| | | appBirthdayGiftVo.setGiftName(birthdayGift.getGoodsName()); |
| | | appBirthdayGiftVo.setGiftNumber(birthdayGift.getGoodsNumber()); |
| | | birthdayGiftSendDto.setGoodsId(birthdayGift.getGoodsId()); |
| | | birthdayGiftSendDto.setCouponNumber(birthdayGift.getGoodsNumber()); |
| | | sendCouponList.add(birthdayGiftSendDto); |
| | | memberGiftRecord.setGoodsId(birthdayGift.getGoodsId()); |
| | | memberGiftRecord.setGoodsName(birthdayGift.getGoodsName()); |
| | | memberGiftRecord.setGoodsNumber(birthdayGift.getGoodsNumber()); |
| | | break; |
| | | case 3: |
| | | // 礼物类型为3,即现金 |
| | | appBirthdayGiftVo.setGiftName("现金"); |
| | | appBirthdayGiftVo.setGiftNumber(memberGiftRecord.getMoney().doubleValue()); |
| | | memberGiftRecord.setMoney(birthdayGift.getMoney()); |
| | | break; |
| | | case 4: |
| | | // 礼物类型为4,即礼品 |
| | | appBirthdayGiftVo.setGiftName(birthdayGift.getGiftName()); |
| | | appBirthdayGiftVo.setGiftNumber(birthdayGift.getGiftNumber()); |
| | | memberGiftRecord.setGiftName(birthdayGift.getGiftName()); |
| | | memberGiftRecord.setGiftNumber(birthdayGift.getGiftNumber()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | birthdayGiftVoList.add(appBirthdayGiftVo); |
| | | memberGiftRecordList.add(memberGiftRecord); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //保存用户礼物记录 |
| | | memberGiftRecordService.saveBatch(memberGiftRecordList); |
| | | appBirthdayCardVo.setBirthdayGiftVoList(birthdayGiftVoList); |
| | | return appBirthdayCardVo; |
| | | } |
| | | |
| | | /** |
| | | * @param page |
| | | * @param userId |
| | | * @return List<AppMemberPrizePageVo> |
| | | * @description |
| | | * @author jqs |
| | | * @date 2023/7/11 18:02 |
| | | */ |
| | | @Override |
| | | public List<AppMemberPrizePageVo> pageAppMemberPrize(Page page, Long userId) { |
| | | List<AppMemberPrizePageVo> memberPrizePageVoList = birthdayCardMapper.pageAppMemberPrize(page, userId); |
| | | if (memberPrizePageVoList != null && !memberPrizePageVoList.isEmpty()) { |
| | | HashSet<Long> shopIdSet = new HashSet<>(); |
| | | for (AppMemberPrizePageVo appMemberPrizePageVo : memberPrizePageVoList) { |
| | | appMemberPrizePageVo.setVerifyCode("3-" + appMemberPrizePageVo.getPrizeId()); |
| | | if (appMemberPrizePageVo.getShopId() != null) { |
| | | shopIdSet.add(appMemberPrizePageVo.getShopId()); |
| | | } |
| | | } |
| | | String shopJoinedString = String.join(",", shopIdSet.stream().map(Object::toString).collect(Collectors.toList())); |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(shopJoinedString); |
| | | List<MgtSimpleShopVo> simpleShopVoList = remoteShopService.listShopSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | Map<Long, MgtSimpleShopVo> shopMap = simpleShopVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); |
| | | for (AppMemberPrizePageVo appMemberPrizePageVo : memberPrizePageVoList) { |
| | | if (appMemberPrizePageVo.getShopId() != null) { |
| | | appMemberPrizePageVo.setVerifyShopName(shopMap.get(appMemberPrizePageVo.getShopId()).getShopName()); |
| | | } |
| | | } |
| | | } |
| | | return memberPrizePageVoList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @description 判断生日卡开启状态 |
| | | * @author jqs |
| | | * @date 2023/8/1 15:43 |
| | | * @param |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public Integer checkBirthdayCard(Long shopId,Integer bindingFlag){ |
| | | // 获取平台生日卡信息 |
| | | Boolean platformBirthdayCardOpen = true; |
| | | BirthdayCard plBirthdayCard = birthdayCardMapper.getMerShopBirthdayCard(0L); |
| | | if (plBirthdayCard == null || plBirthdayCard.getCardStatus()!=1) { |
| | | platformBirthdayCardOpen = false; |
| | | }else{ |
| | | //绑死店铺判断区域和店铺 |
| | | if(bindingFlag==1){ |
| | | //判断指定区域全部店铺 |
| | | if(plBirthdayCard.getShopFlag()==1&&plBirthdayCard.getAreaFlag()==2){ |
| | | Shop shop = remoteShopService.getShop(shopId).getData(); |
| | | if(!StringUtils.checkString(plBirthdayCard.getDesignatedArea(),shop.getShopCityCode())){ |
| | | platformBirthdayCardOpen = false; |
| | | } |
| | | } |
| | | //判断指定店铺 |
| | | if(plBirthdayCard.getShopFlag()==2&&!StringUtils.checkString(plBirthdayCard.getApplicableShop(),shopId.toString())){ |
| | | platformBirthdayCardOpen = false; |
| | | } |
| | | } |
| | | } |
| | | //判断店铺生日卡 |
| | | BirthdayCard shopBirthdayCard = birthdayCardMapper.getMerShopBirthdayCard(shopId); |
| | | // 如果生日卡存在 |
| | | Boolean shopBirthdayCardOpen = true; |
| | | if(bindingFlag==1){ |
| | | if (shopBirthdayCard == null || shopBirthdayCard.getCardStatus()!=1) { |
| | | shopBirthdayCardOpen = false; |
| | | } |
| | | Integer marketingStatus = remoteShopService.getShopMarketingStatus(shopId).getData(); |
| | | if(marketingStatus<=1){ |
| | | shopBirthdayCardOpen = false; |
| | | } |
| | | }else{ |
| | | shopBirthdayCardOpen = false; |
| | | } |
| | | if(platformBirthdayCardOpen||shopBirthdayCardOpen){ |
| | | return 1; |
| | | }else{ |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 获取平台生日卡 |
| | | * @author jqs |
| | | * @date 2023/8/9 19:35 |
| | | * @param |
| | | * @return BirthdayCard |
| | | */ |
| | | @Override |
| | | public BirthdayCard getBirthdayCard(){ |
| | | LambdaQueryWrapper<BirthdayCard> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(BirthdayCard::getDelFlag,0); |
| | | queryWrapper.eq(BirthdayCard::getShopId,0L); |
| | | queryWrapper.eq(BirthdayCard::getCardStatus,1); |
| | | BirthdayCard shopBirthdayCard = this.getOne(queryWrapper,false); |
| | | return shopBirthdayCard; |
| | | } |
| | | } |