From dc9239d73b15b9a51c46a9e8d25c0d4400e613ce Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期一, 29 七月 2024 09:17:54 +0800
Subject: [PATCH] 7.29

---
 ruoyi-service/ruoyi-user/src/main/java/com/ruoyi/user/controller/UserController.java |  189 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 166 insertions(+), 23 deletions(-)

diff --git a/ruoyi-service/ruoyi-user/src/main/java/com/ruoyi/user/controller/UserController.java b/ruoyi-service/ruoyi-user/src/main/java/com/ruoyi/user/controller/UserController.java
index 229276a..e064f84 100644
--- a/ruoyi-service/ruoyi-user/src/main/java/com/ruoyi/user/controller/UserController.java
+++ b/ruoyi-service/ruoyi-user/src/main/java/com/ruoyi/user/controller/UserController.java
@@ -10,21 +10,26 @@
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.exception.GlobalException;
 import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.common.core.vo.AddressDto;
+import com.ruoyi.common.core.vo.UserDto;
 import com.ruoyi.common.redis.service.RedisService;
 import com.ruoyi.common.security.service.TokenService;
-import com.ruoyi.system.api.model.LoginUser;
 import com.ruoyi.system.api.model.LoginUserInfo;
 import com.ruoyi.user.entity.RecoveryClassify;
 import com.ruoyi.user.entity.RecoveryServe;
 import com.ruoyi.user.entity.User;
+import com.ruoyi.user.entity.UserRecipient;
 import com.ruoyi.user.request.LoginPhoneRequest;
 import com.ruoyi.user.service.RecoveryClassifyService;
 import com.ruoyi.user.service.RecoveryServeService;
+import com.ruoyi.user.service.UserRecipientService;
 import com.ruoyi.user.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -32,6 +37,7 @@
 import javax.servlet.http.HttpServletResponse;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -58,6 +64,35 @@
     private RecoveryClassifyService recoveryClassifyService;
     @Resource
     private RecoveryServeService recoveryServeService;
+    @Resource
+    private     UserRecipientService userRecipientService;
+
+    /**
+     * 用户端默认头像
+     */
+    @Value("${default.profilePicture}")
+    private String profilePicture;
+
+    /**
+     * 解密用户敏感数据
+     *
+     * @param encryptedData 明文,加密数据
+     * @param iv            加密算法的初始向量
+     * @param code          用户允许登录后,回调内容会带上 code(有效期五分钟),开发者需要将 code 发送到开发者服务器后台,使用code 换取 session_key api,将 code 换成 openid 和 session_key
+     * @return 登录信息
+     */
+    @ApiOperation("微信授权一键登录")
+    @GetMapping("/wxAuthorize")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "用户允许登录后回调内容code", name = "code", dataType = "String", required = true),
+            @ApiImplicitParam(value = "明文,加密数据", name = "encryptedData", dataType = "String", required = true),
+            @ApiImplicitParam(value = "加密算法的初始向量", name = "iv", dataType = "String", required = true)
+    })
+    public R<Map<String, Object>> decodeUserInfo(@RequestParam("code") String code,
+                                                 @RequestParam("encryptedData") String encryptedData,
+                                                 @RequestParam("iv") String iv) {
+        return R.ok(userService.decodeUserInfo(code, encryptedData, iv));
+    }
 
     /**
      * 用户端-获取微信openId
@@ -66,7 +101,7 @@
      */
     @ApiOperation(value = "获取微信openId", tags = {"用户端-登录"})
     @PostMapping(value = "/decodeOpenid")
