<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // $this->call(UsersTableSeeder::class);
        $tableName = 'strategy_set';//策略设置表
        if(!Schema::hasTable($tableName)){
            Schema::create($tableName, function (Blueprint $table){
                $table->increments('id');
                $table->uuid('strategy_sn')->comment('sn编号'); //sn编号
                $table->char('strategy_name',50)->comment('策略名称');  
                $table->char('user_sn',100)->comment('用户sn');  
                $table->char('user_name',50)->comment('用户名');  
                $table->char('call_number',50)->comment('主叫号码');  
                $table->char('parent_sn',50)->comment('主账号名');  
                $table->char('project_sn',100)->comment('项目sn');  
                
                $table->unsignedSmallInteger('day_type')->default(0)->comment('外呼日期类型 0每天 1日期前一天和当天');  
                $table->unsignedSmallInteger('frequency_type')->default(1)->comment('外呼频率类型 （1 一天一次 2 一天两次）');
                $table->char('call_time_set',50)->comment('呼叫设置时间点，两个用#号分割');  
                $table->unsignedSmallInteger('disabled')->default(0)->comment('是否不可用 0启用 1停用');
                $table->integer('total')->default(0)->comment('excel导入号码总数量');
                $table->integer('latest_total')->default(0)->comment('最新一次导入excel号码数量');
                $table->timestamp('updated_at')->nullable()->comment('更新时间');
                $table->timestamp('created_at')->nullable()->comment('创建时间');
            });
            //加索引
            Schema::table($tableName, function ($table){
                $table->index('strategy_sn');
                $table->index('disabled');
            });
        }
        
        
        $tableName = 'strategy_excel';//策略excel数据记录表
        if(!Schema::hasTable($tableName)){
            Schema::create($tableName, function (Blueprint $table){
                $table->increments('id');
                $table->char('strategy_sn',100)->comment('sn编号'); 
                $table->char('name',50)->nullable()->comment('姓名');  
                $table->date('duty_date')->nullable()->comment('值班日期');                  
                $table->unsignedBigInteger('phone')->comment('手机号');  
                $table->unsignedSmallInteger('last_handle_month')->default(0)->comment('最后处理月份，当月处理后不再处理');
                $table->timestamp('updated_at')->nullable()->comment('更新时间');
                $table->timestamp('created_at')->nullable()->comment('创建时间');
            });
            //加索引
            Schema::table($tableName, function ($table){
                $table->index('strategy_sn');
            });
        }
        
        $tableName = 'strategy_task';//任务数据（任务已建未建）
        if(!Schema::hasTable($tableName)){
            Schema::create($tableName, function (Blueprint $table){
                $table->increments('id');
                $table->uuid('strategy_sn')->comment('策略sn编号'); //sn编号
                $table->char('name',50)->nullable()->comment('姓名'); 
                $table->date('duty_date')->nullable()->comment('值班日期（年月日）');  
                $table->timestamp('import_date')->nullable()->comment('导入日期（年-月-日 时:分:秒）');
                $table->unsignedBigInteger('phone')->comment('手机号');  
                $table->char('call_number',50)->comment('主叫号码'); 
                $table->date('call_date')->comment('外呼时间（年月日）');  
                $table->time('call_time')->comment('外呼时间（时分秒）');
                $table->char('parent_sn',50)->comment('主账号名');  
                $table->char('user_sn',50)->comment('账号sn');  
                $table->char('project_sn',100)->comment('项目sn');  
                
                $table->unsignedSmallInteger('is_created')->default(0)->comment('是否新建任务（0未建 1已建）');
                $table->unsignedSmallInteger('created_fail_number')->default(0)->comment('任务创建失败尝试次数');
                $table->string('create_fail_reason',500)->comment('记录接口返回失败原因');  
                $table->timestamp('created_at')->nullable();
            });
            //加索引
            Schema::table($tableName, function ($table){
                $table->index('is_created');
                $table->index('phone');
            });
        }
        
        
    }
}
