20220715091033_create_save_permission_to_permission.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. use app\model\CompanyStrengthCate;
  6. use app\model\Company;
  7. class CreateSavePermissionToPermission 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. $per = ',companyStrength/imgUpload,data/cluedata,companyStrength/cate,companyStrength/cate_list,companyStrength/cate_add,companyStrength/cate_edit';
  33. $w[] = ['auth_name', '=', '公司实力'];
  34. $w[] = ['pid', '>', 0];
  35. $w[] = ['is_menu', '=', 1];
  36. $info = Permission::where($w)->find();
  37. $per = $info->relation . $per;
  38. $info->relation = $per;
  39. $info->save();
  40. //默认数据
  41. CompanyStrengthCate::where('1=1')->delete();
  42. $root_ids = Company::where('1=1')->column('root_id');
  43. $saves = [];
  44. $arr = ['公司产品介绍','材料品类介绍','材料实验室','实景案例','设计师包赚' ,'工艺标准','团队服务','客户口碑','企业宣传','老板个人包装','销售培训端','客户使用端'];
  45. foreach ($root_ids as $v) {
  46. foreach ($arr as $v2) {
  47. $saves[] = [
  48. 'root_id' => $v,
  49. 'name' => $v2
  50. ];
  51. }
  52. }
  53. (new CompanyStrengthCate())->saveAll($saves);
  54. }
  55. }