From 0586a24d8a7ba5f35fb825fbd49a8363b1e5b289 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期三, 15 一月 2025 10:24:45 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/qijisheng

---
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java      |  110 +++++++++++++++++++++++-------------
 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java |   40 ++++++++-----
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java  |    2 
 ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TechnicianMapper.xml              |    6 +-
 ruoyi-service/ruoyi-other/src/main/resources/mapper/other/GoodsBargainPriceMapper.xml       |    1 
 5 files changed, 100 insertions(+), 59 deletions(-)

diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java
index 07e4f17..9a8431d 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java
@@ -138,6 +138,12 @@
             if(null == appUser){
                 return error("请先注册小程序账号");
             }
+            SysUser one2 = userService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, user.getPhonenumber())
+                    .eq(SysUser::getDelFlag, "0").eq(SysUser::getStatus, "0").eq(SysUser::getObjectId, sysUser1.getObjectId())
+                    .eq(SysUser::getRoleType, 2));
+            if(null != one2){
+                return error("登录账号重复");
+            }
             SysUser one = userService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, user.getPhonenumber())
                     .eq(SysUser::getDelFlag, "0").eq(SysUser::getStatus, "0").eq(SysUser::getRoleType, 2));
             if(null == one){
@@ -666,7 +672,7 @@
     @PostMapping("/saveShopUser")
     public R<Long> saveShopUser(@RequestBody SysUser user){
         SysUser one = userService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getPhonenumber, user.getPhonenumber()).eq(SysUser::getDelFlag, "0")
-                .eq(SysUser::getStatus, "0").eq(SysUser::getRoleType, 2).eq(SysUser::getAppUserId, user.getAppUserId()));
+                .eq(SysUser::getStatus, "0").eq(SysUser::getRoleType, 2));
         if(null == one){
             user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
             userService.save(user);
@@ -688,21 +694,25 @@
      */
     @PostMapping("/user/delShopUser")
     public R delShopUser(@RequestParam("objectId") Integer objectId, @RequestParam("roleType") Integer roleType){
-        List<SysUser> list = userService.list(new LambdaUpdateWrapper<SysUser>().eq(SysUser::getObjectId, objectId).eq(SysUser::getRoleType, roleType)
-                .eq(SysUser::getDelFlag, "0").eq(SysUser::getStatus, "0"));
-        for (SysUser sysUser : list) {
-            List<UserShop> list1 = userShopService.list(new LambdaUpdateWrapper<UserShop>().eq(UserShop::getUserId, sysUser.getUserId()));
-            List<Integer> collect = list1.stream().map(UserShop::getShopId).collect(Collectors.toList());
-            if(collect.contains(objectId) && collect.size() == 1){
-                sysUser.setDelFlag("2");
-                userService.updateById(sysUser);
+        List<UserShop> list2 = userShopService.list(new LambdaQueryWrapper<UserShop>().eq(UserShop::getShopId, objectId));
+        for (UserShop userShop : list2) {
+            List<UserShop> list1 = userShopService.list(new LambdaUpdateWrapper<UserShop>().eq(UserShop::getUserId, userShop.getUserId()));
+            if(list1.size() == 1 && list1.get(0).getShopId().equals(objectId)){
+                //删除管理员账号
+                userService.deleteUserById(userShop.getUserId());
+            }else{
+                //修改管理后台账号关联的门店数据
+                SysUser sysUser = userService.getById(userShop.getUserId());
+                if(sysUser.getObjectId().equals(objectId)){
+                    Optional<UserShop> first = list1.stream().filter(s -> !s.getShopId().equals(objectId)).findFirst();
+                    if(first.isPresent()){
+                        sysUser.setObjectId(first.get().getShopId());
+                        userService.updateById(sysUser);
+                    }
+                    
+                }
             }
-            if(sysUser.getObjectId().equals(objectId) && collect.size() > 1){
-                Integer integer = collect.stream().filter(s -> !s.equals(sysUser.getObjectId())).findFirst().get();
-                sysUser.setObjectId(integer);
-                userService.updateById(sysUser);
-            }
-            userShopService.remove(new LambdaUpdateWrapper<UserShop>().eq(UserShop::getUserId, sysUser.getUserId()).eq(UserShop::getShopId, objectId));
+            userShopService.removeById(userShop.getId());
         }
         return R.ok();
     }
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
index 579cf54..02537dc 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -256,7 +256,7 @@
         Order order = orderMapper.selectById(id);
         boolean check = check(order, shopId, loginUserApplet.getUserid());
         if (!check){
-            throw new ServiceException("订单不存在");
+            throw new ServiceException("该订单与当前扫码门店不一致");
         }
 
         // 售后设置
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
index dda78ca..eea9ac2 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/ShopController.java
@@ -181,10 +181,17 @@
             userShop.setUserId(userId);
             userShop.setShopId(shopId);
             userShop.setRoleType(1);
-            userShop.setRoleId(2L);
-            userShop.setNickName(user.getNickName());
-            userShop.setCreateTime(LocalDateTime.now());
-            userShopClient.saveUserShop(userShop);
+            List<UserShop> data = userShopClient.getUserShop(userShop).getData();
+            if(null == data || data.size() == 0){
+                userShop = new UserShop();
+                userShop.setUserId(userId);
+                userShop.setShopId(shopId);
+                userShop.setRoleType(1);
+                userShop.setRoleId(2L);
+                userShop.setNickName(user.getNickName());
+                userShop.setCreateTime(LocalDateTime.now());
+                userShopClient.saveUserShop(userShop);
+            }
         }
 
         // 更换下级会员绑定门店
@@ -224,16 +231,19 @@
                     .eq(Shop::getId,shop1.getId());
             shopService.update(set);
         }
+        //清除用户绑定当前门店
         appUserClient.clearBindShop(shop.getId());
+        //查询门店绑定的平台账号
         UserShop userShop = new UserShop();
         userShop.setShopId(shop.getId());
         List<UserShop> data = userShopClient.getUserShop(userShop).getData();
         if(data.size() > 0){
+            //删除门店后台账号和关系数据
+            sysUserClient.delShopUser(shop.getId(), 2);
+    
+            //修改小程序用户类型和门店数据
             List<Integer> collect = data.stream().map(UserShop::getUserId).collect(Collectors.toList()).stream().map(Long::intValue).collect(Collectors.toList());
             List<SysUser> sysUserList = sysUserClient.getUserList(collect).getData();
-            //删除门店下的所有员工
-            sysUserClient.delShopUser(shop.getId(), 2);
-            //修改小程序用户类型和门店数据
             for (SysUser sysUser : sysUserList) {
                 //通过电话号码查询小程序用户和门店关系数据
                 AppUser appUser = appUserClient.getAppUserByPhone1(sysUser.getUserName()).getData();
@@ -243,10 +253,10 @@
                     appUser.setUserType(1);
                     appUserClient.editAppUserById(appUser);
                 }
-                //删除用户门店关系表数据
+                //删除用户门店关系数据
                 AppUserShop appUserShop = new AppUserShop();
-                appUserShop.setAppUserId(appUser.getId());
                 appUserShop.setShopId(shop.getId());
+                appUserShop.setAppUserId(sysUser.getUserId());
                 appUserShopClient.delAppUserShop(appUserShop);
             }
         }
