|
|
@@ -0,0 +1,239 @@
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.User;
|
|
|
+import com.etotem.cfc.mapper.UserMapper;
|
|
|
+import com.etotem.cfc.service.UserService;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 供应商管理控制器 - 供应商管理员角色专用
|
|
|
+ * 管理供应商用户、商品发布、服务商层级调整
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/supply-manage")
|
|
|
+public class SupplyManageController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 供应商列表(分页+搜索)
|
|
|
+ * 查询拥有 supplier_admin 角色的用户
|
|
|
+ */
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result<Map<String, Object>> list(@RequestBody Map<String, Object> params) {
|
|
|
+ int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
|
|
|
+ int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
|
|
|
+ String keyword = (String) params.get("keyword");
|
|
|
+ String vendorStatus = (String) params.get("vendorStatus");
|
|
|
+
|
|
|
+ Page<User> pageParam = new Page<>(page, size);
|
|
|
+ LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<User>();
|
|
|
+
|
|
|
+ // 搜索条件:手机号、昵称、真实姓名
|
|
|
+ if (keyword != null && !keyword.isEmpty()) {
|
|
|
+ wrapper.and(w -> w.like(User::getPhone, keyword)
|
|
|
+ .or().like(User::getNickname, keyword)
|
|
|
+ .or().like(User::getRealName, keyword));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 服务商状态筛选
|
|
|
+ if (vendorStatus != null && !vendorStatus.isEmpty()) {
|
|
|
+ wrapper.eq(User::getVendorStatus, vendorStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ wrapper.orderByDesc(User::getUpdatedAt);
|
|
|
+ Page<User> result = userMapper.selectPage(pageParam, wrapper);
|
|
|
+
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("list", result.getRecords());
|
|
|
+ data.put("total", result.getTotal());
|
|
|
+ data.put("page", page);
|
|
|
+ data.put("size", size);
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取供应商详情
|
|
|
+ */
|
|
|
+ @PostMapping("/detail")
|
|
|
+ public Result<User> detail(@RequestBody Map<String, Object> params) {
|
|
|
+ Long id = params.get("id") != null ? ((Number) params.get("id")).longValue() : null;
|
|
|
+ if (id == null) {
|
|
|
+ return Result.error("id不能为空");
|
|
|
+ }
|
|
|
+ User user = userMapper.selectById(id);
|
|
|
+ if (user == null) {
|
|
|
+ return Result.error("供应商不存在");
|
|
|
+ }
|
|
|
+ user.setPassword(null); // 清除密码
|
|
|
+ return Result.success(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建供应商
|
|
|
+ */
|
|
|
+ @PostMapping("/create")
|
|
|
+ public Result<User> create(@RequestBody Map<String, Object> params) {
|
|
|
+ String phone = (String) params.get("phone");
|
|
|
+ String nickname = (String) params.get("nickname");
|
|
|
+ String realName = (String) params.get("realName");
|
|
|
+
|
|
|
+ if (phone == null || phone.isEmpty()) {
|
|
|
+ return Result.error("手机号不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查手机号是否已存在
|
|
|
+ User existing = userMapper.selectOne(new LambdaQueryWrapper<User>()
|
|
|
+ .eq(User::getPhone, phone));
|
|
|
+ if (existing != null) {
|
|
|
+ return Result.error("手机号已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = new User();
|
|
|
+ user.setPhone(phone);
|
|
|
+ user.setNickname(nickname != null ? nickname : "供应商" + phone.substring(7));
|
|
|
+ user.setRealName(realName);
|
|
|
+ user.setRole("supplier_admin");
|
|
|
+ user.setVendorStatus("approved"); // 默认通过审核
|
|
|
+ user.setVendorType("product_supplier"); // 默认商品供应商
|
|
|
+ user.setCreatedAt(new Date());
|
|
|
+ user.setUpdatedAt(new Date());
|
|
|
+
|
|
|
+ userMapper.insert(user);
|
|
|
+ user.setPassword(null);
|
|
|
+ return Result.success(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新供应商信息
|
|
|
+ */
|
|
|
+ @PostMapping("/update")
|
|
|
+ public Result<Boolean> update(@RequestBody Map<String, Object> params) {
|
|
|
+ Long id = params.get("id") != null ? ((Number) params.get("id")).longValue() : null;
|
|
|
+ if (id == null) {
|
|
|
+ return Result.error("id不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = userMapper.selectById(id);
|
|
|
+ if (user == null) {
|
|
|
+ return Result.error("供应商不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (params.containsKey("nickname")) {
|
|
|
+ user.setNickname((String) params.get("nickname"));
|
|
|
+ }
|
|
|
+ if (params.containsKey("realName")) {
|
|
|
+ user.setRealName((String) params.get("realName"));
|
|
|
+ }
|
|
|
+ if (params.containsKey("vendorType")) {
|
|
|
+ user.setVendorType((String) params.get("vendorType"));
|
|
|
+ }
|
|
|
+ if (params.containsKey("vendorStatus")) {
|
|
|
+ user.setVendorStatus((String) params.get("vendorStatus"));
|
|
|
+ }
|
|
|
+ if (params.containsKey("vendorInfo")) {
|
|
|
+ user.setVendorInfo((String) params.get("vendorInfo"));
|
|
|
+ }
|
|
|
+
|
|
|
+ user.setUpdatedAt(new Date());
|
|
|
+ userMapper.updateById(user);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除供应商
|
|
|
+ */
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public Result<Boolean> delete(@RequestBody Map<String, Object> params) {
|
|
|
+ Long id = params.get("id") != null ? ((Number) params.get("id")).longValue() : null;
|
|
|
+ if (id == null) {
|
|
|
+ return Result.error("id不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = userMapper.selectById(id);
|
|
|
+ if (user == null) {
|
|
|
+ return Result.error("供应商不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ userMapper.deleteById(id);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加供应商管理员角色到现有用户
|
|
|
+ */
|
|
|
+ @PostMapping("/add-role")
|
|
|
+ public Result<Boolean> addRole(@RequestBody Map<String, Object> params) {
|
|
|
+ Long userId = params.get("userId") != null ? ((Number) params.get("userId")).longValue() : null;
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.error("userId不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean added = userService.addRole(userId, "supplier_admin");
|
|
|
+ return added ? Result.success(true) : Result.error("添加角色失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 移除供应商管理员角色
|
|
|
+ */
|
|
|
+ @PostMapping("/remove-role")
|
|
|
+ public Result<Boolean> removeRole(@RequestBody Map<String, Object> params) {
|
|
|
+ Long userId = params.get("userId") != null ? ((Number) params.get("userId")).longValue() : null;
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.error("userId不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return Result.error("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 移除 supplier_admin 角色
|
|
|
+ if (user.getRoles() != null && user.getRoles().contains("supplier_admin")) {
|
|
|
+ java.util.List<String> roles = userService.parseRoles(user.getRoles());
|
|
|
+ roles.remove("supplier_admin");
|
|
|
+ user.setRoles(String.join(",", roles));
|
|
|
+ user.setUpdatedAt(new Date());
|
|
|
+ userMapper.updateById(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调整服务商层级
|
|
|
+ * vendorType: planner / activity_provider / product_supplier
|
|
|
+ */
|
|
|
+ @PostMapping("/adjust-tier")
|
|
|
+ public Result<Boolean> adjustTier(@RequestBody Map<String, Object> params) {
|
|
|
+ Long userId = params.get("userId") != null ? ((Number) params.get("userId")).longValue() : null;
|
|
|
+ String vendorType = (String) params.get("vendorType");
|
|
|
+
|
|
|
+ if (userId == null || vendorType == null || vendorType.isEmpty()) {
|
|
|
+ return Result.error("参数不完整");
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ return Result.error("用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ user.setVendorType(vendorType);
|
|
|
+ user.setUpdatedAt(new Date());
|
|
|
+ userMapper.updateById(user);
|
|
|
+
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+}
|