瀏覽代碼

Merge branch 'master' of https://git.7in6.com/liuhairui/mes-dc-server-api

zck 1 月之前
父節點
當前提交
b5d0a89854
共有 2 個文件被更改,包括 75 次插入95 次删除
  1. 1 12
      application/api/controller/WorkOrderProcess.php
  2. 74 83
      application/api/controller/WorkOrderSpotCheck.php

+ 1 - 12
application/api/controller/WorkOrderProcess.php

@@ -452,18 +452,7 @@ class WorkOrderProcess extends Api
         if (empty($params['big_process'])) {
             $this->error('大工艺不能为空');
         }
-        if (empty($params['standard_hour'])) {
-            $this->error('秒不能为空');
-        }
-        if (empty($params['standard_minutes'])) {
-            $this->error('分钟不能为空');
-        }
-        if (empty($params['standard_score'])) {
-            $this->error('定额分不能为空');
-        }
-        if (empty($params['money'])) {
-            $this->error('金额不能为空');
-        }
+  
         if (!isset($params['coefficient']) || $params['coefficient'] === '') {
             $params['coefficient'] = 'C';
         }

+ 74 - 83
application/api/controller/WorkOrderSpotCheck.php

@@ -1016,7 +1016,7 @@ class WorkOrderSpotCheck extends Api{
                         ->find();
 
 //                    if (empty($res)) {
-                        $ci_num = $paramArray[4];
+                    $ci_num = $paramArray[4];
 //                    } else {
 //                        $ci_num = $res["ci_num"];
 //                    }
@@ -1189,8 +1189,6 @@ class WorkOrderSpotCheck extends Api{
             case '总检':
                 //判断是否为子订单编号【$order:DC2503291-0703 子订单编号】
                 if (strpos($order, '-') !== false) {
-                    //子订单编号
-
                     // 定义查询字段
                     $field = "
                             y.订单编号, y.子订单编号, y.款号, j.款式, y.颜色, 
@@ -1314,7 +1312,7 @@ class WorkOrderSpotCheck extends Api{
 
                     if ($allScslEmpty) {
                         // 当前订单未裁剪 请裁剪后报工
-                        $this->success($order."\n" .'未裁剪 请裁剪后,在报工', [
+                        $this->success('查询失败', [
                             'code' => 1,
                             'serial' => '',
                             'serial_num' => '',
@@ -1924,7 +1922,7 @@ class WorkOrderSpotCheck extends Api{
 
                     if ($allScslEmpty) {
                         // 当前子订单未裁剪 请裁剪后报工
-                        $this->success($order."\n" .'未裁剪 请裁剪后,在报工', [
+                        $this->success('当前子订单未裁剪 请裁剪后报工', [
                             'code' => 1,
                             'serial' => '',
                             'serial_num' => '',
@@ -2871,7 +2869,7 @@ class WorkOrderSpotCheck extends Api{
         if (empty($param)){
             $this->error('参数错误');
         }
-         $list = \db('工单_基本资料')->alias('a')
+        $list = \db('工单_基本资料')->alias('a')
             ->field('
             a.订单编号,
             a.生产款号,
@@ -2987,119 +2985,112 @@ class WorkOrderSpotCheck extends Api{
             $this->error('参数错误');
         }
 
-        // 开启事务
-        Db::startTrans();
+        \db()->startTrans();
 
         try {
-            //获取最大批次号
-            $lastBatch = Db::name('物料_库存')
+            $sysRq = date('Y-m-d H:i:s');
+
+            // 获取最大批次号(兼容 GDGL 前缀)
+            $lastBatch = \db('物料_库存')
                 ->where('批次号', 'like', 'GDGL%')
                 ->orderRaw('CAST(SUBSTRING(批次号, 5) AS UNSIGNED) DESC')
                 ->value('批次号');
+
             $currentNumber = $lastBatch ? intval(substr($lastBatch, 4)) : 0;
 
-            $insertInventory = []; // 新入库
-            $updateInventory = []; // 更新库存
-            $insertLogs = [];      // 出入库日志
+            $insertInventory = [];
+            $insertLogs = [];
 
             foreach ($param as $item) {
-                if (empty($item['物料编码']) || empty($item['关联编号']) || !isset($item['number'])) {
+                if (empty($item['物料编码']) || empty($item['关联编号']) || !isset($item['number']) || !is_numeric($item['number']) || $item['number'] <= 0) {
                     continue;
                 }
 
-                // 唯一KEY:物料编码 + 关联号(判断是否已存在)
-                $uniqueKey = $item['物料编码'] . '_' . $item['关联编号'];
+                $qty = intval($item['number']);
 
-                // 检查是否已存在
-                static $exists = [];
-                if (!isset($exists[$uniqueKey])) {
-                    $exists[$uniqueKey] = Db::name('物料_库存')
-                        ->where('物料编号', $item['物料编码'])
-                        ->where('关联号', $item['关联编号'])
-                        ->whereNull('Mod_rq')
-                        ->value('批次号');
-                }
-                $existingBatch = $exists[$uniqueKey];
+                // 唯一KEY:物料编码 + 物料名称 + 关联号 + 未删除
+                $existingBatch = \db('物料_库存')
+                    ->where('物料编号', $item['物料编码'])
+                    ->where('物料名称', $item['物料名称'])
+                    ->where('关联号', $item['关联编号'])
+                    ->whereNull('Mod_rq')
+                    ->value('批次号');
 
                 if ($existingBatch) {
-                    //更新
-                    $updateInventory[] = [
-                        '批次号' => $existingBatch,
-                        'data' => [
-                            '入仓总量'    => Db::raw('入仓总量 + ' . intval($item['number'])),
-                            '库存数量'    => Db::raw('库存数量 + ' . intval($item['number'])),
-                            '实际门幅'    => $item['实际门幅'],
-                            'departname'  => $item['departname'],
-                            'remark'      => $item['remark'] ?? '',
-                            'sys_rq'      => date('Y-m-d H:i:s'),
-                        ]
+                    $updateData = [
+                        '入仓总量'   => Db::raw('入仓总量 + ' . $qty),
+                        '库存数量'   => Db::raw('库存数量 + ' . $qty),
+                        '实际门幅'   => $item['实际门幅'],
+                        'departname' => $item['departname'],
+                        'remark'     => $item['remark'] ?? '',
+                        'sys_rq'     => $sysRq,
                     ];
+                    $sql = \db('物料_库存')
+                        ->where('批次号', $existingBatch)
+                        ->fetchSql(true)
+                        ->update($updateData);
+                    \db()->query($sql);
+
                     $BatchNumber = $existingBatch;
                 } else {
-                    //新增
                     $currentNumber++;
                     $BatchNumber = 'GDGL' . $currentNumber;
 
                     $insertInventory[] = [
-                        '批次号'      => $BatchNumber,
-                        '关联号'      => $item['关联编号'],
-                        '物料编号'    => $item['物料编码'],
-                        '物料名称'    => $item['物料名称'],
-                        '入仓总量'    => $item['number'],
-                        '库存数量'    => $item['number'],
-                        '单位'        => $item['单位'],
-                        '实际门幅'    => $item['实际门幅'],
-                        '状态'        => 1,
-                        'departname'  => $item['departname'],
-                        'remark'      => $item['remark'] ?? '',
-                        'sys_id'      => $item['sys_id'],
-                        'sys_rq'      => date('Y-m-d H:i:s'),
+                        '批次号'     => $BatchNumber,
+                        '关联号'     => $item['关联编号'],
+                        '物料编号'   => $item['物料编码'],
+                        '物料名称'   => $item['物料名称'],
+                        '入仓总量'   => $qty,
+                        '库存数量'   => $qty,
+                        '单位'       => $item['单位'],
+                        '实际门幅'   => $item['实际门幅'],
+                        '状态'       => 1,
+                        'departname' => $item['departname'],
+                        'remark'     => $item['remark'] ?? '',
+                        'sys_id'     => $item['sys_id'],
+                        'sys_rq'     => $sysRq,
                     ];
                 }
 
-                //日志
                 $insertLogs[] = [
-                    '批次号' => $BatchNumber,
-                    'order_id' => $item['order_id'],
-                    '款号' => $item['款号'],
-                    '物料编码' => $item['物料编码'],
-                    '物料名称' => $item['物料名称'],
-                    '库存数量' => $item['number'],
-                    'number' => $item['number'],
-                    'rq' => $item['rq'],
-                    'name' => $item['name'],
-                    'sys_id' => $item['sys_id'],
-                    'receipt_number' => $item['receipt_number'],
-                    'departname' => $item['departname'],
-                    'remark' => $item['remark'] ?? '',
-                    '客户编号' => $item['客户编号'],
-                    '款式' => $item['款式'],
-                    'sys_rq' => date('Y-m-d H:i:s'),
+                    '批次号'           => $BatchNumber,
+                    'order_id'         => $item['order_id'],
+                    '款号'             => $item['款号'],
+                    '物料编码'         => $item['物料编码'],
+                    '物料名称'         => $item['物料名称'],
+                    '库存数量'         => $qty,
+                    'number'           => $qty,
+                    'rq'               => $item['rq'],
+                    'name'             => $item['name'],
+                    'sys_id'           => $item['sys_id'],
+                    'receipt_number'   => $item['receipt_number'],
+                    'departname'       => $item['departname'],
+                    'remark'           => $item['remark'] ?? '',
+                    '客户编号'         => $item['客户编号'],
+                    '款式'             => $item['款式'],
+                    'sys_rq'           => $sysRq,
                 ];
             }
 
-            // 批量新增库存
-            if ($insertInventory) {
-                Db::name('物料_库存')->insertAll($insertInventory);
+            if (empty($insertLogs)) {
+                \db()->rollback();
+                $this->error('无有效入库数据');
             }
 
-            // 批量更新库存
-            foreach ($updateInventory as $u) {
-                Db::name('物料_库存')
-                    ->where('批次号', $u['批次号'])
-                    ->update($u['data']);
+            if (!empty($insertInventory)) {
+                $sql = \db('物料_库存')->fetchSql(true)->insert($insertInventory);
+                \db()->query($sql);
             }
 
-            // 批量写入日志
-            if ($insertLogs) {
-                Db::name('库存_出入库明细')->insertAll($insertLogs);
-            }
+            $sql = \db('库存_出入库明细')->fetchSql(true)->insert($insertLogs);
+            \db()->query($sql);
 
-            Db::commit();
+            \db()->commit();
             $this->success('入库成功');
 
         } catch (\Exception $e) {
-            Db::rollback();
+            \db()->rollback();
             $this->error('操作失败:' . $e->getMessage());
         }
     }
@@ -3394,7 +3385,7 @@ class WorkOrderSpotCheck extends Api{
     /**
      * 总检日产量汇总
      * code:工序名称
-    */
+     */
     public function DailyProductionReport(){
         if ($this->request->isGet() === false) {
             $this->error('请求错误');