Jelajahi Sumber

Merge branch 'liuzj-permission-dev' into test

liuzejian 1 tahun lalu
induk
melakukan
f391c37743

+ 1 - 1
modules/System/Services/Notice/NoitceTypeService.php

@@ -11,7 +11,7 @@
 namespace Modules\System\Services\Notice;
 
 use Illuminate\Support\Facades\DB;
-use Modules\ContentManage\Models\NoticeTypes;
+use Modules\System\Models\NoticeTypes;
 
 class NoitceTypeService
 {

+ 0 - 17
modules/T1/Exceptions/ContentBusinessException.php

@@ -1,17 +0,0 @@
-<?php
-
-namespace Modules\ContentManage\Exceptions;
-
-use Throwable;
-
-class ContentBusinessException 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));
-    }
-}

+ 0 - 20
modules/T1/Exceptions/ContentManageForbidden.php

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

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

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

+ 0 - 33
modules/T1/Http/Controllers/T1Controller.php

@@ -1,33 +0,0 @@
-<?php
-/**
- * ${CARET}
- * @file:NoticesController.php
- * @Created by gnitif
- * @Date: 2023/3/27
- * @Time: 11:18
- */
-
-
-namespace Modules\T1\Http\Controllers;
-
-
-use Catch\Base\CatchController as Controller;
-use Catch\Exceptions\FailedException;
-use Illuminate\Contracts\Pagination\LengthAwarePaginator;
-use Illuminate\Http\Request;
-use Modules\System\Http\Requests\NoticeRequest;
-use Modules\System\Models\NoticeTypes;
-use Modules\System\Services\Notice\NoticesService;
-
-class T1Controller extends Controller
-{
-    public function list(Request $request)
-    {
-        return ['t1', 'list'];
-    }
-
-    public function list2(Request $request)
-    {
-        return ['t2', 'list2'];
-    }
-}

+ 0 - 32
modules/T1/Installer.php

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

+ 0 - 26
modules/T1/Middlewares/ContentManageGate.php

@@ -1,26 +0,0 @@
-<?php
-
-namespace Modules\ContentManage\Middlewares;
-
-use Illuminate\Http\Request;
-use Modules\ContentManage\Exceptions\PermissionForbidden;
-use Modules\User\Models\User;
-
-class ContentManageGate
-{
-    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 PermissionForbidden();
-        }
-
-        return $next($request);
-    }
-}

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

@@ -1,30 +0,0 @@
-<?php
-
-namespace Modules\System\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);
-    }
-}

+ 0 - 15
modules/T1/Models/NoticeTypes.php

@@ -1,15 +0,0 @@
-<?php
-
-namespace Modules\System\Models;
-
-
-
-class NoticeTypes extends BaseModel
-{
-    protected $table = 'notice_types';
-
-    protected $fillable = [
-        'id', 'name', 'is_deleted', 'created_at', 'updated_at', 'deleted_at',
-    ];
-
-}

+ 0 - 73
modules/T1/Models/Notices.php

@@ -1,73 +0,0 @@
-<?php
-
-namespace Modules\System\Models;
-
-
-class Notices extends BaseModel
-{
-    protected $table = 'notices';
-
-    protected $fillable = [
-        'id', 'title', 'content', 'notice_type_id', "sort", 'type', 'notice_obj', 'is_popup', 'is_deleted', 'created_at', 'updated_at', 'deleted_at',
-    ];
-
-    /**
-     * @var array
-     */
-    protected array $fields = ['id', 'title', 'content', "sort", 'notice_type_id', 'type', 'notice_obj', 'is_popup', 'created_at', 'updated_at'];
-
-    /**
-     * @var array
-     */
-    protected array $form = ['title', 'content', 'notice_type_id',"sort", 'type', 'notice_obj', 'is_popup'];
-
-
-    protected $casts = ['notice_obj' => 'array'];
-
-    public array $searchable = [
-        'title' => 'like',
-        'notice_type_id' => '=',
-        'type' => '=',
-
-    ];
-
-    protected string $sortField = 'sort';
-
-
-
-    /**
-     *  添加通知
-     * @param array $data
-     * @return bool
-     * @throws \ReflectionException
-     */
-    public function storeBy(array $data): mixed
-    {
-        $result = '';
-        $this->beginTransaction();
-        try {
-            $result = $this->create($this->filterData($data));
-            if (isset($data['user_ids']) && !empty($data['user_ids'])) {
-                $this->addUserNotice($data['user_ids'], $result->id);
-            }
-            $this->commit();
-        } catch (\Exception $exception) {
-            $this->rollback();
-        }
-        return $result->id ?? 0;
-    }
-
-    private function addUserNotice(mixed $userIds, mixed $id)
-    {
-        $list = [];
-        foreach ($userIds as $val) {
-            $list[] = ['user_id' => $val, 'notice_id' => $id];
-        }
-        if (!empty($list)) {
-            UserNotice::insert($list);
-        }
-        return true;
-    }
-
-
-}