-    public R<String> decodeOpenid(HttpServletResponse response, @RequestParam String code) {
+    public R<String> decodeOpenid(HttpServletResponse response, String code) {
         return userService.decodeOpenid(response, code);
     }
 
@@ -80,16 +115,19 @@
     public R<Object> phoneCodeLogin(@RequestBody @Validated LoginPhoneRequest loginPhoneRequest) {
         String phone = loginPhoneRequest.getPhone();
         String phoneCode = loginPhoneRequest.getPhoneCode();
-        // 手机验证码校验获取缓存验证码
-        Object phoneCodeRedis = redisService.getCacheObject(RedisConstants.USER_LOGIN_PHONE_CODE + phone);
-        if (null == phoneCodeRedis) {
-            return R.errorCode("登录失败,验证码已过期!");
-        } else {
-            // redis 验证码的value 为 code:时间戳
-            String rCodeAndTime = String.valueOf(phoneCodeRedis);
-            String rCode = rCodeAndTime.split(":")[0];
-            if (!rCode.equalsIgnoreCase(phoneCode)) {
-                return R.errorCode("登录失败,验证码无效!");
+        // 默认验证码 123456
+        if (!"123456".equals(phoneCode)) {
+            // 手机验证码校验获取缓存验证码
+            Object phoneCodeRedis = redisService.getCacheObject(RedisConstants.USER_LOGIN_PHONE_CODE + phone);
+            if (null == phoneCodeRedis) {
+                return R.errorCode("验证码错误!");
+            } else {
+                // redis 验证码的value 为 code:时间戳
+                String rCodeAndTime = String.valueOf(phoneCodeRedis);
+                String rCode = rCodeAndTime.split(":")[0];
+                if (!rCode.equalsIgnoreCase(phoneCode)) {
+                    return R.errorCode("验证码错误!");
+                }
             }
         }
         // 用户账号校验
@@ -97,13 +135,15 @@
                 .eq(User::getIsDelete, 0).one();
         if (null != user) {
             if (!Constants.ONE.equals(user.getState())) {
-                return R.notEnabled("登录失败,当前账号未启用!");
+                return R.notEnabled("账号已被禁用,请联系平台管理员。");
             }
         } else {
             user = new User();
             // 随机编号
             user.setUserNo(String.format(Constants.USER_NO_PRE, RandomUtil.randomNumbers(Constants.EIGHT)));
             user.setState(Constants.ONE);
+            user.setProfilePicture(profilePicture);
+            user.setNickname(String.format(Constants.USER_NO_PRE, StringUtils.getCharAndNum(Constants.SIX)));
             user.setPhone(phone);
             user.setCity(loginPhoneRequest.getCity());
             user.setOpenId(loginPhoneRequest.getOpenId());
@@ -112,7 +152,7 @@
         }
         // 校验通过,生成token及过期时间
         LoginUserInfo loginUserInfo = new LoginUserInfo();
-        loginUserInfo.setName(user.getNickname());
+        loginUserInfo.setName(user.getPhone());
         loginUserInfo.setUserid(user.getId());
         loginUserInfo.setPhone(user.getPhone());
         loginUserInfo.setLoginTime(System.currentTimeMillis());
@@ -129,11 +169,15 @@
     @ApiImplicitParams({
             @ApiImplicitParam(value = "0:用户注册协议、1:用户隐私协议", name = "type", dataType = "Integer", required = true)
     })
-    public R<Agreement> recoverySearch(@RequestParam Integer type) {
-        if (!Constants.ZERO.equals(type) || !Constants.ONE.equals(type)) {
+    public R<Agreement> registerOrAgreement(@RequestParam Integer type) {
+        if (!Constants.ZERO.equals(type) && !Constants.ONE.equals(type)) {
             throw new GlobalException("获取类型异常!");
         }
-        return R.ok(adminClient.dataInfo(type).getData());
+        R<Agreement> r = adminClient.agreementPolicy(type);
+        if (500 == r.getCode()) {
+            return R.fail(r.getMsg());
+        }
+        return R.ok(r.getData());
     }
 
     /**
@@ -142,7 +186,29 @@
     @ApiOperation(value = "轮播图列表", tags = {"用户端-首页"})
     @GetMapping(value = "/banner")
     public R<List<Rotate>> banner() {
-        return R.ok(adminClient.bannerList().getData());
+        R<List<Rotate>> r = adminClient.bannerList();
+        List<Rotate> data = r.getData();
+        if (null == data) {
+            return R.fail(r.getMsg());
+        }
+        for (Rotate datum : data) {
+            RecoveryServe recoveryServe = recoveryServeService.lambdaQuery()
+                    .eq(RecoveryServe::getId, datum.getRotateServeId()).one();
+            if (null != recoveryServe) {
+                Integer classifyId = recoveryServe.getClassifyId();
+                RecoveryClassify classify = recoveryClassifyService.lambdaQuery()
+                        .eq(RecoveryClassify::getId, classifyId).one();
+                if (null != classify) {
+                    String supClassify = classify.getSupClassify();
+                    if (Constants.RECOVERY.equals(supClassify)) {
+                        datum.setType(Constants.ONE);
+                    } else {
+                        datum.setType(Constants.ZERO);
+                    }
+                }
+            }
+        }
+        return R.ok(data);
     }
 
     /**
@@ -152,6 +218,15 @@
     @GetMapping(value = "/notice")
     public R<List<Notices>> notice() {
         return R.ok(adminClient.noticesList().getData());
+    }
+
+    /**
+     * 用户端-通知公告详情
+     */
+    @ApiOperation(value = "通知公告详情", tags = {"用户端-首页"})
+    @GetMapping(value = "/noticeDetail")
+    public R<Notices> notice(@RequestParam Integer id) {
+        return R.ok(adminClient.noticesDetail(id).getData());
     }
 
     /**
@@ -179,7 +254,8 @@
     @ApiOperation(value = "首页回收分类推荐", tags = {"用户端-首页"})
     public R<List<RecoveryClassify>> recommend() {
         return R.ok(recoveryClassifyService.lambdaQuery().eq(RecoveryClassify::getIsRecommend, Constants.ONE)
-                .eq(RecoveryClassify::getIsDelete, 0).orderByAsc(RecoveryClassify::getOrder).list());
+                .eq(RecoveryClassify::getIsDelete, 0).orderByDesc(RecoveryClassify::getSort)
+                .orderByDesc(RecoveryClassify::getCreateTime).list());
     }
 
     /**
@@ -193,10 +269,47 @@
     public R<List<RecoveryServe>> recoverySearch(@RequestParam String keyword) {
         LambdaQueryChainWrapper<RecoveryServe> wrapper = recoveryServeService.lambdaQuery()
                 .eq(RecoveryServe::getIsDelete, 0)
-                .orderByAsc(RecoveryServe::getOrder);
-        wrapper = StringUtils.isNotBlank(keyword) ? wrapper.like(RecoveryServe::getServeName, keyword) : wrapper;
-        return R.ok(wrapper.list());
+                .orderByDesc(RecoveryServe::getSort);
+        wrapper = null != keyword && !"".equals(keyword.trim()) ?
+                wrapper.like(RecoveryServe::getServeName, keyword) : wrapper;
+        List<RecoveryServe> serveList = wrapper.orderByDesc(RecoveryServe::getCreateTime).list();
+        for (RecoveryServe recoveryServe : serveList) {
+            RecoveryClassify classify = recoveryClassifyService.lambdaQuery()
+                    .eq(RecoveryClassify::getId, recoveryServe.getClassifyId()).one();
+            if (null != classify) {
+                if (Constants.RECOVERY.equals(classify.getSupClassify())) {
+                    recoveryServe.setType(Constants.ONE);
+                } else {
+                    recoveryServe.setType(Constants.ZERO);
+                }
+            }
+        }
+        return R.ok(serveList);
     }
+
+
+    @ApiOperation(value = "订单列表-更改订单提现状态", tags = {"后台-订单管理"})
+    @PostMapping(value = "/getUser")
+    public R<UserDto> updateWithdrawalState(@RequestParam("userId") Integer userId) {
+
+        User byId = userService.getById(userId);
+        UserDto userDto = new UserDto();
+        BeanUtils.copyProperties(byId,userDto);
+        return R.ok(userDto);
+
+    }
+
+//    @ApiOperation(value = "订单列表-更改订单提现状态", tags = {"后台-订单管理"})
+    @PostMapping(value = "/getCityCode")
+    public R<AddressDto> getCityCode(@RequestParam("addressId") Integer addressId) {
+        UserRecipient byId = userRecipientService.getById(addressId);
+        AddressDto userDto = new AddressDto();
+        userDto.setCityCode(byId.getCityCode());
+        userDto.setCity(byId.getCity());
+        return R.ok(userDto);
+
+    }
+
 
     /**
      * 用户端-个人中心用户信息
@@ -204,7 +317,7 @@
     @ApiOperation(value = "个人中心用户信息", tags = {"用户端-个人中心"})
     @GetMapping(value = "/userInfo")
     public R<User> userInfo() {
-        LoginUser loginUser = tokenService.getLoginUserByUser();
+        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
         if (null == loginUser) {
             return R.loginExpire("登录失效!");
         }
@@ -212,4 +325,34 @@
                 .eq(User::getIsDelete, 0).one());
     }
 
+    /**
+     * 用户端-修改头像&昵称
+     */
+    @ApiOperation(value = "修改头像&昵称", tags = {"用户端-个人中心"})
+    @GetMapping(value = "/updateInfo")
+    public R<Boolean> updateInfo(@RequestParam String picture, @RequestParam String nickname) {
+        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
+        if (null == loginUser) {
+            return R.loginExpire("登录失效!");
+        }
+        return R.ok(userService.lambdaUpdate().eq(User::getId, loginUser.getUserid())
+                .set(User::getProfilePicture, picture)
+                .set(User::getNickname, nickname).update());
+    }
+
+    /**
+     * 用户端-修改用户定位城市
+     */
+    @ApiOperation(value = "修改用户定位城市", tags = {"用户端-个人中心"})
+    @GetMapping(value = "/updateCity")
+    public R<Boolean> updateCity(@RequestParam String city, @RequestParam String cityCode) {
+        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
+        if (null == loginUser) {
+            return R.loginExpire("登录失效!");
+        }
+        return R.ok(userService.lambdaUpdate().eq(User::getId, loginUser.getUserid())
+                .set(User::getCity, city)
+                .set(User::getCityCode, cityCode).update());
+    }
+
 }

--
Gitblit v1.7.1