<?php

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

class CreateVirtualPackagesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('virtual_packages')) {
            return;
        }

        Schema::create('virtual_packages', function (Blueprint $table) {
            $table->increments('id')->comment('企业ID');
            $table->string('sn', 20)->comment('套餐编号');
            $table->string('name', 32)->comment('套餐名称');
            $table->tinyInteger('type')->unsigned()->default(255)->comment('套餐类型（0:基础套餐 2：续费包 3:加油包）');
            $table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)');
            $table->integer('cost_price')->unsigned()->default(0)->comment('成本价格');
            $table->integer('guide_price')->unsigned()->default(0)->comment('指导价格');
            $table->integer('renewal_cost_price')->unsigned()->default(0)->comment('续费成本价格');
            $table->integer('renewal_guide_price')->unsigned()->default(0)->comment('续费指导价格');
            $table->integer('flows')->unsigned()->default(0)->comment('套餐流量 单位MB');
            $table->integer('voices')->unsigned()->default(0)->comment('套餐语音(分钟)');
            $table->integer('messages')->unsigned()->default(0)->comment('套餐短信(条)');
            $table->tinyInteger('has_messages')->unsigned()->default(255)->comment('是否开通短信服务（0:无 1：有）');
            $table->tinyInteger('has_lbs')->unsigned()->default(255)->comment('是否开通LBS服务（0:无 1：有）');
            $table->tinyInteger('reset_months')->unsigned()->default(0)->comment('重置周期(月)');
            $table->tinyInteger('service_months')->unsigned()->default(0)->comment('套餐周期(月)');
            $table->tinyInteger('effect_months')->unsigned()->default(0)->comment('生效延迟周期(月)');
            $table->tinyInteger('delay_months')->unsigned()->default(0)->comment('服务延长周期(月)');
            $table->text('description')->nullable()->comment('描述');
            $table->tinyInteger('flowed')->unsigned()->default(0)->comment('是否是后向流量池套餐 0:否 1:是');
            $table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用');
            $table->timestamps();
            $table->softDeletes();

            $table->unique(['sn', 'deleted_at']);
            $table->index('type');

            $table->comment("VD套餐");
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('virtual_packages');
    }
}
