M250325020133InsertQimallMenu.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\migrations;
  3. use common\models\backend\Menu;
  4. use yii\db\Migration;
  5. /**
  6. * Class M250325020133InsertQimallMenu
  7. */
  8. class M250325020133InsertQimallMenu extends Migration
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function safeUp()
  14. {
  15. // $qimall_menu = Menu::find()->where(['title' => '系统管理', 'cate_id' => 1, 'is_addon' => 0, 'pid' => 0])->asArray()->one();
  16. // $sql = "INSERT INTO `qimall_menu`(`title`, `app_id`, `cate_id`, `addons_name`, `is_addon`, `pid`, `url`, `icon`, `level`, `dev`, `sort`, `params`, `tree`, `status`, `created_at`, `updated_at`) VALUES ('备份管理', 'backend', 1, '', 0, ".$qimall_menu['id'].", 'admin/expire-notice/backups', '', 1, 0, 999, NULL, '', 1, 0, 0);";
  17. // $this->execute($sql);
  18. $sql = "select * from qimall_menu where title='系统管理' and cate_id = 1 and is_addon = 0 and pid = 0";
  19. $list = \Yii::$app->db->createCommand($sql)->queryAll();
  20. $data = [
  21. [
  22. 'cate_id' => '1',// 类型[1=平台,2=商城]
  23. 'pid' => $list[0]['id'],
  24. 'title' => '备份管理',
  25. 'route' => 'admin/expire-notice/backups',
  26. 'icon' => '',
  27. 'authItemChild' => [// 子菜单权限,此参数若为空则表示无需增加子菜单权限)
  28. [
  29. 'title' => '备份当前',
  30. 'name' => 'admin/expire-notice/start-backups',
  31. ],
  32. [
  33. 'title' => '下载',
  34. 'name' => 'admin/expire-notice/down',
  35. ],
  36. [
  37. 'title' => '删除',
  38. 'name' => 'admin/expire-notice/delete',
  39. ],
  40. ]
  41. ]
  42. ];
  43. $res = Menu::migrateCreateMenu($data);
  44. if ($res === false) throw new \Exception(Menu::getStaticError());
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function safeDown()
  50. {
  51. echo "M250325020133InsertQimallMenu cannot be reverted.\n";
  52. return false;
  53. }
  54. /*
  55. // Use up()/down() to run migration code without a transaction.
  56. public function up()
  57. {
  58. }
  59. public function down()
  60. {
  61. echo "M250325020133InsertQimallMenu cannot be reverted.\n";
  62. return false;
  63. }
  64. */
  65. }