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

添加--store_statuses表 store_types表,及对应的service,模型等

haozi 5 лет назад
Родитель
Сommit
45d585b2cb

+ 68 - 0
app/Console/Commands/WasSyncWmsAsnInformation.php

@@ -0,0 +1,68 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Services\LogService;
+use App\Services\OrderTrackingService;
+use App\Services\StoreService;
+use Illuminate\Console\Command;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\Auth;
+
+class WasSyncWmsAsnInformation extends Command
+{
+
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'WasSyncWmsAsnInformation';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '同步WMS的入库信息';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $this->WasSyncWmsAsn();
+    }
+
+    public function WasSyncWmsAsn(){
+
+        /** @var StoreService $storeService */
+        $storeService  = app('storeService');
+
+        $dataInterval = intval(data_get(config('sync'), 'asn_sync.interval')) * 60 + 5;
+
+        $startDate = Carbon::now()->subSeconds($dataInterval);
+
+        $syncStartDate = data_get(config('sync'), 'asn_sync.start_at');
+
+        if($syncStartDate ?? false){
+            $syncStartDate = Carbon::parse($syncStartDate);
+            if ($startDate->lt($syncStartDate)) {
+                $startDate = $syncStartDate;
+            }
+        }
+        $storeService->syncWmsAsnData($startDate);
+    }
+}

+ 2 - 0
app/Http/Controllers/RejectedController.php

@@ -10,9 +10,11 @@ use App\Rejected;
 use App\RejectedAnalyzeOwner;
 use App\RejectedBill;
 use App\Services\LogisticService;
+use App\Services\OracleDocAsnHerderService;
 use App\Services\OwnerService;
 use App\Services\QualityLabelService;
 use App\Services\RejectedService;
+use App\Services\StoreService;
 use Carbon\Carbon;
 use Exception;
 use Illuminate\Http\Request;

+ 5 - 0
app/Http/Controllers/StoreController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 use App\Depository;
 use App\Owner;
 use App\Services\LogService;
+use App\Services\OracleDocAsnHerderService;
 use App\Store;
 use App\StoreItems;
 use App\Warehouse;
@@ -31,7 +32,11 @@ class StoreController extends Controller
      */
     public function index()
     {
+
         if(!Gate::allows('入库管理-快速入库-查询')){ return redirect(url('/'));  }
+        dd(1111);
+        //        $startDate=Carbon::now()->subSeconds(86400);
+        //        $asnHeaders = app(StoreService::class)->syncWmsAsnData($startDate);
         $stores=Store::orderBy('id','DESC')->paginate(50);
         return view('store.fast.index',['stores'=>$stores]);
     }

+ 6 - 0
app/Providers/AppServiceProvider.php

@@ -13,6 +13,7 @@ use App\Services\InventoryCompareService;
 use App\Services\OracleBasSkuService;
 use App\Services\OracleDocAsnDetailService;
 use App\Services\OracleDOCOrderHeaderService;
+use App\Services\OracleDocAsnHerderService;
 use App\Services\OrderIssuePerformanceService;
 use App\Services\AllInventoryService;
 use App\Services\InventoryDailyLogService;
@@ -39,6 +40,8 @@ use App\Services\StoreCheckingReceiveItemService;
 use App\Services\StoreCheckingReceiveService;
 use App\Services\StoreItemService;
 use App\Services\StoreService;
+use App\Services\StoreStatusService;
+use App\Services\StoreTypeService;
 use App\Services\WarehouseService;
 use App\Services\WaybillFinancialService;
 use App\Services\WeighExceptedService;
@@ -62,6 +65,7 @@ class AppServiceProvider extends ServiceProvider
         //
         app()->singleton('orderIssuePerformanceService',OrderIssuePerformanceService::class);
         app()->singleton('inventoryCompareService',InventoryCompareService::class);
