cqpCow 8 maanden geleden
bovenliggende
commit
d92727306e
3 gewijzigde bestanden met toevoegingen van 71 en 7 verwijderingen
  1. 21 3
      app/Service/ConstructionService.php
  2. 2 2
      app/Service/RangeService.php
  3. 48 2
      app/Service/SalesOrderService.php

+ 21 - 3
app/Service/ConstructionService.php

@@ -549,10 +549,24 @@ class ConstructionService extends Service
     public function constructionList($data,$user){
         $model = Construction::Clear($user,$data);
         $model = $model->where('del_time',0)
-            ->select('title','id','model_type','order_number','customer_id','customer_contact_id','install_method','install_position','sales_order_id','construction_fee','construction_time','handover_time','urgency','crt_id','crt_time','mark','state','address1','address2','introduction','service_price','storehouse_id','start_time','end_time','pq_state','day_start_stamp','day_end_stamp')
             ->orderby('id', 'desc');
-
-        if(isset($data['state'])) $model->where('state', $data['state']);
+        if(empty($data['select_field'])){
+            $model->select('title','id','model_type','order_number','customer_id','customer_contact_id','install_method','install_position','sales_order_id','construction_fee','construction_time','handover_time','urgency','crt_id','crt_time','mark','state','address1','address2','introduction','service_price','storehouse_id','start_time','end_time','pq_state','day_start_stamp','day_end_stamp');
+        }else{
+            $model->select('sales_order_id');
+        }
+        if(isset($data['state'])) {
+            $today_stamp = strtotime(date("Y-m-d H:i:00"));
+            if($data['state'] == Construction::STATE_DIFF_TWO){
+                $model->where('state', Construction::STATE_TWO);
+                $model->where('start_time', '>', $today_stamp);
+            }elseif($data['state'] == Construction::STATE_TWO){
+                $model->where('state', Construction::STATE_TWO);
+                $model->where('start_time', '<=', $today_stamp);
+            }else{
+                $model->where('state', $data['state']);
+            }
+        }
         if(isset($data['pq_state'])) $model->where('pq_state', $data['pq_state']);
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);
@@ -596,6 +610,7 @@ class ConstructionService extends Service
         }
         if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
 
+        if(! empty($data['select_field'])) return $model->get()->toArray();
         $list = $this->limit($model,'',$data);
         $list = $this->fillData($list);
 
@@ -815,6 +830,7 @@ class ConstructionService extends Service
     }
 
     public function makeState($value, $state_array){
+        $today_stamp = strtotime(date("Y-m-d H:i:00"));
         if(! empty($state_array[$value['order_number']])){
             $return = $state_array[$value['order_number']];
             if($value['state'] == Construction::State_minus_one){
@@ -824,6 +840,8 @@ class ConstructionService extends Service
             }
         }elseif($value['state'] == Construction::STATE_ZERO){
             $state = "待" . $value['crt_name'] . "提交";
+        }elseif($value['state'] == Construction::STATE_TWO && $value['start_time'] > $today_stamp){
+            $state = Construction::$name[Construction::STATE_DIFF_TWO] ?? '';
         }else{
             $state = Construction::$name[$value['state']] ?? '';
         }

+ 2 - 2
app/Service/RangeService.php

@@ -648,7 +648,7 @@ class RangeService extends Service
             $args = "(state = ". Construction::STATE_ONE . ")";
         }elseif($search['is_check'] == 2){
             //已审
-            $args = "(state = ". Construction::STATE_TWO . ")";
+            $args = "(state >= ". Construction::STATE_TWO . ")";
         }
 
         return $args;
@@ -661,7 +661,7 @@ class RangeService extends Service
             $args = "(state = ". PurchaseOrder::STATE_ONE . ")";
         }elseif($search['is_check'] == 2){
             //已审
-            $args = "(state = ". PurchaseOrder::STATE_TWO . ")";
+            $args = "(state >= ". PurchaseOrder::STATE_TWO . ")";
         }
 
         return $args;

+ 48 - 2
app/Service/SalesOrderService.php

@@ -857,6 +857,15 @@ class SalesOrderService extends Service
             $id = (new CustomerService())->searchBy($data,$user);
             $model->whereIn('customer_id', $id);
         }
+        if(isset($data['construction_state'])){
+            $for_search = [
+                'state' => $data['construction_state'],
+                'select_field' => true,
+            ];
+            $service = new ConstructionService();
+            $return = $service->constructionList($for_search,$user);
+            $model->whereIn('id', array_unique(array_column($return,'sales_order_id')));
+        }
 
         $list = $this->limit($model,'',$data);
         $list = $this->fillData($list,$data);
@@ -864,6 +873,43 @@ class SalesOrderService extends Service
         return [true, $list];
     }
 
+    function createTempTableIfNotExists($ids, &$model)
+    {
+        if (empty($ids)) {
+            $model->whereIn('id', []);
+            return;
+        }
+
+        // 使用事务
+        DB::beginTransaction();
+
+        try {
+            // 先删除已有的临时表
+            DB::unprepared('DROP TEMPORARY TABLE IF EXISTS temp_ids');
+
+            // 创建临时表
+            DB::unprepared('CREATE TEMPORARY TABLE temp_ids (id INT)');
+
+            // 插入数据
+            foreach (array_chunk($ids, 1000) as $chunk) {
+                DB::table('temp_ids')->insert(array_map(function ($id) {
+                    return ['id' => $id];
+                }, $chunk));
+            }
+
+            // 使用临时表
+            $model->whereIn('id', function ($query) {
+                $query->select('id')->from('temp_ids');
+            });
+
+            // 提交事务
+            DB::commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            DB::rollBack();
+        }
+    }
+
     /**
      * 订单参数规则
      * @param $data
@@ -1521,7 +1567,7 @@ class SalesOrderService extends Service
 
         $result = Construction::where('del_time',0)
             ->whereIn('sales_order_id',$sale_order_id)
-            ->select('order_number','sales_order_id','state','crt_id')
+            ->select('order_number','sales_order_id','state','crt_id','start_time')
             ->get()->toArray();
         $emp = Employee::whereIn('crt_id',array_unique(array_column($result,'crt_id')))
             ->pluck('emp_name','id')
@@ -1534,7 +1580,7 @@ class SalesOrderService extends Service
         foreach ($result as $value){
             $value['crt_name'] = $emp[$value['crt_id']] ?? "";
             $state_title = $service->makeState($value, $state_array);
-            $string = $value['order_number'] . ":" . $state_title;
+            $string = $value['order_number'] . " : " . $state_title;
             if(isset($return[$value['sales_order_id']])){
                 $return[$value['sales_order_id']] .= ',' . $string;
             }else{