M230601165236UpdateQimallMenu.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\migrations;
  3. use common\models\rbac\AuthItem;
  4. use common\models\user\MemberLabel;
  5. use yii\db\Migration;
  6. /**
  7. * Class M230601165236UpdateQimallMenu
  8. */
  9. class M230601165236UpdateQimallMenu extends Migration
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function safeUp()
  15. {
  16. try {
  17. // 修改菜单
  18. $sql = "UPDATE `qimall_menu` SET `pid` = 34, `tree` = 'tr_0 tr_34 ' WHERE `url` = 'mall/user-label/index' and `title` = '智能标签';
  19. UPDATE `qimall_rbac_auth_item` SET `pid` = 2820, `tree` = 'tr_0 tr_2820 ' WHERE `title` = '智能标签';";
  20. $this->execute($sql);
  21. // 获取权限id
  22. $itemId = AuthItem::find()->select('id')->where(['title' => '智能标签', 'status' => 1])->scalar();
  23. $rbac_sql = "UPDATE `qimall_rbac_auth_item` SET `level` = 3, `tree` = 'tr_0 tr_2820 tr_{$itemId} ' WHERE `pid` = {$itemId};";
  24. $this->execute($rbac_sql);
  25. } catch (\Exception $e) {
  26. \Yii::error('智能标签菜单转移:' . $e->getMessage());
  27. }
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function safeDown()
  33. {
  34. echo "M230601165236UpdateQimallMenu cannot be reverted.\n";
  35. return false;
  36. }
  37. /*
  38. // Use up()/down() to run migration code without a transaction.
  39. public function up()
  40. {
  41. }
  42. public function down()
  43. {
  44. echo "M230601165236UpdateQimallMenu cannot be reverted.\n";
  45. return false;
  46. }
  47. */
  48. }