20220711093737_add_data_to_train_class_cate.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Company;
  5. use app\model\TrainClassCate;
  6. use app\model\Permission;
  7. class AddDataToTrainClassCate 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. TrainClassCate::where('1=1')->delete();
  33. $root_ids = Company::where([['company_group', '>', 0]])->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 TrainClassCate())->saveAll($saves);
  45. $per = ',train/class_label,train/class_label_list,train/class_label_edit,train/class_label_add,train/class_label_add_ajax,train/get_label';
  46. $w[] = ['auth_name', '=', '课程培训'];
  47. $w[] = ['pid', '>', 0];
  48. $w[] = ['is_menu', '=', 1];
  49. $info = Permission::where($w)->find();
  50. $per = $info->relation . $per;
  51. $info->relation = $per;
  52. $info->save();
  53. }
  54. }