update.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <?php
  2. if (!function_exists('tablename_sql')) {
  3. function tablename_sql($name)
  4. {
  5. return config('database.connections.mysql.prefix') . '' . $name;
  6. }
  7. }
  8. if (!function_exists('fieldexists_sql')) {
  9. function fieldexists_sql($tablename_sql, $fieldname, $ispre = false)
  10. {
  11. $fields = \think\facade\Db::query("SHOW COLUMNS FROM " . ($ispre ? $tablename_sql : tablename_sql($tablename_sql)));
  12. if (empty($fields)) {
  13. return false;
  14. }
  15. foreach ($fields as $field) {
  16. if ($fieldname === $field['Field']) {
  17. return true;
  18. }
  19. }
  20. return false;
  21. }
  22. }
  23. function check_sql($tablename_sql, $id, $ispre = false)
  24. {
  25. $fields = \think\facade\Db::query("SELECT * FROM " . ($ispre ? $tablename_sql : tablename_sql($tablename_sql)) ." where id=" .$id);
  26. if (empty($fields)) {
  27. return false;
  28. }
  29. return true;
  30. }
  31. if (!function_exists('execute_db_sql')) {
  32. function execute_db_sql($sql)
  33. {
  34. return \think\facade\Db::execute($sql);
  35. }
  36. }
  37. if (!function_exists('query__db_sql')) {
  38. function query__db_sql($sql)
  39. {
  40. return \think\facade\Db::query($sql);
  41. }
  42. }
  43. if(!check_sql('admin_menu','123')){
  44. query__db_sql("insert into " . tablename_sql('admin_menu') . "
  45. (`id`, `name`, `href`, `open_type`, `rule`, `is_menu`, `sort`, `pid`, `is_show`, `icon`, `des`, `create_time`, `update_time`, `delete_time`) VALUES
  46. (123, 'AI绘画', '', '_iframe', '', 1, 4, 1, 1, 'layui-icon layui-icon-tree', NULL, '2023-03-08 13:18:12', '2023-03-08 13:18:12', NULL)
  47. ");
  48. }
  49. if(!check_sql('admin_menu','124')){
  50. query__db_sql("insert into " . tablename_sql('admin_menu') . "
  51. (`id`, `name`, `href`, `open_type`, `rule`, `is_menu`, `sort`, `pid`, `is_show`, `icon`, `des`, `create_time`, `update_time`, `delete_time`) VALUES
  52. (124, '艺术画展', '/admin/painting/gallery/index.html', '_iframe', '', 1, 0, 123, 1, '', NULL, '2023-03-08 13:18:12', '2023-03-08 13:18:12', NULL)
  53. ");
  54. }
  55. if(!check_sql('admin_menu','125')){
  56. query__db_sql("insert into " . tablename_sql('admin_menu') . "
  57. (`id`, `name`, `href`, `open_type`, `rule`, `is_menu`, `sort`, `pid`, `is_show`, `icon`, `des`, `create_time`, `update_time`, `delete_time`) VALUES
  58. (125, '文案词条', '/admin/painting/words/index.html', '_iframe', '', 1, 0, 123, 1, '', NULL, '2023-03-08 13:18:12', '2023-03-08 13:18:12', NULL)
  59. ");
  60. }
  61. if(!check_sql('admin_menu','128')){
  62. query__db_sql("insert into " . tablename_sql('admin_menu') . "
  63. (`id`, `name`, `href`, `open_type`, `rule`, `is_menu`, `sort`, `pid`, `is_show`, `icon`, `des`, `create_time`, `update_time`, `delete_time`) VALUES
  64. (128, '入驻订单', '/admin/commission/settle.html', '_iframe', '', 1, 0, 90, 1, '', NULL, '2023-03-08 13:18:12', '2023-03-08 13:18:12', NULL)
  65. ");
  66. }
  67. if(!check_sql('admin_menu','129')){
  68. query__db_sql("insert into " . tablename_sql('admin_menu') . "
  69. (`id`, `name`, `href`, `open_type`, `rule`, `is_menu`, `sort`, `pid`, `is_show`, `icon`, `des`, `create_time`, `update_time`, `delete_time`) VALUES
  70. (129, '模型', '/admin/painting/models/index.html', '_iframe', '', 1, 0, 123, 1, '', NULL, '2023-03-08 13:18:12', '2023-03-08 13:18:12', NULL)
  71. ");
  72. }
  73. if(!check_sql('admin_menu','130')){
  74. query__db_sql("insert into " . tablename_sql('admin_menu') . "
  75. (`id`, `name`, `href`, `open_type`, `rule`, `is_menu`, `sort`, `pid`, `is_show`, `icon`, `des`, `create_time`, `update_time`, `delete_time`) VALUES
  76. (130, '会员', '/admin/vipinfo/index.html', '_iframe', '', 1, 0, 91, 1, '', NULL, '2023-03-08 13:18:12', '2023-03-08 13:18:12', NULL)
  77. ");
  78. }
  79. if(!check_sql('admin_menu','131')){
  80. query__db_sql("insert into " . tablename_sql('admin_menu') . "
  81. (`id`, `name`, `href`, `open_type`, `rule`, `is_menu`, `sort`, `pid`, `is_show`, `icon`, `des`, `create_time`, `update_time`, `delete_time`) VALUES
  82. (131, '分销海报', '/admin/commission/poster.html', '_iframe', '', 1, 0, 90, 1, '', NULL, '2023-03-08 13:18:12', '2023-03-08 13:18:12', NULL)
  83. ");
  84. }
  85. if(!check_sql('admin_menu','132')){
  86. query__db_sql("insert into " . tablename_sql('admin_menu') . "
  87. (`id`, `name`, `href`, `open_type`, `rule`, `is_menu`, `sort`, `pid`, `is_show`, `icon`, `des`, `create_time`, `update_time`, `delete_time`) VALUES
  88. (132, '四方支付', '/admin/conf/system/yipay.html', '_iframe', '', 1, 0, 35, 1, '', NULL, '2023-03-08 13:18:12', '2023-03-08 13:18:12', NULL)
  89. ");
  90. }
  91. query__db_sql("CREATE TABLE IF NOT EXISTS " . tablename_sql("gallery") . "(
  92. `id` int(11) NOT NULL AUTO_INCREMENT,
  93. `uniacid` int(10) UNSIGNED NOT NULL,
  94. `status` tinyint(1) NOT NULL DEFAULT '2' COMMENT '状态.2=锁定,1=正常,默认:2 ',
  95. `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序,从大到小,倒叙排序 ',
  96. `create_time` datetime NOT NULL,
  97. `update_time` datetime NOT NULL,
  98. `delete_time` datetime DEFAULT NULL,
  99. `uid` int(11) UNSIGNED NOT NULL,
  100. `job_id` varchar(64) NOT NULL COMMENT '任务ID ',
  101. `prompt` text COMMENT '描述词',
  102. `img` varchar(32) DEFAULT NULL COMMENT '图片',
  103. `paid_coin` varchar(64) NOT NULL COMMENT '支付的金币',
  104. `mode` varchar(32) DEFAULT NULL COMMENT '文生图或图生图',
  105. `origin_url` varchar(500) DEFAULT NULL COMMENT '原始路径',
  106. `engine` varchar(32) DEFAULT NULL COMMENT '引擎',
  107. `api_id` int(11) DEFAULT 0 COMMENT 'api_id',
  108. `model_id` varchar(128) DEFAULT NULL COMMENT '模型id',
  109. `width` int(11) DEFAULT 0 COMMENT '宽',
  110. `height` int(11) DEFAULT 0 COMMENT '高',
  111. `seed` varchar(128) DEFAULT NULL COMMENT '种子',
  112. `steps` int(5) DEFAULT 0 COMMENT '步数',
  113. `n_samples` int(2) DEFAULT 0 COMMENT '张数',
  114. `scheduler` varchar(128) DEFAULT NULL COMMENT '采样器',
  115. `mj_id` varchar(32) DEFAULT NULL COMMENT 'mj id',
  116. `mj_hash` varchar(128) DEFAULT NULL COMMENT 'mj hash',
  117. `done` tinyint(1) DEFAULT 0 COMMENT 'done',
  118. `uuid` varchar(128) DEFAULT NULL COMMENT 'uuid',
  119. `is_open` tinyint(1) DEFAULT 0 COMMENT '是否公开',
  120. `mj_action` varchar(128) DEFAULT NULL COMMENT 'mj action',
  121. `pid` int(11) DEFAULT 0 COMMENT 'pid',
  122. `real_prompt` varchar(2000) DEFAULT NULL COMMENT 'real_prompt',
  123. PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
  124. ");
  125. query__db_sql("CREATE TABLE IF NOT EXISTS " . tablename_sql("commission_settle") . "(
  126. `id` int(11) NOT NULL AUTO_INCREMENT,
  127. `uid` int(10) UNSIGNED NOT NULL DEFAULT '0',
  128. `uniacid` int(10) UNSIGNED NOT NULL DEFAULT '0',
  129. `create_time` datetime NOT NULL,
  130. `update_time` datetime NOT NULL,
  131. `order_number` varchar(32) NOT NULL COMMENT '订单编号',
  132. `paid` tinyint(1) NOT NULL DEFAULT '0' COMMENT '支付状态 0: 未支付 1:已支付',
  133. `pay_price` decimal(10,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '支付金额',
  134. `pay_type` varchar(32) DEFAULT NULL COMMENT '支付方式',
  135. `pay_time` int(10) DEFAULT '0' COMMENT '确认支付完成时间',
  136. `real_name` varchar(32) DEFAULT NULL COMMENT '姓名',
  137. `telnum` varchar(32) DEFAULT NULL COMMENT '手机号',
  138. PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
  139. ");
  140. query__db_sql("CREATE TABLE IF NOT EXISTS " . tablename_sql("words") . "(
  141. `id` int(11) NOT NULL AUTO_INCREMENT,
  142. `uniacid` int(10) UNSIGNED NOT NULL,
  143. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态.2=锁定,1=正常,默认:1 ',
  144. `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序,从大到小,倒叙排序 ',
  145. `create_time` datetime NOT NULL,
  146. `update_time` datetime NOT NULL,
  147. `delete_time` datetime DEFAULT NULL,
  148. `type` varchar(32) NOT NULL DEFAULT 'word' COMMENT '类型,句子或词',
  149. `name` varchar(500) NOT NULL COMMENT '名称',
  150. `guide` varchar(2000) DEFAULT NULL COMMENT '引导',
  151. PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
  152. ");
  153. query__db_sql("CREATE TABLE IF NOT EXISTS " . tablename_sql("models") . "(
  154. `id` int(11) NOT NULL AUTO_INCREMENT,
  155. `uniacid` int(10) UNSIGNED NOT NULL,
  156. `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态.2=锁定,1=正常,默认:1 ',
  157. `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序,从大到小,倒叙排序 ',
  158. `create_time` datetime NOT NULL,
  159. `update_time` datetime NOT NULL,
  160. `delete_time` datetime DEFAULT NULL,
  161. `name` varchar(500) NOT NULL COMMENT '名称',
  162. `intro` varchar(2000) DEFAULT NULL,
  163. `imgs` varchar(128) DEFAULT NULL,
  164. `coin` int(10) DEFAULT 0,
  165. `code` varchar(32) DEFAULT NULL,
  166. `model_id` varchar(128) NOT NULL,
  167. `type` varchar(32) DEFAULT NULL,
  168. `engine` varchar(32) DEFAULT NULL,
  169. `lora` varchar(128) DEFAULT NULL,
  170. `version` varchar(32) DEFAULT NULL,
  171. PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
  172. ");
  173. query__db_sql("CREATE TABLE IF NOT EXISTS " . tablename_sql("vipinfo") . "(
  174. `uid` int(11) NOT NULL DEFAULT 0,
  175. `uniacid` int(10) UNSIGNED NOT NULL,
  176. `create_time` datetime NOT NULL,
  177. `update_time` datetime NOT NULL,
  178. `order_number` varchar(32) DEFAULT NULL,
  179. `member_id` int(11) NOT NULL DEFAULT 0,
  180. `gpt35_times` int(11) NOT NULL DEFAULT 0,
  181. `gpt4_times` int(11) NOT NULL DEFAULT 0,
  182. `sd_times` int(11) NOT NULL DEFAULT 0,
  183. `mj_times` int(11) NOT NULL DEFAULT 0,
  184. `gpt35_type` varchar(32) NOT NULL DEFAULT 'time',
  185. `gpt4_type` varchar(32) NOT NULL DEFAULT 'time',
  186. `sd_type` varchar(32) NOT NULL DEFAULT 'time',
  187. `mj_type` varchar(32) NOT NULL DEFAULT 'time',
  188. PRIMARY KEY (`uid`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
  189. ");
  190. if (!fieldexists_sql('user', 'account')) {
  191. query__db_sql("ALTER TABLE " . tablename_sql('user') . " ADD `account` varchar(100);");
  192. }
  193. if (!fieldexists_sql('commission_user', 'real_name')) {
  194. query__db_sql("ALTER TABLE " . tablename_sql('commission_user') . " ADD `real_name` varchar(64) DEFAULT NULL COMMENT '真实姓名';");
  195. }
  196. if (!fieldexists_sql('commission_user', 'qrcode_wechat')) {
  197. query__db_sql("ALTER TABLE " . tablename_sql('commission_user') . " ADD `qrcode_wechat` varchar(128) DEFAULT NULL COMMENT '收款码';");
  198. }
  199. if (!fieldexists_sql('commission_user', 'alipay')) {
  200. query__db_sql("ALTER TABLE " . tablename_sql('commission_user') . " ADD `alipay` varchar(128) DEFAULT NULL COMMENT '支付宝';");
  201. }
  202. if (!fieldexists_sql('commission_team', 'gfid')) {
  203. query__db_sql("ALTER TABLE " . tablename_sql('commission_team') . " ADD `gfid` int(10) DEFAULT 0 ;");
  204. }
  205. if (!fieldexists_sql('commission_user', 'telnum')) {
  206. query__db_sql("ALTER TABLE " . tablename_sql('commission_user') . " ADD `telnum` varchar(32) DEFAULT NULL ;");
  207. }
  208. if (!fieldexists_sql('commission_user', 'paid')) {
  209. query__db_sql("ALTER TABLE " . tablename_sql('commission_user') . " ADD `paid` int(10) DEFAULT 1 ;");
  210. }
  211. if (!fieldexists_sql('commission_income', 'oid')) {
  212. query__db_sql("ALTER TABLE " . tablename_sql('commission_income') . " ADD `oid` int(10) DEFAULT 0 ;");
  213. }
  214. if (!fieldexists_sql('commission_income', 'buy_uid')) {
  215. query__db_sql("ALTER TABLE " . tablename_sql('commission_income') . " ADD `buy_uid` int(10) DEFAULT 0 ;");
  216. }
  217. if (!fieldexists_sql('commission_income', 'buy_price')) {
  218. query__db_sql("ALTER TABLE " . tablename_sql('commission_income') . " ADD `buy_price` decimal(8,2) NOT NULL DEFAULT '0.00';");
  219. }
  220. if (!fieldexists_sql('commission_settle', 'real_name')) {
  221. query__db_sql("ALTER TABLE " . tablename_sql('commission_settle') . " ADD `real_name` varchar(32) DEFAULT NULL;");
  222. }
  223. if (!fieldexists_sql('commission_settle', 'telnum')) {
  224. query__db_sql("ALTER TABLE " . tablename_sql('commission_settle') . " ADD `telnum` varchar(32) DEFAULT NULL;");
  225. }
  226. if (!fieldexists_sql('gallery', 'origin_url')) {
  227. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `origin_url` varchar(500) DEFAULT NULL;");
  228. }
  229. if (!fieldexists_sql('gallery', 'imgs')) {
  230. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `imgs` varchar(128) DEFAULT NULL;");
  231. }
  232. if (!fieldexists_sql('gallery', 'uuid')) {
  233. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `uuid` varchar(128) DEFAULT NULL;");
  234. }
  235. if (!fieldexists_sql('gallery', 'engine')) {
  236. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `engine` varchar(32) DEFAULT NULL;");
  237. }
  238. if (!fieldexists_sql('gallery', 'api_id')) {
  239. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `api_id` int(11) DEFAULT 0;");
  240. }
  241. if (!fieldexists_sql('gallery', 'model_id')) {
  242. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `model_id` varchar(128) DEFAULT NULL;");
  243. }
  244. if (!fieldexists_sql('gallery', 'width')) {
  245. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `width` int(11) DEFAULT 0;");
  246. }
  247. if (!fieldexists_sql('gallery', 'height')) {
  248. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `height` int(11) DEFAULT 0;");
  249. }
  250. if (!fieldexists_sql('gallery', 'seed')) {
  251. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `seed` varchar(128) DEFAULT NULL;");
  252. }
  253. if (!fieldexists_sql('gallery', 'steps')) {
  254. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `steps` int(5) DEFAULT 0;");
  255. }
  256. if (!fieldexists_sql('gallery', 'n_samples')) {
  257. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `n_samples` int(2) DEFAULT 0;");
  258. }
  259. if (!fieldexists_sql('gallery', 'scheduler')) {
  260. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `scheduler` varchar(128) DEFAULT NULL;");
  261. }
  262. if (!fieldexists_sql('gallery', 'mj_id')) {
  263. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `mj_id` varchar(32) DEFAULT NULL;");
  264. }
  265. if (!fieldexists_sql('gallery', 'mj_hash')) {
  266. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `mj_hash` varchar(128) DEFAULT NULL;");
  267. }
  268. if (!fieldexists_sql('gallery', 'done')) {
  269. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `done` tinyint(1) DEFAULT 0;");
  270. }
  271. if (!fieldexists_sql('gallery', 'is_open')) {
  272. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `is_open` tinyint(1) DEFAULT 0;");
  273. }
  274. if (!fieldexists_sql('gallery', 'mj_action')) {
  275. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `mj_action` varchar(128) DEFAULT NULL;");
  276. }
  277. if (!fieldexists_sql('gallery', 'pid')) {
  278. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `pid` int(1) DEFAULT 0;");
  279. }
  280. if (!fieldexists_sql('gallery', 'real_prompt')) {
  281. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `real_prompt` varchar(2000) DEFAULT NULL;");
  282. }
  283. if (!fieldexists_sql('gallery', 'mj_api_engine')) {
  284. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `mj_api_engine` varchar(32) DEFAULT NULL;");
  285. }
  286. if (!fieldexists_sql('gallery', 'mj_index')) {
  287. query__db_sql("ALTER TABLE " . tablename_sql('gallery') . " ADD `mj_index` int(1) DEFAULT 0;");
  288. }
  289. if (!fieldexists_sql('words', 'guide')) {
  290. query__db_sql("ALTER TABLE " . tablename_sql('words') . " ADD `guide` varchar(2000) DEFAULT NULL;");
  291. }
  292. if (!fieldexists_sql('bill', 'is_time')) {
  293. query__db_sql("ALTER TABLE " . tablename_sql('bill') . " ADD `is_time` tinyint(1) NOT NULL DEFAULT 0;");
  294. }
  295. if (!fieldexists_sql('member', 'gpt35_times')) {
  296. query__db_sql("ALTER TABLE " . tablename_sql('member') . " ADD `gpt35_times` int(11) NOT NULL DEFAULT 0;");
  297. }
  298. if (!fieldexists_sql('member', 'gpt4_times')) {
  299. query__db_sql("ALTER TABLE " . tablename_sql('member') . " ADD `gpt4_times` int(11) NOT NULL DEFAULT 0;");
  300. }
  301. if (!fieldexists_sql('member', 'sd_times')) {
  302. query__db_sql("ALTER TABLE " . tablename_sql('member') . " ADD `sd_times` int(11) NOT NULL DEFAULT 0;");
  303. }
  304. if (!fieldexists_sql('member', 'mj_times')) {
  305. query__db_sql("ALTER TABLE " . tablename_sql('member') . " ADD `mj_times` int(11) NOT NULL DEFAULT 0;");
  306. }
  307. if (!fieldexists_sql('member', 'gpt35_type')) {
  308. query__db_sql("ALTER TABLE " . tablename_sql('member') . " ADD `gpt35_type` varchar(32) NOT NULL DEFAULT 'time';");
  309. }
  310. if (!fieldexists_sql('member', 'gpt4_type')) {
  311. query__db_sql("ALTER TABLE " . tablename_sql('member') . " ADD `gpt4_type` varchar(32) NOT NULL DEFAULT 'time';");
  312. }
  313. if (!fieldexists_sql('member', 'sd_type')) {
  314. query__db_sql("ALTER TABLE " . tablename_sql('member') . " ADD `sd_type` varchar(32) NOT NULL DEFAULT 'time';");
  315. }
  316. if (!fieldexists_sql('member', 'mj_type')) {
  317. query__db_sql("ALTER TABLE " . tablename_sql('member') . " ADD `mj_type` varchar(32) NOT NULL DEFAULT 'time';");
  318. }