20220708101318_add_train_class_cate_data.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Company;
  5. use app\model\TrainClassCate;
  6. class AddTrainClassCateData 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. $root_ids = Company::where([['company_group', '>', 0]])->column('root_id');
  32. $saves = [];
  33. $arr = ['社群营销', '推广技巧', '网销获客', '邀约转化', '团队管理', '微电影', '短视频广告'];
  34. foreach ($root_ids as $v) {
  35. foreach ($arr as $v2) {
  36. $saves[] = [
  37. 'root_id' => $v,
  38. 'name' => $v2
  39. ];
  40. }
  41. }
  42. (new TrainClassCate())->saveAll($saves);
  43. }
  44. }