+        app()->singleton('oracleDocAsnHerderService',OracleDocAsnHerderService::class);
     }
 
     /**
@@ -121,6 +125,8 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('inventoryAccountMissionService',InventoryAccountMissionService::class);
         app()->singleton('processesContentService',ProcessesContentService::class);
         app()->singleton('storeService',StoreService::class);
+        app()->singleton('storeStatusService',StoreStatusService::class);
+        app()->singleton('storeTypeService',StoreTypeService::class);
         app()->singleton('warehouseService',WarehouseService::class);
         app()->singleton('storeItemService',StoreItemService::class);
 

+ 1 - 1
app/Services/InventoryAccountService.php

@@ -424,7 +424,7 @@ class InventoryAccountService
         $inventoryAccountMission->difference_amount=$count;//盘点差异
         $inventoryAccountMission->checked='是';
         $inventoryAccountMission->save();
-        Controller::logS(__METHOD__,"".__FUNCTION__,json_encode($inventoryId));
+        Controller::logS(__METHOD__,"增加系统之外的盘点记录".__FUNCTION__,json_encode($inventoryAccountMission));
         if ($inventoryAccountMission){
             $inventoryAccountMission->createSignStockInventoryPersons();
             Controller::logS(__METHOD__,"增加盘点人".__FUNCTION__,json_encode($inventoryId));

+ 5 - 5
app/Services/InventoryCompareService.php

@@ -106,10 +106,10 @@ class InventoryCompareService
             $wmsInventoryCompareZp=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->where('质量状态','ZP')->first();
             $wmsInventoryCompareCc=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->where('质量状态','CC')->first();
             $wmsInventoryCompareDj=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->where('质量状态','DJ')->first();
-            //$unknownQualityStatus=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->whereNotIn('质量状态',['DJ','CC','ZP']);
-            //if (!$wmsInventoryCompareZp&&!$wmsInventoryCompareCc&&!$wmsInventoryCompareDj&&$unknownQualityStatus->isEmpty()){
-                //$inventoryCompare=$this->createInventoryCompare_underImport($sku, $custom_location, $amount, $owner_id,$owner_name);
-            //}
+            $unknownQualityStatus=$query->where('属性仓',$custom_location)->where('产品编码',$sku)->whereNotIn('质量状态',['DJ','CC','ZP']);
+            if (!$wmsInventoryCompareZp&&!$wmsInventoryCompareCc&&!$wmsInventoryCompareDj&&$unknownQualityStatus->isEmpty()){
+                $inventoryCompare=$this->createInventoryCompare_underImport($sku, $custom_location, $amount, $owner_id,$owner_name);
+            }
             $creatingMissionCode = $this->getCreatingMissionCode($owner_name);
             $commodityId=Commodity::where('sku',$sku)->where('owner_id',$owner_id)->value('id');
             if ($wmsInventoryCompareZp||$wmsInventoryCompareDj) {
@@ -140,7 +140,7 @@ class InventoryCompareService
                 ];
                 array_push($wasInventoryCompares,$wasInventoryCompareCC);
             }
-            //if($unknownQualityStatus->isNotEmpty())return null;
+            if($unknownQualityStatus->isNotEmpty())return null;
         }
         $inventoryCompares=DB::table('inventory_compares')->insert($wasInventoryCompares);
         if (!$inventoryCompares)return null;

+ 23 - 0
app/Services/OracleDocAsnHerderService.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Services;
+
+use App\OracleDOCASNHeader;
+
+Class OracleDocAsnHerderService
+{
+    public function getWmsAsnOnStartDateCreate($startDate){
+        return OracleDOCASNHeader::query()
+            ->where('addTime','>=',$startDate)
+            ->get();
+    }
+
+    public function getWmsAsnOnStartDateEdit($startDate){
+
+        return OracleDOCASNHeader::query()
+            ->where('EditTime','>=',$startDate)
+            ->whereColumn('EditTime','<>','addTime')
+            ->get();
+    }
+
+}

+ 2 - 2
app/Services/OwnerService.php

@@ -84,10 +84,10 @@ Class OwnerService
         $customerIds = array_diff($customerIds,[null,'','*']);
         $owners = Owner::query()->whereIn('code',data_get($orderHeaders,'*.customerid'))->get();
 
-        if($owners->count() < $customerIds){
+        if($owners->count() < count($customerIds)){
             $customerIds = array_diff($customerIds,data_get($owners,'*.code'));
             $owner_list = $this->createByWmsCustomerIds($customerIds);
-            $owners->concat($owner_list);
+            $owners=$owners->concat($owner_list);
         }
         return $owners;
     }

+ 54 - 5
app/Services/StoreService.php

@@ -1,13 +1,62 @@
-<?php 
+<?php
 
-namespace App\Services; 
+namespace App\Services;
 
 use App\Store;
 
 Class StoreService
-{ 
-    public function create(array $params){
+{
+    public function create(array $params)
+    {
         return Store::query()->create($params);
     }
 
-}
+    public function syncWmsAsnData($startDate)
+    {
+
+        /** @var OwnerService $ownerService */
+        $ownerService = app(OwnerService::class);
+        $this->storeCreateByWms($startDate);
+    }
+
+    public function storeCreateByWms($startDate)
+    {
+        /** @var OracleDocAsnHerderService $oracleDocAsnHerderService */
+        $oracleDocAsnHerderService = app(OracleDocAsnHerderService::class);
+        $asnHerders = $oracleDocAsnHerderService->getWmsAsnOnStartDateCreate($startDate);
+        $this->createStore($asnHerders);
+    }
+
+    public function storeUpdateByWms($startDate)
+    {
+        /** @var OracleDocAsnHerderService $oracleDocAsnHerderService */
+        $oracleDocAsnHerderService = app(OracleDocAsnHerderService::class);
+        $asnHerders = $oracleDocAsnHerderService->getWmsAsnOnStartDateEdit($startDate);
+        $this->updateStore($asnHerders);
+    }
+
+    public function createStore($asnHerders)
+    {
+        if ($asnHerders->isEmpty())return null;
+        /**
+         * @var OwnerService $ownerService
+         * @var WarehouseService $wareHouseService
+         * @var StoreStatusService $storeStatusService
+         * @var StoreTypeService $storeTypeService
+         */
+        $ownerService = app(OwnerService::class);
+        $owners=$ownerService->getByWmsOrders($asnHerders);
+        $wareHouseService=app(WarehouseService::class);
+        $warehouses=$wareHouseService->getByWms($asnHerders);
+        $storeStatusService=app(StoreStatusService::class);
+        $storeStatuses=$storeStatusService->getByWms($asnHerders);
+        $storeTypeService=app(StoreTypeService::class);
+        $storeTypes=$storeTypeService->getByWms($asnHerders);
+        dd($storeTypes);
+    }
+
+    public function updateStore($asnHerders)
+    {
+
+    }
+}

