20220813071259_add_permission_customer_portrait.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. use app\model\Grant;
  6. class AddPermissionCustomerPortrait 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. $find = Permission::where([['auth_name', '=', '客户画像'], ['uri', '=', 'crm/portrait,crm/portrait_edit,crm/portrait_type']])->findOrEmpty();
  32. if ($find->isEmpty()) {
  33. $data = [
  34. 'pid' => 7,
  35. 'auth_name'=> '客户画像',
  36. 'uri' => 'crm/portrait',
  37. 'is_menu' => 1,
  38. 'sort'=> 50,
  39. 'relation' => 'crm/portrait,crm/portrait_edit,crm/portrait_type'
  40. ];
  41. $per_ids3 = Permission::insertGetId($data);
  42. } else {
  43. $per_ids3 = $find->id;
  44. }
  45. $info = Grant::where('id',1)->find();
  46. $pids = (array)$info->permission;
  47. $pids[] = (int)$per_ids3;
  48. $info->permission = array_values($pids);
  49. $info->save();
  50. }
  51. }