20220712100607_create_default_data_talkskill_cate.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Company;
  5. use app\model\TalkskillUsersCate;
  6. use app\model\TrainClassCate;
  7. class CreateDefaultDataTalkskillCate extends Migrator
  8. {
  9. /**
  10. * Change Method.
  11. *
  12. * Write your reversible migrations using this method.
  13. *
  14. * More information on writing migrations is available here:
  15. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  16. *
  17. * The following commands can be used in this method and Phinx will
  18. * automatically reverse them when rolling back:
  19. *
  20. * createTable
  21. * renameTable
  22. * addColumn
  23. * renameColumn
  24. * addIndex
  25. * addForeignKey
  26. *
  27. * Remember to call "create()" or "update()" and NOT "save()" when working
  28. * with the Table class.
  29. */
  30. public function change()
  31. {
  32. //默认值修改
  33. TalkskillUsersCate::where('1=1')->delete();
  34. TrainClassCate::where('1=1')->delete();
  35. //默认数据
  36. $root_ids = Company::where('1=1')->column('root_id');
  37. $saves = $cates = [];
  38. $arr = ['业务部', '网销部', '设计师', '客户经理'];
  39. $cate = ['销冠分享','总裁讲堂','营销工具','工艺标准','营销管理','业务技能','设计常识','产品知识','企业文化','通用知识','其他'];
  40. foreach ($root_ids as $v) {
  41. foreach ($arr as $v2) {
  42. $saves[] = [
  43. 'root_id' => $v,
  44. 'name' => $v2
  45. ];
  46. }
  47. foreach ($cate as $v3) {
  48. $cates[] = [
  49. 'root_id' => $v,
  50. 'name' => $v3
  51. ];
  52. }
  53. }
  54. (new TalkskillUsersCate())->saveAll($saves);
  55. (new TrainClassCate())->saveAll($cates);
  56. }
  57. }