Browse Source

立架入缓存架(出库任务下达)

Zhouzhendong 4 years ago
parent
commit
f9e6f3ca79

+ 67 - 0
app/Console/Commands/CheckCacheRackStorage.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Station;
+use App\StationTask;
+use App\StationTaskMaterialBox;
+use Illuminate\Console\Command;
+use Illuminate\Database\Eloquent\Collection;
+
+class CheckCacheRackStorage extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'check:cacheRack';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'check cache rack storage info';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     */
+    public function handle()
+    {
+        $stations = Station::query()->select("id","code")->where("station_type_id",5)
+            ->whereNotNull("parent_id")
+            ->whereNotIn("id",StationTask::query()->select("station_id")
+                ->where("status","!=","完成")->whereIn("station_id",Station::query()->select("id")->where("station_type_id",5)
+                    ->whereNotNull("parent_id"))->groupBy("station_id"))
+            ->get();
+        foreach ($stations as $station){
+            $box = app("MaterialBoxService")->getAnEmptyBox();
+            if (!$box)continue;
+            $task = StationTask::query()->create([
+                'status' => "待处理",
+                'station_id' => $station->id,
+            ]);
+            $collection = new Collection();
+            $collection->append(StationTaskMaterialBox::query()->create([
+                'station_id' => $station->id,
+                'material_box_id'=>$box->id,
+                'status'=>"待处理",
+                'type' => '取',
+                'station_task_id' => $task->id,
+            ]));
+            app("ForeignHaiRoboticsService")->fetchGroup($station->code,$collection,'','立架出至缓存架');
+        }
+    }
+}

+ 1 - 0
app/Console/Kernel.php

@@ -78,6 +78,7 @@ class  Kernel extends ConsoleKernel
         $schedule->command('create:weightStatistic')->dailyAt("00:30");
         $schedule->command('sync:carrier')->hourlyAt(1);
         $schedule->command('createProcurementTotalBill')->monthlyOn(1);
