|
@@ -865,14 +865,32 @@ class WorkOrder extends Api
|
|
|
} else {
|
|
} else {
|
|
|
$param['订单编号'] = $param['订单编号'];
|
|
$param['订单编号'] = $param['订单编号'];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
|
|
|
|
|
- $res = \db()->query($sql);
|
|
|
|
|
- if ($res !== false){
|
|
|
|
|
- $this->success('成功');
|
|
|
|
|
- }else{
|
|
|
|
|
- $this->error('失败');
|
|
|
|
|
|
|
+ $massage = $param['面料'].',粘衬:'.$param['粘衬'];
|
|
|
|
|
+ $mianliao = $this->Gpt($massage);
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ foreach ($mianliao as $key => $value){
|
|
|
|
|
+ $data[$key] = [
|
|
|
|
|
+ 'BOM_工单编号' => $param['订单编号'],
|
|
|
|
|
+ 'BOM_物料名称' => $value
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+ //插入工单基本资料
|
|
|
|
|
+ $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
|
|
|
|
|
+ $res = \db()->query($sql);
|
|
|
|
|
+ //插入订单物料信息
|
|
|
|
|
+ $BomSql = \db('工单_bom资料')->fetchSql(true)->insertAll($data);
|
|
|
|
|
+ $BomRes = \db()->query($BomSql);
|
|
|
|
|
+
|
|
|
|
|
+ //提交
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+ }catch (\Exception $e){
|
|
|
|
|
+ //回滚
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('成功');
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1947,10 +1965,14 @@ class WorkOrder extends Api
|
|
|
if (empty($param) || !isset($param['order'])){
|
|
if (empty($param) || !isset($param['order'])){
|
|
|
$this->error('参数错误');
|
|
$this->error('参数错误');
|
|
|
}
|
|
}
|
|
|
- $where = ['BOM_工单编号'=>$param['order']];
|
|
|
|
|
|
|
+ $where = ['a.BOM_工单编号'=>$param['order']];
|
|
|
$list = \db('工单_bom资料')
|
|
$list = \db('工单_bom资料')
|
|
|
- ->field('BOM_物料名称 as 物料名称,BOM_投料单位 as 投料单位,BOM_计划用量 as 计划用料,BOM_标准用量 as 定额用料,
|
|
|
|
|
- BOM_实际用量 as 裁床实际用料,BOM_领用数量 as 裁床领用面料,BOM_退还数量 as 裁床退回仓库面料,BOM_desc as 备注,UNIQID')
|
|
|
|
|
|
|
+ ->alias('a')
|
|
|
|
|
+ ->join('工单_基本资料 b','b.订单编号 = a.BOM_工单编号')
|
|
|
|
|
+ ->field('a.BOM_工单编号 as 订单编号,b.生产款号 as 生产款号,b.客户编号 as 客户编号,b.款式 as 款式,
|
|
|
|
|
+ a.BOM_物料名称 as 物料名称,a.BOM_投料单位 as 投料单位,a.BOM_计划用量 as 计划用料,a.BOM_标准用量 as 定额用料,
|
|
|
|
|
+ a.BOM_实际用量 as 裁床实际用料,a.BOM_领用数量 as 裁床领用面料,a.BOM_退还数量 as 裁床退回仓库面料,
|
|
|
|
|
+ a.BOM_desc as 备注,a.UNIQID')
|
|
|
->where($where)
|
|
->where($where)
|
|
|
->select();
|
|
->select();
|
|
|
if (!empty($list)){
|
|
if (!empty($list)){
|
|
@@ -2012,21 +2034,130 @@ class WorkOrder extends Api
|
|
|
if (empty($param) || !isset($param['order'])){
|
|
if (empty($param) || !isset($param['order'])){
|
|
|
$this->error('参数错误');
|
|
$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();
|
|
|
|
|
|
|
+ if (isset($param['searchh']) || !empty($param['search'])){
|
|
|
|
|
+ $list['入库记录'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('order_id|款号',$param['order'])
|
|
|
|
|
+ ->where('name','入库')
|
|
|
|
|
+ ->field('order_id as 订单编号,款号,number as 数量,rq as 出库时间,sys_id as 上报机台')
|
|
|
|
|
+ ->order('出库时间 desc')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //出库记录查询
|
|
|
|
|
+ $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);
|
|
$this->success('成功',$list);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //GPT
|
|
|
|
|
+ public function Gpt($massage)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 设置 API 密钥
|
|
|
|
|
+ $apiKey = 'sk-e0JuPjMntkbgi1BoMjrqyyzMKzAxILkQzyGMSy3xiMupuoWY'; // 替换为您的 API 密钥
|
|
|
|
|
+
|
|
|
|
|
+ // 要发送给 GPT 的消息
|
|
|
|
|
+ $messages = [
|
|
|
|
|
+ [
|
|
|
|
|
+ 'role' => 'user',
|
|
|
|
|
+ 'content' => '你好,帮我按照:面料1、面料2、面料3……来整理归纳下面的面料信息,我只需要面料信息,不需要其他:'.$massage
|
|
|
|
|
+ ]
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ // 创建请求数据
|
|
|
|
|
+ $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));
|
|
|
|
|
+ curl_setopt($ch, CURLOPT_CAINFO, ROOT_PATH . '/public/uploads/cacert.pem');
|
|
|
|
|
+
|
|
|
|
|
+ // 执行请求
|
|
|
|
|
+ $response = curl_exec($ch);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查错误
|
|
|
|
|
+ if (curl_errno($ch)) {
|
|
|
|
|
+ echo 'Error:' . curl_error($ch);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 关闭 cURL
|
|
|
|
|
+ curl_close($ch);
|
|
|
|
|
+
|
|
|
|
|
+ // 解析和输出响应
|
|
|
|
|
+ $responseData = json_decode($response, true);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取 GPT 的回复
|
|
|
|
|
+ if (isset($responseData['choices'][0]['message']['content'])) {
|
|
|
|
|
+ //获取返回内容
|
|
|
|
|
+ $gptReply = $responseData['choices'][0]['message']['content'];
|
|
|
|
|
+// halt($gptReply);
|
|
|
|
|
+ //返回面料信息
|
|
|
|
|
+ $gptArray = explode('面料',$gptReply);
|
|
|
|
|
+ array_shift($gptArray);
|
|
|
|
|
+ foreach ($gptArray as $key=>$value){
|
|
|
|
|
+ $gptArray[$key] = preg_replace('/\s+/', '', substr($value,4));
|
|
|
|
|
+ }
|
|
|
|
|
+ return $gptArray;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ echo "未能获取 GPT 的回复。";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 面料库存
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function fabricList()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ if (empty($param) || !isset($param['order'])){
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $where = ['a.BOM_工单编号'=>$param['order']];
|
|
|
|
|
+ $list = \db('工单_bom资料')
|
|
|
|
|
+ ->alias('a')
|
|
|
|
|
+ ->join('工单_基本资料 b','b.订单编号 = a.BOM_工单编号')
|
|
|
|
|
+ ->field('a.BOM_工单编号 as 订单编号,b.生产款号 as 生产款号,b.客户编号 as 客户编号,b.款式 as 款式,
|
|
|
|
|
+ a.BOM_物料名称 as 物料名称,a.BOM_投料单位 as 投料单位,a.BOM_库存总量 as 库存总量,a.BOM_面料结余 as 面料结余,
|
|
|
|
|
+ a.UNIQID')
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (!empty($list)){
|
|
|
|
|
+ $this->success('成功',$list);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|