|  |  |  | 
|---|
|  |  |  | package cc.mrbird.febs.mall.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.FebsResponse; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.AgentLevelEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.exception.FebsException; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.AppContants; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.LoginUserUtil; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.RedisUtils; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.ShareCodeUtil; | 
|---|
|  |  |  | import cc.mrbird.febs.common.properties.XcxProperties; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.conversion.MallMemberConversion; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.conversion.MallShopApplyConversion; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.dto.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallMember; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallMemberWallet; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallMoneyFlow; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallShoppingCart; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.IApiMallMemberService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.ICommonService; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.MallMemberVo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.MoneyFlowVo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.TeamListVo; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.service.*; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.vo.*; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.model.BrandWCPayRequestData; | 
|---|
|  |  |  | import cc.mrbird.febs.pay.service.IXcxPayService; | 
|---|
|  |  |  | import cn.hutool.core.bean.BeanUtil; | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.date.DateUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.IdUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.StrUtil; | 
|---|
|  |  |  | import cn.hutool.crypto.SecureUtil; | 
|---|
|  |  |  | import cn.hutool.crypto.asymmetric.KeyType; | 
|---|
|  |  |  | import cn.hutool.crypto.asymmetric.RSA; | 
|---|
|  |  |  | import cn.hutool.json.JSONUtil; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | 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.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.boot.autoconfigure.security.SecurityProperties; | 
|---|
|  |  |  | import org.springframework.http.HttpStatus; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author wzy | 
|---|
|  |  |  | 
|---|
|  |  |  | private final MallOrderInfoMapper mallOrderInfoMapper; | 
|---|
|  |  |  | private final MallShoppingCartMapper mallShoppingCartMapper; | 
|---|
|  |  |  | private final MallMoneyFlowMapper mallMoneyFlowMapper; | 
|---|
|  |  |  | private final IApiMallMemberWalletService walletService; | 
|---|
|  |  |  | private final MallMemberPaymentMapper mallMemberPaymentMapper; | 
|---|
|  |  |  | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; | 
|---|
|  |  |  | private final MallShopApplyMapper mallShopApplyMapper; | 
|---|
|  |  |  | private final MallRegisterAppealMapper mallRegisterAppealMapper; | 
|---|
|  |  |  | private final MallTeamLeaderMapper mallTeamLeaderMapper; | 
|---|
|  |  |  | private final SpringContextHolder springContextHolder; | 
|---|
|  |  |  | private final MallAgentRecordMapper mallAgentRecordMapper; | 
|---|
|  |  |  | private final IMallMoneyFlowService mallMoneyFlowService; | 
|---|
|  |  |  | private final IMallMemberCollectionService mallMemberCollectionService; | 
|---|
|  |  |  | private final IMallMemberFootprintService mallMemberFootprintService; | 
|---|
|  |  |  | private final SalemanCouponMapper salemanCouponMapper; | 
|---|
|  |  |  | private final CouponGoodsMapper couponGoodsMapper; | 
|---|
|  |  |  | private final MallGoodsCouponMapper mallGoodsCouponMapper; | 
|---|
|  |  |  | private final MallMemberCouponMapper mallMemberCouponMapper; | 
|---|
|  |  |  | private final MallGoodsMapper mallGoodsMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${spring.profiles.active}") | 
|---|
|  |  |  | private String active; | 
|---|
|  |  |  | 
|---|
|  |  |  | public FebsResponse register(RegisterDto registerDto) { | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectInfoByAccount(registerDto.getAccount()); | 
|---|
|  |  |  | if (mallMember != null) { | 
|---|
|  |  |  | throw new FebsException("该手机号/邮箱已被占用"); | 
|---|
|  |  |  | throw new FebsException("该账号已被占用"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallMember> mallMembers = this.baseMapper.selectMemberByName(registerDto.getName()); | 
|---|
|  |  |  | if (CollUtil.isNotEmpty(mallMembers)) { | 
|---|
|  |  |  | MallRegisterAppeal registerAppeal = mallRegisterAppealMapper.selectByPhoneAndName(registerDto.getName(), registerDto.getAccount()); | 
|---|
|  |  |  | if (registerAppeal == null || registerAppeal.getStatus() != 1) { | 
|---|
|  |  |  | return new FebsResponse().code(HttpStatus.ACCEPTED).message("用户名已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String account = registerDto.getAccount(); | 
|---|
|  |  |  | String code = registerDto.getCode(); | 
|---|
|  |  |  | boolean flags = commonService.verifyCode(account, code); | 
|---|
|  |  |  | if(!flags) { | 
|---|
|  |  |  | throw new FebsException("验证码错误"); | 
|---|
|  |  |  | if (!"admin".equals(registerDto.getRegistType())) { | 
|---|
|  |  |  | String code = registerDto.getCode(); | 
|---|
|  |  |  | boolean flags = commonService.verifyCode(account, code); | 
|---|
|  |  |  | if (!flags) { | 
|---|
|  |  |  | throw new FebsException("验证码错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallMember = new MallMember(); | 
|---|
|  |  |  | 
|---|
|  |  |  | mallMember.setReferrerId(registerDto.getInviteId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallMember.setName(registerDto.getAccount()); | 
|---|
|  |  |  | mallMember.setName(registerDto.getName()); | 
|---|
|  |  |  | mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE); | 
|---|
|  |  |  | mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL); | 
|---|
|  |  |  | mallMember.setLevel("1"); | 
|---|
|  |  |  | mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name()); | 
|---|
|  |  |  | mallMember.setSex("男"); | 
|---|
|  |  |  | mallMember.setBindPhone(registerDto.getAccount()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.baseMapper.insert(mallMember); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //推荐人和推荐人链 | 
|---|
|  |  |  | boolean flag = false; | 
|---|
|  |  |  | String parentId = mallMember.getReferrerId(); | 
|---|
|  |  |  | if (StrUtil.isBlank(parentId)) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String ids = ""; | 
|---|
|  |  |  | while (!flag) { | 
|---|
|  |  |  | if (StrUtil.isBlank(ids)) { | 
|---|
|  |  |  | 
|---|
|  |  |  | redisUtils.set(redisKey, token, 360000); | 
|---|
|  |  |  | Map<String, Object> authInfo = new HashMap<>(); | 
|---|
|  |  |  | authInfo.put("token", token); | 
|---|
|  |  |  | if ("dev".equals(active)) { | 
|---|
|  |  |  | authInfo.put("rasToken", generateAsaToken(token)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | authInfo.put("rasToken", generateAsaToken(token)); | 
|---|
|  |  |  | return new FebsResponse().success().data(authInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String generateAsaToken(String token) { | 
|---|
|  |  |  | RSA rsa = new RSA(null, AppContants.PUBLIC_KEY); | 
|---|
|  |  |  | return rsa.encryptBase64(token + "_" + System.currentTimeMillis(), KeyType.PublicKey); | 
|---|
|  |  |  | //        return rsa.encryptBase64(token + "_" + System.currentTimeMillis(), KeyType.PublicKey); | 
|---|
|  |  |  | //去掉时间戳 | 
|---|
|  |  |  | return rsa.encryptBase64(token, KeyType.PublicKey); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse logout() { | 
|---|
|  |  |  | Long id = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | redisUtils.del(AppContants.APP_LOGIN_PREFIX + id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String redisKey = AppContants.XCX_LOGIN_PREFIX + id; | 
|---|
|  |  |  | String existToken = redisUtils.getString(redisKey); | 
|---|
|  |  |  | if (StrUtil.isNotBlank(existToken)) { | 
|---|
|  |  |  | Object o = redisUtils.get(existToken); | 
|---|
|  |  |  | if (ObjectUtil.isNotEmpty(o)) { | 
|---|
|  |  |  | redisUtils.del(existToken); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | redisUtils.del(AppContants.XCX_LOGIN_PREFIX + id); | 
|---|
|  |  |  | redisUtils.del(AppContants.XCX_LOGIN_PHONE_PREFIX + id); | 
|---|
|  |  |  | return new FebsResponse().success().message("退出登录"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectById(id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberVo mallMemberVo = MallMemberConversion.INSTANCE.entityToVo(mallMember); | 
|---|
|  |  |  | if(StrUtil.isNotEmpty(mallMember.getReferrerId())){ | 
|---|
|  |  |  | MallMember referMember = this.baseMapper.selectInfoByInviteId(mallMember.getReferrerId()); | 
|---|
|  |  |  | if (referMember != null) { | 
|---|
|  |  |  | mallMemberVo.setReferrerName(referMember.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StrUtil.isNotBlank(mallMember.getTradePassword())) { | 
|---|
|  |  |  | mallMemberVo.setHasTradePwd(1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberPayment payment = mallMemberPaymentMapper.selectByMemberId(id); | 
|---|
|  |  |  | if (payment != null) { | 
|---|
|  |  |  | mallMemberVo.setHasPayment(1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MemberCollectionListDto memberCollectionListDto = new MemberCollectionListDto(); | 
|---|
|  |  |  | memberCollectionListDto.setPageNow(1); | 
|---|
|  |  |  | memberCollectionListDto.setPageSize(10); | 
|---|
|  |  |  | List<CollectionListVo> collectionList = mallMemberCollectionService.findMemberCollectionList(memberCollectionListDto); | 
|---|
|  |  |  | mallMemberVo.setCollectionCnt(CollUtil.isNotEmpty(collectionList) ? collectionList.size() : 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MemberFootprintListDto memberFootprintListDto = new MemberFootprintListDto(); | 
|---|
|  |  |  | memberFootprintListDto.setPageNow(1); | 
|---|
|  |  |  | memberFootprintListDto.setPageSize(10); | 
|---|
|  |  |  | List<FootprintListVo> footprintList = mallMemberFootprintService.findMemberFootprintList(memberFootprintListDto); | 
|---|
|  |  |  | mallMemberVo.setFootprintCnt(CollUtil.isNotEmpty(footprintList) ? footprintList.size() : 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallMember> mallMembers = this.baseMapper.selectByRefererId(mallMember.getInviteId()); | 
|---|
|  |  |  | mallMemberVo.setChildCnt(CollUtil.isNotEmpty(mallMembers) ? mallMembers.size() : 0); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(mallMemberVo.getId()); | 
|---|
|  |  |  | mallMemberVo.setBalance(wallet.getBalance()); | 
|---|
|  |  |  | //        mallMemberVo.setScore(wallet.getScore()); | 
|---|
|  |  |  | //        mallMemberVo.setPrizeScore(wallet.getPrizeScore()); | 
|---|
|  |  |  | //        mallMemberVo.setTotalCost(mallOrderInfoMapper.selectTotalAmount(id)); | 
|---|
|  |  |  | return new FebsResponse().success().data(mallMemberVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse setTradePwd(ForgetPwdDto forgetPwdDto) { | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectInfoByAccount(forgetPwdDto.getAccount()); | 
|---|
|  |  |  | MallMember memberId = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectById(memberId); | 
|---|
|  |  |  | if (mallMember == null) { | 
|---|
|  |  |  | throw new FebsException("账号不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectById(memberId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<TeamListVo> list = this.baseMapper.selectTeamListByInviteId(mallMember.getInviteId()); | 
|---|
|  |  |  | BigDecimal ownAmount = this.baseMapper.selectOwnOrderAmountByInviteId(mallMember.getInviteId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TeamListVo own = new TeamListVo(); | 
|---|
|  |  |  | own.setCreatedTime(mallMember.getCreatedTime()); | 
|---|
|  |  |  | own.setAmount(ownAmount); | 
|---|
|  |  |  | own.setName(mallMember.getName()); | 
|---|
|  |  |  | own.setPhone(mallMember.getPhone()); | 
|---|
|  |  |  | own.setInviteId(mallMember.getInviteId()); | 
|---|
|  |  |  | own.setIsCurrent(1); | 
|---|
|  |  |  | own.setCnt(this.baseMapper.selectOwnCntByInviteId(mallMember.getInviteId())); | 
|---|
|  |  |  | own.setOrderCnt(this.baseMapper.selectOwnOrderCntByInviteId(mallMember.getInviteId())); | 
|---|
|  |  |  | own.setId(mallMember.getId()); | 
|---|
|  |  |  | list.add(0, own); | 
|---|
|  |  |  | return new FebsResponse().success().data(list); | 
|---|
|  |  |  | MyTeamVo myTeamVo = new MyTeamVo(); | 
|---|
|  |  |  | myTeamVo.setTeam(list); | 
|---|
|  |  |  | myTeamVo.setMyAchieve(this.mallOrderInfoMapper.selectAmountOrTeamAmount(mallMember.getInviteId(), 1)); | 
|---|
|  |  |  | myTeamVo.setMyTeamAchieve(this.mallOrderInfoMapper.selectAmountOrTeamAmount(mallMember.getInviteId(), 2)); | 
|---|
|  |  |  | myTeamVo.setMyTeamCnt(this.baseMapper.selectAllChildAgentListByInviteId(mallMember.getInviteId()).size()); | 
|---|
|  |  |  | return new FebsResponse().success().data(myTeamVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public MyTeamVo teamListForMine(TeamListDto teamListDto) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status) { | 
|---|
|  |  |  | public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status, Integer flowType) { | 
|---|
|  |  |  | MallMoneyFlow flow = new MallMoneyFlow(); | 
|---|
|  |  |  | flow.setMemberId(memberId); | 
|---|
|  |  |  | flow.setAmount(amount); | 
|---|
|  |  |  | 
|---|
|  |  |  | flow.setRemark(remark); | 
|---|
|  |  |  | flow.setRtMemberId(rtMemberId); | 
|---|
|  |  |  | flow.setStatus(status); | 
|---|
|  |  |  | flow.setFlowType(flowType); | 
|---|
|  |  |  | mallMoneyFlowMapper.insert(flow); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void transfer(TransferDto transferDto) { | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectInfoByAccount(transferDto.getAccount()); | 
|---|
|  |  |  | if (mallMember == null) { | 
|---|
|  |  |  | throw new FebsException("用户不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | MallMember loginMember = this.baseMapper.selectById(memberId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (loginMember.getPhone().equals(transferDto.getAccount()) || loginMember.getInviteId().equals(transferDto.getAccount())) { | 
|---|
|  |  |  | throw new FebsException("不能给自己转账"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StrUtil.isBlank(loginMember.getTradePassword())) { | 
|---|
|  |  |  | throw new FebsException("未设置支付密码"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!loginMember.getTradePassword().equals(SecureUtil.md5(transferDto.getTradePwd()))) { | 
|---|
|  |  |  | throw new FebsException("支付密码错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | walletService.reduceBalance(transferDto.getAmount(), memberId); | 
|---|
|  |  |  | String orderNo = MallUtils.getOrderNum("T"); | 
|---|
|  |  |  | this.addMoneyFlow(memberId, transferDto.getAmount().negate(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, mallMember.getId(), null, FlowTypeEnum.BALANCE.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | walletService.addBalance(transferDto.getAmount(), mallMember.getId()); | 
|---|
|  |  |  | this.addMoneyFlow(mallMember.getId(), transferDto.getAmount(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, memberId, null, FlowTypeEnum.BALANCE.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void setPayment(MallMemberPayment mallMemberPayment) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberPayment exist = mallMemberPaymentMapper.selectByMemberId(member.getId()); | 
|---|
|  |  |  | if (exist == null) { | 
|---|
|  |  |  | mallMemberPayment.setMemberId(member.getId()); | 
|---|
|  |  |  | mallMemberPaymentMapper.insert(mallMemberPayment); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | mallMemberPayment.setId(exist.getId()); | 
|---|
|  |  |  | mallMemberPaymentMapper.updateById(mallMemberPayment); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public MallMemberPayment findMemberPayment() { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  | return mallMemberPaymentMapper.selectByMemberId(member.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void bindPhone(AccountAndCodeDto accountAndCodeDto) { | 
|---|
|  |  |  | boolean b = commonService.verifyCode(accountAndCodeDto.getAccount(), accountAndCodeDto.getCode()); | 
|---|
|  |  |  | if (!b) { | 
|---|
|  |  |  | throw new FebsException("验证码错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long id = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | MallMember member = this.baseMapper.selectById(id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | member.setPhone(accountAndCodeDto.getAccount()); | 
|---|
|  |  |  | this.baseMapper.updateById(member); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public BigDecimal canMoney() { | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); | 
|---|
|  |  |  | return wallet.getBalance().setScale(2,BigDecimal.ROUND_DOWN); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<MallMember> findRankList(RankListDto rankListDto) { | 
|---|
|  |  |  | IPage<MallMember> page = new Page<>(rankListDto.getPageNum(), rankListDto.getPageSize()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMember member = new MallMember(); | 
|---|
|  |  |  | member.setQuery("2"); | 
|---|
|  |  |  | member.setCreatedTime(new Date()); | 
|---|
|  |  |  | IPage<MallMember> list = this.baseMapper.selectRankListInPage(page, member); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return list.getRecords(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public MallMember findMemberInfoByAccount(String phone) { | 
|---|
|  |  |  | return this.baseMapper.selectInfoByAccount(phone); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public MyCommissionVo myCommission() { | 
|---|
|  |  |  | Long id = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectById(id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MyCommissionVo commissionVo = MallMemberConversion.INSTANCE.entityToCommissionVo(mallMember); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMember referMember = this.baseMapper.selectInfoByInviteId(mallMember.getReferrerId()); | 
|---|
|  |  |  | if (referMember != null) { | 
|---|
|  |  |  | commissionVo.setReferrerName(referMember.getName()); | 
|---|
|  |  |  | commissionVo.setAvatar(referMember.getAvatar()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.AGENT_LEVEL, mallMember.getLevel()); | 
|---|
|  |  |  | if (dic != null) { | 
|---|
|  |  |  | commissionVo.setLevelName(dic.getDescription()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(id); | 
|---|
|  |  |  | commissionVo.setCommission(wallet.getCommission()); | 
|---|
|  |  |  | commissionVo.setToday(mallMoneyFlowMapper.selectCommissionIncome(1, new Date(), id)); | 
|---|
|  |  |  | commissionVo.setMonth(mallMoneyFlowMapper.selectCommissionIncome(2, new Date(), id)); | 
|---|
|  |  |  | commissionVo.setTotal(mallMoneyFlowMapper.selectCommissionIncome(null, null, id)); | 
|---|
|  |  |  | commissionVo.setWaitCommission(BigDecimal.ZERO); | 
|---|
|  |  |  | return commissionVo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void shopApply(ShopApplyDto shopApplyDto) { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallShopApply hasApply = mallShopApplyMapper.selectNewestApplyByMemberId(member.getId()); | 
|---|
|  |  |  | if (hasApply != null) { | 
|---|
|  |  |  | if (!hasApply.getStatus().equals(MallShopApply.APPLY_DISAGREE)) { | 
|---|
|  |  |  | throw new FebsException("请勿重复提交申请"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallShopApply mallShopApply = new MallShopApply(); | 
|---|
|  |  |  | BeanUtil.copyProperties(shopApplyDto, mallShopApply); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallShopApply.setStatus(MallShopApply.APPLY_ING); | 
|---|
|  |  |  | mallShopApply.setMemberId(member.getId()); | 
|---|
|  |  |  | mallShopApplyMapper.insert(mallShopApply); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public MallShopApply findNewestApply() { | 
|---|
|  |  |  | MallMember member = LoginUserUtil.getLoginUser(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return mallShopApplyMapper.selectNewestApplyByMemberId(member.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addRegisterAppeal(RegisterAppealDto registerAppeal) { | 
|---|
|  |  |  | MallRegisterAppeal isExist = mallRegisterAppealMapper.selectByPhoneAndName(registerAppeal.getName(), registerAppeal.getPhone()); | 
|---|
|  |  |  | if (isExist != null) { | 
|---|
|  |  |  | throw new FebsException("申诉已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | isExist = new MallRegisterAppeal(); | 
|---|
|  |  |  | isExist.setName(registerAppeal.getName()); | 
|---|
|  |  |  | isExist.setPhone(registerAppeal.getPhone()); | 
|---|
|  |  |  | isExist.setStatus(2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallRegisterAppealMapper.insert(isExist); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public CashOutSettingVo cashOutSetting() { | 
|---|
|  |  |  | CashOutSettingVo cashOutSettingVo = new CashOutSettingVo(); | 
|---|
|  |  |  | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.CASHOUT_SETTING.getType(), DataDictionaryEnum.CASHOUT_SETTING.getCode()); | 
|---|
|  |  |  | if (dic != null) { | 
|---|
|  |  |  | cashOutSettingVo = JSONObject.parseObject(dic.getValue(), CashOutSettingVo.class); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return cashOutSettingVo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ShopListVo> findShopListVo(ShopListDto shopListDto) { | 
|---|
|  |  |  | Page<MallShopApply> page = new Page<>(shopListDto.getPageNow(), shopListDto.getPageSize()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallShopApply shopApply = new MallShopApply(); | 
|---|
|  |  |  | shopApply.setStatus(MallShopApply.APPLY_AGREE); | 
|---|
|  |  |  | IPage<MallShopApply> pageResult = mallShopApplyMapper.selectShopApplyInPage(shopApply, page); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallShopApply> list = pageResult.getRecords(); | 
|---|
|  |  |  | if (CollUtil.isEmpty(list)) { | 
|---|
|  |  |  | list = new ArrayList<>(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return MallShopApplyConversion.INSTANCE.entitiesToVOs(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final XcxProperties xcxProperties = SpringContextHolder.getBean(XcxProperties.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse xcxLogin(ApiXcxLoginDto apiXcxLoginDto) throws IOException { | 
|---|
|  |  |  | log.info("登录请求参数:{}", JSONObject.toJSONString(apiXcxLoginDto)); | 
|---|
|  |  |  | FebsResponse febsResponse = new FebsResponse(); | 
|---|
|  |  |  | String code = apiXcxLoginDto.getCode(); | 
|---|
|  |  |  | log.info("code:" + code); | 
|---|
|  |  |  | if (StrUtil.isNotBlank(code)) { | 
|---|
|  |  |  | String requrl = getXcxLoginUrl(code); | 
|---|
|  |  |  | String reslutData = HttpCurlUtil.sendGetHttp(requrl, null); | 
|---|
|  |  |  | net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(reslutData); | 
|---|
|  |  |  | log.info("微信登录获取到登录信息={}", json); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (json.containsKey("errcode")) { | 
|---|
|  |  |  | log.info("微信登录获取到异常信息errcode"); | 
|---|
|  |  |  | return febsResponse.fail().message("自动登录失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String openId = json.getString("openid"); | 
|---|
|  |  |  | String sessionKey = json.getString("session_key"); | 
|---|
|  |  |  | log.info("openId={},sessionKey={}", openId, sessionKey); | 
|---|
|  |  |  | // 查询用户是否存在 | 
|---|
|  |  |  | MallMember mallMember = null; | 
|---|
|  |  |  | synchronized (this) { | 
|---|
|  |  |  | mallMember = this.baseMapper.selectMemberByOpenId(openId); | 
|---|
|  |  |  | if (ObjectUtil.isEmpty(mallMember)) { | 
|---|
|  |  |  | // 新增用户 | 
|---|
|  |  |  | mallMember = new MallMember(); | 
|---|
|  |  |  | mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE); | 
|---|
|  |  |  | mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL); | 
|---|
|  |  |  | mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name()); | 
|---|
|  |  |  | mallMember.setOpenId(openId); | 
|---|
|  |  |  | mallMember.setSessionKey(sessionKey); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StrUtil.isNotBlank(apiXcxLoginDto.getInviteId())) { | 
|---|
|  |  |  | MallMember member = this.baseMapper.selectInfoByInviteId(apiXcxLoginDto.getInviteId()); | 
|---|
|  |  |  | if (member != null) { | 
|---|
|  |  |  | mallMember.setReferrerId(member.getInviteId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //推荐人和推荐人链 | 
|---|
|  |  |  | boolean flag = false; | 
|---|
|  |  |  | String parentId = mallMember.getReferrerId(); | 
|---|
|  |  |  | if (StrUtil.isBlank(parentId)) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String ids = ""; | 
|---|
|  |  |  | while (!flag) { | 
|---|
|  |  |  | if (StrUtil.isBlank(ids)) { | 
|---|
|  |  |  | ids += parentId; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | ids += ("," + parentId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MallMember parentMember = this.baseMapper.selectInfoByInviteId(parentId); | 
|---|
|  |  |  | if (parentMember == null) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | parentId = parentMember.getReferrerId(); | 
|---|
|  |  |  | if (StrUtil.isBlank(parentMember.getReferrerId())) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StrUtil.isNotBlank(ids)) { | 
|---|
|  |  |  | mallMember.setReferrerIds(ids); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.baseMapper.insert(mallMember); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | mallMember = this.baseMapper.selectMemberByOpenId(openId); | 
|---|
|  |  |  | String inviteId = ShareCodeUtil.toSerialCode(mallMember.getId()); | 
|---|
|  |  |  | mallMember.setInviteId(inviteId); | 
|---|
|  |  |  | this.baseMapper.updateById(mallMember); | 
|---|
|  |  |  | MallMemberWallet wallet = new MallMemberWallet(); | 
|---|
|  |  |  | wallet.setBalance(BigDecimal.ZERO); | 
|---|
|  |  |  | wallet.setMemberId(mallMember.getId()); | 
|---|
|  |  |  | mallMemberWalletMapper.insert(wallet); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | mallMember.setSessionKey(sessionKey); | 
|---|
|  |  |  | this.baseMapper.updateById(mallMember); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 存放redis | 
|---|
|  |  |  | String redisKey = AppContants.XCX_LOGIN_PREFIX + mallMember.getId(); | 
|---|
|  |  |  | String existToken = redisUtils.getString(redisKey); | 
|---|
|  |  |  | if (StrUtil.isNotBlank(existToken)) { | 
|---|
|  |  |  | Object o = redisUtils.get(existToken); | 
|---|
|  |  |  | if (ObjectUtil.isNotEmpty(o)) { | 
|---|
|  |  |  | redisUtils.del(existToken); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = IdUtil.simpleUUID(); | 
|---|
|  |  |  | redisUtils.set(token, JSONObject.toJSONString(mallMember), -1); | 
|---|
|  |  |  | redisUtils.set(redisKey, token, -1); | 
|---|
|  |  |  | Map<String, Object> authInfo = new HashMap<>(); | 
|---|
|  |  |  | authInfo.put("token", token); | 
|---|
|  |  |  | authInfo.put("appid", xcxProperties.getXcxAppid()); | 
|---|
|  |  |  | authInfo.put("member", mallMember); | 
|---|
|  |  |  | authInfo.put("rasToken", generateAsaToken(token)); | 
|---|
|  |  |  | febsResponse.success().data(authInfo); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return febsResponse.fail().message("自动登录失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return febsResponse; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse xcxSaveInfo(ApiXcxSaveInfoDto apiXcxSaveInfoDto) { | 
|---|
|  |  |  | log.info("name={},phone={},avatar={},sex={}", | 
|---|
|  |  |  | apiXcxSaveInfoDto.getNickName(),apiXcxSaveInfoDto.getPhone(),apiXcxSaveInfoDto.getAvatarUrl(),apiXcxSaveInfoDto.getGender()); | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectById(memberId); | 
|---|
|  |  |  | String nickName = apiXcxSaveInfoDto.getNickName(); | 
|---|
|  |  |  | if(StrUtil.isNotEmpty(nickName)){ | 
|---|
|  |  |  | mallMember.setName(nickName); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String phone = apiXcxSaveInfoDto.getPhone(); | 
|---|
|  |  |  | if(StrUtil.isNotEmpty(phone)){ | 
|---|
|  |  |  | mallMember.setPhone(phone); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String avatarUrl = apiXcxSaveInfoDto.getAvatarUrl(); | 
|---|
|  |  |  | if(StrUtil.isNotEmpty(avatarUrl)){ | 
|---|
|  |  |  | mallMember.setAvatar(avatarUrl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        mallMember.setSex(1 == apiXcxSaveInfoDto.getGender() ? "女" : "男"); | 
|---|
|  |  |  | this.baseMapper.updateById(mallMember); | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse xcxPhoneLogin(ApiXcxPhoneLoginDto apiXcxPhoneLoginDto) { | 
|---|
|  |  |  | String phone = apiXcxPhoneLoginDto.getPhone(); | 
|---|
|  |  |  | boolean flag = commonService.verifyCode(phone, apiXcxPhoneLoginDto.getCode()); | 
|---|
|  |  |  | if (flag) { | 
|---|
|  |  |  | // 查询用户是否存在 | 
|---|
|  |  |  | MallMember mallMember = null; | 
|---|
|  |  |  | synchronized (this) { | 
|---|
|  |  |  | mallMember = this.baseMapper.selectInfoByAccount(apiXcxPhoneLoginDto.getPhone()); | 
|---|
|  |  |  | if (ObjectUtil.isEmpty(mallMember)) { | 
|---|
|  |  |  | // 新增用户 | 
|---|
|  |  |  | mallMember = new MallMember(); | 
|---|
|  |  |  | mallMember.setPhone(phone); | 
|---|
|  |  |  | mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE); | 
|---|
|  |  |  | mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL); | 
|---|
|  |  |  | mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name()); | 
|---|
|  |  |  | this.baseMapper.insert(mallMember); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String inviteId = ShareCodeUtil.toSerialCode(mallMember.getId()); | 
|---|
|  |  |  | mallMember.setInviteId(inviteId); | 
|---|
|  |  |  | this.baseMapper.updateById(mallMember); | 
|---|
|  |  |  | MallMemberWallet wallet = new MallMemberWallet(); | 
|---|
|  |  |  | wallet.setBalance(BigDecimal.ZERO); | 
|---|
|  |  |  | wallet.setMemberId(mallMember.getId()); | 
|---|
|  |  |  | mallMemberWalletMapper.insert(wallet); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 存放redis | 
|---|
|  |  |  | String redisKey = AppContants.XCX_LOGIN_PHONE_PREFIX + mallMember.getId(); | 
|---|
|  |  |  | String existToken = redisUtils.getString(redisKey); | 
|---|
|  |  |  | if (StrUtil.isNotBlank(existToken)) { | 
|---|
|  |  |  | Object o = redisUtils.get(existToken); | 
|---|
|  |  |  | if (ObjectUtil.isNotEmpty(o)) { | 
|---|
|  |  |  | redisUtils.del(existToken); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = IdUtil.simpleUUID(); | 
|---|
|  |  |  | redisUtils.set(token, JSONObject.toJSONString(mallMember), 360000); | 
|---|
|  |  |  | redisUtils.set(redisKey, token, 360000); | 
|---|
|  |  |  | Map<String, Object> authInfo = new HashMap<>(); | 
|---|
|  |  |  | authInfo.put("token", token); | 
|---|
|  |  |  | authInfo.put("member", mallMember); | 
|---|
|  |  |  | authInfo.put("rasToken", generateAsaToken(token)); | 
|---|
|  |  |  | return new FebsResponse().success().data(authInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new FebsResponse().fail().message("验证码错误"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse xcxOpen(ApiXcxOpenDto apiXcxOpenDto) { | 
|---|
|  |  |  | DataDictionaryCustom rangeSwitch = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANGE_SWITCH.getType(), DataDictionaryEnum.RANGE_SWITCH.getCode()); | 
|---|
|  |  |  | if(StrUtil.isNotBlank(rangeSwitch.getValue()) && "1".equals(rangeSwitch.getValue())){ | 
|---|
|  |  |  | if(ObjectUtil.isNull(apiXcxOpenDto.getLongitude()) || ObjectUtil.isNull(apiXcxOpenDto.getLatitude())){ | 
|---|
|  |  |  | return new FebsResponse().fail().message("请授权位置信息"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Double longitude = apiXcxOpenDto.getLongitude(); | 
|---|
|  |  |  | Double latitude = apiXcxOpenDto.getLatitude(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | DataDictionaryCustom rangeSize = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.RANGE_SIZE.getType(), DataDictionaryEnum.RANGE_SIZE.getCode()); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(rangeSize)){ | 
|---|
|  |  |  | return new FebsResponse().success().data(2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(StrUtil.isBlank(rangeSize.getValue())){ | 
|---|
|  |  |  | return new FebsResponse().success().data(2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //方位大小,换成单位:米 | 
|---|
|  |  |  | Integer value = Integer.parseInt(rangeSize.getValue()) * 1000; | 
|---|
|  |  |  | //根据经纬度获取周围团长的距离 | 
|---|
|  |  |  | MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByLonAndLat(longitude, latitude); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(mallTeamLeader)){ | 
|---|
|  |  |  | return new FebsResponse().success().data(2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Double distance = mallTeamLeader.getDistance(); | 
|---|
|  |  |  | if(value <= distance){ | 
|---|
|  |  |  | return new FebsResponse().success().data(2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new FebsResponse().success().data(1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final IXcxPayService iXcxPayService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public FebsResponse rechargeWallet(ApiRechargeWalletDto apiRechargeWalletDto) { | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | BigDecimal amount = apiRechargeWalletDto.getAmount(); | 
|---|
|  |  |  | if(BigDecimal.ZERO.compareTo(amount)>0){ | 
|---|
|  |  |  | return new FebsResponse().fail().message("请输入正确的充值金额"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer type = apiRechargeWalletDto.getType(); | 
|---|
|  |  |  | if(2 == type){ | 
|---|
|  |  |  | //成为合伙人的充值金额 | 
|---|
|  |  |  | MallAgentRecord mallAgentRecord = mallAgentRecordMapper.selectById(apiRechargeWalletDto.getAgentApplyId()); | 
|---|
|  |  |  | BigDecimal agentPrice = mallAgentRecord.getAmount(); | 
|---|
|  |  |  | //            DataDictionaryCustom agentPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.PRICE_AMOUNT.getType(), | 
|---|
|  |  |  | //                    DataDictionaryEnum.PRICE_AMOUNT.getCode()); | 
|---|
|  |  |  | //            String agentPrice = agentPriceDic.getValue(); | 
|---|
|  |  |  | //            BigDecimal price = new BigDecimal(agentPrice); | 
|---|
|  |  |  | if(agentPrice.compareTo(amount) != 0){ | 
|---|
|  |  |  | return new FebsResponse().fail().message("成为合伙人的金额为"+agentPrice); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String rechargeNo = "CZ_"+MallUtils.getOrderNum(); | 
|---|
|  |  |  | apiRechargeWalletDto.setRechargeNo(rechargeNo); | 
|---|
|  |  |  | apiRechargeWalletDto.setMemberId(memberId); | 
|---|
|  |  |  | BrandWCPayRequestData brandWCPayRequestData = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | brandWCPayRequestData = iXcxPayService.startRechargeWallet(apiRechargeWalletDto); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | throw new FebsException("支付失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallMoneyFlowService.addMoneyFlow( | 
|---|
|  |  |  | memberId, | 
|---|
|  |  |  | amount, | 
|---|
|  |  |  | MoneyFlowTypeEnum.RECHARGE.getValue(), | 
|---|
|  |  |  | rechargeNo, | 
|---|
|  |  |  | FlowTypeEnum.BALANCE.getValue(), | 
|---|
|  |  |  | "余额充值",1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData); | 
|---|
|  |  |  | String payResultStr = brandWCPayRequestData.getPrepay_id(); | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("orderInfo", payResultStr); | 
|---|
|  |  |  | map.put("wxResultStr", wxResultStr); | 
|---|
|  |  |  | return new FebsResponse().success().data(map).message("充值即将到账"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateMemberAgent(Long memberId,String levelCode) { | 
|---|
|  |  |  | mallAgentRecordMapper.updateStateByMemberId(memberId); | 
|---|
|  |  |  | MallAgentRecord mallAgentRecord = mallAgentRecordMapper.selectById(memberId); | 
|---|
|  |  |  | //更新用户表中的LEVEL | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectById(mallAgentRecord.getMemberId()); | 
|---|
|  |  |  | mallMember.setLevel(levelCode); | 
|---|
|  |  |  | this.baseMapper.updateById(mallMember); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse agentDetail() { | 
|---|
|  |  |  | DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.AGENT_DETAILS.getType(), DataDictionaryEnum.AGENT_DETAILS.getCode()); | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(dataDictionaryCustom)){ | 
|---|
|  |  |  | map.put("agentDetail", dataDictionaryCustom.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new FebsResponse().success().data(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse activityInfo() { | 
|---|
|  |  |  | DataDictionaryCustom activityBulletinDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.ACTIVITY_BULLETIN.getType(), DataDictionaryEnum.ACTIVITY_BULLETIN.getCode()); | 
|---|
|  |  |  | DataDictionaryCustom giveAmountDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.GIVE_AMOUNT.getType(), DataDictionaryEnum.GIVE_AMOUNT.getCode()); | 
|---|
|  |  |  | DataDictionaryCustom giveStateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( | 
|---|
|  |  |  | DataDictionaryEnum.GIVE_STATE.getType(), DataDictionaryEnum.GIVE_STATE.getCode()); | 
|---|
|  |  |  | Map<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(activityBulletinDic)){ | 
|---|
|  |  |  | map.put("activityBulletin", | 
|---|
|  |  |  | ObjectUtil.isEmpty(activityBulletinDic.getValue()) ? "暂无活动" : activityBulletinDic.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(giveAmountDic)){ | 
|---|
|  |  |  | map.put("giveAmount", | 
|---|
|  |  |  | ObjectUtil.isEmpty(giveAmountDic.getValue()) ? 0 : giveAmountDic.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | map.put("giveState",giveStateDic.getValue()); | 
|---|
|  |  |  | return new FebsResponse().success().data(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse agentApplyInfo() { | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | ApiMallAgentRecordVo apiMallAgentRecordVo = mallAgentRecordMapper.selectApiMallAgentRecordVoByMemberIdAndState(memberId,MallAgentRecord.APPLY_ING); | 
|---|
|  |  |  | return new FebsResponse().success().data(apiMallAgentRecordVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse getCoupon(GetCouponDto getCouponDto) { | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String couponUUID = IdUtil.simpleUUID(); | 
|---|
|  |  |  | //        String couponUUID = getCouponDto.getCouponUUID(); | 
|---|
|  |  |  | //        QueryWrapper<MallMemberCoupon> objectQueryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | //        objectQueryWrapper.eq("coupon_uuid",couponUUID); | 
|---|
|  |  |  | //        List<MallMemberCoupon> mallMemberCouponDone = mallMemberCouponMapper.selectList(objectQueryWrapper); | 
|---|
|  |  |  | //        if(CollUtil.isNotEmpty(mallMemberCouponDone)){ | 
|---|
|  |  |  | //            return new FebsResponse().success(); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //通过邀请人信息,获取能领取的优惠卷信息 | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectInfoByInviteId(getCouponDto.getInviteId()); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallMember)){ | 
|---|
|  |  |  | SalemanCoupon salemanCoupon = salemanCouponMapper.selectByMemberId(mallMember.getId()); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(salemanCoupon)){ | 
|---|
|  |  |  | Long couponId = salemanCoupon.getCouponId(); | 
|---|
|  |  |  | Long goodsId = getCouponDto.getGoodsId(); | 
|---|
|  |  |  | MallGoods mallGoods = mallGoodsMapper.selectById(goodsId); | 
|---|
|  |  |  | //验证商品存不存在,且上没上架 | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallGoods) | 
|---|
|  |  |  | && MallGoods.ISSALE_STATUS_ENABLE == mallGoods.getIsSale()){ | 
|---|
|  |  |  | //                List<MallMemberCoupon> mallMemberCoupons = mallMemberCouponMapper.selectListByMemberIdAndGoodsIdAndCouponId(memberId, goodsId, couponId,mallMember.getInviteId()); | 
|---|
|  |  |  | //                List<MallMemberCoupon> mallMemberCoupons = mallMemberCouponMapper.selectListByMemberIdAndGoodsIdAndCouponIdWithOutInviteId(memberId, goodsId, couponId); | 
|---|
|  |  |  | List<MallMemberCoupon> mallMemberCoupons = mallMemberCouponMapper.selectListByMemberIdAndGoodsIdAndCouponIdWithOutInviteId(memberId, goodsId); | 
|---|
|  |  |  | if(CollUtil.isEmpty(mallMemberCoupons)){ | 
|---|
|  |  |  | //商品优惠卷如果绑定了,那么当前登陆者获取一张卷 | 
|---|
|  |  |  | List<CouponGoods> couponGoodsList = couponGoodsMapper.selectByGoodIdAndCouponId(goodsId,couponId); | 
|---|
|  |  |  | MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(couponId); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(couponGoodsList)){ | 
|---|
|  |  |  | MallMemberCoupon mallMemberCoupon = new MallMemberCoupon(); | 
|---|
|  |  |  | mallMemberCoupon.setCouponId(couponId); | 
|---|
|  |  |  | mallMemberCoupon.setCouponName(mallGoodsCoupon.getName()); | 
|---|
|  |  |  | mallMemberCoupon.setMemberId(memberId); | 
|---|
|  |  |  | mallMemberCoupon.setGoodsId(goodsId); | 
|---|
|  |  |  | mallMemberCoupon.setCouponUuid(couponUUID); | 
|---|
|  |  |  | mallMemberCoupon.setInviteId(mallMember.getInviteId()); | 
|---|
|  |  |  | mallMemberCoupon.setState(1); | 
|---|
|  |  |  | mallMemberCoupon.setExpireTime(DateUtil.offsetDay(DateUtil.date(),mallGoodsCoupon.getExpireDay())); | 
|---|
|  |  |  | mallMemberCouponMapper.insert(mallMemberCoupon); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse scanCoupon(GetCouponDto getCouponDto) { | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | String couponUUID = IdUtil.simpleUUID(); | 
|---|
|  |  |  | //通过邀请人信息,获取能领取的优惠卷信息 | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectInfoByInviteId(getCouponDto.getInviteId()); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallMember)){ | 
|---|
|  |  |  | SalemanCoupon salemanCoupon = salemanCouponMapper.selectByMemberId(mallMember.getId()); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(salemanCoupon)){ | 
|---|
|  |  |  | Long couponId = salemanCoupon.getCouponId(); | 
|---|
|  |  |  | List<MallMemberCoupon> mallMemberCoupons = mallMemberCouponMapper.selectListByMemberIdCouponIdWithOutInviteId(memberId, couponId); | 
|---|
|  |  |  | if(CollUtil.isEmpty(mallMemberCoupons)){ | 
|---|
|  |  |  | //商品优惠卷如果绑定了,那么当前登陆者获取一张卷 | 
|---|
|  |  |  | MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(couponId); | 
|---|
|  |  |  | MallMemberCoupon mallMemberCoupon = new MallMemberCoupon(); | 
|---|
|  |  |  | mallMemberCoupon.setCouponId(couponId); | 
|---|
|  |  |  | mallMemberCoupon.setCouponName(mallGoodsCoupon.getName()); | 
|---|
|  |  |  | mallMemberCoupon.setMemberId(memberId); | 
|---|
|  |  |  | mallMemberCoupon.setCouponUuid(couponUUID); | 
|---|
|  |  |  | mallMemberCoupon.setInviteId(mallMember.getInviteId()); | 
|---|
|  |  |  | mallMemberCoupon.setState(1); | 
|---|
|  |  |  | mallMemberCoupon.setExpireTime(DateUtil.offsetDay(DateUtil.date(),mallGoodsCoupon.getExpireDay())); | 
|---|
|  |  |  | mallMemberCouponMapper.insert(mallMemberCoupon); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse memberCoupon(MallMemberCouponDto mallMemberCouponDto) { | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | IPage<MallMemberCouponVo> page = new Page<>(mallMemberCouponDto.getPageNum(), mallMemberCouponDto.getPageSize()); | 
|---|
|  |  |  | mallMemberCouponDto.setMemberId(memberId); | 
|---|
|  |  |  | mallMemberCouponDto.setExpireTime(DateUtil.date()); | 
|---|
|  |  |  | IPage<MallMemberCouponVo> pages = mallMemberCouponMapper.selectListInPage(page, mallMemberCouponDto); | 
|---|
|  |  |  | return new FebsResponse().success().data(pages); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse couponDetails(Long id) { | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(id); | 
|---|
|  |  |  | MallMemberCouponVo mallMemberCouponVo = new MallMemberCouponVo(); | 
|---|
|  |  |  | mallMemberCouponVo.setCouponName(mallMemberCoupon.getCouponName()); | 
|---|
|  |  |  | MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(mallMemberCoupon.getCouponId()); | 
|---|
|  |  |  | mallMemberCouponVo.setCostAmount(mallGoodsCoupon.getCostAmount()); | 
|---|
|  |  |  | mallMemberCouponVo.setRealAmount(mallGoodsCoupon.getRealAmount()); | 
|---|
|  |  |  | return new FebsResponse().success().data(mallMemberCouponVo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse setInvite(ApiSetInviteDto apiSetInviteDto) { | 
|---|
|  |  |  | Long memberId = LoginUserUtil.getLoginUser().getId(); | 
|---|
|  |  |  | MallMember mallMember = this.baseMapper.selectById(memberId); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallMember.getReferrerId())){ | 
|---|
|  |  |  | throw new FebsException("已绑定"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String inviteId = apiSetInviteDto.getInviteId(); | 
|---|
|  |  |  | if(inviteId.equals(mallMember.getInviteId())){ | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MallMember member = this.baseMapper.selectInfoByInviteId(inviteId); | 
|---|
|  |  |  | if (member != null) { | 
|---|
|  |  |  | if (StrUtil.isNotBlank(member.getReferrerIds()) && member.getReferrerIds().contains(mallMember.getInviteId())) { | 
|---|
|  |  |  | log.info("下级不能邀请上级"); | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mallMember.setReferrerId(member.getInviteId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //推荐人和推荐人链 | 
|---|
|  |  |  | boolean flag = false; | 
|---|
|  |  |  | String parentId = mallMember.getReferrerId(); | 
|---|
|  |  |  | if (StrUtil.isBlank(parentId)) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String ids = ""; | 
|---|
|  |  |  | while (!flag) { | 
|---|
|  |  |  | if (StrUtil.isBlank(ids)) { | 
|---|
|  |  |  | ids += parentId; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | ids += ("," + parentId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | MallMember parentMember = this.baseMapper.selectInfoByInviteId(parentId); | 
|---|
|  |  |  | if (parentMember == null) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | parentId = parentMember.getReferrerId(); | 
|---|
|  |  |  | if (StrUtil.isBlank(parentMember.getReferrerId())) { | 
|---|
|  |  |  | flag = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StrUtil.isNotBlank(ids)) { | 
|---|
|  |  |  | mallMember.setReferrerIds(ids); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.baseMapper.updateById(mallMember); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private  String getXcxLoginUrl(String code) { | 
|---|
|  |  |  | String wechatLoginUrl =xcxProperties.getWecharLoginUrl(); | 
|---|
|  |  |  | return String.format(wechatLoginUrl, xcxProperties.getXcxAppid(), xcxProperties.getXcxSecret(), code); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|