Browse Source

工单附件资料

曹鹤洋 1 year ago
parent
commit
a9e08975b5
1 changed files with 107 additions and 48 deletions
  1. 107 48
      application/api/controller/WorkOrder.php

+ 107 - 48
application/api/controller/WorkOrder.php

@@ -313,6 +313,16 @@ class WorkOrder extends Api
             $data['BOM'] = [];
         }
 
+        //工单附件资料
+        $jsRes = db('工单_相关附件')
+            ->where('关联编号','like','%'.$Gd_gdbh.'%')
+            ->select();
+        if (!empty($jsRes)){
+            $data['jsData'] = $jsRes;
+        }else{
+            $data['jsData'] = [];
+        }
+
         $this->success('成功',$data);
     }
 
@@ -1712,7 +1722,7 @@ class WorkOrder extends Api
     }
 
     /**
-     * 获取产品附件列表
+     * 产品附件新增
      */
     public function annexAdd(){
         if(!$this->request->isPost()){
@@ -1761,7 +1771,7 @@ class WorkOrder extends Api
     }
     
     /**
-     * 修改
+     * 产品附件修改
      * @ApiMethod (GET)
      * @param string 'UniqId'
      */
@@ -1794,55 +1804,104 @@ class WorkOrder extends Api
 
     }
 
-    //02-产品管理-技术资料附件
-    public function getExcelInfo()
-    {
-        $fileName = '黄金叶(软大金圆)(二维码版)';
-    $filePath = 'uploads/黄金叶(软大金圆)(二维码版).xlsx'; // Excel文件路径
-    // $fileContent = file_get_contents($filePath);
+    /**
+     * 获取产品附件列表
+     */
+    public function getGdAnnexTable(){
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        if (isset($req['gdbh']) && !empty($req['gdbh'])){
+            $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
+        }else{
+            $this->error('参数错误');
+        }
+        $rows = db('工单_相关附件')
+            ->where($where)
+            ->select();
+        $this->success('成功',$rows);
+    }
 
-    // return $fileContent;
-    
-    
-    $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
-        $host = $_SERVER['HTTP_HOST'];
-        $siteUrl = $protocol . '://' . $host .'/'.$filePath ;
-    $this->success('成功',['fileName'=>$fileName,'filePath'=>$siteUrl]);
-    $excelData = []; // 存储 Excel 数据的数组
-
-    $reader = IOFactory::createReader('Xlsx'); // 创建Excel读取器
-    $spreadsheet = $reader->load($filePath); // 加载Excel文件
-
-    $sheetData = $spreadsheet->getActiveSheet(); // 获取第一个工作表
-
-    // 处理 Excel 数据
-    $celldata = [];
-    $calcChain = [];
-    foreach ($sheetData->getRowIterator() as $row) {
-        foreach ($row->getCellIterator() as $cell) {
-            $coordinate = $cell->getCoordinate();
-            $value = $cell->getValue();
-            // 根据您的逻辑进行数据处理
-
-            // 示例:将坐标和值加入到celldata数组中
-            $celldata[] = [
-                'r' => Coordinate::coordinateFromString($coordinate)[0],
-                'c' => Coordinate::coordinateFromString($coordinate)[1],
-                'v' => $value
+    /**
+     * 产品附件新增
+     */
+    public function gdAnnexAdd(){
+        if(!$this->request->isPost()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        $arr = [
+            'sys_id',
+            '附件备注',
+            '附件内容',
+            '附件类型',
+            '关联编号'
             ];
+        $data = [];
+        foreach ($arr as $key => $value){
+            if (!isset($req[$value])){
+                $this->error('参数错误',$value,$key+1);
+            }
+            $data[$value] = $req[$value];
         }
+        $data['sys_rq'] = date('Y-m-d H:i:s');
+
+        //查询UniqId
+        $UniqId = db('工单_相关附件')->max('UniqId');
+        $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
+            $bool = db()->query($sql);
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
     }
-    // 构建templateData
-    $templateData = [
-        'name' => $spreadsheet->getSheetNames()[0],
-        'index' => '1',
-        'order' => 0,
-        'status' => 1,
-        // 其他字段按照您的逻辑处理
-        'celldata' => $celldata,
-        'calcChain' => $calcChain
-    ];
-
-    return $templateData; // 返回处理后的数据
+    
+    /**
+     * 产品附件修改
+     * @ApiMethod (GET)
+     * @param string 'UniqId'
+     */
+    public function gdAnnexDel()
+    {
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
+            $this->error('参数错误','UniqId',100);
+        }
+
+        //开启事务
+        db()->startTrans();
+        try{
+            $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
+            // 提交事务
+            db()->commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            db()->rollback();
+            $this->error($e->getMessage());
+        }
+
+        if($bool===false) $this->error('失败');
+
+        $this->success('成功');
+
     }
+
 }