get('tables') as $prefix => $type) { Schema::create("{$prefix}_companies", function (Blueprint $table) { $table->increments('id')->comment('企业ID'); $table->string('sn', 32)->comment('企业编号'); $table->string('name', 32)->default('')->comment('企业名称'); $table->string('contacts', 20)->default('')->comment('联系人'); $table->string('phone', 20)->default('')->comment('手机号'); $table->string('address')->default('')->comment('地址'); $table->text('remark')->nullable()->comment('订单备注'); $table->timestamps(); $table->softDeletes(); $table->unique(['sn', 'deleted_at']); }); db_alter("{$prefix}_companies", "{$type}企业"); Schema::create("{$prefix}_packages", function (Blueprint $table) { $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('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->softDeletes(); $table->unique(['sn', 'deleted_at']); $table->index('name'); $table->index('parent_id'); $table->index('type'); $table->index('carrier_operator'); }); db_alter("{$prefix}_packages", "{$type}套餐"); Schema::create("{$prefix}_cards", function (Blueprint $table) { $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']); }); db_alter("{$prefix}_cards", "{$type}订单企业套餐卡关联表"); Schema::create("{$prefix}_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("{$type}企业ID"); $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->string('address')->default('')->comment('收货地址'); $table->string('contact')->default('')->comment('联系人'); $table->string('phone')->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'); }); db_alter("{$prefix}_orders", "{$type}订单"); Schema::create("{$prefix}_added_orders", function (Blueprint $table) { $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->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->text('remark')->nullable()->comment('订单备注'); $table->timestamps(); $table->softDeletes(); $table->unique(['sn', 'deleted_at']); $table->index('type'); $table->index('company_id'); $table->index('order_at'); }); db_alter("{$prefix}_orders", "{$type}增值包订单"); } 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'); }); db_alter("blocs", "卡源集团"); Schema::create("cards", function (Blueprint $table) { $table->bigInteger('sim')->unsigned()->default(0)->comment('sim号'); $table->bigInteger('imsi')->unsigned()->default(0)->comment('imsi号'); $table->bigInteger('iccid')->unsigned()->default(0)->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'); }); db_alter("cards", "卡基础信息表"); Schema::create("virtual_company_accounts", function (Blueprint $table) { $table->increments('id')->comment('自增ID'); $table->string('company_id', 32)->comment('企业ID'); $table->string('phone', 20)->default('')->comment('手机号'); $table->string('username', 32)->default('')->comment('登录名'); $table->string('password', 32)->default('')->comment('密码'); $table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用'); $table->timestamps(); $table->softDeletes(); $table->unique('phone'); }); Schema::create("virtual_company_address", function (Blueprint $table) { $table->increments('id')->comment('自增ID'); $table->string('company_id', 32)->comment('企业ID'); $table->string('contacts', 20)->default('')->comment('联系人'); $table->string('phone', 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(); }); Schema::create("virtual_products", function (Blueprint $table) { $table->increments('id')->comment('自增ID'); $table->string('sn', 32)->comment('产品编码'); $table->string('name', 32)->comment('产品名称'); $table->string('company_id', 32)->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->timestamps(); $table->softDeletes(); $table->unique(['sn', 'deleted_at']); }); } /** * 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}_cards"); Schema::dropIfExists("{$prefix}_packages"); Schema::dropIfExists("{$prefix}_companies"); } Schema::dropIfExists("cards"); Schema::dropIfExists("blocs"); Schema::dropIfExists("virtual_products"); Schema::dropIfExists("virtual_company_address"); Schema::dropIfExists("virtual_company_accounts"); } }