1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- use think\migration\Migrator;
- use think\migration\db\Column;
- class CreateConstructionStepTable extends Migrator
- {
- /**
- * Change Method.
- *
- * Write your reversible migrations using this method.
- *
- * More information on writing migrations is available here:
- * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
- *
- * The following commands can be used in this method and Phinx will
- * automatically reverse them when rolling back:
- *
- * createTable
- * renameTable
- * addColumn
- * renameColumn
- * addIndex
- * addForeignKey
- *
- * Remember to call "create()" or "update()" and NOT "save()" when working
- * with the Table class.
- */
- public function change()
- {
- $this->table('construction_step',['comment' => '施工阶段设置表'])
- ->addColumn('name', 'string', ['limit'=> 255,'comment' => '阶段名称', 'default'=> ''])
- ->addColumn('order', 'integer', ['limit'=> 3,'comment' => '排序'])
- ->addColumn('root_id', 'integer', ['limit'=> 11,'comment' => '企业id'])
- ->addColumn('addtime', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '添加时间'])
- ->create();
- $root_ids = \app\model\Company::where('company_group', '>', 0)->column('root_id');
- foreach ($root_ids as $k => $v) {
- $data = [
- ['name'=> '开工大吉', 'order'=> 1, 'root_id'=> $v],
- ['name'=> '前期施工', 'order'=> 2, 'root_id'=> $v],
- ['name'=> '中期施工', 'order'=> 3, 'root_id'=> $v],
- ['name'=> '后期施工', 'order'=> 4, 'root_id'=> $v],
- ['name'=> '竣工', 'order'=> 5, 'root_id'=> $v]
- ];
- \app\model\ConstructionStep::insertAll($data);
- }
- }
- }
|