20230620180908_install.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <?php
  2. use think\migration\Migrator;
  3. use Phinx\Db\Adapter\MysqlAdapter;
  4. class Install extends Migrator
  5. {
  6. public function change(): void
  7. {
  8. $this->admin();
  9. $this->adminGroup();
  10. $this->adminGroupAccess();
  11. $this->adminLog();
  12. $this->area();
  13. $this->attachment();
  14. $this->captcha();
  15. $this->config();
  16. $this->menuRule();
  17. $this->securityDataRecycle();
  18. $this->securityDataRecycleLog();
  19. $this->securitySensitiveData();
  20. $this->securitySensitiveDataLog();
  21. $this->testBuild();
  22. $this->token();
  23. $this->user();
  24. $this->userGroup();
  25. $this->userMoneyLog();
  26. $this->userRule();
  27. $this->userScoreLog();
  28. $this->crudLog();
  29. }
  30. public function admin(): void
  31. {
  32. if (!$this->hasTable('admin')) {
  33. $table = $this->table('admin', [
  34. 'id' => false,
  35. 'comment' => '管理员表',
  36. 'row_format' => 'DYNAMIC',
  37. 'primary_key' => 'id',
  38. 'collation' => 'utf8mb4_unicode_ci',
  39. ]);
  40. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  41. ->addColumn('username', 'string', ['limit' => 20, 'default' => '', 'comment' => '用户名', 'null' => false])
  42. ->addColumn('nickname', 'string', ['limit' => 50, 'default' => '', 'comment' => '昵称', 'null' => false])
  43. ->addColumn('avatar', 'string', ['limit' => 255, 'default' => '', 'comment' => '头像', 'null' => false])
  44. ->addColumn('email', 'string', ['limit' => 50, 'default' => '', 'comment' => '邮箱', 'null' => false])
  45. ->addColumn('mobile', 'string', ['limit' => 11, 'default' => '', 'comment' => '手机', 'null' => false])
  46. ->addColumn('loginfailure', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '登录失败次数', 'null' => false])
  47. ->addColumn('lastlogintime', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '上次登录时间'])
  48. ->addColumn('lastloginip', 'string', ['limit' => 50, 'default' => '', 'comment' => '上次登录IP', 'null' => false])
  49. ->addColumn('password', 'string', ['limit' => 32, 'default' => '', 'comment' => '密码', 'null' => false])
  50. ->addColumn('salt', 'string', ['limit' => 30, 'default' => '', 'comment' => '密码盐', 'null' => false])
  51. ->addColumn('motto', 'string', ['limit' => 255, 'default' => '', 'comment' => '签名', 'null' => false])
  52. ->addColumn('status', 'enum', ['values' => '0,1', 'default' => '1', 'comment' => '状态:0=禁用,1=启用', 'null' => false])
  53. ->addColumn('createtime', 'integer', ['limit' => 10, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  54. ->addColumn('updatetime', 'integer', ['limit' => 10, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  55. ->addIndex(['username'], [
  56. 'unique' => true,
  57. ])
  58. ->create();
  59. }
  60. }
  61. public function adminGroup(): void
  62. {
  63. if (!$this->hasTable('admin_group')) {
  64. $table = $this->table('admin_group', [
  65. 'id' => false,
  66. 'comment' => '管理分组表',
  67. 'row_format' => 'DYNAMIC',
  68. 'primary_key' => 'id',
  69. 'collation' => 'utf8mb4_unicode_ci',
  70. ]);
  71. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  72. ->addColumn('pid', 'integer', ['comment' => '上级分组', 'default' => 0, 'signed' => false, 'null' => false])
  73. ->addColumn('name', 'string', ['limit' => 100, 'default' => '', 'comment' => '组名', 'null' => false])
  74. ->addColumn('rules', 'text', ['null' => true, 'default' => null, 'comment' => '权限规则ID'])
  75. ->addColumn('status', 'enum', ['values' => '0,1', 'default' => '1', 'comment' => '状态:0=禁用,1=启用', 'null' => false])
  76. ->addColumn('updatetime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  77. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  78. ->create();
  79. }
  80. }
  81. public function adminGroupAccess(): void
  82. {
  83. if (!$this->hasTable('admin_group_access')) {
  84. $table = $this->table('admin_group_access', [
  85. 'id' => false,
  86. 'comment' => '管理分组映射表',
  87. 'row_format' => 'DYNAMIC',
  88. 'collation' => 'utf8mb4_unicode_ci',
  89. ]);
  90. $table->addColumn('uid', 'integer', ['comment' => '管理员ID', 'signed' => false, 'null' => false])
  91. ->addColumn('group_id', 'integer', ['comment' => '分组ID', 'signed' => false, 'null' => false])
  92. ->addIndex(['uid'], [
  93. 'type' => 'BTREE',
  94. ])
  95. ->addIndex(['group_id'], [
  96. 'type' => 'BTREE',
  97. ])
  98. ->create();
  99. }
  100. }
  101. public function adminLog(): void
  102. {
  103. if (!$this->hasTable('admin_log')) {
  104. $table = $this->table('admin_log', [
  105. 'id' => false,
  106. 'comment' => '管理员日志表',
  107. 'row_format' => 'DYNAMIC',
  108. 'primary_key' => 'id',
  109. 'collation' => 'utf8mb4_unicode_ci',
  110. ]);
  111. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  112. ->addColumn('admin_id', 'integer', ['comment' => '管理员ID', 'default' => 0, 'signed' => false, 'null' => false])
  113. ->addColumn('username', 'string', ['limit' => 20, 'default' => '', 'comment' => '管理员用户名', 'null' => false])
  114. ->addColumn('url', 'string', ['limit' => 1500, 'default' => '', 'comment' => '操作Url', 'null' => false])
  115. ->addColumn('title', 'string', ['limit' => 100, 'default' => '', 'comment' => '日志标题', 'null' => false])
  116. ->addColumn('data', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'null' => true, 'default' => null, 'comment' => '请求数据'])
  117. ->addColumn('ip', 'string', ['limit' => 50, 'default' => '', 'comment' => 'IP', 'null' => false])
  118. ->addColumn('useragent', 'string', ['limit' => 255, 'default' => '', 'comment' => 'User-Agent', 'null' => false])
  119. ->addColumn('createtime', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  120. ->create();
  121. }
  122. }
  123. public function area(): void
  124. {
  125. if (!$this->hasTable('area')) {
  126. $table = $this->table('area', [
  127. 'id' => false,
  128. 'comment' => '省份地区表',
  129. 'row_format' => 'DYNAMIC',
  130. 'primary_key' => 'id',
  131. 'collation' => 'utf8mb4_unicode_ci',
  132. ]);
  133. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  134. ->addColumn('pid', 'integer', ['comment' => '父id', 'null' => true, 'default' => null, 'signed' => false])
  135. ->addColumn('shortname', 'string', ['limit' => 100, 'null' => true, 'default' => null, 'comment' => '简称'])
  136. ->addColumn('name', 'string', ['limit' => 100, 'null' => true, 'default' => null, 'comment' => '名称'])
  137. ->addColumn('mergename', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '全称'])
  138. ->addColumn('level', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'null' => true, 'default' => null, 'comment' => '层级:1=省,2=市,3=区/县'])
  139. ->addColumn('pinyin', 'string', ['limit' => 100, 'null' => true, 'default' => null, 'comment' => '拼音'])
  140. ->addColumn('code', 'string', ['limit' => 100, 'null' => true, 'default' => null, 'comment' => '长途区号'])
  141. ->addColumn('zip', 'string', ['limit' => 100, 'null' => true, 'default' => null, 'comment' => '邮编'])
  142. ->addColumn('first', 'string', ['limit' => 50, 'null' => true, 'default' => null, 'comment' => '首字母'])
  143. ->addColumn('lng', 'string', ['limit' => 50, 'null' => true, 'default' => null, 'comment' => '经度'])
  144. ->addColumn('lat', 'string', ['limit' => 50, 'null' => true, 'default' => null, 'comment' => '纬度'])
  145. ->addIndex(['pid'], [
  146. 'type' => 'BTREE',
  147. ])
  148. ->create();
  149. }
  150. }
  151. public function attachment(): void
  152. {
  153. if (!$this->hasTable('attachment')) {
  154. $table = $this->table('attachment', [
  155. 'id' => false,
  156. 'comment' => '附件表',
  157. 'row_format' => 'DYNAMIC',
  158. 'primary_key' => 'id',
  159. 'collation' => 'utf8mb4_unicode_ci',
  160. ]);
  161. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  162. ->addColumn('topic', 'string', ['limit' => 20, 'default' => '', 'comment' => '细目', 'null' => false])
  163. ->addColumn('admin_id', 'integer', ['comment' => '上传管理员ID', 'default' => 0, 'signed' => false, 'null' => false])
  164. ->addColumn('user_id', 'integer', ['comment' => '上传用户ID', 'default' => 0, 'signed' => false, 'null' => false])
  165. ->addColumn('url', 'string', ['limit' => 255, 'default' => '', 'comment' => '物理路径', 'null' => false])
  166. ->addColumn('width', 'integer', ['comment' => '宽度', 'default' => 0, 'signed' => false, 'null' => false])
  167. ->addColumn('height', 'integer', ['comment' => '高度', 'default' => 0, 'signed' => false, 'null' => false])
  168. ->addColumn('name', 'string', ['limit' => 100, 'default' => '', 'comment' => '原始名称', 'null' => false])
  169. ->addColumn('size', 'integer', ['comment' => '大小', 'default' => 0, 'signed' => false, 'null' => false])
  170. ->addColumn('mimetype', 'string', ['limit' => 100, 'default' => '', 'comment' => 'mime类型', 'null' => false])
  171. ->addColumn('quote', 'integer', ['comment' => '上传(引用)次数', 'default' => 0, 'signed' => false, 'null' => false])
  172. ->addColumn('storage', 'string', ['limit' => 50, 'default' => '', 'comment' => '存储方式', 'null' => false])
  173. ->addColumn('sha1', 'string', ['limit' => 40, 'default' => '', 'comment' => 'sha1编码', 'null' => false])
  174. ->addColumn('createtime', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  175. ->addColumn('lastuploadtime', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '最后上传时间'])
  176. ->create();
  177. }
  178. }
  179. public function captcha(): void
  180. {
  181. if (!$this->hasTable('captcha')) {
  182. $table = $this->table('captcha', [
  183. 'id' => false,
  184. 'comment' => '验证码表',
  185. 'row_format' => 'DYNAMIC',
  186. 'primary_key' => 'key',
  187. 'collation' => 'utf8mb4_unicode_ci',
  188. ]);
  189. $table->addColumn('key', 'string', ['limit' => 32, 'default' => '', 'comment' => '验证码Key', 'null' => false])
  190. ->addColumn('code', 'string', ['limit' => 32, 'default' => '', 'comment' => '验证码(加密后)', 'null' => false])
  191. ->addColumn('captcha', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'null' => true, 'default' => null, 'comment' => '验证码数据'])
  192. ->addColumn('createtime', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  193. ->addColumn('expiretime', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '过期时间'])
  194. ->create();
  195. }
  196. }
  197. public function config(): void
  198. {
  199. if (!$this->hasTable('config')) {
  200. $table = $this->table('config', [
  201. 'id' => false,
  202. 'comment' => '系统配置',
  203. 'row_format' => 'DYNAMIC',
  204. 'primary_key' => 'id',
  205. 'collation' => 'utf8mb4_unicode_ci',
  206. ]);
  207. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  208. ->addColumn('name', 'string', ['limit' => 30, 'default' => '', 'comment' => '变量名', 'null' => false])
  209. ->addColumn('group', 'string', ['limit' => 30, 'default' => '', 'comment' => '分组', 'null' => false])
  210. ->addColumn('title', 'string', ['limit' => 50, 'default' => '', 'comment' => '变量标题', 'null' => false])
  211. ->addColumn('tip', 'string', ['limit' => 100, 'default' => '', 'comment' => '变量描述', 'null' => false])
  212. ->addColumn('type', 'string', ['limit' => 30, 'default' => '', 'comment' => '变量输入组件类型', 'null' => false])
  213. ->addColumn('value', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'null' => true, 'default' => null, 'comment' => '变量值'])
  214. ->addColumn('content', 'text', ['limit' => MysqlAdapter::TEXT_LONG, 'null' => true, 'default' => null, 'comment' => '字典数据'])
  215. ->addColumn('rule', 'string', ['limit' => 100, 'default' => '', 'comment' => '验证规则', 'null' => false])
  216. ->addColumn('extend', 'string', ['limit' => 255, 'default' => '', 'comment' => '扩展属性', 'null' => false])
  217. ->addColumn('allow_del', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '允许删除:0=否,1=是', 'null' => false])
  218. ->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
  219. ->addIndex(['name'], [
  220. 'unique' => true,
  221. ])
  222. ->create();
  223. }
  224. }
  225. public function menuRule(): void
  226. {
  227. if (!$this->hasTable('menu_rule') && !$this->hasTable('admin_rule')) {
  228. $table = $this->table('menu_rule', [
  229. 'id' => false,
  230. 'comment' => '菜单和权限规则表',
  231. 'row_format' => 'DYNAMIC',
  232. 'primary_key' => 'id',
  233. 'collation' => 'utf8mb4_unicode_ci',
  234. ]);
  235. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  236. ->addColumn('pid', 'integer', ['comment' => '上级菜单', 'default' => 0, 'signed' => false, 'null' => false])
  237. ->addColumn('type', 'enum', ['values' => 'menu_dir,menu,button', 'default' => 'menu', 'comment' => '类型:menu_dir=菜单目录,menu=菜单项,button=页面按钮', 'null' => false])
  238. ->addColumn('title', 'string', ['limit' => 50, 'default' => '', 'comment' => '标题', 'null' => false])
  239. ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '规则名称', 'null' => false])
  240. ->addColumn('path', 'string', ['limit' => 100, 'default' => '', 'comment' => '路由路径', 'null' => false])
  241. ->addColumn('icon', 'string', ['limit' => 50, 'default' => '', 'comment' => '图标', 'null' => false])
  242. ->addColumn('menu_type', 'enum', ['values' => 'tab,link,iframe', 'null' => true, 'default' => null, 'comment' => '菜单类型:tab=选项卡,link=链接,iframe=Iframe'])
  243. ->addColumn('url', 'string', ['limit' => 255, 'default' => '', 'comment' => 'Url', 'null' => false])
  244. ->addColumn('component', 'string', ['limit' => 100, 'default' => '', 'comment' => '组件路径', 'null' => false])
  245. ->addColumn('keepalive', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '缓存:0=关闭,1=开启', 'null' => false])
  246. ->addColumn('extend', 'enum', ['values' => 'none,add_rules_only,add_menu_only', 'default' => 'none', 'comment' => '扩展属性:none=无,add_rules_only=只添加为路由,add_menu_only=只添加为菜单', 'null' => false])
  247. ->addColumn('remark', 'string', ['limit' => 255, 'default' => '', 'comment' => '备注', 'null' => false])
  248. ->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
  249. ->addColumn('status', 'enum', ['values' => '0,1', 'default' => '1', 'comment' => '状态:0=禁用,1=启用', 'null' => false])
  250. ->addColumn('updatetime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  251. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  252. ->addIndex(['pid'], [
  253. 'type' => 'BTREE',
  254. ])
  255. ->create();
  256. }
  257. }
  258. public function securityDataRecycle(): void
  259. {
  260. if (!$this->hasTable('security_data_recycle')) {
  261. $table = $this->table('security_data_recycle', [
  262. 'id' => false,
  263. 'comment' => '回收规则表',
  264. 'row_format' => 'DYNAMIC',
  265. 'primary_key' => 'id',
  266. 'collation' => 'utf8mb4_unicode_ci',
  267. ]);
  268. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  269. ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '规则名称', 'null' => false])
  270. ->addColumn('controller', 'string', ['limit' => 100, 'default' => '', 'comment' => '控制器', 'null' => false])
  271. ->addColumn('controller_as', 'string', ['limit' => 100, 'default' => '', 'comment' => '控制器别名', 'null' => false])
  272. ->addColumn('data_table', 'string', ['limit' => 100, 'default' => '', 'comment' => '对应数据表', 'null' => false])
  273. ->addColumn('primary_key', 'string', ['limit' => 50, 'default' => '', 'comment' => '数据表主键', 'null' => false])
  274. ->addColumn('status', 'enum', ['values' => '0,1', 'default' => '1', 'comment' => '状态:0=禁用,1=启用', 'null' => false])
  275. ->addColumn('updatetime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  276. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  277. ->create();
  278. }
  279. }
  280. public function securityDataRecycleLog(): void
  281. {
  282. if (!$this->hasTable('security_data_recycle_log')) {
  283. $table = $this->table('security_data_recycle_log', [
  284. 'id' => false,
  285. 'comment' => '数据回收记录表',
  286. 'row_format' => 'DYNAMIC',
  287. 'primary_key' => 'id',
  288. 'collation' => 'utf8mb4_unicode_ci',
  289. ]);
  290. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  291. ->addColumn('admin_id', 'integer', ['comment' => '操作管理员', 'default' => 0, 'signed' => false, 'null' => false])
  292. ->addColumn('recycle_id', 'integer', ['comment' => '回收规则ID', 'default' => 0, 'signed' => false, 'null' => false])
  293. ->addColumn('data', 'text', ['null' => true, 'default' => null, 'comment' => '回收的数据'])
  294. ->addColumn('data_table', 'string', ['limit' => 100, 'default' => '', 'comment' => '数据表', 'null' => false])
  295. ->addColumn('primary_key', 'string', ['limit' => 50, 'default' => '', 'comment' => '数据表主键', 'null' => false])
  296. ->addColumn('is_restore', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '是否已还原:0=否,1=是', 'null' => false])
  297. ->addColumn('ip', 'string', ['limit' => 50, 'default' => '', 'comment' => '操作者IP', 'null' => false])
  298. ->addColumn('useragent', 'string', ['limit' => 255, 'default' => '', 'comment' => 'User-Agent', 'null' => false])
  299. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  300. ->create();
  301. }
  302. }
  303. public function securitySensitiveData(): void
  304. {
  305. if (!$this->hasTable('security_sensitive_data')) {
  306. $table = $this->table('security_sensitive_data', [
  307. 'id' => false,
  308. 'comment' => '敏感数据规则表',
  309. 'row_format' => 'DYNAMIC',
  310. 'primary_key' => 'id',
  311. 'collation' => 'utf8mb4_unicode_ci',
  312. ]);
  313. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  314. ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '规则名称', 'null' => false])
  315. ->addColumn('controller', 'string', ['limit' => 100, 'default' => '', 'comment' => '控制器', 'null' => false])
  316. ->addColumn('controller_as', 'string', ['limit' => 100, 'default' => '', 'comment' => '控制器别名', 'null' => false])
  317. ->addColumn('data_table', 'string', ['limit' => 100, 'default' => '', 'comment' => '对应数据表', 'null' => false])
  318. ->addColumn('primary_key', 'string', ['limit' => 50, 'default' => '', 'comment' => '数据表主键', 'null' => false])
  319. ->addColumn('data_fields', 'text', ['null' => true, 'default' => null, 'comment' => '敏感数据字段'])
  320. ->addColumn('status', 'enum', ['values' => '0,1', 'default' => '1', 'comment' => '状态:0=禁用,1=启用', 'null' => false])
  321. ->addColumn('updatetime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  322. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  323. ->create();
  324. }
  325. }
  326. public function securitySensitiveDataLog(): void
  327. {
  328. if (!$this->hasTable('security_sensitive_data_log')) {
  329. $table = $this->table('security_sensitive_data_log', [
  330. 'id' => false,
  331. 'comment' => '敏感数据修改记录',
  332. 'row_format' => 'DYNAMIC',
  333. 'primary_key' => 'id',
  334. 'collation' => 'utf8mb4_unicode_ci',
  335. ]);
  336. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  337. ->addColumn('admin_id', 'integer', ['comment' => '操作管理员', 'default' => 0, 'signed' => false, 'null' => false])
  338. ->addColumn('sensitive_id', 'integer', ['comment' => '敏感数据规则ID', 'default' => 0, 'signed' => false, 'null' => false])
  339. ->addColumn('data_table', 'string', ['limit' => 100, 'default' => '', 'comment' => '数据表', 'null' => false])
  340. ->addColumn('primary_key', 'string', ['limit' => 50, 'default' => '', 'comment' => '数据表主键', 'null' => false])
  341. ->addColumn('data_field', 'string', ['limit' => 50, 'default' => '', 'comment' => '被修改字段', 'null' => false])
  342. ->addColumn('data_comment', 'string', ['limit' => 50, 'default' => '', 'comment' => '被修改项', 'null' => false])
  343. ->addColumn('id_value', 'integer', ['comment' => '被修改项主键值', 'default' => 0, 'null' => false])
  344. ->addColumn('before', 'text', ['null' => true, 'default' => null, 'comment' => '修改前'])
  345. ->addColumn('after', 'text', ['null' => true, 'default' => null, 'comment' => '修改后'])
  346. ->addColumn('ip', 'string', ['limit' => 50, 'default' => '', 'comment' => '操作者IP', 'null' => false])
  347. ->addColumn('useragent', 'string', ['limit' => 255, 'default' => '', 'comment' => 'User-Agent', 'null' => false])
  348. ->addColumn('is_rollback', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '是否已回滚:0=否,1=是', 'null' => false])
  349. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  350. ->create();
  351. }
  352. }
  353. public function testBuild(): void
  354. {
  355. if (!$this->hasTable('test_build')) {
  356. $table = $this->table('test_build', [
  357. 'id' => false,
  358. 'comment' => '知识库表',
  359. 'row_format' => 'DYNAMIC',
  360. 'primary_key' => 'id',
  361. 'collation' => 'utf8mb4_unicode_ci',
  362. ]);
  363. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  364. ->addColumn('title', 'string', ['limit' => 100, 'default' => '', 'comment' => '标题', 'null' => false])
  365. ->addColumn('keyword_rows', 'string', ['limit' => 100, 'default' => '', 'comment' => '关键词', 'null' => false])
  366. ->addColumn('content', 'text', ['null' => true, 'default' => null, 'comment' => '内容'])
  367. ->addColumn('views', 'integer', ['comment' => '浏览量', 'default' => 0, 'signed' => false, 'null' => false])
  368. ->addColumn('likes', 'integer', ['comment' => '有帮助数', 'default' => 0, 'signed' => false, 'null' => false])
  369. ->addColumn('dislikes', 'integer', ['comment' => '无帮助数', 'default' => 0, 'signed' => false, 'null' => false])
  370. ->addColumn('note_textarea', 'string', ['limit' => 100, 'default' => '', 'comment' => '备注', 'null' => false])
  371. ->addColumn('status', 'enum', ['values' => '0,1', 'default' => '1', 'comment' => '状态:0=隐藏,1=正常', 'null' => false])
  372. ->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
  373. ->addColumn('update_time', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  374. ->addColumn('create_time', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  375. ->create();
  376. }
  377. }
  378. public function token(): void
  379. {
  380. if (!$this->hasTable('token')) {
  381. $table = $this->table('token', [
  382. 'id' => false,
  383. 'comment' => '用户Token表',
  384. 'row_format' => 'DYNAMIC',
  385. 'primary_key' => 'token',
  386. 'collation' => 'utf8mb4_unicode_ci',
  387. ]);
  388. $table->addColumn('token', 'string', ['limit' => 50, 'default' => '', 'comment' => 'Token', 'null' => false])
  389. ->addColumn('type', 'string', ['limit' => 15, 'default' => '', 'comment' => '类型', 'null' => false])
  390. ->addColumn('user_id', 'integer', ['comment' => '用户ID', 'default' => 0, 'signed' => false, 'null' => false])
  391. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  392. ->addColumn('expiretime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '过期时间'])
  393. ->create();
  394. }
  395. }
  396. public function user(): void
  397. {
  398. if (!$this->hasTable('user')) {
  399. $table = $this->table('user', [
  400. 'id' => false,
  401. 'comment' => '会员表',
  402. 'row_format' => 'DYNAMIC',
  403. 'primary_key' => 'id',
  404. 'collation' => 'utf8mb4_unicode_ci',
  405. ]);
  406. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  407. ->addColumn('group_id', 'integer', ['comment' => '分组ID', 'default' => 0, 'signed' => false, 'null' => false])
  408. ->addColumn('username', 'string', ['limit' => 32, 'default' => '', 'comment' => '用户名', 'null' => false])
  409. ->addColumn('nickname', 'string', ['limit' => 50, 'default' => '', 'comment' => '昵称', 'null' => false])
  410. ->addColumn('email', 'string', ['limit' => 50, 'default' => '', 'comment' => '邮箱', 'null' => false])
  411. ->addColumn('mobile', 'string', ['limit' => 11, 'default' => '', 'comment' => '手机', 'null' => false])
  412. ->addColumn('avatar', 'string', ['limit' => 255, 'default' => '', 'comment' => '头像', 'null' => false])
  413. ->addColumn('gender', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '性别:0=未知,1=男,2=女', 'null' => false])
  414. ->addColumn('birthday', 'date', ['null' => true, 'default' => null, 'comment' => '生日'])
  415. ->addColumn('money', 'integer', ['comment' => '余额', 'default' => 0, 'signed' => false, 'null' => false])
  416. ->addColumn('score', 'integer', ['comment' => '积分', 'default' => 0, 'signed' => false, 'null' => false])
  417. ->addColumn('lastlogintime', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '上次登录时间'])
  418. ->addColumn('lastloginip', 'string', ['limit' => 50, 'default' => '', 'comment' => '上次登录IP', 'null' => false])
  419. ->addColumn('loginfailure', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '登录失败次数', 'null' => false])
  420. ->addColumn('joinip', 'string', ['limit' => 50, 'default' => '', 'comment' => '加入IP', 'null' => false])
  421. ->addColumn('jointime', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '加入时间'])
  422. ->addColumn('motto', 'string', ['limit' => 255, 'default' => '', 'comment' => '签名', 'null' => false])
  423. ->addColumn('password', 'string', ['limit' => 32, 'default' => '', 'comment' => '密码', 'null' => false])
  424. ->addColumn('salt', 'string', ['limit' => 30, 'default' => '', 'comment' => '密码盐', 'null' => false])
  425. ->addColumn('status', 'string', ['limit' => 30, 'default' => '', 'comment' => '状态', 'null' => false])
  426. ->addColumn('updatetime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  427. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  428. ->addIndex(['username'], [
  429. 'unique' => true,
  430. ])
  431. ->addIndex(['email'], [
  432. 'unique' => true,
  433. ])
  434. ->addIndex(['mobile'], [
  435. 'unique' => true,
  436. ])
  437. ->create();
  438. }
  439. }
  440. public function userGroup(): void
  441. {
  442. if (!$this->hasTable('user_group')) {
  443. $table = $this->table('user_group', [
  444. 'id' => false,
  445. 'comment' => '会员组表',
  446. 'row_format' => 'DYNAMIC',
  447. 'primary_key' => 'id',
  448. 'collation' => 'utf8mb4_unicode_ci',
  449. ]);
  450. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  451. ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '组名', 'null' => false])
  452. ->addColumn('rules', 'text', ['null' => true, 'default' => null, 'comment' => '权限节点'])
  453. ->addColumn('status', 'enum', ['values' => '0,1', 'default' => '1', 'comment' => '状态:0=禁用,1=启用', 'null' => false])
  454. ->addColumn('updatetime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  455. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  456. ->create();
  457. }
  458. }
  459. public function userMoneyLog(): void
  460. {
  461. if (!$this->hasTable('user_money_log')) {
  462. $table = $this->table('user_money_log', [
  463. 'id' => false,
  464. 'comment' => '会员余额变动表',
  465. 'row_format' => 'DYNAMIC',
  466. 'primary_key' => 'id',
  467. 'collation' => 'utf8mb4_unicode_ci',
  468. ]);
  469. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  470. ->addColumn('user_id', 'integer', ['comment' => '会员ID', 'default' => 0, 'signed' => false, 'null' => false])
  471. ->addColumn('money', 'integer', ['comment' => '变更余额', 'default' => 0, 'null' => false])
  472. ->addColumn('before', 'integer', ['comment' => '变更前余额', 'default' => 0, 'null' => false])
  473. ->addColumn('after', 'integer', ['comment' => '变更后余额', 'default' => 0, 'null' => false])
  474. ->addColumn('memo', 'string', ['limit' => 255, 'default' => '', 'comment' => '备注', 'null' => false])
  475. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  476. ->create();
  477. }
  478. }
  479. public function userRule(): void
  480. {
  481. if (!$this->hasTable('user_rule')) {
  482. $table = $this->table('user_rule', [
  483. 'id' => false,
  484. 'comment' => '会员菜单权限规则表',
  485. 'row_format' => 'DYNAMIC',
  486. 'primary_key' => 'id',
  487. 'collation' => 'utf8mb4_unicode_ci',
  488. ]);
  489. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  490. ->addColumn('pid', 'integer', ['comment' => '上级菜单', 'default' => 0, 'signed' => false, 'null' => false])
  491. ->addColumn('type', 'enum', ['values' => 'route,menu_dir,menu,nav_user_menu,nav,button', 'default' => 'menu', 'comment' => '类型:route=路由,menu_dir=菜单目录,menu=菜单项,nav_user_menu=顶栏会员菜单下拉项,nav=顶栏菜单项,button=页面按钮', 'null' => false])
  492. ->addColumn('title', 'string', ['limit' => 50, 'default' => '', 'comment' => '标题', 'null' => false])
  493. ->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '规则名称', 'null' => false])
  494. ->addColumn('path', 'string', ['limit' => 100, 'default' => '', 'comment' => '路由路径', 'null' => false])
  495. ->addColumn('icon', 'string', ['limit' => 50, 'default' => '', 'comment' => '图标', 'null' => false])
  496. ->addColumn('menu_type', 'enum', ['values' => 'tab,link,iframe', 'default' => 'tab', 'comment' => '菜单类型:tab=选项卡,link=链接,iframe=Iframe', 'null' => false])
  497. ->addColumn('url', 'string', ['limit' => 255, 'default' => '', 'comment' => 'Url', 'null' => false])
  498. ->addColumn('component', 'string', ['limit' => 100, 'default' => '', 'comment' => '组件路径', 'null' => false])
  499. ->addColumn('no_login_valid', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '未登录有效:0=否,1=是', 'null' => false])
  500. ->addColumn('extend', 'enum', ['values' => 'none,add_rules_only,add_menu_only', 'default' => 'none', 'comment' => '扩展属性:none=无,add_rules_only=只添加为路由,add_menu_only=只添加为菜单', 'null' => false])
  501. ->addColumn('remark', 'string', ['limit' => 255, 'default' => '', 'comment' => '备注', 'null' => false])
  502. ->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false])
  503. ->addColumn('status', 'enum', ['values' => '0,1', 'default' => '1', 'comment' => '状态:0=禁用,1=启用', 'null' => false])
  504. ->addColumn('updatetime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间'])
  505. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  506. ->addIndex(['pid'], [
  507. 'type' => 'BTREE',
  508. ])
  509. ->create();
  510. }
  511. }
  512. public function userScoreLog(): void
  513. {
  514. if (!$this->hasTable('user_score_log')) {
  515. $table = $this->table('user_score_log', [
  516. 'id' => false,
  517. 'comment' => '会员积分变动表',
  518. 'row_format' => 'DYNAMIC',
  519. 'primary_key' => 'id',
  520. 'collation' => 'utf8mb4_unicode_ci',
  521. ]);
  522. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  523. ->addColumn('user_id', 'integer', ['comment' => '会员ID', 'default' => 0, 'signed' => false, 'null' => false])
  524. ->addColumn('score', 'integer', ['comment' => '变更积分', 'default' => 0, 'null' => false])
  525. ->addColumn('before', 'integer', ['comment' => '变更前积分', 'default' => 0, 'null' => false])
  526. ->addColumn('after', 'integer', ['comment' => '变更后积分', 'default' => 0, 'null' => false])
  527. ->addColumn('memo', 'string', ['limit' => 255, 'default' => '', 'comment' => '备注', 'null' => false])
  528. ->addColumn('createtime', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  529. ->create();
  530. }
  531. }
  532. public function crudLog(): void
  533. {
  534. if (!$this->hasTable('crud_log')) {
  535. $table = $this->table('crud_log', [
  536. 'id' => false,
  537. 'comment' => 'CRUD记录表',
  538. 'row_format' => 'DYNAMIC',
  539. 'primary_key' => 'id',
  540. 'collation' => 'utf8mb4_unicode_ci',
  541. ]);
  542. $table->addColumn('id', 'integer', ['comment' => 'ID', 'signed' => false, 'identity' => true, 'null' => false])
  543. ->addColumn('table_name', 'string', ['limit' => 200, 'default' => '', 'comment' => '数据表名', 'null' => false])
  544. ->addColumn('table', 'text', ['null' => true, 'default' => null, 'comment' => '数据表数据'])
  545. ->addColumn('fields', 'text', ['null' => true, 'default' => null, 'comment' => '字段数据'])
  546. ->addColumn('status', 'enum', ['values' => 'delete,success,error,start', 'default' => 'start', 'comment' => '状态:delete=已删除,success=成功,error=失败,start=生成中', 'null' => false])
  547. ->addColumn('create_time', 'biginteger', ['signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间'])
  548. ->create();
  549. }
  550. }
  551. }