M231214090725InsertQimallMenu.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\migrations;
  3. use common\models\backend\Menu;
  4. use yii\db\Migration;
  5. /**
  6. * Class M230713150123InsertQimallMenu
  7. */
  8. class M231214090725InsertQimallMenu extends Migration
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function safeUp()
  14. {
  15. try {
  16. $data = [
  17. [
  18. 'cate_id' => '2',// 类型[1=平台,2=商城]
  19. 'pid' => '38',
  20. 'title' => '短信日志',
  21. 'route' => 'mall/sms/index',
  22. 'icon' => '',
  23. 'authItemChild' => [// 子菜单权限,此参数若为空则表示无需增加子菜单权限)
  24. ]
  25. ]
  26. ];
  27. $res = Menu::migrateCreateMenu($data);
  28. if ($res === false) throw new \Exception(Menu::getStaticError());
  29. $sql = 'ALTER TABLE `qimall_sms_log`
  30. DROP INDEX `mall_id`,
  31. ADD INDEX `mall_id+ip`(`mall_id`, `ip`) USING BTREE,
  32. ADD INDEX `mall_id+mobile`(`mall_id`, `mobile`);';
  33. $this->execute($sql);
  34. }catch (\Exception $e){
  35. \Yii::error('迁移错误:' . $e->getMessage());
  36. }
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function safeDown()
  42. {
  43. echo "M230713150123InsertQimallMenu cannot be reverted.\n";
  44. return false;
  45. }
  46. /*
  47. // Use up()/down() to run migration code without a transaction.
  48. public function up()
  49. {
  50. }
  51. public function down()
  52. {
  53. echo "M230713150123InsertQimallMenu cannot be reverted.\n";
  54. return false;
  55. }
  56. */
  57. }