Skip to content

Commit

Permalink
调整安装流程
Browse files Browse the repository at this point in the history
  • Loading branch information
yupoxiong committed Aug 19, 2019
1 parent 13b2418 commit 813acc1
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ composer require yupoxiong/region
```

##### 第二步:创建数据表
复制`vendor/yupoxiong/region/src/migrations`目录下的数据库迁移文件到TP迁移目录(一般是/database/migrations/),然后运行TP自带迁移命令创建表。
复制`vendor/yupoxiong/region/database/migrations`目录下的数据库迁移文件到TP迁移目录(一般是/database/migrations/),然后运行TP自带迁移命令创建表。


#### 添加路由
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"autoload": {
"psr-4": {
"yupoxiong\\region\\": "src"
}
},
"files": [
"helper.php"
]
}

}
13 changes: 13 additions & 0 deletions config/region.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* region配置
*/

return [
//查询缓存秒数,false为不缓存
'cache' => 20140210,
//查询字段,可选项:id,name,code,parent_id,initial,pingyin,citycode,adcode,lng_lat
'field' => 'id,name',
//排序,默认为adcode正序
'order' => 'adcode asc',
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Region extends Migrator
*/
public function change()
{
$region = $this->table('region', ['comment' => '省市区表', 'engine' => 'InnoDB', 'encoding' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci']);
$region->addColumn('parent_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '父级ID'])
$region = $this->table('region', ['comment' => '省市区', 'engine' => 'InnoDB', 'encoding' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci']);
$region->addColumn('parent_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '父级'])
->addColumn('level', 'boolean', ['limit' => 1, 'default' => 1, 'comment' => '等级'])
->addColumn('name', 'string', ['limit' => 50, 'default' => '', 'comment' => '名称'])
->addColumn('initial', 'string', ['limit' => 50, 'default' => '', 'comment' => '首字母'])
Expand Down Expand Up @@ -67,7 +67,9 @@ public function insertData()
$msg = $e->getMessage();
}
print ($msg . "\n");
unset($total);
unset($data);
unset($json);
unlink($zip_file);
unlink($json_file);
}
Expand Down
12 changes: 12 additions & 0 deletions helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

if ('cli' === PHP_SAPI || 'phpdbg' === PHP_SAPI) {
\think\Console::addDefaultCommands([
'region:publish' => \yupoxiong\region\command\Publish::class,
'region:migrate' => \yupoxiong\region\command\Migrate::class,
]);
}

\think\Loader::addClassAlias([
'Region' => \yupoxiong\region\facade\Casbin::class,
]);
22 changes: 22 additions & 0 deletions src/command/Migrate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace yupoxiong\region\command;

use think\migration\command\migrate\Run as MigrateRun;
use Db;

class Migrate extends MigrateRun
{
protected function configure()
{
parent::configure();
$this->setName('region:migrate')->setDescription('Migrate the database for Region');
}

protected function getPath()
{
return __DIR__.'/../../database/migrations';
}


}
24 changes: 24 additions & 0 deletions src/command/Publish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace yupoxiong\region\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;

class Publish extends Command
{
protected function configure()
{
$this->setName('region:publish')->setDescription('Publish Region');
}

protected function execute(Input $input, Output $output)
{


if (!file_exists(env('config_path').'region.php')) {
copy(__DIR__.'/../../config/region.php', env('config_path').'region.php');
}
}
}
14 changes: 14 additions & 0 deletions src/facade/Region.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace \yupoxiong\region\facade;

use think\Facade;

class Region extends Facade
{
protected static function getFacadeClass()
{

return '\yupoxiong\region\model\Region';
}
}
2 changes: 1 addition & 1 deletion src/model/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Region extends Model
public function __construct($data = [])
{
parent::__construct($data);
$config = config('region');
$config = config('region.');
if ($config) {
if (!isset($config['cache']) || !isset($config['field'])|| !isset($config['order'])) {
throw new \Exception('配置不完整');
Expand Down

0 comments on commit 813acc1

Please sign in to comment.