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

解决laborReport模型中appends字段问题
修改asn同步方式

haozi 5 лет назад
Родитель
Сommit
82c2bbf07a

+ 1 - 1
app/Http/Controllers/TestController.php

@@ -1242,7 +1242,7 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
 //       $start=ValueStore::query()->where('name','asn_last_created_sync_at')->value('value');
 //       app(OracleDocAsnHerderService::class)->getWmsAsnOnStartDateCreate($start);
         app(StoreService::class)->storeCreateByWms();
-        //app(StoreService::class)->storeUpdateByWms();
+        app(StoreService::class)->storeUpdateByWms();
         dump('end' . (string)Carbon::now());
     }
 

+ 102 - 76
app/LaborReport.php

@@ -28,6 +28,7 @@ class LaborReport extends Model
         'sequence',
         'amountOfJoined',
     ];
+    public static $withoutAppends = true;
 
     static function tokenOfBroadcastEnterAndLeave(){
         return md5('tokenOfListAll'.Carbon::now()->format('Y-m-d'));
@@ -85,58 +86,69 @@ class LaborReport extends Model
     }
     //总在线时长
     public function getTotalOnlineTimeAttribute(){
-        $laborReports=LaborReport::where('enter_number',$this['enter_number'])->get();
-        $totalOnlineTime=$laborReports->reduce(function ($value,$laborReport){
-            return ($value??0)+$laborReport['thisRecordOnlineTime'];
-        });
-        return $totalOnlineTime;
+        if(self::$withoutAppends) {
+            $laborReports = LaborReport::where('enter_number', $this['enter_number'])->get();
+            $totalOnlineTime = $laborReports->reduce(function ($value, $laborReport) {
+                return ($value ?? 0) + $laborReport['thisRecordOnlineTime'];
+            });
+            return $totalOnlineTime;
+        }
     }
     //总工作时长
     public function getTotalWorkingTimeAttribute(){
-        $laborReports=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->get();
-        $totalWorkingTime=$laborReports->reduce(function ($value,$laborReport){
-            return ($value??0)+$laborReport['thisRecordWorkingTime'];
-        });
-        return $totalWorkingTime;
+        if(self::$withoutAppends) {
+            $laborReports = LaborReport::where('enter_number', $this['enter_number'])->orderBy('id', 'asc')->get();
+            $totalWorkingTime = $laborReports->reduce(function ($value, $laborReport) {
+                return ($value ?? 0) + $laborReport['thisRecordWorkingTime'];
+            });
+            return $totalWorkingTime;
+        }
     }
     //本轮工作起始时间
     public function getThisRoundOnlineStartTimeAttribute(){
-        $laborReports=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->get();
-        foreach ($laborReports as $laborReport){
-            if ($laborReport['enter_at']&&$laborReport['check_in_at'])
-                return $laborReport['check_in_at'];
+        if(self::$withoutAppends) {
+            $laborReports = LaborReport::where('enter_number', $this['enter_number'])->orderBy('id', 'asc')->get();
+            foreach ($laborReports as $laborReport) {
+                if ($laborReport['enter_at'] && $laborReport['check_in_at'])
+                    return $laborReport['check_in_at'];
+            }
         }
     }
     //本轮工作结束时间
     public function getThisRoundOnlineEndTimeAttribute(){
-        $laborReports=LaborReport::where('enter_number',$this['enter_number'])->get();
-        foreach ($laborReports as $laborReport){
-            if ($laborReport['exit_at']&&$laborReport['check_out_at'])
-                return $laborReport['check_out_at'];
+        if(self::$withoutAppends) {
+            $laborReports = LaborReport::where('enter_number', $this['enter_number'])->get();
+            foreach ($laborReports as $laborReport) {
+                if ($laborReport['exit_at'] && $laborReport['check_out_at'])
+                    return $laborReport['check_out_at'];
+            }
         }
     }
     //本次在线时长
     public function getThisRecordOnlineTimeAttribute(){
-        if($this['enter_at']&&!$this['check_out_at']&&!$this['exit_at'])
-            return round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['enter_at']))/3600,2);
-        if ($this['enter_at']&&$this['check_out_at']&&!$this['exit_at'])
-            return round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['enter_at']))/3600,2);
-        if ($this['enter_at']&&$this['exit_at'])
-            return round(Carbon::parse($this['exit_at'])->diffInSeconds(Carbon::parse($this['enter_at']))/3600,2);
-        if ($this['check_in_at']&&!$this['enter_at']&&!$this['check_out_at']&&!$this['exit_at'])
-            return round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
-        if ($this['check_in_at']&&!$this['enter_at']&&$this['check_out_at']&&!$this['exit_at'])
-            return round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
-        if ($this['check_in_at']&&!$this['enter_at']&&$this['exit_at'])
-            return round(Carbon::parse($this['exit_at'])->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
+
+            if ($this['enter_at'] && !$this['check_out_at'] && !$this['exit_at'])
+                return round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['enter_at'])) / 3600, 2);
+            if ($this['enter_at'] && $this['check_out_at'] && !$this['exit_at'])
+                return round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['enter_at'])) / 3600, 2);
+            if ($this['enter_at'] && $this['exit_at'])
+                return round(Carbon::parse($this['exit_at'])->diffInSeconds(Carbon::parse($this['enter_at'])) / 3600, 2);
+            if ($this['check_in_at'] && !$this['enter_at'] && !$this['check_out_at'] && !$this['exit_at'])
+                return round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['check_in_at'])) / 3600, 2);
+            if ($this['check_in_at'] && !$this['enter_at'] && $this['check_out_at'] && !$this['exit_at'])
+                return round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['check_in_at'])) / 3600, 2);
+            if ($this['check_in_at'] && !$this['enter_at'] && $this['exit_at'])
+                return round(Carbon::parse($this['exit_at'])->diffInSeconds(Carbon::parse($this['check_in_at'])) / 3600, 2);
+
     }
     //本次工作时长
     public function getThisRecordWorkingTimeAttribute(){
-        if ($this['check_in_at']&&!$this['check_out_at']&&!$this['relax_time']){
-            $workingTime=round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
-            $checkInTime=Carbon::parse($this['check_in_at']);
-            $checkOutTime=Carbon::parse(Carbon::now())->format('H');
-            return  $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime);
+
+        if ($this['check_in_at']&&!$this['check_out_at']&&!$this['relax_time']) {
+            $workingTime = round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['check_in_at'])) / 3600, 2);
+            $checkInTime = Carbon::parse($this['check_in_at']);
+            $checkOutTime = Carbon::parse(Carbon::now())->format('H');
+            return $this->minusLunchTime($checkInTime, $checkOutTime, $workingTime);
         }
         if ($this['check_in_at']&&$this['check_out_at']&&!$this['relax_time']){
             $workingTime=round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
@@ -150,27 +162,30 @@ class LaborReport extends Model
             $checkOutTime=Carbon::parse($this['check_out_at'])->format('H');
             return  $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime)-$this['relax_time']/60;
         }
