vd/database/migrations/2018_11_27_175137_create_base_tables.php
2018-12-21 16:09:08 +08:00

235 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use App\Dicts;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBaseTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
foreach (app(Dicts::class)->get('tables') as $prefix => $type) {
Schema::create("{$prefix}_companies", function (Blueprint $table) use ($type) {
$table->increments('id')->comment('企业ID');
$table->string('sn', 32)->comment('企业编号');
$table->string('name', 32)->default('')->comment('企业名称');
$table->string('contacts', 20)->default('')->comment('联系人');
$table->string('mobile', 20)->default('')->comment('手机号');
$table->string('address')->default('')->comment('地址');
$table->text('remark')->nullable()->comment('订单备注');
$table->text('extends')->nullable()->comment('扩展信息');
$table->timestamps();
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->comment("{$type}企业");
});
Schema::create("{$prefix}_packages", function (Blueprint $table) use ($type) {
$table->increments('id')->comment('企业ID');
$table->integer('parent_id')->unsigned()->default(0)->comment('父级ID');
$table->string('sn', 20)->comment('套餐编号');
$table->string('name', 32)->comment('套餐名称');
$table->tinyInteger('type')->unsigned()->default(255)->comment('套餐类型0:基础套餐 1续费包 2:加油包 3:可选包 4:附加包)');
$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('套餐流量(M)');
$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->timestamps();
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->index('name');
$table->index('parent_id');
$table->index('type');
$table->index('carrier_operator');
$table->comment("{$type}套餐");
});
Schema::create("{$prefix}_order_cards", function (Blueprint $table) use ($type) {
$table->increments('id')->comment('关联表ID');
$table->bigInteger('sim')->unsigned()->default(0)->comment('sim号');
$table->integer('order_id')->unsigned()->default(0)->comment('订单ID');
$table->integer('company_id')->unsigned()->default(0)->comment("{$type}企业ID");
$table->integer('package_id')->unsigned()->default(0)->comment('套餐ID');
$table->timestamps();
$table->softDeletes();
$table->unique(['sim', 'order_id']);
$table->unique(['sim', 'deleted_at']);
$table->comment("{$type}订单企业套餐卡关联表");
});
Schema::create("{$prefix}_added_orders", function (Blueprint $table) use ($type) {
$table->increments('id')->comment('订单ID');
$table->string('sn', 32)->comment('订单编号');
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型1:套餐续费 2续费包 3:加油包 4:可选包 5:附加包)');
$table->integer('company_id')->unsigned()->default(0)->comment("{$type}企业ID");
$table->string('transaction_no', 64)->comment('交易流水号');
$table->string('pay_channel', 20)->default('')->comment('支付频道');
$table->integer('unit_price')->unsigned()->default(0)->comment('单价');
$table->integer('counts')->unsigned()->default(0)->comment('数量');
$table->integer('total_price')->unsigned()->default(0)->comment('总价');
$table->timestamp('order_at')->nullable()->comment('下单时间');
$table->text('remark')->nullable()->comment('订单备注');
$table->timestamps();
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->index('type');
$table->index('company_id');
$table->index('order_at');
$table->comment("{$type}增值包订单");
});
}
Schema::create("real_orders", function (Blueprint $table) {
$table->increments('id')->comment('订单ID');
$table->string('sn', 32)->comment('订单编号');
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型0:基础套餐)');
$table->integer('company_id')->unsigned()->default(0)->comment("企业ID");
$table->string('transaction_no', 64)->comment('交易流水号');
$table->string('pay_channel', 20)->default('')->comment('支付频道');
$table->integer('unit_price')->unsigned()->default(0)->comment('单价');
$table->integer('counts')->unsigned()->default(0)->comment('数量');
$table->integer('total_price')->unsigned()->default(0)->comment('总价');
$table->timestamp('order_at')->nullable()->comment('下单时间');
$table->string('address')->default('')->comment('收货地址');
$table->string('contacts')->default('')->comment('联系人');
$table->string('mobile')->default('')->comment('电话');
$table->text('logistics_remark')->nullable()->comment('物流备注');
$table->text('remark')->nullable()->comment('订单备注');
$table->timestamps();
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->index('type');
$table->index('company_id');
$table->index('order_at');
$table->comment('RD订单');
});
Schema::create("blocs", function (Blueprint $table) {
$table->increments('id')->comment('集团ID');
$table->string('sn', 32)->comment('集团编号');
$table->string('name', 32)->comment('集团名称');
$table->string('shorthand', 32)->comment('英文简称');
$table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)');
$table->timestamps();
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->index('name');
$table->index('carrier_operator');
$table->comment('卡源集团');
});
Schema::create("cards", function (Blueprint $table) {
$table->bigInteger('sim')->unsigned()->default(0)->comment('sim号');
$table->string('imsi', 32)->default('')->comment('imsi号');
$table->string('iccid', 32)->default('')->comment('iccid号');
$table->integer('bloc_id')->unsigned()->default(0)->comment('来源集团ID');
$table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)');
$table->timestamp('activate_at')->nullable()->comment('激活时间');
$table->timestamp('virtual_activate_at')->nullable()->comment('虚拟激活时间');
$table->tinyInteger('type')->unsigned()->default(0)->comment('类型(0:真实卡 1:虚拟卡)');
$table->timestamps();
$table->primary('sim');
$table->comment('卡基础信息表');
});
Schema::create("virtual_company_accounts", function (Blueprint $table) {
$table->increments('id')->comment('自增ID');
$table->integer('company_id')->unsigned()->default(0)->comment('企业ID');
$table->string('nickname', 32)->default('')->comment('昵称');
$table->string('mobile', 20)->default('')->comment('手机号');
$table->string('username', 32)->default('')->comment('登录名');
$table->string('password', 32)->default('')->comment('密码');
$table->string('salt', 6)->default('')->comment('盐');
$table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0未激活 1正常 2禁用');
$table->timestamps();
$table->softDeletes();
$table->unique(['mobile', 'deleted_at']);
$table->comment('VD企业账号表');
});
Schema::create("virtual_company_addresses", function (Blueprint $table) {
$table->increments('id')->comment('自增ID');
$table->integer('company_id')->unsigned()->default(0)->comment('企业ID');
$table->string('contacts', 20)->default('')->comment('联系人');
$table->string('mobile', 20)->default('')->comment('手机号');
$table->string('area')->default('')->comment('区域');
$table->string('address')->default('')->comment('地址');
$table->tinyInteger('default')->unsigned()->default(0)->comment('是否默认 0:不是 1:是');
$table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用');
$table->timestamps();
$table->softDeletes();
$table->comment('VD企业收货地址表');
});
Schema::create("virtual_products", function (Blueprint $table) {
$table->increments('id')->comment('自增ID');
$table->string('sn', 32)->comment('产品编码');
$table->string('name', 32)->comment('产品名称');
$table->integer('company_id')->unsigned()->default(0)->comment('企业ID');
$table->integer('package_id')->unsigned()->default(0)->comment('套餐ID');
$table->integer('base_price')->unsigned()->default(0)->comment('基础价格');
$table->integer('renewal_price')->unsigned()->default(0)->comment('续费价格');
$table->text('remark')->nullable()->comment('备注');
$table->timestamps();
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->comment('VD企业定价表');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
foreach (app(Dicts::class)->get('tables') as $prefix => $type) {
Schema::dropIfExists("{$prefix}_added_orders");
Schema::dropIfExists("{$prefix}_orders");
Schema::dropIfExists("{$prefix}_order_cards");
Schema::dropIfExists("{$prefix}_packages");
Schema::dropIfExists("{$prefix}_companies");
}
Schema::dropIfExists("cards");
Schema::dropIfExists("blocs");
Schema::dropIfExists("virtual_products");
Schema::dropIfExists("virtual_company_addresses");
Schema::dropIfExists("virtual_company_accounts");
}
}