Browse Source

订单搜索

gorden 1 month ago
parent
commit
64bbe73821

+ 8 - 14
app/admin/controller/order/DishesController.php

@@ -32,6 +32,7 @@ class DishesController extends Curd
     {
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
 
+        $where['order_classify'] = 'DISHES';
         if (!empty($where['order_addtimes'])) {
             $where['order_addtimes'][0] = strtotime($where['order_addtimes'][0]);
             $where['order_addtimes'][1] = strtotime($where['order_addtimes'][1]);
@@ -40,38 +41,31 @@ class DishesController extends Curd
         $order = $request->get('order', 'desc');
         $orderId = $request->get('order_id', '');
         $field = $field ?? 'order_addtimes';
-        // $where['order_category'] = 'DISHES';
         if (!empty($where['order_status_system']) && in_array($where['order_status_system'], ['PENDING', 'WAITING', 'SENDING', 'RECVING', 'SIGNED', 'CONFIRM'])) {
             $where['order_is_complete'] = 'N';
             $where['order_category'] = ['<>', 'RETURN'];
         }
-        $goodsClassify = 'MEALS';
         $orderIds = [];
         if (!empty($orderId)) {
-            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')->pluck('order_id')->toArray();
+            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')
+                ->where('order_classify', 'DISHES')
+                ->pluck('order_id')
+                ->toArray();
         }
         $goodsName = $request->get('goods_name', '');
         if (!empty($goodsName)) {
-            $goodsIds = Goods::where('goods_classify', $goodsClassify)
+            $goodsIds = Goods::where('goods_classify', 'MEALS')
                 ->where('goods_name', 'like', '%' . $goodsName . '%')
                 ->pluck('goods_id')
                 ->toArray();
-        }else if(empty($orderIds)){
-            $goodsIds = Goods::where('goods_classify', $goodsClassify)
-                ->pluck('goods_id')
-                ->toArray();
-        }
-        if (!empty($goodsName) && empty($goodsIds)){
-            $orderIds = [];
-        }else if (!empty($goodsIds)) {
             $goodsOrderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
-            if (!empty($orderIds)){
+            if (!empty($where['order_id'])) {
                 $orderIds = array_intersect($orderIds, $goodsOrderIds);
             }else{
                 $orderIds = $goodsOrderIds;
             }
         }
-        if ($orderIds) {
+        if (!empty($orderId) || !empty($goodsName)) {
             $where['order_id'] = ['in', implode(',', $orderIds)];
         }
 

+ 27 - 30
app/admin/controller/order/GoodsController.php

@@ -10,7 +10,8 @@ use app\model\OrderSheet;
 use support\Request;
 use support\Response;
 
-class GoodsController extends Curd{
+class GoodsController extends Curd
+{
     public function __construct()
     {
         $this->model = new Order();
@@ -30,6 +31,8 @@ class GoodsController extends Curd{
     public function select(Request $request): Response
     {
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
+
+        $where['order_classify'] = 'GOODS';
         if (!empty($where['order_addtimes'])) {
             $where['order_addtimes'][0] = strtotime($where['order_addtimes'][0]);
             $where['order_addtimes'][1] = strtotime($where['order_addtimes'][1]);
@@ -38,45 +41,39 @@ class GoodsController extends Curd{
         $order = $request->get('order', 'desc');
         $field = $field ?? 'order_addtimes';
         if (!empty($where['order_status_system']) && in_array($where['order_status_system'], ['PENDING', 'WAITING', 'SENDING', 'RECVING', 'SIGNED', 'CONFIRM'])) {
-            if ($where['order_status_system'] == 'SENDING'){
+            if ($where['order_status_system'] == 'SENDING') {
                 $where['order_express.order_express_type'] = '配送';
             }
             $where['order_is_complete'] = 'N';
         }
 
         $orderId = $request->get('order_id', '');
-        $goodsClassify = 'GOODS';
         $orderIds = [];
         if (!empty($orderId)) {
-            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')->pluck('order_id')->toArray();
+            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')
+                ->where('order_classify', 'GOODS')
+                ->pluck('order_id')
+                ->toArray();
         }
         $goodsName = $request->get('goods_name', '');
         if (!empty($goodsName)) {
-            $goodsIds = Goods::where('goods_classify', $goodsClassify)
+            $goodsIds = Goods::where('goods_classify', 'GOODS')
                 ->where('goods_name', 'like', '%' . $goodsName . '%')
                 ->pluck('goods_id')
                 ->toArray();
-        }else if(empty($orderIds)){
-            $goodsIds = Goods::where('goods_classify', $goodsClassify)
-                ->pluck('goods_id')
-                ->toArray();
-        }
-        if (!empty($goodsName) && empty($goodsIds)){
-            $orderIds = [];
-        }else if (!empty($goodsIds)) {
             $goodsOrderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
-            if (!empty($orderIds)){
+            if (!empty($where['order_id'])) {
                 $orderIds = array_intersect($orderIds, $goodsOrderIds);
             }else{
                 $orderIds = $goodsOrderIds;
             }
         }
-        if ($orderIds) {
+        if (!empty($orderId) || !empty($goodsName)) {
             $where['order_id'] = ['in', implode(',', $orderIds)];
         }
-        
+
         // 自提订单        
-        if (!empty($where['order_status_system']) && $where['order_status_system'] == 'PICKUP'){
+        if (!empty($where['order_status_system']) && $where['order_status_system'] == 'PICKUP') {
             $where['order_is_complete'] = 'N';
             $where['order_status_system'] = 'SENDING';
             $where['order_express.order_express_type'] = '自提';
@@ -90,7 +87,7 @@ class GoodsController extends Curd{
     {
         $model = $this->model->with([
             'sheets' => function ($query) {
-                $query->select('join_sheet_order_id', 'order_sheet_id', 'join_sheet_goods_id', 'order_sheet_num','order_sheet_price');
+                $query->select('join_sheet_order_id', 'order_sheet_id', 'join_sheet_goods_id', 'order_sheet_num', 'order_sheet_price');
             },
             'member' => function ($query) {
                 $query->select('member_id', 'member_mobile');
@@ -108,8 +105,8 @@ class GoodsController extends Curd{
             // 'express' => function ($query) {
             //     $query->select('join_express_order_id', 'order_express_type');
             // }
-        ])->leftJoin('order_return','order_return.join_return_order_id','=','order.order_id')
-        ->leftJoin('order_express','order_express.join_express_order_id','=','order.order_id');
+        ])->leftJoin('order_return', 'order_return.join_return_order_id', '=', 'order.order_id')
+            ->leftJoin('order_express', 'order_express.join_express_order_id', '=', 'order.order_id');
         // ->leftJoin('order_sheet','join_sheet_order_id','=','order.order_id');
         foreach ($where as $column => $value) {
             if (is_array($value)) {
@@ -143,7 +140,7 @@ class GoodsController extends Curd{
         if ($field) {
             $model = $model->orderBy($field, $order);
         }
-        $model = $model->select('order.*','order_express.join_express_order_id','order_express.order_express_type','order_return.orders_return_id', 'order_return.join_return_order_id', 'order_return.order_return_status','order_return.order_return_apply_json','order_return.order_return_remark');
+        $model = $model->select('order.*', 'order_express.join_express_order_id', 'order_express.order_express_type', 'order_return.orders_return_id', 'order_return.join_return_order_id', 'order_return.order_return_status', 'order_return.order_return_apply_json', 'order_return.order_return_remark');
         return $model;
     }
 
@@ -154,29 +151,29 @@ class GoodsController extends Curd{
             $item['sheet'] = $item['sheets'][0] ?? [];
             if (!empty($item['sheet'])) {
                 $goods = Goods::where('goods_id', $item['sheet']['join_sheet_goods_id'])->first();
-                if(count($item['sheets']) > 1 && $goods->goods_classify == 'MEALS'){
+                if (count($item['sheets']) > 1 && $goods->goods_classify == 'MEALS') {
                     $sheetDeng = ' 等餐品';
                 }
-                $item['sheet']['goods_name'] = ($goods && $goods->goods_name) ? $goods->goods_name.$sheetDeng : '';
+                $item['sheet']['goods_name'] = ($goods && $goods->goods_name) ? $goods->goods_name . $sheetDeng : '';
                 $item['sheet']['goods_classify'] = $goods->goods_classify ?? '';
                 $item['sheet']['order_sheet_num'] = intval($item['sheet']['order_sheet_num']);
             }
             unset($item['sheets']);
-            if (isset($item['orders_return_id'])){
+            if (isset($item['orders_return_id'])) {
                 $item['return'] = [
-                    'orders_return_id'=>$item['orders_return_id'],
+                    'orders_return_id' => $item['orders_return_id'],
                     'join_return_order_id' => $item['join_return_order_id'],
                     'order_return_status' => $item['order_return_status'],
                     'order_return_apply_json' => $item['order_return_apply_json'],
-                    'order_return_remark'=>$item['order_return_remark']
+                    'order_return_remark' => $item['order_return_remark']
                 ];
             }
-            if (isset($item['join_express_order_id'])){
+            if (isset($item['join_express_order_id'])) {
                 $item['express'] = [
-                    'join_express_order_id'=>$item['join_express_order_id'],
-                    'order_express_type'=>$item['order_express_type']
+                    'join_express_order_id' => $item['join_express_order_id'],
+                    'order_express_type' => $item['order_express_type']
                 ];
-                unset($item['join_express_order_id'],$item['order_express_type']);
+                unset($item['join_express_order_id'], $item['order_express_type']);
             }
         }
 

+ 21 - 23
app/admin/controller/order/KangyangCityController.php

@@ -54,6 +54,7 @@ class KangyangCityController extends Curd
     public function select(Request $request): Response
     {
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
+        $where['order_classify'] = 'VIP';
         if (!empty($where['order_addtimes'])) {
             $where['order_addtimes'][0] = strtotime($where['order_addtimes'][0]);
             $where['order_addtimes'][1] = strtotime($where['order_addtimes'][1]);
@@ -61,32 +62,29 @@ class KangyangCityController extends Curd
 
         $order = $request->get('order', 'desc');
         $field = $field ?? 'order_addtimes';
-        // $where['order_id'] = '';
-        $where['order_category'] = 'VIP';
-        // $goodsClassify = 'VIP';
-        $goodsName = $request->get('goods_name', '');
-        if (!empty($goodsName) && empty($goodsClassify)) {
-            $goodsIds = Goods::where('goods_name', 'like', '%' . $request->get('goods_name') . '%')->pluck('goods_id')->toArray();
+        $orderIds = [];
+        if (!empty($orderId)) {
+            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')
+                ->where('order_classify', 'VIP')
+                ->pluck('order_id')
+                ->toArray();
         }
-        // else if(!empty($goodsClassify)){
-        //     if($goodsClassify == 'SERVICE'){
-        //         $goodsModel = Goods::whereIn('goods_classify',['SERVICE','CHNMED','CHNNCD']);
-        //     }else{
-        //         $goodsModel = Goods::where('goods_classify',$goodsClassify);
-        //     }
-
-        //     if(!empty($goodsName)){
-        //         $goodsModel->where('goods_name','like','%'.$goodsName.'%');
-        //     }
-
-        //     $goodsIds = $goodsModel->pluck('goods_id')->toArray();
-        // }
-        if (!empty($goodsIds)) {
-            $orderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
-            if ($orderIds) {
-                $where['order_id'] = ['in', implode(',', $orderIds)];
+        $goodsName = trim($request->get('goods_name', ''));
+        if (!empty($goodsName)) {
+            $goodsIds = Goods::where('goods_classify', 'VIP')
+                ->where('goods_name', 'like', '%' . $goodsName . '%')
+                ->pluck('goods_id')
+                ->toArray();
+            $goodsOrderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
+            if (!empty($where['order_id'])) {
+                $orderIds = array_intersect($orderIds, $goodsOrderIds);
+            }else{
+                $orderIds = $goodsOrderIds;
             }
         }
+        if (!empty($orderId) || !empty($goodsName)) {
+            $where['order_id'] = ['in', implode(',', $orderIds)];
+        }
 
         $query = $this->doSelect($where, $field, $order);
         return $this->doFormat($query, $format, $limit);

+ 11 - 16
app/admin/controller/order/PackagesController.php

@@ -49,45 +49,40 @@ class PackagesController extends Curd
     public function select(Request $request): Response
     {
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
+        $where['order_classify'] = 'PACKAGE';
         if (!empty($where['order_addtimes'])) {
             $where['order_addtimes'][0] = strtotime($where['order_addtimes'][0]);
             $where['order_addtimes'][1] = strtotime($where['order_addtimes'][1]);
         }
 
         $order = $request->get('order', 'desc');
-        $orderId = $request->get('order_id', '');
         $field = $field ?? 'order_addtimes';
         if (!empty($where['order_status_system']) && in_array($where['order_status_system'], ['PENDING', 'WAITING', 'SENDING', 'RECVING', 'SIGNED', 'CONFIRM'])) {
             $where['order_is_complete'] = 'N';
         }
 
-        $goodsClassify = 'PACKAGE';
+        $orderId = trim($request->get('order_id', ''));
         $orderIds = [];
         if (!empty($orderId)) {
-            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')->pluck('order_id')->toArray();
+            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')
+                ->where('order_classify', 'PACKAGE')
+                ->pluck('order_id')
+                ->toArray();
         }
-        $goodsName = $request->get('goods_name', '');
+        $goodsName = trim($request->get('goods_name', ''));
         if (!empty($goodsName)) {
-            $goodsIds = Goods::where('goods_classify', $goodsClassify)
+            $goodsIds = Goods::where('goods_classify', 'PACKAGE')
                 ->where('goods_name', 'like', '%' . $goodsName . '%')
                 ->pluck('goods_id')
                 ->toArray();
-        } else if (empty($orderIds)) {
-            $goodsIds = Goods::where('goods_classify', $goodsClassify)
-                ->pluck('goods_id')
-                ->toArray();
-        }
-        if (!empty($goodsName) && empty($goodsIds)) {
-            $orderIds = [];
-        } else if (!empty($goodsIds)) {
             $goodsOrderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
-            if (!empty($orderIds)) {
+            if (!empty($where['order_id'])) {
                 $orderIds = array_intersect($orderIds, $goodsOrderIds);
-            } else {
+            }else{
                 $orderIds = $goodsOrderIds;
             }
         }
-        if ($orderIds) {
+        if (!empty($orderId) || !empty($goodsName)) {
             $where['order_id'] = ['in', implode(',', $orderIds)];
         }
         if (!empty($where['order_status_system']) && in_array($where['order_status_system'], ['PENDING', 'WAITING', 'SENDING', 'RECVING', 'SIGNED', 'CONFIRM'])) {

+ 10 - 15
app/admin/controller/order/ServicesController.php

@@ -35,41 +35,36 @@ class ServicesController extends Curd{
             $where['order_addtimes'][1] = strtotime($where['order_addtimes'][1]);
         }
 
+        $where['order_classify'] = ['in','SERVICE,CHNMED,CHNNCD'];
         $order = $request->get('order', 'desc');
         $field = $field ?? 'order_addtimes';
-        // $where['order_category'] = ['in','SERVICE,CHNMED,CHNNCD'];
         if (!empty($where['order_status_system']) && in_array($where['order_status_system'], ['PENDING', 'WAITING', 'SENDING', 'RECVING', 'SIGNED', 'CONFIRM'])) {
             $where['order_is_complete'] = 'N';
             $where['order_category'] = ['<>','RETURN'];
         }
 
-        $orderId = $request->get('order_id', '');
+        $orderId = trim($request->get('order_id', ''));
         $orderIds = [];
         if (!empty($orderId)) {
-            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')->pluck('order_id')->toArray();
+            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')
+                ->whereIn('order_classify', ['SERVICE','CHNMED','CHNNCD'])
+                ->pluck('order_id')
+                ->toArray();
         }
-        $goodsName = $request->get('goods_name', '');
+        $goodsName = trim($request->get('goods_name', ''));
         if (!empty($goodsName)) {
-            $goodsIds = Goods::whereIn('goods_classify',['SERVICE','CHNMED','CHNNCD'])
+            $goodsIds = Goods::whereIn('goods_classify', ['SERVICE','CHNMED','CHNNCD'])
                 ->where('goods_name', 'like', '%' . $goodsName . '%')
                 ->pluck('goods_id')
                 ->toArray();
-        }else if(empty($orderIds)){
-            $goodsIds = Goods::whereIn('goods_classify',['SERVICE','CHNMED','CHNNCD'])
-                ->pluck('goods_id')
-                ->toArray();
-        }
-        if (!empty($goodsName) && empty($goodsIds)){
-            $orderIds = [];
-        }else if (!empty($goodsIds)) {
             $goodsOrderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
-            if (!empty($orderIds)){
+            if (!empty($where['order_id'])) {
                 $orderIds = array_intersect($orderIds, $goodsOrderIds);
             }else{
                 $orderIds = $goodsOrderIds;
             }
         }
-        if ($orderIds) {
+        if (!empty($orderId) || !empty($goodsName)) {
             $where['order_id'] = ['in', implode(',', $orderIds)];
         }
 

+ 35 - 26
app/admin/controller/order/WholeController.php

@@ -70,6 +70,11 @@ class WholeController extends Curd
             $where['order_addtimes'][0] = strtotime($where['order_addtimes'][0]);
             $where['order_addtimes'][1] = strtotime($where['order_addtimes'][1]);
         }
+        if ($request->get('goods_classify') && $request->get('goods_classify') == 'SERVICE') {
+            $where['order_classify'] = ['in', 'SERVICE,CHNMED,CHNNCD'];
+        } else if ($request->get('goods_classify')) {
+            $where['order_classify'] = $request->get('goods_classify');
+        }
 
         $order = $request->get('order', 'desc');
         $type = $request->get('type', '');
@@ -131,14 +136,12 @@ class WholeController extends Curd
         }
         if ($request->get('goods_classify') || $request->get('goods_name')) {
             $orderGoodsIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
-//            if ($orderGoodsIds) {
             if (!empty($where['order_id'])) {
                 $orderIds = array_intersect($orderIds, $orderGoodsIds);
                 $where['order_id'] = ['in', implode(',', $orderIds)];
             } else {
                 $where['order_id'] = ['in', implode(',', $orderGoodsIds)];
             }
-//            }
         } elseif (!empty($orderIds)) {
             $where['order_id'] = ['in', implode(',', $orderIds)];
         }
@@ -4180,6 +4183,13 @@ class WholeController extends Curd
     {
         $type = $request->get('type', '');
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
+
+        if ($request->get('goods_classify') && $request->get('goods_classify') == 'SERVICE') {
+            $where['order_classify'] = ['in', 'SERVICE,CHNMED,CHNNCD'];
+        } else if ($request->get('goods_classify')) {
+            $where['order_classify'] = $request->get('goods_classify');
+        }
+
         $where['order_category'] = ['<>', 'RECHARGE'];
         if (!empty($request->get('order_ids'))) {
             $where['order_id'] = ['in', $request->get('order_ids')];
@@ -4202,31 +4212,30 @@ class WholeController extends Curd
                 ->toArray();
             $where['order_groupby'] = ['in', $groupIds];
         }
-        if ($request->get('goods_classify') || $request->get('goods_name')) {
-            $where['order_id'] = '';
-            $goodsClassify = $request->get('goods_classify', '');
-            $goodsName = $request->get('goods_name', '');
-            if (!empty($goodsName) && empty($goodsClassify)) {
-                $goodsIds = Goods::where('goods_name', 'like', '%' . $request->get('goods_name') . '%')->pluck('goods_id')->toArray();
-            } else if (!empty($goodsClassify)) {
-                if ($goodsClassify == 'SERVICE') {
-                    $goodsModel = Goods::whereIn('goods_classify', ['SERVICE', 'CHNMED', 'CHNNCD']);
-                } else {
-                    $goodsModel = Goods::where('goods_classify', $goodsClassify);
-                }
-
-                if (!empty($goodsName)) {
-                    $goodsModel->where('goods_name', 'like', '%' . $goodsName . '%');
-                }
-
-                $goodsIds = $goodsModel->pluck('goods_id')->toArray();
-            }
-            if ($goodsIds) {
-                $orderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
-                if ($orderIds) {
-                    $where['order_id'] = ['in', implode(',', $orderIds)];
-                }
+        $orderId = trim($request->get('order_id', ''));
+        $orderIds = [];
+        if (!empty($orderId)) {
+            $orderIds = Order::where('order_id', 'like', '%' . $orderId . '%')
+                ->whereIn('order_classify', ['SERVICE', 'CHNMED', 'CHNNCD'])
+                ->pluck('order_id')
+                ->toArray();
+        }
+        $goodsName = trim($request->get('goods_name', ''));
+        if (!empty($goodsName)) {
+            $goodsIds = Goods::whereIn('goods_classify', ['SERVICE', 'CHNMED', 'CHNNCD'])
+                ->where('goods_name', 'like', '%' . $goodsName . '%')
+                ->pluck('goods_id')
+                ->toArray();
+            $goodsOrderIds = OrderSheet::whereIn('join_sheet_goods_id', $goodsIds)->pluck('join_sheet_order_id')->toArray();
+            if (!empty($where['order_id'])) {
+                $orderIds = array_intersect($orderIds, $goodsOrderIds);
+            } else {
+                $orderIds = $goodsOrderIds;
             }
+            dump($orderIds);
+        }
+        if (!empty($orderId) || !empty($goodsName)) {
+            $where['order_id'] = ['in', implode(',', $orderIds)];
         }
         $order = $request->get('order', 'desc');
         $field = $field ?? 'order_addtimes';