+ 0 - 14
modules/T1/Models/UserNotice.php

@@ -1,14 +0,0 @@
-<?php
-
-namespace Modules\System\Models;
-
-
-class UserNotice extends BaseModel
-{
-    protected $table = 'user_notice';
-
-    protected $fillable = [
-        'id', 'user_id', 'notice_id', 'is_deleted', 'is_read', 'created_at', 'updated_at', 'deleted_at',
-    ];
-
-}

+ 0 - 29
modules/T1/Providers/T1ServiceProvider.php

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

+ 0 - 10
modules/T1/README.md

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

+ 0 - 10
modules/T1/routes/route.php

@@ -1,10 +0,0 @@
-<?php
-
-use Illuminate\Support\Facades\Route;
-use Modules\T1\Http\Controllers\T1Controller;
-
-Route::prefix('t1')->group(function () {
-    Route::get('list', [T1Controller::class,'list']);
-    Route::get('list2', [T1Controller::class,'list2']);
-});
-

+ 0 - 17
modules/T2/Exceptions/ContentBusinessException.php

@@ -1,17 +0,0 @@
-<?php
-
-namespace Modules\ContentManage\Exceptions;
-
-use Throwable;
-
-class ContentBusinessException 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));
-    }
-}

+ 0 - 20
modules/T2/Exceptions/ContentManageForbidden.php

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

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

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

+ 0 - 29
modules/T2/Http/Controllers/T2Controller.php

@@ -1,29 +0,0 @@
-<?php
-/**
- * ${CARET}
- * @file:NoticesController.php
- * @Created by gnitif
- * @Date: 2023/3/27
- * @Time: 11:18
- */
-
-
-namespace Modules\T2\Http\Controllers;
-
-
-use Catch\Base\CatchController as Controller;
-
-use Illuminate\Http\Request;
-
-
-class T2Controller extends Controller
-{
-    public function list(Request $request)
-    {
-        return ['t2', 'list'];
-    }
-    public function list2(Request $request)
-    {
-        return ['t2', 'list2'];
-    }
-}

+ 0 - 56
modules/T2/Http/Controllers/UserTrait.php

@@ -1,56 +0,0 @@
-<?php
-
-namespace Modules\ContentManage\Http\Controllers;
-
-use Catch\Base\CatchController;
-use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\DB;
-use Modules\User\Models\User;
-
-trait UserTrait
-{
-    // 当前登录用户
-    protected $currentUser;
-
-    /**
-     * 获取当前登录用户
-     * @return User
-     */
-    protected function getCurrentUser(): User {
-        if(!$this->currentUser) {
-            $this->currentUser = $this->getLoginUser();
-        }
-        return $this->currentUser;
-    }
-    /**
-     * 当前用户的所有的角色标识的结合
-     * @return Collection
-     */
-    protected function listUserRoles():Collection {
-        return $this->getCurrentUser()->roles->pluck('identify');
-    }
-
-    /**
-     * 当前用户是否是cp角色
-     * @return bool
-     */
-    public function userIsCp():bool {
-        return $this->listUserRoles()->contains('cp');
-    }
-
-    /**
-     * 如果当前用户是cp角色,返回cp_name,否则返回null
-     * @return string
-     */
-    public function getUserCpName():string|null {
-        if($this->userIsCp()) {
-            return DB::table('user_belong_to_cp')
-                ->where([
-                    'is_enabled' => 1,
-                    'user_id' => $this->getCurrentUser()->id,
-                ])->value('cp_name');
-        } else {
-            return null;
-        }
-    }
-}

+ 0 - 32
modules/T2/Installer.php

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

+ 0 - 26
modules/T2/Middlewares/ContentManageGate.php

@@ -1,26 +0,0 @@
-<?php
-
-namespace Modules\ContentManage\Middlewares;
-
-use Illuminate\Http\Request;
-use Modules\ContentManage\Exceptions\PermissionForbidden;
-use Modules\User\Models\User;
-
-class ContentManageGate
-{
-    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 PermissionForbidden();
-        }
-
-        return $next($request);
-    }
-}

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