+ 58 - 0
app/Services/StoreStatusService.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace App\Services;
+
+use App\OracleBasCode;
+use App\StoreStatus;
+use Carbon\Carbon;
+
+Class StoreStatusService
+{
+    public function getByWms($asnHerders)
+    {
+        $statuses = array_unique(data_get($asnHerders, '*.asnstatus'));
+        $statuses = array_diff($statuses, [null, '', '*']);
+
+        $storeStatuses = StoreStatus::query()->whereIn('code', $statuses)->get();
+        if ($storeStatuses->count() < count($statuses)) {
+            $statuses = array_diff($statuses, data_get($storeStatuses, '*.code'));
+            $storeStatus_list = $this->createStoreStatusByWms($statuses);
+            $storeStatuses=$storeStatuses->concat($storeStatus_list);
+        }
+        return $storeStatuses;
+    }
+
+    public function createStoreStatusByWms($codes){
+        if(!$codes) {return [];}
+        $basCodes = OracleBasCode::query()
+            ->where('codeid','ASN_STS')
+            ->whereIn('code', $codes)
+            ->get();
+
+        $insert_params = [];
+        $created_at = Carbon::now()->format('Y-m-d H:i:s');
+        foreach ($basCodes as $item) {
+            $insert_params[] = [
+                'code' => $item->code,
+                'name' => $item->codename_c,
+                'created_at' => $created_at,
+            ];
+        }
+
+        try {
+            if (count($insert_params) > 0) {
+                $this->insert($insert_params);
+                LogService::log(__METHOD__, __FUNCTION__, '批量创建 storeStatus success' . count($insert_params) . json_encode($insert_params) );
+            }
+        } catch (\Exception $e) {
+            LogService::log(__METHOD__, __FUNCTION__, '批量创建 storeStatus error' . json_encode($insert_params) . '||' . $e->getMessage() . '||' . $e->getTraceAsString());
+        } finally {
+            return StoreStatus::query()->whereIn('code', $codes)->get();
+        }
+    }
+
+    public function insert($fillables){
+        return StoreStatus::query()->insert($fillables);
+    }
+
+}

