<?php

use App\Authority;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateStoreCheckingReceivesTable extends Migration
{

    protected $authNames=[
        "入库管理-盘收一体",
        "入库管理-盘收一体-任务",
        "入库管理-盘收一体-盘收",
        "入库管理-盘收一体-盘收-查看",
        "入库管理-盘收一体-盘收-编辑",
    ];
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('store_checking_receives', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('owner_id')->index()->comment('外键货主');
            $table->timestamp('created_at')->index()->comment('创建时间');
            $table->enum('status',['已导入','清点中','已清点','已ASN入库','已收货','收货失败'])->default('已导入')->comment('状态');
            $table->enum('is_receive_diff',['是','否'])->nullable()->comment('接收差异');
            $table->string('asn')->nullable()->comment('asn单号');
            $table->enum('is_asn_diff',['是','否'])->nullable()->comment('ASN差异');
        });
        foreach ($this->authNames as $name){
            if(!Authority::query()->where('name',$name)->first())(new Authority(['name'=>$name,'alias_name'=>$name]))->save();
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('store_checking_receives');
        foreach ($this->authNames as $name){
            Authority::query()->where('name',$name)->delete();
        }
    }
}
