wugg %!s(int64=2) %!d(string=hai) anos
pai
achega
fe3d11f525
Modificáronse 3 ficheiros con 84 adicións e 49 borrados
  1. 37 44
      app/command/ImportOrderFromCHandleData.php
  2. 44 3
      app/common.php
  3. 3 2
      composer.json

+ 37 - 44
app/command/ImportOrderFromCHandleData.php

@@ -7,7 +7,8 @@ use app\admin\model\ActionLog;
 use app\admin\model\GoodLog;
 use app\admin\model\GoodStockInfo;
 use app\admin\model\OrderImportFromC as OIFCModel;
-use app\admin\model\OrderOutChild;use app\admin\model\ProcessOrder;
+use app\admin\model\OrderOutChild;
+use app\admin\model\ProcessOrder;
 use app\admin\model\Test1;
 use think\console\Command;
 use think\console\Input;
@@ -312,7 +313,8 @@ class ImportOrderFromCHandleData extends Command
                         $bol = $this->createCgd($cgd, $rm, $ri, $standing_book_data);
                         if ($bol == false) throw new Exception('订单创建失败');
 
-                    } else {
+                    }
+                    else {
                         //库存品
 	                        $stockUp =[
 		                        "usable_stock"=>$ct['usable_stock']-$good_num,
@@ -348,32 +350,21 @@ class ImportOrderFromCHandleData extends Command
 	                                    ->where(["orderCode" => $orderCode, "status" => 1])
 	                                    ->find();
 	                                if ($order == false) throw new Exception('未找到可以发货得采购单数据');
-                                $tep = [
-                                    "cgdNo" => $order['cgdNo'],
-                                    "outCode" => $outCode,
-                                    "send_num" => $num,
-                                    "status" => 1,
-                                    "addtime" => date("Y-m-d H:i:s"),
-                                    "updatetime" => date("Y-m-d H:i:s")
-                                ];
-                                $ou = Db::name("order_out")->insertGetId($out);
-                                if ($ou == false) throw new Exception('发货地址添加创建失败');
-                                else {
-                                	OrderOutChild::makeChild($outCode);
-                                	    //修改状态,添加待办
-                                	    if ($is_stock==1){
-                                	    	$roleid = Config('app.wsm_cgder_role');
-		                            $uids = Db::name('user_role')
-		                                ->where('is_del', 0)
-		                                ->whereIn('roleid', $roleid)
-		                                ->column('uid');
-		                            $handle_user_list=implode(',', $uids);
-                                	    }
-
-                                $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
-                                if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
-
-                            }
+	                                $tep = [
+	                                    "cgdNo" => $order['cgdNo'],
+	                                    "outCode" => $outCode,
+	                                    "send_num" => $num,
+	                                    "status" => 1,
+	                                    "addtime" => date("Y-m-d H:i:s"),
+	                                    "updatetime" => date("Y-m-d H:i:s")
+	                                ];
+	                                $sen = Db::name("order_send")->save($tep);
+	                                if ($sen == false) throw new Exception('发货地址添加创建失败');
+
+	                                $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
+	                                if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
+
+                            	}
 
                             $out = [
                                 "orderCode" => $orderCode,
@@ -397,6 +388,8 @@ class ImportOrderFromCHandleData extends Command
                             $ou = Db::name("order_out")->insertGetId($out);
                             if ($ou == false) throw new Exception('发货地址添加创建失败');
                             else {
+                            	OrderOutChild::makeChild($outCode);
+
                                 //修改状态,添加待办
                                 if ($is_stock == 1) {
                                     $roleid = Config('app.wsm_cgder_role');
@@ -466,27 +459,27 @@ class ImportOrderFromCHandleData extends Command
                         ],
                     ], JSON_UNESCAPED_UNICODE);
 //                        Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
-                }
+                    }
 
-                Db::commit();
+                    Db::commit();
 
                 $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
 
