20220714062212_create_company_strength.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. use app\model\Permission;
  5. use app\model\Grant;
  6. class CreateCompanyStrength extends Migrator
  7. {
  8. /**
  9. * Change Method.
  10. *
  11. * Write your reversible migrations using this method.
  12. *
  13. * More information on writing migrations is available here:
  14. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  15. *
  16. * The following commands can be used in this method and Phinx will
  17. * automatically reverse them when rolling back:
  18. *
  19. * createTable
  20. * renameTable
  21. * addColumn
  22. * renameColumn
  23. * addIndex
  24. * addForeignKey
  25. *
  26. * Remember to call "create()" or "update()" and NOT "save()" when working
  27. * with the Table class.
  28. */
  29. public function change()
  30. {
  31. //公司实力菜单
  32. $menu = [
  33. 'pid' => 1,
  34. 'uri' => 'companyStrength/index',
  35. 'auth_name' => '公司实力',
  36. 'is_menu' => 1,
  37. 'sort' => 50,
  38. 'relation' => 'companyStrength/index'
  39. ];
  40. $id = Permission::insertGetId($menu);
  41. //建表
  42. $table = $this->table('company_strength')->setComment('公司实力');
  43. $table->addColumn('root_id', 'integer', ['limit' => 10, 'comment' => '店面id', 'null' => true, 'default' => 0])
  44. ->addColumn('cate', 'string', ['limit' => 250, 'comment' => '分类', 'null' => true, 'default' => ''])
  45. ->addColumn('title', 'string', ['limit' => 255, 'comment' => '标题', 'null' => true, 'default' => ''])
  46. ->addColumn('media_ids', 'string', ['limit' => 255, 'comment' => '媒体链接', 'null' => true, 'default' => ''])
  47. ->addColumn('pics', 'string', ['limit' => 255, 'comment' => '图片/视频地址', 'null' => true, 'default' => ''])
  48. ->addColumn('cover', 'string', ['limit' => 255, 'comment' => '图片/视频封面图', 'null' => true, 'default' => ''])
  49. ->addColumn('desc', 'text', ['comment'=> '描述', 'null'=> true])
  50. ->addColumn('shared_times', 'integer', ['limit' => 10, 'comment' => '分享次数', 'null' => true, 'default' => 0])
  51. ->addColumn('addtime', 'timestamp', ['comment' => '添加时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
  52. ->addColumn('updatetime', 'timestamp', ['comment' => '修改时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
  53. ->addColumn('del', 'integer', ['limit' => 10, 'comment' => '1删除', 'null' => true, 'default' => 0])
  54. ->addColumn('publish', 'integer', ['limit' => 10, 'comment' => '1上架,0下架', 'null' => true, 'default' => 1])
  55. ->addColumn('view_times', 'integer', ['limit' => 10, 'comment' => '浏览次数', 'null' => true, 'default' => 0])
  56. ->addColumn('employee_id', 'integer', ['limit' => 10, 'comment' => '上传人员', 'null' => true, 'default' => 0])
  57. ->addColumn('difference', 'integer', ['limit' => 10, 'comment' => '1视频,2图文', 'null' => true, 'default' => 2])
  58. ->create();
  59. $table = $this->table('company_strength_cate')->setComment('公司实力分类');
  60. $table->addColumn('root_id', 'integer', ['limit' => 10, 'comment' => '店面id', 'null' => true, 'default' => 0])
  61. ->addColumn('name', 'string', ['limit' => 250, 'comment' => '分类', 'null' => true, 'default' => ''])
  62. ->addColumn('addtime', 'timestamp', ['comment' => '添加时间', 'default' => 'CURRENT_TIMESTAMP', 'null' => true])
  63. ->create();
  64. //菜单权限
  65. $info = Grant::where('id',1)->find();
  66. $pids = (array)$info->permission;
  67. $pids[] = (int)$id;
  68. $info->permission = array_values($pids);
  69. $info->save();
  70. //权限
  71. $per = ',companyStrength/list,companyStrength/apipublish,companyStrength/add,companyStrength/adding,companyStrength/edit,companyStrength/editing,companyStrength/del,companyStrength/imgUpload';
  72. $w[] = ['auth_name', '=', '公司实力'];
  73. $w[] = ['pid', '>', 0];
  74. $w[] = ['is_menu', '=', 1];
  75. $info = Permission::where($w)->find();
  76. $per = $info->relation . $per;
  77. $info->relation = $per;
  78. $info->save();
  79. }
  80. }