<?php

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

class AddAuthorityDataMoney extends Migration
{
     public $delAuthorities = [
         '客户管理-财务-即时账单',
         '客户管理-财务-账单确认',
         '客户管理-财务-账单确认-编辑',
         '客户管理-财务-账单确认-完结',
     ];

     public $addAuthorities = [
         "结算管理",
         "结算管理-即时账单",
         "结算管理-账单确认",
         "结算管理-账单确认-编辑",
         "结算管理-账单确认-完结",
     ];

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        foreach ($this->delAuthorities as $authority){
            \App\Authority::query()->where("name",$authority)->delete();
        }
        foreach ($this->addAuthorities as $authority){
            \App\Authority::query()->firstOrCreate([
                "name"=>$authority
            ],[
                "name"=>$authority,
                "alias_name"=>$authority
            ]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        foreach ($this->addAuthorities as $authority){
            \App\Authority::query()->where("name",$authority)->delete();
        }
        foreach ($this->delAuthorities as $authority){
            \App\Authority::query()->firstOrCreate([
                "name"=>$authority
            ],[
                "name"=>$authority,
                "alias_name"=>$authority
            ]);
        }
    }
}