+ 58 - 0
app/Services/StoreTypeService.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace App\Services;
+
+use App\OracleBasCode;
+use App\StoreType;
+use Carbon\Carbon;
+
+Class StoreTypeService
+{
+    public function getByWms($asnHerders)
+    {
+        $types = array_unique(data_get($asnHerders, '*.asntype'));
+        $types = array_diff($types, [null, '', '*']);
+
+        $storeTypes = StoreType::query()->whereIn('code', $types)->get();
+        if ($storeTypes->count() < count($types)) {
+            $types = array_diff($types, data_get($storeTypes, '*.code'));
+            $storeType_list = $this->createStoreTypeByWms($types);
+            $storeTypes=$storeTypes->concat($storeType_list);
+        }
+        return $storeTypes;
+    }
+
+    public function createStoreTypeByWms($codes){
+        if(!$codes) {return [];}
+        $basCodes = OracleBasCode::query()
+            ->where('codeid','ASN_TYP')
+            ->whereIn('code', $codes)
+            ->get();
+
+        $insert_params = [];
+        $created_at = Carbon::now()->format('Y-m-d H:i:s');
+        foreach ($basCodes as $item) {
+            $insert_params[] = [
+                'code' => $item->code,
+                'name' => $item->codename_c,
+                'created_at' => $created_at,
+            ];
+        }
+
+        try {
+            if (count($insert_params) > 0) {
+                $this->insert($insert_params);
+                LogService::log(__METHOD__, __FUNCTION__, '批量创建 storeType success' . count($insert_params) . json_encode($insert_params) );
+            }
+        } catch (\Exception $e) {
+            LogService::log(__METHOD__, __FUNCTION__, '批量创建 storeType error' . json_encode($insert_params) . '||' . $e->getMessage() . '||' . $e->getTraceAsString());
+        } finally {
+            return StoreType::query()->whereIn('code', $codes)->get();
+        }
+    }
+
+    public function insert($fillables){
+        return StoreType::query()->insert($fillables);
+    }
+
+}

+ 50 - 6
app/Services/WarehouseService.php

@@ -1,14 +1,58 @@
-<?php 
+<?php
 
-namespace App\Services; 
+namespace App\Services;
 
+use App\Owner;
 use App\Warehouse;
+use Carbon\Carbon;
 
 Class WarehouseService
-{ 
-    public function firstOrCreate(array $params, array $values = null){
-        if ($values)return Warehouse::query()->firstOrCreate($params,$values);
+{
+    public function firstOrCreate(array $params, array $values = null)
+    {
+        if ($values) return Warehouse::query()->firstOrCreate($params, $values);
         return Warehouse::query()->firstOrCreate($params);
     }
 
-}
+    public function getByWms($asnHerders)
+    {
+        $warehouseids = array_unique(data_get($asnHerders, '*.warehouseid'));
+        $warehouseids = array_diff($warehouseids, [null, '', '*']);
+        $warehouses = Warehouse::query()->whereIn('code', $warehouseids)->get();
+        if ($warehouses->count() < count($warehouseids)) {
+            $warehouseids = array_diff($warehouseids, data_get($warehouses, '*.code'));
+            $warehouse_list = $this->createWarehouseByWms($warehouseids);
+            $warehouses=$warehouses->concat($warehouse_list);
+        }
+        return $warehouses;
+    }
+
+    public function createWarehouseByWms($codes)
+    {
+        if(!$codes) {return [];}
+        $insert_params = [];
+        $created_at = Carbon::now()->format('Y-m-d H:i:s');
+        foreach ($codes as $item) {
+            $insert_params[] = [
+                'code' => $item,
+                'name' => $item,
+                'created_at' => $created_at,
+            ];
+        }
+
+        try {
+            if (count($insert_params) > 0) {
+                $this->insert($insert_params);
+                LogService::log(__METHOD__, __FUNCTION__, '批量创建 warehouse success' . count($insert_params) . json_encode($insert_params) );
+            }
+        } catch (\Exception $e) {
+            LogService::log(__METHOD__, __FUNCTION__, '批量创建 warehouse error' . json_encode($insert_params) . '||' . $e->getMessage() . '||' . $e->getTraceAsString());
+        } finally {
+            return Warehouse::query()->whereIn('code', $codes)->get();
+        }
+    }
+    public function insert($fillables){
+        return Warehouse::query()->insert($fillables);
+    }
+
+}

+ 15 - 0
app/StoreStatus.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use App\Traits\ModelTimeFormat;
+
+class StoreStatus extends Model
+{
+    use ModelTimeFormat;
+    protected $fillable=[
+        'code','name'
+    ];
+}

+ 15 - 0
app/StoreType.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use App\Traits\ModelTimeFormat;
+
+class StoreType extends Model
+{
+    use ModelTimeFormat;
+    protected $fillable=[
+        'code','name'
+    ];
+}

+ 4 - 0
config/sync.php

@@ -4,4 +4,8 @@ return [
         'interval' => 1,   // 时间以分为单位
         'start_at'=> '',    // 开始同步WMS的时间  时间格式: yyyy-MM-dd HH:mm:ss 如 2020-09-05 13:15:16
     ],
+    'asn_sync' => [
+        'interval' => 1,   // 时间以分为单位
+        'start_at'=> '',    // 开始同步WMS的时间  时间格式: yyyy-MM-dd HH:mm:ss 如 2020-09-05 13:15:16
+    ],
 ];

