ソースを参照

:poop: 购物车最大数量99限制提升到10000,足校企业账户时处理企业子账户

Twelve615 1 年間 前
コミット
b9cfbc2185

+ 102 - 24
crmeb-admin/src/main/java/com/zbkj/admin/controller/platform/NewPlatformApi.java

@@ -2,15 +2,18 @@ package com.zbkj.admin.controller.platform;
 
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.google.common.collect.Lists;
 import com.zbkj.admin.controller.newapi.request.BoundShopRequest;
 import com.zbkj.admin.controller.newapi.request.SetLineOfCreditRequest;
 import com.zbkj.admin.controller.newapi.request.UserEnterpriseSearchRequest;
 import com.zbkj.common.constants.BalanceRecordConstants;
+import com.zbkj.common.exception.ExceptionCodeEnum;
 import com.zbkj.common.model.admin.SystemAdmin;
 import com.zbkj.common.model.order.Order;
 import com.zbkj.common.model.organization.Organization;
@@ -42,12 +45,15 @@ import org.aspectj.weaver.ast.Or;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.TransactionTemplate;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @Created by:   zhulei
@@ -91,6 +97,8 @@ public class NewPlatformApi {
     @Autowired
     private OrderService orderService;
 
+    @Autowired
+    private TransactionTemplate transactionTemplate;
 
     @ApiOperation(value = "平台端企业用户分页列表")
     @RequestMapping(value = "/list", method = RequestMethod.GET)
@@ -160,20 +168,69 @@ public class NewPlatformApi {
             if (byId.getUsedLineOfCredit().compareTo(BigDecimal.ZERO) != 0) {
                 return CommonResult.failed("已用额度不为零,需还清后才能注销");
             }
+            //处理企业子账号
+            LambdaQueryWrapper<UserBypassAccount> bypassAccountLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            bypassAccountLambdaQueryWrapper.eq(UserBypassAccount::getEnterpriseId, id);
+            bypassAccountLambdaQueryWrapper.eq(UserBypassAccount::getIsDelete, 0);
+            List<UserBypassAccount> list = userBypassAccountService.list(bypassAccountLambdaQueryWrapper);
+            // 判断子账号是否有已用额度
+            if (list != null && list.size() > 0) {
+                for (UserBypassAccount userBypassAccount : list) {
+                    CommonResult<String> checkIsRemit = checkIsRemit(userBypassAccount);
+                    if (checkIsRemit != null) return checkIsRemit;
+                    CommonResult<String> checkOrder = checkOrder(userBypassAccount);
+                    if (checkOrder != null) return checkOrder;
+                }
+            }
             byId.setIsDelete(1);
-            userEnterpriseService.updateById(byId);
+
+            // 子用户
             LambdaQueryWrapper<UserBypassAccount> queryWrapper = new LambdaQueryWrapper<>();
             queryWrapper.eq(UserBypassAccount::getEnterpriseId, id);
-            userBypassAccountService.remove(queryWrapper);
+
+            // 用户(企业主用户)
             User user = new User();
             user.setId(byId.getUserId());
+            user.setIsAllOrders(2);
             user.setIsEnterpriseUser(1);
-            userService.updateById(user);
+            // 子用户
+            LambdaUpdateWrapper<User> updateWrapper = new LambdaUpdateWrapper<>();
+            updateWrapper.set(User::getIsAllOrders,2);
+            updateWrapper.set(User::getIsEnterpriseUser,1);
+            List<Integer> userIdList = list.stream().map(item -> item.getUserId()).collect(Collectors.toList());
+            if (userIdList.size() > 1000) {
+                //  in表达式超出1000限制 将查询list拆分后用or连接
+                List<List<Integer>> splitList = Lists.partition(userIdList, 1000);
+                for (List<Integer> ids : splitList) {
+                    updateWrapper.or().in(User::getId,ids);
+                }
+            } else {
+                updateWrapper.in(User::getId, userIdList);
+            }
+            //
+            Boolean execute = transactionTemplate.execute(e -> {
+                try {
+                    userService.update(updateWrapper);
+                    userEnterpriseService.updateById(byId);
+                    userBypassAccountService.remove(queryWrapper);
+                    userService.updateById(user);
+                    userBypassAccountService.removeById(id);
+                } catch (Exception ex) {
+                    ex.printStackTrace();
+                    e.setRollbackOnly();
+                    return Boolean.FALSE;
+                }
+                return Boolean.TRUE;
+            });
 //            UserEnterprise userEnterprise = new UserEnterprise();
 //            userEnterprise.setId(id  );
 //            userEnterprise.setIsDelete(  1  );
 //            userEnterpriseService.updateById( userEnterprise );
-            return CommonResult.success("注销企业账户成功");
+            if (execute) {
+                return CommonResult.success("注销企业账户成功");
+            } else {
+                return CommonResult.failed("注销企业账户失败,接口错误");
+            }
         } catch (Exception e) {
             return CommonResult.failed("注销企业账户失败,接口错误");
         }
@@ -266,29 +323,13 @@ public class NewPlatformApi {
     @RequestMapping(value = "/updataBypassAccount/{id}", method = RequestMethod.POST)
     public CommonResult<String> updataBypassAccount(@PathVariable Integer id) {
         try {
-
             UserBypassAccount byId = userBypassAccountService.getById(id);
             User user = new User();
-            LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
-            orderLambdaQueryWrapper.eq(Order::getIsDel, 0);
-            orderLambdaQueryWrapper.and(i -> i.eq(Order::getIsRemit, 2).or().isNull(Order::getIsRemit));
-            orderLambdaQueryWrapper.eq(Order::getUid,byId.getUserId());
-            orderLambdaQueryWrapper.eq(Order::getIsLineOfCredit,1);
-            List<Order> list = orderService.list(orderLambdaQueryWrapper);
-            if (null != list && list.size() > 0) {
-                return CommonResult.failed("删除子账号失败,存在未收款订单无法进行解除");
-            }
+            CommonResult<String> checkIsRemit = checkIsRemit(byId);
+            if (checkIsRemit != null) return checkIsRemit;
 
-            LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>();
-            queryWrapper.in(Order::getStatus, 0, 1, 3, 4);
-            queryWrapper.in(Order::getRefundStatus, 0, 1, 2);
-            queryWrapper.eq(Order::getIsDel, false);
-            queryWrapper.in(Order::getIsEnterpriseUser, 2,3);
-            queryWrapper.eq(Order::getUid, byId.getUserId());
-            List<Order> orderList = orderService.list(queryWrapper);
-            if (null != orderList && orderList.size() > 0) {
-                return CommonResult.failed("该用户存在未完成订单,请完成订单后进行认证");
-            }
+            CommonResult<String> checkOrder = checkOrder(byId);
+            if (checkOrder != null) return checkOrder;
             user.setId(byId.getUserId());
             user.setIsAllOrders(2);
             user.setIsEnterpriseUser(1);
@@ -303,6 +344,43 @@ public class NewPlatformApi {
         }
     }
 
+    /**
+     * 检查是否有未删除订单
+     * @param byId
+     * @return
+     */
+    private CommonResult<String> checkOrder(UserBypassAccount byId) {
+        LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(Order::getStatus, 0, 1, 3, 4);
+        queryWrapper.in(Order::getRefundStatus, 0, 1, 2);
+        queryWrapper.eq(Order::getIsDel, false);
+        queryWrapper.in(Order::getIsEnterpriseUser, 2,3);
+        queryWrapper.eq(Order::getUid, byId.getUserId());
+        List<Order> orderList = orderService.list(queryWrapper);
+        if (null != orderList && orderList.size() > 0) {
+            return CommonResult.failed("用户【" + byId.getNickname() + "-" + byId.getRealName() + "】存在未完成订单,请完成订单后进行认证");
+        }
+        return null;
+    }
+
+    /**
+     * 检查是否有未收款订单
+     * @param byId
+     * @return
+     */
+    private CommonResult<String> checkIsRemit(UserBypassAccount byId) {
+        LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        orderLambdaQueryWrapper.eq(Order::getIsDel, 0);
+        orderLambdaQueryWrapper.and(i -> i.eq(Order::getIsRemit, 2).or().isNull(Order::getIsRemit));
+        orderLambdaQueryWrapper.eq(Order::getUid, byId.getUserId());
+        orderLambdaQueryWrapper.eq(Order::getIsLineOfCredit,1);
+        List<Order> list = orderService.list(orderLambdaQueryWrapper);
+        if (null != list && list.size() > 0) {
+            return CommonResult.failed("删除子账号失败,用户【" + byId.getNickname() + "-" + byId.getRealName() + "】存在未收款订单无法进行解除");
+        }
+        return null;
+    }
+
     @ApiOperation(value = "修改子账号信息id必传")
     @RequestMapping(value = "/updataBypassAccount2", method = RequestMethod.POST)
     public CommonResult<String> updataBypassAccount2(@RequestBody @Validated UserBypassAccount userBypassAccount) {

+ 5 - 5
crmeb-admin/src/main/resources/application-dev.yml

@@ -14,7 +14,7 @@ crmeb:
   activityStyleProductLimit: 100 # 活动边框指定商品上线
   sms:
     pay:
-      notify-url: http://120.79.86.50:8012/api/front/erkai/wechat
+      notify-url: http://182.40.104.187:8012/api/front/erkai/wechat
 # 配置端口
 server:
   port: 8011
@@ -39,9 +39,9 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://120.79.86.50:3306/crmebjava?characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
-    username: root
-    password: b610a50f4cc1971e
+    url: jdbc:mysql://182.40.104.187:3306/gccrmebjava?characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
+    username: gccrmebjava
+    password: YGJbZyPcciGJzwY3
   #正式
   #    url: jdbc:mysql://124.221.230.104:3306/guicaijava?characterEncoding=utf-8&useSSL=false&serverTimeZone=GMT+8
   #    username: guicaijava
@@ -73,7 +73,7 @@ spring:
 
 
   redis:
-    host: 120.79.86.50
+    host: 182.40.104.187
     port: 6379 #端口
     password: 'hdl2022'
     #    host: 124.221.230.104

+ 1 - 1
crmeb-common/src/main/java/com/zbkj/common/request/CartRequest.java

@@ -32,6 +32,6 @@ public class CartRequest {
 
     @ApiModelProperty(value = "商品数量", required = true)
     @NotNull(message = "请选择商品数量")
-    @Range(min = 1, max = 99, message = "单次可添加商品数量范围为 1~99")
+    @Range(min = 1, max = 10000, message = "单次可添加商品数量范围为 1~10000")
     private Integer cartNum;
 }