Ver Fonte

工单BOM管理

qiuenguang há 10 meses atrás
pai
commit
e9f28b110e

+ 153 - 0
application/api/controller/WorkOrder.php

@@ -10,6 +10,7 @@ use think\Config;
 use think\Db;
 use think\Request;
 use PhpOffice\PhpSpreadsheet\IOFactory;
+use function fast\e;
 
 
 /**
@@ -1928,4 +1929,156 @@ class WorkOrder extends Api
             ->select();
         $this->success('成功',$list);
     }
+
+
+    /**
+     * 订单BOM资料显示
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function OrderBomList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['order'])){
+            $this->error('参数错误');
+        }
+        $where = ['BOM_工单编号'=>$param['order']];
+        $list = \db('工单_bom资料')
+            ->field('BOM_物料名称 as 物料名称,BOM_投料单位 as 投料单位,BOM_计划用量 as 计划用料,BOM_标准用量 as 定额用料,
+            BOM_实际用量 as 裁床实际用料,BOM_领用数量 as 裁床领用面料,BOM_退还数量 as 裁床退回仓库面料,BOM_desc as 备注,UNIQID')
+            ->where($where)
+            ->select();
+        if (!empty($list)){
+            $this->success('成功',$list);
+        }
+    }
+
+    /**
+     * 订单面料修改接口
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function FabricEdit()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('请求错误');
+        }
+        foreach ($param as $key=>$value){
+            $data = $value;
+            unset($data['UNIQID']);
+            if ($value['UNIQID'] !== '' || !empty($value['UNIQID'])){
+                $sql = \db('工单_bom资料')
+                    ->where('UNIQID',$value['UNIQID'])
+                    ->fetchSql(true)
+                    ->update($data);
+                $res = \db()->query($sql);
+            }else{
+                $sql = \db('工单_bom资料')
+                    ->fetchSql(true)
+                    ->insert($value);
+                $res = \db()->query($sql);
+            }
+            if ($res === false){
+                $this->error('修改失败');
+            }
+        }
+        $this->success('修改成功');
+    }
+
+    /**
+     * 订单BOM出库、退还详情显示
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function FabricDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param) || !isset($param['order'])){
+            $this->error('参数错误');
+        }
+        //出库记录查询
+        $list['出库记录'] = \db('设备_报工日志')
+            ->where('order_id|款号',$param['order'])
+            ->where('name','出库')
+            ->field('order_id as 订单编号,款号,number as 数量,rq as 出库时间,sys_id as 上报机台')
+            ->order('出库时间 desc')
+            ->select();
+        //退还记录查询
+        $list['退还记录'] = \db('设备_报工日志')
+            ->where('order_id|款号',$param['order'])
+            ->where('name','退还')
+            ->field('order_id as 订单编号,款号,number as 数量,rq as 出库时间,sys_id as 上报机台')
+            ->order('出库时间 desc')
+            ->select();
+        $this->success('成功',$list);
+    }
+
+    //GPT
+    public function GPT()
+    {
+        // 设置 API 密钥
+        $apiKey = 'sk-e0JuPjMntkbgi1BoMjrqyyzMKzAxILkQzyGMSy3xiMupuoWY'; // 替换为您的 API 密钥
+
+// 要发送给 GPT 的消息
+        $messages = [
+            [
+                'role' => 'user',
+                'content' => '你好,GPT!你能帮我写一段 PHP 代码吗?'
+            ]
+        ];
+
+// 创建请求数据
+        $data = [
+            'model' => 'gpt-3.5-turbo', // 使用的模型
+            'messages' => $messages,
+            'max_tokens' => 100, // 设置最大 token 数
+        ];
+
+// 初始化 cURL
+        $ch = curl_init('https://niubi.zeabur.app/v1/chat/completions');
+
+// 设置 cURL 选项
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, [
+            'Content-Type: application/json',
+            'Authorization: Bearer ' . $apiKey,
+        ]);
+        curl_setopt($ch, CURLOPT_POST, true);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+
+// 执行请求
+        $response = curl_exec($ch);
+
+// 检查错误
+        if (curl_errno($ch)) {
+            echo 'Error:' . curl_error($ch);
+        }
+
+// 关闭 cURL
+        curl_close($ch);
+
+// 解析和输出响应
+        $responseData = json_decode($response, true);
+        if (isset($responseData['choices'][0]['message']['content'])) {
+            echo "GPT 回复: " . $responseData['choices'][0]['message']['content'];
+        } else {
+            echo "未能获取 GPT 的回复。";
+        }
+    }
 }

+ 80 - 0
application/api/controller/WorkOrderSpotCheck.php

@@ -2348,5 +2348,85 @@ class WorkOrderSpotCheck extends Api{
         }
     }
 
+    /**
+     * 出库报工
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function outReport()
+    {
+        if ($this->request->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        foreach ($param as $key=>$value){
+            $lastNumber = \db('工单_bom资料')
+                ->where('BOM_工单编号',$value['order_id'])
+                ->where('BOM_物料名称',$value['物料名称'])
+                ->field('BOM_实际用量,Bom_领用数量,BOM_退还数量')
+                ->find();
+            if ($value['name'] === '出库'){
+                $lastNumber['BOM_实际用量'] += $value['number'];
+                $lastNumber['Bom_领用数量'] += $value['number'];
+            }else{
+                $lastNumber['BOM_实际用量'] -= $value['number'];
+                $lastNumber['BOM_退还数量'] += $value['number'];
+            }
+            Db::startTrans();
+            try {
+                //更新工单BOM表数据
+                $BomSql = \db('工单_bom资料')
+                    ->where('BOM_工单编号',$value['order_id'])
+                    ->where('BOM_物料名称',$value['物料名称'])
+                    ->fetchSql(true)
+                    ->update($lastNumber);
+                $res = \db()->query($BomSql);
+                //添加出库、退还历史记录
+                $reportSql = \db('设备_报工日志')
+                    ->fetchSql(true)
+                    ->insert($value);
+                $reportRes = \db()->query($reportSql);
+
+                //提交事务
+                Db::commit();
+            }catch (\Exception $e){
+                //回滚事务
+                Db::rollback();
+            }
+        }
+        $this->success('成功');
+    }
 
+    /**
+     * 订单信息模糊查询
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function orderSearch()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('工单_基本资料')
+            ->where('订单编号|生产款号','like','%'.$param['search'].'%')
+            ->where('Mod_rq',null)
+            ->field('订单编号,生产款号,客户编号,款式,接单日期,Sys_id as 创建人员,Sys_rq as 创建时间')
+            ->select();
+        if (empty($list)){
+            $this->success('未找到相关订单信息');
+        }else{
+            $this->success('成功',$list);
+        }
+    }
 }