From 1af1e9cc1bbd5d387cd46ab2336257763d4b494e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 26 Jul 2022 20:05:14 +0800 Subject: [PATCH 01/35] =?UTF-8?q?feat:=20#20220726=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=A8=A1=E5=9E=8B=E6=9E=84=E5=BB=BA=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +- .../Controllers/Auth/RegisterController.php | 4 +- app/Models/DailyStockRecord.php | 8 + app/Models/FailedJob.php | 8 + app/Models/Goods.php | 8 + app/Models/GoodsBrand.php | 8 + app/Models/GoodsSku.php | 8 + app/Models/GoodsType.php | 8 + app/Models/Log.php | 8 + app/Models/Model.php | 23 +++ app/Models/ModelHasPermissions.php | 8 + app/Models/ModelHasRoles.php | 8 + app/Models/PasswordReset.php | 8 + app/Models/Permission.php | 8 + app/Models/Role.php | 8 + app/Models/RoleHasPermission.php | 8 + app/{ => Models}/User.php | 3 +- composer.json | 3 +- composer.lock | 84 ++++++++- config/app.php | 4 +- config/auth.php | 2 +- config/permission.php | 161 ++++++++++++++++++ database/factories/UserFactory.php | 2 +- ..._07_25_060932_create_permission_tables.php | 141 +++++++++++++++ ..._07_26_061712_create_goods_types_table.php | 35 ++++ ...07_26_085847_create_goods_brands_table.php | 35 ++++ .../2022_07_26_090143_create_goods_table.php | 38 +++++ ...2_07_26_090150_create_goods_skus_table.php | 43 +++++ ...03559_create_daily_stock_records_table.php | 36 ++++ .../2022_07_26_105818_create_logs_table.php | 39 +++++ 30 files changed, 756 insertions(+), 15 deletions(-) create mode 100644 app/Models/DailyStockRecord.php create mode 100644 app/Models/FailedJob.php create mode 100644 app/Models/Goods.php create mode 100644 app/Models/GoodsBrand.php create mode 100644 app/Models/GoodsSku.php create mode 100644 app/Models/GoodsType.php create mode 100644 app/Models/Log.php create mode 100644 app/Models/Model.php create mode 100644 app/Models/ModelHasPermissions.php create mode 100644 app/Models/ModelHasRoles.php create mode 100644 app/Models/PasswordReset.php create mode 100644 app/Models/Permission.php create mode 100644 app/Models/Role.php create mode 100644 app/Models/RoleHasPermission.php rename app/{ => Models}/User.php (91%) create mode 100644 config/permission.php create mode 100644 database/migrations/2022_07_25_060932_create_permission_tables.php create mode 100644 database/migrations/2022_07_26_061712_create_goods_types_table.php create mode 100644 database/migrations/2022_07_26_085847_create_goods_brands_table.php create mode 100644 database/migrations/2022_07_26_090143_create_goods_table.php create mode 100644 database/migrations/2022_07_26_090150_create_goods_skus_table.php create mode 100644 database/migrations/2022_07_26_103559_create_daily_stock_records_table.php create mode 100644 database/migrations/2022_07_26_105818_create_logs_table.php diff --git a/README.md b/README.md index 1e0745e..a25de4b 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,25 @@ #### 介绍 +主要为鲜花售卖提供一个统一的商品管理平台,支持对接第三方平台,包括商品管理,库存同步,订单管理,发货等 + #### 软件架构 - laravel 6.* - vue2.* - element-ui -#### 安装教程 +#### 本地开发安装教程 -1. xxxx -2. xxxx -3. xxxx +1. `composer install` +2. `cp .env.example .env` +3. 创建数据库 `CREATE DATABASE IF NOT EXISTS `erp` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;` +4. 修改 .env 配置项为本地配置 +5. `php artisan migration` #### 使用说明 -1. xxxx +1. 阅读并遵守<<[Laravel项目开发规范](https://learnku.com/docs/laravel-specification/9.x/whats-the-use-of-standards/12720)>> 2. xxxx 3. xxxx diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index c6a6de6..69efd5f 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -3,8 +3,8 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use App\Models\User; use App\Providers\RouteServiceProvider; -use App\User; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; @@ -60,7 +60,7 @@ class RegisterController extends Controller * Create a new user instance after a valid registration. * * @param array $data - * @return \App\User + * @return \App\Models\User */ protected function create(array $data) { diff --git a/app/Models/DailyStockRecord.php b/app/Models/DailyStockRecord.php new file mode 100644 index 0000000..7f609c6 --- /dev/null +++ b/app/Models/DailyStockRecord.php @@ -0,0 +1,8 @@ +orderBy('id', 'desc'); + } + + public function scopeOlder($query) + { + return $query->orderBy('id', 'asc'); + } + + public function scopeByUser($query, User $user) + { + return $query->where('user_id', $user->id); + } +} diff --git a/app/Models/ModelHasPermissions.php b/app/Models/ModelHasPermissions.php new file mode 100644 index 0000000..a4fca01 --- /dev/null +++ b/app/Models/ModelHasPermissions.php @@ -0,0 +1,8 @@ + env('APP_NAME', 'Laravel'), + 'name' => env('APP_NAME', 'CFen Erp'), /* |-------------------------------------------------------------------------- @@ -52,7 +52,7 @@ return [ | */ - 'url' => env('APP_URL', 'http://localhost'), + 'url' => env('APP_URL', 'http://erp.ii090.com'), 'asset_url' => env('ASSET_URL', null), diff --git a/config/auth.php b/config/auth.php index aaf982b..068a52b 100644 --- a/config/auth.php +++ b/config/auth.php @@ -68,7 +68,7 @@ return [ 'providers' => [ 'users' => [ 'driver' => 'eloquent', - 'model' => App\User::class, + 'model' => \App\Models\User::class, ], // 'users' => [ diff --git a/config/permission.php b/config/permission.php new file mode 100644 index 0000000..5b6e184 --- /dev/null +++ b/config/permission.php @@ -0,0 +1,161 @@ + [ + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * Eloquent model should be used to retrieve your permissions. Of course, it + * is often just the "Permission" model but you may use whatever you like. + * + * The model you want to use as a Permission model needs to implement the + * `Spatie\Permission\Contracts\Permission` contract. + */ + + 'permission' => Spatie\Permission\Models\Permission::class, + + /* + * When using the "HasRoles" trait from this package, we need to know which + * Eloquent model should be used to retrieve your roles. Of course, it + * is often just the "Role" model but you may use whatever you like. + * + * The model you want to use as a Role model needs to implement the + * `Spatie\Permission\Contracts\Role` contract. + */ + + 'role' => Spatie\Permission\Models\Role::class, + + ], + + 'table_names' => [ + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'roles' => 'roles', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your permissions. We have chosen a basic + * default value but you may easily change it to any table you like. + */ + + 'permissions' => 'permissions', + + /* + * When using the "HasPermissions" trait from this package, we need to know which + * table should be used to retrieve your models permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_permissions' => 'model_has_permissions', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your models roles. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'model_has_roles' => 'model_has_roles', + + /* + * When using the "HasRoles" trait from this package, we need to know which + * table should be used to retrieve your roles permissions. We have chosen a + * basic default value but you may easily change it to any table you like. + */ + + 'role_has_permissions' => 'role_has_permissions', + ], + + 'column_names' => [ + /* + * Change this if you want to name the related pivots other than defaults + */ + 'role_pivot_key' => null, //default 'role_id', + 'permission_pivot_key' => null, //default 'permission_id', + + /* + * Change this if you want to name the related model primary key other than + * `model_id`. + * + * For example, this would be nice if your primary keys are all UUIDs. In + * that case, name this `model_uuid`. + */ + + 'model_morph_key' => 'model_id', + + /* + * Change this if you want to use the teams feature and your related model's + * foreign key is other than `team_id`. + */ + + 'team_foreign_key' => 'team_id', + ], + + /* + * When set to true, the method for checking permissions will be registered on the gate. + * Set this to false, if you want to implement custom logic for checking permissions. + */ + + 'register_permission_check_method' => true, + + /* + * When set to true the package implements teams using the 'team_foreign_key'. If you want + * the migrations to register the 'team_foreign_key', you must set this to true + * before doing the migration. If you already did the migration then you must make a new + * migration to also add 'team_foreign_key' to 'roles', 'model_has_roles', and + * 'model_has_permissions'(view the latest version of package's migration file) + */ + + 'teams' => false, + + /* + * When set to true, the required permission names are added to the exception + * message. This could be considered an information leak in some contexts, so + * the default setting is false here for optimum safety. + */ + + 'display_permission_in_exception' => false, + + /* + * When set to true, the required role names are added to the exception + * message. This could be considered an information leak in some contexts, so + * the default setting is false here for optimum safety. + */ + + 'display_role_in_exception' => false, + + /* + * By default wildcard permission lookups are disabled. + */ + + 'enable_wildcard_permission' => false, + + 'cache' => [ + + /* + * By default all permissions are cached for 24 hours to speed up performance. + * When permissions or roles are updated the cache is flushed automatically. + */ + + 'expiration_time' => \DateInterval::createFromDateString('24 hours'), + + /* + * The cache key used to store all permissions. + */ + + 'key' => 'spatie.permission.cache', + + /* + * You may optionally indicate a specific cache driver to use for permission and + * role caching using any of the `store` drivers listed in the cache.php config + * file. Using 'default' here means to use the `default` set in cache.php. + */ + + 'store' => 'default', + ], +]; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 741edea..fa9360e 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -2,7 +2,7 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ -use App\User; +use App\Models\User; use Faker\Generator as Faker; use Illuminate\Support\Str; diff --git a/database/migrations/2022_07_25_060932_create_permission_tables.php b/database/migrations/2022_07_25_060932_create_permission_tables.php new file mode 100644 index 0000000..f20ef75 --- /dev/null +++ b/database/migrations/2022_07_25_060932_create_permission_tables.php @@ -0,0 +1,141 @@ +bigIncrements('id'); + $table->string('name'); // For MySQL 8.0 use string('name', 125); + $table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125); + $table->timestamps(); + + $table->unique(['name', 'guard_name']); + }); + + Schema::create($tableNames['roles'], function (Blueprint $table) use ($teams, $columnNames) { + $table->bigIncrements('id'); + if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing + $table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable(); + $table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index'); + } + $table->string('name'); // For MySQL 8.0 use string('name', 125); + $table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125); + $table->timestamps(); + if ($teams || config('permission.testing')) { + $table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']); + } else { + $table->unique(['name', 'guard_name']); + } + }); + + Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission); + + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index'); + + $table->foreign(PermissionRegistrar::$pivotPermission) + ->references('id') + ->on($tableNames['permissions']) + ->onDelete('cascade'); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } else { + $table->primary([PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'], + 'model_has_permissions_permission_model_type_primary'); + } + + }); + + Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotRole); + + $table->string('model_type'); + $table->unsignedBigInteger($columnNames['model_morph_key']); + $table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index'); + + $table->foreign(PermissionRegistrar::$pivotRole) + ->references('id') + ->on($tableNames['roles']) + ->onDelete('cascade'); + if ($teams) { + $table->unsignedBigInteger($columnNames['team_foreign_key']); + $table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index'); + + $table->primary([$columnNames['team_foreign_key'], PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } else { + $table->primary([PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'], + 'model_has_roles_role_model_type_primary'); + } + }); + + Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { + $table->unsignedBigInteger(PermissionRegistrar::$pivotPermission); + $table->unsignedBigInteger(PermissionRegistrar::$pivotRole); + + $table->foreign(PermissionRegistrar::$pivotPermission) + ->references('id') + ->on($tableNames['permissions']) + ->onDelete('cascade'); + + $table->foreign(PermissionRegistrar::$pivotRole) + ->references('id') + ->on($tableNames['roles']) + ->onDelete('cascade'); + + $table->primary([PermissionRegistrar::$pivotPermission, PermissionRegistrar::$pivotRole], 'role_has_permissions_permission_id_role_id_primary'); + }); + + app('cache') + ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) + ->forget(config('permission.cache.key')); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $tableNames = config('permission.table_names'); + + if (empty($tableNames)) { + throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.'); + } + + Schema::drop($tableNames['role_has_permissions']); + Schema::drop($tableNames['model_has_roles']); + Schema::drop($tableNames['model_has_permissions']); + Schema::drop($tableNames['roles']); + Schema::drop($tableNames['permissions']); + } +} diff --git a/database/migrations/2022_07_26_061712_create_goods_types_table.php b/database/migrations/2022_07_26_061712_create_goods_types_table.php new file mode 100644 index 0000000..7ba17c9 --- /dev/null +++ b/database/migrations/2022_07_26_061712_create_goods_types_table.php @@ -0,0 +1,35 @@ +bigIncrements('id'); + $table->string('name')->nullable(false); + $table->unsignedTinyInteger('is_delete')->default(0); + $table->timestamps(); + // 索引 + $table->unique('name'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('goods_types'); + } +} diff --git a/database/migrations/2022_07_26_085847_create_goods_brands_table.php b/database/migrations/2022_07_26_085847_create_goods_brands_table.php new file mode 100644 index 0000000..ed85d2a --- /dev/null +++ b/database/migrations/2022_07_26_085847_create_goods_brands_table.php @@ -0,0 +1,35 @@ +bigIncrements('id'); + $table->string('name')->nullable(false); + $table->unsignedTinyInteger('is_delete')->default(0); + $table->timestamps(); + // 索引 + $table->unique('name'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('goods_brands'); + } +} diff --git a/database/migrations/2022_07_26_090143_create_goods_table.php b/database/migrations/2022_07_26_090143_create_goods_table.php new file mode 100644 index 0000000..c82e352 --- /dev/null +++ b/database/migrations/2022_07_26_090143_create_goods_table.php @@ -0,0 +1,38 @@ +bigIncrements('id'); + $table->string('title')->nullable(false); + $table->string('img_url')->nullable(false)->comment('商品图片'); + $table->unsignedBigInteger('type_id')->nullable(false)->comment('商品种类id'); + $table->unsignedBigInteger('brand_id')->nullable()->comment('商品品牌id'); + $table->string('goods_code', 32)->nullable(false)->comment('商品编码'); + $table->timestamps(); + // 索引 + $table->unique('goods_code'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('goods'); + } +} diff --git a/database/migrations/2022_07_26_090150_create_goods_skus_table.php b/database/migrations/2022_07_26_090150_create_goods_skus_table.php new file mode 100644 index 0000000..af6bd93 --- /dev/null +++ b/database/migrations/2022_07_26_090150_create_goods_skus_table.php @@ -0,0 +1,43 @@ +bigIncrements('id'); + $table->string('title')->nullable(false)->comment('商品规格'); + $table->string('sku_code', 32)->nullable(false)->comment('规格编码'); + $table->unsignedTinyInteger('status')->default(0)->comment('规格状态(0-下架,1在售,2预警)'); + $table->unsignedInteger('num')->default(0)->comment('总量'); + $table->unsignedInteger('stock')->default(0)->comment('库存'); + $table->unsignedDecimal('cost')->default(0)->comment('成本'); + $table->unsignedInteger('two_days_ago_num')->default(0)->comment('2天前库存'); + $table->unsignedInteger('yesterday_num')->default(0)->comment('1天前库存'); + $table->unsignedDecimal('reference_price')->default(0)->comment('参考售价'); + $table->unsignedInteger('reserve')->default(0)->comment('预留量'); + $table->timestamps(); + // 索引 + $table->unique('sku_code'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('goods_skus'); + } +} diff --git a/database/migrations/2022_07_26_103559_create_daily_stock_records_table.php b/database/migrations/2022_07_26_103559_create_daily_stock_records_table.php new file mode 100644 index 0000000..1c4706d --- /dev/null +++ b/database/migrations/2022_07_26_103559_create_daily_stock_records_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->bigInteger('sku_id')->nullable(false); + $table->date('day')->nullable(false); + $table->unsignedInteger('arrived_today_num')->default(0)->comment('今日到货'); + $table->unsignedInteger('loss_num')->default(0)->comment('损耗'); + $table->unsignedInteger('inventory')->default(0)->comment('库存盘点'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('daily_stock_records'); + } +} diff --git a/database/migrations/2022_07_26_105818_create_logs_table.php b/database/migrations/2022_07_26_105818_create_logs_table.php new file mode 100644 index 0000000..6f0820c --- /dev/null +++ b/database/migrations/2022_07_26_105818_create_logs_table.php @@ -0,0 +1,39 @@ +bigIncrements('id'); + $table->string('module')->comment('模块'); + $table->string('action')->comment('操作'); + $table->string('target_type')->comment('目标类型'); + $table->bigInteger('target_id')->comment('目标id'); + $table->string('target_field')->comment('目标字段'); + $table->text('before_update')->comment('更新前数据'); + $table->text('after_update')->comment('更新后数据'); + $table->bigInteger('user_id')->comment('操作人id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('logs'); + } +} From 554105e7662d00cf2bc1912d6914a6200e52d1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Wed, 27 Jul 2022 19:06:16 +0800 Subject: [PATCH 02/35] =?UTF-8?q?feat:=20#20220727=20=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Auth/LoginController.php | 14 ++++ .../Controllers/Auth/RegisterController.php | 14 ++-- .../Goods/GoodsBrandsController.php | 44 ++++++++++++ .../Goods/GoodsTypesController.php | 10 +++ app/Http/Controllers/User/UsersController.php | 43 +++++++++++ app/Http/Resources/GoodsBrandResource.php | 19 +++++ app/Http/Resources/GoodsTypeResource.php | 19 +++++ app/Models/ModelHasPermissions.php | 8 --- app/Models/ModelHasRoles.php | 8 --- app/Models/Permission.php | 8 --- app/Models/Role.php | 8 --- app/Models/RoleHasPermission.php | 8 --- app/Models/User.php | 10 ++- database/factories/UserFactory.php | 3 +- .../2014_10_12_000000_create_users_table.php | 1 + database/seeds/DatabaseSeeder.php | 1 + resources/views/home.blade.php | 71 +++++++++++++++++++ routes/api.php | 24 +++++-- routes/web.php | 12 ++++ 19 files changed, 275 insertions(+), 50 deletions(-) create mode 100644 app/Http/Controllers/Goods/GoodsBrandsController.php create mode 100644 app/Http/Controllers/Goods/GoodsTypesController.php create mode 100644 app/Http/Controllers/User/UsersController.php create mode 100644 app/Http/Resources/GoodsBrandResource.php create mode 100644 app/Http/Resources/GoodsTypeResource.php delete mode 100644 app/Models/ModelHasPermissions.php delete mode 100644 app/Models/ModelHasRoles.php delete mode 100644 app/Models/Permission.php delete mode 100644 app/Models/Role.php delete mode 100644 app/Models/RoleHasPermission.php create mode 100644 resources/views/home.blade.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 18a0d08..993bc4b 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use App\Providers\RouteServiceProvider; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; use Illuminate\Foundation\Auth\AuthenticatesUsers; class LoginController extends Controller @@ -37,4 +39,16 @@ class LoginController extends Controller { $this->middleware('guest')->except('logout'); } + + public function login(Request $request) + { + $credentials = $request->only('name', 'password'); + + if (Auth::attempt($credentials)) { + // 通过认证.. + return response()->json(['token' => '']); + }else { + return response()->json(['error' => 'auth login fail']); + } + } } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 69efd5f..e48e455 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -8,6 +8,8 @@ use App\Providers\RouteServiceProvider; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; +use Faker\Generator as Faker; +use Illuminate\Support\Str; class RegisterController extends Controller { @@ -50,9 +52,10 @@ class RegisterController extends Controller protected function validator(array $data) { return Validator::make($data, [ - 'name' => ['required', 'string', 'max:255'], - 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], + 'name' => ['required', 'string', 'unique:users', 'max:255'], + 'email' => ['string', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], + 'role_id' => ['required', 'numeric', 'exists:roles,id'], ]); } @@ -60,14 +63,17 @@ class RegisterController extends Controller * Create a new user instance after a valid registration. * * @param array $data - * @return \App\Models\User + * @return User */ protected function create(array $data) { + $faker = new Faker(); + return User::create([ 'name' => $data['name'], - 'email' => $data['email'], + 'email' => $data['email'] ?? $faker->unique()->safeEmail, 'password' => Hash::make($data['password']), + 'api_token' => Str::random(60), ]); } } diff --git a/app/Http/Controllers/Goods/GoodsBrandsController.php b/app/Http/Controllers/Goods/GoodsBrandsController.php new file mode 100644 index 0000000..f147810 --- /dev/null +++ b/app/Http/Controllers/Goods/GoodsBrandsController.php @@ -0,0 +1,44 @@ +paginate(); + + return GoodsBrandResource::collection($goodsBrands); + } + + public function store(Request $request) + { + $request->validate([ + 'name' => 'required|string|unique:users|max:255', + ]); + + GoodsBrand::created(); + } + + public function show($id) + { + $columns = ['*']; + $goodsBrand = GoodsBrand::query()->find($id, $columns); + + return GoodsBrandResource::collection($goodsBrand); + } + + public function update() + { + + } + + public function destory() + { + + } +} diff --git a/app/Http/Controllers/Goods/GoodsTypesController.php b/app/Http/Controllers/Goods/GoodsTypesController.php new file mode 100644 index 0000000..55b0a76 --- /dev/null +++ b/app/Http/Controllers/Goods/GoodsTypesController.php @@ -0,0 +1,10 @@ +validate([ + 'name' => 'required|string|unique:users|max:255', + 'password' => 'required|string|min:8|confirmed', + ]); + $user = new User(); + $user->name = $request->name; + $user->password = $request->password; + } + + public function show($id) + { + return User::query()->find($id); + } + + public function update() + { + + } + + public function destory() + { + + } +} diff --git a/app/Http/Resources/GoodsBrandResource.php b/app/Http/Resources/GoodsBrandResource.php new file mode 100644 index 0000000..9d73b57 --- /dev/null +++ b/app/Http/Resources/GoodsBrandResource.php @@ -0,0 +1,19 @@ + 'datetime', ]; + + public function setPasswordAttribute($value) + { + $this->attributes['password'] = Hash::make($value); + } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index fa9360e..fa3372e 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -19,10 +19,11 @@ use Illuminate\Support\Str; $factory->define(User::class, function (Faker $faker) { return [ - 'name' => $faker->name, + 'name' => 'erpAdmin', 'email' => $faker->unique()->safeEmail, 'email_verified_at' => now(), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'api_token' => Str::random(60), 'remember_token' => Str::random(10), ]; }); diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index a91e1d3..5a3b4fa 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -19,6 +19,7 @@ class CreateUsersTable extends Migration $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); + $table->string('api_token', 80)->unique()->nullable()->default(null); $table->rememberToken(); $table->timestamps(); }); diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 91cb6d1..a58fc82 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -12,5 +12,6 @@ class DatabaseSeeder extends Seeder public function run() { // $this->call(UsersTableSeeder::class); + factory(\App\Models\User::class)->create(); } } diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php new file mode 100644 index 0000000..06755ee --- /dev/null +++ b/resources/views/home.blade.php @@ -0,0 +1,71 @@ + + +
+ + + +Rz$KlnO_H2c< z(XX#lPuW_%H#Q+c&(nRyX1-Ia dKR-%$4FYC0fsCmL9ky3 zKpxyjd^JFR+vg2!=HWf}2Z?@Td`0EG`kU?{8zKrvtsm)|7>pPk9nu@2^z96aU2<#` z2QhvH5w&V;wER?mopu+nqu*n8p~(%Q kwSs&*0eJwa zMXR05`OSFpfyRb! Y_+H@O%Y z0=K^y6B8Gcbl?SA)qMP3Z+=C(?8zL@=74R=EVnE?vY!1BQy2@q*RUgRx4yJ$k}MnL zs!?74QciNb-LcG*&o<9=DSL>1n}ZNd)w1z3-0Pd^4ED1{qd=9|!!N?xnXjM!EuylY z5=!H>&hSofh8V?Jofyd!h`xDI1fYAuV(sZwwN~{$a}MX^=+0TH*SFp$vyxmUv7C*W zv^3Gl0+eTFgBi3FVD;$nhcp)ka*4gSskYIqQ&+M}xP9yLAkWzBI^I%zR^l1e?bW_6 zIn{mo{dD=)9@V?s^fa55jh78rP*Ze<3`tRCN4*mpO$@7a^*2B*7N_|A(Ve2VB|)_o z$=#_=aBkhe(ifX}MLT()@5? OV+~7cXC3r!%{QJxriXo9I%*3q4KT4Xxzyd{ z9;_%=W%q!Vw$Z7F3lUnY+1HZ*lO;4;VR2+i4+D(m#01OYq|L_fbnT;KN<^dkkCwtd zF7n+O7KvAw8c`JUh6LmeIrk4`F3o|AagKSMK3))_5Cv~y2Bb2!Ibg9BO7Vkz?pAYX zoI=B}+$R22&IL`NCYUYjrdhwjnM x_v=-Qcx-jmtN>!Zqf|n1^SWrHy zK|MwJ?Z#^>)rfT5YSY{qjZ&`Fjd;^vv&gF-Yj6$9-Dy$<6zeP4s+78gS2|t%Z309b z0^fp~ue_}i`U9j!<|qF92_3oB09NqgAoehQ`)<)dSfKoJl_A6Ec#*Mx9Cpd-p#$Ez z={AM*r-bQs6*z$!*V A4|QE7bf@-4vb?Q+pPKLkY2{yKsw{&udv_2v8{Dbd zm~8VAv!G~s)`O3|Q6vFUV%8%+?ZSVUa(;fhPNg#vab@J*9XE4#D%)$UU-T5`fwjz! z6&gA^`OGu6aUk{l*h9eB?opVdrHK>Q@U>&JQ_2pR%}TyOXGq_6s56_`U(WoOaAb+K zXQr#6H}>a-GYs9^bG P2Y&hSP5gEtW+GVC4=wy0wQk=~%CSXj=GH6q z-T#s!BV`xZVxm{~jr_ezYRpqqIcXC=Oq`b{lu`Rt(IYr4B91hhVC?yg{ol4WUr3v9 zOAk2LG>CIECZ-WIs0$N}F#eoIUEtZudc7DPYIjzGqDLWk_A4#( LgacooD z2K4IWs@N`Bddm-{%oy}!k0^i6Yh)uJ1S*90>|bm3TOZxcV|ywHUb(+CeX-o1|LTZM zwU>dY3R&U)T(}5#Neh?-CWT~@{6Ke@sI)uSuzoah8COy)w)B)aslJmp`WUcjdia-0 zl2Y}&L~XfA`uYQboAJ1;J{XLhYjH){cObH3FDva+^8ioOQy%Z=xyjGLmWMrzfFoH; zEi3AG`_v+%)&lDJE;iJWJDI@-X9K5O)LD~j*PBe(wu+|%ar~C+LK1+-+lK =t# z+Xc+J7qp~5q=B~rD!x78)?1+KUIbYr^5rcl&tB-cTtj+e%{gpZZ4G~6r15+d|J(ky zjg@@UzMW0k9@S#W(1H{u;Nq(7llJbq;;4t$awM;l&(2s+$l!Ay9^Ge|34CVhr7|BG z?dAR83smef^frq9V(OH+a+ki#q&-7TkWfFM=5bsGbU(8mC;>QTCWL5ydz9s6k@?+V zcjiH`VI=59P-(-DWXZ~5DH>B^_H~;4$)KUhnmGo*G!Tq8^LjfUDO)lASN*=#AY_yS zqW9UX(VOCO&p@kHdUUgsBO0KhXxn1sprK5h8}+>IhX(nSXZKwlNsjk^M|RAaqmCZB zHBol OHYBas@&{PT=R+?d8pZu zUHfyucQ`(umXSW7o?HQ3H21M`ZJal+%*)SH1B1j6rxTlG3hx1IGJN^M7{$j(9V;MZ zRKybgVuxKo#XVM+?*yTy{W+XHaU5Jbt-UG33x{u(N-2wmw;zzPH&4DE103HV@ER86 z|FZEmQb|&1s5#`$4!Cm}&`^{(4V}OP$bk`}v6q6rm;P!H)W|2i^e{7lTk2W@jo_9q z*aw|U7#+g59Fv(5qI`#O-qPj#@_P>PC#I(GSp3DLv7x-dmYK=C7lPF8a)bxb=@)B1 zUZ`EqpXV2dR}B&r`uM}N(TS99ZT0UB%IN|0H%DcVO#T%L_chrgn#m6%x4KE*IMfjX zJ%4veCEqbXZ`H`F_+fELMC@wuy_ch%t*+Z+1I}wN#C+dRrf2X{1C8=yZ_%Pt6wL_~ zZ2NN-hXOT4P4n$QFO7yYHS-4wF1Xfr-meG9Pn;uK51?hfel`d38k{W)F*|gJLT2#T z<~>spMu4(mul-8Q3*pf=N4DcI)zzjqAgbE2eOT7~&f1W3VsdD44Ffe;3mJp-V@8UC z)|qnPc12o~$X-+U@L_lWqv-RtvB~%hLF($%Ew5w>^NR82qC_0F B z)=hP1-OEx?lLi#jnLzH}a;Nvr@JDO-zQWd}#k^an$Kwml;MrD&)sC5b`s0ZkVyPkb zt}-jOq^%_9>YZe7Y}PhW{a)c39G`kg(P4@kxjcYfgB4XOOcmezdUI7j-!gs7oAo2o zx(Ph{G+YZ`a%~kzK!HTAA5NXE-7vOFRr5oqY$rH>WI6SFvWmahFav!CfRMM3%8J&c z*p+%|-fNS_@QrFr(at!JY9jCg9F-%5{nb5Bo~z@Y9m&SHYV`49GAJjA5h~h4(G!Se zZmK{Bo7ivCfvl}@A-ptkFGcWXAzj3xfl{evi-OG(TaCn1FAHxRc{}B|x+Ua1D=I6M z!C^ZIvK6aS_c&(=OQDZfm>O`Nxsw{ta&yiYPA~@e#c%N>>#rq)k6Aru-qD4(D^v)y z*>Rs;YUbD1S8^D(ps6Jbj0K3wJw>L4m)0e(6Pee3Y?gy9i0^bZO?$*sv+xKV?WBlh zAp*;v6w!a8;A7sLB*g-^<$Z4L7|5jXxxP1}hQZ<55f9<^KJ>^mKlWSGaLcO0=$jem zWyZkRwe~u{{tU63DlCaS9$Y4CP4f?+wwa(&1ou)b>72yd rFvm`R j-0`kBJgK@nd(*Eh!(NC{F-@=FnF&Y!q`7){YsLLHf0_B6aHc# z>WIuHTyJwIH{BJ4)2RtEauC7Yq7Cytc|S )4^*t8Va3HR zg=~sN^tp9re@w=GTx$;zOWMjcg-7X3Wk^N$n;&Kf1RgVG2}2L-(0o)54C509C&77i zrjSi{X*WV=%C17((N^6R4Ya*4#6s_L99RtQ>m(%#nQ#wrRC8Y%yxkH;d!MdY+Tw@r zjpSnK`;C-U{ATcgaxoEpP0Gf+tx);buOM lK=01D|J+ROu37qc*rD(w`#O=3*O*w9?biwNoq3WN1`&Wp8TvKj3C z3HR9ssH7a&Vr<6waJrUzdLg!ieYz%U^bmpn%;(V%%ugMk92&?_XX1K@mwnVSE6!&%P%Wdi7_h`CpScvspMx?N zQUR>oadnG17#hNc$pkTp+9 lW+MBKHRZ~7 4XWUryd)4yd zj98$%XmIL4(9OnoeO5Fnyn&fpQ9b0h4e6EHHw*l68j;>(ya`g^S&y2{O8U>1*>4zR zq*WSI_2o$CHQ?x0!wl9bpx|Cm2+kFMR)oMud1%n2=qn5nE&t@Fgr#=Zv2?}wtEz^T z9rrj=?I H*qI5{G@Rn&}^Z{+TW}mQe b9=8b<_a`&Cm#n%n~ zU47MvCBsdXFB1+adOO)03+nczfWa#vwk #r{o{dF)QWya9v2nv43Zp3%Ps}($lA02*_g25t;|T{A5snSY?3A zrRQ~(Ygh_ebltHo1VC bJb*eOAr;4cnlXLvI>*$-#AVsGg6B1r7@;g^L zFlJ_th0vxO7;-opU@WAFe;<}?!2q?RBrFK5U{ *ai@NLKZ^};Ul}beukveh?TQn;$%9=R+DX07m82gP$=}Uo_%&ngV`}Hyv8g{u z3SWzTGV|cwQuFIs7ZDOqO_fGf8Q`8MwL}eUp>q?4eqCmOTcwQuXtQckPy|4F1on8l zP*h>d+cH#XQf|+6c|S{7SF(Lg>bR~l(0uY?O{OEVlaxa5@e%T&xju=o1`=OD#qc16 zSvyH*my(dcp6~VqR;o(#@m44Lug@~_qw+HA=mS#Z^ 4reBy8iV?H~I;{LQWk3aKK8$bLRyt$g?- + ++ + + + + diff --git a/resources/frontend/src/css/style.css b/resources/frontend/src/css/style.css new file mode 100644 index 0000000..ec6bae8 --- /dev/null +++ b/resources/frontend/src/css/style.css @@ -0,0 +1,12 @@ +* { + padding: 0 0; + margin: 0 0; +} +body,html { + width: 100%; + height: 100%; + overflow-y: hidden; +} +ul { + list-style: none; +} \ No newline at end of file diff --git a/resources/frontend/src/main.js b/resources/frontend/src/main.js new file mode 100644 index 0000000..047ff6a --- /dev/null +++ b/resources/frontend/src/main.js @@ -0,0 +1,25 @@ +import Vue from 'vue' +import App from './App.vue' +import router from './router' +import store from './store' +import ElementUI from 'element-ui' +import 'element-ui/lib/theme-chalk/index.css' +import '@/css/style.css' +import './router/index2' + + +// import Router from 'vue-router' +// const routerPush = Router.prototype.push +// Router.prototype.push = function push(location) { +// return routerPush.call(this, location).catch(error=> error) +// } + +Vue.use(ElementUI) + +Vue.config.productionTip = false + +new Vue({ + router, + store, + render: h => h(App) +}).$mount('#app') diff --git a/resources/frontend/src/router/index.js b/resources/frontend/src/router/index.js new file mode 100644 index 0000000..b9b8f45 --- /dev/null +++ b/resources/frontend/src/router/index.js @@ -0,0 +1,12 @@ +import Vue from 'vue' +import VueRouter from 'vue-router' + +Vue.use(VueRouter) + +const createRouter = () => + new VueRouter({ + scrollBehavior: () => ({ y: 0 }) + }) + +const router = createRouter() +export default router diff --git a/resources/frontend/src/router/index1.js b/resources/frontend/src/router/index1.js new file mode 100644 index 0000000..96e376b --- /dev/null +++ b/resources/frontend/src/router/index1.js @@ -0,0 +1,77 @@ +/* + * @Description: + * @Author: czw (725551805@qq.com) + * @Date: 2022-02-25 10:40:17 + * @LastEditors: czw (725551805@qq.com) + * @LastEditTime: 2022-03-01 20:29:32 + * @FilePath: /glxt/src/router/index1.js + */ + +const list = [ + { + path: '/logo', + name: 'logo', + component: () => import('../views/logo.vue') + }, + { + path: '/', + component: () => import('../views/index.vue'), + children: [ + { + path: 'GOODS_LIST', + name: '商品列表', + component: () => import('../views/yingyeting/yingyeting.vue') + }, + { + path: 'GOODS_TYPE', + name: '商品种类', + component: () => import('../views/home/home.vue') + }, + { + path: 'GOODS_BRAND', + name: '商品品牌', + component: () => import('../views/brand/brand.vue') + }, + { + path: 'SHOP_MANAGE', + name: '店铺管理', + component: () => import('../views/store/store.vue') + }, + { + path: 'USER_MANAGE', + name: '用户管理', + component: () => import('../views/users/users.vue') + }, + { + path: 'ROLE_MANAGE', + name: '角色管理', + component: () => import('../views/system/role.vue') + }, + { + path: 'PERMISSION_MANAGE', + name: '权限管理', + component: () => import('../views/system/authority.vue') + }, + { + path: 'SYSTEM_LOG', + name: '商品记录', + component: () => import('../views/shuju/shuju.vue') + }, + { + path: '/index/yingyeting/addgoods', + name: '新建商品', + component: () => import('../views/yingyeting/addgoods/addgoods.vue') + }, + { + path: '/', + redirect: 'GOODS_LIST' + } + ] + }, + { + path: '/', + redirect: '/index' + } +] + +export default list diff --git a/resources/frontend/src/router/index2.js b/resources/frontend/src/router/index2.js new file mode 100644 index 0000000..a9ef295 --- /dev/null +++ b/resources/frontend/src/router/index2.js @@ -0,0 +1,18 @@ +/* + * @Description: + * @Author: czw (725551805@qq.com) + * @Date: 2022-02-25 10:40:25 + * @LastEditors: czw (725551805@qq.com) + * @LastEditTime: 2022-02-25 12:18:31 + * @FilePath: /glxt/src/router/index2.js + */ + +import router from './index' +import Home from './index1' +// console.log(...Home); + +Home.forEach(element => { + router.addRoute(element) // 动态添加更多的路由规则 +}) + +// 菜单路由数据 diff --git a/resources/frontend/src/store/index.js b/resources/frontend/src/store/index.js new file mode 100644 index 0000000..332b916 --- /dev/null +++ b/resources/frontend/src/store/index.js @@ -0,0 +1,15 @@ +import Vue from 'vue' +import Vuex from 'vuex' + +Vue.use(Vuex) + +export default new Vuex.Store({ + state: { + }, + mutations: { + }, + actions: { + }, + modules: { + } +}) diff --git a/resources/frontend/src/util/auth.js b/resources/frontend/src/util/auth.js new file mode 100644 index 0000000..9f228e9 --- /dev/null +++ b/resources/frontend/src/util/auth.js @@ -0,0 +1,13 @@ +const TokenKey = 'admin_token' +// 获取token +export function getToken () { + return localStorage.getItem(TokenKey) +} +// 设置token +export function setToken (token) { + return localStorage.setItem(TokenKey, token) +} +// 删除token +export function removeToken () { + return localStorage.removeItem(TokenKey) +} diff --git a/resources/frontend/src/util/http.js b/resources/frontend/src/util/http.js new file mode 100644 index 0000000..01b9817 --- /dev/null +++ b/resources/frontend/src/util/http.js @@ -0,0 +1,82 @@ +/* + * @Description: api请求 + * @Author: chenzhiwei (725551805@qq.com) + * @Date: 2021-08-02 15:52:34 + * @LastEditors: czw (725551805@qq.com) + * @LastEditTime: 2022-03-13 11:05:08 + * @FilePath: /glxt/src/util/http.js + */ +import axios from 'axios' +import { getToken } from '@/util/auth' +import NProgress from 'nprogress' +import 'nprogress/nprogress.css' +import { Message } from 'element-ui' +import router from '@/router' +var instance = axios.create({ + + timeout: 10000 +}) + +instance.interceptors.request.use( + config => { + // config.headers['content-type'] = 'application/json' + + // config.headers['Shop-Id'] = localStorage.getItem('shopId') || 1 + + // 在发送请求之前做些什么 + // config.headers.Authorization = 'Bearer' + getToken() // 请求头 + // config.headers['content-type'] = 'application/json' + config.headers.Authorization = 'Bearer ' + getToken() // 请求头 + NProgress.start() + console.log(config, '1111') // for debug + + return config + }, + error => { + // 对请求错误做些什么 + console.log(error, '222222') // for debug + return Promise.reject(error) + } +) + +// 添加响应拦截器 +instance.interceptors.response.use( + response => { + NProgress.done() + const res = response.status + // 对响应数据做点什么 + console.log(response, '33333') // for debug + if (res === 200 || res === 201) { + return response + } else { + Message({ + message: 'Error', + type: 'error' + + }) + } + }, + error => { + // 对响应错误做点什么 + + console.log(error, '44444') // for debug + // if (error.response.status === 401) { + // Message({ + // message: '账户登录过期,请重新登录', + // type: 'error' + + // }) + // router.push('/login') + // } else { + // Message({ + // message: error.response || 'Error', + // type: 'error' + + // }) + // } + + return Promise.reject(error) + } +) + +export default instance diff --git a/resources/frontend/src/util/remoteLoad.js b/resources/frontend/src/util/remoteLoad.js new file mode 100644 index 0000000..cbf3257 --- /dev/null +++ b/resources/frontend/src/util/remoteLoad.js @@ -0,0 +1,64 @@ +/* + * @Author: 陈智伟 9459156+chen-kaitao@user.noreply.gitee.com + * @Date: 2021-10-05 11:34:34 + * @LastEditors: 陈智伟 9459156+chen-kaitao@user.noreply.gitee.com + * @LastEditTime: 2022-07-23 10:20:28 + * @FilePath: /glxt/src/util/remoteLoad.js + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +export default function remoteLoad (url, hasCallback) { + return createScript(url) + /** + * 创建script + * @param url + * @returns {Promise} + */ + function createScript (url) { + const scriptElement = document.createElement('script') + document.body.appendChild(scriptElement) + const promise = new Promise((resolve, reject) => { + scriptElement.addEventListener( + 'load', + (e) => { + removeScript(scriptElement) + if (!hasCallback) { + resolve(e) + } + }, + false + ) + + scriptElement.addEventListener( + 'error', + (e) => { + removeScript(scriptElement) + reject(e) + }, + false + ) + + if (hasCallback) { + window.____callback____ = function () { + resolve() + window.____callback____ = null + } + } + }) + + if (hasCallback) { + url += '&callback=____callback____' + } + + scriptElement.src = url + + return promise + } + + /** + * 移除script标签 + * @param scriptElement script dom + */ + function removeScript (scriptElement) { + document.body.removeChild(scriptElement) + } +} diff --git a/resources/frontend/src/views/brand/brand.vue b/resources/frontend/src/views/brand/brand.vue new file mode 100644 index 0000000..d30fe53 --- /dev/null +++ b/resources/frontend/src/views/brand/brand.vue @@ -0,0 +1,199 @@ + ++ ++正在加载数据 ...+++ + + + + diff --git a/resources/frontend/src/views/home/home.vue b/resources/frontend/src/views/home/home.vue new file mode 100644 index 0000000..2c66ceb --- /dev/null +++ b/resources/frontend/src/views/home/home.vue @@ -0,0 +1,206 @@ + ++ +新增 ++ ++ ++ ++ + +编辑 +删除 + + ++ + ++ + ++ + ++ ++ + ++ + ++ ++ ++ + + + + \ No newline at end of file diff --git a/resources/frontend/src/views/home/home/cesi.vue b/resources/frontend/src/views/home/home/cesi.vue new file mode 100644 index 0000000..d04f4e2 --- /dev/null +++ b/resources/frontend/src/views/home/home/cesi.vue @@ -0,0 +1,40 @@ + + ++ +新增 ++ ++ ++ ++ + +编辑 +删除 + + ++ + ++ + ++ + ++ ++ + ++ + ++ ++ + ++ + + diff --git a/resources/frontend/src/views/home/home/index.vue b/resources/frontend/src/views/home/home/index.vue new file mode 100644 index 0000000..d8293ed --- /dev/null +++ b/resources/frontend/src/views/home/home/index.vue @@ -0,0 +1,221 @@ + + +++ + + + + + diff --git a/resources/frontend/src/views/index.vue b/resources/frontend/src/views/index.vue new file mode 100644 index 0000000..b2a0c56 --- /dev/null +++ b/resources/frontend/src/views/index.vue @@ -0,0 +1,375 @@ + ++ + + +++{{list}} ++ +++ + + diff --git a/resources/frontend/src/views/logo.vue b/resources/frontend/src/views/logo.vue new file mode 100644 index 0000000..55ed68f --- /dev/null +++ b/resources/frontend/src/views/logo.vue @@ -0,0 +1,74 @@ + + ++ ++ ++ ++ ++++ {{item.name}} + ++ + {{item.name}} + + +{{items.name}} ++ ++++
+- +
++ + +++++ +{{item.name}} +- +
++ 退出 +++++
+- +
- + + + +
+- +
+++ ++ + + + + diff --git a/resources/frontend/src/views/shuju/shuju.vue b/resources/frontend/src/views/shuju/shuju.vue new file mode 100644 index 0000000..b23f4be --- /dev/null +++ b/resources/frontend/src/views/shuju/shuju.vue @@ -0,0 +1,164 @@ + ++ ++ ++ + ++ + +登录 +++ + + + + diff --git a/resources/frontend/src/views/store/store.vue b/resources/frontend/src/views/store/store.vue new file mode 100644 index 0000000..49c5006 --- /dev/null +++ b/resources/frontend/src/views/store/store.vue @@ -0,0 +1,57 @@ + ++ +++ ++ + ++ ++ ++ ++ ++ ++ ++ ++ ++ + +查询 ++ ++ + 历史记录 + (共800条) + ——玫瑰花 +++ + ++ ++ ++ ++ ++ ++ ++ ++ + + + + + diff --git a/resources/frontend/src/views/system/authority.vue b/resources/frontend/src/views/system/authority.vue new file mode 100644 index 0000000..852ebd6 --- /dev/null +++ b/resources/frontend/src/views/system/authority.vue @@ -0,0 +1,22 @@ + ++ ++ ++ ++ ++ + + + + diff --git a/resources/frontend/src/views/system/role.vue b/resources/frontend/src/views/system/role.vue new file mode 100644 index 0000000..5dccecb --- /dev/null +++ b/resources/frontend/src/views/system/role.vue @@ -0,0 +1,22 @@ + ++ ++ + + + + diff --git a/resources/frontend/src/views/users/users.vue b/resources/frontend/src/views/users/users.vue new file mode 100644 index 0000000..637d61d --- /dev/null +++ b/resources/frontend/src/views/users/users.vue @@ -0,0 +1,22 @@ + ++ ++ + + + + diff --git a/resources/frontend/src/views/yingyeting/addgoods/addgoods.vue b/resources/frontend/src/views/yingyeting/addgoods/addgoods.vue new file mode 100644 index 0000000..48010a3 --- /dev/null +++ b/resources/frontend/src/views/yingyeting/addgoods/addgoods.vue @@ -0,0 +1,220 @@ + +++ + + + + diff --git a/resources/frontend/src/views/yingyeting/yingyeting.vue b/resources/frontend/src/views/yingyeting/yingyeting.vue new file mode 100644 index 0000000..62f9e95 --- /dev/null +++ b/resources/frontend/src/views/yingyeting/yingyeting.vue @@ -0,0 +1,363 @@ + + ++ +++ ++ 商品图片: +++ ++ +
+ + ++++ ++ ++ ++ ++ ++ ++ ++ ++ ++ {{i+1}}. +++ + + ++ + ++ ++ + ++ ++ + ++++ ++ + ++ ++ + +删除 +++ ++ +保存 +取消 +++ + + + + diff --git a/resources/frontend/vue.config.js b/resources/frontend/vue.config.js new file mode 100644 index 0000000..c43d458 --- /dev/null +++ b/resources/frontend/vue.config.js @@ -0,0 +1,22 @@ +module.exports = { + lintOnSave: false, + publicPath: './', // 配置打包之后的相对路径 + devServer: { + open: true, // 设置浏览器自动打开项目 + port: 8080, // 开发服务器运行端口号 + overlay: { + warnings: false, + errors: true + }, + proxy: { // 配置代理 + '/api': { + // target: 'http://doc.ii090.com/mock/267/', + target: 'http://erp.staging.miaoxuan66.cn', + changeOrigin: true, // 开启代理 + pathRewrite: { // 重命名 + '^/api': 'api' + } + } + } + } +} From ec7ef4969e391453b80d4e9f23f9bcd5dbf855f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 2 Aug 2022 11:43:46 +0800 Subject: [PATCH 15/35] =?UTF-8?q?feat:=20#20220802=20=E5=BA=97=E9=93=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Goods/GoodsSkusController.php | 104 ++++++++++++++++++ app/Http/Controllers/Shop/ShopsController.php | 45 ++++++++ app/Http/Resources/ShopsResource.php | 19 ++++ app/Models/Shop.php | 42 +++++++ .../2014_10_12_000000_create_users_table.php | 1 + .../2022_08_02_022448_create_shops_table.php | 45 ++++++++ database/seeds/MenusTableSeeder.php | 2 +- 7 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Shop/ShopsController.php create mode 100644 app/Http/Resources/ShopsResource.php create mode 100644 app/Models/Shop.php create mode 100644 database/migrations/2022_08_02_022448_create_shops_table.php diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index edf81ce..cf40820 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -8,6 +8,8 @@ use Illuminate\Http\Request; use App\Models\GoodsSku; use App\Http\Resources\GoodsSkuResource; use App\Imports\GoodsSkusImport; +use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; use Maatwebsite\Excel\Facades\Excel; @@ -35,7 +37,109 @@ class GoodsSkusController extends Controller public function update($id, Request $request) { + $data = $request->all(); + $this->validateUpdate($data); + $sku = GoodsSku::query()->find($id); + $this->setBeforeUpdate($sku->toArray()); + $sku->save($data); + $this->setAfterUpdate($sku->toArray()); + $this->addLog($id, 'update'); + return new GoodsSkuResource($sku); + } + + public function batchUpdate(Request $request) + { + $appendRules = [ + '*.id' => [ + 'required', + Rule::exists('goods_skus', 'id'), + ], + ]; + } + + public function updateField($id, Request $request) + { + $appendRules = [ + 'updateField' => [ + 'required', + Rule::in(['reference_price', 'reserve', 'loss_num', 'status']) + ], + ]; + if ($request->has('loss_num')) { + $appendRules['reason'] = ['required', 'string']; + } + $this->validateUpdate($request->all(), $appendRules); + $updateField = \request('updateField'); + $sku = GoodsSku::query()->find($id); + $this->setBeforeUpdate($sku->$updateField); + $sku->$updateField = $request->$updateField; + $sku->save(); + $this->setAfterUpdate($sku->$updateField); + $this->addLog($id, $updateField); + + return new GoodsSkuResource($sku); + } + + public function updateStock($id, Request $request) + { + $this->validateUpdate($request->all()); + $sku = GoodsSku::query()->where('id', $id)->get(['id', 'two_days_ago_num', 'yesterday_num']); + if ($sku->two_days_ago_num != \request('t wo_days_ago_num') || $sku->yesterday_num != \request('yesterday_num')) { + $this->setBeforeUpdate($sku->toArray()); + } + + } + + private function validateUpdate($data, $appendRules = []) + { + $rules = [ + '*.two_days_ago_num' => [ + 'sometimes', + 'integer', + ], + '*.yesterday_num' => [ + 'sometimes', + 'integer', + ], + '*.arrived_today_num' => [ + 'sometimes', + 'integer', + ], + '*.cost' => [ + 'sometimes', + 'numeric', + 'gt:0' + ], + '*.reference_price' => [ + 'sometimes', + 'numeric', + 'gt:0' + ], + '*.reserve' => [ + 'sometimes', + 'integer', + ], + '*.loss_num' => [ + 'sometimes', + 'integer', + ], + '*.inventory' => [ + 'sometimes', + 'integer', + ], + '*.status' => [ + 'sometimes', + 'integer', + Rule::in([0, 1, 2]) + ], + ]; + $validator = Validator::make($data, array_merge($rules, $appendRules)); + if ($validator->fails()) { + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); + + return response($this->res, $this->res['httpCode']); + } } public function store(Request $request) diff --git a/app/Http/Controllers/Shop/ShopsController.php b/app/Http/Controllers/Shop/ShopsController.php new file mode 100644 index 0000000..f4fd384 --- /dev/null +++ b/app/Http/Controllers/Shop/ShopsController.php @@ -0,0 +1,45 @@ +paginate(); + + return ShopsResource::collection($shops); + } + + public function getPlatList() + { + $shop = new Shop(); + + return new ShopsResource($shop->getPlatList()); + } + + public function store(Request $request) + { + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:255|unique:shops,name', + 'plat_id' => 'required|integer', + ]); + if ($validator->fails()) { + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); + + return response($this->res, $this->res['httpCode']); + } + $shop = new Shop(); + $shop->name = $request->name; + $shop->plat_id = $request->plat_id; + $shop->save(); + + return response($this->res, $this->res['httpCode']); + } +} diff --git a/app/Http/Resources/ShopsResource.php b/app/Http/Resources/ShopsResource.php new file mode 100644 index 0000000..33fdcbf --- /dev/null +++ b/app/Http/Resources/ShopsResource.php @@ -0,0 +1,19 @@ + '未授权', + 1 => '已授权', + 2 => '无需授权', + 3 => '停用', + ]; + + return $map[$value]; + } + + public function getPlatList() + { + return ['妙选', '快团团']; + } + + public function getPlatIdAttribute($value) + { + $map = $this->getPlatList(); + + return $map[$value]; + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index fc36207..03b4dc9 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -20,6 +20,7 @@ class CreateUsersTable extends Migration $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->string('api_token', 80)->unique()->nullable(false); + $table->softDeletes(); $table->rememberToken(); $table->timestamps(); }); diff --git a/database/migrations/2022_08_02_022448_create_shops_table.php b/database/migrations/2022_08_02_022448_create_shops_table.php new file mode 100644 index 0000000..7fddb77 --- /dev/null +++ b/database/migrations/2022_08_02_022448_create_shops_table.php @@ -0,0 +1,45 @@ +bigIncrements('id'); + $table->string('name')->unique(); + $table->unsignedTinyInteger('plat_id')->comment('平台id'); + $table->string('access_token')->nullable(); + $table->unsignedMediumInteger('expires_at')->nullable()->comment('access_token过期时间点'); + $table->unsignedInteger('expires_in')->nullable()->comment('access_token过期时间段,10(表示10秒后过期)'); + $table->string('owner_id')->nullable()->comment('商家店铺id'); + $table->string('owner_name')->nullable()->comment('商家账号名称'); + $table->string('refresh_token')->nullable()->comment('refresh token,可用来刷新access_token'); + $table->unsignedMediumInteger('refresh_token_expires_at')->nullable()->comment('Refresh token过期时间点'); + $table->unsignedInteger('refresh_token_expires_in')->nullable()->comment('refresh_token过期时间段,10表示10秒后过期'); + $table->text('scope')->nullable()->comment('接口列表'); + $table->text('pop_auth_token_create_response')->nullable()->comment('授权认证信息'); + $table->string('status')->default(0)->comment('状态'); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('shops'); + } +} diff --git a/database/seeds/MenusTableSeeder.php b/database/seeds/MenusTableSeeder.php index 3aff505..d968742 100644 --- a/database/seeds/MenusTableSeeder.php +++ b/database/seeds/MenusTableSeeder.php @@ -30,6 +30,6 @@ class MenusTableSeeder extends Seeder ['parent_id' => $id,'code' => 'PERMISSION_MANAGE', 'name' => '权限管理', 'seq' => 1], ]); // 系统日志 - DB::table('menus')->insertGetId(['parent_id' => 0,'code' => 'SYSTEM_LOG', 'name' => '系统管理', 'seq' => 4]); + DB::table('menus')->insertGetId(['parent_id' => 0,'code' => 'SYSTEM_LOG', 'name' => '系统日志', 'seq' => 4]); } } From ad4f38fcbe45729c1fdd4b099e5dd7e1aedf0038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 2 Aug 2022 16:28:22 +0800 Subject: [PATCH 16/35] =?UTF-8?q?feat:=20#20220802=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=A2=9E=E5=8A=A0=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/User/UsersController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/User/UsersController.php b/app/Http/Controllers/User/UsersController.php index f2f4f30..dd69dc0 100644 --- a/app/Http/Controllers/User/UsersController.php +++ b/app/Http/Controllers/User/UsersController.php @@ -35,6 +35,7 @@ class UsersController extends Controller 'name' => 'required|string|unique:users,name|max:255', 'password' => 'required|string|min:8|confirmed', 'email' => 'email', + 'role_name' => 'required|string|exists:roles,name' ]); if ($validator->fails()) { $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); @@ -49,6 +50,7 @@ class UsersController extends Controller $user->save(); $this->setAfterUpdate($user->toArray()); $this->addLog($user->id, 'add'); + $user->assignRole($request->role_name); return new UsersResource($user); } From e83421ea5b6dee5db3b6ec7ee7d0332a75bf2bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 2 Aug 2022 18:20:06 +0800 Subject: [PATCH 17/35] =?UTF-8?q?feat:=20#20220802=20=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Role/RolesController.php | 2 +- app/Http/Controllers/User/UsersController.php | 46 +++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Role/RolesController.php b/app/Http/Controllers/Role/RolesController.php index caca780..93ecc3d 100644 --- a/app/Http/Controllers/Role/RolesController.php +++ b/app/Http/Controllers/Role/RolesController.php @@ -45,7 +45,7 @@ class RolesController extends Controller $this->setAfterUpdate($role->name); $this->addLog($role->id, 'add'); - return response($this->res, $this->res['httpCode']); + return new RolesResource($role); } public function addPermissions($id, Request $request) diff --git a/app/Http/Controllers/User/UsersController.php b/app/Http/Controllers/User/UsersController.php index dd69dc0..e341bae 100644 --- a/app/Http/Controllers/User/UsersController.php +++ b/app/Http/Controllers/User/UsersController.php @@ -10,6 +10,7 @@ use Faker\Generator as Faker; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use App\Http\Resources\UsersResource; +use Illuminate\Validation\Rule; class UsersController extends Controller { @@ -24,7 +25,7 @@ class UsersController extends Controller public function index() { - $users = User::query()->where('id', '<>', 1)->paginate(); + $users = User::query()->where('id', '<>', 1)->with('roles:id,name,guard_name')->paginate(); return UsersResource::collection($users); } @@ -32,7 +33,7 @@ class UsersController extends Controller public function store(Request $request, Faker $faker) { $validator = Validator::make($request->all(), [ - 'name' => 'required|string|unique:users,name|max:255', + 'name' => 'required|string|max:255|unique:users,name', 'password' => 'required|string|min:8|confirmed', 'email' => 'email', 'role_name' => 'required|string|exists:roles,name' @@ -57,16 +58,51 @@ class UsersController extends Controller public function show($id) { - return new UsersResource(User::query()->find($id)); + return new UsersResource(User::query()->with('roles:id,name,guard_name')->find($id)); } - public function update() + public function update($id, Request $request) { + $validator = Validator::make($request->all(), [ + 'name' => [ + 'required', + 'string', + 'max:255', + Rule::unique('users')->ignore($id), + ], +// 'old_password' => 'sometimes|required|string|min:8', + 'password' => 'sometimes|string|min:8|confirmed', + 'email' => 'sometimes|email', + 'role_name' => 'sometimes|required|string|exists:roles,name' + ]); + if ($validator->fails()) { + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); + return response($this->res, $this->res['httpCode']); + } + $user = User::query()->find($id); + $user->update($request->toArray()); + if ($request->has('role_name')) { + $user->syncRoles($request->role_name); + } + + return new UsersResource($user); } - public function destory() + public function destory($id) { + $user = User::query()->find($id); + try { + $user->delete(); + $this->addLog($id, 'status'); + } catch (\Exception $e) { + $this->res = [ + 'httpCode' => 500, + 'errorCode' => 500416, + 'errorMessage' => $e->getMessage(), + ]; + } + return response($this->res, $this->res['httpCode']); } } From 1ae21f041f170d63aad8a01d3974facf4936ff59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 2 Aug 2022 18:56:04 +0800 Subject: [PATCH 18/35] =?UTF-8?q?feat:=20#20220802=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/UploadController.php | 33 +++ app/Utils/UploadUtils.php | 123 +++++++++ composer.json | 2 + composer.lock | 290 +++++++++++++++++++++- config/filesystems.php | 13 +- routes/api.php | 2 + 6 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/UploadController.php create mode 100644 app/Utils/UploadUtils.php diff --git a/app/Http/Controllers/UploadController.php b/app/Http/Controllers/UploadController.php new file mode 100644 index 0000000..59773ce --- /dev/null +++ b/app/Http/Controllers/UploadController.php @@ -0,0 +1,33 @@ +log = new LogModel([ + 'module' => 'file', + 'action' => $request->getMethod(), + 'target_type' => 'upload', + ]); + } + + public function store(Request $request) + { + if (!$request->hasFile('uploadFile')) { + $this->res = [ + 'httpCode' => 404, + 'errorCode' => 404404, + 'errorMessage' => 'not found file', + ]; + } + $this->addLog(0, 'add'); + + return UploadUtils::putForUploadedFile('image', $request->uploadFile); + } +} diff --git a/app/Utils/UploadUtils.php b/app/Utils/UploadUtils.php new file mode 100644 index 0000000..caaba2c --- /dev/null +++ b/app/Utils/UploadUtils.php @@ -0,0 +1,123 @@ +extension() != 'gif') { + // 压缩图片 + $originalName = static::randomFileName($extension ?: $upload->getClientOriginalExtension()); + $storagePath = storage_path('app/public/file/') . $originalName; + $img = Image::make($upload->getRealPath()); + + // 未传宽度 大于800压缩至800 否则按照原宽度 + $width = $img->width() >= 800 ? 800 : $img->width(); + // 高度自适应 + $img->resize($width, null, function ($constraint) { + $constraint->aspectRatio(); + }); + $img->save($storagePath); + $upload = new UploadedFile($storagePath, $originalName); + } + + // 上传并删除压缩图片 + try { + $filePath = static::put($bucketPath, $upload->getRealPath(), $upload->getClientOriginalExtension()); + } catch (OssException $e) { + throw $e; + } finally { + if (isset($storagePath)) { + unlink($storagePath); + } + } + + return $filePath; + } + + //上传图片 + public static function putForUploadedFile($bucketPath, UploadedFile $upload) + { + return static::put($bucketPath, $upload->getRealPath(), $upload->getClientOriginalExtension()); + } + + public static function put($bucketPath, $filepath, $ext) + { + static::init(); + try { + $filePath = static::$prefix . $bucketPath . '/' . static::randomFileName($ext); + static::$ossClient->uploadFile(static::$bucket, $filePath, $filepath); + } catch (OssException $e) { + throw $e; + } + return $filePath; + } + + public static function buildFilePath() + { + return date('Y') . '/' . date('m') . '/' . date('d'); + } + + public static function randomFileName($ext, $len = 40) + { + return Str::random($len) . '.' . $ext; + } + + //删除修改前,上传修改后图片 + public static function delAndUploadImage($file, $filePath, UploadedFile $upload) + { + static::delFile($file); + return static::putForUploadedFile($filePath, $upload); + } + + //删除修改前,上传修改后视频 + public static function delAndUploadVideo($file, $filePath, UploadedFile $upload) + { + static::delFile($file); + return static::putForUploadedFile($filePath, $upload); + } + + public static function delFile($file) + { + static::init(); + if (static::exist($file)) { + return static::$ossClient->deleteObject(static::$bucket, $file); + } + return false; + } + + public static function exist($file) + { + static::init(); + return static::$ossClient->doesObjectExist(static::$bucket, $file); + } + + public static function getFullImgUrl($filePath) + { + return config('filesystems.disks.aliyun.url') . $filePath; + } + +} diff --git a/composer.json b/composer.json index 63a511a..e442ecc 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,9 @@ "license": "MIT", "require": { "php": "^7.2.5|^8.0", + "aliyuncs/oss-sdk-php": "^2.5", "fideloper/proxy": "^4.4", + "intervention/image": "^2.7", "laravel/framework": "^6.20.26", "laravel/tinker": "^2.5", "maatwebsite/excel": "^3.1", diff --git a/composer.lock b/composer.lock index 6c4e88e..b66292d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,53 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "486f251784470138e7bd835f6ea84ce3", + "content-hash": "87b78d5c6e1dfc1285abb501c7eb8372", "packages": [ + { + "name": "aliyuncs/oss-sdk-php", + "version": "v2.5.0", + "source": { + "type": "git", + "url": "https://github.com/aliyun/aliyun-oss-php-sdk.git", + "reference": "f0413667d765855eb0aaa728b596801464ffdb06" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aliyun/aliyun-oss-php-sdk/zipball/f0413667d765855eb0aaa728b596801464ffdb06", + "reference": "f0413667d765855eb0aaa728b596801464ffdb06", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "*", + "satooshi/php-coveralls": "*" + }, + "type": "library", + "autoload": { + "psr-4": { + "OSS\\": "src/OSS" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Aliyuncs", + "homepage": "http://www.aliyun.com" + } + ], + "description": "Aliyun OSS SDK for PHP", + "homepage": "http://www.aliyun.com/product/oss/", + "support": { + "issues": "https://github.com/aliyun/aliyun-oss-php-sdk/issues", + "source": "https://github.com/aliyun/aliyun-oss-php-sdk/tree/v2.5.0" + }, + "time": "2022-05-13T07:41:28+00:00" + }, { "name": "doctrine/inflector", "version": "2.0.4", @@ -414,6 +459,205 @@ }, "time": "2022-02-09T13:33:34+00:00" }, + { + "name": "guzzlehttp/psr7", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "13388f00956b1503577598873fffb5ae994b5737" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/13388f00956b1503577598873fffb5ae994b5737", + "reference": "13388f00956b1503577598873fffb5ae994b5737", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.8 || ^9.3.10" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.4.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2022-06-20T21:43:11+00:00" + }, + { + "name": "intervention/image", + "version": "2.7.2", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "04be355f8d6734c826045d02a1079ad658322dad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/04be355f8d6734c826045d02a1079ad658322dad", + "reference": "04be355f8d6734c826045d02a1079ad658322dad", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "guzzlehttp/psr7": "~1.1 || ^2.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9.2", + "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15" + }, + "suggest": { + "ext-gd": "to use GD library based image processing.", + "ext-imagick": "to use Imagick based image processing.", + "intervention/imagecache": "Caching extension for the Intervention Image library" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + }, + "laravel": { + "providers": [ + "Intervention\\Image\\ImageServiceProvider" + ], + "aliases": { + "Image": "Intervention\\Image\\Facades\\Image" + } + } + }, + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src/Intervention/Image" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" + } + ], + "description": "Image handling and manipulation library with support for Laravel integration", + "homepage": "http://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "laravel", + "thumbnail", + "watermark" + ], + "support": { + "issues": "https://github.com/Intervention/image/issues", + "source": "https://github.com/Intervention/image/tree/2.7.2" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + } + ], + "time": "2022-05-21T17:30:32+00:00" + }, { "name": "laravel/framework", "version": "v6.20.44", @@ -2131,6 +2375,50 @@ }, "time": "2022-07-07T13:49:11+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, { "name": "ramsey/uuid", "version": "3.9.6", diff --git a/config/filesystems.php b/config/filesystems.php index 220c010..9df9941 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -64,7 +64,18 @@ return [ 'url' => env('AWS_URL'), 'endpoint' => env('AWS_ENDPOINT'), ], - + 'aliyun' => [ + 'driver' => 'oss', + 'access_id' => 'LTAI6do39W9jINpe', + 'access_key' => 'XLhp5w4WnRcqji204GYOm7hZsoXSB6', + 'bucket' => 'ct-upimg', + 'endpoint' => 'oss-cn-hangzhou.aliyuncs.com', // OSS 外网节点或自定义外部域名 +// 'cdnDomain' => 'cdn-xiangma.yx090.com', // 如果isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url,如果cdnDomain未设置,则使用endpoint来生成url,否则使用cdn + 'url' => 'https://ct-upimg.yx090.com/', + 'ssl' => true, + 'isCName' => false, // 是否使用自定义域名,true: 则Storage.url()会使用自定义的cdn或域名生成文件url, false: 则使用外部节点生成url + 'debug' => true + ], ], ]; diff --git a/routes/api.php b/routes/api.php index e97d2a3..2ce75fd 100644 --- a/routes/api.php +++ b/routes/api.php @@ -2,6 +2,7 @@ use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Role\RolesController; +use App\Http\Controllers\UploadController; /* |-------------------------------------------------------------------------- @@ -37,6 +38,7 @@ Route::middleware('auth:api')->group(function () { Route::resource('menus', 'Menu\MenusController', ['only' => ['index', // 'store', 'show', 'update', 'destroy' ]]); + Route::post('upload', [UploadController::class, 'store'])->name('upload.file'); }); Route::post('/auth/login', [LoginController::class, 'login'])->name('auth.login'); From 92c95b529691976931a904234f67e2e15462969e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 2 Aug 2022 19:01:47 +0800 Subject: [PATCH 19/35] =?UTF-8?q?feat:=20#20220802=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/UploadController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/UploadController.php b/app/Http/Controllers/UploadController.php index 59773ce..38ede3f 100644 --- a/app/Http/Controllers/UploadController.php +++ b/app/Http/Controllers/UploadController.php @@ -27,7 +27,8 @@ class UploadController extends Controller ]; } $this->addLog(0, 'add'); + $this->res['resource'] = UploadUtils::putForUploadedFile('image', $request->uploadFile); - return UploadUtils::putForUploadedFile('image', $request->uploadFile); + return response($this->res, $this->res['httpCode']); } } From 4e7d24e0151437c83b2fd833b0a7925370b899c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 2 Aug 2022 20:02:48 +0800 Subject: [PATCH 20/35] =?UTF-8?q?feat:=20#20220802=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E5=B9=B3=E5=8F=B0=E5=88=97=E8=A1=A8=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/api.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes/api.php b/routes/api.php index 2ce75fd..7ae0b39 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,6 +3,7 @@ use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Role\RolesController; use App\Http\Controllers\UploadController; +use App\Http\Controllers\Shop\ShopsController; /* |-------------------------------------------------------------------------- @@ -29,6 +30,7 @@ Route::middleware('auth:api')->group(function () { Route::resource('goods_skus', 'Goods\GoodsSkusController', ['only' => ['index', 'show', 'update', 'store']]); // 店铺 Route::resource('shops', 'Shop\ShopsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]); + Route::get('shop_platforms', [ShopsController::class, 'getPlatList'])->name('plat.list'); // 角色 Route::resource('roles', 'Role\RolesController', ['only' => ['index', 'store', 'show', 'update']]); Route::post('roles/{id}/permissions', [RolesController::class, 'addPermissions'])->name('role.permission'); From 2d59a6f9da9788bf34be9ae9d5defc604e5c7299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 2 Aug 2022 20:15:57 +0800 Subject: [PATCH 21/35] =?UTF-8?q?feat:=20#20220802=20=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=9F=A5=E7=9C=8B=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Goods/GoodsSkusController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index cf40820..ff4a3fa 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -32,7 +32,11 @@ class GoodsSkusController extends Controller public function show($id) { - return new GoodsSkuResource(GoodsSku::query()->with(['goods', 'brand'])->find($id)); + return new GoodsSkuResource(GoodsSku::query() + ->with(['goods' => function ($query) { + $query->with(['type:id,name', 'brand:id,name']); + }]) + ->find($id)); } public function update($id, Request $request) @@ -41,7 +45,7 @@ class GoodsSkusController extends Controller $this->validateUpdate($data); $sku = GoodsSku::query()->find($id); $this->setBeforeUpdate($sku->toArray()); - $sku->save($data); + $sku->update($data); $this->setAfterUpdate($sku->toArray()); $this->addLog($id, 'update'); From ada42eaae66641ea3d3d38a438dd4c71e4c20b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Wed, 3 Aug 2022 11:14:08 +0800 Subject: [PATCH 22/35] =?UTF-8?q?feat:=20#20220803=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Goods/GoodsController.php | 53 ++++++++++--------- .../Controllers/Goods/GoodsSkusController.php | 31 ++++++++--- routes/api.php | 2 + 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/app/Http/Controllers/Goods/GoodsController.php b/app/Http/Controllers/Goods/GoodsController.php index 4498091..b50aa0f 100644 --- a/app/Http/Controllers/Goods/GoodsController.php +++ b/app/Http/Controllers/Goods/GoodsController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Goods; use App\Http\Controllers\Controller; +use App\Http\Resources\GoodsResource; use App\Http\Resources\GoodsSkuResource; use App\Models\Log as LogModel; use Illuminate\Http\Request; @@ -25,39 +26,35 @@ class GoodsController extends Controller public function index(Request $request) { - $goods = Goods::query()->filter()->get()->toArray(); - $goodsIds = array_column($goods, 'id'); - // 状态变更时间查询,日志 - $day = date('Y-m-d'); //早上7点之前是昨天,7点之后是今天 - $goodsSkus = GoodsSku::query() - ->whereIn('goods_id', $goodsIds) - ->filter() - ->with(['goods' => function ($query) { - $query->with(['type:id,name', 'brand:id,name']); - }]) - ->with(['daily' => function ($query) use ($day){ - $query->where('day', $day)->with(['daily:id,sku_id,day,arrived_today_num,loss_num,inventory']); - }]) - ->paginate(); + $goods = Goods::query()->get(['id', 'title', 'img_url', 'type_id', 'brand_id', 'goods_code']); - return GoodsSkuResource::collection($goodsSkus); + return GoodsResource::collection($goods); } public function store(Request $request) { - $validator = Validator::make($request->all(), [ + $goodsRules = [ 'title' => ['required', 'string', 'max:255'], 'img_url' => ['required', 'string', 'max:255'], 'type_id' => ['required', 'integer', 'exists:goods_types,id'], 'brand_id' => ['integer', 'exists:goods_brands,id'], 'goods_code' => ['required', 'alpha_dash', 'max:32', 'unique:goods,goods_code'], + ]; + + if ($useGoods = !empty($request->goods_id)) { + $goodsRules = [ + 'goods_id' => ['required', 'integer', 'exists:goods,id'], + ]; + } + $skuRules = [ 'skus' => ['required', 'array'], 'skus.*.title' => ['required', 'string', 'max:255'], 'skus.*.sku_code' => ['required', 'distinct', 'alpha_dash', 'max:32'], 'skus.*.status' => ['required', 'integer', Rule::in([0, 1, 2])], - 'skus.*.num' => ['required', 'integer', 'max:10'], - 'skus.*.cost' => ['required', 'numeric', 'max:10'], - ]); + 'skus.*.num' => ['required', 'integer'], + 'skus.*.cost' => ['required', 'numeric'], + ]; + $validator = Validator::make($request->all(), array_merge($goodsRules, $skuRules)); if ($validator->fails()) { $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); @@ -65,13 +62,17 @@ class GoodsController extends Controller } DB::beginTransaction(); try { - $goods = new Goods(); - $goods->title = $request->title; - $goods->img_url = $request->img_url; - $goods->type_id = $request->type_id; - $goods->brand_id = $request->brand_id; - $goods->goods_code = $request->goods_code; - $goods->save(); + if ($useGoods) { + $goods = Goods::query()->find($request->goods_id); + } else { + $goods = new Goods(); + $goods->title = $request->title; + $goods->img_url = $request->img_url; + $goods->type_id = $request->type_id; + $goods->brand_id = $request->brand_id; + $goods->goods_code = $request->goods_code; + $goods->save(); + } $goodsSkus = []; foreach ($request->skus as $item) { $item['goods_id'] = $goods->id; diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index ff4a3fa..fa8af86 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Goods; use App\Http\Controllers\Controller; +use App\Models\Goods; use App\Models\Log as LogModel; use Illuminate\Http\Request; use App\Models\GoodsSku; @@ -27,7 +28,22 @@ class GoodsSkusController extends Controller public function index(Request $request) { - return new GoodsSkuResource(GoodsSku::query()->get(['id', 'title'])); + $goods = Goods::query()->filter()->get()->toArray(); + $goodsIds = array_column($goods, 'id'); + // 状态变更时间查询,日志 + $day = date('Y-m-d'); //早上7点之前是昨天,7点之后是今天 + $goodsSkus = GoodsSku::query() + ->whereIn('goods_id', $goodsIds) + ->filter() + ->with(['goods' => function ($query) { + $query->with(['type:id,name', 'brand:id,name']); + }]) + ->with(['daily' => function ($query) use ($day){ + $query->where('day', $day)->with(['daily:id,sku_id,day,arrived_today_num,loss_num,inventory']); + }]) + ->paginate(); + + return GoodsSkuResource::collection($goodsSkus); } public function show($id) @@ -55,11 +71,16 @@ class GoodsSkusController extends Controller public function batchUpdate(Request $request) { $appendRules = [ - '*.id' => [ + 'skus' => ['required', 'array'], + 'skus.*.id' => [ 'required', Rule::exists('goods_skus', 'id'), ], ]; + $data = $request->all(); + $this->validateUpdate($data, $appendRules); + GoodsSku::whereIn('id', array_column($data, 'id')) + ->update($data); } public function updateField($id, Request $request) @@ -138,12 +159,8 @@ class GoodsSkusController extends Controller Rule::in([0, 1, 2]) ], ]; +// $validator = Validator::make($data, array_merge($rules, $appendRules))->validate(); $validator = Validator::make($data, array_merge($rules, $appendRules)); - if ($validator->fails()) { - $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); - - return response($this->res, $this->res['httpCode']); - } } public function store(Request $request) diff --git a/routes/api.php b/routes/api.php index 7ae0b39..c6b756b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Role\RolesController; use App\Http\Controllers\UploadController; use App\Http\Controllers\Shop\ShopsController; +use App\Http\Controllers\Goods\GoodsSkusController; /* |-------------------------------------------------------------------------- @@ -28,6 +29,7 @@ Route::middleware('auth:api')->group(function () { Route::resource('goods', 'Goods\GoodsController', ['only' => ['index', 'store']]); // 商品规格 Route::resource('goods_skus', 'Goods\GoodsSkusController', ['only' => ['index', 'show', 'update', 'store']]); + Route::patch('batch/goods_skus', [GoodsSkusController::class, 'batchUpdate'])->name('goods_sku.batch_update'); // 店铺 Route::resource('shops', 'Shop\ShopsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]); Route::get('shop_platforms', [ShopsController::class, 'getPlatList'])->name('plat.list'); From 1ee5c5eb8571a76c2986fc8939d5e9b451ded581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Wed, 3 Aug 2022 16:41:15 +0800 Subject: [PATCH 23/35] =?UTF-8?q?feat:=20#20220803=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Goods/GoodsController.php | 36 ++++---------- .../Controllers/Goods/GoodsSkusController.php | 43 +++++++++++++---- app/Http/Requests/GoodsRequest.php | 47 ++++++++++++++++++ app/Http/Requests/GoodsSkuPost.php | 30 ------------ app/Http/Requests/GoodsSkuRequest.php | 48 +++++++++++++++++++ app/Models/Goods.php | 2 + 6 files changed, 140 insertions(+), 66 deletions(-) create mode 100644 app/Http/Requests/GoodsRequest.php delete mode 100644 app/Http/Requests/GoodsSkuPost.php create mode 100644 app/Http/Requests/GoodsSkuRequest.php diff --git a/app/Http/Controllers/Goods/GoodsController.php b/app/Http/Controllers/Goods/GoodsController.php index b50aa0f..9a114dd 100644 --- a/app/Http/Controllers/Goods/GoodsController.php +++ b/app/Http/Controllers/Goods/GoodsController.php @@ -3,15 +3,14 @@ namespace App\Http\Controllers\Goods; use App\Http\Controllers\Controller; +use App\Http\Requests\GoodsSkuRequest; use App\Http\Resources\GoodsResource; -use App\Http\Resources\GoodsSkuResource; use App\Models\Log as LogModel; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\Rule; use App\Models\Goods; -use App\Models\GoodsSku; +use App\Http\Requests\GoodsRequest; class GoodsController extends Controller { @@ -33,28 +32,9 @@ class GoodsController extends Controller public function store(Request $request) { - $goodsRules = [ - 'title' => ['required', 'string', 'max:255'], - 'img_url' => ['required', 'string', 'max:255'], - 'type_id' => ['required', 'integer', 'exists:goods_types,id'], - 'brand_id' => ['integer', 'exists:goods_brands,id'], - 'goods_code' => ['required', 'alpha_dash', 'max:32', 'unique:goods,goods_code'], - ]; - - if ($useGoods = !empty($request->goods_id)) { - $goodsRules = [ - 'goods_id' => ['required', 'integer', 'exists:goods,id'], - ]; - } - $skuRules = [ - 'skus' => ['required', 'array'], - 'skus.*.title' => ['required', 'string', 'max:255'], - 'skus.*.sku_code' => ['required', 'distinct', 'alpha_dash', 'max:32'], - 'skus.*.status' => ['required', 'integer', Rule::in([0, 1, 2])], - 'skus.*.num' => ['required', 'integer'], - 'skus.*.cost' => ['required', 'numeric'], - ]; - $validator = Validator::make($request->all(), array_merge($goodsRules, $skuRules)); + $goodsRules = (new GoodsRequest())->rules(); + $skuRules = (new GoodsSkuRequest())->arrayRules('skus.*.'); + $validator = Validator::make($request->all(), array_merge($goodsRules, ['skus' => ['required', 'array']], $skuRules)); if ($validator->fails()) { $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); @@ -62,8 +42,8 @@ class GoodsController extends Controller } DB::beginTransaction(); try { - if ($useGoods) { - $goods = Goods::query()->find($request->goods_id); + if (!empty($request->id)) { + $goods = Goods::query()->find($request->id); } else { $goods = new Goods(); $goods->title = $request->title; @@ -79,9 +59,9 @@ class GoodsController extends Controller $goodsSkus[] = $item; } $collection = $goods->skus()->createMany($goodsSkus); - DB::commit(); $this->setAfterUpdate($collection->toArray()); $this->addLog(0, 'add'); + DB::commit(); } catch (\Exception $exception) { DB::rollBack(); $this->res = [ diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index fa8af86..d3344c8 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -3,12 +3,15 @@ namespace App\Http\Controllers\Goods; use App\Http\Controllers\Controller; +use App\Http\Requests\GoodsRequest; +use App\Http\Requests\GoodsSkuRequest; use App\Models\Goods; use App\Models\Log as LogModel; use Illuminate\Http\Request; use App\Models\GoodsSku; use App\Http\Resources\GoodsSkuResource; use App\Imports\GoodsSkusImport; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; @@ -57,15 +60,39 @@ class GoodsSkusController extends Controller public function update($id, Request $request) { - $data = $request->all(); - $this->validateUpdate($data); - $sku = GoodsSku::query()->find($id); - $this->setBeforeUpdate($sku->toArray()); - $sku->update($data); - $this->setAfterUpdate($sku->toArray()); - $this->addLog($id, 'update'); + $goodsRules = (new GoodsRequest())->arrayRules('goods.'); + $skuRules = (new GoodsSkuRequest())->arrayRules('sku.'); + $validator = Validator::make($request->all(), array_merge($goodsRules, $skuRules)); + if ($validator->fails()) { + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); - return new GoodsSkuResource($sku); + return response($this->res, $this->res['httpCode']); + } + DB::beginTransaction(); + try { + // 商品规格更新 + $sku = GoodsSku::query()->find($id); + $this->setBeforeUpdate($sku->toArray()); + $sku->update($request->sku); + $this->setAfterUpdate($sku->toArray()); + $this->addLog($id, 'update'); + // 商品更新 + $goods = Goods::query()->find($sku->goods_id); + $this->setBeforeUpdate($goods->toArray()); + $goods->update($request->goods); + $this->setAfterUpdate($goods->toArray()); + $this->addLog($sku->goods_id, 'update', 'goods'); + DB::commit(); + } catch (\Exception $exception) { + DB::rollBack(); + $this->res = [ + 'httpCode' => 400, + 'errorCode' => 400416, + 'errorMessage' => $exception->getMessage(), + ]; + } + + return response($this->res, $this->res['httpCode']); } public function batchUpdate(Request $request) diff --git a/app/Http/Requests/GoodsRequest.php b/app/Http/Requests/GoodsRequest.php new file mode 100644 index 0000000..e0ecc5f --- /dev/null +++ b/app/Http/Requests/GoodsRequest.php @@ -0,0 +1,47 @@ + ['sometimes', 'required', 'integer', 'exists:goods,id'], + 'title' => ['required', 'string', 'max:255'], + 'img_url' => ['required', 'string', 'max:255'], + 'type_id' => ['required', 'integer', 'exists:goods_types,id'], + 'brand_id' => ['integer', 'exists:goods_brands,id'], + 'goods_code' => ['required', 'alpha_dash', 'max:32', Rule::unique('goods')->ignore(request('goods_id'))], + ]; + } + + public function arrayRules($arrayName) + { + $arrayRules = []; + $rules = $this->rules(); + foreach ($rules as $key => $val) { + $arrayRules[$arrayName . $key] = $val; + } + + return $arrayRules; + } +} diff --git a/app/Http/Requests/GoodsSkuPost.php b/app/Http/Requests/GoodsSkuPost.php deleted file mode 100644 index cabbf76..0000000 --- a/app/Http/Requests/GoodsSkuPost.php +++ /dev/null @@ -1,30 +0,0 @@ - ['sometimes', 'required', 'integer', 'exists:goods_skus,id'], + 'goods_id' => ['sometimes', 'required', 'integer', 'exists:goods,id'], + 'title' => ['required', 'string', 'max:255'], + 'sku_code' => ['required', 'distinct', 'alpha_dash', 'max:32'], + 'status' => ['required', 'integer', Rule::in([0, 1, 2])], + 'num' => ['required', 'integer'], + 'cost' => ['required', 'numeric'], + ]; + } + + public function arrayRules($arrayName) + { + $arrayRules = []; + $rules = $this->rules(); + foreach ($rules as $key => $val) { + $arrayRules[$arrayName . $key] = $val; + } + + return $arrayRules; + } +} diff --git a/app/Models/Goods.php b/app/Models/Goods.php index 3498be6..f9f9ff2 100644 --- a/app/Models/Goods.php +++ b/app/Models/Goods.php @@ -15,6 +15,8 @@ class Goods extends Model 'brand_id', ]; + protected $guarded = []; + /** * 多规格 */ From dc013d9ae5f9b8e604aaa1dc0d873977f4cf199e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Wed, 3 Aug 2022 20:28:42 +0800 Subject: [PATCH 24/35] =?UTF-8?q?feat:=20#20220803=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=A7=84=E6=A0=BC=E7=BC=96=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Goods/GoodsController.php | 20 +- .../Controllers/Goods/GoodsSkusController.php | 251 +++++++++++++----- app/Http/Requests/GoodsSkuRequest.php | 17 ++ app/Utils/FormatUtils.php | 21 +- .../2022_07_26_105818_create_logs_table.php | 1 + routes/api.php | 1 + 6 files changed, 232 insertions(+), 79 deletions(-) diff --git a/app/Http/Controllers/Goods/GoodsController.php b/app/Http/Controllers/Goods/GoodsController.php index 9a114dd..234752e 100644 --- a/app/Http/Controllers/Goods/GoodsController.php +++ b/app/Http/Controllers/Goods/GoodsController.php @@ -6,11 +6,13 @@ use App\Http\Controllers\Controller; use App\Http\Requests\GoodsSkuRequest; use App\Http\Resources\GoodsResource; use App\Models\Log as LogModel; +use App\Utils\FormatUtils; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; use App\Models\Goods; use App\Http\Requests\GoodsRequest; +use App\Models\DailyStockRecord; class GoodsController extends Controller { @@ -42,8 +44,8 @@ class GoodsController extends Controller } DB::beginTransaction(); try { - if (!empty($request->id)) { - $goods = Goods::query()->find($request->id); + if (!empty($request->goods_id)) { + $goods = Goods::query()->find($request->goods_id); } else { $goods = new Goods(); $goods->title = $request->title; @@ -56,11 +58,21 @@ class GoodsController extends Controller $goodsSkus = []; foreach ($request->skus as $item) { $item['goods_id'] = $goods->id; + $item['reference_price'] = $item['cost'] * 1.5; $goodsSkus[] = $item; } - $collection = $goods->skus()->createMany($goodsSkus); - $this->setAfterUpdate($collection->toArray()); + $collection = $goods->skus()->createMany($goodsSkus)->toArray(); + $this->setAfterUpdate($collection); $this->addLog(0, 'add'); + $newRecords = []; + foreach ($collection as $sku) { + $newRecords[] = [ + 'sku_id' => $sku['id'], + 'day' => FormatUtils::date(), + ]; + } + $record = new DailyStockRecord(); + $record->batchInsert($newRecords); DB::commit(); } catch (\Exception $exception) { DB::rollBack(); diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index d3344c8..1798db4 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -7,6 +7,7 @@ use App\Http\Requests\GoodsRequest; use App\Http\Requests\GoodsSkuRequest; use App\Models\Goods; use App\Models\Log as LogModel; +use App\Utils\FormatUtils; use Illuminate\Http\Request; use App\Models\GoodsSku; use App\Http\Resources\GoodsSkuResource; @@ -16,6 +17,7 @@ use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; use Maatwebsite\Excel\Facades\Excel; +use App\Models\DailyStockRecord; class GoodsSkusController extends Controller { @@ -34,14 +36,14 @@ class GoodsSkusController extends Controller $goods = Goods::query()->filter()->get()->toArray(); $goodsIds = array_column($goods, 'id'); // 状态变更时间查询,日志 - $day = date('Y-m-d'); //早上7点之前是昨天,7点之后是今天 + $day = FormatUtils::date(); $goodsSkus = GoodsSku::query() ->whereIn('goods_id', $goodsIds) ->filter() ->with(['goods' => function ($query) { $query->with(['type:id,name', 'brand:id,name']); }]) - ->with(['daily' => function ($query) use ($day){ + ->with(['daily' => function ($query) use ($day) { $query->where('day', $day)->with(['daily:id,sku_id,day,arrived_today_num,loss_num,inventory']); }]) ->paginate(); @@ -98,96 +100,199 @@ class GoodsSkusController extends Controller public function batchUpdate(Request $request) { $appendRules = [ + 'updateType' => ['required', 'string', Rule::in(['newest', 'inventory', 'stock'])], 'skus' => ['required', 'array'], 'skus.*.id' => [ 'required', Rule::exists('goods_skus', 'id'), ], ]; - $data = $request->all(); - $this->validateUpdate($data, $appendRules); - GoodsSku::whereIn('id', array_column($data, 'id')) - ->update($data); + $validator = $this->validateUpdate($request->all(), $appendRules); + if ($validator->fails()) { + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); + + return response($this->res, $this->res['httpCode']); + } + $function = $request->updateType; + + return $this->$function($request); + } + + private function newest($request) + { + DB::beginTransaction(); + try { + $logs = []; + foreach ($request->skus as $sku) { + $costLog = $arrivedLog = [ + 'module' => 'goods', + 'action' => $request->getMethod(), + 'target_type' => 'goods_sku', + 'target_id' => $sku['id'], + 'user_id' => $request->user()->id + ]; + // 成本 + $goodsSku = GoodsSku::query()->where('id', $sku['id'])->first(['id', 'cost']); + $costLog['target_field'] = 'cost'; + $costLog['before_update'] = $goodsSku->cost; + $goodsSku->cost = $sku['cost']; + $goodsSku->reference_price = $sku['cost'] * 1.5; + $goodsSku->save(); + $costLog['after_update'] = $goodsSku->cost; + $logs[] = $costLog; + // 今日到货 + $record = DailyStockRecord::query()->where('sku_id', $sku['id'])->where('day', FormatUtils::date())->first(['id', 'arrived_today_num']); + $arrivedLog['target_field'] = 'arrived_today_num'; + $arrivedLog['before_update'] = $record->arrived_today_num; + $record->arrived_today_num = $sku['arrived_today_num']; + $record->save(); + $arrivedLog['after_update'] = $record->arrived_today_num; + $logs[] = $arrivedLog; + } + $log = new LogModel(); + $log->batchInsert($logs); + DB::commit(); + } catch (\Exception $exception) { + DB::rollBack(); + $this->res = [ + 'httpCode' => 400, + 'errorCode' => 400500, + 'errorMessage' => $exception->getMessage(), + ]; + } + + return response($this->res, $this->res['httpCode']); + } + + private function inventory($request) + { + DB::beginTransaction(); + try { + $logs = []; + foreach ($request->skus as $sku) { + $inventoryLog = [ + 'module' => 'goods', + 'action' => $request->getMethod(), + 'target_type' => 'goods_sku', + 'target_id' => $sku['id'], + 'user_id' => $request->user()->id + ]; + // 今日到货 + $record = DailyStockRecord::query()->where('sku_id', $sku['id'])->where('day', FormatUtils::date())->first(['id', 'inventory']); + $inventoryLog['target_field'] = 'inventory'; + $inventoryLog['before_update'] = $record->inventory; + $record->inventory = $sku['inventory']; + $record->save(); + $inventoryLog['after_update'] = $record->inventory; + $logs[] = $inventoryLog; + } + $log = new LogModel(); + $log->batchInsert($logs); + DB::commit(); + } catch (\Exception $exception) { + DB::rollBack(); + $this->res = [ + 'httpCode' => 400, + 'errorCode' => 400500, + 'errorMessage' => $exception->getMessage(), + ]; + } + + return response($this->res, $this->res['httpCode']); + } + + private function stock($skus) + { + $update = reset($skus); + DB::beginTransaction(); + try { + $sku = GoodsSku::query()->where('id', $update['id'])->get(['id', 'two_days_ago_num', 'yesterday_num']); + $record = DailyStockRecord::query() + ->where('sku_id', $sku->id) + ->where('day', FormatUtils::date()) + ->first(); + $this->setBeforeUpdate([ + 'two_days_ago_num' => $sku->two_days_ago_num, + 'yesterday_num' => $sku->yesterday_num, + 'arrived_today_num' => $record->arrived_today_num, + ]); + $sku->two_days_ago_num = $update['two_days_ago_num']; + $sku->yesterday_num = $update['two_days_ago_num']; + $sku->save(); + $record->arrived_today_num = $update['arrived_today_num']; + $record->save(); + $this->setAfterUpdate([ + 'two_days_ago_num' => $sku->two_days_ago_num, + 'yesterday_num' => $sku->yesterday_num, + 'arrived_today_num' => $record->arrived_today_num, + ]); + $this->addLog($sku->id, 'stock'); + DB::commit(); + } catch (\Exception $exception) { + DB::rollBack(); + $this->res = [ + 'httpCode' => 400, + 'errorCode' => 400416, + 'errorMessage' => $exception->getMessage(), + ]; + } + + return response($this->res, $this->res['httpCode']); } public function updateField($id, Request $request) { - $appendRules = [ + $rules = [ 'updateField' => [ 'required', Rule::in(['reference_price', 'reserve', 'loss_num', 'status']) ], + 'reference_price' => [ + 'sometimes', + 'numeric', + 'gt:0' + ], + 'reserve' => [ + 'sometimes', + 'integer', + ], + 'loss_num' => [ + 'sometimes', + 'integer', + ], + 'inventory' => [ + 'sometimes', + 'integer', + ], + 'reason' => [ + 'sometimes', + 'required', + 'string' + ] ]; - if ($request->has('loss_num')) { - $appendRules['reason'] = ['required', 'string']; + $validator = Validator::make($request->all(), $rules); + if ($validator->fails()) { + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); + + return response($this->res, $this->res['httpCode']); } - $this->validateUpdate($request->all(), $appendRules); $updateField = \request('updateField'); - $sku = GoodsSku::query()->find($id); - $this->setBeforeUpdate($sku->$updateField); - $sku->$updateField = $request->$updateField; - $sku->save(); - $this->setAfterUpdate($sku->$updateField); + if ('loss_num' === $updateField) { + $model = DailyStockRecord::query() + ->where('sku_id', $id) + ->where('day', FormatUtils::date()) + ->first(['id', 'loss_num']); + $this->log->message = $request->input('reason', ''); + } else { + $model = GoodsSku::query()->find($id); + } + $this->setBeforeUpdate($model->$updateField); + $model->$updateField = $request->$updateField; + $model->save(); + $this->setAfterUpdate($model->$updateField); $this->addLog($id, $updateField); - return new GoodsSkuResource($sku); - } - - public function updateStock($id, Request $request) - { - $this->validateUpdate($request->all()); - $sku = GoodsSku::query()->where('id', $id)->get(['id', 'two_days_ago_num', 'yesterday_num']); - if ($sku->two_days_ago_num != \request('t wo_days_ago_num') || $sku->yesterday_num != \request('yesterday_num')) { - $this->setBeforeUpdate($sku->toArray()); - } - - } - - private function validateUpdate($data, $appendRules = []) - { - $rules = [ - '*.two_days_ago_num' => [ - 'sometimes', - 'integer', - ], - '*.yesterday_num' => [ - 'sometimes', - 'integer', - ], - '*.arrived_today_num' => [ - 'sometimes', - 'integer', - ], - '*.cost' => [ - 'sometimes', - 'numeric', - 'gt:0' - ], - '*.reference_price' => [ - 'sometimes', - 'numeric', - 'gt:0' - ], - '*.reserve' => [ - 'sometimes', - 'integer', - ], - '*.loss_num' => [ - 'sometimes', - 'integer', - ], - '*.inventory' => [ - 'sometimes', - 'integer', - ], - '*.status' => [ - 'sometimes', - 'integer', - Rule::in([0, 1, 2]) - ], - ]; -// $validator = Validator::make($data, array_merge($rules, $appendRules))->validate(); - $validator = Validator::make($data, array_merge($rules, $appendRules)); + return response($this->res, $this->res['httpCode']); } public function store(Request $request) diff --git a/app/Http/Requests/GoodsSkuRequest.php b/app/Http/Requests/GoodsSkuRequest.php index d6824e0..c403df0 100644 --- a/app/Http/Requests/GoodsSkuRequest.php +++ b/app/Http/Requests/GoodsSkuRequest.php @@ -32,6 +32,23 @@ class GoodsSkuRequest extends FormRequest 'status' => ['required', 'integer', Rule::in([0, 1, 2])], 'num' => ['required', 'integer'], 'cost' => ['required', 'numeric'], + 'reference_price' => [ + 'sometimes', + 'numeric', + 'gt:0' + ], + 'reserve' => [ + 'sometimes', + 'integer', + ], + 'loss_num' => [ + 'sometimes', + 'integer', + ], + 'inventory' => [ + 'sometimes', + 'integer', + ], ]; } diff --git a/app/Utils/FormatUtils.php b/app/Utils/FormatUtils.php index 667f332..a0a98d5 100644 --- a/app/Utils/FormatUtils.php +++ b/app/Utils/FormatUtils.php @@ -7,8 +7,11 @@ class FormatUtils /** * 格式化为树形结构 * @param $menus - * @param $parentId - * @param $juniorTitle //下级标题 + * @param $parentValue + * @param string $juniorTitle //下级标题 + * @param string $parentKey + * @param string $subKey + * @param string $useKey * @return array */ public static function formatTreeData($menus, $parentValue, $juniorTitle = 'children', $parentKey = 'parent_id', $subKey = 'id', $useKey = '') @@ -30,4 +33,18 @@ class FormatUtils } return $data; } + + /** + * 今天7点到明天7点算作今天 + */ + public static function date() + { + $time = time(); + $inventoryTime = strtotime(date('Y-m-d 07:00:00')); + if ($time < $inventoryTime) { + $time = strtotime('-1 day'); + } + + return date('Y-m-d', $time); + } } diff --git a/database/migrations/2022_07_26_105818_create_logs_table.php b/database/migrations/2022_07_26_105818_create_logs_table.php index 1ca6436..1530d0c 100644 --- a/database/migrations/2022_07_26_105818_create_logs_table.php +++ b/database/migrations/2022_07_26_105818_create_logs_table.php @@ -22,6 +22,7 @@ class CreateLogsTable extends Migration $table->string('target_field')->nullable()->comment('目标字段'); $table->text('before_update')->nullable()->comment('更新前数据'); $table->text('after_update')->nullable()->comment('更新后数据'); + $table->text('message')->nullable()->comment('备注信息'); $table->bigInteger('user_id')->comment('操作人id'); $table->timestamps(); }); diff --git a/routes/api.php b/routes/api.php index c6b756b..5c5adc8 100644 --- a/routes/api.php +++ b/routes/api.php @@ -30,6 +30,7 @@ Route::middleware('auth:api')->group(function () { // 商品规格 Route::resource('goods_skus', 'Goods\GoodsSkusController', ['only' => ['index', 'show', 'update', 'store']]); Route::patch('batch/goods_skus', [GoodsSkusController::class, 'batchUpdate'])->name('goods_sku.batch_update'); + Route::patch('single/goods_skus/{id}', [GoodsSkusController::class, 'updateField'])->name('goods_sku.single_update'); // 店铺 Route::resource('shops', 'Shop\ShopsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]); Route::get('shop_platforms', [ShopsController::class, 'getPlatList'])->name('plat.list'); From c45c004ad8545c54f2743cddb359f2e777b5ef48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Wed, 3 Aug 2022 20:41:04 +0800 Subject: [PATCH 25/35] =?UTF-8?q?feat:=20#20220803=20=E5=8D=95=E4=B8=AA?= =?UTF-8?q?=E5=95=86=E5=93=81=E4=BF=A1=E6=81=AF=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Goods/GoodsSkusController.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index 1798db4..d47c1cb 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -260,15 +260,16 @@ class GoodsSkusController extends Controller 'sometimes', 'integer', ], - 'inventory' => [ - 'sometimes', - 'integer', - ], 'reason' => [ 'sometimes', 'required', 'string' - ] + ], + 'status' => [ + 'sometimes', + 'required', + 'integer', + Rule::in([0, 1, 2])], ]; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { From 9553c73c427de976192a5ec90041c721eeb642db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Thu, 4 Aug 2022 13:21:45 +0800 Subject: [PATCH 26/35] =?UTF-8?q?feat:=20#20220804=207=E7=82=B9=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=9B=98=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/Inventory.php | 79 +++++++++++++++++++ .../Controllers/Goods/GoodsSkusController.php | 1 + app/Models/Log.php | 2 +- ...03559_create_daily_stock_records_table.php | 1 + .../2022_07_26_105818_create_logs_table.php | 1 + 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/Inventory.php diff --git a/app/Console/Commands/Inventory.php b/app/Console/Commands/Inventory.php new file mode 100644 index 0000000..59ad9f9 --- /dev/null +++ b/app/Console/Commands/Inventory.php @@ -0,0 +1,79 @@ +get(['id', 'stock', 'two_days_ago_num', 'yesterday_num']); + $data = []; + $date = date('Y-m-d'); + foreach ($skus as $sku) { + $data[] = [ + 'sku_id' => $sku->id, + 'day' => $date, + ]; + GoodsSku::where('id', $sku->id)->update([ + 'stock' => $sku->stock + $sku->two_days_ago_num + $sku->yesterday_num, + 'yesterday_num' => $sku->stock, + 'two_days_ago_num' => $sku->two_days_ago_num + $sku->yesterday_num, + ]); + } + $log = new Log(); + $log->module = 'goods'; + $log->action = 'PATCH'; + $log->target_type = 'goods_sku'; + $log->target_id = 0; + $log->target_field = 'timingInventory'; + $log->user_id = 1; + $record = new DailyStockRecord(); + $record->batchInsert($data); + $log->message = '成功'; + DB::commit(); + } catch (\Exception $exception) { + $log->message = '失败'; + DB::rollBack(); + } + $log->save(); + $this->info($log->message); + } +} diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index d47c1cb..f72f1a7 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -36,6 +36,7 @@ class GoodsSkusController extends Controller $goods = Goods::query()->filter()->get()->toArray(); $goodsIds = array_column($goods, 'id'); // 状态变更时间查询,日志 + $day = FormatUtils::date(); $goodsSkus = GoodsSku::query() ->whereIn('goods_id', $goodsIds) diff --git a/app/Models/Log.php b/app/Models/Log.php index 2b09204..75c1cd7 100644 --- a/app/Models/Log.php +++ b/app/Models/Log.php @@ -87,7 +87,7 @@ class Log extends Model public function setUserIdAttribute($value) { - $this->attributes['user_id'] = Auth::id(); + $this->attributes['user_id'] = Auth::id() ?: $value; } public function add($targetId = 0, $targetField = '') diff --git a/database/migrations/2022_07_26_103559_create_daily_stock_records_table.php b/database/migrations/2022_07_26_103559_create_daily_stock_records_table.php index 1c4706d..7d97f34 100644 --- a/database/migrations/2022_07_26_103559_create_daily_stock_records_table.php +++ b/database/migrations/2022_07_26_103559_create_daily_stock_records_table.php @@ -20,6 +20,7 @@ class CreateDailyStockRecordsTable extends Migration $table->unsignedInteger('arrived_today_num')->default(0)->comment('今日到货'); $table->unsignedInteger('loss_num')->default(0)->comment('损耗'); $table->unsignedInteger('inventory')->default(0)->comment('库存盘点'); + $table->unique('sku_id', 'day'); $table->timestamps(); }); } diff --git a/database/migrations/2022_07_26_105818_create_logs_table.php b/database/migrations/2022_07_26_105818_create_logs_table.php index 1530d0c..2a30d1c 100644 --- a/database/migrations/2022_07_26_105818_create_logs_table.php +++ b/database/migrations/2022_07_26_105818_create_logs_table.php @@ -24,6 +24,7 @@ class CreateLogsTable extends Migration $table->text('after_update')->nullable()->comment('更新后数据'); $table->text('message')->nullable()->comment('备注信息'); $table->bigInteger('user_id')->comment('操作人id'); + $table->index('target_type', 'target_id', 'target_field'); $table->timestamps(); }); } From 088c41cee9cb2c5a5d7e0e2a2ba81947294e8976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Thu, 4 Aug 2022 13:55:28 +0800 Subject: [PATCH 27/35] =?UTF-8?q?feat:=20#20220804=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E6=B5=8B=E8=AF=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Goods/GoodsSkusController.php | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index f72f1a7..044d95e 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\GoodsRequest; use App\Http\Requests\GoodsSkuRequest; use App\Models\Goods; +use App\Models\Log; use App\Models\Log as LogModel; use App\Utils\FormatUtils; use Illuminate\Http\Request; @@ -36,10 +37,20 @@ class GoodsSkusController extends Controller $goods = Goods::query()->filter()->get()->toArray(); $goodsIds = array_column($goods, 'id'); // 状态变更时间查询,日志 - + $ids = []; + if ($request->get('keyword_type', '') && $request->get('keyword_value', '')) { + $ids = Log::query()->where('target_type', 'sku') + ->where('target_field', $request->keyword_type) + ->whereBetween('created_at', explode(' - ', $request->keyword_value)) + ->pluck('sku_id') + ->toArray(); + } $day = FormatUtils::date(); $goodsSkus = GoodsSku::query() ->whereIn('goods_id', $goodsIds) + ->when($ids, function ($query, $ids) { + return $query->whereIn('id', $ids); + }) ->filter() ->with(['goods' => function ($query) { $query->with(['type:id,name', 'brand:id,name']); @@ -133,11 +144,13 @@ class GoodsSkusController extends Controller 'user_id' => $request->user()->id ]; // 成本 - $goodsSku = GoodsSku::query()->where('id', $sku['id'])->first(['id', 'cost']); + $goodsSku = GoodsSku::query()->where('id', $sku['id'])->first(['id', 'cost', 'stock', 'num']); $costLog['target_field'] = 'cost'; $costLog['before_update'] = $goodsSku->cost; $goodsSku->cost = $sku['cost']; $goodsSku->reference_price = $sku['cost'] * 1.5; + $goodsSku->stock += $sku['arrived_today_num']; + $goodsSku->num += $sku['arrived_today_num']; $goodsSku->save(); $costLog['after_update'] = $goodsSku->cost; $logs[] = $costLog; @@ -145,7 +158,7 @@ class GoodsSkusController extends Controller $record = DailyStockRecord::query()->where('sku_id', $sku['id'])->where('day', FormatUtils::date())->first(['id', 'arrived_today_num']); $arrivedLog['target_field'] = 'arrived_today_num'; $arrivedLog['before_update'] = $record->arrived_today_num; - $record->arrived_today_num = $sku['arrived_today_num']; + $record->arrived_today_num += $sku['arrived_today_num']; $record->save(); $arrivedLog['after_update'] = $record->arrived_today_num; $logs[] = $arrivedLog; @@ -207,7 +220,7 @@ class GoodsSkusController extends Controller $update = reset($skus); DB::beginTransaction(); try { - $sku = GoodsSku::query()->where('id', $update['id'])->get(['id', 'two_days_ago_num', 'yesterday_num']); + $sku = GoodsSku::query()->where('id', $update['id'])->get(['id', 'two_days_ago_num', 'yesterday_num', 'num', 'stock']); $record = DailyStockRecord::query() ->where('sku_id', $sku->id) ->where('day', FormatUtils::date()) @@ -215,10 +228,12 @@ class GoodsSkusController extends Controller $this->setBeforeUpdate([ 'two_days_ago_num' => $sku->two_days_ago_num, 'yesterday_num' => $sku->yesterday_num, + 'num' => $sku->num, 'arrived_today_num' => $record->arrived_today_num, ]); $sku->two_days_ago_num = $update['two_days_ago_num']; - $sku->yesterday_num = $update['two_days_ago_num']; + $sku->yesterday_num = $update['yesterday_num']; + $sku->num = $update['two_days_ago_num'] + $update['yesterday_num'] + $sku->stock; $sku->save(); $record->arrived_today_num = $update['arrived_today_num']; $record->save(); @@ -284,12 +299,21 @@ class GoodsSkusController extends Controller ->where('sku_id', $id) ->where('day', FormatUtils::date()) ->first(['id', 'loss_num']); - $this->log->message = $request->input('reason', ''); + $this->log->message = $request->get('reason'); + $this->setBeforeUpdate($model->loss_num); + $model->loss_num += $request->loss_num; } else { $model = GoodsSku::query()->find($id); + $this->setBeforeUpdate($model->$updateField); + if ('reserve' === $updateField) { + $changeNum = $model->reserve - $request->reserve; + $model->stock += $changeNum; + $model->reserve = $request->reserve; + $model->num += $changeNum; + } else { + $model->$updateField = $request->$updateField; + } } - $this->setBeforeUpdate($model->$updateField); - $model->$updateField = $request->$updateField; $model->save(); $this->setAfterUpdate($model->$updateField); $this->addLog($id, $updateField); From 2dc13086751143861460f057189d8df7cd0a716b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Thu, 4 Aug 2022 14:25:12 +0800 Subject: [PATCH 28/35] =?UTF-8?q?feat:=20#20220804=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exports/GoodsSkusExport.php | 75 +++++++++++++++++++ .../Controllers/Goods/GoodsSkusController.php | 8 ++ routes/web.php | 4 + 3 files changed, 87 insertions(+) create mode 100644 app/Exports/GoodsSkusExport.php diff --git a/app/Exports/GoodsSkusExport.php b/app/Exports/GoodsSkusExport.php new file mode 100644 index 0000000..d9316a8 --- /dev/null +++ b/app/Exports/GoodsSkusExport.php @@ -0,0 +1,75 @@ +type = $type; + $this->data = $this->createData(); + } + + /** + * @return \Illuminate\Support\Collection + */ + public function collection() + { + return new Collection($this->data); + } + + private function createData() + { + $headTitle = [ + '商品编码', + '商品名称', + '商品种类', + '商品品牌', + '规格编码', + '规格名称', + '成本', + '库存', + ]; + $inventoryTime = strtotime(date('Y-m-d 07:00:00')); + $ids = Log::query()->where('target_type', 'sku') + ->where('target_field', $this->type) + ->where('created_at', '>', $inventoryTime) + ->pluck('sku_id') + ->toArray(); + $data = GoodsSku::query() + ->when($ids, function ($query, $ids) { + return $query->whereIn('id', $ids); + }) + ->with(['goods' => function ($query) { + $query->with(['type:id,name', 'brand:id,name']); + }]) + ->get() + ->toArray(); + if (empty($data)) { + return [$headTitle]; + } + $bodyData = []; + foreach ($data as $item) { + $arr[0] = $item['goods']['goods_code']; + $arr[1] = $item['goods']['title']; + $arr[2] = $item['goods']['type']['name']; + $arr[3] = $item['goods']['brand']['name']; + $arr[4] = $item['goods']['sku_code']; + $arr[5] = $item['goods']['title']; + $arr[6] = $item['goods']['cost']; + $arr[7] = $item['goods']['stock']; + $bodyData[] = $arr; + } + unset($arr); + return [$headTitle, $bodyData]; + } +} diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index 044d95e..97053f1 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Goods; +use App\Exports\GoodsSkusExport; use App\Http\Controllers\Controller; use App\Http\Requests\GoodsRequest; use App\Http\Requests\GoodsSkuRequest; @@ -340,4 +341,11 @@ class GoodsSkusController extends Controller return response($this->res, $this->res['httpCode']); } + + public function export(Request $request) + { + $type = $request->get('exportType'); + ob_end_clean(); + return Excel::download(new GoodsSkusExport($type), $type, '.xlsx'); + } } diff --git a/routes/web.php b/routes/web.php index 4f8529e..0af6dd8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,7 @@ name('register'); + +Route::get('goods_skus/export', [GoodsSkusController::class, 'export'])->name('goods_skus.export'); From 6520d8bd6f5485cdd85e7270af61541d1f392a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Thu, 4 Aug 2022 18:13:00 +0800 Subject: [PATCH 29/35] =?UTF-8?q?feat:=20#20220804=20=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/UpdateSuperPermissions.php | 6 +- .../Controllers/Goods/GoodsSkusController.php | 1 - app/Http/Controllers/Menu/MenusController.php | 16 +- .../Permission/PermissionsController.php | 12 +- app/Http/Kernel.php | 1 + app/Http/Middleware/CheckPermissions.php | 38 +++ app/Models/User.php | 5 + config/filesystems.php | 4 + .../2022_07_26_105818_create_logs_table.php | 2 +- database/seeds/PermissionsTableSeeder.php | 18 +- resources/lang/zh-CN/permission.php | 234 ++++++++++++++++++ resources/templates/goods_skus_import.xlsx | Bin 0 -> 10134 bytes routes/api.php | 13 +- routes/web.php | 2 +- 14 files changed, 326 insertions(+), 26 deletions(-) create mode 100644 app/Http/Middleware/CheckPermissions.php create mode 100644 resources/lang/zh-CN/permission.php create mode 100644 resources/templates/goods_skus_import.xlsx diff --git a/app/Console/Commands/UpdateSuperPermissions.php b/app/Console/Commands/UpdateSuperPermissions.php index 637d6f8..c662b0b 100644 --- a/app/Console/Commands/UpdateSuperPermissions.php +++ b/app/Console/Commands/UpdateSuperPermissions.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Models\User; use Illuminate\Console\Command; use Spatie\Permission\Models\Permission; use Spatie\Permission\Models\Role; @@ -39,9 +40,12 @@ class UpdateSuperPermissions extends Command */ public function handle() { - $role = Role::query()->where('name', '超级管理员')->find(1); + $roleName = '超级管理员'; + $role = Role::query()->where('name', $roleName)->find(1); $permissions = Permission::query()->get(); $role->syncPermissions($permissions); + $user = User::query()->find(1); + $user->assignRole($role); $this->info('更新成功'); } } diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index 97053f1..e04ad52 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -25,7 +25,6 @@ class GoodsSkusController extends Controller { public function __construct(Request $request) { -// $this->middleware(['role:super-admin','permission:publish articles|edit articles']); $this->log = new LogModel([ 'module' => 'goods', 'action' => $request->getMethod(), diff --git a/app/Http/Controllers/Menu/MenusController.php b/app/Http/Controllers/Menu/MenusController.php index ee53406..dd50b68 100644 --- a/app/Http/Controllers/Menu/MenusController.php +++ b/app/Http/Controllers/Menu/MenusController.php @@ -6,6 +6,8 @@ use App\Http\Controllers\Controller; use App\Models\Log as LogModel; use App\Models\Menu; use App\Http\Resources\MenusResource; +use App\Models\User; +use App\Utils\ArrayUtils; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; @@ -22,10 +24,18 @@ class MenusController extends Controller ]); } - public function index() + public function index(Request $request) { - $menus = Menu::query()->get(); - $menus = FormatUtils::formatTreeData($menus, 0); + $permissions = $request->user()->getPermissionsViaRoles()->toArray(); + $permissions = array_column($permissions, 'name'); + $menus = Menu::query()->get()->toArray(); + $hasPermissionMenus = []; + foreach ($menus as $menu) { + if (in_array($menu['code'], $permissions, true)) { + $hasPermissionMenus[] = $menu; + } + } + $menus = FormatUtils::formatTreeData($hasPermissionMenus, 0); return MenusResource::collection($menus); } diff --git a/app/Http/Controllers/Permission/PermissionsController.php b/app/Http/Controllers/Permission/PermissionsController.php index 7507489..112f82b 100644 --- a/app/Http/Controllers/Permission/PermissionsController.php +++ b/app/Http/Controllers/Permission/PermissionsController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers\Permission; use App\Http\Controllers\Controller; use App\Models\Log as LogModel; +use App\Utils\ArrayUtils; +use App\Utils\FormatUtils; use Spatie\Permission\Models\Permission; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; @@ -23,9 +25,15 @@ class PermissionsController extends Controller public function index() { - $permissions = Permission::query()->get(); + $permissions = Permission::query()->get()->toArray(); + $permissions = ArrayUtils::index($permissions, 'name'); + $routes = include(resource_path('lang/zh-CN/permission.php')); + foreach ($routes as $key => &$route) { + $route['id'] = $permissions[$key]['id']; + } + $routes = FormatUtils::formatTreeData($routes, 0); - return PermissionsResource::collection($permissions); + return PermissionsResource::collection($routes); } public function store(Request $request) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index b1c73d6..cf52c70 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -63,6 +63,7 @@ class Kernel extends HttpKernel 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class, 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class, + 'check.permissions' => \App\Http\Middleware\CheckPermissions::class, ]; /** diff --git a/app/Http/Middleware/CheckPermissions.php b/app/Http/Middleware/CheckPermissions.php new file mode 100644 index 0000000..b8f8ae4 --- /dev/null +++ b/app/Http/Middleware/CheckPermissions.php @@ -0,0 +1,38 @@ +user()->getPermissionsViaRoles()->toArray(); + $permissions = array_column($permissions, 'name'); + if (in_array($currentRouteName, $permissions, true)) { + return $next($request); + } + } + + $res = [ + 'httpCode' => 403, + 'errorCode' => 403403, + 'errorMessage' => '您没有使用此功能的权限', + ]; + return response($res, 403); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index b6d8d5e..88194f2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -43,4 +43,9 @@ class User extends Authenticatable { $this->attributes['password'] = Hash::make($value); } + + public function isRoot() + { + return $this->name === 'erpAdmin'; + } } diff --git a/config/filesystems.php b/config/filesystems.php index 9df9941..b2f1d2f 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -76,6 +76,10 @@ return [ 'isCName' => false, // 是否使用自定义域名,true: 则Storage.url()会使用自定义的cdn或域名生成文件url, false: 则使用外部节点生成url 'debug' => true ], + 'root' => [ + 'driver' => 'local', + 'root' => '/' + ] ], ]; diff --git a/database/migrations/2022_07_26_105818_create_logs_table.php b/database/migrations/2022_07_26_105818_create_logs_table.php index 2a30d1c..da9c3c2 100644 --- a/database/migrations/2022_07_26_105818_create_logs_table.php +++ b/database/migrations/2022_07_26_105818_create_logs_table.php @@ -24,7 +24,7 @@ class CreateLogsTable extends Migration $table->text('after_update')->nullable()->comment('更新后数据'); $table->text('message')->nullable()->comment('备注信息'); $table->bigInteger('user_id')->comment('操作人id'); - $table->index('target_type', 'target_id', 'target_field'); + $table->index(['target_type', 'target_id', 'target_field']); $table->timestamps(); }); } diff --git a/database/seeds/PermissionsTableSeeder.php b/database/seeds/PermissionsTableSeeder.php index 0df8a79..c0aa0f7 100644 --- a/database/seeds/PermissionsTableSeeder.php +++ b/database/seeds/PermissionsTableSeeder.php @@ -12,17 +12,11 @@ class PermissionsTableSeeder extends Seeder */ public function run() { - DB::table('permissions')->insert([ - ['name' => 'GOODS_MANAGE', 'guard_name' => 'api'], - ['name' => 'GOODS_LIST', 'guard_name' => 'api'], - ['name' => 'GOODS_TYPE', 'guard_name' => 'api'], - ['name' => 'GOODS_BRAND', 'guard_name' => 'api'], - ['name' => 'SHOP_MANAGE', 'guard_name' => 'api'], - ['name' => 'USER_MANAGE', 'guard_name' => 'api'], - ['name' => 'SYSTEM_MANAGE', 'guard_name' => 'api'], - ['name' => 'ROLE_MANAGE', 'guard_name' => 'api'], - ['name' => 'PERMISSION_MANAGE', 'guard_name' => 'api'], - ['name' => 'SYSTEM_LOG', 'guard_name' => 'api'], - ]); + $routes = include(resource_path('lang/zh-CN/permission.php')); + $data = []; + foreach ($routes as $key => $route) { + $data[] = ['name' => $key, 'guard_name' => 'api']; + } + DB::table('permissions')->insert($data); } } diff --git a/resources/lang/zh-CN/permission.php b/resources/lang/zh-CN/permission.php new file mode 100644 index 0000000..7493111 --- /dev/null +++ b/resources/lang/zh-CN/permission.php @@ -0,0 +1,234 @@ + [ + 'id' => 1, + 'name' => '商品管理', + 'parent_id' => 0, + ], + 'GOODS_LIST' => [ + 'id' => 2, + 'name' => '商品列表', + 'parent_id' => 1, + ], + 'goods.index' => [ + 'id' => 20, + 'name' => '商品列表', + 'parent_id' => 2, + ], + 'goods.store' => [ + 'id' => 21, + 'name' => '新增商品', + 'parent_id' => 2, + ], + 'goods_skus.index' => [ + 'id' => 22, + 'name' => '规格列表', + 'parent_id' => 2, + ], + 'goods_skus.store' => [ + 'id' => 23, + 'name' => '新增规格', + 'parent_id' => 2, + ], + 'goods_skus.show' => [ + 'id' => 24, + 'name' => '规格查看', + 'parent_id' => 2, + ], + 'goods_skus.udpate' => [ + 'id' => 25, + 'name' => '规格更新', + 'parent_id' => 2, + ], + 'goods_sku.batch_update' => [ + 'id' => 26, + 'name' => '上新/盘点', + 'parent_id' => 2, + ], + 'goods_sku.single_update' => [ + 'id' => 27, + 'name' => '字段更新', + 'parent_id' => 2, + ], + 'GOODS_TYPE' => [ + 'id' => 3, + 'name' => '商品种类', + 'parent_id' => 1, + ], + 'goods_types.index' => [ + 'id' => 30, + 'name' => '列表', + 'parent_id' => 3, + ], + 'goods_types.store' => [ + 'id' => 31, + 'name' => '新增', + 'parent_id' => 3, + ], + 'goods_types.show' => [ + 'id' => 32, + 'name' => '查看', + 'parent_id' => 3, + ], + 'goods_types.update' => [ + 'id' => 33, + 'name' => '更新', + 'parent_id' => 3, + ], + 'goods_types.destroy' => [ + 'id' => 34, + 'name' => '删除', + 'parent_id' => 3, + ], + 'GOODS_BRAND' => [ + 'id' => 4, + 'name' => '商品品牌', + 'parent_id' => 1, + ], + 'goods_brands.index' => [ + 'id' => 40, + 'name' => '列表', + 'parent_id' => 4, + ], + 'goods_brands.store' => [ + 'id' => 41, + 'name' => '新增', + 'parent_id' => 4, + ], + 'goods_brands.show' => [ + 'id' => 42, + 'name' => '查看', + 'parent_id' => 4, + ], + 'goods_brands.update' => [ + 'id' => 43, + 'name' => '更新', + 'parent_id' => 4, + ], + 'goods_brands.destroy' => [ + 'id' => 44, + 'name' => '删除', + 'parent_id' => 4, + ], + // 店铺管理 + 'SHOP_MANAGE' => [ + 'id' => 5, + 'name' => '店铺管理', + 'parent_id' => 0, + ], + 'shops.index' => [ + 'id' => 50, + 'name' => '列表', + 'parent_id' => 5, + ], + 'shops.store' => [ + 'id' => 51, + 'name' => '新增', + 'parent_id' => 5, + ], + 'shops.show' => [ + 'id' => 52, + 'name' => '查看', + 'parent_id' => 5, + ], + 'shops.update' => [ + 'id' => 53, + 'name' => '更新', + 'parent_id' => 5, + ], + 'shops.destroy' => [ + 'id' => 54, + 'name' => '删除', + 'parent_id' => 5, + ], + // 用户管理 + 'USER_MANAGE' => [ + 'id' => 6, + 'name' => '用户管理', + 'parent_id' => 0, + ], + 'user.index' => [ + 'id' => 60, + 'name' => '列表', + 'parent_id' => 6, + ], + 'user.store' => [ + 'id' => 61, + 'name' => '新增', + 'parent_id' => 6, + ], + 'user.show' => [ + 'id' => 62, + 'name' => '查看', + 'parent_id' => 6, + ], + 'user.update' => [ + 'id' => 63, + 'name' => '更新', + 'parent_id' => 6, + ], + 'user.destroy' => [ + 'id' => 64, + 'name' => '删除', + 'parent_id' => 6, + ], + // 系统管理 + 'SYSTEM_MANAGE' => [ + 'id' => 7, + 'name' => '系统管理', + 'parent_id' => 0, + ], + 'ROLE_MANAGE' => [ + 'id' => 8, + 'name' => '角色管理', + 'parent_id' => 7, + ], + 'role.index' => [ + 'id' => 80, + 'name' => '列表', + 'parent_id' => 8, + ], + 'role.store' => [ + 'id' => 81, + 'name' => '新增', + 'parent_id' => 8, + ], + 'role.show' => [ + 'id' => 82, + 'name' => '查看', + 'parent_id' => 8, + ], + 'role.update' => [ + 'id' => 83, + 'name' => '更新', + 'parent_id' => 8, + ], + 'role.permission' => [ + 'id' => 84, + 'name' => '设置权限', + 'parent_id' => 8, + ], + 'PERMISSION_MANAGE' => [ + 'id' => 9, + 'name' => '权限管理', + 'parent_id' => 7, + ], + 'permissions.index' => [ + 'id' => 90, + 'name' => '列表', + 'parent_id' => 9, + ], + // 系统日志 + 'SYSTEM_LOG' => [ + 'id' => 10, + 'name' => '系统日志', + 'parent_id' => 0, + ], + 'logs.index' => [ + 'id' => 100, + 'name' => '列表', + 'parent_id' => 10, + ], +]; diff --git a/resources/templates/goods_skus_import.xlsx b/resources/templates/goods_skus_import.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..16d6c963a0bdbbd2c24f7e0173f6c6857bfe9ae4 GIT binary patch literal 10134 zcmeHtg;yNe_I2a#E(z{Vkl-FH5D38`1a~L6ySuxG-~@NK#$6f@1PP%D1h-!&Gw;g` zGv8nEURAG>Rdx2NzW3~V_c`Y($-}_n0^k9N004jjAja!IVFLvKz`_9lH~>UwZ3$Z& zCu18Yy*F-l#*VtIuGUuM`LNLRxd3R$`~Tbii(8=l&9F@mJ7&B3frw;>T3B94X(=LU z3#m5s9zv>Xyasi{4iWvW7oCZ+Y7JsHjk48*Htne(VZ}17rnu;5E7ohxSJdxNK15YG zd>6Wt$&vCeELV%Fjg8>WB}4;*;b-a*UN$Wouv$<)P}1OY*C9XK?LJZ57cUDHk)Ua3 z{89>iwfI$NxJMIOp5Z;A!E@Ju*DS+ + +++ ++ + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + +筛选 +重置筛选 ++ + ++ +++ + 全部商品(共800条) + ++ +++新建商品 +上新 +库存盘点 +导入商品 +表格导出 ++ ++ ++ {{ scope.row.date }} + ++ ++ ++ ++ ++ ++ + +++ + ++ + + +++ + ++ + + ++ ++ ++ ++ + +66+++ +损耗数量:++ + +备选项 +备选项 +备选项 ++ ++ ++ + ++ + +++修改 +++编辑 +++ + + +记录 +确定 ++ +i9249mqDRj@e;$*$3`lX&Cy1-$ zKSPD}Lp_vmFk3v2B)uvFp|57;i;-<4e@7>|hw$v-0S2J-H=5R~vQzzl_})v%QxphI z^&E_?9NAcZ9{)$r|6)%5<*%2=E4=DuM-2wc+=dKY%&o>^ip#r*$+S|u@%EKn!KjZa zpe9-Eq$9 ZAHRFWq@yiWCE=DTDK<^-!cF%nJ@X)wM}nxEEyg65jRWhK;{ zxXQPR;Oa)++=GOP44;MM;(aucP`;Ok(`k4^js~Vnm7YUZ6lYh&sw!rD=G6w-4*ZmE zdPY`Vr;-_+ICq{bikU;NDY>vOIVYqCX>!kewCcFNk7T*^@gnt>4IK~rN061QL1wIf zk_6QU+G7zykUDq(00Yu8u2yU=whopCwzif(=dp5CkWB$Qrk9@i1JqTPzh5kD(wk;X z>%vvl*{|}2Kqxv5sL|zOS=F<37gP%K^c0&``tR>z_=KN160%k~yO{_oQxLI<2eMfi zO;UbAVw$IDY0XL(GLn%B4>W4arEo9C) XHw}gPf7H z)9VH^w_B{H%uof@bdCvmUyV =ivy9(!>@8RydrYy@hXU&;n+%VJmA3 z9Pm+CujF(Ab#t-85o93z0Xl}otlbSmnQWRpoEdJxYV3PD%_{`v2gKlSYz6wUY86R< z_zT&(alecJ_!Oq(shbxq@C+mC)C)<#*f^|@`GE}Sfh8y^9Yuq1p>l6_N(_ixv!cH) z4-u1Y3lgyVEn_^Bk`lvxaw_gOdp_IASVruT>3~^duki5ZrIM?Qs5mBiBsKcb>+vwT zC^;hvVuT0*BrI0XiGBA7q$HC5k$#f>ILEAqfJ>Qj!$$J8U=_y)Vdq?0f3 qA7_xUDf#%+R-&TU$q5p9((ip9kyCket2vQY{iW`gWn=rnho6 z?fOm~@x`UssBF=+7dN+4s384n+E;?5`lnV1c=FL)Zx8Q`EpBYgysG%$tu`JJtpW{K z&t?~eswp=?m}weiXID-w6 6)R6gbKtjRGMB2 zWwL)-Qz{jpRw}Ddo-OT|(#4Trnr~3#EO|a@8mj64m9inGpE_c &0Pr&Q&;EB@* zZ#h+MB?1`t#o9b%uZcRUMnm`Z4#RW71&+bBzA*k(Gwdk-7U7m&golEOIZBM>S0N^8 z*m*W^VZ6uP&BbL{apWbm pd73BLMx(4Mwgxw{>84qj8iH-75^(zMAa2*4Pmg1TBk988p z7F~^bc{Ui^U^npCpz{Sc`W6h%SvONjI5w<1jult{&UWl{3 d+iI8Lk(cA!2d$SZwm)%n5h$n5gCJJujmfZ!{s5_)( z@=r^-g*=0u$U}yt$$S{%9e486T2;ZDPU1H}hEC84^T-dd$@cKz+&ZME|LHRKcHHm{ zFaSU&5&%F5dE?J<)6vY>*vXOY*NNlj0GgSg5VOpV84OOkCSzU?!+F;zFR7ubmFG}) z?dF_`RC6qCA%IeH-~(P1)d)jbrmw*PfuDi _Wx5_gYnv73h%>O{nXvaB!-m?XE*dfmdzaN`efW4vQxvFm-y(=g) zrm_z)RO=Jdo|=$qPE%>nD!#s=(Fd=$C3JlS=ZeC15yH{b2wGaY*l)szI8a~Lkz?QG z#A!;>lH}R0vq8;&4DRHg79Byr>sY!Yhy}5}E95i5moKo2X4`<9ryc;BU@?}9LpMl{ zxHeQ5UgqWJOlDe%t51D6^ou9<)EEiPmqZoTxVz!Xh>Wrj43>?$(`;|jj$lf_zp3R} z?m!!e|NQW)?|&T<6SZvu*fFIV{o4Sf2=uZ>v086Uh=!yTMAF}I6n#6gl!JBrfWhFi zmmRm`K{$D|cp 86HG|`4J+I!X6%wqkP=!wehYpUyC^7~gSNybdc^}a(5(xcgi zS_wzBuY+5%ai>7^@L%V)4)~T6YZ86+qj=^(S8<4MU6wEI%qiDCbCWsc5D#A?#Yda{ zfYFoTT){7+W#u+!p$I*G`0CbVQue%9w{3&B2)UM&+9!UD*^R^EV4qua!Yw$irOS#e z8#D4oKTG#V$0|izMC;2kV)}Zc2=_knu&OQI3rTO~$wDK#d*sV!{)8&$+kRC_{VUi4 z;#}c9=7NmUZ;vlXD=N%=I$FcMMq%O>{+;UzBEHOl5PjrJ{4?JF#dRk$V{2o!U&miG zKh&JC1@Yi^U@Sh6?;UA1&@7=J;5Jy%Stc}?t)L4{^H|s9NlFwZ5KH;#x)8DFk~kAp zgV1|@p+V*;cf2eOM=^_3G}=ZldGF$&S0@P(sSiA2$ksisFC`Xi1r S6Y{hBWue!wVo z0Cbt(iF^duyLP>V$aT!eFv5{HRs^O>wAsf8MTGPPrWE9wPq@0TP&3B!*X2qNZ@bO9 zEwL+HID_n~#>uysJo#s4ys< I7 asboiRc`06*4>TLe93A09-NQ=<~eQs5yI zinU NX(K}Y5SKeMR?tvFE`9eYoroe!x%p(L?lKl=H z#G`=ngG3;7+^gg?niPc8H1Ox}aZEKvm{QwNH}Prtq&xp&1Tw9eZwH=m7B()o!u)Gv zp=Z|oZMkc$b`N4>M+L_21ihA@giO8S4`0Q9y9d*FEVO!_iR)TC8**+IRxdj<+BNWc zK`(^G6du#0Rppo(S1e)nh6JfTW5sF>pF;;<8wQ4VBKDI#Cv68crEu63H2xWP{aNN| z&snAb%7A`FRr(w)q26(YGwR58s=}#|MFs6eL9?qJHPD%Dv99-Ce0#52^Qe{QXim|& z@_f(|diva2#w;t1niwB@>^+sy=6mYdp~^rhP)|P1YL!a;_!cd$sC5FK1}9(j HLMNS)vP@#MOrDpNAuG<* zOQ>M4oOP`~too%zw|F*}PNK$}M2>iDK4hpKHx6Z4R7ID;>>$%+r5dZtZ4s7*{|NQ` z+AfVb*SSgOfRaB1rZ#Nogy3E`(Kyb2N?LFnrc#nlJs=P z0XZTWOEb?9aPS3sybUeUgo!KVk2*^h&gm-_de2I{`47O`)$Zwd7K&B6?>| &LNEMq6yzDa>Yp RxLO~|c)i1VmO}(pIHR>Jw zHL93YH_Kw4Twfsac*AZ@g(R%g;OP`$ckmb?;(J{!*|U-yhYRBO6Ju3o8o%H_!eQIH zRu&3ne9J`m<~A6tswLK_ybmu{z=LS 3*|O=)=3_4eyB@cs4{CT13$zSp8noriwW>K;0icjrQBT|u?_eu#3d$f2}Y znULoJzbW#e3rQRqx>iy(z7(Fw59&L$*6AN#&nnjs8{oY!%xfb3;&xAz`=EQuT)#b_ z{F^|HsYi{+h6q$30sw&a$E4-x <7d*fCcL_MRXf;dxm#H&8Hyenv!$ zg@%iVUY*7^#@Uq4HIr7H(&ZJBRbNF|{lO*W9*IuFrxu%U{y9nkeVEsF%@g;@f`0+p z9G(j2z AY +rdZ?=2^_h*SH9@?pI<#q{KyQ?J#v9X6g^I aId z?<05u1NsMTu#Ll+qEHLb6D^tJ5trAR9?o~}Z!kQ{$o;=tTcVZc$vV3zu*a?u>&h3< z)Ve&Yp_|Z0CuU^IXQD4lUVV3&nKPgZcTc$6zM(CFEtW)BYK;7$L|e~VKJ>M?SfkVC z-V#V&p}`yT{Ap8EFSQnZmITZ 1vP9Fp(a l{Syo#*wMDNg+NmpcIR#G zxswezIjRqEnvRZVc7&hru35&Gw7O#VY}yS;jEO@D!3zWpPIqx BOkf9)3PTVZ$W9G z@@a1DZ)!B(=aqu4yIG;@9uh$Envg}v2BS(F9Y#tAOv*}#q{al-*0Q5{tn?B@n@*hF zIZtYzY|gTa@g=nCeB+#L6pw#*lS00tOS^I>{rn2TjekaWM%O()myjSI4MHB=KgnaJ z?_g}C;^bg%WBQ9j<*E~}aKs4PdG{aK$2D7L;G-B?NAki3V8RfhcE_A^Gn`BpvKZpD z
wovS6 z`7Fh@^Rpg_r=za(E31fRXB}lZjSZ1kUE-39wV$TZptPft1hJDSIc*TMDy>)TUY-se zwFtIz?Gn9T4`1~|iZO`|c+w1Ng2}GWF3C7v5j2S#$ga|PQzd2pDKHPEPOiqw;qE@6 zS#D|t_nY3AqcXo(GA$Q&w1J}$aOciI-mMi^db)m{v&D4W9_dgLl_SULD=fxT#5A!Y zw}k7E;Ik@BV8%+-LDV%_whwMr_LN=2#npTqR_`3+x YJz`EZ_Z&%SsZ^xSzB*O z8N+qB-3{NX``{?e`Z8HS0<5sc?%(a?-&@fUxcPY)ymL`GZdFEO_+pUx!%%YfkxY zh=+(nyoKryPx+ZN`ZEvkM;7UKHsDtdDKMrxyoViE>H_9o!qp>TJ_uDpg_p8Pbr;6q zdKn&+5_^Gr=TS>)+_ke~H?hN$aU=MV!~{K#dA0>QXxos$toqnvnWa;#=J~-2E)t7i zto{sZM>>q6qFmTutOg!RO^`D69bvC`-%?F9(#KfgFH5pvZtTNX5hRo4r54sFdI)uF ziuGXTZ7=lzexcWz_lMD5WP&yYo#Qem6M?dPvG0WQW%!1qzMc3Qh<$ZA&$jeJhb^`q z9XUOR Ht>t(vx87t+c`oXlH!bv oU(gj(Pi#}w; zpNfgz<@JqI`r*Mgs8Aa2`d{Lp_m3x!GBtAcuJqTrVS9x1<_)>&lYdE7fmXiVK)xUh zWkT=6yE*1TuMWo1Ob$BbPbg+lZCzjq&*v#4_n9ox`3#~ 6UiPUI2>3{6l%P%n0f zqzjnb6V3EWX>k_y4qi{a%6%};Ayn|wvUE<7vGfMxN=>mb4fd0H*|fCu6DLWW<27XF zE)Km#>0Z6;x(mg<;S_#u{uC(|@SmUP0HWQ+DOlIx6oEDpnU5}4*~r0{q?Y2;4)?)n zsp;4&r$Y)_1v>L^4~1G3+DDB1PUF;~9USP0U7=-C|8d$-#uxUJ)CMHh{bzS?`5joR zLAu)z67*w1a-~MLhDr{$c8+X@whqRBmcIX&B8Bk4Gaix(VJ8d%!>#9ScPPxX@JWFD zfR&_(inw6$6I&)8bJ={*TDP`Wf*%I;o?&W(cE!uKQ6I&Q%+my;w&b7-)aC6WIV>dc zZNIIep*c#a#@a9u@$8zHNNS15uj`-!29~}n_b>tF(H2_DMM0#IyD~tfw?$^=)>0fi zo=EX&U3`f+yG6;PEd_5k!oN#507!#2G3BdYvX9uI{V0nLb(ZNCFgh!YfG2+*3{6dM z$&Q40|6OZx`qnK^* o=ztLd#ZARO(O0}|gc)T1s-u~bZ>bwf7BI;+A z&vTivG9A!HllgC!ZA8}Ah4u8XS2E^Fm{V(18V}vjw>)QfpN2;-;+oZv3lfAiz?}ni zJ?;52a+#5byD&n$pQpxQ(U@`xyOpfpzweA*MBirZ?(CyK=~WS-<>sJGM0M{IB9}kz zZXD`>xZFRTkze-*RyyPfCPe6B{?!@v?d<;Nix4OLbIXkHhUk4rofGaFJ@_ap(}q4+ zR86^%$$haJAnUGf%#Y6~@83r}oNb))1pW}sc^Tx?^|YWas#p=EVoU9_wIKa^%M-L% z9+VpC0+*raknA_p!DXXTeRgoLjWdGHsLuHH39c1FSk}mAs+v$?QArpEDwGstHL75u zUD<`n5-y6RxYt*U^o3kDO;wBqo6}!!;7Lzr1VuhqOWDyR(&^g{!4GOifVo-Pk1nUj zEC>)a!Xq%tr;yF%uIBdk5~|p5+UDNDkwy6LCFg<*y0b>%$UYc+ObX&78j)Lq^%o)N z<1Vo=M=>^t&+penA@&-Lzf!amFkY&Vo7}`LSDm5{37o4(lO+SivIBj5yoGM>zCY~R zcFU4kcs;jyGWew+^BfJAl*bt!1_3D~kSPFvy3rz!vI9!+3Csm5%#m+xIh38N <`#=sBOPx1RdsbR_ScX@+u{F{oUUVzd@Eq8d7gwNXW zTR`imWIBoyv{xaS gsw~qlH2hYC&itv8{{0^lbn?4R5ew%I){bBkzkan zSW^B*KqY {$Z1pxk`3LcyPedPYD ec{s&i%>Nw6mE_?dJ_rDyLUvk+8*5Sjy!$`8Sa~J@ literal 0 HcmV?d00001 diff --git a/routes/api.php b/routes/api.php index 5c5adc8..4a047f0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -16,7 +16,7 @@ use App\Http\Controllers\Goods\GoodsSkusController; | is assigned the "api" middleware group. Enjoy building your API! | */ -Route::middleware('auth:api')->group(function () { +Route::middleware(['auth:api', 'check.permissions'])->group(function () { // 用户 Route::resource('users', 'User\UsersController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]); // 商品种类 @@ -33,17 +33,20 @@ Route::middleware('auth:api')->group(function () { Route::patch('single/goods_skus/{id}', [GoodsSkusController::class, 'updateField'])->name('goods_sku.single_update'); // 店铺 Route::resource('shops', 'Shop\ShopsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]); - Route::get('shop_platforms', [ShopsController::class, 'getPlatList'])->name('plat.list'); // 角色 Route::resource('roles', 'Role\RolesController', ['only' => ['index', 'store', 'show', 'update']]); Route::post('roles/{id}/permissions', [RolesController::class, 'addPermissions'])->name('role.permission'); // 权限 - Route::resource('permissions', 'Permission\PermissionsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]); - // 菜单 - Route::resource('menus', 'Menu\MenusController', ['only' => ['index', + Route::resource('permissions', 'Permission\PermissionsController', ['only' => ['index', // 'store', 'show', 'update', 'destroy' ]]); Route::post('upload', [UploadController::class, 'store'])->name('upload.file'); }); Route::post('/auth/login', [LoginController::class, 'login'])->name('auth.login'); + +// 菜单 +Route::resource('menus', 'Menu\MenusController', ['only' => ['index', +// 'store', 'show', 'update', 'destroy' +]])->middleware('auth:api'); +Route::get('shop_platforms', [ShopsController::class, 'getPlatList'])->name('plat.list')->middleware('auth:api'); diff --git a/routes/web.php b/routes/web.php index 0af6dd8..b342af8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -29,4 +29,4 @@ Route::get('/register', function () { return view('welcome'); })->name('register'); -Route::get('goods_skus/export', [GoodsSkusController::class, 'export'])->name('goods_skus.export'); +Route::get('goods_skus/export', [GoodsSkusController::class, 'export'])->name('goods_skus.export')->middleware('check.permissions'); From 7ada42695ac683ba75bfa944e2a79ee7a03dc42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Thu, 4 Aug 2022 18:20:59 +0800 Subject: [PATCH 30/35] =?UTF-8?q?feat:=20#20220804=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=AF=BC=E5=85=A5=E6=A8=A1=E6=9D=BF=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Goods/GoodsController.php | 6 ++++++ routes/web.php | 3 +++ 2 files changed, 9 insertions(+) diff --git a/app/Http/Controllers/Goods/GoodsController.php b/app/Http/Controllers/Goods/GoodsController.php index 234752e..1d25ed8 100644 --- a/app/Http/Controllers/Goods/GoodsController.php +++ b/app/Http/Controllers/Goods/GoodsController.php @@ -13,6 +13,7 @@ use Illuminate\Support\Facades\Validator; use App\Models\Goods; use App\Http\Requests\GoodsRequest; use App\Models\DailyStockRecord; +use Illuminate\Support\Facades\Storage; class GoodsController extends Controller { @@ -85,4 +86,9 @@ class GoodsController extends Controller return response($this->res, $this->res['httpCode']); } + + public function download() + { + return Storage::download(resource_path('templates/goods_skus_import.xlsx')); + } } diff --git a/routes/web.php b/routes/web.php index b342af8..20cc097 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ name('register'); Route::get('goods_skus/export', [GoodsSkusController::class, 'export'])->name('goods_skus.export')->middleware('check.permissions'); + +Route::get('goods/import/template', [GoodsController::class, 'download'])->name('download.goods_import.template'); From d586d31228caddb451b977c6a5000a5f2b60d5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Fri, 5 Aug 2022 10:36:55 +0800 Subject: [PATCH 31/35] =?UTF-8?q?feat:=20#20220805=20=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=9D=83=E9=99=90=E8=BF=94=E5=9B=9E=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Role/RolesController.php | 10 +++++++++- app/Http/Middleware/CheckPermissions.php | 2 +- app/Models/Shop.php | 2 ++ resources/lang/zh-CN/permission.php | 20 +++++++++---------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Role/RolesController.php b/app/Http/Controllers/Role/RolesController.php index 93ecc3d..2f861c2 100644 --- a/app/Http/Controllers/Role/RolesController.php +++ b/app/Http/Controllers/Role/RolesController.php @@ -24,7 +24,15 @@ class RolesController extends Controller public function index() { - $roles = Role::query()->get(); + $roles = Role::query()->with('permissions')->get()->toArray(); + $routes = include(resource_path('lang/zh-CN/permission.php')); + foreach ($roles as &$role) { + $permissions = []; + foreach ($role['permissions'] as $item) { + $permissions[] = $routes[$item['name']]['name']; + } + $role['permissions'] = $permissions; + } return RolesResource::collection($roles); } diff --git a/app/Http/Middleware/CheckPermissions.php b/app/Http/Middleware/CheckPermissions.php index b8f8ae4..0973abd 100644 --- a/app/Http/Middleware/CheckPermissions.php +++ b/app/Http/Middleware/CheckPermissions.php @@ -31,7 +31,7 @@ class CheckPermissions $res = [ 'httpCode' => 403, 'errorCode' => 403403, - 'errorMessage' => '您没有使用此功能的权限', + 'errorMessage' => '您没有使用此功能的权限' . $currentRouteName, ]; return response($res, 403); } diff --git a/app/Models/Shop.php b/app/Models/Shop.php index bd806c3..cee46e5 100644 --- a/app/Models/Shop.php +++ b/app/Models/Shop.php @@ -16,6 +16,8 @@ class Shop extends Model 'pop_auth_token_create_response', ]; + protected $guarded = []; + public function getStatusAttribute($value) { $map = [ diff --git a/resources/lang/zh-CN/permission.php b/resources/lang/zh-CN/permission.php index 7493111..7ac3875 100644 --- a/resources/lang/zh-CN/permission.php +++ b/resources/lang/zh-CN/permission.php @@ -149,27 +149,27 @@ return [ 'name' => '用户管理', 'parent_id' => 0, ], - 'user.index' => [ + 'users.index' => [ 'id' => 60, 'name' => '列表', 'parent_id' => 6, ], - 'user.store' => [ + 'users.store' => [ 'id' => 61, 'name' => '新增', 'parent_id' => 6, ], - 'user.show' => [ + 'users.show' => [ 'id' => 62, 'name' => '查看', 'parent_id' => 6, ], - 'user.update' => [ + 'users.update' => [ 'id' => 63, 'name' => '更新', 'parent_id' => 6, ], - 'user.destroy' => [ + 'users.destroy' => [ 'id' => 64, 'name' => '删除', 'parent_id' => 6, @@ -185,27 +185,27 @@ return [ 'name' => '角色管理', 'parent_id' => 7, ], - 'role.index' => [ + 'roles.index' => [ 'id' => 80, 'name' => '列表', 'parent_id' => 8, ], - 'role.store' => [ + 'roles.store' => [ 'id' => 81, 'name' => '新增', 'parent_id' => 8, ], - 'role.show' => [ + 'roles.show' => [ 'id' => 82, 'name' => '查看', 'parent_id' => 8, ], - 'role.update' => [ + 'roles.update' => [ 'id' => 83, 'name' => '更新', 'parent_id' => 8, ], - 'role.permission' => [ + 'roles.permission' => [ 'id' => 84, 'name' => '设置权限', 'parent_id' => 8, From b68d9626c0138ac40219d2fab6e5bcfae97c6d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Sat, 6 Aug 2022 15:25:13 +0800 Subject: [PATCH 32/35] =?UTF-8?q?feat:=20#20220806=20=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E6=8E=88=E6=9D=83,=E5=AF=B9=E6=8E=A5=E5=95=86=E5=9F=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Auth/LoginController.php | 4 +- app/Http/Controllers/Shop/ShopsController.php | 50 +++++++ app/Models/BusinessGoodsSku.php | 13 ++ app/Models/BusinessOrder.php | 13 ++ app/Models/BusinessOrderItem.php | 13 ++ app/Services/Business/BusinessClient.php | 88 +++++++++++ app/Services/Business/BusinessFactory.php | 25 ++++ app/Services/Business/KuaiTuanTuan/Goods.php | 63 ++++++++ .../Business/KuaiTuanTuan/KuaiTuanTuan.php | 137 ++++++++++++++++++ app/Services/Business/KuaiTuanTuan/Order.php | 70 +++++++++ app/Services/Business/MiaoXuan/Goods.php | 30 ++++ app/Services/Business/MiaoXuan/MiaoXuan.php | 49 +++++++ app/Services/Business/MiaoXuan/Order.php | 26 ++++ database/factories/UserFactory.php | 2 +- ...30834_create_business_goods_skus_table.php | 56 +++++++ ...05_093629_create_business_orders_table.php | 71 +++++++++ ...3658_create_business_order_items_table.php | 54 +++++++ routes/api.php | 5 +- routes/web.php | 3 + 19 files changed, 768 insertions(+), 4 deletions(-) create mode 100644 app/Models/BusinessGoodsSku.php create mode 100644 app/Models/BusinessOrder.php create mode 100644 app/Models/BusinessOrderItem.php create mode 100644 app/Services/Business/BusinessClient.php create mode 100644 app/Services/Business/BusinessFactory.php create mode 100644 app/Services/Business/KuaiTuanTuan/Goods.php create mode 100644 app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php create mode 100644 app/Services/Business/KuaiTuanTuan/Order.php create mode 100644 app/Services/Business/MiaoXuan/Goods.php create mode 100644 app/Services/Business/MiaoXuan/MiaoXuan.php create mode 100644 app/Services/Business/MiaoXuan/Order.php create mode 100644 database/migrations/2022_08_05_030834_create_business_goods_skus_table.php create mode 100644 database/migrations/2022_08_05_093629_create_business_orders_table.php create mode 100644 database/migrations/2022_08_05_093658_create_business_order_items_table.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index df2f808..ea52a85 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -52,8 +52,8 @@ class LoginController extends Controller if (Auth::attempt($credentials)) { // 通过认证.. return response()->json(['token' => $request->user()->api_token]); - }else { - return response()->json(['error' => 'auth login fail']); } + + return response()->json(['error' => 'auth login fail']); } } diff --git a/app/Http/Controllers/Shop/ShopsController.php b/app/Http/Controllers/Shop/ShopsController.php index f4fd384..5ec522d 100644 --- a/app/Http/Controllers/Shop/ShopsController.php +++ b/app/Http/Controllers/Shop/ShopsController.php @@ -7,12 +7,20 @@ use App\Models\Shop; use App\Http\Resources\ShopsResource; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; +use App\Services\Business\BusinessFactory; +use Illuminate\Validation\Rule; class ShopsController extends Controller { public function index() { $shops = Shop::query()->paginate(); + foreach ($shops as $shop) { + $shop->authUrl = ''; + if ('妙选' !== $shop->plat_id && '未授权' === $shop->status) { + $shop->authUrl = BusinessFactory::init()->make($shop->plat_id)->getAuthUrl($shop->id, $shop->getOriginal('plat_id')); + } + } return ShopsResource::collection($shops); } @@ -42,4 +50,46 @@ class ShopsController extends Controller return response($this->res, $this->res['httpCode']); } + + public function authBind(Request $request) + { + [$shopId, $platId] = explode('_', $request->get('state')); + $shop = new Shop(); + $platList = $shop->getPlatList(); + $shop = $shop->find($shopId); + if ($platList[$platId] === $shop->plat_id) { + BusinessFactory::init()->make($shop->plat_id)->authCallback($request->get('code'), $shop->id); + } else { + $this->res = [ + 'httpCode' => 403, + 'errorCode' => 403400, + 'errorMessage' => '信息不匹配', + ]; + } + + return response($this->res, $this->res['httpCode']); + } + + public function business(Request $request) + { + $validator = Validator::make($request->all(), [ + 'type' => ['required', 'string', Rule::in(['goods', 'orders'])], + 'erp_shop_id' => ['required', 'integer', 'exists:shops,id'], + ]); + if ($validator->fails()) { + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); + + return response($this->res, $this->res['httpCode']); + } + $shop = new Shop(); + $shop = $shop->find($request->get('erp_shop_id')); + $business = BusinessFactory::init()->make($shop->plat_id); + $business->setShop($shop); + if ('goods' === $request->get('type')) { + $business->downloadGoodsAndBind($request->get('data')); + } + if ('orders' === $request->get('type')) { + $business->downloadOrders(); + } + } } diff --git a/app/Models/BusinessGoodsSku.php b/app/Models/BusinessGoodsSku.php new file mode 100644 index 0000000..468332d --- /dev/null +++ b/app/Models/BusinessGoodsSku.php @@ -0,0 +1,13 @@ +setCode($code); + $this->setShop($shopId); + $this->auth(); + + return $this; + } + + public function setShopWithId($shopId) + { + $this->shop = Shop::query()->find($shopId); + + return $this; + } + + public function setShop(Shop $shop) + { + $this->shop = $shop; + + return $this; + } + + public function getShop() + { + return $this->shop; + } + + protected function setCode($code) + { + $this->code = $code; + + return $this; + } + + protected function getCode() + { + return $this->code; + } + + public function formDataPostRequest($url, $params) + { + $headers = [ + 'headers' => ['Content-type' => 'multipart/form-data;charset=UTF-8'], + 'form_params' => $params + ]; + $res = (new Client())->makeCurlRequest('POST', $url, $headers); + $res = json_decode($res->getBody()->getContents(), true); + if (isset($res['error_response'])) { + $log = new Log(); + $log->module = 'plat'; + $log->action = 'POST'; + $log->target_type = 'kuaituantuan'; + $log->target_id = 0; + $log->target_field = '更新库存'; + $log->user_id = 1; + $log->message = json_encode($res, 256); + $log->save(); + + throw new \Exception($res['error_response']['error_msg'], $res['error_response']['error_code']); + } + + return $res; + } +} diff --git a/app/Services/Business/BusinessFactory.php b/app/Services/Business/BusinessFactory.php new file mode 100644 index 0000000..b34277c --- /dev/null +++ b/app/Services/Business/BusinessFactory.php @@ -0,0 +1,25 @@ +platList['快团团'] = KuaiTuanTuan::class; + } + + public function make($platName) + { + return new $this->platList[$platName]; + } + + public static function init() + { + return new self(); + } +} diff --git a/app/Services/Business/KuaiTuanTuan/Goods.php b/app/Services/Business/KuaiTuanTuan/Goods.php new file mode 100644 index 0000000..7f4e540 --- /dev/null +++ b/app/Services/Business/KuaiTuanTuan/Goods.php @@ -0,0 +1,63 @@ + $activityNo, // 非必填,团号(团号和创建时间只能传一个) + 'page' => $page, + 'size' => $size, +// 'update_time_end' => '', // 非必填,结束最后更新时间(毫秒级时间戳) +// 'update_time_start' => '', // 非必填,起始最后更新时间(毫秒级时间戳) +// 'create_time_end' => '', // 非必填,开始时间结束(毫秒级时间戳) +// 'create_time_start' => '' // 非必填, 开始时间起始(毫秒级时间戳) + ]; + + return [$type, $appendParams]; + } + + public static function bindGoods(array $goodsList, $shopId) + { + foreach ($goodsList as $businessGood) { + $skuList = $businessGood['sku_list']; + unset($businessGood['sku_list']); + foreach ($skuList as $sku) { + $sku['spec_list'] = json_encode($sku['spec_list'], 256); + $data = array_merge($businessGood, $sku); + BusinessGoodsSku::updateOrCreate( + ['shop_id' => $shopId, 'activity_no' => $businessGood['activity_no'], 'goods_id' => $businessGood['goods_id'], 'sku_id' => $sku['sku_id']], + $data + ); + } + } + } + + public function downloadSingle($goodsId) + { + $type = 'pdd.ktt.goods.query.single'; + $appendParams = [ + 'goods_id' => $goodsId + ]; + } + + public static function incrQuantity($goodsId, $quantity, $skuId, $modifyType = 2) + { + $type = 'pdd.ktt.goods.incr.quantity'; + $appendParams = [ + 'goods_id' => $goodsId, + 'quantity_delta' => $quantity, + 'sku_id' => $skuId, + // 非必填 + 'modify_quantity_type' => $modifyType, // 修改库存的类型,不传或1代表增量修改,2代表全量修改 + ]; + + return [$type, $appendParams]; + } +} + diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php new file mode 100644 index 0000000..60dd313 --- /dev/null +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -0,0 +1,137 @@ + '', + 'client_id' => '', + 'access_token' => '', // 非必填,通过code获取的access_token + 'timestamp' => '', + 'data_type' => '', // 非必填,响应格式,即返回数据的格式,JSON或者XML(二选一),默认JSON,注意是大写 + 'version' => '', // 非必填, API协议版本号,默认为V1,可不填 + 'sign' => '' + ]; + + public function __construct() + { + } + + public function getAuthUrl($shopId, $platId) + { + $state = $shopId . '_' . $platId; + + return "https://oauth.pinduoduo.com/authorize/ktt?client_id={$this->clientId}&redirect_uri={$this->redirectUri}&state={$state}"; + } + + public function auth() + { + $accessToken = $this->getAccessTokenWithCode(); + $accessToken['pop_auth_token_create_response'] = json_encode($accessToken, 256); + $this->shop->update($accessToken); + + return $this->shop; + } + + public function getAccessTokenWithCode() + { + $type = 'pdd.pop.auth.token.create'; + $res = $this->request($type, ['code' => $this->code]); + + return $res['pop_auth_token_create_response']; + } + + public function getAccessToken() + { + return ''; + } + + public function getSign($params) + { + $params = ksort($params); + $str = ''; + foreach ($params as $key => $val) { + $str .= $key . $val; + } + $str = $this->clientSecret . $str . $this->clientSecret; + + return strtoupper(md5($str)); + } + + public function request($type, $appendParams = [], $url = 'http://gw-api.pinduoduo.com/api/router') + { + $publicParams = [ + 'type' => $type, + 'client_id' => $this->clientId, + 'timestamp' => time() + ]; + if ('pdd.pop.auth.token.create' !== $type) { + $publicParams['access_token'] = $this->getAccessToken(); + } + $publicParams = array_merge($publicParams, $appendParams); + $publicParams['sign'] = $this->getSign($publicParams); + + return $this->formDataPostRequest($url, $publicParams); + } + + public function downloadGoodsAndBind($page = 1) + { + [$type, $appendParams] = Goods::downloadGoods($this->shop->owner_name, $page); + $res = $this->formDataPostRequest($type, $appendParams); + $goods = $res['ktt_goods_query_list_response']['goods_list']; + Goods::bindGoods($goods, $this->shop->id); + $pageNum = ceil($res['total'] / $appendParams['size']); + if ($pageNum > $page && 10 >= $page) { + $this->downloadGoodsAndBind($page + 1); + } + } + + public function incrQuantity($skuId) + { + $goodsSku = GoodsSku::query()->find($skuId); + $business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id']); + [$type, $appendParams] = Goods::incrQuantity($business->goodsId, $goodsSku->stock, $business->sku_id); + $this->formDataPostRequest($type, $appendParams); + $log = new Log(); + $log->module = 'plat'; + $log->action = 'POST'; + $log->target_type = 'kuaituantuan'; + $log->target_id = 0; + $log->target_field = $type; + $log->user_id = 1; + $log->message = 'success'; + $log->save(); + } + + public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default') + { + if ('increment' === $downloadType) { + [$type, $appendParams] = Order::downloadIncrementOrders($beginTime, $endTime, $activityNo); + } else { + [$type, $appendParams] = Order::downloadOrders($beginTime, $endTime, $activityNo); + } + $res = $this->formDataPostRequest($type, $appendParams); + + + return $res['ktt_order_list_response']['order_list']; + } + + public function bindGoods($goods) + { + // TODO: Implement bindGoods() method. + } +} diff --git a/app/Services/Business/KuaiTuanTuan/Order.php b/app/Services/Business/KuaiTuanTuan/Order.php new file mode 100644 index 0000000..fed5f51 --- /dev/null +++ b/app/Services/Business/KuaiTuanTuan/Order.php @@ -0,0 +1,70 @@ + $beginTime, // 成交启始时间, 必填,毫秒时间戳 + 'confirm_at_end' => $endTime, // 成交结束时间,必填, 毫秒时间戳,成交结束时间 - 成交启始时间 <= 24h + 'page_number' => 1, // 页码, 必填 + 'page_size' => 100, // 数量, 必填, 1~100 + // 非必填 + 'activity_no' => $activityNo, // 团号 + 'after_sales_status' => 0, // 售后状态, 可选 0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭 + 'cancel_status' => 0, // 取消状态, 可选 0-未取消 1-已取消 +// 'shipping_status' => '', // 发货状态 0-未发货 1-已发货 2-部分发货 3-已收货 +// 'verification_status' => '', // 核销状态, 可选 0-未核销 1-已核销 2-部分核销 + ]; + + return [$type, $appendParams]; + } + + /** + * 快团团增量查订单 + */ + public static function downloadIncrementOrders($beginTime, $endTime, $activityNo) + { + $type = 'pdd.ktt.increment.order.query'; + $appendParams = [ + 'start_updated_at' => $beginTime, // 更新起始时间 + 'end_updated_at' => $endTime, // 更新结束时间 + 'page_number' => 1, // 页码 + 'page_size' => 100, // 数量 + // 非必填 + 'activity_no' => $activityNo, // 团号 + 'after_sales_status' => 0, // 售后状态, 可选 0-未发起售后 1-退款中 2-退款成功 3-待处理 4-拒绝退款 6-待(顾客)退货 7-待(团长)确认退货 8-(顾客)撤销 9-(系统)关闭 + 'cancel_status' => 0, // 取消状态, 可选 0-未取消 1-已取消 +// 'shipping_status' => '', // 发货状态 0-未发货 1-已发货 2-部分发货 3-已收货 +// 'verification_status' => '', // 核销状态, 可选 0-未核销 1-已核销 2-部分核销 + ]; + + return [$type, $appendParams]; + } + + // 下载订单事件之后去统计 然后更新库存 + public static function saveOrders(array $orders, $shopId) + { + foreach ($orders as $order) { + $orderRecord = BusinessOrder::updateOrCreate( + ['shop_id' => $shopId, 'order_sn' => $order['order_sn']], + $order + ); + foreach ($order['sub_order_list'] as $item) { + $orderRecord = BusinessOrder::updateOrCreate( + ['shop_id' => $shopId, 'business_order_id' => $orderRecord->id, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']], + $item + ); + } + } + } +} + diff --git a/app/Services/Business/MiaoXuan/Goods.php b/app/Services/Business/MiaoXuan/Goods.php new file mode 100644 index 0000000..06ceddf --- /dev/null +++ b/app/Services/Business/MiaoXuan/Goods.php @@ -0,0 +1,30 @@ + $shopId, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']], + $item + ); + } + } + + public static function incrQuantity($shopId, $quantity, $businessGoods) + { + return [ + 'stock' => $quantity, + 'business_sku_id' => $businessGoods['sku_id'], + 'business_goods_id' => $businessGoods['goods_id'], + 'erp_shop_id' => $shopId, + 'erp_sku_id' => $businessGoods['external_sku_id'] + ]; + } +} + diff --git a/app/Services/Business/MiaoXuan/MiaoXuan.php b/app/Services/Business/MiaoXuan/MiaoXuan.php new file mode 100644 index 0000000..041d2de --- /dev/null +++ b/app/Services/Business/MiaoXuan/MiaoXuan.php @@ -0,0 +1,49 @@ +find($skuId); + $business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id', 'external_sku_id'])->toArray(); + $appendParams = Goods::incrQuantity($this->shop->id, $goodsSku->stock, $business); + + $this->formDataPostRequest($type, $appendParams); + $log = new Log(); + $log->module = 'plat'; + $log->action = 'POST'; + $log->target_type = 'miaoxuan'; + $log->target_id = 0; + $log->target_field = '更新库存'; + $log->user_id = 1; + $log->message = 'success'; + $log->save(); + } + + public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default') + { + Order::saveOrders($beginTime, $endTime, $activityNo); + } + + public function bindGoods($goods) + { + Goods::bindGoods($goods, $this->shop->id); + } +} diff --git a/app/Services/Business/MiaoXuan/Order.php b/app/Services/Business/MiaoXuan/Order.php new file mode 100644 index 0000000..c8489a4 --- /dev/null +++ b/app/Services/Business/MiaoXuan/Order.php @@ -0,0 +1,26 @@ + $shopId, 'order_sn' => $order['order_sn']], + $order + ); + foreach ($order['sub_order_list'] as $item) { + $orderRecord = BusinessOrder::updateOrCreate( + ['shop_id' => $shopId, 'business_order_id' => $orderRecord->id, 'goods_id' => $item['goods_id'], 'sku_id' => $item['sku_id']], + $item + ); + } + } + } +} + diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index fa3372e..cb1446a 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -22,7 +22,7 @@ $factory->define(User::class, function (Faker $faker) { 'name' => 'erpAdmin', 'email' => $faker->unique()->safeEmail, 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'password' => 'password', // password 'api_token' => Str::random(60), 'remember_token' => Str::random(10), ]; diff --git a/database/migrations/2022_08_05_030834_create_business_goods_skus_table.php b/database/migrations/2022_08_05_030834_create_business_goods_skus_table.php new file mode 100644 index 0000000..8dce10b --- /dev/null +++ b/database/migrations/2022_08_05_030834_create_business_goods_skus_table.php @@ -0,0 +1,56 @@ +bigIncrements('id'); + $table->bigInteger('shop_id'); + $table->bigInteger('self_sku_id')->nullable(); + $table->string('activity_no')->nullable(); + $table->string('category_name')->nullable(); + $table->mediumInteger('create_time')->nullable(); + $table->text('goods_desc')->nullable(); + $table->string('goods_id')->nullable(); + $table->text('goods_image_list')->nullable(); + $table->string('goods_name')->nullable(); + $table->integer('is_activity_delete')->nullable(); + $table->integer('limit_buy')->nullable(); + $table->mediumInteger('market_price')->nullable(); + $table->mediumInteger('update_time')->nullable(); + $table->string('external_sku_id')->nullable(); + $table->mediumInteger('goods_purchase_price')->nullable(); + $table->mediumInteger('price_in_fen')->nullable(); + $table->mediumInteger('quantity')->nullable(); + $table->integer('quantity_type')->nullable(); + $table->mediumInteger('reserve_quantity')->nullable(); + $table->mediumInteger('sku_id')->nullable(); + $table->mediumInteger('sold_quantity')->nullable(); + $table->text('spec_list')->nullable(); + $table->string('spec_name')->nullable(); + $table->string('thumb_url')->nullable(); + $table->mediumInteger('total_quantity')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('business_goods'); + } +} diff --git a/database/migrations/2022_08_05_093629_create_business_orders_table.php b/database/migrations/2022_08_05_093629_create_business_orders_table.php new file mode 100644 index 0000000..b5b0311 --- /dev/null +++ b/database/migrations/2022_08_05_093629_create_business_orders_table.php @@ -0,0 +1,71 @@ +bigIncrements('id'); + $table->integer('shop_id'); + $table->bigInteger('activity_no')->nullable(); + $table->string('activity_title')->nullable(); + $table->mediumInteger('after_sales_status')->nullable(); + $table->string('business_note')->nullable(); + $table->string('buyer_memo')->nullable(); + $table->integer('cancel_status')->nullable(); + $table->mediumInteger('confirm_at')->nullable(); + $table->mediumInteger('discount_amount')->nullable(); + $table->string('help_sell_nickname')->nullable(); + $table->string('inner_transaction_id')->nullable(); + $table->boolean('is_supplier')->nullable(); + $table->integer('logistics_type')->nullable(); + $table->integer('mall_activity_type')->nullable(); + $table->string('nick_name')->nullable(); + $table->mediumInteger('order_amount')->nullable(); + $table->string('order_sn')->nullable(); + $table->integer('participate_no')->nullable(); + $table->mediumInteger('platform_discount_amount')->nullable(); + $table->string('receiver_address_city')->nullable(); + $table->string('receiver_address_detail')->nullable(); + $table->string('receiver_address_district')->nullable(); + $table->string('receiver_address_province')->nullable(); + $table->string('receiver_mobile')->nullable(); + $table->string('receiver_name')->nullable(); + $table->string('secret_remark')->nullable(); + $table->string('self_pick_site_no')->nullable(); + $table->string('self_pick_up_address')->nullable(); + $table->string('self_pick_up_contact_mobile')->nullable(); + $table->string('self_pick_up_contact_name')->nullable(); + $table->string('self_pick_up_site_name')->nullable(); + $table->mediumInteger('service_amount')->nullable(); + $table->mediumInteger('shipping_amount')->nullable(); + $table->integer('shipping_status')->nullable(); + $table->string('supply_activity_no')->nullable(); + $table->integer('supply_participate_no')->nullable(); + $table->mediumInteger('theoretical_refund_amount')->nullable(); + $table->string('transaction_id')->nullable(); + $table->mediumInteger('updated_at')->nullable(); + $table->integer('verification_status')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('business_orders'); + } +} diff --git a/database/migrations/2022_08_05_093658_create_business_order_items_table.php b/database/migrations/2022_08_05_093658_create_business_order_items_table.php new file mode 100644 index 0000000..325103c --- /dev/null +++ b/database/migrations/2022_08_05_093658_create_business_order_items_table.php @@ -0,0 +1,54 @@ +bigIncrements('id'); + $table->bigInteger('shop_id'); + $table->bigInteger('business_order_id'); + $table->integer('already_cancel_number')->nullable(); + $table->integer('cancel_status')->nullable(); + $table->string('category_name')->nullable(); + $table->string('external_sku_id')->nullable(); + $table->mediumInteger('goods_amount')->nullable(); + $table->mediumInteger('goods_cost_price')->nullable(); + $table->mediumInteger('goods_id')->nullable(); + $table->string('goods_name')->nullable(); + $table->integer('goods_number')->nullable(); + $table->mediumInteger('goods_price')->nullable(); + $table->mediumInteger('goods_purchase_price')->nullable(); + $table->string('goods_specification')->nullable(); + $table->mediumInteger('help_sell_amount')->nullable(); + $table->boolean('is_supplier')->nullable(); + $table->integer('need_verification_number')->nullable(); + $table->integer('shipping_status')->nullable(); + $table->mediumInteger('sku_id')->nullable(); + $table->string('sub_order_sn')->nullable(); + $table->mediumInteger('theoretically_refund_amount')->nullable(); + $table->string('thumb_url')->nullable(); + $table->integer('verification_number')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('business_order_items'); + } +} diff --git a/routes/api.php b/routes/api.php index 4a047f0..b322c4f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -35,7 +35,7 @@ Route::middleware(['auth:api', 'check.permissions'])->group(function () { Route::resource('shops', 'Shop\ShopsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]); // 角色 Route::resource('roles', 'Role\RolesController', ['only' => ['index', 'store', 'show', 'update']]); - Route::post('roles/{id}/permissions', [RolesController::class, 'addPermissions'])->name('role.permission'); + Route::post('roles/{id}/permissions', [RolesController::class, 'addPermissions'])->name('roles.permission'); // 权限 Route::resource('permissions', 'Permission\PermissionsController', ['only' => ['index', // 'store', 'show', 'update', 'destroy' @@ -49,4 +49,7 @@ Route::post('/auth/login', [LoginController::class, 'login'])->name('auth.login' Route::resource('menus', 'Menu\MenusController', ['only' => ['index', // 'store', 'show', 'update', 'destroy' ]])->middleware('auth:api'); + Route::get('shop_platforms', [ShopsController::class, 'getPlatList'])->name('plat.list')->middleware('auth:api'); + +Route::post('business', [ShopsController::class, 'business'])->name('shop.put.business'); diff --git a/routes/web.php b/routes/web.php index 20cc097..17deaf8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\Goods\GoodsSkusController; use App\Http\Controllers\Goods\GoodsController; +use App\Http\Controllers\Shop\ShopsController; /* |-------------------------------------------------------------------------- @@ -33,3 +34,5 @@ Route::get('/register', function () { Route::get('goods_skus/export', [GoodsSkusController::class, 'export'])->name('goods_skus.export')->middleware('check.permissions'); Route::get('goods/import/template', [GoodsController::class, 'download'])->name('download.goods_import.template'); + +Route::get('callback', [ShopsController::class, 'authBind'])->name('shop.auth_bind.callback'); From 0c3fd316cbe99e46bc193b8910971b55ec56dfe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Sat, 6 Aug 2022 16:10:14 +0800 Subject: [PATCH 33/35] =?UTF-8?q?feat:=20#00000=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Goods/GoodsSkusController.php | 2 +- app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index e04ad52..71a6e25 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -56,7 +56,7 @@ class GoodsSkusController extends Controller $query->with(['type:id,name', 'brand:id,name']); }]) ->with(['daily' => function ($query) use ($day) { - $query->where('day', $day)->with(['daily:id,sku_id,day,arrived_today_num,loss_num,inventory']); + return $query->where('day', $day)->first(['id', 'sku_id', 'day', 'arrived_today_num', 'loss_num', 'inventory']); }]) ->paginate(); diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index 60dd313..706a81c 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -55,11 +55,6 @@ class KuaiTuanTuan extends BusinessClient return $res['pop_auth_token_create_response']; } - public function getAccessToken() - { - return ''; - } - public function getSign($params) { $params = ksort($params); From 5b628380ce379185b52ec7c1e99089113d00e73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Sat, 6 Aug 2022 16:38:04 +0800 Subject: [PATCH 34/35] =?UTF-8?q?feat:=20#00000=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/BusinessOrderItem.php | 5 + app/Models/GoodsSku.php | 5 + app/Services/Business/BusinessClient.php | 4 +- .../Business/KuaiTuanTuan/KuaiTuanTuan.php | 106 +++++++++--------- app/Services/Business/MiaoXuan/MiaoXuan.php | 16 ++- app/Services/Business/MiaoXuan/Order.php | 2 +- 6 files changed, 78 insertions(+), 60 deletions(-) diff --git a/app/Models/BusinessOrderItem.php b/app/Models/BusinessOrderItem.php index b8f5423..daa3675 100644 --- a/app/Models/BusinessOrderItem.php +++ b/app/Models/BusinessOrderItem.php @@ -10,4 +10,9 @@ class BusinessOrderItem extends Model * @var array */ protected $guarded = []; + + public function order() + { + return $this->hasOne(BusinessOrder::class, 'id', 'business_order_id'); + } } diff --git a/app/Models/GoodsSku.php b/app/Models/GoodsSku.php index 36a612a..19c1770 100644 --- a/app/Models/GoodsSku.php +++ b/app/Models/GoodsSku.php @@ -54,4 +54,9 @@ class GoodsSku extends Model { return $this->hasOne(DailyStockRecord::class, 'sku_id', 'id'); } + + public function order() + { + return $this->hasOne(BusinessOrderItem::class, 'external_sku_id', 'id'); + } } diff --git a/app/Services/Business/BusinessClient.php b/app/Services/Business/BusinessClient.php index 48772e6..cc36aeb 100644 --- a/app/Services/Business/BusinessClient.php +++ b/app/Services/Business/BusinessClient.php @@ -13,7 +13,7 @@ abstract class BusinessClient abstract public function auth(); - abstract public function downloadGoodsAndBind(); + abstract public function downloadGoods(); abstract public function bindGoods($goods); @@ -21,6 +21,8 @@ abstract class BusinessClient abstract public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default'); + abstract public function saveOrders($orders); + public function authCallback($code, $shopId) { $this->setCode($code); diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index 706a81c..9b588be 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -27,17 +27,6 @@ class KuaiTuanTuan extends BusinessClient 'sign' => '' ]; - public function __construct() - { - } - - public function getAuthUrl($shopId, $platId) - { - $state = $shopId . '_' . $platId; - - return "https://oauth.pinduoduo.com/authorize/ktt?client_id={$this->clientId}&redirect_uri={$this->redirectUri}&state={$state}"; - } - public function auth() { $accessToken = $this->getAccessTokenWithCode(); @@ -47,54 +36,23 @@ class KuaiTuanTuan extends BusinessClient return $this->shop; } - public function getAccessTokenWithCode() - { - $type = 'pdd.pop.auth.token.create'; - $res = $this->request($type, ['code' => $this->code]); - - return $res['pop_auth_token_create_response']; - } - - public function getSign($params) - { - $params = ksort($params); - $str = ''; - foreach ($params as $key => $val) { - $str .= $key . $val; - } - $str = $this->clientSecret . $str . $this->clientSecret; - - return strtoupper(md5($str)); - } - - public function request($type, $appendParams = [], $url = 'http://gw-api.pinduoduo.com/api/router') - { - $publicParams = [ - 'type' => $type, - 'client_id' => $this->clientId, - 'timestamp' => time() - ]; - if ('pdd.pop.auth.token.create' !== $type) { - $publicParams['access_token'] = $this->getAccessToken(); - } - $publicParams = array_merge($publicParams, $appendParams); - $publicParams['sign'] = $this->getSign($publicParams); - - return $this->formDataPostRequest($url, $publicParams); - } - - public function downloadGoodsAndBind($page = 1) + public function downloadGoods($page = 1) { [$type, $appendParams] = Goods::downloadGoods($this->shop->owner_name, $page); $res = $this->formDataPostRequest($type, $appendParams); $goods = $res['ktt_goods_query_list_response']['goods_list']; - Goods::bindGoods($goods, $this->shop->id); + $this->bindGoods($goods); $pageNum = ceil($res['total'] / $appendParams['size']); if ($pageNum > $page && 10 >= $page) { - $this->downloadGoodsAndBind($page + 1); + $this->downloadGoods($page + 1); } } + public function bindGoods($goods) + { + Goods::bindGoods($goods, $this->shop->id); + } + public function incrQuantity($skuId) { $goodsSku = GoodsSku::query()->find($skuId); @@ -125,8 +83,52 @@ class KuaiTuanTuan extends BusinessClient return $res['ktt_order_list_response']['order_list']; } - public function bindGoods($goods) + public function saveOrders($orders) { - // TODO: Implement bindGoods() method. + Order::saveOrders($orders, $this->shop->id); + } + + protected function getAccessTokenWithCode() + { + $type = 'pdd.pop.auth.token.create'; + $res = $this->doRequest($type, ['code' => $this->code]); + + return $res['pop_auth_token_create_response']; + } + + protected function getSign($params) + { + $params = ksort($params); + $str = ''; + foreach ($params as $key => $val) { + $str .= $key . $val; + } + $str = $this->clientSecret . $str . $this->clientSecret; + + return strtoupper(md5($str)); + } + + public function doRequest($type, $appendParams = [], $url = 'http://gw-api.pinduoduo.com/api/router') + { + $publicParams = [ + 'type' => $type, + 'client_id' => $this->clientId, + 'timestamp' => time() + ]; + if ('pdd.pop.auth.token.create' !== $type) { + $publicParams['access_token'] = $this->getAccessToken(); + } + $publicParams = array_merge($publicParams, $appendParams); + $publicParams['sign'] = $this->getSign($publicParams); + + return $this->formDataPostRequest($url, $publicParams); + } + + + public function getAuthUrl($shopId, $platId) + { + $state = $shopId . '_' . $platId; + + return "https://oauth.pinduoduo.com/authorize/ktt?client_id={$this->clientId}&redirect_uri={$this->redirectUri}&state={$state}"; } } diff --git a/app/Services/Business/MiaoXuan/MiaoXuan.php b/app/Services/Business/MiaoXuan/MiaoXuan.php index 041d2de..3415a33 100644 --- a/app/Services/Business/MiaoXuan/MiaoXuan.php +++ b/app/Services/Business/MiaoXuan/MiaoXuan.php @@ -15,17 +15,22 @@ class MiaoXuan extends BusinessClient // TODO: Implement auth() method. } - public function downloadGoodsAndBind() + public function downloadGoods() { } + public function bindGoods($goods) + { + Goods::bindGoods($goods, $this->shop->id); + } + public function incrQuantity($skuId) { $goodsSku = GoodsSku::query()->find($skuId); $business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id', 'external_sku_id'])->toArray(); $appendParams = Goods::incrQuantity($this->shop->id, $goodsSku->stock, $business); - - $this->formDataPostRequest($type, $appendParams); + $url = ''; // http://shop.chutang66.com/miaoxuan/stock + $this->formDataPostRequest($url, $appendParams); $log = new Log(); $log->module = 'plat'; $log->action = 'POST'; @@ -39,11 +44,10 @@ class MiaoXuan extends BusinessClient public function downloadOrders($beginTime, $endTime, $activityNo, $downloadType = 'default') { - Order::saveOrders($beginTime, $endTime, $activityNo); } - public function bindGoods($goods) + public function saveOrders($orders) { - Goods::bindGoods($goods, $this->shop->id); + Order::saveOrders($orders, $this->shop->id); } } diff --git a/app/Services/Business/MiaoXuan/Order.php b/app/Services/Business/MiaoXuan/Order.php index c8489a4..07278fa 100644 --- a/app/Services/Business/MiaoXuan/Order.php +++ b/app/Services/Business/MiaoXuan/Order.php @@ -7,7 +7,7 @@ use App\Models\BusinessOrder; class Order { // 下载订单事件之后去统计 然后更新库存 - public static function saveOrders(array $orders) + public static function saveOrders(array $orders, $shopId) { foreach ($orders as $order) { $orderRecord = BusinessOrder::updateOrCreate( From e0f68a2d4da4cdb6585bcbbc0e09e2a994dedb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Mon, 8 Aug 2022 10:43:59 +0800 Subject: [PATCH 35/35] =?UTF-8?q?feat:=20#20220808=20=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AF=A6=E7=BB=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Shop/ShopsController.php | 8 +++-- app/Listeners/BindBusinessGoods.php | 34 +++++++++++++++++++ app/Listeners/SendDatabaseNotification.php | 31 +++++++++++++++++ app/Listeners/UpdateBusinessGoodsStock.php | 34 +++++++++++++++++++ app/Models/Log.php | 8 +++++ app/Providers/EventServiceProvider.php | 6 ++++ .../Business/KuaiTuanTuan/KuaiTuanTuan.php | 1 + 7 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 app/Listeners/BindBusinessGoods.php create mode 100644 app/Listeners/SendDatabaseNotification.php create mode 100644 app/Listeners/UpdateBusinessGoodsStock.php diff --git a/app/Http/Controllers/Shop/ShopsController.php b/app/Http/Controllers/Shop/ShopsController.php index 5ec522d..d32528c 100644 --- a/app/Http/Controllers/Shop/ShopsController.php +++ b/app/Http/Controllers/Shop/ShopsController.php @@ -3,6 +3,8 @@ namespace App\Http\Controllers\Shop; use App\Http\Controllers\Controller; +use App\Listeners\BindBusinessGoods; +use App\Listeners\UpdateBusinessGoodsStock; use App\Models\Shop; use App\Http\Resources\ShopsResource; use Illuminate\Http\Request; @@ -86,10 +88,12 @@ class ShopsController extends Controller $business = BusinessFactory::init()->make($shop->plat_id); $business->setShop($shop); if ('goods' === $request->get('type')) { - $business->downloadGoodsAndBind($request->get('data')); + $business->bindGoods($request->get('data')); + event(new BindBusinessGoods($shop)); } if ('orders' === $request->get('type')) { - $business->downloadOrders(); + $business->saveOrders(); + event(new UpdateBusinessGoodsStock($shop)); } } } diff --git a/app/Listeners/BindBusinessGoods.php b/app/Listeners/BindBusinessGoods.php new file mode 100644 index 0000000..b6c3ed8 --- /dev/null +++ b/app/Listeners/BindBusinessGoods.php @@ -0,0 +1,34 @@ +shop = $shop; + } + + /** + * Handle the event. + * + * @param Registered $event + * @return void + */ + public function handle(Registered $event) + { + // + } +} diff --git a/app/Listeners/SendDatabaseNotification.php b/app/Listeners/SendDatabaseNotification.php new file mode 100644 index 0000000..ce0cbee --- /dev/null +++ b/app/Listeners/SendDatabaseNotification.php @@ -0,0 +1,31 @@ +shop = $shop; + } + + /** + * Handle the event. + * + * @param Registered $event + * @return void + */ + public function handle(Registered $event) + { + // + } +} diff --git a/app/Models/Log.php b/app/Models/Log.php index 75c1cd7..06bc265 100644 --- a/app/Models/Log.php +++ b/app/Models/Log.php @@ -38,6 +38,8 @@ class Log extends Model 'permission' => '权限', 'role' => '角色', 'user' => '用户', + 'plat' => '平台', + 'file' => '文件', ]; return $map[$value]; @@ -65,6 +67,9 @@ class Log extends Model 'role' => '角色', 'menu' => '菜单', 'user' => '用户', + 'upload' => '上传', + 'kuaituantuan' => '快团团', + 'miaoxuan' => '妙选', ]; return $map[$value]; @@ -80,6 +85,9 @@ class Log extends Model 'import' => '导入', 'export' => '导出', 'set' => '设置', + 'cost' => '成本', + 'stock' => '库存', + 'inventory' => '库存盘点', ]; return $map[$value]; diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 723a290..b975ef6 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -6,6 +6,9 @@ use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Event; +use App\Listeners\SendDatabaseNotification; +use App\Listeners\BindBusinessGoods; +use App\Listeners\UpdateBusinessGoodsStock; class EventServiceProvider extends ServiceProvider { @@ -17,6 +20,9 @@ class EventServiceProvider extends ServiceProvider protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, + SendDatabaseNotification::class, + BindBusinessGoods::class, + UpdateBusinessGoodsStock::class, ], ]; diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index 9b588be..d75d708 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -2,6 +2,7 @@ namespace App\Services\Business\KuaiTuanTuan; +use App\Listeners\BindBusinessGoods; use App\Models\BusinessGoodsSku; use App\Models\GoodsSku; use App\Services\Business\BusinessClient;