+
     }
     //本次取整工作时长
     public function getThisRoundRecordWorkingTimeAttribute(){
-        if ($this['round_check_in_at']&&!$this['round_check_out_at']&&!$this['relax_time']){
-            $workingTime=round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['round_check_in_at']))/3600,2);
-            $checkInTime=Carbon::parse($this['round_check_in_at']);
-            $checkOutTime=Carbon::parse(Carbon::now())->format('H');
-            return  $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime);
-        }
-        if ($this['round_check_in_at']&&$this['round_check_out_at']&&!$this['relax_time']){
-            $workingTime=round(Carbon::parse($this['round_check_out_at'])->diffInSeconds(Carbon::parse($this['round_check_in_at']))/3600,2);
-            $checkInTime=Carbon::parse($this['round_check_in_at']);
-            $checkOutTime=Carbon::parse($this['round_check_out_at'])->format('H');
-            return  $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime);
-        }
-        if ($this['round_check_in_at']&&$this['round_check_out_at']&&$this['relax_time']){
-            $workingTime=round(Carbon::parse($this['round_check_out_at'])->diffInSeconds(Carbon::parse($this['round_check_in_at']))/3600,2);
-            $checkInTime=Carbon::parse($this['round_check_in_at']);
-            $checkOutTime=Carbon::parse($this['round_check_out_at'])->format('H');
-            return  $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime)-$this['relax_time']/60;
-        }
+
+            if ($this['round_check_in_at'] && !$this['round_check_out_at'] && !$this['relax_time']) {
+                $workingTime = round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['round_check_in_at'])) / 3600, 2);
+                $checkInTime = Carbon::parse($this['round_check_in_at']);
+                $checkOutTime = Carbon::parse(Carbon::now())->format('H');
+                return $this->minusLunchTime($checkInTime, $checkOutTime, $workingTime);
+            }
+            if ($this['round_check_in_at'] && $this['round_check_out_at'] && !$this['relax_time']) {
+                $workingTime = round(Carbon::parse($this['round_check_out_at'])->diffInSeconds(Carbon::parse($this['round_check_in_at'])) / 3600, 2);
+                $checkInTime = Carbon::parse($this['round_check_in_at']);
+                $checkOutTime = Carbon::parse($this['round_check_out_at'])->format('H');
+                return $this->minusLunchTime($checkInTime, $checkOutTime, $workingTime);
+            }
+            if ($this['round_check_in_at'] && $this['round_check_out_at'] && $this['relax_time']) {
+                $workingTime = round(Carbon::parse($this['round_check_out_at'])->diffInSeconds(Carbon::parse($this['round_check_in_at'])) / 3600, 2);
+                $checkInTime = Carbon::parse($this['round_check_in_at']);
+                $checkOutTime = Carbon::parse($this['round_check_out_at'])->format('H');
+                return $this->minusLunchTime($checkInTime, $checkOutTime, $workingTime) - $this['relax_time'] / 60;
+            }
+
     }
 
     //工作时长减午饭休息时间
