M230202083942UpdateNameToRbacAuthItem.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M230202083942UpdateNameToRbacAuthItem
  6. */
  7. class M230202083942UpdateNameToRbacAuthItem extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. try {
  15. $platform_order = $this->db->createCommand("select * from qimall_rbac_auth_item where name = 'admin/platform-order/index' ")->queryAll();
  16. if(!$platform_order){
  17. $column = ['name', 'title', 'app_id','addons_name', 'pid','level','is_addon','sort','tree','status','created_at','updated_at','cate_id'];
  18. $data = [
  19. ['admin/platform-order/index', '订单管理', 'backend', '', '0', '1', '0', '999', 'tr_0 ', '1', time(), time(), '1'],
  20. ['admin/finance/index', '财务管理', 'backend', '', '0', '1', '0', '999', 'tr_0 ', '1', time(), time(), '1'],
  21. ['admin/upgrade/index', '更新管理', 'backend', '', '0', '1', '0', '999', 'tr_0 ', '1', time(), time(), '1'],
  22. ];
  23. $this->batchInsert('qimall_rbac_auth_item', $column, $data);
  24. $platform_order = $this->db->createCommand("select * from qimall_rbac_auth_item where name = 'admin/platform-order/index' ")->queryAll();
  25. $pid = $platform_order[0]['id'];
  26. $finance = $this->db->createCommand("select * from qimall_rbac_auth_item where name = 'admin/finance/index' ")->queryAll();
  27. $finance_pid = $finance[0]['id'];
  28. $upgrade = $this->db->createCommand("select * from qimall_rbac_auth_item where name = 'admin/upgrade/index' ")->queryAll();
  29. $upgrade_pid = $upgrade[0]['id'];
  30. $data = [
  31. ['admin/platform-order/index', '订单列表', 'backend' , '',$pid, 2 , 0 , 999 ,'tr_0 tree_'.$pid, 1 , time(),time(),1],
  32. ['admin/finance/index', '账单明细', 'backend' , '',$finance_pid, 2 , 0 , 999 ,'tr_0 tree_'.$finance_pid, 1 , time(),time(),1],
  33. ['admin/upgrade/index', '更新记录', 'backend' , '',$upgrade_pid, 2 , 0 , 999 ,'tr_0 tree_'.$upgrade_pid, 1 , time(),time(),1],
  34. ];
  35. $this->db->createCommand()->batchInsert('qimall_rbac_auth_item', $column, $data)->execute();
  36. }
  37. $sql = "UPDATE `qimall_rbac_auth_item` SET `name`='admin/link/cate-index' WHERE (`name`='admin/link/cate') LIMIT 1";
  38. $this->execute($sql);
  39. }catch (\Exception $e){
  40. }
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function safeDown()
  46. {
  47. echo "M230202083942UpdateNameToRbacAuthItem cannot be reverted.\n";
  48. return false;
  49. }
  50. /*
  51. // Use up()/down() to run migration code without a transaction.
  52. public function up()
  53. {
  54. }
  55. public function down()
  56. {
  57. echo "M230202083942UpdateNameToRbacAuthItem cannot be reverted.\n";
  58. return false;
  59. }
  60. */
  61. }