@@ -257,6 +267,14 @@
                 technician.setDelFlag(1);
             }
             technicianService.updateBatchById(list);
+            //删除技师和门店关系数据
+            //删除用户门店关系数据
+            AppUserShop appUserShop = new AppUserShop();
+            appUserShop.setShopId(shop.getId());
+            appUserShop.setRoleType(3);
+            appUserShopClient.delAppUserShop(appUserShop);
+            
+            //取消门店预约技师数据
             Set<Integer> collect = list.stream().map(Technician::getId).collect(Collectors.toSet());
             technicianSubscribeService.update(new LambdaUpdateWrapper<TechnicianSubscribe>().in(TechnicianSubscribe::getTechnicianId, collect).eq(TechnicianSubscribe::getDelFlag, 0)
                     .eq(TechnicianSubscribe::getStatus, 0).set(TechnicianSubscribe::getStatus, 2));
@@ -290,6 +308,7 @@
         AppUser appUser = appUserClient.getAppUserById(old_shop.getAppUserId());
         //需要先判断用户是否没有关联任何门店
         List<AppUserShop> userShops = appUserShopClient.getAppUserShop(appUser.getId()).getData();
+        //当前小程序账号如果关联的店铺是最后一个,则将其修改为普通用户
         if(userShops.size() == 1 && userShops.get(0).getShopId().equals(shop.getId())){
             appUser.setUserType(1);
             appUserClient.editAppUserById(appUser);
@@ -300,6 +319,22 @@
         appUserShop.setShopId(shop.getId());
         appUserShop.setRoleType(1);
         appUserShopClient.delAppUserShop(appUserShop);
+        //删除后台用户和店铺关系数据
+        UserShop userShop = new UserShop();
+        userShop.setShopId(shop.getId());
+        userShop.setRoleType(1);
+        List<UserShop> data = userShopClient.getUserShop(userShop).getData();
+        if(null != data && data.size() > 0){
+            UserShop userShop1 = data.get(0);
+            userShopClient.delUserShop(userShop1);
+            //如果当前后台账户关联的店铺是最后一个,删除后台账户
+            userShop = new UserShop();
+            userShop.setUserId(userShop1.getUserId());
+            data = userShopClient.getUserShop(userShop).getData();
+            if(data.size() == 0){
+                sysUserClient.delSysUserById(userShop1.getUserId());
+            }
+        }
 
         //添加新管理员
         appUser = appUserClient.getAppUserByPhone1(phone).getData();
@@ -314,35 +349,24 @@
         //修改管理员
         shop.setAppUserId(appUser.getId());
         shopService.updateById(shop);
-    
-    
-        //删除门店用户店铺关系数据
-        UserShop userShop = new UserShop();
-        userShop.setShopId(shop.getId());
-        userShop.setRoleType(1);
-        List<UserShop> data = userShopClient.getUserShop(userShop).getData();
-        if(data.size() > 0){
-            UserShop userShop1 = data.get(0);
-            userShopClient.delUserShop(userShop1);
-    
-            userShop = new UserShop();
-            userShop.setUserId(userShop1.getUserId());
-            data = userShopClient.getUserShop(userShop).getData();
-            if(data.size() == 0){
-                sysUserClient.delSysUserById(userShop1.getUserId());
-            }
-        }
+        
         //添加门店后台账号和门店关系数据
         SysUser sysUser = sysUserClient.queryUserByUserName(phone).getData();
         if(null != sysUser){
             userShop = new UserShop();
-            userShop.setUserId(sysUser.getUserId());
             userShop.setShopId(shop.getId());
-            userShop.setRoleType(1);
-            userShop.setRoleId(2L);
-            userShop.setNickName(sysUser.getNickName());
-            userShop.setCreateTime(LocalDateTime.now());
-            userShopClient.saveUserShop(userShop);
+            userShop.setUserId(sysUser.getUserId());
+            data = userShopClient.getUserShop(userShop).getData();
+            if(null == data || data.size() == 0){
+                userShop = new UserShop();
+                userShop.setUserId(sysUser.getUserId());
+                userShop.setShopId(shop.getId());
+                userShop.setRoleType(1);
+                userShop.setRoleId(2L);
+                userShop.setNickName(sysUser.getNickName());
+                userShop.setCreateTime(LocalDateTime.now());
+                userShopClient.saveUserShop(userShop);
+            }
         }else{
             //添加管理后台账号
             SysUser user = new SysUser();
@@ -359,15 +383,21 @@
             user.setPassword(phone.substring(5));
             user.setCreateTime(new Date());
             Long userId = sysUserClient.saveShopUser(user).getData();
-
+    
             userShop = new UserShop();
-            userShop.setUserId(userId);
             userShop.setShopId(shop.getId());
-            userShop.setRoleType(1);
-            userShop.setRoleId(2L);
-            userShop.setNickName(appUser.getName());
-            userShop.setCreateTime(LocalDateTime.now());
-            userShopClient.saveUserShop(userShop);
+            userShop.setUserId(userId);
+            data = userShopClient.getUserShop(userShop).getData();
+            if(null == data || data.size() == 0){
+                userShop = new UserShop();
+                userShop.setUserId(userId);
+                userShop.setShopId(shop.getId());
+                userShop.setRoleType(1);
+                userShop.setRoleId(2L);
+                userShop.setNickName(appUser.getName());
+                userShop.setCreateTime(LocalDateTime.now());
+                userShopClient.saveUserShop(userShop);
+            }
         }
         return R.ok();
     }
