20220617080850_update_construction_step_table.php 1.5 KB

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