Parcourir la source

库存记录,缓存架入库库位占用

Zhouzhendong il y a 4 ans
Parent
commit
508411caef

+ 1 - 3
app/Console/Commands/CheckCacheRackStorage.php

@@ -4,9 +4,7 @@ namespace App\Console\Commands;
 
 use App\Station;
 use App\StationTask;
-use App\StationTaskMaterialBox;
 use Illuminate\Console\Command;
-use Illuminate\Support\Collection;
 
 class CheckCacheRackStorage extends Command
 {
@@ -46,6 +44,6 @@ class CheckCacheRackStorage extends Command
                 ->where("status","!=","完成")->whereIn("station_id",Station::query()->select("id")->where("station_type_id",5)
                     ->whereNotNull("parent_id"))->groupBy("station_id"))
             ->get();
-        app("StorageService")->paddingCacheShelf($stations);
+        app("ForeignHaiRoboticsService")->paddingCacheShelf($stations);
     }
 }

+ 21 - 12
app/Http/Controllers/StorageController.php

@@ -4,12 +4,13 @@ namespace App\Http\Controllers;
 
 use App\Components\AsyncResponse;
 use App\MaterialBox;
-use App\Services\LogService;
 use App\Station;
 use App\StationTask;
 use App\StationTaskMaterialBox;
 use App\Storage;
+use App\StoreItem;
 use App\ValueStore;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
 
@@ -46,8 +47,7 @@ sql;
             $nums[] = (int)$asn->fmqty;
         }
         //flux上架
-        if ($result!==null)$this->fluxPA($asns[$result],$ide,$amount);
-        else{
+        if ($result===null){
             $result = $this->twoSum($nums,$amount);
             if (!$result)$this->error("无法匹配入库记录,检查您的上架数量");
             DB::connection("oracle")->transaction(function ()use($result,$asns,$ide){
@@ -55,13 +55,25 @@ sql;
                     $this->fluxPA($asns[$index],$ide,(int)$asns[$index]->fmqty);
                 }
             });
-        }
+        } else $this->fluxPA($asns[$result],$ide,$amount);
         //亮灯
         app("CacheShelfService")->_stationCacheLightOn($fromLocation,$ide);
+        //库存相关信息
+        /** @var Station|\stdClass $station */
+        $station = Station::query()->firstOrCreate(["code"=>$fromLocation],[
+            'name' => $fromLocation, 'code' => $fromLocation, 'station_type_id' => 5
+        ]);
+        $item = StoreItem::query()->whereHas("store",function (Builder $query){
+            $query->where("asn_code",request("asn"));
+        })->whereHas("commodity",function (Builder $query)use($barCode){
+            $query->whereHas("barcodes",function (Builder $query)use($barCode){
+                $query->where("code",$barCode);
+            });
+        })->first();
+        //库存记录
+        app("StorageService")->enterWarehouse($station->id, $box->id, $item->commodity_id ?? null, $amount);
         //建立入库任务
-        if (!app("ForeignHaiRoboticsService")->putWareHousing($fromLocation,'',$box->id))$this->error("错误库位或库位已被下达任务");
-        //占用库位 应在任务完成后释放
-        app("StorageService")->markOccupy($fromLocation);
+        if (!app("ForeignHaiRoboticsService")->putWareHousing($fromLocation,$box->id))$this->error("错误库位或库位已被下达任务");
         $this->success();
     }
 
@@ -213,12 +225,9 @@ sql;
         StationTask::query()->where("status","!=",'完成')->whereIn("station_id",$station)->update([
             "status" => "完成"
         ]);
-        //清理库存
-        Storage::query()->whereIn("station_id",$station)->update([
-            "status" => 0,"material_box_id" => null, "commodity_id" => null, "amount" => 0,
-        ]);
+
         //重新调取料箱
-        app("StorageService")->paddingCacheShelf($station->get());
+        app("ForeignHaiRoboticsService")->paddingCacheShelf($station->get());
         $this->success(["data"=>$data,"boxes"=>$boxes]);
     }
 }

+ 2 - 0
app/Providers/AppServiceProvider.php

@@ -119,6 +119,7 @@ use App\Services\OrderPackageExceptionTypeCountingRecordService;
 use App\Services\LogisticYDService;
 use App\Services\ForeignZhenCangService;
 use App\Services\StorageService;
+use App\Services\TaskTransactionService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -267,6 +268,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('StoreItemService',StoreItemService::class);
         app()->singleton('StoreService',StoreService::class);
         app()->singleton('SupplierService',SupplierService::class);
