Browse Source

优化excel

qiuenguang 1 year ago
parent
commit
543b76dd69
2 changed files with 18 additions and 15 deletions
  1. 12 11
      application/admin/controller/Deliver.php
  2. 6 4
      application/admin/controller/QcodeAdd.php

+ 12 - 11
application/admin/controller/Deliver.php

@@ -266,8 +266,8 @@ class Deliver extends Backend
             'supplier_no' => $bachList['supplier_code'],
             'matter_name' => $bachList['matter_name'],
             'matter_no' => $bachList['matter_no'],
-            'manufacture_date' => $bachList['manufacture_date'],
-            'print_date' => $bachList['print_date'],
+            'manufacture_date' => date('Y/m/d',strtotime('20'.$bachList['manufacture_date'])),
+            'print_date' => date('Y/m/d',strtotime('20'.$bachList['print_date'])),
             'box_num' => $large_num,
             'tray_num' => $bachList['tray_num'],
             'small_num' => $small_num,
@@ -275,21 +275,21 @@ class Deliver extends Backend
             's_reservation' => $bachList['s_reservation'],
             'l_flow' => $bachList['l_flow'],
             's_flow' => $bachList['s_flow'],
-            'l_weight' => $bachList['l_weight'],
-            's_weight' => $bachList['s_weight'],
+            'l_weight' => 0,
+            's_weight' => $bachList['s_weight']/1000,
             'code' => [],
         ];
         $large_id = explode(',', $large_str);
         foreach ($large_id as $k => $v) {
             $largeList = $large->name($company . '_' . 'qcode_large')->where('_id', $v)->find();
+            $data['l_weight'] = $data['l_weight'] + (int)$largeList['l_weight']/100;
             $small_list = $small->name($company . '_' . 'qcode_small')->where('large_id', $v)->select();
-
             foreach ($small_list as $value) {
                 $code = [
                     'large_code' => $largeList['code'],
                     'small_code' => $value['code'],
                 ];
-                $data['code'][] = $code;
+                array_push($data['code'],$code);
             }
         }
         return $data;
@@ -352,11 +352,12 @@ class Deliver extends Backend
         $sheet->getCell('C10')->setValue(isset($data['s_flow'])?$data['s_flow']:'');
         $sheet->getCell('C12')->setValue(isset($data['l_weight'])?$data['l_weight']:'');
         $sheet->getCell('C14')->setValue(isset($data['s_weight'])?$data['s_weight']:'');
-        foreach ($data['code'] as $v){
-            $sheet->getCell('A16')->setValue(isset($v['large_code'])?$v['large_code']:'');
-            $sheet->getCell('B16')->setValue('');
-            $sheet->getCell('C16')->setValue(isset($v['small_code'])?$v['small_code']:'');
-            $sheet->getCell('D16')->setValue('');
+        foreach ($data['code'] as $k=>$v){
+            $m = $k+16;
+            $sheet->getCell('A'.$m)->setValue(isset($v['large_code'])?$v['large_code']:'');
+            $sheet->getCell('B'.$m)->setValue('');
+            $sheet->getCell('C'.$m)->setValue(isset($v['small_code'])?$v['small_code']:'');
+            $sheet->getCell('D'.$m)->setValue('');
         }
         //文件另存
         $filename = date('Ymd',time()).rand(100,999).'_'.$data['supplier_name'].'_'.str_replace('/','_',$data['matter_name']).'_'.$data['small_num'].'.xlsx';

+ 6 - 4
application/admin/controller/QcodeAdd.php

@@ -113,6 +113,7 @@ class QcodeAdd extends Backend
         if ($data['danwei'] == 1){
             $num = $data['number'];
             $tray_num = $data['tray_num'];
+            $tray_num1 = $data['tray_num'];
             $box_number = $data['box_number'];
             $small_num = (int)ceil((int)$data['number']/(int)$data['box_number']);
             $large_num = (int)ceil($small_num/$tray_num);
@@ -122,6 +123,7 @@ class QcodeAdd extends Backend
             $small_num = $data['small_num'];
             $large_num = (int)ceil($small_num/$tray_num);
             $box_number = 1;
+            $tray_num1 = 1;
         }
         //插入批次信息
         $userinfo = Session::get('admin');//获取用户信息
@@ -143,7 +145,7 @@ class QcodeAdd extends Backend
             'manufacture_date' => (int)date('ymd',strtotime($data['manufacture_date'])),
             'print_date' => (int)date('ymd',strtotime($data['print_date'])),
             'box_num' => $box_number,
-            'tray_num' => $tray_num,
+            'tray_num' => $tray_num1,
             'l_reservation' => '',
             'l_flow' => $data['big_liushui'],
             'l_weight' => $data['big_weight'],
@@ -197,7 +199,7 @@ class QcodeAdd extends Backend
             }else{
                 //小件二维码不存在,新增记录
                 $liushui->save($small_liushui);
-                $lastNum['last_num'] = 1;
+                $lastNum['last_num'] = 0;
             }
 
             //循环插入大件二维码数据
@@ -230,7 +232,7 @@ class QcodeAdd extends Backend
                     'create_time' => time(),
                     'p_nums' => 0,
                     'userid' =>$userinfo['id'],
-                    'l_weight' =>$batchList['l_weight'],
+                    'l_weight' =>$l_weight,
                     'l_num' =>$l_num,
                     'l_status' => 0,
                     'l_print' => 0
@@ -243,7 +245,7 @@ class QcodeAdd extends Backend
                 if ($large_id){
 //                    //小件码循环插入
                     for ($j=0;$j<$tray_num and ($j+$i*$tray_num)<$batchList['small_num'];$j++){
-                            $small = new QcodeSmall();
+                        $small = new QcodeSmall();
                         $s_flow = $this->intTochar($batchList['s_flow']+$j+$i*$batchList['tray_num']+$lastNum['last_num'],6);//小件码序号从1开始
                         $s_weight = $this->intTochar($batchList['s_weight'],6);
                         $small_sign = '000';