44323
2023-10-30 21ee583563d59d9d04840f65cb0053df9b183554
cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
@@ -1,6 +1,7 @@
package com.dsh.account.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
@@ -14,7 +15,9 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsh.account.dto.BindDto;
import com.dsh.account.dto.SelectDto;
import com.dsh.account.dto.UpdateInfoDto;
import com.dsh.account.dto.UserInfoQueryDTO;
import com.dsh.account.entity.*;
import com.dsh.account.enums.RechargeRecordEnum;
@@ -411,11 +414,14 @@
        tAppUser.setIsVip(0);
        tAppUser.setState(1);
        tAppUser.setInsertTime(new Date());
        this.baseMapper.insert(tAppUser);
        // 介绍有礼
        if(addAppUserVo.getReferralUserId()!=null){
        if(addAppUserVo.getReferralUserId()!=null || ToolUtil.isNotEmpty(addAppUserVo.getInvitePhone())){
            if(ToolUtil.isEmpty(addAppUserVo.getLat()) || ToolUtil.isEmpty(addAppUserVo.getLon())){
                return ResultUtil.error("请先开启定位", "");
            }
            Map<String, String> geocode = gdMapGeocodingUtil.geocode(addAppUserVo.getLon(), addAppUserVo.getLat());
            Integer num=0;
            if(null != geocode){
@@ -424,6 +430,12 @@
                String city = geocode.get("city");
                String cityCode = geocode.get("cityCode");
                 num =  introduceRewardsClient.getGiftList(cityCode);
            }
            if(ToolUtil.isNotEmpty(addAppUserVo.getInvitePhone())){
                List<TAppUser> tAppUsers = this.baseMapper.selectList(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, addAppUserVo.getInvitePhone()));
                if(tAppUsers.size()>0){
                    addAppUserVo.setReferralUserId(tAppUsers.get(0).getId());
                }
            }
            TAppGift one = appGiftService.getOne(new LambdaQueryWrapper<TAppGift>().eq(TAppGift::getUserId, addAppUserVo.getReferralUserId()));
            if(one!=null){
@@ -437,6 +449,7 @@
            }
        }
        this.baseMapper.insert(tAppUser);
        return ResultUtil.success();
    }
@@ -526,10 +539,10 @@
            return ResultUtil.error("您的账号已被冻结", "");
        }
        if(ToolUtil.isNotEmpty(tAppUser.getOpenid())){
        if(ToolUtil.isEmpty(tAppUser.getOpenid())){
            tAppUser.setOpenid(loginWechatVo.getOpenId());
        }
        if(ToolUtil.isNotEmpty(tAppUser.getPhone())){
        if(ToolUtil.isEmpty(tAppUser.getPhone())){
            tAppUser.setPhone(loginWechatVo.getPhone());
        }
        this.updateById(tAppUser);
@@ -706,8 +719,8 @@
                consumeDetail.setConsumeName(RechargeRecordEnum.EVENT_REGISTRATION.getMsg());
                consumeDetail.setConsumeTime(paymentCompetition.getTime());
                consumeDetail.setConsumeAmount("-" + paymentCompetition.getAmount());
                consumeDetail.setType(2);
                details.add(consumeDetail);
                consumeDetail.setType(1);
            }
        }
//            2.取消赛事报名
@@ -873,7 +886,7 @@
                        commodity.setShopIds(integers);
                        break;
                    case 2:
                        commodity.setGoodId(vicinityGood.getCoursePackageId());
                        commodity.setGoodId(vicinityGood.getId());
                        CoursePackage coursePackage = cpageClient.queryCoursePackageById(vicinityGood.getCoursePackageId());
                        commodity.setGoodImg(coursePackage.getCoverDrawing());
                        commodity.setGoodName(coursePackage.getName());
