liuhairui 9 сар өмнө
parent
commit
de8b9d04a2

+ 29 - 29
application/api/controller/WorkOrder.php

@@ -2011,39 +2011,39 @@ class WorkOrder extends Api
         $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;
-                }
+        // 定义一个标志变量来追踪是否所有更新都成功
+        $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('没有找到相关数据', []);
-                }
+        // 如果所有更新都成功,返回成功信息
+        if ($allUpdated) {
+            $list = \db('工单_bom资料')
+                ->whereIn('UNIQID', $uniqids)  // 查询所有传入的UNIQID
+                ->select();
+            if (!empty($list)) {
+                $this->success('删除成功');
             } else {
-                // 如果有更新失败的记录,返回失败的UNIQID
-                $this->error('部分更新失败,无法更新以下UNIQID: ' . implode(', ', $failedUniqids));
+                $this->GdGtpAiOrder($param['order']);
+                return $this->success('没有找到相关数据', []);
             }
+        } else {
+            // 如果有更新失败的记录,返回失败的UNIQID
+            $this->error('部分更新失败,无法更新以下UNIQID: ' . implode(', ', $failedUniqids));
+        }
 
     }
 

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

@@ -2346,5 +2346,90 @@ 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){
+            if ($value['number'] != '' || $value['number'] == 0 ){
+                $lastNumber = \db('工单_bom资料')
+                    ->where('BOM_工单编号',$value['order_id'])
+                    ->where('BOM_物料名称',$value['物料名称'])
+                    ->field('BOM_库存总量,BOM_面料结余,Bom_领用数量,BOM_退还数量')
+                    ->find();
+                if ($value['name'] === '出库'){
+                    $lastNumber['BOM_面料结余'] -= $value['number'];
+                    $lastNumber['Bom_领用数量'] += $value['number'];
+                }elseif ($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);
+        }
+    }
 }