فهرست منبع

花掌柜PC端订单列表接口

ouyang 1 روز پیش
والد
کامیت
6f7e3546e5
1فایلهای تغییر یافته به همراه59 افزوده شده و 1 حذف شده
  1. 59 1
      app-hd/controllers/OrderController.php

+ 59 - 1
app-hd/controllers/OrderController.php

@@ -1467,6 +1467,10 @@ class OrderController extends BaseController
         util::success($detail);
     }
 
+    /**
+     * 订单列表(PC/小程序共用)
+     * 支持图1独立筛选项:订单编号、货号、订单类型、配送方式、付款类型、人员关键词、创建时间
+     */
     public function actionList()
     {
         $get = Yii::$app->request->get();
@@ -1499,7 +1503,34 @@ class OrderController extends BaseController
         if (!empty($get['shopAdminId'])) {
             $where['shopAdminId'] = $get['shopAdminId'];
         }
-        // 按搜索词自动识别:纯数字查货号,否则查姓名
+        // PC 端独立筛选:订单编号 / 货号
+        if (!empty($get['orderSn'])) {
+            $where['orderSn'] = ['like', trim((string)$get['orderSn'])];
+        }
+        if (!empty($get['sendNum'])) {
+            $where['sendNum'] = trim((string)$get['sendNum']);
+        }
+        // 订单类型 fromType:门店/商城/微信/美团/饿了么
+        if (isset($get['fromType']) && $get['fromType'] !== '' && (int)$get['fromType'] > -1) {
+            $where['fromType'] = (int)$get['fromType'];
+        }
+        // 配送方式 sendType
+        if (isset($get['sendType']) && $get['sendType'] !== '' && (int)$get['sendType'] > -1) {
+            $where['sendType'] = (int)$get['sendType'];
+        }
+        // 付款类型:兼容 payWay 或 onlinePay
+        if (isset($get['payWay']) && $get['payWay'] !== '' && (int)$get['payWay'] > -1) {
+            $where['payWay'] = (int)$get['payWay'];
+        }
+        if (isset($get['onlinePay']) && $get['onlinePay'] !== '' && (int)$get['onlinePay'] > -1) {
+            $where['onlinePay'] = (int)$get['onlinePay'];
+        }
+        // 下单人/收货人/姓名/手机号:多字段 OR 模糊匹配,先查 id 再并入 where(Base 条件不支持 OR)
+        if (!empty($get['keyword'])) {
+            $keywordIds = $this->findOrderIdsByKeyword($shopId, trim((string)$get['keyword']));
+            $where['id'] = ['in', !empty($keywordIds) ? $keywordIds : [0]];
+        }
+        // 按搜索词自动识别:纯数字查货号,否则查姓名(小程序兼容)
         if (!empty($searchText)) {
             $this->appendOrderListSearchWhere($where, $searchText);
         }
@@ -1672,4 +1703,31 @@ class OrderController extends BaseController
         $where['customName'] = ['like', $searchText];
     }
 
+    /**
+     * 按人员/手机关键词查订单 id(下单人、收货人、客户名、开单人、手机号)
+     * @param int $shopId 门店 id
+     * @param string $keyword 关键词
+     * @return array
+     */
+    private function findOrderIdsByKeyword($shopId, $keyword)
+    {
+        if ($keyword === '' || empty($shopId)) {
+            return [];
+        }
+        return (new \yii\db\Query())
+            ->select('id')
+            ->from(\bizHd\order\models\Order::tableName())
+            ->where(['shopId' => $shopId])
+            ->andWhere([
+                'or',
+                ['like', 'bookName', $keyword],
+                ['like', 'receiveUserName', $keyword],
+                ['like', 'customName', $keyword],
+                ['like', 'shopAdminName', $keyword],
+                ['like', 'bookMobile', $keyword],
+                ['like', 'receiveMobile', $keyword],
+            ])
+            ->column();
+    }
+
 }