浏览代码

创建模块

zqwang 2 年之前
父节点
当前提交
d8c7ab9516

+ 17 - 0
modules/CpManage/Exceptions/CpManageBusinessException.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace Modules\DuanJu\Exceptions;
+
+use Throwable;
+
+class DuanJuBusinessException extends \RuntimeException
+{
+    public function __construct($message = "", $code = 0, Throwable $previous = null)
+    {
+        parent::__construct($message, $code, $previous);
+    }
+
+    public static function throwError($error, Throwable $previous = null) {
+        throw (new static($error[1], $error[0], $previous));
+    }
+}

+ 20 - 0
modules/CpManage/Exceptions/CpManagePermissionForbidden.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Modules\DuanJu\Exceptions;
+
+use Catch\Enums\Code;
+use Catch\Exceptions\CatchException;
+use Symfony\Component\HttpFoundation\Response;
+
+class DuanJuPermissionForbidden extends CatchException
+{
+    protected $message = 'permission forbidden';
+
+    protected $code = Code::PERMISSION_FORBIDDEN;
+
+
+    public function statusCode(): int
+    {
+        return Response::HTTP_FORBIDDEN;
+    }
+}

+ 9 - 0
modules/CpManage/Exceptions/Errors.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace Modules\DuanJu\Exceptions;
+
+class Errors
+{
+    public const REQUEST_HTTP_STATUS_ERROR = [500001, '请求上游接口返回http状态码有误'];
+    public const REQUEST_CODE_STATUS_ERROR = [500002, '请求上游接口返回code状态码有误'];
+}

+ 33 - 0
modules/CpManage/Installer.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace Modules\DuanJu;
+
+use Catch\Support\Module\Installer as ModuleInstaller;
+use Modules\DuanJu\Providers\DuanJuServiceProvider;
+
+
+class Installer extends ModuleInstaller
+{
+    protected function info(): array
+    {
+        // TODO: Implement info() method.
+        return [
+            'title' => 'cp管理',
+            'name' => 'DuanJu',
+            'path' => 'DuanJu',
+            'keywords' => '短剧',
+            'description' => '短剧模块',
+            'provider' => DuanJuServiceProvider::class
+        ];
+    }
+
+    protected function requirePackages(): void
+    {
+        // TODO: Implement requirePackages() method.
+    }
+
+    protected function removePackages(): void
+    {
+        // TODO: Implement removePackages() method.
+    }
+}

+ 28 - 0
modules/CpManage/Middlewares/CpManageGate.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace Modules\CpManage\Middlewares;
+
+use Illuminate\Http\Request;
+
+use Modules\CpManage\Exceptions\CpManagePermissionForbidden;
+use Modules\User\Models\User;
+
+class CpManageGate
+{
+    public function handle(Request $request, \Closure $next)
+    {
+        if ($request->isMethod('get')) {
+            return $next($request);
+        }
+
+        /* @var User $user */
+        $user = $request->user(getGuardName());
+
+        if (! $user->can()) {
+            throw new CpManagePermissionForbidden();
+        }
+
+        return $next($request);
+    }
+}
+

+ 30 - 0
modules/CpManage/Models/BaseModel.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace Modules\DuanJu\Models;
+
+use Catch\Base\CatchModel as Model;
+use Illuminate\Database\Eloquent\Builder;
+
+
+abstract class BaseModel extends Model
+{
+
+    protected array $defaultHidden = [];
+
+    protected array $defaultCasts = [
+        'created_at' => 'datetime:Y-m-d H:i:s',
+
+        'updated_at' => 'datetime:Y-m-d H:i:s',
+    ];
+    protected $dateFormat = '';
+
+    public static function bootSoftDeletes(): void{
+
+    }
+
+
+    public function scopeActive(Builder $query): void
+    {
+        $query->where($this->table.'.is_enabled', 1);
+    }
+}

+ 32 - 0
modules/CpManage/Providers/CpManageServiceProvider.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Modules\CpManage\Providers;
+
+
+use Catch\Providers\CatchModuleServiceProvider;
+use Modules\CpManage\Middlewares\DaunJuGate;
+
+class CpManageServiceProvider extends CatchModuleServiceProvider
+{
+    /**
+     * middlewares
+     *
+     * @return string[]
+     */
+    protected function middlewares(): array
+    {
+       return [DaunJuGate::class];
+    }
+
+    /**
+     * route path
+     *
+     * @return string|array
+     */
+    public function moduleName(): string|array
+    {
+        // TODO: Implement path() method.
+        return 'cpManage';
+    }
+}
+

+ 10 - 0
modules/CpManage/README.md

@@ -0,0 +1,10 @@
+#短剧模块
+关于短剧模块 相关的后台接口,对外api接口,都写在这里
+配置文件放在: config目录下,读取配置文件示例:config('daunju.zhushuyunpublicapi.public_domain');
+config("模块名.配置文件名.配置项");
+
+数据库模型文件放在:Models 目录下面
+服务层文件放在:Services 目录下面
+控制器放在:modules/DuanJu/Http/Controllers 目录下面
+中间件放在:modules/DuanJu/Middlewares 目录下面
+路由只能现在 modules/DuanJu/rout/route.php 文件里

+ 4 - 0
modules/CpManage/config/ok.php

@@ -0,0 +1,4 @@
+<?php
+return [
+    'is_ok' => true
+];

+ 4 - 0
modules/CpManage/config/oks.php

@@ -0,0 +1,4 @@
+<?php
+return [
+    'is_ok' => true
+];

+ 11 - 0
modules/CpManage/routes/route.php

@@ -0,0 +1,11 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+
+Route::prefix('daunJu')->group(function () {
+    
+
+});
+
+

