cqpCow 1 سال پیش
والد
کامیت
eb3a5945bc
3فایلهای تغییر یافته به همراه81 افزوده شده و 0 حذف شده
  1. 12 0
      app/Http/Controllers/Api/DeleteController.php
  2. 66 0
      app/Service/DeleteService.php
  3. 3 0
      routes/api.php

+ 12 - 0
app/Http/Controllers/Api/DeleteController.php

@@ -56,4 +56,16 @@ class DeleteController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function pq(Request $request){
+        $service = new DeleteService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->pq($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 66 - 0
app/Service/DeleteService.php

@@ -2,10 +2,12 @@
 
 namespace App\Service;
 
+use App\Model\Construction;
 use App\Model\Employee;
 use App\Model\OrderOperation;
 use App\Model\SalesOrder;
 use App\Model\SalesOrderInfo;
+use App\Model\ScheduleInfo;
 use Illuminate\Support\Facades\DB;
 
 class DeleteService extends Service
@@ -167,4 +169,68 @@ class DeleteService extends Service
             ],$user);
         }
     }
+
+    public function pq($data,$user){
+        list($status,$msg) = $this->pqRule($data,$user);
+        if(! $status) return [false,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            if(! empty($msg['schedule_id']) && ! empty($msg['day_start_stamp']) && ! empty($msg['day_end_stamp'])){
+                //如果已经设置过排期 将子表占用数据释放
+                $schedule = ScheduleInfo::where('del_time',0)
+                    ->where('schedule_id',$msg['schedule_id'])
+                    ->where('start_time',$msg['day_start_stamp'])
+                    ->where('end_time',$msg['day_end_stamp'])
+                    ->where('is_use','>', ScheduleInfo::not_use)
+                    ->first();
+                if(! empty($schedule)) ScheduleInfo::where('id',$schedule->id)->update(['is_use' => ScheduleInfo::not_use]);
+            }
+
+            Construction::where('id',$data['id'])->update([
+                'schedule_id' => $data['schedule_id'],
+                'day_stamp' => $data['day_stamp'],
+                'day_start_stamp' => $data['day_start_stamp'],
+                'day_end_stamp' => $data['day_end_stamp'],
+            ]);
+
+            if(! empty($data['schedule_info_id'])) ScheduleInfo::where('id',$data['schedule_info_id'])->update(['is_use' => 1]);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            $this->dellimitingSendRequestBackg(ScheduleInfo::limit_key . $data['schedule_info_id']);
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        $this->dellimitingSendRequestBackg(ScheduleInfo::limit_key . $data['schedule_info_id']);
+
+        return [true,''];
+    }
+
+    public function pqRule(&$data,$user){
+        if(empty($data['id'])) return [false, '施工单不能为空!'];
+        $construction = Construction::where('id',$data['id'])->where('del_time',0)->first();
+        if(empty($construction)) return [false,'施工单不存在或已被删除'];
+        $construction = $construction->toArray();
+        if(empty($data['schedule_id']) ||empty($data['day_stamp']) || empty($data['day_start_stamp']) || empty($data['day_end_stamp'])) return [false,'排班时间信息不能为空'];
+        //day_stamp 日期的时间戳(0点的) day_start_stamp 日期加上开始时分的时间戳  day_end_stamp 日期加上结束时分的时间戳
+        if($construction['day_stamp'] != $data['day_stamp'] || $construction['day_start_stamp'] != $data['day_start_stamp'] && $construction['day_end_stamp'] != $data['day_end_stamp']) {
+            $schedule_info = ScheduleInfo::where('del_time',0)
+                ->where('day',$data['day_stamp'])
+                ->where('start_time',$data['day_start_stamp'])
+                ->where('end_time',$data['day_end_stamp'])
+                ->where('is_use',ScheduleInfo::not_use)
+                ->first();
+            if(! empty($schedule_info)) return [false,'该时间段排班已满或不存在!'];
+            $data['schedule_info_id'] = $schedule_info->id;
+            list($status,$msg) = $this->limitingSendRequestBackg(ScheduleInfo::limit_key . $data['schedule_info_id']);
+            if(! $status) return [false,'操作频繁,请稍等!'];
+        }else{
+            return [false,'排期未做更新!'];
+        }
+
+        return [true, $construction];
+    }
 }

+ 3 - 0
routes/api.php

@@ -254,6 +254,9 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //移交 分配
     $route->any('fpMan','Api\DeleteController@fp');
     $route->any('yjMan','Api\DeleteController@yj');
+    //排期
+    $route->any('pq','Api\DeleteController@pq');
+
     //导入
     $route->any('import','Api\ImportController@import');