@@ -184,45 +199,54 @@ class LaborReport extends Model
     //转场序号
     public function getSequenceAttribute()
     {
-        if(Arr::has($this->tempFields,'sequence'))return $this->tempFields['sequence'];
-        $laborReports=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->get();
-        foreach($laborReports as $i=>$laborReport){
-            if($laborReport['id']==$this['id']){
-                $this->tempFields['sequence']=$i+1;
-                return $this->tempFields['sequence'];
+        if(self::$withoutAppends) {
+            if (Arr::has($this->tempFields, 'sequence')) return $this->tempFields['sequence'];
+            $laborReports = LaborReport::where('enter_number', $this['enter_number'])->orderBy('id', 'asc')->get();
+            foreach ($laborReports as $i => $laborReport) {
+                if ($laborReport['id'] == $this['id']) {
+                    $this->tempFields['sequence'] = $i + 1;
+                    return $this->tempFields['sequence'];
+                }
             }
         }
     }
     public function getAmountOfJoinedAttribute()
     {
-        if(Arr::has($this->tempFields,'amountOfJoined'))return $this->tempFields['amountOfJoined'];
-        $this->tempFields['amountOfJoined']=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->count();
-        return $this->tempFields['amountOfJoined'];
+        if(self::$withoutAppends) {
+            if (Arr::has($this->tempFields, 'amountOfJoined')) return $this->tempFields['amountOfJoined'];
+            $this->tempFields['amountOfJoined'] = LaborReport::where('enter_number', $this['enter_number'])->orderBy('id', 'asc')->count();
+            return $this->tempFields['amountOfJoined'];
+        }
     }
 
     //进场时间
     public function getEnterAtAttribute()
     {
-        $laborReportStatus=LaborReportStatus::where('labor_report_id',$this['id'])->where('status','未审核')->orderBy('id','desc')->first();
-        if (empty($laborReportStatus))return null;
-        return Carbon::parse($laborReportStatus['created_at'])->format('Y-m-d H:i:s');
+        if(self::$withoutAppends) {
+            $laborReportStatus = LaborReportStatus::where('labor_report_id', $this['id'])->where('status', '未审核')->orderBy('id', 'desc')->first();
+            if (empty($laborReportStatus)) return null;
+            return Carbon::parse($laborReportStatus['created_at'])->format('Y-m-d H:i:s');
+        }
     }
 
     public function getEnteringRecordAttribute()
     {
-        $laborReport=LaborReport::with(['laborReportStatus'=>function($query){
-            return $query->whereIn('status',['已入场','未审核']);
-        }])->where('user_id',$this['user_id'])->orderBy('id','desc')->first();
-        if(empty($laborReport))return null;
-        return $laborReport;
-
+        if(self::$withoutAppends) {
+            $laborReport = LaborReport::with(['laborReportStatus' => function ($query) {
+                return $query->whereIn('status', ['已入场', '未审核']);
+            }])->where('user_id', $this['user_id'])->orderBy('id', 'desc')->first();
+            if (empty($laborReport)) return null;
+            return $laborReport;
+        }
     }
 
     public function getExitAtAttribute()
     {
-        $laborReportStatus=LaborReportStatus::where('labor_report_id',$this['id'])->where('status','已退场')->orderBy('id','desc')->first();
-        if (empty($laborReportStatus))return null;
-        return Carbon::parse($laborReportStatus['created_at'])->format('Y-m-d H:i:s');
+        if(self::$withoutAppends) {
+            $laborReportStatus = LaborReportStatus::where('labor_report_id', $this['id'])->where('status', '已退场')->orderBy('id', 'desc')->first();
+            if (empty($laborReportStatus)) return null;
+            return Carbon::parse($laborReportStatus['created_at'])->format('Y-m-d H:i:s');
+        }
     }
 
     //创建或获取进场编号
@@ -236,8 +260,10 @@ class LaborReport extends Model
     }
 
     public function getIsExportAttribute(){
-        $laborReportStatus=$this->laborReportStatus()->where('labor_report_id',$this['id'])->orderBy('id','desc')->first();
-        return $laborReportStatus['status']=='已退场'?true:false;
+        if(self::$withoutAppends) {
+            $laborReportStatus = $this->laborReportStatus()->where('labor_report_id', $this['id'])->orderBy('id', 'desc')->first();
+            return $laborReportStatus['status'] == '已退场' ? true : false;
+        }
     }
     //出场更新临时工报表信息
     static function exitAndChangeLaborReport($laborReport,$userDutyCheck){

+ 0 - 5
app/OracleDOCASNDetail.php

@@ -25,9 +25,4 @@ class OracleDOCASNDetail extends Model
         return $this->hasOne(OracleBasCode::class,'code','lotatt08')
             ->where('codeid','QLT_STS');
     }
-    public function basSku()
-    {
-        return $this->hasOne(OracleBasSKU::class,'sku','sku')
-            ->select('customerid','sku','alternate_sku1');
-    }
 }

