20220716070828_update_data_to_company_strength_cate.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 UpdateDataToCompanyStrengthCate 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. CompanyStrengthCate::where('1=1')->delete();
  33. $root_ids = Company::where('1=1')->column('root_id');
  34. $saves = [];
  35. $arr = ['发展历程','产品介绍','材料实验室','老板访谈','工艺标准','团队承诺','荣誉奖项'];
  36. foreach ($root_ids as $v) {
  37. foreach ($arr as $v2) {
  38. $saves[] = [
  39. 'root_id' => $v,
  40. 'name' => $v2
  41. ];
  42. }
  43. }
  44. (new CompanyStrengthCate())->saveAll($saves);
  45. }
  46. }