|
|
@@ -33,8 +33,8 @@ class OrderTrackingImport implements ToCollection
|
|
|
public $orderPackages = [];
|
|
|
public $order_is = [];
|
|
|
/**
|
|
|
- * @param Collection $collection
|
|
|
- */
|
|
|
+ * @param Collection $collection
|
|
|
+ */
|
|
|
public function collection(Collection $collection)
|
|
|
{
|
|
|
/**
|
|
|
@@ -54,17 +54,17 @@ class OrderTrackingImport implements ToCollection
|
|
|
foreach ($array as $item_arr) {
|
|
|
$inner_params = [];
|
|
|
foreach ($item_arr as $items) {
|
|
|
- $order = $this->getOrder($items[1],$items) ;
|
|
|
+ $order = $this->getOrder($items[1], $items);
|
|
|
$orderPackageCommodities = $this->getOrderPackageCommodities($items);
|
|
|
$bas_sku = $this->getBasSku((string)$items[6]);
|
|
|
- $gross_weight = round(($bas_sku->grossweight ?? 0) * $orderPackageCommodities->amount,2);
|
|
|
- $bulk = round(($bas_sku->cube ?? 0) * $orderPackageCommodities->amount,2) ;
|
|
|
+ $gross_weight = round(($bas_sku->grossweight ?? 0) * $orderPackageCommodities->amount, 2);
|
|
|
+ $bulk = round(($bas_sku->cube ?? 0) * $orderPackageCommodities->amount, 2);
|
|
|
$inner_params[] = [
|
|
|
'order_package_commodity_id' => $orderPackageCommodities->id,
|
|
|
'owner_id' => $owner->id,
|
|
|
'web_order_number' => $items[2],
|
|
|
'order_client_code' => $order->client_code,
|
|
|
- 'gross_weight' => $gross_weight,
|
|
|
+ 'gross_weight' => $gross_weight,
|
|
|
'bulk' => $bulk,
|
|
|
];
|
|
|
}
|
|
|
@@ -92,6 +92,9 @@ class OrderTrackingImport implements ToCollection
|
|
|
$orderService = app('OrderService');
|
|
|
$packages = $this->getPackage($items[1],$items);
|
|
|
$packages = collect($packages);
|
|
|
+ if(!$packages||$packages->isEmpty()){
|
|
|
+ app('LogService')->log(__METHOD__,__FUNCTION__,'导入空值:'.json_encode($packages));
|
|
|
+ };
|
|
|
$orderPackageCommodities = null;
|
|
|
if(count($packages)>1){
|
|
|
$bool = false;
|
|
|
@@ -123,9 +126,14 @@ class OrderTrackingImport implements ToCollection
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if($orderPackageCommodities == null){
|
|
|
- $package = $packages->first();
|
|
|
- $commodity = $this->getCommodity((string)$items[6],$items);
|
|
|
+
|
|
|
+ if ($orderPackageCommodities == null) {
|
|
|
+ $package = $packages->first();
|
|
|
+ if(!$package){
|
|
|
+ $order=$this->order[$items[1]];
|
|
|
+ $package=$order->package;
|
|
|
+ }
|
|
|
+ $commodity = $this->getCommodity((string)$items[6], $items);
|
|
|
$orderPackageCommodities = OrderPackageCommodities::query()->create(['order_package_id' => $package['id'], 'commodity_id' => $commodity->id, 'amount' => $items[8]]);
|
|
|
}
|
|
|
return $orderPackageCommodities;
|
|
|
@@ -148,7 +156,7 @@ class OrderTrackingImport implements ToCollection
|
|
|
}
|
|
|
|
|
|
public function getShop($name){
|
|
|
- if($this->shops[$name] ?? false){
|
|
|
+ if(!empty($this->shops[$name])){
|
|
|
return $this->shops[$name];
|
|
|
}else{
|
|
|
$shop = Shop::query()->firstOrCreate(['owner_id'=>$this->owner->id,'name'=>$name]);
|
|
|
@@ -157,7 +165,7 @@ class OrderTrackingImport implements ToCollection
|
|
|
}
|
|
|
}
|
|
|
public function getCommodity(string $sku,&$items){
|
|
|
- if($this->commodities[(string)$sku]?? false){
|
|
|
+ if(!empty($this->commodities[(string)$sku])){
|
|
|
return $this->commodities[(string)$sku];
|
|
|
}else{
|
|
|
$bas_sku = $this->getBasSku((string)$sku);
|
|
|
@@ -173,7 +181,7 @@ class OrderTrackingImport implements ToCollection
|
|
|
}
|
|
|
|
|
|
public function getBasSku($sku){
|
|
|
- if($this->bas_skus[(string)$sku]?? false){
|
|
|
+ if(!empty($this->bas_skus[(string)$sku])){
|
|
|
return $this->bas_skus[(string)$sku];
|
|
|
}else{
|
|
|
$bas_sku = OracleBasSKU::query()->selectRaw('BAS_SKU.sku,BAS_SKU.customerid,BAS_SKU.grossweight,BAS_SKU.cube,BAS_SKU.descr_c')->where('sku',(string)$sku)->where('customerid',$this->owner->code)->first();
|
|
|
@@ -187,36 +195,46 @@ class OrderTrackingImport implements ToCollection
|
|
|
* @var OrderService $orderService
|
|
|
*/
|
|
|
$orderService = app('OrderService');
|
|
|
- if($this->order[$client_no] ?? false){
|
|
|
+ if( !empty($this->order[$client_no])){
|
|
|
return $this->order[$client_no];
|
|
|
+ }
|
|
|
+
|
|
|
+ $order = Order::query()->with('packages.commodities.commodity')->where('client_code',$client_no)->first();
|
|
|
+ if($order){
|
|
|
+ $this->order[$client_no] = $order;
|
|
|
+// if(!$order)app('LogService')->log(__METHOD__,__FUNCTION__,'get1:'.json_encode($order));
|
|
|
+ return $order;
|
|
|
}else{
|
|
|
- $order = Order::query()->with('packages.commodities.commodity')->where('client_code',$client_no)->first();
|
|
|
- if($order ?? false){
|
|
|
- $this->order[$client_no] = $order;
|
|
|
- return $order;
|
|
|
- }else{
|
|
|
- $orderHeader = $this->getOrderHeader($client_no);
|
|
|
- if($orderHeader ?? false){
|
|
|
- $orderService->createOrFindOrderInfo($orderHeader);
|
|
|
- $order = Order::query()->with('packages.commodities.commodity')->where('client_code',$client_no)->first();
|
|
|
- $this->order[$client_no] = $order;
|
|
|
- unset($orderHeader);
|
|
|
- return $order;
|
|
|
- }else{
|
|
|
+ $orderHeader = $this->getOrderHeader($client_no);
|
|
|
+ if($orderHeader){
|
|
|
+ $orderService->createOrFindOrderInfo($orderHeader);
|
|
|
+ $order = Order::query()->with('packages.commodities.commodity')->where('client_code',$client_no)->first();
|
|
|
+ if(!$order){
|
|
|
$shop = $this->getShop($items[5]);
|
|
|
$order = Order::query()->create([
|
|
|
'code'=>'null'.Str::uuid(),'client_code' => $items[1],'web_order_number' => $items[2],'shop_id'=>$shop->id
|
|
|
]);
|
|
|
- $this->order[$client_no] = $order;
|
|
|
- return $order;
|
|
|
}
|
|
|
+ $this->order[$client_no] = $order;
|
|
|
+ unset($orderHeader);
|
|
|
+// if(!$order)app('LogService')->log(__METHOD__,__FUNCTION__,'get2:'.json_encode($order));
|
|
|
+ return $order;
|
|
|
+ }else{
|
|
|
+ $shop = $this->getShop($items[5]);
|
|
|
+ $order = Order::query()->create([
|
|
|
+ 'code'=>'null'.Str::uuid(),'client_code' => $items[1],'web_order_number' => $items[2],'shop_id'=>$shop->id
|
|
|
+ ]);
|
|
|
+// app('LogService')->log(__METHOD__,__FUNCTION__,'create1:'.json_encode($order));
|
|
|
+ $this->order[$client_no] = $order;
|
|
|
+// if(!$order)app('LogService')->log(__METHOD__,__FUNCTION__,'get3:'.json_encode($order));
|
|
|
+ return $order;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function getPackage($client_code,&$items)
|
|
|
{
|
|
|
- if($this->orderPackages[$client_code] ?? false){
|
|
|
+ if(!empty($this->orderPackages[$client_code])){
|
|
|
return $this->orderPackages[$client_code];
|
|
|
}else{
|
|
|
$order = $this->getOrder($client_code,$items);
|