+ 4 - 0
app/Services/LaborReportsCountingRecordService.php

@@ -14,6 +14,10 @@ use Ramsey\Uuid\Type\Integer;
 
 class LaborReportsCountingRecordService
 {
+    public function __construct(LaborReport $laborReport)
+    {
+        $laborReport::$withoutAppends = false;
+    }
     public function userGroupsCount($start, $end)
     {
         $resultByCache = Cache::remember('userGroupsCount_' . $start . '_' . $end, 600, function () use ($start, $end) {

+ 2 - 6
app/Services/OracleDocAsnHerderService.php

@@ -10,9 +10,7 @@ Class OracleDocAsnHerderService
     {
         if (!$startDate) return null;
         $oracleDocAsnHerder= OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus',
-               /* 'asnDetails' => function ($query) {$query->with(['lineStatus', 'qualityStatus','basSku']);}*/
-            ])
+            ->with(['asnType', 'asnStatus'])
             ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3')
             ->where('addTime', '>=', $startDate)
             ->orderByDesc('addtime')
@@ -24,9 +22,7 @@ Class OracleDocAsnHerderService
     {
         if (!$startDate) return null;
         $oracleDocAsnHerder= OracleDOCASNHeader::query()
-            ->with(['asnType', 'asnStatus',
-                /*'asnDetails' => function ($query) {$query->with(['lineStatus', 'qualityStatus','basSku']);}*/
-            ])
+            ->with(['asnType', 'asnStatus'])
             ->select('asnno','asnstatus','asntype','addtime','edittime','customerid','notes','warehouseid','asnreference3')
             ->where('EditTime', '>=', $startDate)
             ->whereColumn('EditTime', '<>', 'addTime')

+ 80 - 39
app/Services/StoreItemService.php

@@ -3,6 +3,7 @@
 namespace App\Services;
 
 use App\OracleDOCASNDetail;
+use App\Owner;
 use App\Services\common\BatchUpdateService;
 use App\Services\common\DataHandlerService;
 use App\Store;
@@ -39,19 +40,27 @@ Class StoreItemService
             $asnnos->add($asnHerder->asnno);
         }
         $asnnos = $asnnos->unique()->toArray();
-        $db = DB::connection('oracle');
-        $sql = <<<sql
-            SELECT d.asnno,d.ASNLINENO,d.SKUDESCRC,d.CUSTOMERID,d.SKU,c.CODENAME_C as lotatt08,b.CODENAME_C as linestatus,d.lotatt05,
-            d.receivedqty,d.expectedqty,d.addtime,d.edittime FROM DOC_ASN_DETAILS d
-            LEFT JOIN BAS_CODES b ON d.linestatus = b.code AND 'ASN_STS' = b.codeid
-            LEFT JOIN BAS_CODES c ON d.lotatt08 = c.code AND 'QLT_STS' = c.codeid WHERE d.ASNNO in (
-sql;
-        $asno_str = '';
-        foreach ($asnnos as $str) $asno_str .= "'" . $str . "',";
-        $asno_str = rtrim($asno_str, ',');
-        $sql=$sql.$asno_str.")";
-        $asnDetails = $db->select(DB::raw($sql));
-        $asnDetails=collect($asnDetails);
+        $asnDetails=OracleDOCASNDetail::query()
+            ->with(['lineStatus', 'qualityStatus'])
+            ->whereIn('asnno',$asnnos)
+            ->select('asnno','asnlineno','customerid','sku','skudescrc','linestatus','lotatt08','lotatt05','receivedqty','expectedqty','addtime','edittime')
+            ->get();
+        //dd($asnDetails->first());
+//        $db = DB::connection('oracle');
+//        $sql = <<<sql
+//            SELECT d.asnno,d.ASNLINENO,d.SKUDESCRC,d.CUSTOMERID,d.SKU,c.CODENAME_C as lotatt08,b.CODENAME_C as linestatus,d.lotatt05,
+//            d.receivedqty,d.expectedqty,d.addtime,d.edittime FROM DOC_ASN_DETAILS d
+//            LEFT JOIN BAS_CODES b ON d.linestatus = b.code AND 'ASN_STS' = b.codeid
+//            LEFT JOIN BAS_CODES c ON d.lotatt08 = c.code AND 'QLT_STS' = c.codeid WHERE d.ASNNO in (
+//sql;
+//        $asno_str = '';
+//        foreach ($asnnos as $str) $asno_str .= "'" . $str . "',";
+//        $asno_str = rtrim($asno_str, ',');
+//        $sql=$sql.$asno_str.")";
+//        $asnDetails = $db->select(DB::raw($sql));
+//        $asnDetails=collect($asnDetails);
+
+
 //        $asnDetails = collect();
 //        $asnHerders->each(function ($asnHeader) use ($asnDetails) {
 //            $asnHeader->asnDetails->each(function ($asnDetail) use ($asnDetails) {
@@ -79,14 +88,35 @@ sql;
 
     public function getParamsByAsnDetails($asnDetails, $store_asn_code_map)
     {
-        /** @var DataHandlerService $dataHandlerService */
+        /**
+         * @var DataHandlerService $dataHandlerService
+         * @var CommodityService $commodityService
+         */
         $dataHandlerService = app(DataHandlerService::class);
+        $commodityService = app(CommodityService::class);
+        $owners = Owner::query()->whereIn('code', array_unique(data_get($asnDetails,'*.customerid')))->get();
+        $owner_map=[];
+        foreach ($owners as $owner){
+            $owner_map[$owner->code]=$owner->id;
+        }
+        $maps = [];
+        foreach ($asnDetails as $asnDetail) {
+            $value = [
+                'owner_code' => $asnDetail->customerid,
+                'sku' => $asnDetail->sku,
+            ];
+            $maps[json_encode($value)] = $value;
+        }
+        $commodities=$commodityService->getCommoditiesByMaps($maps);
+        $commodities_map= $dataHandlerService->dataHeader(['owner_id','sku'], $commodities);
         $storeItems = $this->getByWms($asnDetails);
-        $storeItem_map = $dataHandlerService->dataHeader(['store_asn_code', 'asn_line_code', 'sku'], $storeItems);
+        $storeItem_map = $dataHandlerService->dataHeader(['store_asn_code', 'asn_line_code', 'commodity_id'], $storeItems);
         $params = [];
         foreach ($asnDetails as $asnDetail) {
+            $commodity=$dataHandlerService->getKeyValue(['owner_id'=>$owner_map[$asnDetail->customerid],'sku'=>$asnDetail->sku],$commodities_map);
+            if (!$commodity)continue;
             $storeItem = $dataHandlerService
-                ->getKeyValue(['store_asn_code' => $asnDetail->asnno, 'asn_line_code' => $asnDetail->asnlineno, 'sku' => $asnDetail->sku], $storeItem_map);
+                ->getKeyValue(['store_asn_code' => $asnDetail->asnno, 'asn_line_code' => $asnDetail->asnlineno, 'commodity_id' => $commodity->id], $storeItem_map);
             if ($storeItem ?? false) continue;
             $status = null;
             if ($asnDetail->lineStatus && $asnDetail->lineStatus->codename_c == '完全收货') $status = '已入库';
@@ -95,11 +125,11 @@ sql;
             $params[] = [
                 'store_id' => $store_asn_code_map[$asnDetail->asnno]['id'],
                 'asn_line_code' => (string)$asnDetail->asnlineno,
+                'commodity_id' => $commodity->id,
                 'name' => $asnDetail->skudescrc,
                 'sku' => $asnDetail->sku,
-                'barcode' => $asnDetail->basSku ? $asnDetail->basSku->alternate_sku1 : '',
                 'amount' => $asnDetail->receivedqty ?? 0,
-                'quality' => $asnDetail->qualityStatus ? $asnDetail->qualityStatus->codename_c : '',
+                'quality' => $asnDetail->qualityStatus ?$asnDetail->qualityStatus->codename_c :' ',
                 'status' => $status ? $status : $asnDetail->lineStatus->codename_c,
                 'created_at' => $asnDetail->addtime ?? null,
                 'updated_at' => $asnDetail->edittime ?? null,
@@ -128,17 +158,37 @@ sql;
         if (!$asnDetails || $asnDetails->count() == 0) {
             return null;
         }
-        /** @var DataHandlerService $dataHandlerService */
+        /**
+         * @var DataHandlerService $dataHandlerService
+         * @var CommodityService $commodityService
+         */
         $dataHandlerService = app(DataHandlerService::class);
+        $commodityService = app(CommodityService::class);
+        $owners = Owner::query()->whereIn('code', array_unique(data_get($asnDetails,'*.customerid')))->get();
+        $owner_map=[];
+        foreach ($owners as $owner){
+            $owner_map[$owner->id]=$owner->code;
+        }
+        $maps = [];
+        foreach ($asnDetails as $asnDetail) {
+            $value = [
+                'owner_code' => $asnDetail->customerid,
+                'sku' => $asnDetail->sku,
+            ];
+            $maps[json_encode($value)] = $value;
+        }
+        $commodities=$commodityService->getCommoditiesByMaps($maps);
+        $commodities_map= $dataHandlerService->dataHeader(['id'], $commodities);
         $storeItems = $this->getByWms($asnDetails);
-        $asnDetails_map = $dataHandlerService->dataHeader(['asnno', 'asnlineno', 'sku'], $asnDetails);
+        $asnDetails_map = $dataHandlerService->dataHeader(['asnno', 'asnlineno','customerid','sku'], $asnDetails);
         $updateParams = [[
             'id', 'store_id', 'asn_line_code', 'name', 'sku', 'barcode', 'amount', 'quality', 'status', 'created_at', 'updated_at'
         ]];
         $delete_storeItems = [];
         foreach ($storeItems as $storeItem) {
+            $commodity=$dataHandlerService->getKeyValue(['id'=>$storeItem->commodity_id],$commodities_map);if (!$commodity)continue;
             $asnDetail = $dataHandlerService
-                ->getKeyValue(['asnno' => $storeItem->store_asn_code, 'asnlineno' => $storeItem->asn_line_code, 'sku' => $storeItem->sku], $asnDetails_map);
+                ->getKeyValue(['asnno' => $storeItem->store_asn_code, 'asnlineno' => $storeItem->asn_line_code,'customerid'=>$owner_map[$commodity->owner_id],'sku' => $commodity->sku], $asnDetails_map);
             if (!$asnDetail) {
                 array_push($delete_storeItems, $storeItem);
                 continue;
@@ -146,27 +196,18 @@ sql;
             $status = null;
             if ($asnDetail->lineStatus && $asnDetail->lineStatus->codename_c == '完全收货') $status = '已入库';
             if ($asnDetail->lineStatus && $asnDetail->lineStatus->codename_c == '订单创建') $status = '未入库';
-            if ($storeItem->asn_line_code != $asnDetail['asnlineno'] ||
-                $storeItem->name != $asnDetail['skudescrc'] ||
-                $storeItem->sku != $asnDetail['sku'] ||
-                $storeItem->barcode != $asnDetail['basSku']['alternate_sku1'] ||
-                $storeItem->amount != $asnDetail['receivedqty'] ||
-                $storeItem->quality != $asnDetail['qualityStatus'] ?? $asnDetail['qualityStatus']['codename_c'] ||
-                $storeItem->status != $asnDetail['lineStatus'] ?? $asnDetail['lineStatus']['codename_c'] ||
-                $storeItem->created_at != $asnDetail['addtime'] ||
-                $storeItem->updated_at != $asnDetail['edittime']) {
+            if ($storeItem->updated_at != $asnDetail->edittime) {
                 $updateParams[] = [
                     'id' => $storeItem->id,
                     'store_id' => $storeItem->store->id,
-                    'asn_line_code' => (string)$asnDetail['asnlineno'],
-                    'name' => $asnDetail['skudescrc'],
-                    'sku' => $asnDetail['sku'],
-                    'barcode' => $asnDetail['basSku'] ? $asnDetail['basSku']['alternate_sku1'] : '',
-                    'amount' => $asnDetail['receivedqty'] ?? 0,
-                    'quality' => $asnDetail['qualityStatus'] ? $asnDetail['qualityStatus']['codename_c'] : '',
-                    'status' => $status ? $status : $asnDetail['lineStatus']['codename_c'],
-                    'created_at' => $asnDetail['addtime'] ?? null,
-                    'updated_at' => $asnDetail['edittime'],
+                    'asn_line_code' => (string)$asnDetail->asnlineno,
+                    'name' => $asnDetail->skudescrc,
+                    'sku' => $asnDetail->sku,
+                    'amount' => $asnDetail->receivedqty ?? 0,
+                    'quality' => $asnDetail->qualityStatus ?$asnDetail->qualityStatus->codename_c :' ',
+                    'status' => $status ? $status : $asnDetail->lineStatus->codename_c,
+                    'created_at' => $asnDetail->addtime ?? null,
+                    'updated_at' => $asnDetail->edittime ?? null,
                 ];
             }
         }

+ 0 - 8
app/Services/StoreService.php

@@ -50,15 +50,11 @@ Class StoreService
         /** @var OracleDocAsnHerderService $oracleDocAsnHerderService */
         $oracleDocAsnHerderService = app(OracleDocAsnHerderService::class);
         $last_time = $this->getAsnLastSyncAt($created_at, 'create');
-        dump('getWmsAsnOnStartDateCreate'.'start'.(string)Carbon::now());
         $asnHerders = $oracleDocAsnHerderService->getWmsAsnOnStartDateCreate($last_time);
-        dump('getWmsAsnOnStartDateCreate'.'end'.(string)Carbon::now());
         $last_time = $asnHerders->first()['addtime'];
         $last_records = $asnHerders->where('addtime', $last_time);
         if (!$asnHerders) return;
-        dump('createStore'.'start'.(string)Carbon::now());
         $this->createStore($asnHerders);
-        dump('createStore'.'end'.(string)Carbon::now());
         $this->deleteCacheKey($create_set, $create_keys);
         $this->setLastRecordsByRedis($create_key, $create_set, $create_keys, $last_records);
         $this->setAsnLastSyncAt($created_at, $last_time);
@@ -74,16 +70,12 @@ Class StoreService
         /** @var OracleDocAsnHerderService $oracleDocAsnHerderService */
         $oracleDocAsnHerderService = app(OracleDocAsnHerderService::class);
         $last_time = $this->getAsnLastSyncAt($updated_at, 'update');
-        dump('getWmsAsnOnStartDateEdit'.'start'.(string)Carbon::now());
         $asnHerders = $oracleDocAsnHerderService->getWmsAsnOnStartDateEdit($last_time);
-        dump('getWmsAsnOnStartDateEdit'.'end'.(string)Carbon::now());
         $last_time = $asnHerders->first()['edittime'];
         $last_records = $asnHerders->where('edittime', $last_time);
         if (!$asnHerders) return;
-        dump('updateStore'.'start'.(string)Carbon::now());
         $this->createStore($asnHerders);
         $this->updateStore($asnHerders);
-        dump('updateStore'.'end'.(string)Carbon::now());
         $this->deleteCacheKey($update_set, $update_keys);
         $this->setLastRecordsByRedis($update_key, $update_set, $update_keys, $last_records);
         $this->setAsnLastSyncAt($updated_at, $last_time);