20220927033922_create_customer_package_table.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. use app\model\Permission;
  3. use think\migration\Migrator;
  4. use think\migration\db\Column;
  5. class CreateCustomerPackageTable extends Migrator
  6. {
  7. /**
  8. * Change Method.
  9. *
  10. * Write your reversible migrations using this method.
  11. *
  12. * More information on writing migrations is available here:
  13. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  14. *
  15. * The following commands can be used in this method and Phinx will
  16. * automatically reverse them when rolling back:
  17. *
  18. * createTable
  19. * renameTable
  20. * addColumn
  21. * renameColumn
  22. * addIndex
  23. * addForeignKey
  24. *
  25. * Remember to call "create()" or "update()" and NOT "save()" when working
  26. * with the Table class.
  27. */
  28. public function change()
  29. {
  30. $this->table('customer_package')
  31. ->addColumn('root_id', 'integer', ['comment' => '所属企业'])
  32. ->addColumn('name', 'string', ['comment' => '产品名', 'limit' => 50])
  33. ->addColumn('total_price', 'integer', ['comment' => '总价'])
  34. ->create();
  35. // 添加产品管理权限
  36. $p = Permission::where(['uri' => 'customerSetting/index'])->find();
  37. $relation = array_merge(explode(',', $p->relation), ['customerSetting/package', 'customerSetting/editPackage', 'customerSetting/delPackage']);
  38. $p->relation = implode(',', $relation);
  39. $p->save();
  40. }
  41. }