diff --git a/app/common/command/curd/Migrate.php b/app/common/command/curd/Migrate.php index 9c8a312..2773940 100644 --- a/app/common/command/curd/Migrate.php +++ b/app/common/command/curd/Migrate.php @@ -135,7 +135,17 @@ class Migrate extends Command $column_item['type'] = $type_info[0]; $length = substr($type_info[1], 0, strpos($type_info[1], ')')); - $column_item['options']['limit'] = $length; + + if (strpos($length, ',') !== false) { + + $length_info = explode(',', $length); + + $column_item['options']['precision'] = $length_info[0]; + $column_item['options']['scale'] = $length_info[1]; + } else { + + $column_item['options']['limit'] = $length; + } if (strpos($type, 'unsigned') !== false) { // 无符号 @@ -183,6 +193,17 @@ class Migrate extends Command if (isset($type_map[$column_item_set['type']])) { $column_item_set['type'] = $type_map[$column_item_set['type']]; } + + foreach ($column_item_set['options'] as $key => $option) { + + if(is_array($option)){ + + $column_item_set['options'][$key] = "[".implode(',',$option)."]"; + + }else{ + $column_item_set['options'][$key] = "'{$option}'"; + } + } } diff --git a/app/common/command/curd/migrate.tpl b/app/common/command/curd/migrate.tpl index 8a8928e..dab8d51 100644 --- a/app/common/command/curd/migrate.tpl +++ b/app/common/command/curd/migrate.tpl @@ -28,7 +28,7 @@ class {$class_name} extends Migrator { $table = $this->table('{$table}') ->setComment('{$table_info.TABLE_COMMENT}') - {volist name="table_columns" id="column"}->addColumn('{$column.field}', '{$column.type}', [{volist name="column.options" id="option"}'{$key}' => '{$option}', {/volist}]) + {volist name="table_columns" id="column"}->addColumn('{$column.field}', '{$column.type}', [{volist name="column.options" id="option"}'{$key}' => {$option|raw}, {/volist}]) {/volist} {volist name="table_keys_uni" id="vo"}->addIndex('{$vo}',['unique'=>true]) {/volist} diff --git a/database/migrations/20220905222557_test_goods.php b/database/migrations/20220905222557_test_goods.php index 9dfd8dc..f72cfd4 100644 --- a/database/migrations/20220905222557_test_goods.php +++ b/database/migrations/20220905222557_test_goods.php @@ -30,36 +30,36 @@ class TestGoods extends Migrator { $table = $this->table('test_goods') ->setComment('商品列表') - ->addColumn('cate_id', 'biginteger', ['limit' => '20', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '分类ID {relation} (table:mall_cate,relationBindSelect:title)',]) - ->addColumn('title', 'char', ['limit' => '20', 'null' => '0', 'default' => '', 'comment' => '商品名称',]) - ->addColumn('logo', 'char', ['limit' => '255', 'null' => '0', 'comment' => '商品logo {image}',]) - ->addColumn('images', 'text', ['null' => '0', 'comment' => '商品图片 {images}',]) - ->addColumn('describe', 'text', ['null' => '0', 'comment' => '商品描述 {editor}',]) - ->addColumn('total_stock', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '总库存',]) - ->addColumn('sort', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '排序',]) - ->addColumn('status', 'integer', ['limit' => '1', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '状态 {radio} (0:正常,1:禁用)',]) - ->addColumn('cert_file', 'string', ['limit' => '100', 'null' => '0', 'comment' => '合格证 {file}',]) - ->addColumn('verfiy_file', 'text', ['null' => '0', 'comment' => '检测报告 {files}',]) - ->addColumn('remark', 'char', ['limit' => '255', 'null' => '0', 'default' => '', 'comment' => '备注说明',]) - ->addColumn('create_time', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '',]) - ->addColumn('update_time', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '',]) - ->addColumn('delete_time', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '',]) - ->addColumn('publish_time', 'integer', ['limit' => '10', 'signed' => '0', 'null' => '0', 'comment' => '发布日期 {date} (date)',]) - ->addColumn('sale_time', 'biginteger', ['limit' => '20', 'signed' => '0', 'null' => '0', 'comment' => '售卖日期 {date} (datetime)',]) - ->addColumn('intro', 'string', ['limit' => '100', 'null' => '0', 'comment' => '简介 {textarea}',]) - ->addColumn('time_status', 'integer', ['limit' => '5', 'signed' => '0', 'null' => '0', 'comment' => '秒杀状态 {select} (0:未参加,1:已开始,3:已结束)',]) - ->addColumn('is_recommend', 'integer', ['limit' => '4', 'null' => '0', 'comment' => '是否推荐 {switch} (0:不推荐,1:推荐)',]) - ->addColumn('shop_type', 'string', ['limit' => '100', 'null' => '0', 'comment' => '商品类型 {checkbox} (taobao:淘宝,jd:京东)',]) - ->addColumn('tag', 'string', ['limit' => '100', 'null' => '0', 'comment' => '商品标签 {table} (table:mall_tag,type:checkbox,valueField:id,fieldName:title)',]) - ->addColumn('tag_backup', 'string', ['limit' => '100', 'null' => '1', 'comment' => '商品标签(单选) {table} (table:mall_tag,type:radio,valueField:id,fieldName:title)',]) - ->addColumn('from_area', 'string', ['limit' => '100', 'null' => '0', 'comment' => '产地 {city} (name-province:0,code:0)',]) - ->addColumn('store_city', 'string', ['limit' => '100', 'null' => '0', 'default' => '山东省/临沂市', 'comment' => '仓库 {city} (level:city)',]) - ->addColumn('tag_input', 'string', ['limit' => '100', 'null' => '0', 'comment' => '商品标签 (输入) {tag}',]) - ->addColumn('uid', 'string', ['limit' => '100', 'null' => '0', 'comment' => '唯一id',]) - ->addColumn('price', 'decimal', ['limit' => '10,2', 'null' => '1', 'comment' => '价格',]) - ->addColumn('detail', 'text', ['null' => '1', 'comment' => '详情',]) - ->addIndex('uid', ['unique' => true]) - ->addIndex('detail', ['type' => 'fulltext']) + ->addColumn('cate_id', 'biginteger', ['limit' => '20', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '分类ID {relation} (table:mall_cate,relationBindSelect:title)', ]) + ->addColumn('title', 'char', ['limit' => '20', 'null' => '0', 'default' => '', 'comment' => '商品名称', ]) + ->addColumn('logo', 'char', ['limit' => '255', 'null' => '0', 'comment' => '商品logo {image}', ]) + ->addColumn('images', 'text', ['null' => '0', 'comment' => '商品图片 {images}', ]) + ->addColumn('describe', 'text', ['null' => '0', 'comment' => '商品描述 {editor}', ]) + ->addColumn('total_stock', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '总库存', ]) + ->addColumn('sort', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '排序', ]) + ->addColumn('status', 'integer', ['limit' => '1', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '状态 {radio} (0:正常,1:禁用)', ]) + ->addColumn('cert_file', 'string', ['limit' => '100', 'null' => '0', 'comment' => '合格证 {file}', ]) + ->addColumn('verfiy_file', 'text', ['null' => '0', 'comment' => '检测报告 {files}', ]) + ->addColumn('remark', 'char', ['limit' => '255', 'null' => '0', 'default' => '', 'comment' => '备注说明', ]) + ->addColumn('create_time', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '', ]) + ->addColumn('update_time', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '', ]) + ->addColumn('delete_time', 'integer', ['limit' => '11', 'signed' => '0', 'null' => '0', 'default' => '0', 'comment' => '', ]) + ->addColumn('publish_time', 'integer', ['limit' => '10', 'signed' => '0', 'null' => '0', 'comment' => '发布日期 {date} (date)', ]) + ->addColumn('sale_time', 'biginteger', ['limit' => '20', 'signed' => '0', 'null' => '0', 'comment' => '售卖日期 {date} (datetime)', ]) + ->addColumn('intro', 'string', ['limit' => '100', 'null' => '0', 'comment' => '简介 {textarea}', ]) + ->addColumn('time_status', 'integer', ['limit' => '5', 'signed' => '0', 'null' => '0', 'comment' => '秒杀状态 {select} (0:未参加,1:已开始,3:已结束)', ]) + ->addColumn('is_recommend', 'integer', ['limit' => '4', 'null' => '0', 'comment' => '是否推荐 {switch} (0:不推荐,1:推荐)', ]) + ->addColumn('shop_type', 'string', ['limit' => '100', 'null' => '0', 'comment' => '商品类型 {checkbox} (taobao:淘宝,jd:京东)', ]) + ->addColumn('tag', 'string', ['limit' => '100', 'null' => '0', 'comment' => '商品标签 {table} (table:mall_tag,type:checkbox,valueField:id,fieldName:title)', ]) + ->addColumn('tag_backup', 'string', ['limit' => '100', 'null' => '1', 'comment' => '商品标签(单选) {table} (table:mall_tag,type:radio,valueField:id,fieldName:title)', ]) + ->addColumn('from_area', 'string', ['limit' => '100', 'null' => '0', 'comment' => '产地 {city} (name-province:0,code:0)', ]) + ->addColumn('store_city', 'string', ['limit' => '100', 'null' => '0', 'default' => '山东省/临沂市', 'comment' => '仓库 {city} (level:city)', ]) + ->addColumn('tag_input', 'string', ['limit' => '100', 'null' => '0', 'comment' => '商品标签 (输入) {tag}', ]) + ->addColumn('uid', 'string', ['limit' => '100', 'null' => '0', 'comment' => '唯一id', ]) + ->addColumn('price', 'decimal', ['precision' => '10', 'scale' => '2', 'null' => '1', 'comment' => '价格', ]) + ->addColumn('detail', 'text', ['null' => '1', 'comment' => '详情', ]) + ->addIndex('uid',['unique'=>true]) + ->addIndex('detail',['type'=>'fulltext']) ->addIndex('cate_id') ->create(); }