From d6b1c8f75ede9475a837662a2a6b0d116be1dcda Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期一, 30 十月 2023 09:32:45 +0800
Subject: [PATCH] 修改bug

---
 cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java |  131 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 127 insertions(+), 4 deletions(-)

diff --git a/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java b/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
index 00455c9..14f73c9 100644
--- a/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
+++ b/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);
@@ -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){

--
Gitblit v1.7.1