Kaynağa Gözat

feat(admin): 管理端功能优化

- AdminController: 支持ID搜索
- ProductOrderService: SKU价格计算
- Form.vue: 标签更新
Xiaogang Liao 3 ay önce
ebeveyn
işleme
d13041162f

+ 9 - 2
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/AdminController.java

@@ -146,16 +146,23 @@ public class AdminController {
 
 
     /**
     /**
      * 用户搜索(供应商体系选择管理员用)
      * 用户搜索(供应商体系选择管理员用)
-     * 支持按 nickname/phone/realName 模糊搜索,返回列表用于下拉选择
+     * 支持按 ID 精确 / nickname / phone / realName 模糊搜索,返回列表用于下拉选择
      */
      */
     @PostMapping("/user/search")
     @PostMapping("/user/search")
     public Result<List<User>> searchUsers(@RequestBody Map<String, Object> params) {
     public Result<List<User>> searchUsers(@RequestBody Map<String, Object> params) {
-        String keyword = params.get("keyword") != null ? String.valueOf(params.get("keyword")) : "";
+        String keyword = params.get("keyword") != null ? String.valueOf(params.get("keyword")).trim() : "";
         LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
         if (!keyword.isEmpty()) {
         if (!keyword.isEmpty()) {
             wrapper.and(w -> w.like(User::getNickname, keyword)
             wrapper.and(w -> w.like(User::getNickname, keyword)
                     .or().like(User::getPhone, keyword)
                     .or().like(User::getPhone, keyword)
                     .or().like(User::getRealName, keyword));
                     .or().like(User::getRealName, keyword));
+            // 关键词为纯数字时,额外按用户 ID 精确匹配
+            try {
+                Long idVal = Long.parseLong(keyword);
+                wrapper.or().eq(User::getId, idVal);
+            } catch (NumberFormatException ignored) {
+                // 非数字关键词,跳过 ID 精确匹配
+            }
         }
         }
         wrapper.orderByDesc(User::getUpdatedAt).last("LIMIT 50");
         wrapper.orderByDesc(User::getUpdatedAt).last("LIMIT 50");
         List<User> users = userMapper.selectList(wrapper);
         List<User> users = userMapper.selectList(wrapper);

+ 16 - 2
cfc-backend/src/main/java/com/etotem/cfc/service/ProductOrderService.java

@@ -15,6 +15,8 @@ import com.etotem.cfc.mapper.AfterSalesRequestMapper;
 import com.etotem.cfc.mapper.ProductMapper;
 import com.etotem.cfc.mapper.ProductMapper;
 import com.etotem.cfc.mapper.ProductOrderMapper;
 import com.etotem.cfc.mapper.ProductOrderMapper;
 import com.etotem.cfc.mapper.UserMapper;
 import com.etotem.cfc.mapper.UserMapper;
+import com.etotem.cfc.entity.ProductSku;
+import com.etotem.cfc.service.ProductSkuService;
 import com.etotem.cfc.service.CommissionService;
 import com.etotem.cfc.service.CommissionService;
 import com.etotem.cfc.service.AssessmentProductService;
 import com.etotem.cfc.service.AssessmentProductService;
 import com.etotem.cfc.service.AssessmentQuotaService;
 import com.etotem.cfc.service.AssessmentQuotaService;
@@ -53,6 +55,9 @@ public class ProductOrderService {
     @Resource
     @Resource
     private ProductService productService;
     private ProductService productService;
 
 
+    @Resource
+    private ProductSkuService productSkuService;
+
     @Resource
     @Resource
     private CommissionService commissionService;
     private CommissionService commissionService;
 
 
@@ -147,6 +152,7 @@ public class ProductOrderService {
         int totalQuantity = 0;
         int totalQuantity = 0;
         OrderItemVO firstItem = dto.getItems().get(0);
         OrderItemVO firstItem = dto.getItems().get(0);
         Product firstProduct = null;
         Product firstProduct = null;
+        int firstUnitPrice = 0;
 
 
         for (OrderItemVO item : dto.getItems()) {
         for (OrderItemVO item : dto.getItems()) {
             Product product = productMapper.selectById(item.getProductId());
             Product product = productMapper.selectById(item.getProductId());
@@ -162,10 +168,18 @@ public class ProductOrderService {
                     && product.getStock() < item.getQuantity()) {
                     && product.getStock() < item.getQuantity()) {
                 return Result.error("库存不足: " + product.getName());
                 return Result.error("库存不足: " + product.getName());
             }
             }
-            totalAmount += product.getPrice() * item.getQuantity();
+            int unitPrice = product.getPrice();
+            if (item.getSkuId() != null) {
+                ProductSku sku = productSkuService.getById(item.getSkuId());
+                if (sku != null && sku.getPrice() != null) {
+                    unitPrice = sku.getPrice().multiply(new java.math.BigDecimal(100)).intValue();
+                }
+            }
+            totalAmount += unitPrice * item.getQuantity();
             totalQuantity += item.getQuantity();
             totalQuantity += item.getQuantity();
             if (firstProduct == null) {
             if (firstProduct == null) {
                 firstProduct = product;
                 firstProduct = product;
+                firstUnitPrice = unitPrice;
             }
             }
         }
         }
 
 
@@ -178,7 +192,7 @@ public class ProductOrderService {
         order.setBuyerId(buyerId);
         order.setBuyerId(buyerId);
         order.setFamilyId(buyer != null ? buyer.getFamilyId() : null);
         order.setFamilyId(buyer != null ? buyer.getFamilyId() : null);
         order.setQuantity(totalQuantity);
         order.setQuantity(totalQuantity);
-        order.setUnitPrice(firstProduct.getPrice());
+        order.setUnitPrice(firstUnitPrice);
         order.setTotalAmount(totalAmount);
         order.setTotalAmount(totalAmount);
         order.setPointsUsed(dto.getPointsUsed() != null ? dto.getPointsUsed() : 0);
         order.setPointsUsed(dto.getPointsUsed() != null ? dto.getPointsUsed() : 0);
         int pointsCost = dto.getPointsUsed() != null ? dto.getPointsUsed() : 0;
         int pointsCost = dto.getPointsUsed() != null ? dto.getPointsUsed() : 0;

+ 2 - 2
cfc-web/src/views/admin/supply-system/Form.vue

@@ -16,7 +16,7 @@
             v-model="form.adminId"
             v-model="form.adminId"
             filterable
             filterable
             remote
             remote
-            placeholder="搜索用户ID或昵称"
+            placeholder="输入用户ID、昵称或手机号搜索"
             :remote-method="searchUsers"
             :remote-method="searchUsers"
             :loading="searchingUser"
             :loading="searchingUser"
             style="width: 100%"
             style="width: 100%"
@@ -24,7 +24,7 @@
             <el-option
             <el-option
               v-for="u in userOptions"
               v-for="u in userOptions"
               :key="u.id"
               :key="u.id"
-              :label="u.nickname + '(' + u.id + ')'"
+              :label="u.nickname + '(ID:' + u.id + (u.phone ? ', ' + u.phone : '') + ')'"
               :value="u.id">
               :value="u.id">
             </el-option>
             </el-option>
           </el-select>
           </el-select>