+        $schedule->command('check:cacheRack')->everyMinute();
     }
 
     /**

+ 87 - 0
app/Http/Controllers/StorageController.php

@@ -0,0 +1,87 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Components\AsyncResponse;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\DB;
+
+class StorageController extends Controller
+{
+    use AsyncResponse;
+
+    public function putShelf()
+    {
+        $asn = \request("asn");
+        $ide = \request("ide");
+        $barCode = \request("barCode");
+        $amount = \request("amount");
+        if (!$asn || !$ide || !$barCode || !$amount)$this->error("信息不完整");
+        $sql = <<<sql
+SELECT * FROM DOC_ASN_DETAILS LEFT JOIN BAS_SKU ON DOC_ASN_DETAILS.CUSTOMERID = BAS_SKU.CUSTOMERID AND DOC_ASN_DETAILS.SKU = BAS_SKU.SKU
+WHERE asnno = ? AND (ALTERNATE_SKU1 = ? OR ALTERNATE_SKU2 = ?)
+sql;
+        $asn = DB::connection("oracle")->selectOne(DB::raw($sql),[$asn,$barCode,$barCode]);
+        if (!$asn || $asn->receivedqty_each<$amount)$this->error("ASN不存在或数量异常");
+        $sql = <<<sql
+SELECT fmlotnum,fmlocation,toid FROM ACT_TRANSACTION_LOG WHERE transactiontype = 'IN' AND fmcustomerid = ? AND fmsku = ? AND docno = ? AND doclineno = ? AND doctype = 'ASN' AND pa_flag = 'Y'
+sql;
+        $act = DB::connection("oracle")->selectOne(DB::raw($sql),[$asn->customerid,$asn->sku,$asn->asnno,$asn->asnlineno]);
+        if (!$act)$this->error("没有入库记录");
+        $sql = <<<sql
+SELECT * FROM inv_lot_loc_id  WHERE lotnum = ? AND traceid = ? AND customerid= ?  and sku = ?
+sql;
+        $inv = DB::connection("oracle")->select(DB::raw($sql),[$act->fmlotnum,$act->toid,$asn->customerid,$asn->sku]);
+        if (!$inv)$this->error("余量与入库不符");
+        DB::transaction(function ()use($inv,$amount,$ide,$asn,$act){
+            $db = DB::connection("oracle");
+            $qty = $amount;
+            foreach ($inv as $in){
+                if ($qty==0)break;
+                if ($in->qty > $qty){
+                    $db->update(DB::raw("update inv_lot_loc_id set qty = qty-?,qtymvout = qty-? where lotnum = ? and locationid = ? and traceid = ?"),[
+                        $qty,$qty,$in->lotnum,$in->locationid,$in->traceid
+                    ]);//TODO 遗留问题:对应生成分配库位上架数量未被变更
+                    $in->qty = $in->qty-$qty;
+                    $qty = 0;
+                }else{
+                    $db->delete(DB::raw("DELETE FROM inv_lot_loc_id WHERE lotnum = ? and locationid = ? and traceid = ?"),[
+                        $in->lotnum,$in->locationid,$in->traceid
+                    ]);
+                    $qty = $qty-$in->qty;
+                }
+            }
+            if ($qty!=0){
+                $db->rollBack();
+                $this->error("上架数量与入库数量不符");
+            }
+            $db->delete(DB::raw("DELETE FROM inv_lot_loc_id WHERE lotnum = ? AND traceid = ? AND traceid != '*'"),[
+                $inv[0]->lotnum,$inv[0]->traceid
+            ]);
+            $inv = $db->selectOne(DB::raw("SELECT * FROM inv_lot_loc_id WHERE lotnum = ? AND locationid = ? AND customerid = ? AND sku = ? AND traceid = '*' FOR UPDATE"),[
+                $inv[0]->lotnum,$ide,$inv[0]->customerid,$inv[0]->sku
+            ]);
+            $who = 'WAS'.(Auth::user() ? '-'.Auth::user()["name"] : '');
+            if ($inv)$db->update(DB::raw("UPDATE inv_lot_loc_id SET qty = qty+? WHERE lotnum = ? AND locationid = ? AND traceid = '*'"),[
+                (int)$amount,$inv[0]->lotnum,$ide
+            ]);
+            else $db->insert(DB::raw("INSERT INTO inv_lot_loc_id VALUES(?,?,'*',?,?,?,0,0,0,0,0,0,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,0,0,0,0,0,'*',0,null)"),[
+                $inv[0]->lotnum,$ide,$inv[0]->customerid,$inv[0]->sku,$amount,date("Y-m-d H:i:s"),$who,
+                date("Y-m-d H:i:s"),$who
+            ]);
+            $sql = <<<sql
+INSERT INTO ACT_TRANSACTION_LOG VALUES(?,'PA',?,?,?,?,'ASN',?,?,?,?,?,?,?,?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')),?,
+TO_DATE(?,'yyyy-mm-dd hh24:mi:ss')),?,0,0,0,0,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?,?,null,null,null,'*',?,?,?,?,?,?,?,
+?,?,?,?,?,'N',null,?,?,?,?,?,?,?,null,null)
+sql;
+            $db->insert(DB::raw($sql),[
+                'WA'.date('ymdHis').substr(\request("asn"),-2).rand(0,9),$asn->customerid,$asn->sku,
+                $asn->asnno,$asn->asnlineno,$inv[0]->lotnum,$act->fmlocation,$act->toid,$asn->packid,$asn->uom,$amount,$amount,$act->status,date("Y-m-d H:i:s"),$who,
+                date("Y-m-d H:i:s"),$who,date("Y-m-d H:i:s"),$asn->customerid,$asn->sku,$ide,$who,$asn->packid,$asn->uom,$amount,$amount,$inv[0]->lotnum,
+                'QC_TASKID',$act->qc_sequence,$act->qc_flag,'*',$act->pa_sequence,$act->warehouseid,$act->userdefine1,$act->userdefine2,
+                $act->userdefine3,$act->userdefine4,$act->userdefine5,$act->edisendflag
+            ]);
+        });
+        //成功后应去修改ASN状态及数量
+    }
+}

+ 39 - 8
app/Http/Controllers/TestController.php

@@ -177,17 +177,48 @@ class TestController extends Controller
     {
         return call_user_func([$this, $method], $request);
     }
-    public function test()
+    public function createCacheRack()
     {
-        Owner::query()->where("id",360)->update([
-            "relevance" => [0,1],
-        ]);
-        $customers = DB::connection("oracle")->select(DB::raw("select * from BAS_CUSTOMER where CUSTOMER_TYPE = 'CA'"));
-        foreach ($customers as $customer){
-            $l = Logistic::query()->where("code",$customer->customerid)->orWhere("name",$customer->descr_c)->first();
-            if ($l)$l->update(["english_name"=>$customer->descr_e]);
+        $stations = [
+            "HAIB1-01-02","HAIB1-01-03",
+            "HAIB1-02-01","HAIB1-02-03",
+            "HAIB1-03-01","HAIB1-03-02","HAIB1-03-03"
+        ];
+        foreach ($stations as $station){
+            Station::query()->create([
+                "parent_id" => 6,
+                "name" => $station,
+                "code" => $station,
+                "station_type_id" => 5,
+            ]);
         }
         dd("OK");
+    }
+    public function test()
+    {
+        $stations = Station::query()->select("id","code")->where("station_type_id",5)
+            ->whereNotNull("parent_id")
+            ->whereNotIn("id",StationTask::query()->select("station_id")
+                ->where("status","!=","完成")->whereIn("station_id",Station::query()->select("id")->where("station_type_id",5)
+                    ->whereNotNull("parent_id"))->groupBy("station_id"))
+            ->get();
+        foreach ($stations as $station){
+            $box = app("MaterialBoxService")->getAnEmptyBox();
+            if (!$box)continue;
+            $task = StationTask::query()->create([
+                'status' => "待处理",
+                'station_id' => $station->id,
+            ]);
+            $collection = new \Illuminate\Database\Eloquent\Collection();
+            $collection->append(StationTaskMaterialBox::query()->create([
+                'station_id' => $station->id,
+                'material_box_id'=>$box->id,
+                'status'=>"待处理",
+                'type' => '取',
+                'station_task_id' => $task->id,
+            ]));
+        }
+        dd(1);
         $asnno = "ASN2105141388";
         $query = DB::raw("SELECT b.ALTERNATE_SKU1,h.WAREHOUSEID,h.asnno,d.ASNLINENO,d.SKUDESCRC,h.CUSTOMERID,d.SKU,d.PACKID,d.RECEIVEDQTY_EACH,d.EXPECTEDQTY_EACH,d.LOTATT01,d.LOTATT02,d.lotatt04,".
             "d.lotatt05,d.lotatt08,d.USERDEFINE1,d.USERDEFINE2,d.USERDEFINE3,d.USERDEFINE4,d.USERDEFINE5,d.RECEIVINGLOCATION FROM DOC_ASN_DETAILS d ".

+ 1 - 3
app/Package.php

@@ -103,9 +103,7 @@ class Package extends Model
                 "created_at"=>$now,
             ]);
         }
-        DB::transaction(function ()use($packages){
-            Package::query()->insert($packages);
-        });
+        Package::query()->insert($packages);
     }
     public function unifyThisMeasureUnderSameBatch(){
         $this->fetchPaperBox();

+ 2 - 2
app/Services/ForeignHaiRoboticsService.php

@@ -87,13 +87,13 @@ class ForeignHaiRoboticsService
         ]];
     }
 
-    public function fetchGroup($toLocation, Collection $taskMaterialBoxes, $groupIdPrefix=''): bool
+    public function fetchGroup($toLocation, Collection $taskMaterialBoxes, $groupIdPrefix='',$mode='立架出至输送线'): bool
     {
         LogService::log(__METHOD__,'runMany','波次任务分配6.r5f0:');
         LogService::log(__METHOD__,'runMany','波次任务分配6.r5f1:'.json_encode($toLocation).json_encode($taskMaterialBoxes).json_encode($groupIdPrefix));
         $dataToPost=$this->makeJson_move(
             $taskMaterialBoxes,
-            '立架出至输送线',
+            $mode,
             '',
             $toLocation??'',
             $groupIdPrefix

+ 34 - 0
app/Services/MaterialBoxService.php

@@ -8,6 +8,7 @@ use App\MaterialBox;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Cache;
 use App\Traits\ServiceAppAop;
+use Illuminate\Support\Facades\DB;
 
 
 class MaterialBoxService
@@ -16,4 +17,37 @@ class MaterialBoxService
     protected $modelClass=MaterialBox::class;
 
 
+    /**
+     * 获取一个空料箱
+     *
+     * @return MaterialBox|null
+     */
+    public function getAnEmptyBox()
+    {
+        $id = 0;
+        while (true){
+            $boxes = MaterialBox::query()->select('id',"code")->where("id",">",$id)->where("code","like","IDE%")
+                ->where("status",4)->limit(10)->orderBy("id")->get();
+            if ($boxes->count()==0)break;
+            $ides = [];
+            $str = "(";
+            for ($i=0;$i<count($boxes)-1;$i++){
+                $str .= "'".$boxes[$i]->code."',";
+                $ides[$boxes[$i]->code] = $boxes[$i];
+            }
+            $box = $boxes[count($boxes)-1];
+            $ides[$box->code] = $box;
+            $str .= "'".$box->code."')";
+            $id = $box->id;
+            $sql = <<<sql
+SELECT LOCATIONID,SUM(QTY+QTYPA) qty FROM INV_LOT_LOC_ID WHERE LOCATIONID IN {$str} GROUP BY LOCATIONID
+sql;
+            foreach (DB::connection("oracle")->select(DB::raw($sql)) as $item){
+                if ((int)$item->qty==0)return $ides[$item->locationid];
+                unset($ides[$item->locationid]);
+            }
+            if ($ides)return current($ides);
+        }
+        return null;
+    }
 }

