qiuenguang 1 жил өмнө
parent
commit
b2272be611

+ 84 - 0
application/api/controller/ReportingWork.php

@@ -467,4 +467,88 @@ class ReportingWork extends Api
         }
         $this->success('请求成功',$list);
     }
+
+
+    /**
+     * 设置当前生产工单
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function MachineWorkOrderEdit()
+    {
+        if (Request::instance()->isPost() === false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        $list = \db('工单_基本资料')
+            ->alias('a')
+            ->field([
+                'RTRIM( b.Gy0_sj1 )' => 'sj1',
+                'RTRIM( b.Gy0_sj2 )' => 'sj2',
+                'RTRIM( b.UniqId )' => 'id'
+            ])
+            ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
+            ->where([
+                'a.gd_statu' => '2-生产中',
+                'a.行号' => '1',
+                'b.Gy0_sbbh' => ['LIKE', '%' . $params['machine'] . '%'],
+                'b.PD_WG' => '1900-01-01 00:00:00',
+                'b.Gy0_sj1' => ['>', '1900-01-01 00:00:00'],
+            ])
+            ->where('b.Gy0_sj1', '<', '2099-01-01 00:00:00')
+            ->group('a.Gd_gdbh,b.Gy0_gxh')
+            ->order('Gy0_sj1')
+            ->select();
+        $start = date('Y-m-d H:i:s', time());
+        if ($start < date('Y-m-d H:15:00', time())) {
+            $start = date('Y-m-d H:00:00', time());
+        } elseif ($start > date('Y-m-d H:45:00', time())) {
+            $start = date('Y-m-d H+1:00:00', time());
+        } else {
+            $start = date('Y-m-d H:30:00', time());
+        }
+        $data = $time = [];
+        $i = 0;
+        foreach ($list as $key => $value) {
+            if ($value['id'] === $params['UniqId']) {
+                $time = [
+                    'Gy0_sj1' => $start,
+                    'Gy0_sj2' => date('Y-m-d H:i:s', strtotime($start) + (strtotime($value['sj1']) - strtotime($value['sj2']))),
+                    'id' => $value['id']
+                ];
+                unset($list[$key]);
+            }
+        }
+        $arr = array_values($list);
+        $data[0] = $time;
+        foreach ($arr as $key => $value){
+            $workTime = [
+                'Gy0_sj1' => $data[$key]['Gy0_sj2'],
+                'Gy0_sj2' => date('Y-m-d H:i:s', strtotime($data[$key]['Gy0_sj2']) + (strtotime($value['sj1']) - strtotime($value['sj2']))),
+                'id' => $value['id']
+            ];
+            array_push($data,$workTime);
+        }
+        foreach ($data as $key=>$value){
+            unset($value['id']);
+            $sql = \db('工单_工艺资料')
+                ->where('UniqId',$data[$key]['id'])
+                ->fetchSql(true)
+                ->update($value);
+            $res = \db()->query($sql);
+            if ($res === false){
+                $i++;
+            }
+        }
+        if ($i !== 0){
+            $this->error('失败');
+        }else{
+            $this->success('成功');
+        }
+    }
 }