|
|
@@ -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 的回复。";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|