-            } catch (\think\Exception $exception) {
-                Db::rollback();
-                $order_import_from_c_db
-                    ->where(['id' => $c_data['id'], 'status' => OIFCModel::$status_wait_relation])
-                    ->save([
-                        'status' => $order_import_from_c_db::$status_stock_not_enough,
-                        'updatetime' => date('Y-m-d H:i:s'),
-                        'remark' => $exception->getMessage(),
-                        'updateid' => 0,
-                        'updater' => 'system'
-                    ]);
-                // 指令输出
-                $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
+                } catch (\think\Exception $exception) {
+                    Db::rollback();
+                    $order_import_from_c_db
+                        ->where(['id' => $c_data['id'], 'status' => OIFCModel::$status_wait_relation])
+                        ->save([
+                            'status' => $order_import_from_c_db::$status_stock_not_enough,
+                            'updatetime' => date('Y-m-d H:i:s'),
+                            'remark' => $exception->getMessage(),
+                            'updateid' => 0,
+                            'updater' => 'system'
+                        ]);
+                    // 指令输出
+                    $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
+                }
             }
-        }
 //        }
 
     }

+ 44 - 3
app/common.php

@@ -1001,11 +1001,9 @@ if (!function_exists('excelSaveFile')) {
     function excelSaveFile($datas, string $filename = '')
     {
 
-//        $urls = [];
+
         $dir = root_path() . 'public/storage/report/' . date("YmdHis") . "/";
         if (!is_dir($dir)) mkdir($dir, 0777, true);
-
-//        foreach ($datas as $item) {
         PHPExcel_Settings::setCacheStorageMethod();
         PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;//单元格缓存为MemoryGZip
         $objPHPExcel = new PHPExcel();
@@ -1074,6 +1072,49 @@ if (!function_exists('excelSaveFile')) {
     }
 }
 
+
+if (!function_exists('xlswriter')) {
+    function xlswriter($datas, string $filename = '')
+    {
+
+
+        $dir = root_path() . 'public/storage/report/' . date("YmdHis") . "/";
+        if (!is_dir($dir)) mkdir($dir, 0777, true);
+        $config=["path"=>$dir];
+        $objPHPExcel = new \Vtiful\Kernel\Excel($config);
+		$fileObject = $objPHPExcel->constMemory($filename,"sheet1");
+		$format = new \Vtiful\Kernel\Format($fileObject->getHandle());
+        foreach ($datas as $key => $rows) { // 行写入
+            //第一行取key作表头
+                if($key==0){
+                	$header = array_keys($rows);
+                	$fileObject->header($header);
+                }
+
+                foreach ($rows as $k=>$v) {
+                    $fileObject->insertText($key,$k,$v);
+                }
+        }
+		$filePath = $fileObject->output();
+//         Set Header
+		header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+		header('Content-Disposition: attachment;filename="' . $filename . '"');
+		header('Content-Length: ' . filesize($filePath));
+		header('Content-Transfer-Encoding: binary');
+		header('Cache-Control: must-revalidate');
+		header('Cache-Control: max-age=0');
+		header('Pragma: public');
+		ob_clean();
+		flush();
+		if (copy($filePath, 'php://output') === false) {
+		    // Throw exception
+		    exit('copy file to path error');
+		}
+		// Delete temporary file
+		@unlink($filePath);
+    }
+}
+
 //通过快递网的api获取物流信息
 if (!function_exists('get_logistics_information')) {
     function get_logistics_information(string $post_code = '', string $phone = '')

+ 3 - 2
composer.json

@@ -24,9 +24,10 @@
         "topthink/framework": "^6.0.0",
         "topthink/think-orm": "^2.0",
         "topthink/think-multi-app": "^1.0",
-        "phpoffice/phpexcel": "^1.8",
+        "phpoffice/phpspreadsheet": "*",
         "huaweicloud/huaweicloud-sdk-php": "3.0.3-beta",
-        "youzanyun/open-sdk": "^2.0"
+        "youzanyun/open-sdk": "^2.0",
+        "ext-xlswriter": "*"
     },
     "require-dev": {
         "symfony/var-dumper": "^4.2",