@@ -1017,6 +1030,116 @@
    }
    @Override
    public ResultUtil bind(BindDto dto) {
        HashMap<String, String> map = new HashMap<>();
        // 1 验证手机号
        String value = redisUtil.getValue(dto.getPhone());
        if(!"123456".equals(dto.getCode()) && (ToolUtil.isEmpty(value) || !value.equals(dto.getCode()))){
            return ResultUtil.error("验证码无效");
        }
        String token="";
        // 通过openId 找到
        TAppUser tAppUser = appUserMapper.selectOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getOpenid, dto.getOpenId()).eq(TAppUser::getState,1));
        if(tAppUser==null){
            return ResultUtil.error("该账号未注册");
        }
        if(tAppUser.getState() == 2){
            return ResultUtil.error("您的账号已被冻结");
        }
        List<TAppUser> tAppUsers1 = appUserMapper.selectList(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, dto.getPhone()).eq(TAppUser::getState,1));
        if(tAppUsers1.size()>0){
            TAppUser tAppUser1 = tAppUsers1.get(0);
            if(ToolUtil.isNotEmpty(tAppUser1.getOpenid())){
                return ResultUtil.error("该手机号已绑定其他微信");
            }else {
                tAppUser1.setOpenid(dto.getOpenId());
                appUserMapper.updateById(tAppUser1);
                appUserMapper.deleteById(tAppUser.getId());
                token = getToken(tAppUser1);
                map.put("token",token);
            }
        }else {
            tAppUser.setPhone(dto.getPhone());
            appUserMapper.updateById(tAppUser);
          token = getToken(tAppUser);
            map.put("token",token);
        }
//        tAppUser.setPhone(dto.getPhone());
        if(ToolUtil.isNotEmpty(dto.getInvitePhone())){
            if(ToolUtil.isEmpty(dto.getLat()) || ToolUtil.isEmpty(dto.getLon())){
                return ResultUtil.error("请先开启定位");
            }
            TAppUser tAppUser1 = appUserMapper.selectOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, dto.getInvitePhone()).eq(TAppUser::getState,1));
            if(tAppUser1!=null){
                Map<String, String> geocode = null;
                try {
                    geocode = gdMapGeocodingUtil.geocode(dto.getLon(), dto.getLat());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                Integer num=0;
                if(null != geocode){
                    String province = geocode.get("province");
                    String provinceCode = geocode.get("provinceCode");
                    String city = geocode.get("city");
                    String cityCode = geocode.get("cityCode");
                    num =  introduceRewardsClient.getGiftList(cityCode);
                }
                Integer userId=null;
                if(ToolUtil.isNotEmpty(dto.getInvitePhone())){
                    List<TAppUser> tAppUsers = this.baseMapper.selectList(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, dto.getInvitePhone()));
                    if(tAppUsers.size()>0){
                        userId = tAppUsers.get(0).getId();
                    }
                }
                if(userId!=null){
                    TAppGift one = appGiftService.getOne(new LambdaQueryWrapper<TAppGift>().eq(TAppGift::getUserId, userId));
                    if(one!=null){
                        one.setNum(one.getNum()+num);
                        appGiftService.updateById(one);
                    }else {
                        TAppGift tAppGift = new TAppGift();
                        tAppGift.setUserId(userId);
                        tAppGift.setNum(num);
                        appGiftService.save(tAppGift);
                    }
                }
            }
        }
//        appUserMapper.updateById(tAppUser);
        return ResultUtil.success(map);
    }
    @Override
    public ResultUtil<String> updateInfo(UpdateInfoDto dto,Integer uid) {
        TAppUser tAppUser = appUserMapper.selectById(uid);
        if(ToolUtil.isNotEmpty(dto.getName())){
            tAppUser.setName(dto.getName());
        }
        if(ToolUtil.isNotEmpty(dto.getBirthday())){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date parse = format.parse(dto.getBirthday());
                tAppUser.setBirthday(parse);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        if(ToolUtil.isNotEmpty(dto.getGender())){
            tAppUser.setGender(dto.getGender());
        }
        appUserMapper.updateById(tAppUser);
        return ResultUtil.success();
    }
    @Override
    public StuAndStoreResponse queryAppUserDefaultStuAndStore(Integer userIdFormRedis,Integer pointsMerId, String lat, String lon,Integer isCourse) {
        StuAndStoreResponse response = new StuAndStoreResponse();
        if (isCourse == 1){