+        app()->singleton('TaskTransactionService',TaskTransactionService::class);
         app()->singleton('UnitService',UnitService::class);
         app()->singleton('UserOwnerGroupService',UserOwnerGroupService::class);
         app()->singleton('UserService',UserService::class);

+ 37 - 8
app/Services/ForeignHaiRoboticsService.php

@@ -8,7 +8,6 @@ use App\Exceptions\ErrorException;
 use App\Exceptions\Exception;
 use App\MaterialBox;
 use App\Station;
-use App\StationCacheShelfGrid;
 use App\StationTask;
 use App\StationTaskMaterialBox;
 use Carbon\Carbon;
@@ -16,7 +15,6 @@ use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Http;
 use App\Traits\ServiceAppAop;
-use Illuminate\Support\Facades\Log;
 
 
 class ForeignHaiRoboticsService
@@ -501,27 +499,58 @@ class ForeignHaiRoboticsService
      * put cache rack box to warehousing(将缓存架料箱入库)
      *
      * @param string $fromLocation
-     * @param string $toLocation
      * @param integer $boxId
      *
-     * @return bool
+     * @return int
      */
-    public function putWareHousing(string $fromLocation, string $toLocation, $boxId):bool
+    public function putWareHousing(string $fromLocation, $boxId):?int
     {
         $station = Station::query()->select("id")->where("code",$fromLocation)->first();
-        if (!$station)return false;
-        if (StationTask::query()->select("id")->where("status","!=",'完成')->where("station_id",$station->id)->first())return false;
+        if (!$station)return null;
+        if (StationTask::query()->select("id")->where("status","!=",'完成')->where("station_id",$station->id)->first())return null;
         /** @var \stdClass $task */
         $task = StationTask::query()->create([
             'status' => "待处理",
             'station_id' => $station->id,
         ]);
-        StationTaskMaterialBox::query()->create([
+        /** @var StationTaskMaterialBox|\stdClass $stmb */
+        $stmb = StationTaskMaterialBox::query()->create([
             'station_id' => $station->id,
             'material_box_id'=>$boxId,
             'status'=>"待处理",
             'type' => '放',
             'station_task_id' => $task->id,
         ]);
+        return $stmb->id;
+    }
+
+    /**
+     * 填充缓存架
+     *
+     * @param \Illuminate\Database\Eloquent\Collection $stations
+     */
+    public function paddingCacheShelf($stations)
+    {
+        $collection = new Collection();
+        $stationCollection = new Collection();
+        $blacklist = [];
+        foreach ($stations as $station){
+            $box = app("MaterialBoxService")->getAnEmptyBox($blacklist);
+            if (!$box)continue;
+            $task = StationTask::query()->create([
+                'status' => "待处理",
+                'station_id' => $station->id,
+            ]);
+            $collection->add(StationTaskMaterialBox::query()->create([
+                'station_id' => $station->id,
+                'material_box_id'=>$box->id,
+                'status'=>"待处理",
+                'type' => '取',
+                'station_task_id' => $task->id,
+            ]));
+            $stationCollection->add($station->code);
+            $blacklist[] = $box->id;
+        }
+        app("ForeignHaiRoboticsService")->fetchGroup_multiLocation($stationCollection,$collection,'','立架出至缓存架');
     }
 }

+ 4 - 0
app/Services/StationTaskMaterialBoxService.php

@@ -41,6 +41,8 @@ class StationTaskMaterialBoxService
     private $materialBoxService;
     /** @var CacheShelfService $cacheShelfService */
     private $cacheShelfService;
+    /** @var StorageService $storageService */
+    private $storageService;
     public function __construct(){
         $this->stationService=null;
         $this->stationTypeService=null;
@@ -151,6 +153,7 @@ class StationTaskMaterialBoxService
         $this->instant($this->stationTaskService,'StationTaskService');
         $this->instant($this->stationService,'StationService');
         $this->instant($this->cacheShelfService,'CacheShelfService');
+        $this->instant($this->storageService,'StorageService');
         try{
             LogService::log('海柔请求','markHasTaken1','');
             $taskType=$this->getServingTaskType($stationTaskMaterialBox);
@@ -176,6 +179,7 @@ class StationTaskMaterialBoxService
                     $this->cacheShelfService->putStationTaskMaterialBoxProcess($stationTaskMaterialBox);
                     $stationTaskMaterialBox->materialBox['status']='在立库';
                     $stationTaskMaterialBox->materialBox->update();
+                    $this->storageService->releaseOccupation($stationTaskMaterialBox); //释放库位占用
                     break;
                 case '入缓存架':
                     $stationTaskMaterialBox->materialBox['status']='在缓存架';

+ 36 - 8
app/Services/StorageService.php

@@ -8,6 +8,7 @@ use App\Traits\ServiceAppAop;
 use App\Storage;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\DB;
 
 class StorageService
 {
@@ -44,18 +45,45 @@ class StorageService
         }
         app("ForeignHaiRoboticsService")->fetchGroup_multiLocation($stationCollection,$collection,'','立架出至缓存架');
     }
+
     /**
-     * 标记指定库位为占用
-     *
-     * @param string $location
+     * 释放库位占用
      *
-     * @return int
+     * @param StationTaskMaterialBox|\stdClass $stationTaskMaterialBox
      */
-    public function markOccupy($location)
+    public function releaseOccupation($stationTaskMaterialBox)
     {
-        return Storage::query()->whereHas("station",function (Builder $query)use($location){
-            $query->where("code",$location);
-        })->update(["status"=>1]);
+        $stationTaskMaterialBox->loadMissing("station");
+        if ($stationTaskMaterialBox->station->station_type_id != 5)return;
+        $storage = Storage::query()->where("material_box_id",$stationTaskMaterialBox->material_box_id)->first();
+        if (!$storage)return;
+        $update = [];
+        if ($storage->status == 1)$update["status"] = 0;
+        if ($storage->station_id)$update["station_id"] = null;
+        if ($update)$storage->update($update);
     }
 
+    /**
+     * 入库
+     *
+     * @param integer $stationId
+     * @param integer $boxId
+     * @param integer $commodityId
+     * @param integer $amount
+     */
+    public function enterWarehouse($stationId, $boxId, $commodityId, $amount)
+    {
+        $storage = Storage::query()->where("material_box_id",$boxId)->first();
+        $obj = [
+            "station_id" => $stationId,
+            "material_box_id" => $boxId,
+            "commodity_id" => $commodityId,
+            "amount" => $amount,
+            "status" => 1,
+        ];
+        if ($storage){
+            $obj["amount"] = DB::raw("amount+{$amount}");
+            $storage->update($obj);
+        } else Storage::query()->create($obj);
+    }
 }

+ 0 - 41
database/migrations/2021_06_03_094123_create_task_transactions_table.php

@@ -1,41 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-class CreateTaskTransactionsTable extends Migration
-{
-    /**
-     * Run the migrations.
-     *
-     * @return void
-     */
-    public function up()
-    {
-        Schema::create('task_transactions', function (Blueprint $table) {
-            $table->id();
-            $table->string("source_table")->nullable()->comment("来源表");
-            $table->bigInteger("rel_id")->nullable()->index()->comment("关联ID");
-            $table->string("fm_box")->nullable()->comment("来源箱");
-            $table->string("to_box")->nullable()->comment("目标箱");
-            $table->bigInteger("task_id")->nullable()->index()->comment("任务ID");
-            $table->bigInteger("commodity_id")->nullable()->comment("商品ID");
-            $table->enum("type",["出库","入库","移库"])->comment("操作类型");
-            $table->integer("amount")->default(0)->comment("数量");
-            $table->tinyInteger("status")->default(0)->comment("事务状态");
-            $table->bigInteger("user_id")->nullable()->comment("操作人");
-            $table->timestamps();
-        });
-    }
-
-    /**
-     * Reverse the migrations.
-     *
-     * @return void
-     */
-    public function down()
-    {
-        Schema::dropIfExists('task_transactions');
-    }
-}

+ 2 - 8
resources/views/store/checkingReceive/show.blade.php

@@ -95,7 +95,7 @@
         <!-- pc >544 -->
         <div class="d-none d-sm-block">
             <table class="table table-striped table-sm text-nowrap table-hover mt-1 td-min-width-80" id="table">
-                <tr v-for="(storeCheckingReceiveItem,i) in storeCheckingReceiveItems" @click="selectedColor(i,$event)">
+                <tr v-for="(storeCheckingReceiveItem,i) in storeCheckingReceiveItems" @click="selectedColor(storeCheckingReceiveItem.id)" :class="selectTr==storeCheckingReceiveItem.id ? 'focusing' : ''">
                     <td><span>@{{ i+1 }}</span></td>
                     <td><span>@{{ storeCheckingReceiveItem.bin_number }}</span></td>
                     <td><span>@{{ storeCheckingReceiveItem.commodity_name }}</span></td>
@@ -282,14 +282,8 @@
             this.scanListening();
         },
         methods:{
-            selectedColor(id,e){
-                $('#headerParent tr[class=focusing]').removeClass('focusing')
-                if (id==this.selectTr){
-                    this.selectTr='';
-                    return;
-                }
+            selectedColor(id){
                 this.selectTr=id;
-                $(e.target).parent('tr').addClass('focusing')
             },
             //显示该条全部信息
             openAll(id){