cqpCow 1 年之前
父节点
当前提交
a6ccd7a47f
共有 3 个文件被更改,包括 110 次插入0 次删除
  1. 26 0
      app/Http/Controllers/Api/ScheduleController.php
  2. 82 0
      app/Service/ScheduleService.php
  3. 2 0
      routes/api.php

+ 26 - 0
app/Http/Controllers/Api/ScheduleController.php

@@ -100,4 +100,30 @@ class ScheduleController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function getSettingTotal(Request $request)
+    {
+        $service = new ScheduleService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->getSettingTotal($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function getSettingGetDetail(Request $request)
+    {
+        $service = new ScheduleService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->getSettingGetDetail($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 82 - 0
app/Service/ScheduleService.php

@@ -4,6 +4,7 @@ namespace App\Service;
 
 use App\Model\BasicType;
 use App\Model\Construction;
+use App\Model\ConstructionProductInfo;
 use App\Model\Employee;
 use App\Model\Product;
 use App\Model\ProductActivity;
@@ -466,4 +467,85 @@ class ScheduleService extends Service
 
         return [true, $result];
     }
+
+    public function getSettingTotal($data,$user){
+        if(empty($data['schedule'])) return [true,""];
+        // 获取指定年月的开始日期时间戳
+        $startTimestamp = strtotime($data['schedule'] . "-01");
+        // 获取下个月的开始日期时间戳,然后减去一秒得到本月的结束日期时间戳
+        $endTimestamp = strtotime("+1 month", $startTimestamp) - 1;
+
+        $return = [];
+        for ($i = $startTimestamp; $i <= $endTimestamp; $i += 86400) { // 每天86400秒
+            $time = date("Y-m-d", $i);
+            $return[$i] = [
+                'time' => $time,
+                'num' => 0,
+                'order' => "",
+            ];
+        }
+
+        $model = Schedule::TopClear($user,$data);
+        $schedule = $model->where('del_time',0)
+            ->where('start_time', '>=', $startTimestamp)
+            ->where('end_time', '<=', $endTimestamp)
+            ->select('id')
+            ->get()->toArray();
+        if(empty($schedule)) return [true, $return];
+
+        $construction = Construction::where('del_time',0)
+            ->whereIn('schedule_id',array_column($schedule,'id'))
+            ->select('day_stamp','id')
+            ->get()->toArray();
+
+        foreach ($construction as $value){
+            if(isset($return[$value['day_stamp']])){
+                $return[$value['day_stamp']]['num'] += 1;
+                $return[$value['day_stamp']]['order'] .= $value['id'] . ',';
+            }
+        }
+
+        return [true, array_values($return)];
+    }
+
+    public function getSettingGetDetail($data, $user){
+        if(empty($data['order'])) return [true, ""];
+        $order_id = array_filter(explode(',', $data['order']));
+        if(empty($order_id)) return [true, ""];
+
+        $construction = Construction::where('del_time',0)
+            ->whereIn('id',$order_id)
+            ->select('id','order_number','crt_id')
+            ->get()->toArray();
+        if(empty($construction)) return [true, ""];
+        $emp = Employee::whereIn('id',array_unique(array_column($construction,'crt_id')))
+            ->pluck('emp_name','id')
+            ->toArray();
+        $product_title = [];
+        $product = ConstructionProductInfo::whereIn('construction_id',array_unique(array_column($construction,'id')))
+            ->select('product_id','construction_id')
+            ->get()->toArray();
+        $product_map = Product::whereIn('id',array_unique(array_column($product,'product_id')))
+            ->pluck('title','id')
+            ->toArray();
+        foreach ($product as $value){
+            if(! isset($product_title[$value['construction_id']])){
+                $product_title[$value['construction_id']] = $product_map[$value['product_id']];
+            }else{
+                $product_title[$value['construction_id']] .= "," . $product_map[$value['product_id']];
+            }
+        }
+
+        $return = [];
+        foreach ($construction as $value){
+            $tmp = [
+                'order_number' => $value['order_number'],
+                'crt_name' => $emp[$value['crt_id']] ?? "",
+                'product' => $product_title[$value['id']],
+            ];
+            $return[] = $tmp;
+        }
+
+        return [true, $return];
+    }
 }

+ 2 - 0
routes/api.php

@@ -247,6 +247,8 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('scheduleDel', 'Api\ScheduleController@del');
     $route->any('scheduleGetForConstruction', 'Api\ScheduleController@scheduleGetForConstruction');
     $route->any('getScheduleSetting', 'Api\ScheduleController@getScheduleSetting');
+    $route->any('getSettingTotal', 'Api\ScheduleController@getSettingTotal');
+    $route->any('getSettingGetDetail', 'Api\ScheduleController@getSettingGetDetail');
 
     //现存量
     $route->any('productInventoryList', 'Api\ProductInventoryController@productInventoryList');