136 lines
6.7 KiB
PHP
136 lines
6.7 KiB
PHP
<?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()
|
||
{
|
||
Schema::create("real_blocs", function (Blueprint $table) {
|
||
$table->string('id', 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->primary('id');
|
||
$table->index('name');
|
||
$table->index('carrier_operator');
|
||
$table->softDeletes();
|
||
});
|
||
|
||
db_alter("real_blocs", "卡源集团");
|
||
|
||
foreach (app(Dicts::class)->get('tables') as $prefix => $type) {
|
||
Schema::create("{$prefix}_companies", function (Blueprint $table) {
|
||
$table->increments('id')->comment('企业编号');
|
||
$table->string('name', 32)->default('')->comment('企业名称');
|
||
$table->string('phone', 20)->default('')->comment('手机号');
|
||
$table->string('username', 32)->default('')->comment('登录名');
|
||
$table->string('password', 32)->default('')->comment('密码');
|
||
$table->timestamps();
|
||
$table->softDeletes();
|
||
});
|
||
|
||
db_alter("{$prefix}_companies", "{$type}企业");
|
||
|
||
Schema::create("{$prefix}_packages", function (Blueprint $table) {
|
||
$table->string('id', 20)->comment('套餐编号');
|
||
$table->string('parent_id', 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('flows')->unsigned()->default(0)->comment('套餐流量(M)');
|
||
$table->integer('voices')->unsigned()->default(0)->comment('套餐语音(分钟)');
|
||
$table->integer('messages')->unsigned()->default(0)->comment('套餐短信(条)');
|
||
$table->tinyInteger('has_message_switch')->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->primary('id');
|
||
$table->index('name');
|
||
$table->index('parent_id');
|
||
$table->index('type');
|
||
$table->index('carrier_operator');
|
||
$table->softDeletes();
|
||
});
|
||
|
||
db_alter("{$prefix}_packages", "{$type}套餐");
|
||
|
||
Schema::create("{$prefix}_cards", function (Blueprint $table) {
|
||
$table->string('sim', 20)->comment('sim号');
|
||
$table->string('imsi', 20)->comment('imsi号');
|
||
$table->string('iccid', 20)->comment('iccid号');
|
||
$table->string('bloc_id', 32)->comment('来源集团ID');
|
||
$table->integer('company_id')->unsigned()->default(0)->comment("{$type}企业编号");
|
||
$table->string('package_id', 20)->comment('套餐编号');
|
||
$table->string('price', 20)->comment('单价');
|
||
$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->timestamps();
|
||
|
||
$table->primary('sim');
|
||
$table->index('imsi');
|
||
$table->index('iccid');
|
||
});
|
||
|
||
db_alter("{$prefix}_cards", "{$type}卡基础信息表");
|
||
|
||
|
||
|
||
Schema::create("{$prefix}_orders", function (Blueprint $table) {
|
||
$table->string('id', 32)->comment('订单编号');
|
||
$table->tinyInteger('type')->unsigned()->default(255)->comment('订单类型(0:基础套餐 1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)');
|
||
$table->integer('company_id')->unsigned()->default(0)->comment("{$type}企业编号");
|
||
$table->string('transaction_no', 64)->comment('交易流水号');
|
||
$table->tinyInteger('pay_channel')->unsigned()->default(0)->comment('支付方式(0:银行转账 1:账户余额 2:微信支付 3:支付宝 4:天猫续费)');
|
||
$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->timestamps();
|
||
|
||
$table->primary('id');
|
||
$table->index('type');
|
||
$table->index('company_id');
|
||
$table->index('order_at');
|
||
});
|
||
|
||
db_alter("{$prefix}_orders", "{$type}订单");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Reverse the migrations.
|
||
*
|
||
* @return void
|
||
*/
|
||
public function down()
|
||
{
|
||
foreach (app(Dicts::class)->get('tables') as $prefix => $type) {
|
||
Schema::dropIfExists("{$prefix}_orders");
|
||
Schema::dropIfExists("{$prefix}_cards");
|
||
Schema::dropIfExists("{$prefix}_packages");
|
||
Schema::dropIfExists("{$prefix}_companies");
|
||
}
|
||
|
||
Schema::dropIfExists("real_blocs");
|
||
}
|
||
}
|