Zhouzhendong 5 лет назад
Родитель
Сommit
8c7e10ea9b

+ 5 - 1
app/Batch.php

@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model;
 class Batch extends Model
 {
     protected $fillable = [
-        'id','code','type', 'wms_type', 'status', 'wms_status', 'wms_created_at',"remark",
+        'id','code','type', 'wms_type', 'status', 'wms_status', 'wms_created_at',"remark","owner_id",
     ];
     public function orders(){
         return $this->hasMany('App\Order','batch_id','id');
@@ -33,5 +33,9 @@ class Batch extends Model
         });
         return parent::delete(); // TODO: Change the autogenerated stub
     }
+    public function owner()
+    {
+        return $this->hasOne(Owner::class,"id","owner_id");
+    }
 
 }

+ 2 - 0
app/Console/Commands/SyncBatchTask.php

@@ -58,12 +58,14 @@ class SyncBatchTask extends Command
                 ];
                 continue;
             }
+            $owner = app("OwnerService")->codeGetOwner($wave->customerid);
             $insert[] = [
                 "code" => $wave->waveno,
                 "status" => $status,
                 "remark"=>$wave->descr,
                 "created_at"=>$wave->addtime,
                 "updated_at"=>$wave->edittime,
+                "owner_id"=>$owner->id,
             ];
         }
 

+ 7 - 0
app/Services/OwnerService.php

@@ -216,4 +216,11 @@ Class OwnerService
         return $builder;
     }
 
+    public function codeGetOwner($code)
+    {
+        return app(CacheService::class)->getOrExecute("owner_".$code,function ()use($code){
+            return Owner::query()->firstOrCreate(["code"=>$code],["code"=>$code,"name"=>$code]);
+        });
+    }
+
 }

+ 2 - 0
database/migrations/2020_11_30_133112_save_value_store_data_date.php

@@ -16,6 +16,7 @@ class SaveValueStoreDataDate extends Migration
         \App\ValueStore::query()->firstOrCreate(["name"=>"wave_last_sync_date"]);
         Schema::table("batches",function (Blueprint $table){
             $table->string("remark")->nullable()->comment("中文描述");
+            $table->string("owner_id")->index()->nullable()->comment("外键货主");
         });
     }
 
@@ -29,6 +30,7 @@ class SaveValueStoreDataDate extends Migration
         \App\ValueStore::query()->where("name","wave_last_sync_date")->delete();
         Schema::table("batches",function (Blueprint $table){
             $table->dropColumn("remark");
+            $table->dropColumn("owner_id");
         });
     }
 }