Explorar el Código

零售端-订单列表搜索条件:纯数字按货号精确匹配,否则按客户姓名模糊匹配

ouyang hace 2 semanas
padre
commit
264dc82b02
Se han modificado 1 ficheros con 21 adiciones y 3 borrados
  1. 21 3
      app-hd/controllers/OrderController.php

+ 21 - 3
app-hd/controllers/OrderController.php

@@ -1314,7 +1314,6 @@ class OrderController extends BaseController
     {
         $get = Yii::$app->request->get();
         $searchText = $get['searchText'] ?? '';
-        $searchStyle = $get['searchStyle'] ?? 0;
         $shopId = $this->shopId ?? 0;
         if (empty($shopId)) {
             //没有登录不显示数据
@@ -1343,8 +1342,9 @@ class OrderController extends BaseController
         if (!empty($get['shopAdminId'])) {
             $where['shopAdminId'] = $get['shopAdminId'];
         }
-        if ($searchStyle == 1 && !empty($searchText)) {
-            $where['sendNum'] = $searchText;
+        // 按搜索词自动识别:纯数字查货号,否则查姓名
+        if (!empty($searchText)) {
+            $this->appendOrderListSearchWhere($where, $searchText);
         }
         if (isset($get['repeat']) && $get['repeat'] > -1) {
             $where['repeat'] = $get['repeat'];
@@ -1497,4 +1497,22 @@ class OrderController extends BaseController
         util::success(['sedCost' => 10]);
     }
 
+    /**
+     * 订单列表搜索条件:纯数字按货号精确匹配,否则按客户姓名模糊匹配
+     * @param array $where 查询条件(引用传递)
+     * @param string $searchText 搜索关键词
+     */
+    private function appendOrderListSearchWhere(&$where, $searchText)
+    {
+        $searchText = trim((string)$searchText);
+        if ($searchText === '') {
+            return;
+        }
+        if (preg_match('/^\d+$/', $searchText)) {
+            $where['sendNum'] = $searchText;
+            return;
+        }
+        $where['customName'] = ['like', $searchText];
+    }
+
 }