Просмотр исходного кода

问题件生成 问题件生成时,商铺的如果有同名的生成不了

ajun 5 лет назад
Родитель
Сommit
06e52e32a9
3 измененных файлов с 18 добавлено и 53 удалено
  1. 2 0
      app/Services/OrderService.php
  2. 10 53
      app/Services/ShopService.php
  3. 6 0
      app/Shop.php

+ 2 - 0
app/Services/OrderService.php

@@ -509,6 +509,7 @@ class OrderService
             $shop_name_map[$key] = $shop;
         }
         $insert_params = $this->getParamsByOrderHeader($orderHeaders,$owners_code_map,$logistics_code_map,$shop_name_map);
+
         if(count($insert_params)> 0){
             $this->create($insert_params);
         }
@@ -535,6 +536,7 @@ class OrderService
             $logistic =  $logistics_code_map[$orderHeader->userdefine1] ?? null;
             $key = ' owner_code='.$orderHeader->customerid.' name='.$orderHeader->issuepartyname ?? '';
             $shop = $shop_name_map[$key] ?? '';
+
             // 自提 转 新杰物流
             if($logistic!= null && $logistic->name == '自提'){
                 $logistic = $logistic_XJWL;

+ 10 - 53
app/Services/ShopService.php

@@ -25,71 +25,28 @@ class ShopService
     {
         return app(BatchUpdateService::class)->batchUpdate('shops',$params);
     }
-    public function 根据追踪的WMS订单返回商铺($WMSOrderHeaders, $owners = null)
-    {
-        if ($owners == null) {
-            /** @var $ownerService OwnerService */
-            $ownerService = app('ownerService');
-            $owners = $ownerService->获取订单跟踪的货主();
-        }
-        if(count($WMSOrderHeaders) == 0){
-            return [];
-        }
-        $issuePartyNames = [];
-        foreach ($WMSOrderHeaders as $WMSOrderHeader) {
-            $issuePartyNames[$WMSOrderHeader['issuepartyname']] = $WMSOrderHeader;
-        }
-        $issuePartyNames = array_unique($issuePartyNames);
-        $issuePartyNames = array_diff($issuePartyNames,['','*',null]);
-
-        $shops = Shop::query()->whereIn('name',array_keys($issuePartyNames))->get();
-        $insert_params = [];
-
-        if (count($shops) < count($issuePartyNames)) {
-            $shopNames = data_get($shops, '*.name');
-            $shopDiff = array_diff($issuePartyNames, $shopNames);
-            foreach ($shopDiff as $key=>$item) {
-                if($key === '' ){
-                    continue;
-                }
-                $owner = $owners->where('code', $item['customerid'])->first();
-                if($owner === null || $item['issuepartyname'] ?? false)
-                    continue;
-                array_push($insert_params,['owner_id' => $owner['id'], 'name' => $item['issuepartyname']]);
-            }
-        }
-        try {
-            if(count($insert_params) > 0){
-                Shop::query()->insert($insert_params);
-                LogService::log(__METHOD__, __FUNCTION__, '批量创建 shop' .json_encode($insert_params));
-            }
-        } catch (\Exception $e) {
-            LogService::log(__METHOD__, __FUNCTION__, '创建创建 shop error' .json_encode($insert_params) . $e->getMessage(),$e->getTraceAsString());
-        }
-        return Shop::query()->whereIn('name',array_keys($issuePartyNames))->get();
-    }
 
-    public function getByWmsOrders($orderHeaders){
-        //issuepartyname
+    public function getByWmsOrders($orderHeaders)
+    {    //issuepartyname
         $maps = [];
         foreach ($orderHeaders as $orderHeader) {
             $value = ['owner_code'=>$orderHeader->customerid,'issuepartyname'=>$orderHeader->issuepartyname];
-            if(!in_array($value,$maps)){
+            if(!in_array($value,$maps))
                 $maps[] = $value;
-            }
         }
-        $issuepartynames = array_diff(array_unique(data_get($maps,'*.issuepartyname')),['','*',null])  ;
-        $shops = Shop::query()
-            ->whereIn('name',$issuepartynames)
-            ->get();
+        $issuepartynames = array_diff(array_unique(data_get($maps,'*.issuepartyname')),['','*',null]);
+        $owner_codes = array_diff(array_unique(data_get($maps,'*.owner_code')),['','*',null]);
+        $shops = Shop::query()->with('owner')
+            ->whereHas('owner',function($query)use($owner_codes){
+                $query->whereIn('code',$owner_codes);
+            })->whereIn('name',$issuepartynames)->get();
         if($shops->count() < count($issuepartynames)){
             $shops_code = data_get($shops,'*.name');
             $issuepartynames = array_diff($issuepartynames,$shops_code);
             $params = [];
             foreach ($maps as $item){
-               if(in_array($item['issuepartyname'],$issuepartynames)){
+               if(in_array($item['issuepartyname'],$issuepartynames))
                    $params[] = $item;
-               }
             }
             $shops_list = $this->createByNameAndOwnerCode($params);
             $shops->concat($shops_list);

+ 6 - 0
app/Shop.php

@@ -11,4 +11,10 @@ class Shop extends Model
     use ModelTimeFormat;
 
     protected $fillable = ['name','owner_id'];
+
+    public function owner()
+    {
+        return $this->belongsTo(Owner::class);
+    }
+
 }