+ 1 - 1
app/StationTaskMaterialBox.php

@@ -13,7 +13,7 @@ class StationTaskMaterialBox extends Model
 {
     use ModelLogChanging;
 
-    protected $fillable=['station_id','material_box_id','status'];
+    protected $fillable=['station_id','material_box_id','status','type','station_task_batch_id','station_task_id'];
 
     function materialBox(): HasOne
     {

+ 27 - 0
app/Storage.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+
+class Storage extends Model
+{
+    use ModelLogChanging;
+
+    protected $fillable = [
+        "material_box_id",
+        "commodity_id",
+        "amount"
+    ];
+
+    public function materialBox()
+    {   //料箱
+        $this->belongsTo(MaterialBox::class);
+    }
+    public function commodity()
+    {   //商品
+        $this->belongsTo(Commodity::class);
+    }
+}

+ 34 - 0
database/migrations/2021_05_19_172118_create_storages_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateStoragesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('storages', function (Blueprint $table) {
+            $table->id();
+            $table->bigInteger("material_box_id")->index()->comment("外键料箱");
+            $table->bigInteger("commodity_id")->nullable()->index()->comment("外键商品");
+            $table->integer("amount")->default(0)->comment("数量");
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('storages');
+    }
+}

+ 2 - 1
resources/views/store/inStorage/cacheRackStorage.blade.php

@@ -32,7 +32,7 @@
                         <input type="text" class="form-control rounded col-sm-5 col-8 ml-sm-1 ml-2" :class="errors.barCode ? 'is-invalid' : ''" id="barCode" @blur="codeBlur()" @keydown.enter="checkInfo()" v-model="info.barCode">
                         <div class="input-group-append mt-sm-0 mt-4">
                             <span class="input-group-text d-none d-sm-block">@数量</span>
-                            <label class="d-sm-none col-4 text-right">数量:</label>
+                            <label for="amount" class="d-sm-none col-4 text-right">数量:</label>
                             <span class="input-group-text p-0 border-0">
                                 <input class="form-control" type="number" :class="errors.amount ? 'is-invalid' : ''" step="1" min="1" id="amount" v-model="info.amount">
                             </span>
@@ -105,6 +105,7 @@
                     this._exeTask();
                 },
                 _exeTask(){
+                    window.tempTip.postBasicRequest("{{url('')}}");
                     console.log("ok");
                     //入库成功
                     this.info = {};