@@ -1,30 +0,0 @@
-<?php
-
-namespace Modules\System\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);
-    }
-}

+ 0 - 15
modules/T2/Models/NoticeTypes.php

@@ -1,15 +0,0 @@
-<?php
-
-namespace Modules\System\Models;
-
-
-
-class NoticeTypes extends BaseModel
-{
-    protected $table = 'notice_types';
-
-    protected $fillable = [
-        'id', 'name', 'is_deleted', 'created_at', 'updated_at', 'deleted_at',
-    ];
-
-}

+ 0 - 73
modules/T2/Models/Notices.php

@@ -1,73 +0,0 @@
-<?php
-
-namespace Modules\System\Models;
-
-
-class Notices extends BaseModel
-{
-    protected $table = 'notices';
-
-    protected $fillable = [
-        'id', 'title', 'content', 'notice_type_id', "sort", 'type', 'notice_obj', 'is_popup', 'is_deleted', 'created_at', 'updated_at', 'deleted_at',
-    ];
-
-    /**
-     * @var array
-     */
-    protected array $fields = ['id', 'title', 'content', "sort", 'notice_type_id', 'type', 'notice_obj', 'is_popup', 'created_at', 'updated_at'];
-
-    /**
-     * @var array
-     */
-    protected array $form = ['title', 'content', 'notice_type_id',"sort", 'type', 'notice_obj', 'is_popup'];
-
-
-    protected $casts = ['notice_obj' => 'array'];
-
-    public array $searchable = [
-        'title' => 'like',
-        'notice_type_id' => '=',
-        'type' => '=',
-
-    ];
-
-    protected string $sortField = 'sort';
-
-
-
-    /**
-     *  添加通知
-     * @param array $data
-     * @return bool
-     * @throws \ReflectionException
-     */
-    public function storeBy(array $data): mixed
-    {
-        $result = '';
-        $this->beginTransaction();
-        try {
-            $result = $this->create($this->filterData($data));
-            if (isset($data['user_ids']) && !empty($data['user_ids'])) {
-                $this->addUserNotice($data['user_ids'], $result->id);
-            }
-            $this->commit();
-        } catch (\Exception $exception) {
-            $this->rollback();
-        }
-        return $result->id ?? 0;
-    }
-
-    private function addUserNotice(mixed $userIds, mixed $id)
-    {
-        $list = [];
-        foreach ($userIds as $val) {
-            $list[] = ['user_id' => $val, 'notice_id' => $id];
-        }
-        if (!empty($list)) {
-            UserNotice::insert($list);
-        }
-        return true;
-    }
-
-
-}

+ 0 - 14
modules/T2/Models/UserNotice.php

@@ -1,14 +0,0 @@
-<?php
-
-namespace Modules\System\Models;
-
-
-class UserNotice extends BaseModel
-{
-    protected $table = 'user_notice';
-
-    protected $fillable = [
-        'id', 'user_id', 'notice_id', 'is_deleted', 'is_read', 'created_at', 'updated_at', 'deleted_at',
-    ];
-
-}

+ 0 - 31
modules/T2/Providers/T2ServiceProvider.php

@@ -1,31 +0,0 @@
-<?php
-
-namespace Modules\T2\Providers;
-
-use Catch\CatchAdmin;
-use Catch\Providers\CatchModuleServiceProvider;
-use Modules\ContentManage\Middlewares\ContentManageGate;
-
-class T2ServiceProvider extends CatchModuleServiceProvider
-{
-    /**
-     * middlewares
-     *
-     * @return string[]
-     */
-    protected function middlewares(): array
-    {
-       return [];
-    }
-
-    /**
-     * route path
-     *
-     * @return string|array
-     */
-    public function moduleName(): string|array
-    {
-        // TODO: Implement path() method.
-        return 't2';
-    }
-}

+ 0 - 10
modules/T2/README.md

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

+ 0 - 10
modules/T2/routes/route.php

@@ -1,10 +0,0 @@
-<?php
-
-use Illuminate\Support\Facades\Route;
-use Modules\T2\Http\Controllers\T2Controller;
-
-
-Route::prefix('t2')->group(function () {
-    Route::get('list', [T2Controller::class,'list']);
-    Route::get('list', [T2Controller::class, 'list2']);
-});