+ 17 - 0
modules/DuanJu/Exceptions/DuanJuBusinessException.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace Modules\DuanJu\Exceptions;
+
+use Throwable;
+
+class DuanJuBusinessException extends \RuntimeException
+{
+    public function __construct($message = "", $code = 0, Throwable $previous = null)
+    {
+        parent::__construct($message, $code, $previous);
+    }
+
+    public static function throwError($error, Throwable $previous = null) {
+        throw (new static($error[1], $error[0], $previous));
+    }
+}

+ 20 - 0
modules/DuanJu/Exceptions/DuanJuPermissionForbidden.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Modules\DuanJu\Exceptions;
+
+use Catch\Enums\Code;
+use Catch\Exceptions\CatchException;
+use Symfony\Component\HttpFoundation\Response;
+
+class DuanJuPermissionForbidden extends CatchException
+{
+    protected $message = 'permission forbidden';
+
+    protected $code = Code::PERMISSION_FORBIDDEN;
+
+
+    public function statusCode(): int
+    {
+        return Response::HTTP_FORBIDDEN;
+    }
+}

+ 9 - 0
modules/DuanJu/Exceptions/Errors.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace Modules\DuanJu\Exceptions;
+
+class Errors
+{
+    public const REQUEST_HTTP_STATUS_ERROR = [500001, '请求上游接口返回http状态码有误'];
+    public const REQUEST_CODE_STATUS_ERROR = [500002, '请求上游接口返回code状态码有误'];
+}

+ 33 - 0
modules/DuanJu/Installer.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace Modules\DuanJu;
+
+use Catch\Support\Module\Installer as ModuleInstaller;
+use Modules\DuanJu\Providers\DuanJuServiceProvider;
+
+
+class Installer extends ModuleInstaller
+{
+    protected function info(): array
+    {
+        // TODO: Implement info() method.
+        return [
+            'title' => '短剧',
+            'name' => 'DuanJu',
+            'path' => 'DuanJu',
+            'keywords' => '短剧',
+            'description' => '短剧模块',
+            'provider' => DuanJuServiceProvider::class
+        ];
+    }
+
+    protected function requirePackages(): void
+    {
+        // TODO: Implement requirePackages() method.
+    }
+
+    protected function removePackages(): void
+    {
+        // TODO: Implement removePackages() method.
+    }
+}

+ 28 - 0
modules/DuanJu/Middlewares/DaunJuGate.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace Modules\DuanJu\Middlewares;
+
+use Illuminate\Http\Request;
+
+use Modules\DuanJu\Exceptions\DuanJuPermissionForbidden;
+use Modules\User\Models\User;
+
+class DaunJuGate
+{
+    public function handle(Request $request, \Closure $next)
+    {
+        if ($request->isMethod('get')) {
+            return $next($request);
+        }
+
+        /* @var User $user */
+        $user = $request->user(getGuardName());
+
+        if (! $user->can()) {
+            throw new DuanJuPermissionForbidden();
+        }
+
+        return $next($request);
+    }
+}
+

+ 30 - 0
modules/DuanJu/Models/BaseModel.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace Modules\DuanJu\Models;
+
+use Catch\Base\CatchModel as Model;
+use Illuminate\Database\Eloquent\Builder;
+
+
+abstract class BaseModel extends Model
+{
+
+    protected array $defaultHidden = [];
+
+    protected array $defaultCasts = [
+        'created_at' => 'datetime:Y-m-d H:i:s',
+
+        'updated_at' => 'datetime:Y-m-d H:i:s',
+    ];
+    protected $dateFormat = '';
+
+    public static function bootSoftDeletes(): void{
+
+    }
+
+
+    public function scopeActive(Builder $query): void
+    {
+        $query->where($this->table.'.is_enabled', 1);
+    }
+}

+ 32 - 0
modules/DuanJu/Providers/DuanJuServiceProvider.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Modules\DuanJu\Providers;
+
+
+use Catch\Providers\CatchModuleServiceProvider;
+use Modules\DuanJu\Middlewares\DaunJuGate;
+
+class DuanJuServiceProvider extends CatchModuleServiceProvider
+{
+    /**
+     * middlewares
+     *
+     * @return string[]
+     */
+    protected function middlewares(): array
+    {
+       return [DaunJuGate::class];
+    }
+
+    /**
+     * route path
+     *
+     * @return string|array
+     */
+    public function moduleName(): string|array
+    {
+        // TODO: Implement path() method.
+        return 'duanJu';
+    }
+}
+

+ 10 - 0
modules/DuanJu/README.md

@@ -0,0 +1,10 @@
+#短剧模块
+关于短剧模块 相关的后台接口,对外api接口,都写在这里
+配置文件放在: config目录下,读取配置文件示例:config('daunju.zhushuyunpublicapi.public_domain');
+config("模块名.配置文件名.配置项");
+
+数据库模型文件放在:Models 目录下面
+服务层文件放在:Services 目录下面
+控制器放在:modules/DuanJu/Http/Controllers 目录下面
+中间件放在:modules/DuanJu/Middlewares 目录下面
+路由只能现在 modules/DuanJu/rout/route.php 文件里

+ 4 - 0
modules/DuanJu/config/ok.php

@@ -0,0 +1,4 @@
+<?php
+return [
+    'is_ok' => true
+];

+ 4 - 0
modules/DuanJu/config/oks.php

@@ -0,0 +1,4 @@
+<?php
+return [
+    'is_ok' => true
+];

+ 11 - 0
modules/DuanJu/routes/route.php

@@ -0,0 +1,11 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+
+Route::prefix('daunJu')->group(function () {
+    
+
+});
+
+