Selaa lähdekoodia

糊盒报工优化

unknown 3 kuukautta sitten
vanhempi
sitoutus
d5421423ba
1 muutettua tiedostoa jossa 140 lisäystä ja 10 poistoa
  1. 140 10
      application/api/controller/GluingReport.php

+ 140 - 10
application/api/controller/GluingReport.php

@@ -298,22 +298,65 @@ class GluingReport extends Api
      * @throws \think\db\exception\BindParamException
      * @throws \think\exception\PDOException
      */
-    public function AddGluingReportData()
+    public function addGluingReportData()
     {
-        if ($this->request->isPost() === false){
+        // 1. 请求验证
+        if (!$this->request->isPost()) {
             $this->error('请求错误');
         }
-        $param = Request::instance()->post();
-        if (empty($param)){
+
+        // 2. 参数验证
+        $param = $this->request->post();
+        if (empty($param)) {
             $this->error('参数错误');
         }
-        $param['sys_rq'] = date('Y-m-d H:i:s',time());
-        $Sql = db('设备_糊盒报工资料')->fetchSql(true)->insert($param);
-        $res = db()->query($Sql);
-        if ($res === false){
-            $this->error('报工失败');
-        }else{
+
+        // 3. 使用事务确保数据一致性
+        Db::startTrans();
+        try {
+            // 准备数据
+            $currentTime = date('Y-m-d H:i:s');
+
+            // 构建班组数据
+            $classData = [
+                'sys_rq'  => $currentTime,
+                'jtbh'    => $param['sczl_jtbh'] ?? '',
+                'gdbh'    => $param['sczl_gdbh'] ?? '',
+                'gxmc'    => $param['sczl_gxmc'] ?? '',
+                'sys_id'  => $param['sys_id'] ?? '',
+                'sczl_rq' => $param['sczl_rq'] ?? '',
+            ];
+
+            // 处理动态字段
+            for ($i = 1; $i <= 30; $i++) {
+                $classData['bh'.$i] = $param['bh'.$i] ?? '';
+                $classData['rate'.$i] = $param['rate'.$i] ?? '';
+                unset($param['bh'.$i], $param['rate'.$i]);
+            }
+
+            // 保存班组数据
+            $classId = \db('糊盒报工班组')->insertGetId($classData);
+            if (!$classId) {
+                throw new \Exception('保存班组数据失败');
+            }
+
+            // 保存设备数据
+            unset($param['sczl_jtbh'], $param['sczl_gdbh'], $param['sczl_gxmc']);
+            $param['role'] = $classId;
+            $param['sys_rq'] = $currentTime;
+
+            $sql = \db('设备_糊盒报工资料')->fetchSql(true)->insert($param);
+            $result = db()->query($sql);
+            if (!$result) {
+                throw new \Exception('保存设备数据失败');
+            }
+
+            Db::commit();
             $this->success('报工成功');
+
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage() ?: '报工失败');
         }
     }
 
@@ -738,4 +781,91 @@ class GluingReport extends Api
         $this->success('成功',$list);
     }
 
+
+    /**
+     * 工单查询
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function getWorkOrderList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $params = $this->request->param();
+        if (!isset($params['search']) || empty($params['search'])){
+            $this->error('参数错误');
+        }
+        $search = $params['search'];
+        $list = \db('工单_基本资料')
+            ->where('Gd_gdbh|Gd_cpmc','like',$search.'%')
+            ->field('Gd_gdbh as 工单编号,Gd_cpdh as  产品代号,Gd_cpmc as 产品名称')
+            ->order('Gd_gdbh desc')
+            ->select();
+        if (empty($list)){
+            $this->error('未找到数据');
+        }else{
+            $this->success('成功',$list);
+        }
+    }
+
+
+    /**
+     * 查询机台编号
+     * @return void
+     */
+    public function getMachineList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $params = $this->request->param();
+        if (!isset($params['search']) || empty($params['search'])){
+            $this->error('参数错误');
+        }
+        $search = $params['search'];
+        $list = \db('设备_基本资料')
+            ->where('使用部门',$search)
+            ->column('设备名称','设备编号');
+        if (empty($list)){
+            $this->error('未找到数据');
+        }else{
+            $this->success('成功',$list);
+        }
+    }
+
+    /**
+     * 查询工艺名称
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function gitProcessList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $params = $this->request->param();
+        if (!isset($params['search']) || empty($params['search'])){
+            $this->error('参数错误');
+        }
+        $search = $params['search'];
+        $list = \db('erp_常用字典')
+            ->where('分类','糊盒工艺')
+            ->where('名称','like','%'.$search.'%')
+            ->field('名称')
+            ->select();
+        $data = [];
+        if (empty($list)){
+            $this->error('未找到工艺数据');
+        }
+        foreach ($list as $k=>$v){
+            $name = explode('_',$v['名称']);
+            $data[] = $name[2];
+        }
+        $this->success('成功',$data);
+    }
 }