parent
a95c25d026
commit
f134e9e00a
@ -0,0 +1,15 @@ |
||||
root = true |
||||
|
||||
[*] |
||||
charset = utf-8 |
||||
end_of_line = lf |
||||
insert_final_newline = true |
||||
indent_style = space |
||||
indent_size = 4 |
||||
trim_trailing_whitespace = true |
||||
|
||||
[*.md] |
||||
trim_trailing_whitespace = false |
||||
|
||||
[*.{yml,yaml}] |
||||
indent_size = 2 |
@ -0,0 +1,49 @@ |
||||
APP_NAME=Laravel |
||||
APP_ENV=local |
||||
APP_KEY= |
||||
APP_DEBUG=true |
||||
APP_URL=http://localhost |
||||
|
||||
LOG_CHANNEL=stack |
||||
LOG_LEVEL=debug |
||||
|
||||
DB_CONNECTION=mysql |
||||
DB_HOST=127.0.0.1 |
||||
DB_PORT=3306 |
||||
DB_DATABASE=laravel |
||||
DB_USERNAME=root |
||||
DB_PASSWORD= |
||||
|
||||
BROADCAST_DRIVER=log |
||||
CACHE_DRIVER=file |
||||
QUEUE_CONNECTION=sync |
||||
SESSION_DRIVER=file |
||||
SESSION_LIFETIME=120 |
||||
|
||||
MEMCACHED_HOST=127.0.0.1 |
||||
|
||||
REDIS_HOST=127.0.0.1 |
||||
REDIS_PASSWORD=null |
||||
REDIS_PORT=6379 |
||||
|
||||
MAIL_MAILER=smtp |
||||
MAIL_HOST=mailhog |
||||
MAIL_PORT=1025 |
||||
MAIL_USERNAME=null |
||||
MAIL_PASSWORD=null |
||||
MAIL_ENCRYPTION=null |
||||
MAIL_FROM_ADDRESS=null |
||||
MAIL_FROM_NAME="${APP_NAME}" |
||||
|
||||
AWS_ACCESS_KEY_ID= |
||||
AWS_SECRET_ACCESS_KEY= |
||||
AWS_DEFAULT_REGION=us-east-1 |
||||
AWS_BUCKET= |
||||
|
||||
PUSHER_APP_ID= |
||||
PUSHER_APP_KEY= |
||||
PUSHER_APP_SECRET= |
||||
PUSHER_APP_CLUSTER=mt1 |
||||
|
||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" |
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" |
@ -0,0 +1,5 @@ |
||||
* text=auto |
||||
*.css linguist-vendored |
||||
*.scss linguist-vendored |
||||
*.js linguist-vendored |
||||
CHANGELOG.md export-ignore |
@ -0,0 +1,14 @@ |
||||
/node_modules |
||||
/public/hot |
||||
/public/storage |
||||
/storage/*.key |
||||
/vendor |
||||
/.idea |
||||
.env |
||||
.env.backup |
||||
.phpunit.result.cache |
||||
docker-compose.override.yml |
||||
Homestead.json |
||||
Homestead.yaml |
||||
npm-debug.log |
||||
yarn-error.log |
@ -0,0 +1,13 @@ |
||||
php: |
||||
preset: laravel |
||||
disabled: |
||||
- no_unused_imports |
||||
finder: |
||||
not-name: |
||||
- index.php |
||||
- server.php |
||||
js: |
||||
finder: |
||||
not-name: |
||||
- webpack.mix.js |
||||
css: true |
@ -1,2 +1,62 @@ |
||||
# user_center |
||||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400"></a></p> |
||||
|
||||
<p align="center"> |
||||
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a> |
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a> |
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a> |
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a> |
||||
</p> |
||||
|
||||
## About Laravel |
||||
|
||||
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: |
||||
|
||||
- [Simple, fast routing engine](https://laravel.com/docs/routing). |
||||
- [Powerful dependency injection container](https://laravel.com/docs/container). |
||||
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. |
||||
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). |
||||
- Database agnostic [schema migrations](https://laravel.com/docs/migrations). |
||||
- [Robust background job processing](https://laravel.com/docs/queues). |
||||
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). |
||||
|
||||
Laravel is accessible, powerful, and provides tools required for large, robust applications. |
||||
|
||||
## Learning Laravel |
||||
|
||||
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. |
||||
|
||||
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. |
||||
|
||||
## Laravel Sponsors |
||||
|
||||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). |
||||
|
||||
### Premium Partners |
||||
|
||||
- **[Vehikl](https://vehikl.com/)** |
||||
- **[Tighten Co.](https://tighten.co)** |
||||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** |
||||
- **[64 Robots](https://64robots.com)** |
||||
- **[Cubet Techno Labs](https://cubettech.com)** |
||||
- **[Cyber-Duck](https://cyber-duck.co.uk)** |
||||
- **[Many](https://www.many.co.uk)** |
||||
- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** |
||||
- **[DevSquad](https://devsquad.com)** |
||||
- **[Curotec](https://www.curotec.com/)** |
||||
- **[OP.GG](https://op.gg)** |
||||
|
||||
## Contributing |
||||
|
||||
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). |
||||
|
||||
## Code of Conduct |
||||
|
||||
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). |
||||
|
||||
## Security Vulnerabilities |
||||
|
||||
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. |
||||
|
||||
## License |
||||
|
||||
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
||||
|
@ -0,0 +1,181 @@ |
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use Illuminate\Console\GeneratorCommand; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Str; |
||||
use Symfony\Component\Console\Input\InputOption; |
||||
|
||||
class ApiControllerGenerator extends GeneratorCommand |
||||
{ |
||||
/** |
||||
* The console command name. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $name = 'make:apiController'; |
||||
|
||||
/** |
||||
* The console command description. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $description = 'Create a new controller class'; |
||||
|
||||
/** |
||||
* The type of class being generated. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $type = 'Controller'; |
||||
|
||||
/** |
||||
* Get the stub file for the generator. |
||||
* |
||||
* @return string |
||||
*/ |
||||
protected function getStub() |
||||
{ |
||||
return $this->resolveStubPath('/stubs/controller.model.api.stub'); |
||||
} |
||||
|
||||
/** |
||||
* Resolve the fully-qualified path to the stub. |
||||
* |
||||
* @param string $stub |
||||
* @return string |
||||
*/ |
||||
protected function resolveStubPath($stub) |
||||
{ |
||||
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) |
||||
? $customPath |
||||
: __DIR__.$stub; |
||||
} |
||||
|
||||
/** |
||||
* Get the default namespace for the class. |
||||
* |
||||
* @param string $rootNamespace |
||||
* @return string |
||||
*/ |
||||
protected function getDefaultNamespace($rootNamespace) |
||||
{ |
||||
return $rootNamespace.'\Http\Controllers\Api'; |
||||
} |
||||
|
||||
/** |
||||
* Build the class with the given name. |
||||
* |
||||
* Remove the base controller import if we are already in base namespace. |
||||
* |
||||
* @param string $name |
||||
* @return string |
||||
*/ |
||||
protected function buildClass($name) |
||||
{ |
||||
$modelClass = $this->parseModel(Str::replaceLast('Controller', 'T', class_basename($name))); |
||||
|
||||
if (! class_exists($modelClass)) { |
||||
if ($this->confirm("A {$modelClass} model does not exist. Do you want to generate it?", true)) { |
||||
$this->call('make:apiModel', ['name' => $modelClass]); |
||||
} |
||||
} |
||||
|
||||
$resourceClass = $this->qualifyResource(Str::replaceLast('Controller', '', class_basename($name))); |
||||
if (! class_exists($resourceClass)) { |
||||
if ($this->confirm("A {$resourceClass} resource does not exist. Do you want to generate it?", true)) { |
||||
$this->call('make:apiResource', ['name' => $resourceClass]); |
||||
} |
||||
} |
||||
$resourceCollectionClass = $resourceClass . 'Collection'; |
||||
if (! class_exists($resourceCollectionClass)) { |
||||
if ($this->confirm("A {$resourceCollectionClass} resource collection does not exist. Do you want to generate it?", true)) { |
||||
$this->call('make:resource', ['name' => $resourceCollectionClass]); |
||||
} |
||||
} |
||||
|
||||
$table_name = env('DB_PREFIX') . Str::snake(str_replace([$this->getNamespace($name).'\\', 'Controller'], ['','T'], $name)); |
||||
$columns = DB::select("select COLUMN_NAME,DATA_TYPE,IS_NULLABLE,COLUMN_DEFAULT from information_schema.COLUMNS where table_name = '$table_name'"); |
||||
$attributes = ''; |
||||
$rules = ''; |
||||
foreach ($columns as $column){ |
||||
if(!in_array($column->COLUMN_NAME, ['id', 'created_at', 'updated_at'])){ |
||||
$attributes .= ' $this->model->'. $column->COLUMN_NAME .' = $this->params[\''. $column->COLUMN_NAME .'\']'; |
||||
$rule = " '{$column->COLUMN_NAME}' => '"; |
||||
if ($column->IS_NULLABLE == 'NO' && $column->COLUMN_DEFAULT === null) { |
||||
$rule .= 'required|'; |
||||
} |
||||
if(in_array($column->DATA_TYPE, ['int','integer', 'tinyint','smallint','mediumint','bigint','decimal'])){ |
||||
$rule .= 'numeric|'; |
||||
$attributes .= ' ?? 0'; |
||||
} |
||||
if(in_array($column->DATA_TYPE, ['varchar','char'])){ |
||||
$rule .= 'string|'; |
||||
$attributes .= ' ?? \'\''; |
||||
} |
||||
$attributes .= ';'. PHP_EOL; |
||||
if (Str::endsWith($rule,'|')) { |
||||
$rules .= Str::replaceLast('|', '', $rule) .'\',' . PHP_EOL; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
$replace = [ |
||||
'{{ namespacedModel }}' => $modelClass, |
||||
'{{ model }}' => class_basename($modelClass), |
||||
'{{ namespacedResource }}' => $resourceClass, |
||||
'{{ resource }}' => class_basename($resourceClass), |
||||
'{{ namespacedResourceCollection }}' => $resourceCollectionClass, |
||||
'{{ resourceCollection }}' => class_basename($resourceCollectionClass), |
||||
'{{ attrList }}' => Str::replaceLast(PHP_EOL, '', $attributes), |
||||
'{{ ruleList }}' => Str::replaceLast(PHP_EOL, '', $rules), |
||||
]; |
||||
|
||||
return str_replace( |
||||
array_keys($replace), array_values($replace), parent::buildClass($name) |
||||
); |
||||
} |
||||
|
||||
protected function qualifyResource(string $name) |
||||
{ |
||||
$rootNamespace = $this->rootNamespace(); |
||||
|
||||
return $rootNamespace. 'Http' . DIRECTORY_SEPARATOR .'Resources'. DIRECTORY_SEPARATOR . $name; |
||||
} |
||||
|
||||
/** |
||||
* Get the fully-qualified model class name. |
||||
* |
||||
* @param string $model |
||||
* @return string |
||||
* |
||||
* @throws \InvalidArgumentException |
||||
*/ |
||||
protected function parseModel($model) |
||||
{ |
||||
if (preg_match('([^A-Za-z0-9_/\\\\])', $model)) { |
||||
throw new InvalidArgumentException('Model name contains invalid characters.'); |
||||
} |
||||
|
||||
return $this->qualifyModel($model); |
||||
} |
||||
|
||||
/** |
||||
* Get the console command options. |
||||
* |
||||
* @return array |
||||
*/ |
||||
protected function getOptions() |
||||
{ |
||||
return [ |
||||
['api', null, InputOption::VALUE_NONE, 'Exclude the create and edit methods from the controller.'], |
||||
['force', null, InputOption::VALUE_NONE, 'Create the class even if the controller already exists'], |
||||
['invokable', 'i', InputOption::VALUE_NONE, 'Generate a single method, invokable controller class.'], |
||||
['model', 'm', InputOption::VALUE_OPTIONAL, 'Generate a resource controller for the given model.'], |
||||
['parent', 'p', InputOption::VALUE_OPTIONAL, 'Generate a nested resource controller class.'], |
||||
['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource controller class.'], |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,186 @@ |
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use Illuminate\Console\GeneratorCommand; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Str; |
||||
use Symfony\Component\Console\Input\InputOption; |
||||
|
||||
class ApiModelGenerator extends GeneratorCommand |
||||
{ |
||||
/** |
||||
* The console command name. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $name = 'make:apiModel'; |
||||
|
||||
/** |
||||
* The console command description. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $description = 'Create a new api resource.'; |
||||
|
||||
/** |
||||
* The type of class being generated. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $type = 'Model'; |
||||
|
||||
public function handle() |
||||
{ |
||||
if (parent::handle() === false && ! $this->option('force')) { |
||||
return false; |
||||
} |
||||
|
||||
if ($this->option('all')) { |
||||
$this->input->setOption('controller', true); |
||||
$this->input->setOption('resource', true); |
||||
} |
||||
|
||||
if ($this->option('resource')) { |
||||
$this->createResource(); |
||||
} |
||||
|
||||
if ($this->option('controller')) { |
||||
$this->createController(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Build the class with the given name. |
||||
* |
||||
* @param string $name |
||||
* @return string |
||||
* |
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
||||
*/ |
||||
protected function buildClass($name) |
||||
{ |
||||
$db_name = DB::connection()->getDatabaseName(); |
||||
$table_name = env('DB_PREFIX') . Str::snake(str_replace($this->getNamespace($name).'\\', '', $name)); |
||||
|
||||
$properties = $attributes = ''; |
||||
$columns = DB::select("SELECT COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT,IS_NULLABLE,COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{$db_name}' AND TABLE_NAME = '{$table_name}'"); |
||||
foreach ($columns as $column){ |
||||
$properties .= ' * @property $'. $column->COLUMN_NAME . ' ' . $column->DATA_TYPE . PHP_EOL; |
||||
if(in_array($column->COLUMN_NAME, ['id', 'created_at', 'updated_at'])) continue; |
||||
$attributes .= " '{$column->COLUMN_NAME}' => ['name' => '{$column->COLUMN_NAME}', 'title' => '". ($column->COLUMN_COMMENT ? explode(':', $column->COLUMN_COMMENT)[0] : $column->COLUMN_NAME) ."', 'type' => '{$column->DATA_TYPE}', 'is_must' => '". intval($column->IS_NULLABLE == 'NO' && $column->COLUMN_DEFAULT === null) ."'], " . PHP_EOL; |
||||
} |
||||
|
||||
$replace = [ |
||||
'{{ table }}' => $table_name, |
||||
'{{ propertiesList }}' => Str::replaceLast(PHP_EOL, '', $properties), |
||||
'{{ attrList }}' => Str::replaceLast(PHP_EOL, '', $attributes) |
||||
]; |
||||
|
||||
return str_replace( |
||||
array_keys($replace), array_values($replace), parent::buildClass($name) |
||||
); |
||||
} |
||||
|
||||
protected function generatorProperty(&$stub, $name) |
||||
{ |
||||
$db_name = DB::connection()->getDatabaseName(); |
||||
$table_name = env('DB_PREFIX') . Str::snake(str_replace($this->getNamespace($name).'\\', '', $name)); |
||||
|
||||
$properties = $attributes = ''; |
||||
$columns = DB::select("SELECT COLUMN_NAME,DATA_TYPE,COLUMN_COMMENT,IS_NULLABLE,COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{$db_name}' AND TABLE_NAME = '{$table_name}'"); |
||||
foreach ($columns as $column){ |
||||
$properties .= ' * @property $'. $column->COLUMN_NAME . ' ' . $column->DATA_TYPE . PHP_EOL; |
||||
if(in_array($column->COLUMN_NAME, ['id', 'created_at', 'updated_at'])) continue; |
||||
$attributes .= " '{$column->COLUMN_NAME}' => ['name' => '{$column->COLUMN_NAME}', 'title' => '". ($column->COLUMN_COMMENT ? explode(':', $column->COLUMN_COMMENT)[0] : $column->COLUMN_NAME) ."', 'type' => '{$column->DATA_TYPE}', 'is_must' => '". intval($column->IS_NULLABLE == 'NO' && $column->COLUMN_DEFAULT === null) ."'], " . PHP_EOL; |
||||
} |
||||
|
||||
$stub = str_replace(['{{ table }}', '{{ propertiesList }}', '{{ attrList }}'], [$table_name, Str::replaceLast(PHP_EOL, '', $properties), Str::replaceLast(PHP_EOL, '', $attributes)], $stub); |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Create a seeder file for the model. |
||||
* |
||||
* @return void |
||||
*/ |
||||
protected function createResource() |
||||
{ |
||||
$resource = Str::replaceLast('T', '', Str::studly(class_basename($this->argument('name')))); |
||||
|
||||
$this->call('make:apiResource', [ |
||||
'name' => "{$resource}", |
||||
]); |
||||
|
||||
$this->call('make:resource', [ |
||||
'name' => "{$resource}Collection", |
||||
]); |
||||
} |
||||
|
||||
/** |
||||
* Create a controller for the model. |
||||
* |
||||
* @return void |
||||
*/ |
||||
protected function createController() |
||||
{ |
||||
$controller = Str::replaceLast('T', '', Str::studly(class_basename($this->argument('name')))); |
||||
|
||||
$modelName = $this->qualifyClass($this->getNameInput()); |
||||
|
||||
$this->call('make:apiController', array_filter([ |
||||
'name' => "App\\Http\\Controllers\\Api\\{$controller}Controller", |
||||
'--model' => $modelName, |
||||
'--api' => true, |
||||
])); |
||||
} |
||||
|
||||
/** |
||||
* Get the stub file for the generator. |
||||
* |
||||
* @return string |
||||
*/ |
||||
protected function getStub() |
||||
{ |
||||
return $this->resolveStubPath('/stubs/model.stub'); |
||||
} |
||||
|
||||
/** |
||||
* Resolve the fully-qualified path to the stub. |
||||
* |
||||
* @param string $stub |
||||
* @return string |
||||
*/ |
||||
protected function resolveStubPath($stub) |
||||
{ |
||||
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) |
||||
? $customPath |
||||
: __DIR__.$stub; |
||||
} |
||||
|
||||
/** |
||||
* Get the default namespace for the class. |
||||
* |
||||
* @param string $rootNamespace |
||||
* @return string |
||||
*/ |
||||
protected function getDefaultNamespace($rootNamespace) |
||||
{ |
||||
return is_dir(app_path('Models')) ? $rootNamespace.'\\Models' : $rootNamespace; |
||||
} |
||||
|
||||
/** |
||||
* Get the console command options. |
||||
* |
||||
* @return array |
||||
*/ |
||||
protected function getOptions() |
||||
{ |
||||
return [ |
||||
['all', 'a', InputOption::VALUE_NONE, 'Generate a resource and controller for the model'], |
||||
['controller', 'c', InputOption::VALUE_NONE, 'Create a new controller for the model'], |
||||
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the model already exists'], |
||||
['resource', 'r', InputOption::VALUE_NONE, 'Indicates if the generated controller should be a resource controller'], |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,127 @@ |
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use Illuminate\Console\GeneratorCommand; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Str; |
||||
use Symfony\Component\Console\Input\InputOption; |
||||
|
||||
class ApiResourceGenerator extends GeneratorCommand |
||||
{ |
||||
/** |
||||
* The console command name. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $name = 'make:apiResource'; |
||||
|
||||
/** |
||||
* The console command description. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $description = 'Create a new resource'; |
||||
|
||||
/** |
||||
* The type of class being generated. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $type = 'Resource'; |
||||
|
||||
/** |
||||
* Execute the console command. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function handle() |
||||
{ |
||||
if ($this->collection()) { |
||||
$this->type = 'Resource collection'; |
||||
} |
||||
|
||||
parent::handle(); |
||||
} |
||||
|
||||
protected function buildClass($name) |
||||
{ |
||||
$db_name = DB::connection()->getDatabaseName(); |
||||
$table_name = env('DB_PREFIX') . Str::snake(str_replace($this->getNamespace($name).'\\', '', $name) . 'T'); |
||||
|
||||
$properties = ''; |
||||
$columns = DB::select("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{$db_name}' AND TABLE_NAME = '{$table_name}'"); |
||||
foreach ($columns as $column){ |
||||
$properties .= ' \''. $column->COLUMN_NAME . '\' => $this->' . $column->COLUMN_NAME . ',' . PHP_EOL; |
||||
} |
||||
|
||||
$replace = [ |
||||
'{{ propertiesList }}' => Str::replaceLast(PHP_EOL, '', $properties), |
||||
]; |
||||
|
||||
return str_replace( |
||||
array_keys($replace), array_values($replace), parent::buildClass($name) |
||||
); |
||||
|
||||
return str_replace( |
||||
array_keys($replace), array_values($replace), parent::buildClass($name) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* Get the stub file for the generator. |
||||
* |
||||
* @return string |
||||
*/ |
||||
protected function getStub() |
||||
{ |
||||
return $this->resolveStubPath('/stubs/resource.stub'); |
||||
} |
||||
|
||||
/** |
||||
* Determine if the command is generating a resource collection. |
||||
* |
||||
* @return bool |
||||
*/ |
||||
protected function collection() |
||||
{ |
||||
return $this->option('collection') || |
||||
Str::endsWith($this->argument('name'), 'Collection'); |
||||
} |
||||
|
||||
/** |
||||
* Resolve the fully-qualified path to the stub. |
||||
* |
||||
* @param string $stub |
||||
* @return string |
||||
*/ |
||||
protected function resolveStubPath($stub) |
||||
{ |
||||
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) |
||||
? $customPath |
||||
: __DIR__.$stub; |
||||
} |
||||
|
||||
/** |
||||
* Get the default namespace for the class. |
||||
* |
||||
* @param string $rootNamespace |
||||
* @return string |
||||
*/ |
||||
protected function getDefaultNamespace($rootNamespace) |
||||
{ |
||||
return $rootNamespace.'\Http\Resources'; |
||||
} |
||||
|
||||
/** |
||||
* Get the console command options. |
||||
* |
||||
* @return array |
||||
*/ |
||||
protected function getOptions() |
||||
{ |
||||
return [ |
||||
['collection', 'c', InputOption::VALUE_NONE, 'Create a resource collection'], |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,216 @@ |
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use App\Models\CarBrandT; |
||||
use App\Models\CarModelT; |
||||
use App\Models\CarSeriesT; |
||||
use App\Models\CarSubBrandT; |
||||
use Illuminate\Console\Command; |
||||
use Illuminate\Support\Facades\Storage; |
||||
use Illuminate\Support\Str; |
||||
use simple_html_dom; |
||||
|
||||
class CarModelUpdate extends Command |
||||
{ |
||||
/** |
||||
* The name and signature of the console command. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $signature = 'car-model:update'; |
||||
|
||||
/** |
||||
* The console command description. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $description = '车辆牌品更新(途虎)'; |
||||
|
||||
/** |
||||
* Create a new command instance. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
parent::__construct(); |
||||
} |
||||
|
||||
/** |
||||
* Execute the console command. |
||||
* |
||||
*/ |
||||
public function handle() |
||||
{ |
||||
$begin_time = time(); |
||||
$this->tuhu(); |
||||
$end_time = time(); |
||||
$total_time = $end_time - $begin_time; |
||||
$h = floor($total_time/3600); |
||||
$m = floor(($total_time - $h * 3600)/60); |
||||
$s = $total_time - $h * 3600 - $m * 60; |
||||
echo '花费时间: '.$h.'小时'.$m.'分钟'.$s.'秒<br>'; |
||||
} |
||||
|
||||
private function tuhu(){ |
||||
$disk = Storage::disk('oss'); |
||||
$brand_infos = json_decode($this->getHtml('https://item.tuhu.cn/Car/GetCarBrands2', 'https://by.tuhu.cn/'), true); |
||||
foreach ($brand_infos as $letter => $brands_info) { |
||||
if($letter == 'hot'){ |
||||
continue; |
||||
} |
||||
foreach ($brands_info as $brand_info) { |
||||
$name = trim(explode('-', $brand_info['Brand'])[1]); |
||||
$brand = CarBrandT::where('name',$name)->where('letter',$letter)->first(); |
||||
if (!$brand) { |
||||
$brand = new CarBrandT(); |
||||
$brand->logo = ''; |
||||
} |
||||
if(!Str::startsWith($brand->logo, 'http://images.banmacar.com')){ |
||||
file_put_contents(storage_path(). 'logo.png',file_get_contents('https://img1.tuhu.org'. $brand_info['Url'])); |
||||
$filename = $disk->putFile("png/".date('Ymd'), storage_path(). 'logo.png'); |
||||
$brand->logo = str_replace('http://bmoc-files.oss-cn-hangzhou.aliyuncs.com', 'http://images.banmacar.com', $disk->getUrl($filename)); |
||||
} |
||||
$brand->name = $name; |
||||
$brand->letter = $letter; |
||||
$brand->save(); |
||||
$sub_brand_array = []; |
||||
$sub_brand_infos = json_decode($this->getHtml('https://item.tuhu.cn/Car/SelOneBrand?Brand='. urlencode($brand_info['Brand']), 'https://by.tuhu.cn/'),true); |
||||
foreach ($sub_brand_infos['OneBrand'] as $sub_brand_info) { |
||||
if(!isset($sub_brand_array[$sub_brand_info['BrandType']])){ |
||||
$sub_brand = CarSubBrandT::where('car_brand_id',$brand->id) |
||||
->where('name',$sub_brand_info['BrandType'])->first(); |
||||
if (!$sub_brand) { |
||||
$sub_brand = new CarSubBrandT(); |
||||
$sub_brand->car_brand_id = $brand->id; |
||||
} |
||||
$sub_brand->name = $sub_brand_info['BrandType']; |
||||
$sub_brand->save(); |
||||
echo '----'. $sub_brand_info['BrandType']. '<br>' . PHP_EOL; |
||||
$sub_brand_array[$sub_brand_info['BrandType']] = $sub_brand->id; |
||||
} |
||||
$series = CarSeriesT::where('car_sub_brand_id',$sub_brand_array[$sub_brand_info['BrandType']]) |
||||
->where('name',$sub_brand_info['CarName'])->first(); |
||||
if (!$series) { |
||||
$series = new CarSeriesT(); |
||||
$series->car_sub_brand_id = $sub_brand_array[$sub_brand_info['BrandType']]; |
||||
} |
||||
$series->name = $sub_brand_info['CarName']; |
||||
$series->save(); |
||||
echo '--------'. $sub_brand_info['CarName']. '<br>' . PHP_EOL; |
||||
$displacement_infos = json_decode($this->getHtml('https://item.tuhu.cn/Car/SelectVehicle?VehicleID='. urlencode($sub_brand_info['ProductID']), 'https://by.tuhu.cn/'),true); |
||||
foreach ($displacement_infos['PaiLiang'] as $displacement_info) { |
||||
$years = json_decode($this->getHtml('https://item.tuhu.cn/Car/SelectVehicle?VehicleID='. urlencode($sub_brand_info['ProductID']) . '&PaiLiang='. urlencode($displacement_info['Value']), 'https://by.tuhu.cn/'),true); |
||||
if(!isset($years['Nian'])){ |
||||
sleep(3); |
||||
$years = json_decode($this->getHtml('https://item.tuhu.cn/Car/SelectVehicle?VehicleID='. urlencode($sub_brand_info['ProductID']) . '&PaiLiang='. urlencode($displacement_info['Value']), 'https://by.tuhu.cn/'),true); |
||||
}else if(count($years['Nian']) <= 0){ |
||||
continue; |
||||
} |
||||
$model_years = ''; |
||||
foreach ($years['Nian'] as $year) { |
||||
$model_years .= $year['Value'] . ','; |
||||
} |
||||
$model_years = substr($model_years,0,-1); |
||||
foreach ($years['Nian'] as $year) { |
||||
$model_infos = json_decode($this->getHtml('https://item.tuhu.cn/Car/SelectVehicleSalesName?VehicleID='. urlencode($sub_brand_info['ProductID']) . '&PaiLiang='. urlencode($displacement_info['Value']) . '&Nian='. urlencode($year['Value']), 'https://by.tuhu.cn/'),true); |
||||
if(!isset($model_infos['SalesName'])){ |
||||
sleep(3); |
||||
$model_infos = json_decode($this->getHtml('https://item.tuhu.cn/Car/SelectVehicleSalesName?VehicleID='. urlencode($sub_brand_info['ProductID']) . '&PaiLiang='. urlencode($displacement_info['Value']) . '&Nian='. urlencode($year['Value']), 'https://by.tuhu.cn/'),true); |
||||
} |
||||
foreach ($model_infos['SalesName'] as $model_info) { |
||||
$model = CarModelT::where('car_series_id',$series->id) |
||||
->where('name',$model_info['Name'])->first(); |
||||
if (!$model) { |
||||
$model = new CarModelT(); |
||||
$model->car_series_id = $series->id; |
||||
} |
||||
$model->year = $year['Value']; |
||||
$model->tuhu_code = $model_info['TID']; |
||||
$model->modelYears = $model_years; |
||||
$model->displacement = $displacement_info['Value']; |
||||
$model->name = $model_info['Name']; |
||||
$model->save(); |
||||
echo '------------'. $model_info['Name']. '<br>' . PHP_EOL; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
echo 'over'; |
||||
} |
||||
|
||||
private function autohome(){ |
||||
$brand_html_str = mb_convert_encoding(substr($this->getHtml($this->url . '?' . http_build_query($this->param), 'https://car.autohome.com.cn/'), 18, -2),'utf-8','gbk'); |
||||
$brand_content_html = new \simple_html_dom(); |
||||
$brand_content_html->load($brand_html_str); |
||||
foreach ($brand_content_html->find('.cartree-letter') as $letter_html) { |
||||
$letter = $letter_html->plaintext; |
||||
$brand_html = $letter_html->next_sibling()->find('h3'); |
||||
foreach ($brand_html as $brand_h3) { |
||||
$brand_a = $brand_h3->find('a', 0); |
||||
$name = $brand_a->plaintext; |
||||
$name = substr($name,0,stripos($name,'(')); |
||||
$brand = CarBrandT::where('name',$name)->where('letter',$letter)->first(); |
||||
preg_match('/\-(\d+)/',$brand_a->href,$match); |
||||
if (!$brand) { |
||||
$brand = new CarBrandT(); |
||||
$brand->uuid = MyLib::uuid(); |
||||
echo $name. '<br>' . PHP_EOL; |
||||
} |
||||
$brand->name = $name; |
||||
$brand->autohome_id = $match[1]; |
||||
$brand->letter = $letter; |
||||
$series_html_str = mb_convert_encoding(substr($this->getHtml($brand_a->href, 'https://car.autohome.com.cn/'), 18, -2),'utf-8','gbk'); |
||||
$series_content_html = new \simple_html_dom(); |
||||
$series_content_html->load($series_html_str); |
||||
foreach ($brand_content_html->find('.carbradn-cont .list-dl') as $sub_brand_html) { |
||||
$sub_brand_a = $sub_brand_html->find('dt a', 0); |
||||
$sub_brand = CarSubBrandT::where('car_brand_id',$brand->id)->where('name',$name)->first(); |
||||
if (!$sub_brand) { |
||||
$sub_brand = new CarSubBrandT(); |
||||
$sub_brand->uuid = MyLib::uuid(); |
||||
$sub_brand->car_brand_id = $brand->id; |
||||
echo $name. '<br>' . PHP_EOL; |
||||
} |
||||
$sub_brand->name = $sub_brand_a->plaintext; |
||||
$sub_brand->save(); |
||||
foreach ($sub_brand_html->find('.list-dl-text a') as $series_a) { |
||||
$sub_brand_a = $sub_brand_html->find('dt a', 0); |
||||
$sub_brand = CarSubBrandT::where('car_brand_id',$brand->id)->where('name',$name)->first(); |
||||
if (!$sub_brand) { |
||||
$sub_brand = new CarSubBrandT(); |
||||
$sub_brand->uuid = MyLib::uuid(); |
||||
$sub_brand->car_brand_id = $brand->id; |
||||
echo $name. '<br>' . PHP_EOL; |
||||
} |
||||
$sub_brand->name = $sub_brand_a->plaintext; |
||||
$sub_brand->save(); |
||||
} |
||||
} |
||||
$brand->logo = $series_content_html->find('.carbradn-pic img',0)->src; |
||||
$brand->save(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private function getHtml($url,$last_url) |
||||
{ |
||||
// 构造包头,模拟浏览器请求 |
||||
$header = array ( |
||||
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', |
||||
); |
||||
$ch = curl_init(); |
||||
curl_setopt($ch,CURLOPT_URL, $url); |
||||
curl_setopt($ch,CURLOPT_HTTPHEADER, $header); |
||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); |
||||
$content = curl_exec($ch); |
||||
if ($content == FALSE) { |
||||
echo "error:" . curl_error($ch); |
||||
} |
||||
curl_close($ch); |
||||
return $content; |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
<?php |
||||
|
||||
namespace App\Console\Commands; |
||||
|
||||
use Illuminate\Console\Command; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\Storage; |
||||
|
||||
class Test extends Command |
||||
{ |
||||
/** |
||||
* The name and signature of the console command. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $signature = 'command:test'; |
||||
|
||||
/** |
||||
* The console command description. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $description = 'Command description'; |
||||
|
||||
/** |
||||
* Create a new command instance. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
parent::__construct(); |
||||
} |
||||
|
||||
/** |
||||
* Execute the console command. |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function handle() |
||||
{ |
||||
|
||||
var_dump($columns = collect(DB::select('show columns from uc_car_brand_t'))->keyBy('Field')->toArray()); |
||||
exit(); |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
<?php |
||||
|
||||
namespace App\Console; |
||||
|
||||
use Illuminate\Console\Scheduling\Schedule; |
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; |
||||
|
||||
class Kernel extends ConsoleKernel |
||||
{ |
||||
/** |
||||
* The Artisan commands provided by your application. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $commands = [ |
||||
// |
||||
]; |
||||
|
||||
/** |
||||
* Define the application's command schedule. |
||||
* |
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule |
||||
* @return void |
||||
*/ |
||||
protected function schedule(Schedule $schedule) |
||||
{ |
||||
// $schedule->command('inspire')->hourly(); |
||||
} |
||||
|
||||
/** |
||||
* Register the commands for the application. |
||||
* |
||||
* @return void |
||||
*/ |
||||
protected function commands() |
||||
{ |
||||
$this->load(__DIR__.'/Commands'); |
||||
|
||||
require base_path('routes/console.php'); |
||||
} |
||||
} |
@ -0,0 +1,40 @@ |
||||
<?php |
||||
|
||||
namespace App\Exceptions; |
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
||||
use Throwable; |
||||
|
||||
class Handler extends ExceptionHandler |
||||
{ |
||||
/** |
||||
* A list of the exception types that are not reported. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $dontReport = [ |
||||
// |
||||
]; |
||||
|
||||
/** |
||||
* A list of the inputs that are never flashed for validation exceptions. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $dontFlash = [ |
||||
'password', |
||||
'password_confirmation', |
||||
]; |
||||
|
||||
/** |
||||
* Register the exception handling callbacks for the application. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function register() |
||||
{ |
||||
$this->reportable(function (Throwable $e) { |
||||
// |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,418 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\AuthRule; |
||||
use App\Libs\MyLib; |
||||
use App\Models\AuthRuleT; |
||||
use App\Models\EmployeeGroupT; |
||||
use App\Models\EmployeeT; |
||||
use Illuminate\Http\Request; |
||||
use App\Http\Resources\AuthRuleCollection; |
||||
|
||||
/** |
||||
* @title 权限认证管理 |
||||
* @description 用户登录及权限管理 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
class AuthController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'login' => [ |
||||
'rules' => [ |
||||
'username' => 'required', |
||||
'password' => 'required', |
||||
], |
||||
'messages' => [ |
||||
'username.required' => '用户名不能为空', |
||||
'password.required' => '密码不能为空' |
||||
], |
||||
], |
||||
'modifyPassword' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'oldPassword' => 'required', |
||||
'newPassword' => 'required', |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeT,id' |
||||
], |
||||
'resetPassword' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeT,id' |
||||
], |
||||
'EmployeeAuth' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'rules' => 'required' |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeT,id' |
||||
], |
||||
'EmployeeGroupAuth' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'rules' => 'required' |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeGroupT,id' |
||||
], |
||||
'store' => [ |
||||
'rules' => [ |
||||
'title' => 'required|max:20', |
||||
'name' => 'bail|required|unique:App\Models\AuthRuleT|max:20', |
||||
'method' => 'required|in:GET,POST,PUT,PATCH,DELETE', |
||||
'group' => 'required', |
||||
'module' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'unique,App\Models\AuthRuleT,name' |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\AuthRuleT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'title' => 'required|max:20', |
||||
'name' => 'bail|required|max:20', |
||||
'method' => 'required|in:GET,POST,PUT,PATCH,DELETE', |
||||
'group' => 'required', |
||||
'module' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\AuthRuleT,id', |
||||
'unique,App\Models\AuthRuleT,name,id' |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\AuthRuleT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new AuthRuleT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 登录 |
||||
* @description 登录授权,返回jwt凭据 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function login() |
||||
{ |
||||
if (!$token = auth('api')->attempt([ |
||||
'username' => $this->params['username'], |
||||
'password' => $this->params['password'], |
||||
])) { |
||||
return $this->error(401, '登录失败,用户名或密码错误'); |
||||
} |
||||
|
||||
return $this->success([ |
||||
'access_token' => $token, |
||||
'token_type' => 'bearer', |
||||
'expires_in' => auth('api')->factory()->getTTL() * 60 |
||||
]); |
||||
} |
||||
|
||||
/** |
||||
* @title 注销登录 |
||||
* @description 注销登录,全局退出并通知其他系统退出 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function logout() |
||||
{ |
||||
auth('api')->logout(); |
||||
return $this->success(); |
||||
} |
||||
|
||||
/** |
||||
* @title 刷新token |
||||
* @description 刷新token,如果开启黑名单,以前的token便会失效 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function refresh() |
||||
{ |
||||
try { |
||||
$token = auth('api')->refresh(); |
||||
return $this->success([ |
||||
'access_token' => $token, |
||||
'token_type' => 'bearer', |
||||
'expires_in' => auth('api')->factory()->getTTL() * 60 |
||||
]); |
||||
} catch (\Exception $e){ |
||||
return $this->error(403, '令牌已过期'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 修改密码 |
||||
* @description 本人或管理员修改密码 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/2/2 |
||||
*/ |
||||
public function modifyPassword($id){ |
||||
$user = auth('api')->user(); |
||||
if($user['id'] != $id && $user['id'] != 1){ |
||||
return $this->error(403, '权限不足'); |
||||
} |
||||
$employee = EmployeeT::find($id); |
||||
if(!password_verify($this->params['oldPassword'], $employee['password'])){ |
||||
return $this->error(403, '原密码错误'); |
||||
}; |
||||
$employee->password = password_hash($this->params['newPassword'], PASSWORD_DEFAULT); |
||||
if($employee->save()){ |
||||
return $this->success('','密码修改成功'); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 重置密码 |
||||
* @description 管理员重置密码 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/2/2 |
||||
*/ |
||||
public function resetPassword($id) |
||||
{ |
||||
if(auth('api')->user()['id'] != 1){ |
||||
return $this->error(403, '权限不足'); |
||||
} |
||||
EmployeeT::where('id',$id)->update(['password' => password_hash('123456', PASSWORD_DEFAULT)]); |
||||
auth('api')->tokenById('id'); |
||||
return $this->success('','密码重置成功'); |
||||
} |
||||
|
||||
/** |
||||
* @title 用户授权 |
||||
* @description 单用户授权 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/2/2 |
||||
*/ |
||||
public function EmployeeAuth($id) |
||||
{ |
||||
$user = EmployeeT::find($id); |
||||
$authList = $user->getAuthList(); |
||||
$rules = array_diff($this->params['rules'], array_intersect($this->params['rules'], $authList)); |
||||
$user->rules = implode(',', $rules); |
||||
if($user->save()){ |
||||
return $this->success('','权限添加成功,用户需重新登录获取权限'); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 用户组授权 |
||||
* @description 用户组授权 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/2/3 |
||||
*/ |
||||
public function EmployeeGroupAuth($id) |
||||
{ |
||||
$group = EmployeeGroupT::find($id); |
||||
$rules = array_diff($this->params['rules'], array_intersect($this->params['rules'], explode(',',$group->rules))); |
||||
$group->rules = implode(',', $rules); |
||||
if($group->save()){ |
||||
return $this->success('','权限添加成功,用户需重新登录获取权限'); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 节点列表 |
||||
* @description 权限节点列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = AuthRuleT::query(); |
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
if(isset($this->params['title']) && $this->params['title'] != ''){ |
||||
$query->where('title', 'like', '%'. $this->params['title'] .'%'); |
||||
} |
||||
|
||||
if(isset($this->params['status']) && $this->params['status'] >= 0){ |
||||
$query->where('status', $this->params['status']); |
||||
} else { |
||||
$query->where('status', 1); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new AuthRuleCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 节点新增 |
||||
* @description 手动创建节点 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$rule = new AuthRuleT(); |
||||
$rule->title = $this->params['title']; |
||||
$rule->name = $this->params['name']; |
||||
$rule->method = $this->params['method'] ?? ''; |
||||
$rule->desc = $this->params['desc'] ?? ''; |
||||
$rule->module = $this->params['module']; |
||||
$rule->group = $this->params['group']; |
||||
$rule->condition = $this->params['condition'] ?? ''; |
||||
$rule->status = $this->params['status'] ?? 1; |
||||
if($rule->save()){ |
||||
return $this->success(new AuthRule($rule)); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 节点详情 |
||||
* @description 节点详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
$rule = AuthRuleT::find($id); |
||||
return $this->success(new AuthRule($rule)); |
||||
} |
||||
|
||||
/** |
||||
* @title 节点更新 |
||||
* @description 节点更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$rule = AuthRuleT::find($id); |
||||
$rule->title = $this->params['title']; |
||||
$rule->name = $this->params['name']; |
||||
$rule->method = $this->params['method'] ?? $rule->method; |
||||
$rule->desc = $this->params['desc'] ?? $rule->desc; |
||||
$rule->module = $this->params['module']; |
||||
$rule->group = $this->params['group']; |
||||
$rule->condition = $this->params['condition'] ?? $rule->condition; |
||||
$rule->status = $this->params['status'] ?? $rule->status; |
||||
if($rule->save()){ |
||||
return $this->success(new AuthRule($rule)); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 节点扫描 |
||||
* @description 扫描控制器目录,更新或创建权限节点 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @throws \ReflectionException |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function scanNode(){ |
||||
$path = app_path('Http/Controllers'); |
||||
$dirs = scandir($path); |
||||
$list = []; |
||||
foreach ($dirs as $dir) { |
||||
if ($dir != '.' && $dir != '..' && is_dir($path . DIRECTORY_SEPARATOR . $dir)) { |
||||
$classes = MyLib::scanFile($path . DIRECTORY_SEPARATOR . $dir); |
||||
foreach ($classes as $class) { |
||||
if($class == 'BaseController'){ |
||||
continue; |
||||
} |
||||
$classname = "App\\Http\\Controllers\\" . $dir . "\\" . $class; |
||||
if (class_exists($classname)) { |
||||
$reflection = new \ReflectionClass($classname); |
||||
$group_doc = MyLib::Parser($reflection->getDocComment()); |
||||
$methods = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC); |
||||
$group_doc['name'] = $class; |
||||
foreach ($methods as $key => $method) { |
||||
if (!in_array($method->name, ['__construct'])) { |
||||
$title_doc = MyLib::Parser($method->getDocComment()); |
||||
$title_doc['param'] = $title_doc['param'] ?? []; |
||||
unset($title_doc['param']['Request']); |
||||
if (isset($title_doc['title']) && $title_doc['title']) { |
||||
$route = app('router')->getRoutes()->getByAction($classname .'@'. $method->name); |
||||
$list[] = array( |
||||
'title' => trim($title_doc['title']), |
||||
'name' => $route->uri(), |
||||
'desc' => trim($title_doc['description']), |
||||
'group' => trim($group_doc['title']), |
||||
'method' => $route->methods()[0], |
||||
'module' => $dir, |
||||
); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
if(AuthRuleT::upsert($list, ['name', 'module'], ['title', 'desc', 'group'])){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500,'权限节点更新失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 节点删除 |
||||
* @description 软删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
$rule = AuthRuleT::find($id); |
||||
$rule->status = 0; |
||||
if($rule->save()){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Controllers\Controller; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Http\Resources\Json\ResourceCollection; |
||||
|
||||
class BaseController extends Controller |
||||
{ |
||||
// |
||||
protected $rules; |
||||
protected $params; |
||||
protected $request; |
||||
protected $model; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->request = $request; |
||||
$this->params = $request->input(); |
||||
$this->initialize(); |
||||
} |
||||
|
||||
protected function initialize() { |
||||
$this->request->attributes->add([ |
||||
'rules' => $this->rules[explode('@', $this->request->route()->getActionName())[1]] ?? [], |
||||
'attributes' => $this->model->attrs, |
||||
]); |
||||
$this->middleware('param_verify'); |
||||
} |
||||
|
||||
protected function success($data = [], $msg = '请求成功', $code = 200) |
||||
{ |
||||
|
||||
if($data instanceof ResourceCollection){ |
||||
$response = ['code' => $code, 'msg' => $msg] + $data->toArray($this->request); |
||||
} else { |
||||
$response = ['code' => $code, 'msg' => $msg, 'data' => $data,]; |
||||
} |
||||
return response()->json($response, $code); |
||||
} |
||||
|
||||
protected function error($code = 400, $msg = '请求失败', $data = []) |
||||
{ |
||||
return response()->json([ |
||||
'code' => $code, |
||||
'msg' => $msg, |
||||
'data' => $data, |
||||
], $code); |
||||
} |
||||
} |
@ -0,0 +1,104 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\CarBrand; |
||||
use App\Http\Resources\CarBrandCollection; |
||||
use App\Models\CarBrandT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 车辆品牌管理 |
||||
* @description CarBrandController |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
*/ |
||||
class CarBrandController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'name' => 'required', |
||||
] |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'name' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CarBrandT,id', |
||||
] |
||||
], |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new CarBrandT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 车辆品牌列表 |
||||
* @description 车辆品牌列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
if(isset($this->params['car_brand_id']) && $this->params['car_brand_id'] > 0){ |
||||
$query->where('car_brand_id', $this->params['car_brand_id']); |
||||
} |
||||
|
||||
if(isset($this->params['is_page']) && $this->params['is_page'] == 1){ |
||||
return $this->success(new CarBrandCollection($query->paginate())); |
||||
} else { |
||||
return $this->success($query->get()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 车辆品牌保存 |
||||
* @description 车辆品牌保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->name = $this->params['name']; |
||||
$this->model->logo = $this->params['logo']; |
||||
$this->model->letter = $this->params['letter']; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarBrand($this->model)); |
||||
} else { |
||||
return $this->error(500, '车辆品牌信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 车辆品牌更新 |
||||
* @description 车辆品牌更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->name = $this->params['name']; |
||||
$this->model->logo = $this->params['logo']; |
||||
$this->model->letter = $this->params['letter']; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarBrand($this->model)); |
||||
} else { |
||||
return $this->error(500, '车辆品牌信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,178 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\CarInfo; |
||||
use App\Http\Resources\CarInfoCollection; |
||||
use App\Models\CarInfoT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title CarInfoController |
||||
* @description CarInfoController |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
*/ |
||||
class CarInfoController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'car_no' => 'required', |
||||
'frame_no' => 'required', |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\CarInfoT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'car_no' => 'required', |
||||
'frame_no' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CarInfoT,id', |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CarInfoT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new CarInfoT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础列表 |
||||
* @description 基础列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new CarInfoCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础保存 |
||||
* @description 基础保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->car_no = $this->params['car_no']; |
||||
$this->model->frame_no = $this->params['frame_no']; |
||||
$this->model->engine_no = $this->params['engine_no']; |
||||
$this->model->factory_model = $this->params['factory_model']; |
||||
$this->model->car_used_type = $this->params['car_used_type']; |
||||
$this->model->car_man = $this->params['car_man']; |
||||
$this->model->purchase_price = $this->params['purchase_price']; |
||||
$this->model->register_date = $this->params['register_date']; |
||||
$this->model->seat_count = $this->params['seat_count']; |
||||
$this->model->insurance_times = $this->params['insurance_times']; |
||||
$this->model->insurance_serial_times = $this->params['insurance_serial_times']; |
||||
$this->model->repair_times = $this->params['repair_times']; |
||||
$this->model->insurance_repair_times = $this->params['insurance_repair_times']; |
||||
$this->model->last_insurance_company = $this->params['last_insurance_company']; |
||||
$this->model->last_insurance_type = $this->params['last_insurance_type']; |
||||
$this->model->last_insurance_rate = $this->params['last_insurance_rate']; |
||||
$this->model->last_insurance_salesman = $this->params['last_insurance_salesman']; |
||||
$this->model->last_insurance_date = $this->params['last_insurance_date']; |
||||
$this->model->force_expire_date = $this->params['force_expire_date']; |
||||
$this->model->business_expire_date = $this->params['business_expire_date']; |
||||
$this->model->status = $this->params['status']; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarInfo($this->model)); |
||||
} else { |
||||
return $this->error(500, '基础信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 基础详情 |
||||
* @description 基础详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new CarInfo($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础更新 |
||||
* @description 基础更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->car_no = $this->params['car_no']; |
||||
$this->model->frame_no = $this->params['frame_no']; |
||||
$this->model->engine_no = $this->params['engine_no']; |
||||
$this->model->factory_model = $this->params['factory_model']; |
||||
$this->model->car_used_type = $this->params['car_used_type']; |
||||
$this->model->car_man = $this->params['car_man']; |
||||
$this->model->purchase_price = $this->params['purchase_price']; |
||||
$this->model->register_date = $this->params['register_date']; |
||||
$this->model->seat_count = $this->params['seat_count']; |
||||
$this->model->insurance_times = $this->params['insurance_times']; |
||||
$this->model->insurance_serial_times = $this->params['insurance_serial_times']; |
||||
$this->model->repair_times = $this->params['repair_times']; |
||||
$this->model->insurance_repair_times = $this->params['insurance_repair_times']; |
||||
$this->model->last_insurance_company = $this->params['last_insurance_company']; |
||||
$this->model->last_insurance_type = $this->params['last_insurance_type']; |
||||
$this->model->last_insurance_rate = $this->params['last_insurance_rate']; |
||||
$this->model->last_insurance_salesman = $this->params['last_insurance_salesman']; |
||||
$this->model->last_insurance_date = $this->params['last_insurance_date']; |
||||
$this->model->force_expire_date = $this->params['force_expire_date']; |
||||
$this->model->business_expire_date = $this->params['business_expire_date']; |
||||
$this->model->status = $this->params['status']; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarInfo($this->model)); |
||||
} else { |
||||
return $this->error(500, '基础信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 基础删除 |
||||
* @description 基础删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
if($this->model->destroy($id)){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '基础信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,158 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\CarModel; |
||||
use App\Http\Resources\CarModelCollection; |
||||
use App\Models\CarModelT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title CarModelController |
||||
* @description CarModelController |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
*/ |
||||
class CarModelController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'car_series_id' => 'required', |
||||
'name' => 'required', |
||||
'year' => 'required', |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\CarModelT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'car_series_id' => 'required', |
||||
'name' => 'required', |
||||
'year' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CarModelT,id', |
||||
] |
||||
], |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new CarModelT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础列表 |
||||
* @description 基础列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
if(isset($this->params['is_page']) && $this->params['is_page'] == 1){ |
||||
$data = $query->paginate(); |
||||
} else { |
||||
$data = $query->get(); |
||||
} |
||||
|
||||
return $this->success(new CarModelCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础保存 |
||||
* @description 基础保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->car_series_id = $this->params['car_series_id']; |
||||
$this->model->name = $this->params['name']; |
||||
$this->model->year = $this->params['year']; |
||||
$this->model->modelYears = $this->params['modelYears']; |
||||
$this->model->vehicle_type = $this->params['vehicle_type']; |
||||
$this->model->vehicle_size = $this->params['vehicle_size']; |
||||
$this->model->engine_model = $this->params['engine_model']; |
||||
$this->model->emission_standard = $this->params['emission_standard']; |
||||
$this->model->displacement = $this->params['displacement']; |
||||
$this->model->induction = $this->params['induction']; |
||||
$this->model->fuel_type = $this->params['fuel_type']; |
||||
$this->model->transmission_type = $this->params['transmission_type']; |
||||
$this->model->transmission_description = $this->params['transmission_description']; |
||||
$this->model->gear_number = $this->params['gear_number']; |
||||
$this->model->front_tyre = $this->params['front_tyre']; |
||||
$this->model->rear_tyre = $this->params['rear_tyre']; |
||||
$this->model->doors = $this->params['doors']; |
||||
$this->model->seats = $this->params['seats']; |
||||
$this->model->tuhu_code = $this->params['tuhu_code']; |
||||
$this->model->guidance_price = $this->params['guidance_price']; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarModel($this->model)); |
||||
} else { |
||||
return $this->error(500, '基础信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 基础详情 |
||||
* @description 基础详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new CarModel($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础更新 |
||||
* @description 基础更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->car_series_id = $this->params['car_series_id']; |
||||
$this->model->name = $this->params['name']; |
||||
$this->model->year = $this->params['year']; |
||||
$this->model->modelYears = $this->params['modelYears']; |
||||
$this->model->vehicle_type = $this->params['vehicle_type']; |
||||
$this->model->vehicle_size = $this->params['vehicle_size']; |
||||
$this->model->engine_model = $this->params['engine_model']; |
||||
$this->model->emission_standard = $this->params['emission_standard']; |
||||
$this->model->displacement = $this->params['displacement']; |
||||
$this->model->induction = $this->params['induction']; |
||||
$this->model->fuel_type = $this->params['fuel_type']; |
||||
$this->model->transmission_type = $this->params['transmission_type']; |
||||
$this->model->transmission_description = $this->params['transmission_description']; |
||||
$this->model->gear_number = $this->params['gear_number']; |
||||
$this->model->front_tyre = $this->params['front_tyre']; |
||||
$this->model->rear_tyre = $this->params['rear_tyre']; |
||||
$this->model->doors = $this->params['doors']; |
||||
$this->model->seats = $this->params['seats']; |
||||
$this->model->tuhu_code = $this->params['tuhu_code']; |
||||
$this->model->guidance_price = $this->params['guidance_price']; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarModel($this->model)); |
||||
} else { |
||||
return $this->error(500, '基础信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,192 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\CarSeries; |
||||
use App\Http\Resources\CarSeriesCollection; |
||||
use App\Models\CarSeriesT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 基础管理 |
||||
* @description CarSeriesController |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
*/ |
||||
class CarSeriesController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'car_sub_brand_id' => 'required|numeric', |
||||
'name' => 'required|string', |
||||
'series' => 'string', |
||||
'level' => 'string', |
||||
'externalPanelPrice' => 'numeric', |
||||
'internalPanelPrice' => 'numeric', |
||||
'externalPaintPrice' => 'numeric', |
||||
'internalPaintPrice' => 'numeric', |
||||
'externalUnderPrice' => 'numeric', |
||||
'internalUnderPrice' => 'numeric', |
||||
'externalPolishPrice' => 'numeric', |
||||
'internalPolishPrice' => 'numeric', |
||||
'externalRepairPrice' => 'numeric', |
||||
'internalRepairPrice' => 'numeric', |
||||
'externalOutreachPrice' => 'numeric', |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\CarSeriesT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'car_sub_brand_id' => 'required|numeric', |
||||
'name' => 'required|string', |
||||
'series' => 'string', |
||||
'level' => 'string', |
||||
'externalPanelPrice' => 'numeric', |
||||
'internalPanelPrice' => 'numeric', |
||||
'externalPaintPrice' => 'numeric', |
||||
'internalPaintPrice' => 'numeric', |
||||
'externalUnderPrice' => 'numeric', |
||||
'internalUnderPrice' => 'numeric', |
||||
'externalPolishPrice' => 'numeric', |
||||
'internalPolishPrice' => 'numeric', |
||||
'externalRepairPrice' => 'numeric', |
||||
'internalRepairPrice' => 'numeric', |
||||
'externalOutreachPrice' => 'numeric', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CarSeriesT,id', |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CarSeriesT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new CarSeriesT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础列表 |
||||
* @description 基础列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] > 0){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new CarSeriesCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础保存 |
||||
* @description 基础保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->car_sub_brand_id = $this->params['car_sub_brand_id'] ?? 0; |
||||
$this->model->name = $this->params['name'] ?? ''; |
||||
$this->model->series = $this->params['series'] ?? ''; |
||||
$this->model->level = $this->params['level'] ?? ''; |
||||
$this->model->externalPanelPrice = $this->params['externalPanelPrice'] ?? 0; |
||||
$this->model->internalPanelPrice = $this->params['internalPanelPrice'] ?? 0; |
||||
$this->model->externalPaintPrice = $this->params['externalPaintPrice'] ?? 0; |
||||
$this->model->internalPaintPrice = $this->params['internalPaintPrice'] ?? 0; |
||||
$this->model->externalUnderPrice = $this->params['externalUnderPrice'] ?? 0; |
||||
$this->model->internalUnderPrice = $this->params['internalUnderPrice'] ?? 0; |
||||
$this->model->externalPolishPrice = $this->params['externalPolishPrice'] ?? 0; |
||||
$this->model->internalPolishPrice = $this->params['internalPolishPrice'] ?? 0; |
||||
$this->model->externalRepairPrice = $this->params['externalRepairPrice'] ?? 0; |
||||
$this->model->internalRepairPrice = $this->params['internalRepairPrice'] ?? 0; |
||||
$this->model->externalOutreachPrice = $this->params['externalOutreachPrice'] ?? 0; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarSeries($this->model)); |
||||
} else { |
||||
return $this->error(500, '基础信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 基础详情 |
||||
* @description 基础详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new CarSeries($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 基础更新 |
||||
* @description 基础更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->car_sub_brand_id = $this->params['car_sub_brand_id'] ?? 0; |
||||
$this->model->name = $this->params['name'] ?? ''; |
||||
$this->model->series = $this->params['series'] ?? ''; |
||||
$this->model->level = $this->params['level'] ?? ''; |
||||
$this->model->externalPanelPrice = $this->params['externalPanelPrice'] ?? 0; |
||||
$this->model->internalPanelPrice = $this->params['internalPanelPrice'] ?? 0; |
||||
$this->model->externalPaintPrice = $this->params['externalPaintPrice'] ?? 0; |
||||
$this->model->internalPaintPrice = $this->params['internalPaintPrice'] ?? 0; |
||||
$this->model->externalUnderPrice = $this->params['externalUnderPrice'] ?? 0; |
||||
$this->model->internalUnderPrice = $this->params['internalUnderPrice'] ?? 0; |
||||
$this->model->externalPolishPrice = $this->params['externalPolishPrice'] ?? 0; |
||||
$this->model->internalPolishPrice = $this->params['internalPolishPrice'] ?? 0; |
||||
$this->model->externalRepairPrice = $this->params['externalRepairPrice'] ?? 0; |
||||
$this->model->internalRepairPrice = $this->params['internalRepairPrice'] ?? 0; |
||||
$this->model->externalOutreachPrice = $this->params['externalOutreachPrice'] ?? 0; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarSeries($this->model)); |
||||
} else { |
||||
return $this->error(500, '基础信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 基础删除 |
||||
* @description 基础删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
if($this->model->destroy($id)){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '基础信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,132 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\CarSubBrand; |
||||
use App\Http\Resources\CarSubBrandCollection; |
||||
use App\Models\CarSubBrandT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 车辆厂家管理 |
||||
* @description CarSubBrandController |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
*/ |
||||
class CarSubBrandController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'car_brand_id' => 'required', |
||||
'name' => 'required', |
||||
] |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'car_brand_id' => 'required', |
||||
'name' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CarSubBrandT,id', |
||||
] |
||||
], |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new CarSubBrandT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 厂家列表 |
||||
* @description 厂家列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
if(isset($this->params['car_brand_id']) && $this->params['car_brand_id'] > 0){ |
||||
$query->where('car_brand_id', $this->params['car_brand_id']); |
||||
} |
||||
|
||||
if(isset($this->params['is_page']) && $this->params['is_page'] == 1){ |
||||
return $this->success(new CarSubBrandCollection($query->paginate())); |
||||
} else { |
||||
return $this->success($query->get()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 厂家保存 |
||||
* @description 厂家保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->car_brand_id = $this->params['car_brand_id']; |
||||
$this->model->name = $this->params['name']; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarSubBrand($this->model)); |
||||
} else { |
||||
return $this->error(500, '厂家信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 厂家详情 |
||||
* @description 厂家详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new CarSubBrand($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 厂家更新 |
||||
* @description 厂家更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->car_brand_id = $this->params['car_brand_id']; |
||||
$this->model->name = $this->params['name']; |
||||
if($this->model->save()){ |
||||
return $this->success(new CarSubBrand($this->model)); |
||||
} else { |
||||
return $this->error(500, '厂家信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 厂家删除 |
||||
* @description 厂家删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
if($this->model->destroy($id)){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '厂家信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Storage; |
||||
|
||||
/** |
||||
* @title CommonController |
||||
* @description CommonController |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
*/ |
||||
class CommonController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'upload' => [ |
||||
'rules' => [ |
||||
'file' => 'required', |
||||
'file_type' => 'required' |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function upload(Request $request) { |
||||
$file = $request->file('file'); |
||||
$fileType = $request->input('file_type','files'); |
||||
$disk = Storage::disk('oss'); |
||||
$filename = $disk->putFile($fileType."/".date('Ymd'), $file); |
||||
$url = str_replace('http://bmoc-files.oss-cn-hangzhou.aliyuncs.com', 'http://images.banmacar.com', $disk->getUrl($filename)); |
||||
return $this->success(['url' => $url]); |
||||
} |
||||
} |
@ -0,0 +1,155 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\CompanyCollection; |
||||
use App\Http\Resources\Company; |
||||
use App\Models\CompanyT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 公司设置 |
||||
* @description 公司设置 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/1/29 |
||||
*/ |
||||
class CompanyController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'title' => 'bail|required|unique:App\Models\CompanyT|max:20', |
||||
'name' => 'bail|required|unique:App\Models\CompanyT|max:20', |
||||
'pid' => 'required', |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|inter|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\CompanyT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|inter|min:1', |
||||
'title' => 'required|max:20', |
||||
'name' => 'bail|required|max:20', |
||||
'pid' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CompanyT,id', |
||||
'unique,App\Models\CompanyT,title,id', |
||||
'unique,App\Models\CompanyT,name,id' |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|inter|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\CompanyT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new CompanyT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 公司列表 |
||||
* @description 公司列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = CompanyT::query(); |
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
if(isset($this->params['title']) && $this->params['title'] != ''){ |
||||
$query->where('title', 'like', '%'. $this->params['title'] .'%'); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new CompanyCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 公司新增 |
||||
* @description 公司新增 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$company = new CompanyT(); |
||||
$company->title = $this->params['title']; |
||||
$company->name = $this->params['name']; |
||||
$company->pid = $this->params['pid']; |
||||
if($company->save()){ |
||||
return $this->success(new Company($company)); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 公司详情 |
||||
* @description 公司详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new Company($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 公司更新 |
||||
* @description 公司更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$company = $this->model->where('id', $id)->first(); |
||||
$company->title = $this->params['title']; |
||||
$company->name = $this->params['name']; |
||||
$company->pid = $this->params['pid']; |
||||
if($company->save()){ |
||||
return $this->success(new Company($company)); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 公司删除 |
||||
* @description 公司删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
if(CompanyT::destroy($id)){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,160 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\DictionaryCollection; |
||||
use App\Http\Resources\Dictionary; |
||||
use App\Models\DictionaryT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 字典管理 |
||||
* @description 字典管理 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/2/3 |
||||
*/ |
||||
class DictionaryController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'name' => 'required', |
||||
'title' => 'required', |
||||
], |
||||
'custom' => 'unique,App\Models\DictionaryT,pid,name' |
||||
|
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\DictionaryT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'name' => 'required', |
||||
'title' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\DictionaryT,id', |
||||
'custom' => 'unique,App\Models\DictionaryT,pid,name,id' |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\DictionaryT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new DictionaryT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 字典列表 |
||||
* @description 字典列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
if(isset($this->params['title']) && $this->params['title'] > 0){ |
||||
$query->where('title', $this->params['title']); |
||||
} |
||||
|
||||
if(isset($this->params['status']) && $this->params['status'] >= 0){ |
||||
$query->where('status', $this->params['status']); |
||||
} else { |
||||
$query->where('status', 1); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new DictionaryCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 字典保存 |
||||
* @description 字典保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->pid = $this->params['pid'] ?? 0; |
||||
$this->model->name = $this->params['name']; |
||||
$this->model->title = $this->params['title']; |
||||
$this->model->status = $this->params['status'] ?? '1'; |
||||
if($this->model->save()){ |
||||
return $this->success(new Dictionary($this->model)); |
||||
} else { |
||||
return $this->error(500, '字典信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 字典详情 |
||||
* @description 字典详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new Dictionary($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 字典更新 |
||||
* @description 字典更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->pid = $this->params['pid'] ?? $this->model->pid; |
||||
$this->model->name = $this->params['name']; |
||||
$this->model->title = $this->params['title']; |
||||
$this->model->status = $this->params['status'] ?? $this->model->status; |
||||
if($this->model->save()){ |
||||
return $this->success(new Dictionary($this->model)); |
||||
} else { |
||||
return $this->error(500, '字典信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 字典删除 |
||||
* @description 字典删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->status = 0; |
||||
if($this->model->save()){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '字典信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,165 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\EmployeeBankCollection; |
||||
use App\Http\Resources\EmployeeBank; |
||||
use App\Models\EmployeeBankT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 银行卡管理 |
||||
* @description 员工银行卡管理 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/2/3 |
||||
*/ |
||||
class EmployeeBankController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'employee_id' => 'required', |
||||
'super_bank_name' => 'required', |
||||
'bank_name' => 'required', |
||||
'bank_code' => 'required', |
||||
'bank_num' => 'required', |
||||
'bank_man' => 'required', |
||||
'maximum' => 'max:10000000', |
||||
], |
||||
'custom' => 'unique,App\Models\EmployeeBankT,bank_num' |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeBankT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'employee_id' => 'required', |
||||
'super_bank_name' => 'required', |
||||
'bank_name' => 'required', |
||||
'bank_code' => 'required', |
||||
'bank_num' => 'required', |
||||
'bank_man' => 'required', |
||||
'maximum' => 'max:10000000', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeBankT,id', |
||||
'unique,App\Models\EmployeeBankT,bank_num,id' |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeBankT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new EmployeeBankT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 银行卡列表 |
||||
* @description 银行卡列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new EmployeeBankCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 银行卡保存 |
||||
* @description 银行卡保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->employee_id = $this->params['employee_id']; |
||||
$this->model->super_bank_name = $this->params['super_bank_name']; |
||||
$this->model->bank_name = $this->params['bank_name']; |
||||
$this->model->bank_code = $this->params['bank_code']; |
||||
$this->model->bank_num = $this->params['bank_num']; |
||||
$this->model->bank_man = $this->params['bank_man']; |
||||
$this->model->maximum = $this->params['maximum']; |
||||
$this->model->priority = $this->params['priority']; |
||||
if($this->model->save()){ |
||||
return $this->success(new EmployeeBank($this->model)); |
||||
} else { |
||||
return $this->error(500, '银行卡信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 银行卡详情 |
||||
* @description 银行卡详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new EmployeeBank($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 银行卡更新 |
||||
* @description 银行卡更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->employee_id = $this->params['employee_id']; |
||||
$this->model->super_bank_name = $this->params['super_bank_name']; |
||||
$this->model->bank_name = $this->params['bank_name']; |
||||
$this->model->bank_code = $this->params['bank_code']; |
||||
$this->model->bank_num = $this->params['bank_num']; |
||||
$this->model->bank_man = $this->params['bank_man']; |
||||
$this->model->maximum = $this->params['maximum']; |
||||
$this->model->priority = $this->params['priority']; |
||||
if($this->model->save()){ |
||||
return $this->success(new EmployeeBank($this->model)); |
||||
} else { |
||||
return $this->error(500, '银行卡信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 银行卡删除 |
||||
* @description 银行卡删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
if($this->model->destroy($id)){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '银行卡信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,170 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\EmployeeCollection; |
||||
use App\Http\Resources\Employee; |
||||
use App\Models\EmployeeT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 员工管理 |
||||
* @description 员工管理 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/2/3 |
||||
*/ |
||||
class EmployeeController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'username' => 'required', |
||||
'nickname' => 'required', |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|integer|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|integer|min:1', |
||||
'username' => 'required', |
||||
'nickname' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeT,id', |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|integer|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new EmployeeT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 员工列表 |
||||
* @description 员工列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
if(isset($this->params['status']) && $this->params['status'] >= 0){ |
||||
$query->where('status', $this->params['status']); |
||||
} else { |
||||
$query->where('status', 3); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new EmployeeCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 员工保存 |
||||
* @description 员工保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->username = $this->params['username']; |
||||
$this->model->nickname = $this->params['nickname']; |
||||
$this->model->password = password_hash($this->params['password']??'123456', PASSWORD_DEFAULT ); |
||||
$this->model->company_id = $this->params['company_id']; |
||||
$this->model->group_id = $this->params['group_id']; |
||||
$this->model->phone = $this->params['phone']; |
||||
$this->model->monthly_working_days = $this->params['monthly_working_days']; |
||||
$this->model->entry_date = $this->params['entry_date']; |
||||
$this->model->official_date = $this->params['official_date']; |
||||
$this->model->resign_date = $this->params['resign_date']; |
||||
$this->model->probation_salary = $this->params['probation_salary']; |
||||
$this->model->official_salary = $this->params['official_salary']; |
||||
$this->model->is_outer = $this->params['is_outer']; |
||||
$this->model->status = $this->params['status']; |
||||
if($this->model->save()){ |
||||
return $this->success(new Employee($this->model)); |
||||
} else { |
||||
return $this->error(500, '员工信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 员工详情 |
||||
* @description 员工详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new Employee($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 员工更新 |
||||
* @description 员工更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->username = $this->params['username']; |
||||
$this->model->nickname = $this->params['nickname']; |
||||
$this->model->company_id = $this->params['company_id']; |
||||
$this->model->group_id = $this->params['group_id']; |
||||
$this->model->phone = $this->params['phone']; |
||||
$this->model->monthly_working_days = $this->params['monthly_working_days']; |
||||
$this->model->entry_date = $this->params['entry_date']; |
||||
$this->model->official_date = $this->params['official_date']; |
||||
$this->model->resign_date = $this->params['resign_date']; |
||||
$this->model->probation_salary = $this->params['probation_salary']; |
||||
$this->model->official_salary = $this->params['official_salary']; |
||||
$this->model->is_outer = $this->params['is_outer']; |
||||
$this->model->status = $this->params['status']; |
||||
if($this->model->save()){ |
||||
return $this->success(new Employee($this->model)); |
||||
} else { |
||||
return $this->error(500, '员工信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 员工删除 |
||||
* @description 员工删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
if($this->model->destroy($id)){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '员工信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,143 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\EmployeeGroup; |
||||
use App\Http\Resources\EmployeeGroupCollection; |
||||
use App\Models\EmployeeGroupT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 岗位管理 |
||||
* @description 岗位管理 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/2/3 |
||||
*/ |
||||
class EmployeeGroupController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'title' => 'required', |
||||
'pid' => 'required', |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeGroupT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'pid' => 'required', |
||||
'title' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeGroupT,id', |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeGroupT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new EmployeeGroupT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 岗位列表 |
||||
* @description 岗位列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$data = $this->model->getTree($this->params['status'] ?? null, $this->params['pid'] ?? 0); |
||||
|
||||
return $this->success($data); |
||||
} |
||||
|
||||
/** |
||||
* @title 岗位保存 |
||||
* @description 岗位保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->pid = $this->params['pid']; |
||||
$this->model->title = $this->params['title']; |
||||
$this->model->level = $this->params['level']; |
||||
$this->model->description = $this->params['description'] ?? ''; |
||||
$this->model->base_salary = $this->params['base_salary'] ?? 0; |
||||
$this->model->status = $this->params['status'] ?? 2; |
||||
if($this->model->save()){ |
||||
return $this->success(new EmployeeGroup($this->model)); |
||||
} else { |
||||
return $this->error(500, '岗位信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 岗位详情 |
||||
* @description 岗位详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new EmployeeGroup($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 岗位更新 |
||||
* @description 岗位更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->pid = $this->params['pid']; |
||||
$this->model->title = $this->params['title']; |
||||
$this->model->level = $this->params['level'] ?? $this->model->level; |
||||
$this->model->description = $this->params['description'] ?? $this->model->description; |
||||
$this->model->base_salary = $this->params['base_salary'] ?? $this->model->base_salary; |
||||
$this->model->status = $this->params['status'] ?? $this->model->status; |
||||
if($this->model->save()){ |
||||
return $this->success(new EmployeeGroup($this->model)); |
||||
} else { |
||||
return $this->error(500, '岗位信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 岗位删除 |
||||
* @description 岗位删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
if($this->model->where('id', $id)->update(['status' => 0])){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '岗位信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,157 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\EmployeeRewardPunishment; |
||||
use App\Http\Resources\EmployeeRewardPunishmentCollection; |
||||
use App\Models\EmployeeRewardPunishmentT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 奖惩管理 |
||||
* @description 考勤,奖励,惩罚等 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/2/3 |
||||
*/ |
||||
class EmployeeRewardPunishmentController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'employee_id' => 'required', |
||||
'type' => 'required', |
||||
'date' => 'required|date', |
||||
'price' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'unique,App\Models\EmployeeRewardPunishmentT,date,type' |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeRewardPunishmentT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'employee_id' => 'required', |
||||
'type' => 'required', |
||||
'date' => 'required|date', |
||||
'price' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeRewardPunishmentT,id', |
||||
'unique,App\Models\EmployeeRewardPunishmentT,date,type,id' |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeRewardPunishmentT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new EmployeeRewardPunishmentT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 奖惩列表 |
||||
* @description 奖惩列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new EmployeeRewardPunishmentCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 奖惩保存 |
||||
* @description 奖惩保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->employee_id = $this->params['employee_id']; |
||||
$this->model->type = $this->params['type']; |
||||
$this->model->price = $this->params['type'] > 600 ? abs($this->params['price']) : -abs($this->params['price']); |
||||
$this->model->remark = $this->params['remark'] ?? ''; |
||||
$this->model->date = $this->params['date'] ?? ''; |
||||
$this->model->status = $this->params['status'] ?? 1; |
||||
if($this->model->save()){ |
||||
return $this->success(new EmployeeRewardPunishment($this->model)); |
||||
} else { |
||||
return $this->error(500, '奖惩信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 奖惩详情 |
||||
* @description 奖惩详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new EmployeeRewardPunishment($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 奖惩更新 |
||||
* @description 奖惩更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->employee_id = $this->params['employee_id']; |
||||
$this->model->type = $this->params['type']; |
||||
$this->model->price = $this->params['type'] > 600 ? abs($this->params['price']) : -abs($this->params['price']); |
||||
$this->model->remark = $this->params['remark'] ?? $this->model->remark; |
||||
if($this->model->save()){ |
||||
return $this->success(new EmployeeRewardPunishment($this->model)); |
||||
} else { |
||||
return $this->error(500, '奖惩信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 奖惩删除 |
||||
* @description 奖惩删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
$this->model = $this->model::find($id); |
||||
$this->model->status = 0; |
||||
if($this->model->save()){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '奖惩信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,157 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\EmployeeSocialItemsCollection; |
||||
use App\Http\Resources\EmployeeSocialItems; |
||||
use App\Models\EmployeeSocialItemsT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 社保管理 |
||||
* @description 社保管理 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/2/3 |
||||
*/ |
||||
class EmployeeSocialItemsController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'employee_id' => 'required', |
||||
'social_type' => 'required', |
||||
'base_price' => 'required', |
||||
'personal_rate' => 'required', |
||||
'unit_rate' => 'required', |
||||
] |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => 'exists,App\Models\EmployeeSocialItemsT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
'employee_id' => 'required', |
||||
'social_type' => 'required', |
||||
'base_price' => 'required', |
||||
'personal_rate' => 'required', |
||||
'unit_rate' => 'required', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeSocialItemsT,id', |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|min:1', |
||||
], |
||||
'custom' => [ |
||||
'exists,App\Models\EmployeeSocialItemsT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new EmployeeSocialItemsT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 社保列表 |
||||
* @description 社保列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = $this->model->query(); |
||||
|
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new EmployeeSocialItemsCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 社保保存 |
||||
* @description 社保保存 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function store() |
||||
{ |
||||
$this->model->employee_id = $this->params['employee_id']; |
||||
$this->model->social_type = $this->params['social_type']; |
||||
$this->model->base_price = $this->params['base_price']; |
||||
$this->model->personal_rate = $this->params['personal_rate']; |
||||
$this->model->unit_rate = $this->params['unit_rate']; |
||||
$this->model->personal_price = $this->params['personal_price'] ?: route($this->params['base_price'] * $this->params['personal_rate'] / 100); |
||||
$this->model->unit_price = $this->params['unit_price'] ?: route($this->params['base_price'] * $this->params['unit_rate'] / 100); |
||||
if($this->model->save()){ |
||||
return $this->success(new EmployeeSocialItems($this->model)); |
||||
} else { |
||||
return $this->error(500, '社保信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 社保详情 |
||||
* @description 社保详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
return $this->success(new EmployeeSocialItems($this->model->where('id', $id)->first())); |
||||
} |
||||
|
||||
/** |
||||
* @title 社保更新 |
||||
* @description 社保更新 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function update($id) |
||||
{ |
||||
$this->model = $this->model->where('id', $id)->first(); |
||||
$this->model->employee_id = $this->params['employee_id']; |
||||
$this->model->social_type = $this->params['social_type']; |
||||
$this->model->base_price = $this->params['base_price']; |
||||
$this->model->personal_rate = $this->params['personal_rate']; |
||||
$this->model->unit_rate = $this->params['unit_rate']; |
||||
$this->model->personal_price = $this->params['personal_price'] ?: route($this->params['base_price'] * $this->params['personal_price'] / 100); |
||||
$this->model->unit_price = $this->params['unit_price'] ?: route($this->params['base_price'] * $this->params['unit_rate'] / 100); |
||||
if($this->model->save()){ |
||||
return $this->success(new EmployeeSocialItems($this->model)); |
||||
} else { |
||||
return $this->error(500, '社保信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 社保删除 |
||||
* @description 社保删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
if($this->model->destroy($id)){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '社保信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,194 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers\Api; |
||||
|
||||
use App\Http\Resources\SystemSetting; |
||||
use App\Http\Resources\SystemSettingCollection; |
||||
use App\Models\SystemSettingT; |
||||
use Illuminate\Http\Request; |
||||
|
||||
/** |
||||
* @title 系统设置 |
||||
* @description 系统设置 |
||||
* @package App\Http\Controllers\Api |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
class SystemSettingController extends BaseController |
||||
{ |
||||
|
||||
protected $rules = [ |
||||
'store' => [ |
||||
'rules' => [ |
||||
'title' => 'required|max:20', |
||||
'name' => 'bail|required|unique:App\Models\SystemSettingT|max:20', |
||||
'data_type' => 'required', |
||||
'prop' => 'required', |
||||
'content' => 'required', |
||||
'sort' => 'integer', |
||||
'status' => 'integer', |
||||
], |
||||
'messages' => [], |
||||
], |
||||
'show' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|inter|min:1', |
||||
], |
||||
'messages' => [], |
||||
'custom' => 'exists,App\Models\SystemSettingT,id' |
||||
], |
||||
'update' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|inter|min:1', |
||||
'title' => 'required|max:20', |
||||
'name' => 'bail|required|max:20', |
||||
'data_type' => 'required', |
||||
'prop' => 'required', |
||||
'content' => 'required', |
||||
'sort' => 'integer', |
||||
'status' => 'integer', |
||||
], |
||||
'messages' => [], |
||||
'custom' => [ |
||||
'exists,App\Models\SystemSettingT,id', |
||||
'unique,App\Models\SystemSettingT,name,id' |
||||
] |
||||
], |
||||
'destroy' => [ |
||||
'rules' => [ |
||||
'id' => 'bail|inter|min:1', |
||||
], |
||||
'messages' => [], |
||||
'custom' => [ |
||||
'exists,App\Models\SystemSettingT,id', |
||||
] |
||||
] |
||||
]; |
||||
|
||||
public function __construct(Request $request) |
||||
{ |
||||
$this->model = new SystemSettingT(); |
||||
parent::__construct($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 配置列表 |
||||
* @description 配置列表 |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function index() |
||||
{ |
||||
$query = SystemSettingT::query(); |
||||
if(isset($this->params['prop']) && $this->params['prop'] != ''){ |
||||
$query->where('prop', $this->params['prop']); |
||||
} |
||||
if(isset($this->params['group']) && $this->params['group'] != ''){ |
||||
$query->where('group', $this->params['group']); |
||||
} |
||||
if(isset($this->params['name']) && $this->params['name'] != ''){ |
||||
$query->where('name', $this->params['name']); |
||||
} |
||||
if(isset($this->params['status']) && $this->params['status'] >= 0){ |
||||
$query->where('status', $this->params['status']); |
||||
} else { |
||||
$query->where('status', 1); |
||||
} |
||||
if(isset($this->params['title']) && $this->params['title'] != ''){ |
||||
$query->where('title', 'like', '%'. $this->params['title'] .'%'); |
||||
} |
||||
|
||||
$data = $query->paginate(); |
||||
|
||||
return $this->success(new SystemSettingCollection($data)); |
||||
} |
||||
|
||||
/** |
||||
* @title 配置新增 |
||||
* @description 配置新增 |
||||
* @param Request $request |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function store(Request $request) |
||||
{ |
||||
$setting = new SystemSettingT(); |
||||
$setting->name = $this->params['name']; |
||||
$setting->title = $this->params['title']; |
||||
$setting->data_type = $this->params['data_type']; |
||||
$setting->prop = $this->params['prop']; |
||||
$setting->group = $this->params['group'] ?? ''; |
||||
$setting->content = $this->params['content']; |
||||
$setting->remark = $this->params['remark'] ?? ''; |
||||
$setting->sort = $this->params['sort'] ?? 1; |
||||
$setting->status = $this->params['status'] ?? 1; |
||||
if($setting->save()){ |
||||
return $this->success($setting); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 配置详情 |
||||
* @description 配置详情 |
||||
* @param $id |
||||
* @return mixed |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function show($id) |
||||
{ |
||||
$setting = SystemSettingT::find($id); |
||||
return $this->success(new SystemSetting($setting)); |
||||
} |
||||
|
||||
/** |
||||
* @title 配置更新 |
||||
* @description 配置更新 |
||||
* @param Request $request |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function update(Request $request, $id) |
||||
{ |
||||
$setting = SystemSettingT::find($id); |
||||
$setting->name = $this->params['name']; |
||||
$setting->title = $this->params['title']; |
||||
$setting->data_type = $this->params['data_type']; |
||||
$setting->prop = $this->params['prop']; |
||||
$setting->group = $this->params['group'] ?? $setting->group; |
||||
$setting->content = $this->params['content']; |
||||
$setting->remark = $this->params['remark'] ?? $setting->remark; |
||||
$setting->sort = $this->params['sort'] ?? $setting->sort; |
||||
$setting->status = $this->params['status'] ?? $setting->status; |
||||
if($setting->save()){ |
||||
return $this->success(new SystemSetting($setting)); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @title 配置删除 |
||||
* @description 软删除 |
||||
* @param $id |
||||
* @return \Illuminate\Http\JsonResponse |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
$setting = SystemSettingT::find($id); |
||||
$setting->status = 0; |
||||
if($setting->save()){ |
||||
return $this->success(); |
||||
} else { |
||||
return $this->error(500, '配置信息保存失败'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,13 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
||||
use Illuminate\Foundation\Bus\DispatchesJobs; |
||||
use Illuminate\Foundation\Validation\ValidatesRequests; |
||||
use Illuminate\Routing\Controller as BaseController; |
||||
|
||||
class Controller extends BaseController |
||||
{ |
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; |
||||
} |
@ -0,0 +1,67 @@ |
||||
<?php |
||||
|
||||
namespace App\Http; |
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel; |
||||
|
||||
class Kernel extends HttpKernel |
||||
{ |
||||
/** |
||||
* The application's global HTTP middleware stack. |
||||
* |
||||
* These middleware are run during every request to your application. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $middleware = [ |
||||
// \App\Http\Middleware\TrustHosts::class, |
||||
\App\Http\Middleware\TrustProxies::class, |
||||
\Fruitcake\Cors\HandleCors::class, |
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class, |
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, |
||||
\App\Http\Middleware\TrimStrings::class, |
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, |
||||
]; |
||||
|
||||
/** |
||||
* The application's route middleware groups. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $middlewareGroups = [ |
||||
'web' => [ |
||||
\App\Http\Middleware\EncryptCookies::class, |
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, |
||||
\Illuminate\Session\Middleware\StartSession::class, |
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class, |
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class, |
||||
\App\Http\Middleware\VerifyCsrfToken::class, |
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class, |
||||
], |
||||
|
||||
'api' => [ |
||||
'throttle:api', |
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class, |
||||
], |
||||
]; |
||||
|
||||
/** |
||||
* The application's route middleware. |
||||
* |
||||
* These middleware may be assigned to groups or used individually. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $routeMiddleware = [ |
||||
'auth' => \App\Http\Middleware\Authenticate::class, |
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, |
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, |
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class, |
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, |
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, |
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, |
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, |
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, |
||||
'param_verify' => \App\Http\Middleware\ParamVerify::class, |
||||
]; |
||||
} |
@ -0,0 +1,22 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use App\Services\Authenticate as Middleware; |
||||
|
||||
class Authenticate extends Middleware |
||||
{ |
||||
|
||||
/** |
||||
* Get the path the user should be redirected to when they are not authenticated. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return string|null |
||||
*/ |
||||
protected function redirectTo($request) |
||||
{ |
||||
// if (! $request->expectsJson()) { |
||||
// return route('login'); |
||||
// } |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware; |
||||
|
||||
class EncryptCookies extends Middleware |
||||
{ |
||||
/** |
||||
* The names of the cookies that should not be encrypted. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $except = [ |
||||
// |
||||
]; |
||||
} |
@ -0,0 +1,123 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use App\Libs\MyLib; |
||||
use Closure; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Support\Facades\Validator; |
||||
|
||||
class ParamVerify |
||||
{ |
||||
/** |
||||
* Handle an incoming request. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @param \Closure $next |
||||
* @return mixed |
||||
*/ |
||||
public function handle(Request $request, Closure $next) |
||||
{ |
||||
$rules = $request->get('rules'); |
||||
$attributes = $request->get('attributes'); |
||||
array_walk($attributes, function(&$value){ |
||||
if(is_array($value)) $value = $value['title']; |
||||
}); |
||||
if(count($rules) > 0) { |
||||
$validator = Validator::make($request->input(), $rules['rules'], $rules['messages'] ?? [], $attributes); |
||||
if (isset($rules['custom']) && $rules['custom']) { |
||||
$param = $request->input(); |
||||
if($request->route('id')){ |
||||
$param['id'] = $request->route('id'); |
||||
} |
||||
$validator->after(function ($validator) use ($rules, &$param, &$attributes) { |
||||
$data = true; |
||||
if(is_array($rules['custom'])){ |
||||
foreach ($rules['custom'] as $callback){ |
||||
$data = $this->validate(explode(',', $callback), $param, $attributes); |
||||
if($data !== true){ |
||||
break; |
||||
} |
||||
} |
||||
} else { |
||||
$data = $this->validate(explode(',', $rules['custom']), $param, $attributes); |
||||
} |
||||
if (is_array($data)) { |
||||
$validator->errors()->add($data['field'], $data['message']); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
if ($validator->fails()) { |
||||
return response()->json(['code' => 422, 'msg' => $validator->errors()->first(), 'data' => $validator->errors()->all()], 400); |
||||
} |
||||
} |
||||
return $next($request); |
||||
} |
||||
|
||||
private function validate($rule, $param, $attributes) |
||||
{ |
||||
switch ($rule[0]) { |
||||
case 'exists': |
||||
$model = new $rule[1](); |
||||
if ($model->where($rule[2], $param[$rule[2]])->count() > 0) { |
||||
return true; |
||||
} else { |
||||
return ['field' => 'id', 'message' => '当前信息不存在']; |
||||
} |
||||
break; |
||||
case 'unique': |
||||
$model = new $rule[1](); |
||||
$msg = $attributes[$rule[2]]; |
||||
$model = $model->where($rule[2], $param[$rule[2]]); |
||||
if((count($rule)) >= 4){ |
||||
foreach ($rule as $key => $item){ |
||||
if($item == 'id'){ |
||||
$model = $model->where('id', '<>', $param['id']); |
||||
} else if($key > 2){ |
||||
$msg .= '--'. $attributes[$item]; |
||||
$model = $model->where($item, $param[$item]); |
||||
} |
||||
} |
||||
} |
||||
if ($model->count() > 0) { |
||||
return ['field' => 'id', 'message' => $msg .' 字段已存在']; |
||||
} else { |
||||
return true; |
||||
} |
||||
break; |
||||
case 'ip_check': |
||||
$model = new $rule[1](); |
||||
$ip_addrs = explode(',', $model->where('name', $rule[2])->value('content')); |
||||
if (in_array(MyLib::GetClientIP(), $ip_addrs)) { |
||||
return true; |
||||
} else { |
||||
return ['field' => 'ip', 'message' => '禁止外网访问']; |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
|
||||
private function calc($operator, $value1, $value2) |
||||
{ |
||||
switch ($operator){ |
||||
case 'eq': |
||||
return $value1 == $value2; |
||||
case 'neq': |
||||
return $value1 != $value2; |
||||
case 'gt': |
||||
return $value1 > $value2; |
||||
case 'egt': |
||||
return $value1 >= $value2; |
||||
case 'lt': |
||||
return $value1 < $value2; |
||||
case 'elt': |
||||
return $value1 <= $value2; |
||||
case 'heq': |
||||
return $value1 === $value2; |
||||
case 'nheq': |
||||
return $value1 !== $value2; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware; |
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware |
||||
{ |
||||
/** |
||||
* The URIs that should be reachable while maintenance mode is enabled. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $except = [ |
||||
// |
||||
]; |
||||
} |
@ -0,0 +1,32 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use App\Providers\RouteServiceProvider; |
||||
use Closure; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\Auth; |
||||
|
||||
class RedirectIfAuthenticated |
||||
{ |
||||
/** |
||||
* Handle an incoming request. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @param \Closure $next |
||||
* @param string|null ...$guards |
||||
* @return mixed |
||||
*/ |
||||
public function handle(Request $request, Closure $next, ...$guards) |
||||
{ |
||||
$guards = empty($guards) ? [null] : $guards; |
||||
|
||||
foreach ($guards as $guard) { |
||||
if (Auth::guard($guard)->check()) { |
||||
return redirect(RouteServiceProvider::HOME); |
||||
} |
||||
} |
||||
|
||||
return $next($request); |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware; |
||||
|
||||
class TrimStrings extends Middleware |
||||
{ |
||||
/** |
||||
* The names of the attributes that should not be trimmed. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $except = [ |
||||
'password', |
||||
'password_confirmation', |
||||
]; |
||||
} |
@ -0,0 +1,20 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware; |
||||
|
||||
class TrustHosts extends Middleware |
||||
{ |
||||
/** |
||||
* Get the host patterns that should be trusted. |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function hosts() |
||||
{ |
||||
return [ |
||||
$this->allSubdomainsOfApplicationUrl(), |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use Fideloper\Proxy\TrustProxies as Middleware; |
||||
use Illuminate\Http\Request; |
||||
|
||||
class TrustProxies extends Middleware |
||||
{ |
||||
/** |
||||
* The trusted proxies for this application. |
||||
* |
||||
* @var array|string|null |
||||
*/ |
||||
protected $proxies; |
||||
|
||||
/** |
||||
* The headers that should be used to detect proxies. |
||||
* |
||||
* @var int |
||||
*/ |
||||
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB; |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Middleware; |
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware; |
||||
|
||||
class VerifyCsrfToken extends Middleware |
||||
{ |
||||
/** |
||||
* The URIs that should be excluded from CSRF verification. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $except = [ |
||||
// |
||||
]; |
||||
} |
@ -0,0 +1,30 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class AuthRule extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
$status_txts = [0 => '删除', 1 => '启用', 2 => '关闭']; |
||||
return [ |
||||
'id' => $this->id, |
||||
'name' => $this->name, |
||||
'method' => $this->method, |
||||
'title' => $this->title, |
||||
'group' => $this->group, |
||||
'module' => $this->module, |
||||
'condition' => $this->condition, |
||||
'status' => $this->status, |
||||
'status_txt' => $status_txts[$this->status] |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
|
||||
class AuthRuleCollection extends BaseCollection |
||||
{ |
||||
|
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection; |
||||
|
||||
class BaseCollection extends ResourceCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'data' => $this->collection, |
||||
'links' => [ |
||||
'path' => $this->path(), |
||||
"first"=> $this->url(1), |
||||
"last"=> $this->url($this->lastPage()), |
||||
"prev"=> $this->previousPageUrl(), |
||||
"next"=> $this->nextPageUrl() |
||||
|
||||
], |
||||
'meta' => [ |
||||
"current_page"=> $this->currentPage(), |
||||
"last_page"=> $this->lastPage(), |
||||
'per_page' => $this->perPage(), |
||||
"total"=> $this->total() |
||||
], |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class CarBrand extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'name' => $this->name, |
||||
'logo' => $this->logo, |
||||
'letter' => $this->letter, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class CarBrandCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,44 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class CarInfo extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'car_no' => $this->car_no, |
||||
'frame_no' => $this->frame_no, |
||||
'engine_no' => $this->engine_no, |
||||
'factory_model' => $this->factory_model, |
||||
'car_used_type' => $this->car_used_type, |
||||
'car_man' => $this->car_man, |
||||
'purchase_price' => $this->purchase_price, |
||||
'register_date' => $this->register_date, |
||||
'seat_count' => $this->seat_count, |
||||
'insurance_times' => $this->insurance_times, |
||||
'insurance_serial_times' => $this->insurance_serial_times, |
||||
'repair_times' => $this->repair_times, |
||||
'insurance_repair_times' => $this->insurance_repair_times, |
||||
'last_insurance_company' => $this->last_insurance_company, |
||||
'last_insurance_type' => $this->last_insurance_type, |
||||
'last_insurance_rate' => $this->last_insurance_rate, |
||||
'last_insurance_salesman' => $this->last_insurance_salesman, |
||||
'last_insurance_date' => $this->last_insurance_date, |
||||
'force_expire_date' => $this->force_expire_date, |
||||
'business_expire_date' => $this->business_expire_date, |
||||
'status' => $this->status, |
||||
'created_at' => $this->created_at, |
||||
'updated_at' => $this->updated_at, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class CarInfoCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class CarModel extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'car_series_id' => $this->car_series_id, |
||||
'name' => $this->name, |
||||
'year' => $this->year, |
||||
'modelYears' => $this->modelYears, |
||||
'vehicle_type' => $this->vehicle_type, |
||||
'vehicle_size' => $this->vehicle_size, |
||||
'engine_model' => $this->engine_model, |
||||
'emission_standard' => $this->emission_standard, |
||||
'displacement' => $this->displacement, |
||||
'induction' => $this->induction, |
||||
'fuel_type' => $this->fuel_type, |
||||
'transmission_type' => $this->transmission_type, |
||||
'transmission_description' => $this->transmission_description, |
||||
'gear_number' => $this->gear_number, |
||||
'front_tyre' => $this->front_tyre, |
||||
'rear_tyre' => $this->rear_tyre, |
||||
'doors' => $this->doors, |
||||
'seats' => $this->seats, |
||||
'tuhu_code' => $this->tuhu_code, |
||||
'guidance_price' => $this->guidance_price, |
||||
'created_at' => $this->created_at, |
||||
'updated_at' => $this->updated_at, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class CarModelCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class CarSeries extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'car_sub_brand_id' => $this->car_sub_brand_id, |
||||
'name' => $this->name, |
||||
'series' => $this->series, |
||||
'level' => $this->level, |
||||
'externalPanelPrice' => $this->externalPanelPrice, |
||||
'internalPanelPrice' => $this->internalPanelPrice, |
||||
'externalPaintPrice' => $this->externalPaintPrice, |
||||
'internalPaintPrice' => $this->internalPaintPrice, |
||||
'externalUnderPrice' => $this->externalUnderPrice, |
||||
'internalUnderPrice' => $this->internalUnderPrice, |
||||
'externalPolishPrice' => $this->externalPolishPrice, |
||||
'internalPolishPrice' => $this->internalPolishPrice, |
||||
'externalRepairPrice' => $this->externalRepairPrice, |
||||
'internalRepairPrice' => $this->internalRepairPrice, |
||||
'externalOutreachPrice' => $this->externalOutreachPrice, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class CarSeriesCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class CarSubBrand extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'car_brand_id' => $this->car_brand_id, |
||||
'name' => $this->name, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class CarSubBrandCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class Company extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'name' => $this->name, |
||||
'title' => $this->title, |
||||
'pid' => $this->pid, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
|
||||
class CompanyCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,25 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class Dictionary extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'pid' => $this->pid, |
||||
'name' => $this->name, |
||||
'title' => $this->title, |
||||
'status' => $this->status, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
|
||||
class DictionaryCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,34 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class Employee extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'username' => $this->username, |
||||
'nickname' => $this->nickname, |
||||
'company_id' => $this->company_id, |
||||
'group_id' => $this->group_id, |
||||
'phone' => $this->phone, |
||||
'monthly_working_days' => $this->monthly_working_days, |
||||
'entry_date' => $this->entry_date, |
||||
'official_date' => $this->official_date, |
||||
'resign_date' => $this->resign_date, |
||||
'probation_salary' => $this->probation_salary, |
||||
'official_salary' => $this->official_salary, |
||||
'is_outer' => $this->is_outer, |
||||
'status' => $this->status, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,29 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class EmployeeBank extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'employee_id' => $this->employee_id, |
||||
'super_bank_name' => $this->super_bank_name, |
||||
'bank_name' => $this->bank_name, |
||||
'bank_code' => $this->bank_code, |
||||
'bank_num' => $this->bank_num, |
||||
'bank_man' => $this->bank_man, |
||||
'maximum' => $this->maximum, |
||||
'priority' => $this->priority, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class EmployeeBankCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class EmployeeCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class EmployeeGroup extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'pid' => $this->pid, |
||||
'title' => $this->title, |
||||
'level' => $this->level, |
||||
'description' => $this->description, |
||||
'base_salary' => $this->base_salary, |
||||
'status' => $this->status, |
||||
'rules' => $this->rules, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class EmployeeGroupCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use App\Models\DictionaryT; |
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class EmployeeRewardPunishment extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'employee_id' => $this->employee_id, |
||||
'type' => $this->type, |
||||
'date' => $this->date, |
||||
'type_txt' => DictionaryT::getDictValue('REWARD_TYPE', $this->type), |
||||
'price' => $this->price, |
||||
'remark' => $this->remark, |
||||
'status' => $this->status, |
||||
'status_txt' => DictionaryT::getDictValue('REWARD_STATUS', $this->status), |
||||
'created_at' => $this->created_at->toDateTimeString(), |
||||
'updated_at' => $this->updated_at->toDateTimeString(), |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class EmployeeRewardPunishmentCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class EmployeeSocialItems extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return [ |
||||
'id' => $this->id, |
||||
'employee_id' => $this->employee_id, |
||||
'social_type' => $this->social_type, |
||||
'base_price' => $this->base_price, |
||||
'personal_rate' => $this->personal_rate, |
||||
'unit_rate' => $this->unit_rate, |
||||
'personal_price' => $this->personal_price, |
||||
'unit_price' => $this->unit_price, |
||||
'created_at' => $this->created_at, |
||||
'updated_at' => $this->updated_at, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
class EmployeeSocialItemsCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,34 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class SystemSetting extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
$status_txts = [0 => '删除', 1 => '启用', 2 => '关闭']; |
||||
return [ |
||||
'id' => $this->id, |
||||
'name' => $this->name, |
||||
'data_type' => $this->data_type, |
||||
'title' => $this->title, |
||||
'group' => $this->group, |
||||
'prop' => $this->prop, |
||||
'content' => $this->content, |
||||
'remark' => $this->remark, |
||||
'sort' => $this->sort, |
||||
'status' => $this->status, |
||||
'status_txt' => $status_txts[$this->status], |
||||
'created_at' => $this->created_at->toDateTimeString(), |
||||
'updated_at' => $this->updated_at->toDateTimeString() |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
<?php |
||||
|
||||
namespace App\Http\Resources; |
||||
|
||||
|
||||
class SystemSettingCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,140 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace App\Libs; |
||||
|
||||
|
||||
/** |
||||
* @title Doc |
||||
* @description Doc |
||||
* @package App\Libs |
||||
* @author zcstatham |
||||
* @time 2021/1/28 |
||||
*/ |
||||
Class Doc{ |
||||
|
||||
private $params = array (); |
||||
/** |
||||
* 解析注释 |
||||
* @param string $doc |
||||
* @return array |
||||
*/ |
||||
public function parse($doc = '') { |
||||
if ($doc == '' || !$doc) { |
||||
return $this->params; |
||||
} |
||||
// Get the comment |
||||
if (preg_match('#^/\*\*(.*)\*/#s', $doc, $comment) === false) |
||||
return $this->params; |
||||
$comment = trim($comment[1]); |
||||
// Get all the lines and strip the * from the first character |
||||
if (preg_match_all('#^\s*\*(.*)#m', $comment, $lines) === false) |
||||
return $this->params; |
||||
$this->parseLines($lines[1]); |
||||
return $this->params; |
||||
} |
||||
|
||||
private function parseLines($lines) { |
||||
$desc = []; |
||||
foreach ($lines as $line) { |
||||
$parsedLine = $this->parseLine($line); // Parse the line |
||||
if ($parsedLine === false && !isset ($this->params['description'])) { |
||||
if (isset ($desc)) { |
||||
// Store the first line in the short description |
||||
$this->params['description'] = implode(PHP_EOL, $desc); |
||||
} |
||||
$desc = array(); |
||||
} elseif ($parsedLine !== false) { |
||||
$desc[] = $parsedLine; // Store the line in the long description |
||||
} |
||||
} |
||||
$desc = implode(' ', $desc); |
||||
if (!empty ($desc)) |
||||
$this->params['long_description'] = $desc; |
||||
} |
||||
|
||||
private function parseLine($line) { |
||||
// trim the whitespace from the line |
||||
$line = trim($line); |
||||
if (empty ($line)) |
||||
return false; // Empty line |
||||
if (strpos($line, '@') === 0) { |
||||
if (strpos($line, ' ') > 0) { |
||||
// Get the parameter name |
||||
$param = substr($line, 1, strpos($line, ' ') - 1); |
||||
$value = substr($line, strlen($param) + 2); // Get the value |
||||
} else { |
||||
$param = substr($line, 1); |
||||
$value = ''; |
||||
} |
||||
if($value == 'Request $request') |
||||
return false; |
||||
// Parse the line and return false if the parameter is valid |
||||
if ($this->setParam($param, $value)) |
||||
return false; |
||||
} |
||||
return $line; |
||||
} |
||||
|
||||
private function setParam($param, $value) { |
||||
if ($param == 'param' || $param == 'header') |
||||
$value = $this->formatParam($value); |
||||
if ($param == 'class') |
||||
list ($param, $value) = $this->formatClass($value); |
||||
if ($param == 'return' || $param == 'param' || $param == 'header') { |
||||
$this->params[$param][] = $value; |
||||
} else if (empty ($this->params[$param])) { |
||||
$this->params[$param] = $value; |
||||
} else { |
||||
$this->params[$param] = $this->params[$param] . $value; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
private function formatClass($value) { |
||||
$r = preg_split("[\(|\)]", $value); |
||||
if (is_array($r)) { |
||||
$param = $r[0]; |
||||
parse_str($r[1], $value); |
||||
foreach ($value as $key => $val) { |
||||
$val = explode(',', $val); |
||||
if (count($val) > 1) |
||||
$value[$key] = $val; |
||||
} |
||||
} else { |
||||
$param = 'Unknown'; |
||||
} |
||||
return array($param, $value); |
||||
} |
||||
|
||||
private function formatParam($string) { |
||||
$string = $string . " "; |
||||
if (preg_match_all('/(\w+):(.*?)[\s\n]/s', $string, $match)) { |
||||
$param = []; |
||||
foreach ($match[1] as $key => $value) { |
||||
$param[$match[1][$key]] = $this->getParamType($match[2][$key]); |
||||
} |
||||
return $param; |
||||
} else if (preg_match('/(\w+) (\$.*?)[\s\n]/s', $string, $match)) { |
||||
return $match[2]; |
||||
} else { |
||||
return trim($string); |
||||
} |
||||
} |
||||
|
||||
private function getParamType($type) |
||||
{ |
||||
$typeMaps = [ |
||||
'string' => '字符串', |
||||
'int' => '整型', |
||||
'float' => '浮点型', |
||||
'boolean' => '布尔型', |
||||
'date' => '日期', |
||||
'array' => '数组', |
||||
'fixed' => '固定值', |
||||
'enum' => '枚举类型', |
||||
'object' => '对象', |
||||
]; |
||||
return array_key_exists($type, $typeMaps) ? $typeMaps[$type] : $type; |
||||
} |
||||
} |
@ -0,0 +1,73 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace App\Libs; |
||||
|
||||
|
||||
/** |
||||
* @title MyLib |
||||
* @description MyLib |
||||
* @package App\Service |
||||
* @author zcstatham |
||||
* @time 2021/1/25 |
||||
*/ |
||||
class MyLib |
||||
{ |
||||
public static function scanFile($path) { |
||||
$result = array(); |
||||
$files = scandir($path); |
||||
foreach ($files as $file) { |
||||
if ($file != '.' && $file != '..') { |
||||
if (is_dir($path . '/' . $file)) { |
||||
self::scanFile($path . '/' . $file); |
||||
} else { |
||||
$result[] = substr(basename($file), 0, -4); |
||||
} |
||||
} |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
public static function Parser($text) { |
||||
$doc = new Doc(); |
||||
return $doc->parse($text); |
||||
} |
||||
|
||||
public static function GetClientIP() |
||||
{ |
||||
global $HTTP_SERVER_VARS; |
||||
if (isset($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) { |
||||
$ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]; |
||||
} elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"]) { |
||||
$ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"]; |
||||
} elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"]) { |
||||
$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"]; |
||||
} elseif (getenv("HTTP_X_FORWARDED_FOR")) { |
||||
$ip = getenv("HTTP_X_FORWARDED_FOR"); |
||||
} elseif (getenv("HTTP_CLIENT_IP")) { |
||||
$ip = getenv("HTTP_CLIENT_IP"); |
||||
} elseif (getenv("REMOTE_ADDR")) { |
||||
$ip = getenv("REMOTE_ADDR"); |
||||
} else { |
||||
$ip = "0.0.0.0"; |
||||
} |
||||
return $ip ; |
||||
} |
||||
|
||||
public static function GetServerIP() |
||||
{ |
||||
$ip = '0.0.0.0'; |
||||
if (isset($_SERVER)) { |
||||
if (isset($_SERVER['SERVER_ADDR'])) { |
||||
$ip = $_SERVER['SERVER_ADDR']; |
||||
} elseif (isset($_SERVER['LOCAL_ADDR'])) { |
||||
$ip = $_SERVER['LOCAL_ADDR']; |
||||
} elseif (isset($_SERVER['SERVER_NAME'])) { |
||||
return gethostbyname($_SERVER['SERVER_NAME']); |
||||
} |
||||
} else { |
||||
$ip = getenv('SERVER_ADDR'); |
||||
} |
||||
return $ip; |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,47 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_auth_rule_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $title varchar |
||||
* @property $name varchar |
||||
* @property $method varchar |
||||
* @property $desc varchar |
||||
* @property $group varchar |
||||
* @property $module varchar |
||||
* @property $condition varchar |
||||
* @property $status tinyint |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class AuthRuleT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_auth_rule_t'; |
||||
|
||||
public $attrs = [ |
||||
'title' => ['name' => 'title', 'title' => '标题', 'type' => 'varchar', 'is_must' => '1'], |
||||
'name' => ['name' => 'name', 'title' => '名称,英文唯一标识', 'type' => 'varchar', 'is_must' => '1'], |
||||
'method' => ['name' => 'method', 'title' => '请求方法', 'type' => 'varchar', 'is_must' => '1'], |
||||
'desc' => ['name' => 'desc', 'title' => '描述', 'type' => 'varchar', 'is_must' => '1'], |
||||
'group' => ['name' => 'group', 'title' => '权限节点分组', 'type' => 'varchar', 'is_must' => '1'], |
||||
'module' => ['name' => 'module', 'title' => '所属模块', 'type' => 'varchar', 'is_must' => '1'], |
||||
'condition' => ['name' => 'condition', 'title' => '规则附加条件', 'type' => 'varchar', 'is_must' => '1'], |
||||
'status' => ['name' => 'status', 'title' => '状态 1 有效 2 无效', 'type' => 'tinyint', 'is_must' => '1'], |
||||
]; |
||||
|
||||
protected $fillable = [ |
||||
'title', |
||||
'name', |
||||
'desc', |
||||
'group', |
||||
'module', |
||||
]; |
||||
} |
@ -0,0 +1,28 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_car_brand_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $name varchar |
||||
* @property $logo varchar |
||||
* @property $letter varchar |
||||
*/ |
||||
class CarBrandT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_car_brand_t'; |
||||
public $timestamps = false; |
||||
|
||||
public $attrs = [ |
||||
'name' => ['name' => 'name', 'title' => '名称', 'type' => 'varchar', 'is_must' => '1'], |
||||
'logo' => ['name' => 'logo', 'title' => '图标', 'type' => 'varchar', 'is_must' => '0'], |
||||
'letter' => ['name' => 'letter', 'title' => '字母', 'type' => 'varchar', 'is_must' => '0'], |
||||
]; |
||||
} |
@ -0,0 +1,65 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_car_info_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $car_no varchar |
||||
* @property $frame_no varchar |
||||
* @property $engine_no varchar |
||||
* @property $factory_model varchar |
||||
* @property $car_used_type varchar |
||||
* @property $car_man varchar |
||||
* @property $purchase_price varchar |
||||
* @property $register_date varchar |
||||
* @property $seat_count varchar |
||||
* @property $insurance_times tinyint |
||||
* @property $insurance_serial_times tinyint |
||||
* @property $repair_times tinyint |
||||
* @property $insurance_repair_times tinyint |
||||
* @property $last_insurance_company varchar |
||||
* @property $last_insurance_type varchar |
||||
* @property $last_insurance_rate tinyint |
||||
* @property $last_insurance_salesman varchar |
||||
* @property $last_insurance_date varchar |
||||
* @property $force_expire_date varchar |
||||
* @property $business_expire_date varchar |
||||
* @property $status tinyint |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class CarInfoT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_car_info_t'; |
||||
|
||||
public $attrs = [ |
||||
'car_no' => ['name' => 'car_no', 'title' => '车牌号', 'type' => 'varchar', 'is_must' => '1'], |
||||
'frame_no' => ['name' => 'frame_no', 'title' => '车架号', 'type' => 'varchar', 'is_must' => '1'], |
||||
'engine_no' => ['name' => 'engine_no', 'title' => '发动机号', 'type' => 'varchar', 'is_must' => '0'], |
||||
'factory_model' => ['name' => 'factory_model', 'title' => '厂牌型号', 'type' => 'varchar', 'is_must' => '0'], |
||||
'car_used_type' => ['name' => 'car_used_type', 'title' => '车辆使用性质', 'type' => 'varchar', 'is_must' => '0'], |
||||
'car_man' => ['name' => 'car_man', 'title' => '车主姓名', 'type' => 'varchar', 'is_must' => '0'], |
||||
'purchase_price' => ['name' => 'purchase_price', 'title' => '新车购置价', 'type' => 'varchar', 'is_must' => '0'], |
||||
'register_date' => ['name' => 'register_date', 'title' => '初登日期', 'type' => 'varchar', 'is_must' => '0'], |
||||
'seat_count' => ['name' => 'seat_count', 'title' => '座位数', 'type' => 'varchar', 'is_must' => '0'], |
||||
'insurance_times' => ['name' => 'insurance_times', 'title' => '投保次数', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'insurance_serial_times' => ['name' => 'insurance_serial_times', 'title' => '连续投保次数', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'repair_times' => ['name' => 'repair_times', 'title' => '维修次数', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'insurance_repair_times' => ['name' => 'insurance_repair_times', 'title' => '回修次数', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'last_insurance_company' => ['name' => 'last_insurance_company', 'title' => '上年承保公司', 'type' => 'varchar', 'is_must' => '0'], |
||||
'last_insurance_type' => ['name' => 'last_insurance_type', 'title' => '上年承保险种', 'type' => 'varchar', 'is_must' => '0'], |
||||
'last_insurance_rate' => ['name' => 'last_insurance_rate', 'title' => '上年保险折扣率', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'last_insurance_salesman' => ['name' => 'last_insurance_salesman', 'title' => '上年保险业务', 'type' => 'varchar', 'is_must' => '0'], |
||||
'last_insurance_date' => ['name' => 'last_insurance_date', 'title' => '上年正本日期', 'type' => 'varchar', 'is_must' => '0'], |
||||
'force_expire_date' => ['name' => 'force_expire_date', 'title' => '交强到期日期', 'type' => 'varchar', 'is_must' => '0'], |
||||
'business_expire_date' => ['name' => 'business_expire_date', 'title' => '商业到期日期', 'type' => 'varchar', 'is_must' => '0'], |
||||
'status' => ['name' => 'status', 'title' => '数据状态', 'type' => 'tinyint', 'is_must' => '0'], |
||||
]; |
||||
} |
@ -0,0 +1,63 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_car_model_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $car_series_id int |
||||
* @property $name varchar |
||||
* @property $year varchar |
||||
* @property $modelYears varchar |
||||
* @property $vehicle_type varchar |
||||
* @property $vehicle_size varchar |
||||
* @property $engine_model varchar |
||||
* @property $emission_standard varchar |
||||
* @property $displacement varchar |
||||
* @property $induction varchar |
||||
* @property $fuel_type varchar |
||||
* @property $transmission_type varchar |
||||
* @property $transmission_description varchar |
||||
* @property $gear_number varchar |
||||
* @property $front_tyre varchar |
||||
* @property $rear_tyre varchar |
||||
* @property $doors varchar |
||||
* @property $seats varchar |
||||
* @property $tuhu_code varchar |
||||
* @property $guidance_price varchar |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class CarModelT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_car_model_t'; |
||||
|
||||
public $attrs = [ |
||||
'car_series_id' => ['name' => 'car_series_id', 'title' => '车系ID', 'type' => 'int', 'is_must' => '1'], |
||||
'name' => ['name' => 'name', 'title' => '名称', 'type' => 'varchar', 'is_must' => '1'], |
||||
'year' => ['name' => 'year', 'title' => '年款', 'type' => 'varchar', 'is_must' => '1'], |
||||
'modelYears' => ['name' => 'modelYears', 'title' => '生产年份', 'type' => 'varchar', 'is_must' => '0'], |
||||
'vehicle_type' => ['name' => 'vehicle_type', 'title' => '车辆类型', 'type' => 'varchar', 'is_must' => '0'], |
||||
'vehicle_size' => ['name' => 'vehicle_size', 'title' => '车辆级别', 'type' => 'varchar', 'is_must' => '0'], |
||||
'engine_model' => ['name' => 'engine_model', 'title' => '发动机型号', 'type' => 'varchar', 'is_must' => '0'], |
||||
'emission_standard' => ['name' => 'emission_standard', 'title' => '排放标准', 'type' => 'varchar', 'is_must' => '0'], |
||||
'displacement' => ['name' => 'displacement', 'title' => '排量', 'type' => 'varchar', 'is_must' => '0'], |
||||
'induction' => ['name' => 'induction', 'title' => '进气形式', 'type' => 'varchar', 'is_must' => '0'], |
||||
'fuel_type' => ['name' => 'fuel_type', 'title' => '燃油类型', 'type' => 'varchar', 'is_must' => '0'], |
||||
'transmission_type' => ['name' => 'transmission_type', 'title' => '变速器类型', 'type' => 'varchar', 'is_must' => '0'], |
||||
'transmission_description' => ['name' => 'transmission_description', 'title' => '变速器描述', 'type' => 'varchar', 'is_must' => '0'], |
||||
'gear_number' => ['name' => 'gear_number', 'title' => '档位数', 'type' => 'varchar', 'is_must' => '0'], |
||||
'front_tyre' => ['name' => 'front_tyre', 'title' => '前轮胎规格', 'type' => 'varchar', 'is_must' => '0'], |
||||
'rear_tyre' => ['name' => 'rear_tyre', 'title' => '后轮胎规格', 'type' => 'varchar', 'is_must' => '0'], |
||||
'doors' => ['name' => 'doors', 'title' => '车门数', 'type' => 'varchar', 'is_must' => '0'], |
||||
'seats' => ['name' => 'seats', 'title' => '座位数', 'type' => 'varchar', 'is_must' => '0'], |
||||
'tuhu_code' => ['name' => 'tuhu_code', 'title' => '途虎码', 'type' => 'varchar', 'is_must' => '0'], |
||||
'guidance_price' => ['name' => 'guidance_price', 'title' => '指导价', 'type' => 'varchar', 'is_must' => '0'], |
||||
]; |
||||
} |
@ -0,0 +1,52 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_car_series_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $car_sub_brand_id int |
||||
* @property $name varchar |
||||
* @property $series varchar |
||||
* @property $level varchar |
||||
* @property $externalPanelPrice decimal |
||||
* @property $internalPanelPrice decimal |
||||
* @property $externalPaintPrice decimal |
||||
* @property $internalPaintPrice decimal |
||||
* @property $externalUnderPrice decimal |
||||
* @property $internalUnderPrice decimal |
||||
* @property $externalPolishPrice decimal |
||||
* @property $internalPolishPrice decimal |
||||
* @property $externalRepairPrice decimal |
||||
* @property $internalRepairPrice decimal |
||||
* @property $externalOutreachPrice decimal |
||||
*/ |
||||
class CarSeriesT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_car_series_t'; |
||||
public $timestamps = false; |
||||
|
||||
public $attrs = [ |
||||
'car_sub_brand_id' => ['name' => 'car_sub_brand_id', 'title' => '厂家ID', 'type' => 'int', 'is_must' => '1'], |
||||
'name' => ['name' => 'name', 'title' => '名称', 'type' => 'varchar', 'is_must' => '1'], |
||||
'series' => ['name' => 'series', 'title' => '系列', 'type' => 'varchar', 'is_must' => '0'], |
||||
'level' => ['name' => 'level', 'title' => '等级', 'type' => 'varchar', 'is_must' => '0'], |
||||
'externalPanelPrice' => ['name' => 'externalPanelPrice', 'title' => '钣金外工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'internalPanelPrice' => ['name' => 'internalPanelPrice', 'title' => '钣金内工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'externalPaintPrice' => ['name' => 'externalPaintPrice', 'title' => '喷漆外工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'internalPaintPrice' => ['name' => 'internalPaintPrice', 'title' => '喷漆内工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'externalUnderPrice' => ['name' => 'externalUnderPrice', 'title' => '中涂外工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'internalUnderPrice' => ['name' => 'internalUnderPrice', 'title' => '中涂内工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'externalPolishPrice' => ['name' => 'externalPolishPrice', 'title' => '美容外工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'internalPolishPrice' => ['name' => 'internalPolishPrice', 'title' => '美容内工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'externalRepairPrice' => ['name' => 'externalRepairPrice', 'title' => '机电外工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'internalRepairPrice' => ['name' => 'internalRepairPrice', 'title' => '机电内工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'externalOutreachPrice' => ['name' => 'externalOutreachPrice', 'title' => '外联工时费', 'type' => 'decimal', 'is_must' => '0'], |
||||
]; |
||||
} |
@ -0,0 +1,26 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_car_sub_brand_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $car_brand_id int |
||||
* @property $name varchar |
||||
*/ |
||||
class CarSubBrandT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_car_sub_brand_t'; |
||||
public $timestamps = false; |
||||
|
||||
public $attrs = [ |
||||
'car_brand_id' => ['name' => 'car_brand_id', 'title' => '品牌ID', 'type' => 'int', 'is_must' => '1'], |
||||
'name' => ['name' => 'name', 'title' => '名称', 'type' => 'varchar', 'is_must' => '1'], |
||||
]; |
||||
} |
@ -0,0 +1,29 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_company_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $title varchar |
||||
* @property $name varchar |
||||
* @property $pid int |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class CompanyT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_company_t'; |
||||
|
||||
public $attrs = [ |
||||
'title' => ['name' => 'title', 'title' => '简称', 'type' => 'varchar', 'is_must' => '1'], |
||||
'name' => ['name' => 'name', 'title' => '公司名称', 'type' => 'varchar', 'is_must' => '1'], |
||||
'pid' => ['name' => 'pid', 'title' => '上级公司ID', 'type' => 'int', 'is_must' => '1'], |
||||
]; |
||||
} |
@ -0,0 +1,56 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
use Illuminate\Support\Facades\Cache; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_dictionary_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $pid bigint |
||||
* @property $name varchar |
||||
* @property $title varchar |
||||
* @property $status tinyint |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class DictionaryT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_dictionary_t'; |
||||
|
||||
public $attrs = [ |
||||
'pid' => ['name' => 'pid', 'title' => '父ID', 'type' => 'bigint', 'is_must' => '0'], |
||||
'name' => ['name' => 'name', 'title' => '字典值', 'type' => 'varchar', 'is_must' => '1'], |
||||
'title' => ['name' => 'title', 'title' => '字典名', 'type' => 'varchar', 'is_must' => '1'], |
||||
'status' => ['name' => 'status', 'title' => '状态:1 启用 2 关闭', 'type' => 'tinyint', 'is_must' => '0'], |
||||
]; |
||||
|
||||
public function child() |
||||
{ |
||||
return $this->hasMany(get_class($this), 'pid', $this->getKeyName()); |
||||
} |
||||
|
||||
public function parent() |
||||
{ |
||||
return $this->hasOne(get_class($this), $this->getKeyName(), 'pid'); |
||||
} |
||||
|
||||
public static function getDictValue($name, $value = '') |
||||
{ |
||||
$list = Cache::get('dict_list_'.$name); |
||||
if(!$list) { |
||||
$parent = self::where('pid', 0)->where('name', $name)->first(); |
||||
$list = $parent->child()->pluck('title', 'name')->toArray(); |
||||
Cache::put('dict_list_' . $name, $list, 60 * 60); |
||||
} |
||||
if($value !== ''){ |
||||
return $list[$value]; |
||||
} |
||||
return $list; |
||||
} |
||||
} |
@ -0,0 +1,39 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_employee_bank_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $employee_id bigint |
||||
* @property $super_bank_name varchar |
||||
* @property $bank_name varchar |
||||
* @property $bank_code varchar |
||||
* @property $bank_num varchar |
||||
* @property $bank_man varchar |
||||
* @property $maximum decimal |
||||
* @property $priority tinyint |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class EmployeeBankT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_employee_bank_t'; |
||||
|
||||
public $attrs = [ |
||||
'employee_id' => ['name' => 'employee_id', 'title' => 'employee_id', 'type' => 'bigint', 'is_must' => '1'], |
||||
'super_bank_name' => ['name' => 'super_bank_name', 'title' => '银行名', 'type' => 'varchar', 'is_must' => '1'], |
||||
'bank_name' => ['name' => 'bank_name', 'title' => '开户行', 'type' => 'varchar', 'is_must' => '1'], |
||||
'bank_code' => ['name' => 'bank_code', 'title' => '开户行号', 'type' => 'varchar', 'is_must' => '1'], |
||||
'bank_num' => ['name' => 'bank_num', 'title' => '银行卡号', 'type' => 'varchar', 'is_must' => '1'], |
||||
'bank_man' => ['name' => 'bank_man', 'title' => '开户人', 'type' => 'varchar', 'is_must' => '1'], |
||||
'maximum' => ['name' => 'maximum', 'title' => '最大值', 'type' => 'decimal', 'is_must' => '0'], |
||||
'priority' => ['name' => 'priority', 'title' => '排序', 'type' => 'tinyint', 'is_must' => '0'], |
||||
]; |
||||
} |
@ -0,0 +1,64 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_employee_group_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $pid bigint |
||||
* @property $title varchar |
||||
* @property $level tinyint |
||||
* @property $description varchar |
||||
* @property $base_salary decimal |
||||
* @property $status tinyint |
||||
* @property $rules varchar |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class EmployeeGroupT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_employee_group_t'; |
||||
|
||||
public $attrs = [ |
||||
'pid' => ['name' => 'pid', 'title' => '父ID', 'type' => 'bigint', 'is_must' => '0'], |
||||
'title' => ['name' => 'title', 'title' => '岗位名称', 'type' => 'varchar', 'is_must' => '1'], |
||||
'level' => ['name' => 'level', 'title' => '数据等级', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'description' => ['name' => 'description', 'title' => '岗位描述', 'type' => 'varchar', 'is_must' => '0'], |
||||
'base_salary' => ['name' => 'base_salary', 'title' => '基础工资', 'type' => 'decimal', 'is_must' => '0'], |
||||
'status' => ['name' => 'status', 'title' => '岗位状态: 1 开启 2 关闭', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'rules' => ['name' => 'rules', 'title' => '规则id,多个规则 , 隔开', 'type' => 'varchar', 'is_must' => '0'], |
||||
]; |
||||
|
||||
public function getTree($status, $pid = 0) |
||||
{ |
||||
$data = []; |
||||
if($status){ |
||||
$this->where('status', $status); |
||||
} |
||||
$list = $this->where('pid', $pid)->get(); |
||||
foreach ($list as $item) { |
||||
$row = [ |
||||
'id' => $item->id, |
||||
'pid' => $item->pid, |
||||
'title' => $item->title, |
||||
'level' => $item->level, |
||||
'description' => $item->description, |
||||
'base_salary' => $item->base_salary, |
||||
'status' => $item->status, |
||||
'rules' => $item->rules, |
||||
]; |
||||
$children = $this->getTree($status, $item->id); |
||||
if(count($children) > 0){ |
||||
$row['children'] = $children; |
||||
} |
||||
$data[] = $row; |
||||
} |
||||
return $data; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_employee_reward_punishment_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $employee_id bigint |
||||
* @property $type tinyint |
||||
* @property $date string |
||||
* @property $price decimal |
||||
* @property $remark varchar |
||||
* @property $status tinyint |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class EmployeeRewardPunishmentT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_employee_reward_punishment_t'; |
||||
|
||||
public $attrs = [ |
||||
'employee_id' => ['name' => 'employee_id', 'title' => '员工ID', 'type' => 'bigint', 'is_must' => '1'], |
||||
'type' => ['name' => 'type', 'title' => '奖惩类型', 'type' => 'tinyint', 'is_must' => '1'], |
||||
'date' => ['name' => 'date', 'title' => '奖惩日期', 'type' => 'date', 'is_must' => '1'], |
||||
'price' => ['name' => 'price', 'title' => '奖惩金额', 'type' => 'decimal', 'is_must' => '1'], |
||||
'remark' => ['name' => 'remark', 'title' => '备注', 'type' => 'varchar', 'is_must' => '1'], |
||||
'status' => ['name' => 'status', 'title' => '状态', 'type' => 'tinyint', 'is_must' => '0'], |
||||
]; |
||||
} |
@ -0,0 +1,37 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_employee_social_items_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $employee_id bigint |
||||
* @property $social_type tinyint |
||||
* @property $base_price decimal |
||||
* @property $personal_rate decimal |
||||
* @property $unit_rate decimal |
||||
* @property $personal_price decimal |
||||
* @property $unit_price decimal |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class EmployeeSocialItemsT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_employee_social_items_t'; |
||||
|
||||
public $attrs = [ |
||||
'employee_id' => ['name' => 'employee_id', 'title' => 'employee_id', 'type' => 'bigint', 'is_must' => '1'], |
||||
'social_type' => ['name' => 'social_type', 'title' => '类型', 'type' => 'tinyint', 'is_must' => '1'], |
||||
'base_price' => ['name' => 'base_price', 'title' => '缴费基数', 'type' => 'decimal', 'is_must' => '0'], |
||||
'personal_rate' => ['name' => 'personal_rate', 'title' => '个人比例', 'type' => 'decimal', 'is_must' => '0'], |
||||
'unit_rate' => ['name' => 'unit_rate', 'title' => '单位比例', 'type' => 'decimal', 'is_must' => '0'], |
||||
'personal_price' => ['name' => 'personal_price', 'title' => '个人缴费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'unit_price' => ['name' => 'unit_price', 'title' => '单位缴费', 'type' => 'decimal', 'is_must' => '0'], |
||||
]; |
||||
} |
@ -0,0 +1,108 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Notifications\Notifiable; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Tymon\JWTAuth\Contracts\JWTSubject; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_employee_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $username varchar |
||||
* @property $nickname varchar |
||||
* @property $password varchar |
||||
* @property $company_id int |
||||
* @property $group_id int |
||||
* @property $phone bigint |
||||
* @property $monthly_working_days int |
||||
* @property $entry_date date |
||||
* @property $official_date date |
||||
* @property $resign_date date |
||||
* @property $probation_salary decimal |
||||
* @property $official_salary decimal |
||||
* @property $is_outer tinyint |
||||
* @property $status tinyint |
||||
* @property $rules varchar |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class EmployeeT extends Authenticatable implements JWTSubject |
||||
{ |
||||
use HasFactory, Notifiable; |
||||
|
||||
protected $table = 'uc_employee_t'; |
||||
|
||||
public $attrs = [ |
||||
'username' => ['name' => 'username', 'title' => '员工工号', 'type' => 'varchar', 'is_must' => '1'], |
||||
'nickname' => ['name' => 'nickname', 'title' => '员工姓名', 'type' => 'varchar', 'is_must' => '1'], |
||||
'password' => ['name' => 'password', 'title' => 'password', 'type' => 'varchar', 'is_must' => '1'], |
||||
'company_id' => ['name' => 'company_id', 'title' => '公司ID', 'type' => 'int', 'is_must' => '0'], |
||||
'group_id' => ['name' => 'group_id', 'title' => '岗位ID', 'type' => 'int', 'is_must' => '0'], |
||||
'phone' => ['name' => 'phone', 'title' => '联系电话', 'type' => 'bigint', 'is_must' => '0'], |
||||
'monthly_working_days' => ['name' => 'monthly_working_days', 'title' => '月工作天数', 'type' => 'int', 'is_must' => '0'], |
||||
'entry_date' => ['name' => 'entry_date', 'title' => '入职日期', 'type' => 'date', 'is_must' => '0'], |
||||
'official_date' => ['name' => 'official_date', 'title' => '转正日期', 'type' => 'date', 'is_must' => '0'], |
||||
'resign_date' => ['name' => 'resign_date', 'title' => '离职日期', 'type' => 'date', 'is_must' => '0'], |
||||
'probation_salary' => ['name' => 'probation_salary', 'title' => '试用工资', 'type' => 'decimal', 'is_must' => '0'], |
||||
'official_salary' => ['name' => 'official_salary', 'title' => '转正工资', 'type' => 'decimal', 'is_must' => '0'], |
||||
'is_outer' => ['name' => 'is_outer', 'title' => '外网登录', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'status' => ['name' => 'status', 'title' => '员工状态', 'type' => 'tinyint', 'is_must' => '0'], |
||||
'rules' => ['name' => 'rules', 'title' => '规则id,多个规则 , 隔开', 'type' => 'varchar', 'is_must' => '0'], |
||||
]; |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getJWTIdentifier() |
||||
{ |
||||
// TODO: Implement getJWTIdentifier() method. |
||||
return $this->getKey(); |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function getJWTCustomClaims() |
||||
{ |
||||
// TODO: Implement getJWTCustomClaims() method. |
||||
return ['auth_list' => $this->getAuthList()]; |
||||
} |
||||
|
||||
public function getAuthList() |
||||
{ |
||||
$config = config('auth.conf'); |
||||
$user_auth_ids = DB::table($config['auth_group']) |
||||
->where('id', $this->group_id) |
||||
->value('rules'); |
||||
$ids = array_unique(explode(',', $user_auth_ids . ',' . $this->rules)); |
||||
if (empty($ids)) { |
||||
return array(); |
||||
} |
||||
|
||||
//读取用户组所有权限规则 |
||||
$rules = DB::table($config['auth_rule']) |
||||
->whereIn('id',$ids) |
||||
->where('status',1)->select(['condition','name','module','method'])->get(); |
||||
|
||||
//循环规则,判断结果。 |
||||
$authList = array(); // |
||||
foreach ($rules as $rule) { |
||||
if (!empty($rule->condition)) { //根据condition进行验证 |
||||
$command = preg_replace('/\{(\w*?)\}/', '$user[\'\\1\']', $rule->condition); |
||||
$condition = false; |
||||
@(eval('$condition=(' . $command . ');')); |
||||
if ($condition) { |
||||
$authList[] = strtolower($rule->module .'_'. $rule->method .'_'. $rule->name); |
||||
} |
||||
} else { |
||||
//只要存在就记录 |
||||
$authList[] = strtolower($rule->module .'_'. $rule->method .'_'. $rule->name); |
||||
} |
||||
} |
||||
return array_unique($authList); |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_employee_wave_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $employee_id bigint |
||||
* @property $wave tinyint |
||||
* @property $base_price decimal |
||||
* @property $personal_rate decimal |
||||
* @property $unit_rate decimal |
||||
* @property $personal_price decimal |
||||
* @property $unit_price decimal |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class EmployeeWaveT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_employee_wave_t'; |
||||
|
||||
public $attrs = [ |
||||
'employee_id' => ['name' => 'employee_id', 'title' => 'employee_id', 'type' => 'bigint', 'is_must' => '1'], |
||||
'wave' => ['name' => 'wave', 'title' => '社保/公积金/个税', 'type' => 'tinyint', 'is_must' => '1'], |
||||
'base_price' => ['name' => 'base_price', 'title' => '缴费基数', 'type' => 'decimal', 'is_must' => '0'], |
||||
'personal_rate' => ['name' => 'personal_rate', 'title' => '个人比例', 'type' => 'decimal', 'is_must' => '0'], |
||||
'unit_rate' => ['name' => 'unit_rate', 'title' => '单位比例', 'type' => 'decimal', 'is_must' => '0'], |
||||
'personal_price' => ['name' => 'personal_price', 'title' => '个人缴费', 'type' => 'decimal', 'is_must' => '0'], |
||||
'unit_price' => ['name' => 'unit_price', 'title' => '单位缴费', 'type' => 'decimal', 'is_must' => '0'], |
||||
]; |
||||
} |
@ -0,0 +1,41 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_system_setting_t". |
||||
* |
||||
* @property $id bigint |
||||
* @property $title varchar |
||||
* @property $name varchar |
||||
* @property $data_type set |
||||
* @property $prop varchar |
||||
* @property $group varchar |
||||
* @property $content varchar |
||||
* @property $remark varchar |
||||
* @property $sort int |
||||
* @property $status tinyint |
||||
* @property $created_at timestamp |
||||
* @property $updated_at timestamp |
||||
*/ |
||||
class SystemSettingT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_system_setting_t'; |
||||
|
||||
public $attrs = [ |
||||
'title' => ['name' => 'title', 'title' => '标题', 'type' => 'varchar', 'is_must' => '1'], |
||||
'name' => ['name' => 'name', 'title' => '名字,英文唯一', 'type' => 'varchar', 'is_must' => '1'], |
||||
'data_type' => ['name' => 'data_type', 'title' => '存储类型', 'type' => 'set', 'is_must' => '1'], |
||||
'prop' => ['name' => 'prop', 'title' => '归属', 'type' => 'varchar', 'is_must' => '1'], |
||||
'group' => ['name' => 'group', 'title' => '分组', 'type' => 'varchar', 'is_must' => '1'], |
||||
'content' => ['name' => 'content', 'title' => '内容', 'type' => 'varchar', 'is_must' => '1'], |
||||
'remark' => ['name' => 'remark', 'title' => '说明', 'type' => 'varchar', 'is_must' => '1'], |
||||
'sort' => ['name' => 'sort', 'title' => '排序', 'type' => 'int', 'is_must' => '1'], |
||||
'status' => ['name' => 'status', 'title' => '状态', 'type' => 'tinyint', 'is_must' => '1'], |
||||
]; |
||||
} |
@ -0,0 +1,43 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail; |
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Foundation\Auth\User as Authenticatable; |
||||
use Illuminate\Notifications\Notifiable; |
||||
|
||||
class User extends Authenticatable |
||||
{ |
||||
use HasFactory, Notifiable; |
||||
|
||||
/** |
||||
* The attributes that are mass assignable. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $fillable = [ |
||||
'name', |
||||
'email', |
||||
'password', |
||||
]; |
||||
|
||||
/** |
||||
* The attributes that should be hidden for arrays. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $hidden = [ |
||||
'password', |
||||
'remember_token', |
||||
]; |
||||
|
||||
/** |
||||
* The attributes that should be cast to native types. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $casts = [ |
||||
'email_verified_at' => 'datetime', |
||||
]; |
||||
} |
@ -0,0 +1,22 @@ |
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
/** |
||||
* This is the model class for table "uc_test_t". |
||||
* |
||||
|
||||
*/ |
||||
class testT extends Model |
||||
{ |
||||
use HasFactory; |
||||
|
||||
protected $table = 'uc_test_t'; |
||||
|
||||
public $attrs = [ |
||||
|
||||
]; |
||||
} |
@ -0,0 +1,28 @@ |
||||
<?php |
||||
|
||||
namespace App\Providers; |
||||
|
||||
use Illuminate\Support\ServiceProvider; |
||||
|
||||
class AppServiceProvider extends ServiceProvider |
||||
{ |
||||
/** |
||||
* Register any application services. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function register() |
||||
{ |
||||
// |
||||
} |
||||
|
||||
/** |
||||
* Bootstrap any application services. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function boot() |
||||
{ |
||||
// |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
<?php |
||||
|
||||
namespace App\Providers; |
||||
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; |
||||
use Illuminate\Support\Facades\Gate; |
||||
|
||||
class AuthServiceProvider extends ServiceProvider |
||||
{ |
||||
/** |
||||
* The policy mappings for the application. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $policies = [ |
||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy', |
||||
]; |
||||
|
||||
/** |
||||
* Register any authentication / authorization services. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function boot() |
||||
{ |
||||
$this->registerPolicies(); |
||||
|
||||
// |
||||
} |
||||
} |
@ -0,0 +1,21 @@ |
||||
<?php |
||||
|
||||
namespace App\Providers; |
||||
|
||||
use Illuminate\Support\Facades\Broadcast; |
||||
use Illuminate\Support\ServiceProvider; |
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider |
||||
{ |
||||
/** |
||||
* Bootstrap any application services. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function boot() |
||||
{ |
||||
Broadcast::routes(); |
||||
|
||||
require base_path('routes/channels.php'); |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
<?php |
||||
|
||||
namespace App\Providers; |
||||
|
||||
use Illuminate\Auth\Events\Registered; |
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification; |
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; |
||||
use Illuminate\Support\Facades\Event; |
||||
|
||||
class EventServiceProvider extends ServiceProvider |
||||
{ |
||||
/** |
||||
* The event listener mappings for the application. |
||||
* |
||||
* @var array |
||||
*/ |
||||
protected $listen = [ |
||||
Registered::class => [ |
||||
SendEmailVerificationNotification::class, |
||||
], |
||||
]; |
||||
|
||||
/** |
||||
* Register any events for your application. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function boot() |
||||
{ |
||||
// |
||||
} |
||||
} |
@ -0,0 +1,63 @@ |
||||
<?php |
||||
|
||||
namespace App\Providers; |
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit; |
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; |
||||
use Illuminate\Http\Request; |
||||
use Illuminate\Support\Facades\RateLimiter; |
||||
use Illuminate\Support\Facades\Route; |
||||
|
||||
class RouteServiceProvider extends ServiceProvider |
||||
{ |
||||
/** |
||||
* The path to the "home" route for your application. |
||||
* |
||||
* This is used by Laravel authentication to redirect users after login. |
||||
* |
||||
* @var string |
||||
*/ |
||||
public const HOME = '/home'; |
||||
|
||||
/** |
||||
* The controller namespace for the application. |
||||
* |
||||
* When present, controller route declarations will automatically be prefixed with this namespace. |
||||
* |
||||
* @var string|null |
||||
*/ |
||||
// protected $namespace = 'App\\Http\\Controllers'; |
||||
|
||||
/** |
||||
* Define your route model bindings, pattern filters, etc. |
||||
* |
||||
* @return void |
||||
*/ |
||||
public function boot() |
||||
{ |
||||
$this->configureRateLimiting(); |
||||
|
||||
$this->routes(function () { |
||||
Route::prefix('api') |
||||
->middleware('api') |
||||
->namespace($this->namespace) |
||||
->group(base_path('routes/api.php')); |
||||
|
||||
Route::middleware('web') |
||||
->namespace($this->namespace) |
||||
->group(base_path('routes/web.php')); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* Configure the rate limiters for the application. |
||||
* |
||||
* @return void |
||||
*/ |
||||
protected function configureRateLimiting() |
||||
{ |
||||
RateLimiter::for('api', function (Request $request) { |
||||
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip()); |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
<?php |
||||
|
||||
namespace App\Resources; |
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource; |
||||
|
||||
class EmployeeController extends JsonResource |
||||
{ |
||||
/** |
||||
* Transform the resource into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace App\Resources; |
||||
|
||||
class EmployeeControllerCollection extends BaseCollection |
||||
{ |
||||
/** |
||||
* Transform the resource collection into an array. |
||||
* |
||||
* @param \Illuminate\Http\Request $request |
||||
* @return array |
||||
*/ |
||||
public function toArray($request) |
||||
{ |
||||
return parent::toArray($request); |
||||
} |
||||
} |
@ -0,0 +1,117 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace App\Services; |
||||
|
||||
use Closure; |
||||
use Illuminate\Contracts\Auth\Factory as Auth; |
||||
use Illuminate\Support\Facades\Cache; |
||||
use Illuminate\Support\Facades\DB; |
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware; |
||||
use phpDocumentor\Reflection\Types\Self_; |
||||
|
||||
/** |
||||
* @title 权限认证类 |
||||
* @description |
||||
* 功能特性: |
||||
* 1,是对规则进行认证,不是对节点进行认证。用户可以把节点当作规则名称实现对节点进行认证。 |
||||
* $auth=new Auth(); $auth->check('规则名称','用户id') |
||||
* 2,可以同时对多条规则进行认证,并设置多条规则的关系(or或者and) |
||||
* $auth=new Auth(); $auth->check('规则1,规则2','用户id','and') |
||||
* 第三个参数为and时表示,用户需要同时具有规则1和规则2的权限。 当第三个参数为or时,表示用户值需要具备其中一个条件即可。默认为or |
||||
* 3,一个用户可以属于多个用户组(think_auth_group_access表 定义了用户所属用户组)。我们需要设置每个用户组拥有哪些规则(think_auth_group 定义了用户组权限) |
||||
* 4,支持规则表达式。 |
||||
* @package App\Service |
||||
* @author zcstatham |
||||
* @time 2021/1/25 |
||||
*/ |
||||
class Authenticate extends Middleware |
||||
{ |
||||
|
||||
//默认配置 |
||||
protected $_config = array( |
||||
'auth_on' => true, // 认证开关 |
||||
'auth_type' => 1, // 认证方式,1为实时认证;2为登录认证。 |
||||
'auth_group' => 'uc_employee_group_t', // 用户组数据表名 |
||||
'auth_rule' => 'uc_auth_rule_t', // 权限规则表 |
||||
'auth_user' => 'uc_employee_t' // 用户信息表 |
||||
); |
||||
|
||||
public function __construct(Auth $auth) |
||||
{ |
||||
parent::__construct($auth); |
||||
$this->_config = array_merge($this->_config, config('auth.conf')); |
||||
} |
||||
|
||||
public function handle($request, Closure $next, ...$guards) |
||||
{ |
||||
// 登录验证 |
||||
if (!$this->auth->guard('api')->check()) { |
||||
return response()->json(['code' => 401, 'msg' => '用户未登录'], 401); |
||||
} |
||||
$url =''; |
||||
$route = $request->route(); |
||||
preg_match('/Controllers.(\w+).\w+@\w+/', $route->getActionName(), $match); |
||||
foreach ($route->methods() as $method){ |
||||
$url .= $match[1] . '_' . $method .'_'. $route->uri() . ','; |
||||
} |
||||
// 权限验证 |
||||
if (!$this->check($url, $this->auth)) { |
||||
return response()->json(['code' => 403, 'msg' => '用户未授权访问'], 403); |
||||
} |
||||
return $next($request); |
||||
} |
||||
|
||||
/** |
||||
* @title 检查权限 |
||||
* @description check |
||||
* @param $name |
||||
* @param $auth |
||||
* @param string $mode |
||||
* @param string $relation |
||||
* @return bool |
||||
* @author zcstatham |
||||
* @time 2021/1/25 |
||||
*/ |
||||
public function check($name, $auth, $mode = 'url', $relation = 'or') |
||||
{ |
||||
$user = $auth->user(); |
||||
if (!$this->_config['auth_on']) { |
||||
return true; |
||||
} |
||||
if ($user['id'] == 1) { |
||||
return true; |
||||
} |
||||
$authList = $auth->payload()->get('auth_list'); |
||||
if (is_string($name)) { |
||||
$name = strtolower($name); |
||||
if (strpos($name, ',') !== false) { |
||||
$name = explode(',', $name); |
||||
} else { |
||||
$name = array($name); |
||||
} |
||||
} |
||||
$list = array(); //保存验证通过的规则名 |
||||
foreach ($authList as $auth) { |
||||
$query = preg_replace('/^.+\?/U', '', $auth); |
||||
if ($mode == 'url' && $query != $auth) { |
||||
parse_str($query, $param); //解析规则中的param |
||||
$intersect = array_intersect_assoc(request()->param(), $param); |
||||
$auth = preg_replace('/\?.*$/U', '', $auth); |
||||
if (in_array($auth, $name) && $intersect == $param) { //如果节点相符且url参数满足 |
||||
$list[] = $auth; |
||||
} |
||||
} else if (in_array($auth, $name)) { |
||||
$list[] = $auth; |
||||
} |
||||
} |
||||
if ($relation == 'or' and !empty($list)) { |
||||
return true; |
||||
} |
||||
$diff = array_diff($name, $list); |
||||
if ($relation == 'and' and empty($diff)) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,53 @@ |
||||
#!/usr/bin/env php |
||||
<?php |
||||
|
||||
define('LARAVEL_START', microtime(true)); |
||||
|
||||
/* |
||||
|-------------------------------------------------------------------------- |
||||
| Register The Auto Loader |
||||
|-------------------------------------------------------------------------- |
||||
| |
||||
| Composer provides a convenient, automatically generated class loader |
||||
| for our application. We just need to utilize it! We'll require it |
||||
| into the script here so that we do not have to worry about the |
||||
| loading of any our classes "manually". Feels great to relax. |
||||
| |
||||
*/ |
||||
|
||||
require __DIR__.'/vendor/autoload.php'; |
||||
|
||||
$app = require_once __DIR__.'/bootstrap/app.php'; |
||||
|
||||
/* |
||||
|-------------------------------------------------------------------------- |
||||
| Run The Artisan Application |
||||
|-------------------------------------------------------------------------- |
||||
| |
||||
| When we run the console application, the current CLI command will be |
||||
| executed in this console and the response sent back to a terminal |
||||
| or another output device for the developers. Here goes nothing! |
||||
| |
||||
*/ |
||||
|
||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class); |
||||
|
||||
$status = $kernel->handle( |
||||
$input = new Symfony\Component\Console\Input\ArgvInput, |
||||
new Symfony\Component\Console\Output\ConsoleOutput |
||||
); |
||||
|
||||
/* |
||||
|-------------------------------------------------------------------------- |
||||
| Shutdown The Application |
||||
|-------------------------------------------------------------------------- |
||||
| |
||||
| Once Artisan has finished running, we will fire off the shutdown events |
||||
| so that any final work may be done by the application before we shut |
||||
| down the process. This is the last thing to happen to the request. |
||||
| |
||||
*/ |
||||
|
||||
$kernel->terminate($input, $status); |
||||
|
||||
exit($status); |
@ -0,0 +1,55 @@ |
||||
<?php |
||||
|
||||
/* |
||||
|-------------------------------------------------------------------------- |
||||
| Create The Application |
||||
|-------------------------------------------------------------------------- |
||||
| |
||||
| The first thing we will do is create a new Laravel application instance |
||||
| which serves as the "glue" for all the components of Laravel, and is |
||||
| the IoC container for the system binding all of the various parts. |
||||
| |
||||
*/ |
||||
|
||||
$app = new Illuminate\Foundation\Application( |
||||
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__) |
||||
); |
||||
|
||||
/* |
||||
|-------------------------------------------------------------------------- |
||||
| Bind Important Interfaces |
||||
|-------------------------------------------------------------------------- |
||||
| |
||||
| Next, we need to bind some important interfaces into the container so |
||||
| we will be able to resolve them when needed. The kernels serve the |
||||
| incoming requests to this application from both the web and CLI. |
||||
| |
||||
*/ |
||||
|
||||
$app->singleton( |
||||
Illuminate\Contracts\Http\Kernel::class, |
||||
App\Http\Kernel::class |
||||
); |
||||
|
||||
$app->singleton( |
||||
Illuminate\Contracts\Console\Kernel::class, |
||||
App\Console\Kernel::class |
||||
); |
||||
|
||||
$app->singleton( |
||||
Illuminate\Contracts\Debug\ExceptionHandler::class, |
||||
App\Exceptions\Handler::class |
||||
); |
||||
|
||||
/* |
||||
|-------------------------------------------------------------------------- |
||||
| Return The Application |
||||
|-------------------------------------------------------------------------- |
||||
| |
||||
| This script returns the application instance. The instance is given to |
||||
| the calling script so we can separate the building of the instances |
||||
| from the actual running of the application and sending responses. |
||||
| |
||||
*/ |
||||
|
||||
return $app; |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue