20220714072654_create_company_strength_data.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\CompanyStrengthCate;
  5. use app\model\Company;
  6. class CreateCompanyStrengthData extends Migrator
  7. {
  8. /**
  9. * Change Method.
  10. *
  11. * Write your reversible migrations using this method.
  12. *
  13. * More information on writing migrations is available here:
  14. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  15. *
  16. * The following commands can be used in this method and Phinx will
  17. * automatically reverse them when rolling back:
  18. *
  19. * createTable
  20. * renameTable
  21. * addColumn
  22. * renameColumn
  23. * addIndex
  24. * addForeignKey
  25. *
  26. * Remember to call "create()" or "update()" and NOT "save()" when working
  27. * with the Table class.
  28. */
  29. public function change()
  30. {
  31. //默认数据
  32. $root_ids = Company::where('1=1')->column('root_id');
  33. $saves = [];
  34. $arr = ['品牌介绍', '发展历程', '公司承诺', '老板访谈','材料讲解' , '施工工艺' ];
  35. foreach ($root_ids as $v) {
  36. foreach ($arr as $v2) {
  37. $saves[] = [
  38. 'root_id' => $v,
  39. 'name' => $v2
  40. ];
  41. }
  42. }
  43. (new CompanyStrengthCate())->saveAll($saves);
  44. }
  45. }