20220519033556_create_construction_step_table.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. class CreateConstructionStepTable extends Migrator
  5. {
  6. /**
  7. * Change Method.
  8. *
  9. * Write your reversible migrations using this method.
  10. *
  11. * More information on writing migrations is available here:
  12. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  13. *
  14. * The following commands can be used in this method and Phinx will
  15. * automatically reverse them when rolling back:
  16. *
  17. * createTable
  18. * renameTable
  19. * addColumn
  20. * renameColumn
  21. * addIndex
  22. * addForeignKey
  23. *
  24. * Remember to call "create()" or "update()" and NOT "save()" when working
  25. * with the Table class.
  26. */
  27. public function change()
  28. {
  29. $this->table('construction_step',['comment' => '施工阶段设置表'])
  30. ->addColumn('name', 'string', ['limit'=> 255,'comment' => '阶段名称', 'default'=> ''])
  31. ->addColumn('order', 'integer', ['limit'=> 3,'comment' => '排序'])
  32. ->addColumn('root_id', 'integer', ['limit'=> 11,'comment' => '企业id'])
  33. ->addColumn('addtime', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'comment' => '添加时间'])
  34. ->create();
  35. $root_ids = \app\model\Company::where('company_group', '>', 0)->column('root_id');
  36. foreach ($root_ids as $k => $v) {
  37. $data = [
  38. ['name'=> '开工大吉', 'order'=> 1, 'root_id'=> $v],
  39. ['name'=> '前期施工', 'order'=> 2, 'root_id'=> $v],
  40. ['name'=> '中期施工', 'order'=> 3, 'root_id'=> $v],
  41. ['name'=> '后期施工', 'order'=> 4, 'root_id'=> $v],
  42. ['name'=> '竣工', 'order'=> 5, 'root_id'=> $v]
  43. ];
  44. \app\model\ConstructionStep::insertAll($data);
  45. }
  46. }
  47. }