panlumeng 3 years ago
parent
commit
9c1f5bf5ac
3 changed files with 235 additions and 97 deletions
  1. 11 7
      app/admin/controller/Allot.php
  2. 91 90
      app/admin/controller/Check.php
  3. 133 0
      app/common.php

+ 11 - 7
app/admin/controller/Allot.php

@@ -71,6 +71,10 @@ class Allot extends BaseController
     $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
     $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) : "";
     $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) :"0";
+    $dain = isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
+    if($dain==""){
+        return error_show(1002,"商品不能为空");
+        }
     Db::startTrans();
     try {
             $data=[
@@ -187,24 +191,24 @@ class Allot extends BaseController
             if($da>0) {
                 foreach ($dain as $value) {
                     $st = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
-                        ->join("good_stock c", "c.good_type_code = b.type_code", "left")->where(['wsm_code'=>$wsm_out,'good_type_code' => $value['type_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
+                        ->join("good_stock c", "c.good_type_code = b.type_code", "left")->where(['wsm_code' => $wsm_out, 'good_type_code' => $value['type_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
                         ->field("b.type_code,a.good_name,a.unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock")->find();
-                    if(empty($st)){
+                    if (empty($st)) {
                         Db::rollback();
-                        return error_show(1003,"商品不能为空");
+                        return error_show(1003, "商品不能为空");
                     }
                     $temp = [];
-                    $temp['id']=$value['id'];
+                    $temp['id'] = $value['id'];
                     $temp['good_name'] = $st['good_name'];
                     $temp['good_type_code'] = $value['good_type_code'];
                     $temp['allot_num'] = $value['allot_num'];
                     $temp['usable_num'] = 0;
                     $temp['error_num'] = 0;
                     $temp['error_remark'] = "";
-                    $temp['allot_code'] =$etid['allot_code'];
-                    $temp['stock_num'] =0;
+                    $temp['allot_code'] = $etid['allot_code'];
+                    $temp['stock_num'] = 0;
                     $temp['updatetime'] = date("Y-m-d H:i:s");
-                    $dn []= $temp;
+                    $dn [] = $temp;
                     $np = Db::name('allot_info')->save(['updatetime' => date('Y-m-d H:i:s')]);
                     $io = db::name('allot_info')->insertAll($dn);
                     if ($io) {

+ 91 - 90
app/admin/controller/Check.php

@@ -65,7 +65,8 @@ public function list()
     $list = Db::name('good_check')->alias('a')->join("warehouse_info b","a.wsm_code = b.wsm_code","left")
         ->join("depart_user c","c.uid=a.apply_id","left")
         ->join("company_item d","d.id=c.itemid","left")
-        ->field("a.apply_id,a.apply_name,a.type,a.addtime,a.wsm_code,a.check_code,b.name,c.itemid,d.name as 'rename',a.id")->where($where)->page($page,$size)->select();
+        ->join("supplier v","v.code=b.supplierNo","left")
+        ->field("a.status,a.apply_id,a.apply_name,a.type,a.addtime,a.wsm_code,a.check_code,b.name,c.itemid,d.name as 'rename',a.id,v.name as 'caname',v.code")->where($where)->page($page,$size)->select();
     return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
     }
 public function goodlist(){
@@ -101,23 +102,23 @@ public function create(){
     $rm= isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
     $ri= isset($apply_name["data"]['nickname']) ?  $apply_name["data"]['nickname'] : "";
     $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
-    $dain=isset($this->post['good']) && $this->post['good'] !=="" ? trim($this->post['good']):"";
-    if($type==2){
-        if($dain==""||empty($dain)){
-            return error_show(1002,"商品不能为空");
-        }
-    }else{
-        if($type==1) {
-
-        $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
-              ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
-              ->field("b.type_code,a.good_name")->select();
-        //var_dump($dain);
-        }
-        if($dain==""){
-            return error_show(1003,"商品不能为空");
-        }
-    }
+//    $dain=isset($this->post['good']) && $this->post['good'] !=="" ? trim($this->post['good']):"";
+//    if($type==2){
+//        if($dain==""||empty($dain)){
+//            return error_show(1002,"商品不能为空");
+//        }
+//    }else{
+//        if($type==1) {
+//
+//        $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
+//              ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
+//              ->field("b.type_code,a.good_name")->select();
+//        //var_dump($dain);
+//        }
+//        if($dain==""){
+//            return error_show(1003,"商品不能为空");
+//        }
+//    }
     Db::startTrans();
     try{
         $data=[
@@ -132,33 +133,33 @@ public function create(){
             "updatetime"=>date("Y-m-d H:i:s")
         ];
         $da= Db::name('good_check')->insert($data,true);
-        $dio=[];
-        if($da>0){
-            foreach ($dain as $value){
-            $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
-                ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
-                ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
-
-            $temp=[];
-            $temp['good_name']=$st['good_name'];
-            $temp['origin_price']=$st['original_price'];
-            $temp['good_type_code']=$st['good_type_code'];
-            $temp['origin_num']=$st['usable_stock'];
-            $temp['check_num']=0;
-            $temp['diff_num']=0;
-            $temp['status']=0;
-            $temp['remark']="";
-            $temp['is_del']=0;
-            $temp['check_time']=date('Y-m-d H:i:s');
-            $temp['check_code']=$check_code;
-            $temp['addtime']=date("Y-m-d H:i:s");
-            $temp['updatetime']=date("Y-m-d H:i:s");
-            $dio[] =$temp;
-            }
-            $in= Db::name('check_item')->insertAll($dio);
-        }
-        if($in){
-            Db::commit();
+//        $dio=[];
+//        if($da>0){
+//            foreach ($dain as $value){
+//            $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
+//                ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
+//                ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
+//
+//            $temp=[];
+//            $temp['good_name']=$st['good_name'];
+//            $temp['origin_price']=$st['original_price'];
+//            $temp['good_type_code']=$st['good_type_code'];
+//            $temp['origin_num']=$st['usable_stock'];
+//            $temp['check_num']=0;
+//            $temp['diff_num']=0;
+//            $temp['status']=0;
+//            $temp['remark']="";
+//            $temp['is_del']=0;
+//            $temp['check_time']=date('Y-m-d H:i:s');
+//            $temp['check_code']=$check_code;
+//            $temp['addtime']=date("Y-m-d H:i:s");
+//            $temp['updatetime']=date("Y-m-d H:i:s");
+//            $dio[] =$temp;
+//            }
+//            $in= Db::name('check_item')->insertAll($dio);
+//        }
+        if($da){
+           Db::commit();
             return error_show(0,"盘点创建成功");
         }else{
             Db::rollback();
@@ -167,7 +168,7 @@ public function create(){
     }catch (\Exception $e){
         Db::rollback();
         return error_show(1005,$e->getMessage());
-    }
+   }
     }
 public function info(){
     $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
@@ -223,24 +224,24 @@ public function edit()
     }
     $rm= isset($apply_id["data"]['id']) ?  $apply_id["data"]['id'] : "";
     $ri= isset($apply_name["data"]['nickname']) ?  $apply_name["data"]['nickname'] : "";
-    $dain=isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
-    if($type==2){
-       // var_dump($dain);
-        if($dain==""||empty($dain)){
-            return error_show(1002,"商品不能为空");
-        }
-    }else{
-        if($type==1) {
-
-            $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
-                ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
-                ->field("b.type_code,a.good_name")->select();
-            //var_dump($dain);
-        }
-        if($dain==""){
-            return error_show(1003,"商品不能为空");
-        }
-    }
+//    $dain=isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
+//    if($type==2){
+//       // var_dump($dain);
+//        if($dain==""||empty($dain)){
+//            return error_show(1002,"商品不能为空");
+//        }
+//    }else{
+//        if($type==1) {
+//
+//            $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
+//                ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
+//                ->field("b.type_code,a.good_name")->select();
+//            //var_dump($dain);
+//        }
+//        if($dain==""){
+//            return error_show(1003,"商品不能为空");
+//        }
+//    }
     Db::startTrans();
     try {
         $var = [
@@ -251,36 +252,36 @@ public function edit()
             "updatetime" => date("Y-m-d H:i:s")
         ];
         $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
-            $dn =[];
-            if($up>0){
-                foreach ($dain as $value){
-                    $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
-                        ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
-                        ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
-                    $temp=[];
-                    $temp['good_name']=$st['good_name'];
-                    $temp['origin_price']=$st['original_price'];
-                    $temp['good_type_code']=$st['good_type_code'];
-                    $temp['origin_num']=$st['usable_stock'];
-                    $temp['check_num']=0;
-                    $temp['diff_num']=0;
-                    $temp['status']=0;
-                    $temp['remark']="";
-                    $temp['is_del']=0;
-                    $temp['check_time']=date('Y-m-d H:i:s');
-                    $temp['check_code']=$eid['check_code'];
-                    $temp['addtime']=date("Y-m-d H:i:s");
-                    $temp['updatetime']=date("Y-m-d H:i:s");
-                    $dn[] =$temp;
-                }
-                $np = Db::name('check_item')->where(['check_code'=>$eid['check_code'],'is_del'=>0])->update(['is_del'=>1,'updatetime'=>date('Y-m-d H:i:s')]);
-               $io = db::name('check_item')->insertAll($dn);
+//            $dn =[];
+//            if($up>0){
+//                foreach ($dain as $value){
+//                    $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
+//                        ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
+//                        ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
+//                    $temp=[];
+//                    $temp['good_name']=$st['good_name'];
+//                    $temp['origin_price']=$st['original_price'];
+//                    $temp['good_type_code']=$st['good_type_code'];
+//                    $temp['origin_num']=$st['usable_stock'];
+//                    $temp['check_num']=0;
+//                    $temp['diff_num']=0;
+//                    $temp['status']=0;
+//                    $temp['remark']="";
+//                    $temp['is_del']=0;
+//                    $temp['check_time']=date('Y-m-d H:i:s');
+//                    $temp['check_code']=$eid['check_code'];
+//                    $temp['addtime']=date("Y-m-d H:i:s");
+//                    $temp['updatetime']=date("Y-m-d H:i:s");
+//                    $dn[] =$temp;
+//                }
+//                $np = Db::name('check_item')->where(['check_code'=>$eid['check_code'],'is_del'=>0])->update(['is_del'=>1,'updatetime'=>date('Y-m-d H:i:s')]);
+//               $io = db::name('check_item')->insertAll($up);
                // var_dump(Db::name('check_item')->getLastSql());
-                if ($io) {
+                if ($up) {
                     Db::commit();
                     return error_show(0, "盘点更新成功");
                 }
-            }
+
         Db::rollback();
         return error_show(1003,"盘点更新失败");
     } catch (\Exception $e) {

+ 133 - 0
app/common.php

@@ -294,3 +294,136 @@ function crea($data,$vio=0)
     return $data;
 }
 
+/**
+ * @param $files
+ * @param string $extend
+ * @return array
+ * @throws PHPExcel_Exception
+ * @throws PHPExcel_Reader_Exception
+ */
+function upload_excel($files,$extend="xls")
+{
+    // 获取表单上传文件
+    try {
+        validate([
+            'file' => [
+                // 限制文件大小(单位b),这里限制为4M
+                //fileSize' => 4 * 1024 * 1024,
+                'fileExt' => 'xlsx,xls'
+            ]
+        ],
+            [
+                //'file.fileSize' => '文件太大',
+                'file.fileExt' => '不支持的文件',
+            ]
+        )->check(['file' => $files]);
+
+        // $name = $files->getOriginalExtension();
+        if ($extend == 'xlsx') {
+            $objReader = PHPExcel_IOFactory::createReader('Excel2007');
+        } else {
+            $objReader = PHPExcel_IOFactory::createReader('Excel5');
+        }
+
+        $savename = Filesystem::disk('public')->putFile('topic/excel', $files);
+        $import_path = root_path() . 'public/storage/' . $savename;
+
+        $spreadsheet = $objReader->load($import_path);
+        $sheet = $spreadsheet->getActiveSheet();
+        $sheetData = $sheet->toArray();
+        if (empty($sheetData) || !is_array($sheetData)) {
+            return ['code' => 1003, "msg" => '数据不能为空'];
+        }
+        $list = [];
+
+        foreach ($sheetData as $key => $value) {
+            $list[] = $value;
+        }
+        return ['code' => 0, "msg" => '数据解析成功', 'data' => $list];
+    } catch (think\exception\ValidateException $e) {
+        // echo $e->getMessage();
+        return ['code' => 1003, "msg" => $e->getMessage()];
+    }
+}
+/**
+ * @param string $fileName
+ * @param array $headArr
+ * @param array $data
+ */
+function excelSave($fileName = '', $headArr = [], $data = [])
+{
+    $objPHPExcel = new PHPExcel();
+    $objPHPExcel->getProperties();
+    $keyA = 0; // 设置表头
+    foreach ($headArr as $v) {
+        $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
+        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
+        $keyA += 1;
+    }
+
+    $column = 2;
+    $objActSheet = $objPHPExcel->getActiveSheet();
+
+    foreach ($data as $key => $rows) { // 行写入
+        $span = 0;
+        foreach ($rows as $keyName => $value) { // 列写入
+            //判断数据是否有数组,如果有数组,转换成字符串
+
+            if(is_array($value)){
+                $value = implode("、", $value);
+            }
+            $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
+            $span++;
+        }
+        $column++;
+    }
+    //  var_dump($objActSheet->getActiveCell());
+    $file = $fileName. ".xls";
+    //$fileName .= "_" . date("Y_m_d", Request()->instance()->time()) . ".xls";
+    //$fileName = iconv("utf-8", "gb2312", $fileName); // 重命名表
+    $dir =root_path() . 'public/storage/report/'.date("YmdHis")."/";
+    if(!is_dir($dir)){
+        mkdir($dir,0777,true);
+    }
+    $objPHPExcel->setActiveSheetIndex(0); // 设置活动单指数到第一个表,所以Excel打开这是第一个表
+    $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
+    $objWriter->save($dir . $file); // 文件通过浏览器下载
+    $url = $dir . $file;
+    if(!file_exists($url)){
+        echo "文件生成失败";
+    }
+    $saveDir = root_path()."public/storage/zip/";
+    if(!is_dir( $saveDir)){
+        mkdir($saveDir,0777,true);
+    }
+    $datetime = date("Y-m-d H:i:s");
+    $file_dir = $saveDir.$datetime.".zip";
+    # 5.1 文件打包,提示:使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
+    $zip = new \ZipArchive ();
+    # 5.2 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
+    if ($zip->open($file_dir, \ZipArchive::OVERWRITE) !== true && $zip->open($file_dir, \ZipArchive::CREATE) !==
+        true) echo '无法打开文件或者文件创建失败';
+
+    # 5.3 批量写入压缩包
+    $zip->addEmptyDir($fileName);
+    // @$zip->addFile($v['file_path'], 'resume'.DIRECTORY_SEPARATOR.basename($headername));
+    @$zip->addFile($url,$fileName.DIRECTORY_SEPARATOR.basename($url));
+    # 5.4 关闭压缩包写入
+    $zip->close();
+    @deldir($dir);
+    # 6. 检查文件是否存在,并输出文件
+    if (! file_exists ( $file_dir ))  echo '简历文件不存在';
+
+    ob_clean();
+    flush();
+    header("Cache-Control: max-age=0");
+    header("Content-Description: File Transfer");
+    header('Content-disposition: attachment; filename=' . basename($file_dir)); # 处理文件名
+    header("Content-Type: application/octet-stream");                           # 流文件输出
+    header("Content-Transfer-Encoding: binary");                                # 告诉浏览器,这是二进制文件
+    header('Content-Length: ' . filesize($file_dir));                           # 告诉浏览器,文件大小
+    readfile($file_dir);                                                        # 输出文件
+    @ unlink($file_dir);
+    exit();
+}
+