|
@@ -10,6 +10,7 @@ use think\Config;
|
|
|
use think\Db;
|
|
use think\Db;
|
|
|
use think\Request;
|
|
use think\Request;
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
|
+use function fast\e;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -864,14 +865,33 @@ 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,
|
|
|
|
|
+ 'Sys_rq' => date('Y-m-d H:i:s',time()),
|
|
|
|
|
+ 'Sys_id' => $param['Sys_id']
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
|
|
+ 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('成功');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1487,7 +1507,7 @@ class WorkOrder extends Api
|
|
|
$data['xhdata'] = $arr;
|
|
$data['xhdata'] = $arr;
|
|
|
$this->success('成功',$data);
|
|
$this->success('成功',$data);
|
|
|
} elseif (strlen($afterDash) == 4) {
|
|
} elseif (strlen($afterDash) == 4) {
|
|
|
- //一条子订单编号一个条码,统计颜色
|
|
|
|
|
|
|
+ //一条子订单编号一个条码,统计颜色
|
|
|
// $processlist = \db('工单_印件资料')
|
|
// $processlist = \db('工单_印件资料')
|
|
|
// ->where('订单编号', $param['order'])
|
|
// ->where('订单编号', $param['order'])
|
|
|
// ->whereNull('Mod_rq') // 查询未删除数据
|
|
// ->whereNull('Mod_rq') // 查询未删除数据
|
|
@@ -1580,11 +1600,11 @@ class WorkOrder extends Api
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- $data['scslTotals'] = $scslTotals;
|
|
|
|
|
- $data['process'] = $table;//汇总数据集
|
|
|
|
|
- $data['order'] = $list;//表格数据
|
|
|
|
|
- $data['xhdata'] = $arr;//尺码表头
|
|
|
|
|
- $this->success('成功', $data);
|
|
|
|
|
|
|
+ $data['scslTotals'] = $scslTotals;
|
|
|
|
|
+ $data['process'] = $table;//汇总数据集
|
|
|
|
|
+ $data['order'] = $list;//表格数据
|
|
|
|
|
+ $data['xhdata'] = $arr;//尺码表头
|
|
|
|
|
+ $this->success('成功', $data);
|
|
|
// }
|
|
// }
|
|
|
} else {
|
|
} else {
|
|
|
echo "子订单编号 - 后不是2位也不是4位:$afterDash";
|
|
echo "子订单编号 - 后不是2位也不是4位:$afterDash";
|
|
@@ -1928,4 +1948,708 @@ class WorkOrder extends Api
|
|
|
->select();
|
|
->select();
|
|
|
$this->success('成功',$list);
|
|
$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 = ['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.BOM_实际用量 as 裁床实际用料,a.BOM_领用数量 as 裁床领用面料,a.BOM_退还数量 as 裁床退回仓库面料,
|
|
|
|
|
+ a.BOM_desc as 备注,a.UNIQID,a.BOM_库存总量 as 入库总量,a.BOM_门封 as 门封,a.BOM_面料结余 as 面料结余,a.Sys_ID as ID,a.Sys_rq as 日期')
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->whereNull('a.Mod_rq')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (!empty($list)) {
|
|
|
|
|
+ $this->success('成功', $list);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 调用其他方法处理逻辑(例如记录日志、执行其他操作等)
|
|
|
|
|
+ $this->GdGtpAiOrder($param['order']);
|
|
|
|
|
+
|
|
|
|
|
+ // 返回空数据的统一处理
|
|
|
|
|
+ return $this->success('没有找到相关数据', []);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Bom资料删除
|
|
|
|
|
+ * */
|
|
|
|
|
+ public function Bomdel()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取请求参数
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+
|
|
|
|
|
+ // 检查参数是否为空或者缺少UNIQID
|
|
|
|
|
+ if (empty($param) || !isset($param['UNIQID'])) {
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 判断UNIQID是否是逗号分隔的多个ID,如果是则拆分成数组,否则直接处理为单个ID
|
|
|
|
|
+ $uniqids = strpos($param['UNIQID'], ',') !== false ? explode(',', $param['UNIQID']) : [$param['UNIQID']];
|
|
|
|
|
+
|
|
|
|
|
+ $where = [];
|
|
|
|
|
+ $where['Mod_rq'] = date('Y-m-d H:i:s', time());
|
|
|
|
|
+
|
|
|
|
|
+ // 定义一个标志变量来追踪是否所有更新都成功
|
|
|
|
|
+ $allUpdated = true;
|
|
|
|
|
+ $failedUniqids = [];
|
|
|
|
|
+ // 遍历所有UNIQID并更新数据库
|
|
|
|
|
+ foreach ($uniqids as $uniqid) {
|
|
|
|
|
+ // 更新指定UNIQID的记录
|
|
|
|
|
+ $result = \db('工单_bom资料')
|
|
|
|
|
+ ->where('UNIQID', $uniqid)
|
|
|
|
|
+ ->update($where);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查更新结果
|
|
|
|
|
+ if (!$result) {
|
|
|
|
|
+ // 如果某个UNIQID更新失败,记录失败的ID
|
|
|
|
|
+ $allUpdated = false;
|
|
|
|
|
+ $failedUniqids[] = $uniqid;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果所有更新都成功,返回成功信息
|
|
|
|
|
+ if ($allUpdated) {
|
|
|
|
|
+ $list = \db('工单_bom资料')
|
|
|
|
|
+ ->whereIn('UNIQID', $uniqids) // 查询所有传入的UNIQID
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (!empty($list)) {
|
|
|
|
|
+ $this->success('删除成功');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->GdGtpAiOrder($param['order']);
|
|
|
|
|
+ return $this->success('没有找到相关数据', []);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果有更新失败的记录,返回失败的UNIQID
|
|
|
|
|
+ $this->error('部分更新失败,无法更新以下UNIQID: ' . implode(', ', $failedUniqids));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 前端选择订单时如果BOM资料数据为空则单独调用,重新生成最新
|
|
|
|
|
+ */
|
|
|
|
|
+ public function GdGtpAiOrder($order){
|
|
|
|
|
+ // 判断是否有指定的订单号
|
|
|
|
|
+ if (!empty($order)) {
|
|
|
|
|
+ // 查询单个订单的最大编号
|
|
|
|
|
+ $maxOrder = \db('工单_基本资料')
|
|
|
|
|
+ ->where('订单编号', 'like', "{$order}%")
|
|
|
|
|
+ ->order('订单编号', 'desc')
|
|
|
|
|
+ ->limit(1)
|
|
|
|
|
+ ->value('订单编号');
|
|
|
|
|
+
|
|
|
|
|
+ // 查询该订单的基本资料
|
|
|
|
|
+ $list = \db('工单_基本资料')
|
|
|
|
|
+ ->where('订单编号', 'like', "{$order}%")
|
|
|
|
|
+ ->order('订单编号', 'desc')
|
|
|
|
|
+ ->limit(1)
|
|
|
|
|
+ ->find();
|
|
|
|
|
+
|
|
|
|
|
+ // 如果面料数据为空,提示错误
|
|
|
|
|
+ if (empty($list['面料'])) {
|
|
|
|
|
+ $this->error('面料数据为空无法定义BOM');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理订单编号
|
|
|
|
|
+ $numericPart = substr($maxOrder, 2);
|
|
|
|
|
+ $newNumericPart = str_pad((int)$numericPart + 1, strlen($numericPart), '0', STR_PAD_LEFT);
|
|
|
|
|
+ $param['订单编号'] = $order . $newNumericPart;
|
|
|
|
|
+
|
|
|
|
|
+ // 处理物料信息
|
|
|
|
|
+ $massage = empty($list['粘衬']) || $list['粘衬'] == '无' ? $list['面料'] : $list['面料'] . ',粘衬:' . $list['粘衬'];
|
|
|
|
|
+ $mianliao = $this->Gpt($massage);
|
|
|
|
|
+
|
|
|
|
|
+ // 插入物料数据
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ foreach ($mianliao as $key => $value) {
|
|
|
|
|
+ if (!empty($value) && $value !== '粘衬') { // 排除空值和粘衬
|
|
|
|
|
+ $data[] = [
|
|
|
|
|
+ 'BOM_工单编号' => $list['订单编号'],
|
|
|
|
|
+ 'BOM_物料名称' => $value,
|
|
|
|
|
+ 'Sys_rq' => date('Y-m-d H:i:s'),
|
|
|
|
|
+ 'Sys_ID' => '超级管理员'
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 批量插入BOM资料
|
|
|
|
|
+ if (!empty($data)) {
|
|
|
|
|
+ \db('工单_bom资料')->insertAll($data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->success('成功',$order);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果没有指定订单号,批量查询订单号并处理
|
|
|
|
|
+ $has_bom = \db('工单_bom资料')->alias('a')->field('a.BOM_工单编号')->group('a.BOM_工单编号')->select();
|
|
|
|
|
+ $all_orders = \db('工单_基本资料')->alias('a')->field('a.订单编号')->where('a.面料', '<>', '')->group('a.订单编号')->select();
|
|
|
|
|
+
|
|
|
|
|
+ // 提取有BOM资料的订单号
|
|
|
|
|
+ $has_bom_orders = array_column($has_bom, 'BOM_工单编号');
|
|
|
|
|
+
|
|
|
|
|
+ // 筛选出没有对应BOM资料的订单号
|
|
|
|
|
+ $no_bom_orders = array_filter($all_orders, function ($order) use ($has_bom_orders) {
|
|
|
|
|
+ return !in_array($order['订单编号'], $has_bom_orders);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历没有BOM资料的订单
|
|
|
|
|
+ foreach ($no_bom_orders as $orderData) {
|
|
|
|
|
+ // 获取该订单号的最大订单编号
|
|
|
|
|
+ $maxOrder = \db('工单_基本资料')
|
|
|
|
|
+ ->where('订单编号', 'like', "{$orderData['订单编号']}%")
|
|
|
|
|
+ ->order('订单编号', 'desc')
|
|
|
|
|
+ ->limit(1)
|
|
|
|
|
+ ->value('订单编号');
|
|
|
|
|
+
|
|
|
|
|
+ // 获取该订单号的具体数据
|
|
|
|
|
+ $list = \db('工单_基本资料')
|
|
|
|
|
+ ->where('订单编号', 'like', "{$orderData['订单编号']}%")
|
|
|
|
|
+ ->order('订单编号', 'desc')
|
|
|
|
|
+ ->limit(1)
|
|
|
|
|
+ ->find();
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($list['面料'])) {
|
|
|
|
|
+ $this->error("订单 {$orderData['订单编号']} 面料数据为空,无法定义BOM");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理订单编号
|
|
|
|
|
+ $numericPart = substr($maxOrder, 2);
|
|
|
|
|
+ $newNumericPart = str_pad((int)$numericPart + 1, strlen($numericPart), '0', STR_PAD_LEFT);
|
|
|
|
|
+ $param['订单编号'] = $order . $newNumericPart;
|
|
|
|
|
+
|
|
|
|
|
+ // 处理物料信息
|
|
|
|
|
+ $massage = empty($list['粘衬']) || $list['粘衬'] == '无' ? $list['面料'] : $list['面料'] . ',粘衬:' . $list['粘衬'];
|
|
|
|
|
+ $mianliao = $this->Gpt($massage);
|
|
|
|
|
+ // 插入物料数据
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ foreach ($mianliao as $key => $value) {
|
|
|
|
|
+ if (!empty($value) && $value !== '粘衬') { // 排除空值和粘衬
|
|
|
|
|
+ $data[] = [
|
|
|
|
|
+ 'BOM_工单编号' => $list['订单编号'],
|
|
|
|
|
+ 'BOM_物料名称' => $value,
|
|
|
|
|
+ 'Sys_rq' => date('Y-m-d H:i:s'),
|
|
|
|
|
+ 'Sys_ID' => '超级管理员'
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 批量插入BOM资料
|
|
|
|
|
+ if (!empty($data)) {
|
|
|
|
|
+ \db('工单_bom资料')->insertAll($data);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('成功');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 订单面料修改接口
|
|
|
|
|
+ * @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('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($param['searchh']) || !empty($param['search'])){
|
|
|
|
|
+ $list['入库记录'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('order_id|款号',$param['order'])
|
|
|
|
|
+ ->where('name','入库')
|
|
|
|
|
+ ->field('id,order_id as 订单编号,款号,sum(number) as 数量,rq as 入库时间,sys_id as 入库人员,recipient as 入仓人员,receipt_number as 单号')
|
|
|
|
|
+ ->group('receipt_number')
|
|
|
|
|
+ ->order('入库时间 desc')
|
|
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //出库记录查询
|
|
|
|
|
+ $list['出库记录'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('order_id|款号',$param['order'])
|
|
|
|
|
+ ->where('name','出库')
|
|
|
|
|
+ ->field('id,order_id as 订单编号,款号,sum(number) as 数量,rq as 出库时间,sys_id as 出库人员,receipt_number as 出库单据编号,recipient as 出库人员,receipt_number as 单号')
|
|
|
|
|
+ ->group('receipt_number')
|
|
|
|
|
+ ->order('出库时间 desc')
|
|
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ //退还记录查询
|
|
|
|
|
+ $list['退还记录'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('order_id|款号',$param['order'])
|
|
|
|
|
+ ->where('name','退还')
|
|
|
|
|
+ ->field('id,order_id as 订单编号,款号,sum(number) as 数量,rq as 退还时间,sys_id as 退还机台,recipient as 退还人员,receipt_number as 单号')
|
|
|
|
|
+ ->group('receipt_number')
|
|
|
|
|
+ ->order('退还时间 desc')
|
|
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->success('成功',$list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 入库、出库、退还详情数据
|
|
|
|
|
+ */
|
|
|
|
|
+ public function FabricDetaillist()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ if (empty($param) || !isset($param['order'])){
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($param['searchh']) || !empty($param['search'])){
|
|
|
|
|
+ $list['入库记录'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('receipt_number',$param['order'])
|
|
|
|
|
+ ->where('name','入库')
|
|
|
|
|
+ ->field('id,order_id as 订单编号,款号,number as 数量,rq as 入库时间,sys_id as 入库人员,recipient as 入仓人员,receipt_number as 单号,物料名称')
|
|
|
|
|
+ ->order('入库时间 desc')
|
|
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //出库记录查询
|
|
|
|
|
+ $list['出库记录'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('receipt_number',$param['order'])
|
|
|
|
|
+ ->where('name','出库')
|
|
|
|
|
+ ->field('id,order_id as 订单编号,款号,number as 数量,rq as 出库时间,sys_id as 出库人员,recipient as 出库人员,receipt_number as 单号,物料名称')
|
|
|
|
|
+ ->order('出库时间 desc')
|
|
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ //退还记录查询
|
|
|
|
|
+ $list['退还记录'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('receipt_number',$param['order'])
|
|
|
|
|
+ ->where('name','退还')
|
|
|
|
|
+ ->field('id,order_id as 订单编号,款号,number as 数量,rq as 退还时间,sys_id as 退还机台,recipient as 退还人员,receipt_number as 单号,物料名称')
|
|
|
|
|
+ ->order('退还时间 desc')
|
|
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('成功',$list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 入库、出库、退还删除
|
|
|
|
|
+ */
|
|
|
|
|
+ public function FabricDetaildel()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isPost() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $param = Request::instance()->post();
|
|
|
|
|
+ if (empty($param)){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ // 判断UNIQID是否是逗号分隔的多个ID,如果是则拆分成数组,否则直接处理为单个ID
|
|
|
|
|
+ $ids = strpos($param['id'], ',') !== false ? explode(',', $param['id']) : [$param['id']];
|
|
|
|
|
+
|
|
|
|
|
+ $where = [];
|
|
|
|
|
+ $where['Mod_id'] = $param['Mod_id'];
|
|
|
|
|
+ $where['Mod_rq'] = date('Y-m-d H:i:s', time());
|
|
|
|
|
+
|
|
|
|
|
+ // 定义一个标志变量来追踪是否所有更新都成功
|
|
|
|
|
+ $allUpdated = true;
|
|
|
|
|
+ $failedUniqids = [];
|
|
|
|
|
+ // 遍历所有UNIQID并更新数据库
|
|
|
|
|
+ foreach ($ids as $id) {
|
|
|
|
|
+ // 更新指定UNIQID的记录
|
|
|
|
|
+ $result = \db('设备_报工日志')
|
|
|
|
|
+ ->where('id', $id)
|
|
|
|
|
+ ->update($where);
|
|
|
|
|
+
|
|
|
|
|
+ // 检查更新结果
|
|
|
|
|
+ if (!$result) {
|
|
|
|
|
+ // 如果某个UNIQID更新失败,记录失败的ID
|
|
|
|
|
+ $allUpdated = false;
|
|
|
|
|
+ $failedUniqids[] = $id;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果所有更新都成功,返回成功信息
|
|
|
|
|
+ if ($allUpdated) {
|
|
|
|
|
+ $list = \db('设备_报工日志')
|
|
|
|
|
+ ->whereIn('id', $id) // 查询所有传入的UNIQID
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (!empty($list)) {
|
|
|
|
|
+ $this->success('删除成功');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->GdGtpAiOrder($param['order']);
|
|
|
|
|
+ return $this->success('没有找到相关数据', []);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果有更新失败的记录,返回失败的UNIQID
|
|
|
|
|
+ $this->error('部分更新失败,无法更新以下UNIQID: ' . implode(', ', $failedUniqids));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //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();
|
|
|
|
|
+ $where = [];
|
|
|
|
|
+ if (isset($param['order'])){
|
|
|
|
|
+ $where = ['a.BOM_工单编号'=>$param['order']];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isset($param['mouth'])){
|
|
|
|
|
+ $where = ['a.Sys_rq'=>['like',$param['mouth'].'%']];
|
|
|
|
|
+ }
|
|
|
|
|
+ $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')
|
|
|
|
|
+ ->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,a.BOM_库存总量 as 入库总量,a.BOM_门封 as 门封,a.BOM_面料结余 as 面料结余,a.Sys_ID as ID,a.Sys_rq as 日期')
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (!empty($list)){
|
|
|
|
|
+ $this->success('成功',$list);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->success('没有找到相关数据', []);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单条面料详情
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function oneFabricDetail()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ if (empty($param)){
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ //面料入库记录
|
|
|
|
|
+ $list['入库'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('order_id',$param['order'])
|
|
|
|
|
+ ->where('物料名称',$param['fabricName'])
|
|
|
|
|
+ ->where('name','入库')
|
|
|
|
|
+ ->field('order_id as 订单编号,款号,物料名称,number as 数量,rq as 日期,sys_id as 操作机台,recipient as 入仓人员')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ //面料出库记录
|
|
|
|
|
+ $list['出库'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('order_id',$param['order'])
|
|
|
|
|
+ ->where('物料名称',$param['fabricName'])
|
|
|
|
|
+ ->where('name','出库')
|
|
|
|
|
+ ->field('order_id as 订单编号,款号,物料名称,number as 数量,rq as 日期,sys_id as 操作机台,receipt_number as 出库单据编号,recipient as 领用人员')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ //面料退还记录
|
|
|
|
|
+ $list['退还'] = \db('设备_报工日志')
|
|
|
|
|
+ ->where('order_id',$param['order'])
|
|
|
|
|
+ ->where('物料名称',$param['fabricName'])
|
|
|
|
|
+ ->where('name','退还')
|
|
|
|
|
+ ->field('order_id as 订单编号,款号,物料名称,number as 数量,rq as 日期,sys_id as 操作机台,recipient as 退还人员')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ $this->success('成功',$list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单据号查询数据
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function ReceiptDetail()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ if (empty($param)){
|
|
|
|
|
+ $this->error('单据编号参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $list = \db('设备_报工日志')
|
|
|
|
|
+// ->where('receipt_number','like','%',$param['receipt'].'%')
|
|
|
|
|
+ ->where('receipt_number',$param['receipt'])
|
|
|
|
|
+ ->field('order_id as 订单编号,款号,物料名称,number as 数量,rq as 日期,sys_id as 操作机台,receipt_number as 出库单据编号,recipient as 领用人员')
|
|
|
|
|
+ ->whereNull('Mod_rq')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ 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 ReceiptList()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ if (empty($param)){
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $list = \db('设备_报工日志')
|
|
|
|
|
+ ->where('rq','like','%'.$param['mouth'].'%')
|
|
|
|
|
+ ->field('receipt_number as 出库单,order_id as 订单编号,款号,物料名称,rq as 日期,sys_id as 操作机台,recipient as 领料人员')
|
|
|
|
|
+ ->group('出库单')
|
|
|
|
|
+ ->order('rq desc')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (empty($list)){
|
|
|
|
|
+ $this->success('未找到数据');
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $this->success('成功',$list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 出库单左侧菜单
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getReceiptTab()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $list = \db('设备_报工日志')
|
|
|
|
|
+ ->field([
|
|
|
|
|
+ "DATE_FORMAT(rq, '%Y-%m') AS month",
|
|
|
|
|
+ ])
|
|
|
|
|
+ ->group('month')
|
|
|
|
|
+ ->order('month DESC')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (empty($list)){
|
|
|
|
|
+ $this->error('未找到数据');
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $this->success('成功',$list);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取入库单号、出库单号
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function gitReceiptNumber()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $param = $this->request->param();
|
|
|
|
|
+ if (empty($param)){
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $lastNumber = \db('设备_报工日志')
|
|
|
|
|
+ ->where('receipt_number','like',$param['number'].'%')
|
|
|
|
|
+ ->order('receipt_number desc')
|
|
|
|
|
+ ->limit(1)
|
|
|
|
|
+ ->column('receipt_number as 单号');
|
|
|
|
|
+ if (empty($lastNumber)){
|
|
|
|
|
+ $num = 1;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $num = (int)(substr($lastNumber[0],12,3))+1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($num < 10){
|
|
|
|
|
+ $num = '00'.$num;
|
|
|
|
|
+ }elseif ($num>=10 && $num<100){
|
|
|
|
|
+ $num = '0'.$num;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $num;
|
|
|
|
|
+ }
|
|
|
|
|
+ $number = $param['number'].date('Ymd',time()).'-'.$num;
|
|
|
|
|
+
|
|
|
|
|
+ $lastNumber = \db('设备_报工日志')
|
|
|
|
|
+ ->where('name','出库')
|
|
|
|
|
+ ->order('recipient desc')
|
|
|
|
|
+ ->group('recipient')
|
|
|
|
|
+ ->limit(1)
|
|
|
|
|
+ ->value('recipient as 人员');
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'number' => $number,
|
|
|
|
|
+ 'username' => $lastNumber
|
|
|
|
|
+ ];
|
|
|
|
|
+ $this->success('成功', $data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 面料汇总左侧菜单
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getFabricTab()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->request->isGet() === false){
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $list = \db('工单_bom资料')
|
|
|
|
|
+ ->field([
|
|
|
|
|
+ "DATE_FORMAT(Sys_rq, '%Y-%m') AS month",
|
|
|
|
|
+ ])
|
|
|
|
|
+ ->group('month')
|
|
|
|
|
+ ->order('month DESC')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ if (empty($list)){
|
|
|
|
|
+ $this->error('未找到数据');
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $this->success('成功',$list);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|