diff --git a/ruoyi-service/ruoyi-other/src/main/resources/mapper/other/GoodsBargainPriceMapper.xml b/ruoyi-service/ruoyi-other/src/main/resources/mapper/other/GoodsBargainPriceMapper.xml
index af49c50..e3717b0 100644
--- a/ruoyi-service/ruoyi-other/src/main/resources/mapper/other/GoodsBargainPriceMapper.xml
+++ b/ruoyi-service/ruoyi-other/src/main/resources/mapper/other/GoodsBargainPriceMapper.xml
@@ -31,5 +31,6 @@
         <if test="gp.auditStatus != null">
             and tgbp.audit_status = #{gp.auditStatus}
         </if>
+        order by tgbp.create_time desc
     </select>
 </mapper>
\ No newline at end of file
diff --git a/ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TechnicianMapper.xml b/ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TechnicianMapper.xml
index 640c729..f74199c 100644
--- a/ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TechnicianMapper.xml
+++ b/ruoyi-service/ruoyi-other/src/main/resources/mapper/other/TechnicianMapper.xml
@@ -18,7 +18,7 @@
           AND tt.del_flag = 0
           AND tt.shop_id = #{shopId}
         <if test="name != null and name != ''">
-            AND tt.`name` LIKE concat('%', #{name}, '%')
+            AND tt.name LIKE concat('%', #{name}, '%')
         </if>
         GROUP BY
             tt.id,
@@ -26,10 +26,10 @@
             tt.introduction,
             tt.home_picture
         <if test="point != null and point == 1">
-        order by ttsc.score DESC
+        order by score DESC
         </if>
         <if test="point != null and point == 2">
-        order by ttsc.score
+        order by score
         </if>
     </select>
     <select id="selectTechnicianDetail" resultType="com.ruoyi.other.vo.TechnicianDetailVO">

--
Gitblit v1.7.1