M231027025607InsertAttachmentQimallMenu.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\migrations;
  3. use common\models\backend\Menu;
  4. use common\models\rbac\AuthItem;
  5. use yii\db\Migration;
  6. /**
  7. * Class M231027025607InsertAttachmentQimallMenu
  8. */
  9. class M231027025607InsertAttachmentQimallMenu extends Migration
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function safeUp()
  15. {
  16. try {
  17. $menu = Menu::find()->where(['cate_id' => 2, 'url' => 'mall/diy/index', 'pid' => 0, 'level' => 1, 'status' => 1])
  18. ->asArray()->one();
  19. if (empty($menu)) throw new \Exception('qimall_menu没有查询到数据');
  20. $pid = $menu['id'];
  21. $tree = $menu['tree'] . ' tr_' . $pid;
  22. $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', 2, '', 0, $pid, 'mall/attachment/index', '', 2, 0, 999, NULL, '$tree', 1, 1689130872, 1689130872);";
  23. $this->execute($sql);
  24. $auth_item = AuthItem::find()->where(['cate_id' => 2, 'name' => 'mall/diy/index', 'pid' => 0, 'level' => 1, 'status' => 1])->asArray()->one();
  25. if (empty($auth_item)) throw new \Exception('qimall_rbac_auth_item没有查询到数据');
  26. $pid = $auth_item['id'];
  27. $tree = $auth_item['tree'] . ' tr_' . $pid;
  28. $sql = "INSERT INTO `qimall_rbac_auth_item` ( `name`, `title`, `app_id`, `addons_name`, `pid`, `level`, `is_addon`, `sort`, `tree`, `status`, `created_at`, `updated_at`, `cate_id`) VALUES ( 'mall/attachment/index', '素材管理', 'backend', '', $pid, 2, 0, 999, '$tree', 1, 1689129562, 1689129585, 2);";
  29. $this->execute($sql);
  30. echo '素材管理菜单插入成功' . PHP_EOL;
  31. } catch (\Exception $e) {
  32. echo '素材管理菜单插入失败:' . $e->getMessage() . PHP_EOL;
  33. }
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function safeDown()
  39. {
  40. echo "M231027025607InsertAttachmentQimallMenu cannot be reverted.\n";
  41. return false;
  42. }
  43. /*
  44. // Use up()/down() to run migration code without a transaction.
  45. public function up()
  46. {
  47. }
  48. public function down()
  49. {
  50. echo "M231027025607InsertAttachmentQimallMenu cannot be reverted.\n";
  51. return false;
  52. }
  53. */
  54. }