+ 34 - 0
database/migrations/2020_10_29_110927_add_stores_volumn.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddStoresVolumn extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('stores', function (Blueprint $table) {
+            $table->integer('store_type_id')->nullable()->index()->comment('外键asn入库类型');
+            $table->integer('store_status_id')->nullable()->index()->comment('外键asn入库状态');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('stores', function (Blueprint $table) {
+            $table->dropColumn('store_type_id');
+            $table->dropColumn('store_status_id');
+        });
+    }
+}

+ 33 - 0
database/migrations/2020_10_29_111537_create_store_types.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateStoreTypes extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('store_types', function (Blueprint $table) {
+            $table->id();
+            $table->string('code')->comment('代码');
+            $table->string('name')->comment('asn类型');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('store_types');
+    }
+}

+ 33 - 0
database/migrations/2020_10_29_172949_create_store_statuses.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateStoreStatuses extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('store_statuses', function (Blueprint $table) {
+            $table->id();
+            $table->string('code')->comment('代码');
+            $table->string('name')->comment('asn状态');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('store_statuses');
+    }
+}

+ 3 - 2
package-lock.json

@@ -6192,7 +6192,8 @@
         },
         "minimist": {
             "version": "1.2.0",
-            "resolved": "",
+            "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
+            "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
             "dev": true
         },
         "mississippi": {
@@ -8767,7 +8768,7 @@
         },
         "socket.io-client": {
             "version": "2.3.0",
-            "resolved": "https://registry.npm.taobao.org/socket.io-client/download/socket.io-client-2.3.0.tgz",
+            "resolved": "https://registry.npm.taobao.org/socket.io-client/download/socket.io-client-2.3.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsocket.io-client%2Fdownload%2Fsocket.io-client-2.3.0.tgz",
             "integrity": "sha1-FNW6LgC5vNFFrkQ6uWs/hsvMG7Q=",
             "requires": {
                 "backo2": "1.0.2",

+ 4 - 4
public/js/app.js

@@ -2330,7 +2330,7 @@ function fromByteArray (uint8) {
 var BlobBuilder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
   typeof WebKitBlobBuilder !== 'undefined' ? WebKitBlobBuilder :
   typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
-  typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder :
+  typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : 
   false;
 
 /**
@@ -86472,8 +86472,8 @@ module.exports = tempTip;
 /*! no static exports found */
 /***/ (function(module, exports, __webpack_require__) {
 
-__webpack_require__(/*! D:\Reald\desktop\BsWAS\src\resources\js\app.js */"./resources/js/app.js");
-module.exports = __webpack_require__(/*! D:\Reald\desktop\BsWAS\src\resources\sass\app.scss */"./resources/sass/app.scss");
+__webpack_require__(/*! D:\wamp64\www\bswas\resources\js\app.js */"./resources/js/app.js");
+module.exports = __webpack_require__(/*! D:\wamp64\www\bswas\resources\sass\app.scss */"./resources/sass/app.scss");
 
 
 /***/ }),
@@ -86489,4 +86489,4 @@ module.exports = __webpack_require__(/*! D:\Reald\desktop\BsWAS\src\resources\sa
 
 /***/ })
 
-/******/ });
+/******/ });