xiaoyong931011
2023-07-28 0290bb9994709f504e7b98c09f89f089560f8158
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
@@ -604,7 +604,56 @@
            // 查询用户是否存在
            MallMember mallMember = this.baseMapper.selectMemberByOpenId(openId);
            if (ObjectUtil.isEmpty(mallMember)) {
                return febsResponse.fail().message("请先关注公众号");
                //根据OPENID,查询用户信息,如果存在,直接返回
                mallMember = new MallMember();
                mallMember.setPassword(SecureUtil.md5("a123456"));
                mallMember.setName("微信用户");
                mallMember.setSubStatus(MallMember.SUB_STATUS_DISABLED);
                mallMember.setReferrerId(null);
                mallMember.setPhone(null);
                mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE);
                mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL);
                mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name());
                mallMember.setSex("男");
                mallMember.setBindPhone(null);
                mallMember.setOpenId(openId);
                this.baseMapper.insert(mallMember);
                //生成邀请码
                String inviteId = ShareCodeUtil.toSerialCode(mallMember.getId());
                mallMember.setInviteId(inviteId);
                //推荐人和推荐人链
                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);
                //初始化钱包信息
                MallMemberWallet wallet = new MallMemberWallet();
                wallet.setBalance(BigDecimal.ZERO);
                wallet.setMemberId(mallMember.getId());
                mallMemberWalletMapper.insert(wallet);
                return new FebsResponse().fail().message("请先关注公众号");
            }
            // 存放redis
            String redisKey = AppContants.XCX_LOGIN_PREFIX + mallMember.getId();